Commit Graph

1012 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire 03a998bae8 Typechecker
- Removed `assert(false)` in code which handles a mismatched parameter type versus argument type, replaced with a throws `TypeMismatchException`
2023-02-11 12:19:44 +02:00
Tristan B. Velloza Kildaire ab66860e7b Typechecker
- See TODO
2023-02-11 12:16:11 +02:00
Tristan B. Velloza Kildaire dcdaa87c54 Typehecker
- Any attempt to dereference an entity of which is not a pointer type will now throw a `TypeCheckerException` instead of a failing assertion with a print-out
2023-02-11 12:13:08 +02:00
Tristan B. Velloza Kildaire 9332b955ff Typechecker
- On processing of binary operations, if there is a type mismatch now a `TypeMismatchException` will be thrown instead of a print0out followed by an `assert(false)`
2023-02-11 12:09:09 +02:00
Tristan B. Velloza Kildaire 59920286e2 Typechecker
- Removed TODO
- Added some TODO temporary checks that are no-ops for now regarding `-` handling in the `UnaryOpInstr` handler if-branch
2023-02-11 12:03:25 +02:00
Tristan B. Velloza Kildaire 561ce505a0 Test cases
- Added new test case `simple_literals6.t` for future test
2023-02-11 12:02:06 +02:00
Tristan B. Velloza Kildaire ede4db948b Typechecker
- Corrected casted variable, was `literalInstr` but is meant to be `operandInstr`
- Added support for coercing signed literals in ranges for `byte`, `short`, `int` and `long`
- Added initial support for signed-literal coercion (e.g. `-1`)
- Set type for `UnaryOpInstr` (when doing `ADD` or `SUB` to the type of the embedded instruction (of type `Value` - this is soon to change in certain cases

Test cases

- Updated test case `simple_literals4.t`
- Updated test case `simple_literals5.t`
2023-02-06 21:49:25 +02:00
Tristan B. Velloza Kildaire 4474561ee1 Test cases
- Updated test case `simple_literals3.t` to showcase more values
2023-02-06 16:08:54 +02:00
Tristan B. Velloza Kildaire a884bfe441 Packaging
- Fixed module naming; autocomplete now works

Typing

- Added a TODO/NOTE comment

Parser

- Implemented range-based literal type encoding for integer literals

Check

- Switched from directly calling `isNumeric(string)` to our own `isNumericLiteral(string)` to check if a token is a `SymbolType.NUMBER_LITERAL`

Test cases

- Added new test case `simple_literals3.t`
2023-02-05 20:21:26 +02:00
Tristan B. Velloza Kildaire 18b784f861 Parser
- Updated `ParserException` to have a sub-error type `ParserErrorType`
- Updated `SyntaxError` to overwrite the exception's `msg` field
- Added literal encoding for integer support to parser

Typechecker

- Removed exception check which is now redundant seeing as literal overflows would be checked within the parser (way before typechecking begins)
- Added conversion support (type transfers) for the `LiteralValue` instruction codegen
- Removed uneeded sub-error type in `TypeCheckerException`'s `TypecheckError` (rempved `TypecheckError.LITERAL_OVERFLOW`)
2023-02-05 14:13:15 +02:00
Tristan B. Velloza Kildaire f7a4091620 TypeChecker
- Corrected enum for error sub-type from `TypeheckError` to `TypecheckError`
- Added new sub-type error `TypecheckError.LITERAL_OVERFLOW`
- If the literal value is too big then throw a `TypeCheckerException`
2023-02-05 12:47:27 +02:00
Tristan B. Velloza Kildaire 185db68311 Coercion
- Added support for range checking `ubyte` type coercion
2023-02-05 12:27:47 +02:00
Tristan B. Velloza Kildaire 45eec9fb20 DUB configuration
- Added homepage to dub configuration
2023-02-05 12:27:14 +02:00
Tristan B. Velloza Kildaire 065c8d5816 Exceptions
- `TypeCheckerException` now inherits from `TError`
- `TypeCheckerException`  now produces a neat error message using an enum `TypecheckError`
- Added new sub-class `TypeMismatchException` to be used when two types do not match

TypeChecker

- Hoisted out the coercion code into two methods, `isCoercibleRange` and `attemptCoercion`
- Make both variabel declarations (with assignments) and standlaone variable assignments call the `attemptCoercion()` method when the call to `isSameType(Type t1, Type t2)` returns `false`

Test cases

- Added new test case `simple_literals2.t`
2023-02-04 14:37:40 +02:00
Tristan B. Velloza Kildaire c1ee7d06ba LiteralValue, LiteralValueFloat
- Made the `data` field `private` and now accessible through a call to `string getLiteralValue()`

UnaryOpInstr

- Use `Value` instead of `Instruction` for unary operator instructions

DGen

- Switched to using `getLiteralValue()` where required due to the aforementioned reasons
2023-02-04 14:25:39 +02:00
Tristan B. Velloza Kildaire de37eeec8c Merge branch 'compiler_object' into literal_encodings 2023-02-04 12:53:25 +02:00
Tristan B. Velloza Kildaire 00ac28c553 Commands
- Enable pretty code generation on the command-line by default
- Explicitly make the `SymbolMappingTechnique.HASHMAPPER` the default symbol translation technique
2023-02-04 12:52:18 +02:00
Tristan B. Velloza Kildaire e919dcc8e4 DGen
- Removed the `varDecWantsConsumeVarAss` as it is not used anymore
- The transformation of the `VariableAssignmentInstr` instruction (which is generated by a corresponding `VariableStdAloneAss` parser node) does not check for `varDecWantsConsumeVarAss` anymore and will directly `transform(varAss.data)` (the embedded `Value` instruction in the `VariableAssignmentInstr`
- If a `VariableDeclaration` instruction has an assignment then we extract the `Value` instruction from it and perform a `transform(Value)` - no longer do we have an intermediary `VariableAssignmentInstr`

Instruction

- `VariableDeclaration` now uses a `Value`-based instruction rather than a `VariableAssignmentInstr` as the embedded `varAssInstr`

Dependency

- The creation of a `StaticVariableDeclaration` DNode for `Variable`-declarations that happen to have assignments will now process such assignments by pooling the expression being assigned (via `expressionPass()` and then make the `VarDecNode` depend on it, therefore removing the intermediary `VariableAssignmentNode` dependency-node

Typechecker/Codegen

- When processing a variable declaration (a `StaticVariableDeclaration` dependency-node) we now pop an instruction which would be directly the `Value`-based instruction that we `need()`'d in the dependency generation (this links up with the changes made to the dependency generation for variable declarations)
2023-02-04 12:41:30 +02:00
Tristan B. Velloza Kildaire 4ed6b2a18b Test case
- Updated test case `simple_literals.t` to to perform a standalone variable assignment
2023-02-03 16:29:50 +02:00
Tristan B. Velloza Kildaire b7b0bb452a Instruction
- Set `context` field to `private` - enforcing usage of `setContext(Context)`/`getContext()`

CastedValueInstruction

- Removed field `castToType`, we may as well use the inherited field `type` for that seeing as the type we shall be after the cast is the `castToType`
- Ensured that the constructor copies over the parameter `castToType` to `this.type`
- Ensured that `getCastToType()` now returns `this.type`

TypeChecker

- Switched to using `setContext(Context)` in cases where `instr.context = <context...>` was being used
2023-02-03 16:13:40 +02:00
Tristan B. Velloza Kildaire ba3f6eee7b Instruction
- Removed unneeded constructor
2023-02-01 17:34:55 +02:00
Tristan B. Velloza Kildaire 9b07884012 Instruction
- Added TODO regarding access modifier of the `context` field
- Added `setContext(Context)` for setting the context of the Instruction object
2023-02-01 17:26:39 +02:00
Tristan B. Velloza Kildaire 085adc3536 LiteralValueFloat
- Overriden `toString()` with new `produceToStrEnclose()`
2023-02-01 17:13:23 +02:00
Tristan B. Velloza Kildaire b7c8724245 Instruction
- Made the `toString()` method non-final
- Implemented `produceToStrEnclose(string)` which will create the wrapper `[Instruction: <classNameHere>: <addInfo>]` where `<addinfo>` is the string parameter passed in

LiteralValue

- Implemented custom `toString()` - this will fix the whole updating opf types issue
2023-02-01 16:48:12 +02:00
Tristan B. Velloza Kildaire aee83ccfdd TypeChecker
- Removed all typequeue-related methods
- Removed any remaining calls to the typequeue methods (basically only `printTypeQueue()`)
2023-02-01 15:05:31 +02:00
Tristan B. Velloza Kildaire 008af76e8b TypeChecker
- Removed most commented-out blocks of code referring to the now-defunct "typequeue" methods
2023-02-01 15:03:29 +02:00
Tristan B. Velloza Kildaire eddd17775d VariableAssignmentInstr
- Removed now-completed TODO

Value

- Made the `type` field private and added a comment explaining it
- Implemented `setInstrType(Type)` and `Type getInstrType()`

TypeChecker

- Switched to using `getInstrType()` and `setInstrType()`

DGen

TypeChecker

- Switched to using `getInstrType()`
2023-02-01 14:55:23 +02:00
Tristan B. Velloza Kildaire d97d1c9ce2 TypeChecker
- Disabled all calls to `popType()`, `addType()`, etc.
- Disabled `StringExpression` processing for now
- Binary operator type selection is now done through the if-statement
- Removed purposeful assertion for handling `VariableAssignmentStdAlone` (for now)
2023-02-01 14:45:55 +02:00
Tristan B. Velloza Kildaire 13b42d06b7 TypeChecker
- Use the `type` field found in all `Value`-instructions in order to determine and set the types
2023-02-01 14:32:29 +02:00
Tristan B. Velloza Kildaire a802ea3500 .gitignore
- Ensure that any `.o` files such as that produced from `extern_test.sh` are not candidate for git adding
2023-01-31 13:38:20 +02:00
Tristan B. Velloza Kildaire e80650a561 Test cases
- Added `simple_literals.t` test case to test coercion
2023-01-30 19:09:03 +02:00
Tristan B. Velloza Kildaire 1ea77c3fb0 DGen
- Added a note to fix the way we do standalone variable assignments, we should embed them in a way similiar to that of `VariableDeclaration`'s (with assignments enabled)

TypeChecker/Codegen

- Initial work on handling `IntegerLiteral` parser node types added

VariableAssignmentNode

- Push the type onto the typestack and make it the type fo what was popped (relates to the embedded instruction)

StaticVariableDeclaration

- Initial work on type coercion begun

VariableAssignmentStdAlone

- Make handling of this fail now till we do the dependency node fix up for this

DGen

- Added debug prints which until they stop segfaulting we will know if everything is okay
2023-01-30 19:08:48 +02:00
Tristan B. Velloza Kildaire ecbaa5d4de Expressions
- Added a second parameter to the constructor for `IntegerLiteral`, this takes in the encoding of type `IntegerLiteralEncoding`

Parser

- Updated the `SymbolType.NUMBER_LITERAL` handling code to handle the new constructor for `IntegerLiteral`
2023-01-30 19:05:31 +02:00
Tristan B. Velloza Kildaire be3b2085ad Instructions
- All `Value` instructions are to have a `Type` field named `type`
- Removed the `len` field in `LiteralValue`
- Replaced the `data` field of typr `ulong` with a `data` field of type `string` in `LiteralValue`
- Replaced the `data` field of typr `ulong` with a `data` field of type `string` in `LiteralValueFloat`
2023-01-30 19:03:48 +02:00
Tristan B. Velloza Kildaire 96f8230bd1 Expressions
- Split `NumberLiteral` into an abstract class with two sub-classes for `IntegerLiteral` and `FloatingLiteral` (floating-point literals)

Parser

- Use new `IntegerLiteral` and `FloatingLiteral` based on the type of token (whether a `.` is present or not)

TypeChecker/Codegen

- Updated code to check for `NumberLiteral` sub-type

Test cases

- Added `simple_literals.t` for testing `literal_encodings` branch
2023-01-29 14:13:04 +02:00
Tristan B. Velloza Kildaire a1c023ecc3 Parser
- Removed TODO
2023-01-29 13:38:15 +02:00
Tristan B. Velloza Kildaire d26435b529 Expressions
- Added enum type `NumberLiteralEncoding` mimicking that of D's integer literals encoding variations
- Added an instance of `NumberLiteralEncoding` to `NumberLiteral` along with a `getEncoding()` method to fetch said field

Parser

- Added TODO
2023-01-29 13:36:48 +02:00
Tristan B. Velloza Kildaire 9d33b05817 Fixed failing unittest compilation mode due to missing imports 2023-01-28 21:04:42 +02:00
Tristan B. Velloza Kildaire 712f049306 Token
- Moved to own module

Exceptions (Lexer)

- Moved to own module

Misc

- Fixed up imports for new `tokens` and `exceptions` (lexer) modules
2023-01-28 21:01:34 +02:00
Tristan B. Velloza Kildaire 73c70fbb71 Lexer
- Corrected module filename for `compiler.lexer.core` from `lexer.d` to `core.d`
2023-01-28 20:30:54 +02:00
Tristan B. Velloza Kildaire 2707b012e9 Configuration
- Removed TODO comments
- Made `CompilerConfiguration` class final
2023-01-28 20:09:19 +02:00
Tristan B. Velloza Kildaire d548a066a6 Check
- Corrected import path for `compiler.lexer` -> `compiler.lexer.core`

Parser

- Corrected import path for `compiler.lexer` -> `compiler.lexer.core`

TypeChecker

- Corrected import path for `compiler.lexer` -> `compiler.lexer.core`

Compiler

- Moved configuration code outside of it
- Renamed to `compiler.core`

DGen

- Check for any object files to link in, if so append them to the `cc` call

Lexer

- Moved from `compiler.lexer` to `compiler.lexer.core`

Configuration

- Overhauled configuration system

Mapper

- Added definition to `SymbolMappingTechnique`

Command-line

- Migrated to new configuration system
- Migrated `SymbolMappingTechnique` to Mapper module
- Added support for specifying object fils to link in using the `-ll` flag`

Tests

- Added `file_io.c` for testing `simple_extern.t` with `extern_test.sh`
- Added `extern_test.sh` for testing `simple_extern.t`
2023-01-28 18:12:49 +02:00
Tristan B. Velloza Kildaire a5d1617d15 Commands
- Upgraded to jcli 0.25.1-beta
- Added aggregate command-line arguments `library-link` to support future library linking
- Added stub mixin template `TypeCheckerBase`
- Made verbosity an optional flag
2023-01-26 16:32:55 +02:00
Tristan B. Velloza Kildaire 3f84020e22 DGen
- Compiler flag name change
- Comment formatting

Compiler

- Implemented `getConfig()` in order to return the `Compiler` object's `CompilerConfiguration` instance
- Updated a configuration parameters name in the `defaultConfig()`
- Added some work-in-progress data structures `ConfigObject` and `ConfigList`

Command-line

- Added a plethorah of new flags and re-worked a lot of the common flags across the multiple commands to use mixins to avoid code duplication and enforce code re-use
- The compilation command now uses the `Compiler` object
- You can now control the symbol mapper used
- You can now set the verbosity level (no-oped currently)
- You can set the output filename
- You can set whether pretty code is to be used or not
- You can set whether or not to generate the entrypoint testing code during emit
2023-01-24 19:57:27 +02:00
Tristan B. Velloza Kildaire 1f6e9cbbb6 Compiler
- Use `hasConfig(string)` instead of `canFind(string[], string)`
2023-01-23 23:56:48 +02:00
Tristan B. Velloza Kildaire d30ffb7684 Command-line
- All compilation stages now make use of the `Compiler` object

Compiler

- Added new exception type `CompilerException` complete with a sub-type enum, `CompilerError`
- `getConfig()` will now throw a `CompilerException` when a key is not found, rather than return false (which didn't work under different template types anyways)
- Implemented `hasConfig()` to check for the existence of a key in the configuration sub-system's key-value store
- The `Compiler` object now stores the `Token[] tokens` generated from the call to `doLex()`
- The `Compiler` object now stores the resulting container (`Module`) generated from the call to `doParse()`
- Set default symbol mapping technique to the hashmapper technique
- Implemented `dolex()` for performing tokenization, it will create and store a `Lexer` instance and the produced `Token[] tokens` into the `Compiler` object
- Added `getTokens()` to fetch the tokens generated by `doLex()`
- Implemented `doParse()`, `doTypeCheck()` and `doEmit()` in a similiar fashion to `doLex()`
- Implemented `getMdoule()` to get the container (`Module`) generated by `doParse()`
- Implemented `compile()` which calls `doLex()`, then `doParse()`, then `doTypeCheck()` and finally `doEmit()`

CodeEmitter

- The `CodeEmitter` constructor now takes in an instance of the chosen `SymbolMapper`

DGen

- Switched to the instance of the `mapper` inheited from the `CodeMapper` parent class for any `symbolMap` calls required
- Use the inherited `TypeChecker` instance and not an instance of it provided by `Context`

SymbolMapper

- Reworked this class into an abstract class which must have its children implement a `symbolMap(Entity)` interface, this provides us pluggable mapping techniques

HashMapper

- Moved hashing symbol-mapping technique into `HashMapper`

Lebanese

- Created a kind-of `SymbolMapper` which, unlike `HashMapper`, produces human-redable-yet-valid C symbols (by replacing the `.`'s with `_`'s)

TypeChecker

- Removed code for setting now-nonexistent `SymbolMapper.tc`
- Removed code for setting now-nonexistent `Context.tc`

Context

- Removed `static TypeChecker tc` field
2023-01-23 20:44:35 +02:00
Tristan B. Velloza Kildaire a8a88c86e1 Command-line
- Cleaned up comments that are now complete
2023-01-22 15:13:11 +02:00
Tristan B. Velloza Kildaire e1e554d6ba Command-line
- Added missing exception catch
2023-01-22 15:05:54 +02:00
Tristan B. Velloza Kildaire 078a971a67 Lexer
- When throwing an exception when lexing include the current position and column
2023-01-22 15:04:32 +02:00
Tristan B. Velloza Kildaire d716c306a2 Lexer
- Fully integrated new `LexerException` system into `performLex()`

COmmand-line

- Updated `commands.d` to catch any `TError` and report the error back

Parser

- Updated unittests to use `LexerException`

Compiler

- Disabled unit tests for now as they cause errors
2023-01-22 14:59:55 +02:00