Commit Graph

850 Commits

Author SHA1 Message Date
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
Tristan B. Velloza Kildaire 5fd1bef2a4 Lexer
- Added new exception type `LexerException`
- Added `LexerError` enum to support various error types of the `LexerException` exception type
2023-01-22 14:45:25 +02:00
Tristan B. Velloza Kildaire 31adeb4223 Compiler
- Added back tests as commented-out block
2023-01-20 21:21:12 +02:00
Tristan B. Velloza Kildaire 62ca320c76 Compiler
- Removed unses `Lexer[]` `lexers` array
- Disabled some tests
2023-01-20 21:20:54 +02:00
Tristan B. Velloza Kildaire cd43b41d66 Merge branch 'vardec_varass_dependency' into compiler_object 2023-01-20 20:16:52 +02:00
Tristan B. Velloza Kildaire 57ebd443b0 Dependency
- Now throws a `DependencyException` on erronenous calls
- Added `DependencyException` exception class and `DependencyError` enum
2023-01-20 19:19:35 +02:00
Tristan B. Velloza Kildaire 68e1a25c9a Dependency
- Actually removed `static DNode[] poes`
- Actually added some todos

TypeChecker

- Actually removed any references to `DNode.poes`
2023-01-20 16:49:41 +02:00
Tristan B. Velloza Kildaire 2ee2bc22a4 Dependency
- `getLinearizedNodes()` returns the `DNode[]` of the linearization results
` `getTree()` returns the string representation of the dependency tree
- New linearization method which requires calling `performLinearization()` before `getLinearizedNodes()` or `getTree()`, if not then an exception is thrown
- Made `tree()` private
- `tree()` now takes in argument `ref DNode[]` of which it will read the linerization into instead of `static DNode[] poes`
- Added comment regarding Problem 5 of issue #41
- Removed `static DNode[] poes`

TypeCheck

- Added better comments
- Switched to new linearization methods for both module-level processing and function definition (`FuncData`) processing
- Removed any reference to `DNode.poes`
2023-01-20 16:43:04 +02:00
Tristan B. Velloza Kildaire 44f8392450 - Ren-enabled tests for multiple files 2023-01-20 15:13:21 +02:00
Tristan B. Velloza Kildaire 8edc03e3f3 Merge branch 'extern_symbols' into vardec_varass_dependency 2023-01-20 14:52:14 +02:00
Tristan B. Velloza Kildaire a987f114ac Compiler
- Moved configuration sub-system to its own class `CompilerConfiguration`
- `getConfig()` and `setConfig()` are now templatised to generate, at compile-time, type-specific versions which will fetch and convert using the requested type
- Added some more default configuration parameters for DGen

DGen

- Implemented configuration checking for `genTabs()` and `emitEntryPoint()` (both which have the default config value of `true`)
- Added commented-out testing code (see issue #88)
2023-01-19 21:06:20 +02:00
Tristan B. Velloza Kildaire a772b55966 Compiler
- Added missing `typeChecker.beginCheck()` call to the TypChecker in `compile()`
- Print error on lexing error
- Removed old compilation code and replaced with an instantiation of a `Compiler` object and a corresponding call to `.compile()`
2023-01-19 18:10:39 +02:00
Tristan B. Velloza Kildaire b986a2b193 - Added `texterned.c` for later extern testing 2023-01-19 17:52:46 +02:00