Commit Graph

833 Commits

Author SHA1 Message Date
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
Tristan B. Velloza Kildaire 9e79bc6f8b Parser
- Added comments and removed TODO for now complete feature on `parseTypedDeclaration()`

Dependency

- Added support for external variable symbols to `transform()` for declarations, assignments and variable expressions

Test cases

- Updated extern evar test case to new symbol name that wouldn't clash
- Added assignment usage and expression usage
2023-01-19 09:03:19 +02:00
Tristan B. Velloza Kildaire cb42713377 Merge branch 'parsetypedev_fix' into extern_symbols 2023-01-19 08:47:31 +02:00
Tristan B. Velloza Kildaire 75e2fc2e68 Parser
- `parseTypedDeclaration()`  will no longer consume the SEMICOLON after a vardec
- `parseTypedDeclaration()` will no longer consume theSEMICOLON after an assignment
- `parseName()` will expect a semicolon if the returned object from `parseTypedDeclaration()` is of type `Variable`. If of type `Function` then nothing will be expected
2023-01-19 08:45:06 +02:00
Tristan B. Velloza Kildaire d288440e18 Parser
- Added `allowVarDec` and `allwFuncDef` to `parseTypedDeclaration()` as default arguments with `true` as their default values
- If `allowFuncDef` is true then parse a function
- If `allowVarDec` is `true` then allow a variable definition
- If `allowVarDec` is true but we have an assignment and `wantsBody` is false then throw an error
- NOTE: A fix for `parseTypedDeclaration()` is needed for this to work

Tests

- Updated `simple_extern.t` to include an `extern evar`
2023-01-19 08:08:41 +02:00
Tristan B. Velloza Kildaire a7bfed12fb Compiler
- Added parameter configuration management interface for the `Compiler` object
- Added `defaultConfig()` for setting the default config
2023-01-17 19:43:37 +02:00
Tristan B. Velloza Kildaire 37debd8160 Compiler
- Added some comments and now use the provided `outFile` for code emitting stage in `Compiler` class
2023-01-16 12:07:11 +02:00
Tristan B. Velloza Kildaire 167e946b34 Compiler
- Implemented type `Compiler` which wraps compilation all into one object which can have `compile()` called on it to perform the full sequence of tests
2023-01-16 11:56:54 +02:00
Tristan B. Velloza Kildaire aa11af5bba - Removed added debug prints which were not needed actually 2023-01-15 20:58:47 +02:00
Tristan B. Velloza Kildaire 2abb28bcaf Check
- Added new symbol types `EXTERN`, `EXTERN_EFUNC` and `EXTERN_EVAR` and related back-mappings

Parser

- `parseFuncDef()` now accepts a default argument (set to `true`) on whether to expect a body for a function or not, in the not case expect a semi-colon - this helps with extern support
- Likewise because `parseFuncDef(bool wantsBody = true)` is called by `parseTypedDeclaration()` we have added same argument to `parseTypedDeclaration(bool wantsBody = true)`
- Ensure we pass the parameter from `parseTypedDeclaration()` into `parseFuncDef(bool)` in function definition case
- Implemented `parseExtern()` for extern support
- `parse()` supports `SymbolType.EXTERN` now

Data

- Added `ExternStmt` to represent the parser node derived from a call to `parseExtern()`
- The `Entity` parser node type now has an `isExternal()` flag to know if the entity is marked for `extern` link time or TLang internal time (default)

Typechecker

- Implemented `processPseudoEntities(Container)` which loops through the given container and finds all extern statements and then extracts those nodes, parents them to the given container and marks them as external (pseudo-handling support)
- Added first call inside `beginCheck()` to be a call to `processPseudoEntities(modulle)`

Dependency

- Added useless no-op check for `ExternStmt` - it does nothing

DGen

- In `emitFunctionSignature()`, prepend the string `extern ` to the signatur if the given `Function` entity is marked as external (`isExternal()` is true)
- In `emitFunctionDefinitions()` do not emit a function body at all (or anything, no signature) if the `Function` is marked as external (`isExternal()` is true)
- Added entry point test for `simple_extern.t`
2023-01-15 20:48:40 +02:00
Tristan B. Velloza Kildaire d3e15e7a2f Merge branch 'pointers' into vardec_varass_dependency 2023-01-15 12:59:41 +02:00
Tristan B. Velloza Kildaire bbb9aaaa51 Typing
- Added `getReferType()` to `Pointer` type to refer the `Type` instance of the data being pointed to

DGen

- Fixed bug whereby pointer types were not being transformed correctly in typeTransform()`
2023-01-15 12:49:28 +02:00
Tristan B. Velloza Kildaire 7f8973a4aa DGen
- VariableParameter's now have their `Type` object extracted and type transformed as part of function definitions.

Tests cases

- Updated `simple_cast.t` to test new typeTransform() usage on VariableParameter (as stated above)
2023-01-15 12:40:42 +02:00
Tristan B. Velloza Kildaire b1d168ab44 Typechecker
- Extract the `Variable`'s `Type` object and pass it into the instruction constructor

Instruction

- `VariableDeclaration` instruction now takes in an instance of `Type` upon construction

Dependency

- Fixed null pointer exception where Function did not have its `context` set

DGen

- Added `typeTransform(Type)` to transform the given types into the C equivalent
- Variable declarations use `typeTransform()` now
- Casting instructions use `typeTransform()` now
- Added `emitStdint()` to emit `#include<stdint.h>` as part of header in generated C code
- `generateSignature(Function)` now uses `typeTransform()` for the return type emit
2023-01-15 12:36:54 +02:00
Tristan B. Velloza Kildaire b7b30db391 - Updated test case 2023-01-14 18:45:47 +02:00
Tristan B. Velloza Kildaire 113386ebe2 Instruction
- Implemented new instruction `CastedValueInstruction`
- Added import for `Type`

DGen

- Implemented primitive type casting code generation in `transform()`
- Added import for `Type` and `Primitive`

Parser

- Implemented `parseCast()` which is called by `parseExpression()`

Check

- Added new symbol type `SymbolType.CAST`

Expressions

- Implemented new expression type `CastedExpression`

Typechecker

- Implemented processing of `CastedExpression` in the expression section, along with correct type/instruction pushes and pops

Dependency

- Implemented dependency generation of `CastedExpression` in `expressionPass()`

Test cases

- Added test file `simple_cast.t`
2023-01-14 18:40:08 +02:00
Tristan B. Velloza Kildaire 2c91213249 - Cleaned up test case whitespace 2023-01-14 12:43:21 +02:00
Tristan B. Velloza Kildaire 6b3fccfc15 Types
- Added `getReferredType()` to `Pointer` to fetch the type of the data being referred to

Typechecker

- Unary operator `STAR` now will check popped type, ensure it is a pointer, then push the type of the referred-to data

Test cases

- Updated the `simple_pointer.t` test case to do pointer dereferencing

DGen

- Updated entry point testing code for the pointer test `simple_pointer.t`
2023-01-14 12:39:37 +02:00