Commit Graph

1012 Commits

Author SHA1 Message Date
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
Tristan B. Velloza Kildaire c1ba609609 Resolution
- Fixed indentation
2023-01-13 11:35:25 +02:00
Tristan B. Velloza Kildaire 7a12c25f74 DGen
- We now emit function prototypes
2023-01-13 11:22:47 +02:00
Tristan B. Velloza Kildaire 2072c23fb9 Typecheck
- Disabled unit test (for now) as it uses module-level `discard` statements
2023-01-13 11:13:14 +02:00
Tristan B. Velloza Kildaire a4b9e7b393 Parser
- Don't allow `discard` statements at the module-level
2023-01-13 10:54:05 +02:00
Tristan B. Velloza Kildaire 6333fdcd42 Instruction
- Added new instruction `DiscardInstruction`

DGen

- Added ability to transform `DiscardInstruction`

Parser

- Implemented `parseDiscard()`
- Removed a TODO
- Added a unittest testing the new `parseDiscard()`
- Typo fixes here and there in unittests

Data

- Added new parser node `DiscardStatement`

Typechecker

- Added codegen for `DiscardStatement` type

Dependency

- Added dependency processing for `DiscardStatement` type

Tests

- Added new test case `simple_discard.t`
2023-01-13 10:49:47 +02:00
Tristan B. Velloza Kildaire 1dd70911d0 Typecheck
- Marked code as dead
2023-01-12 23:34:24 +02:00
Tristan B. Velloza Kildaire 0480cecef6 Typecheck
- Cleaned up old comments and fixed some to be more precise
- Removed some debug prints
2023-01-12 13:31:42 +02:00
Tristan B. Velloza Kildaire 934bbb3b30 - Removed old unused code
- Moved exceptions class for typechecker from `old/` to `typecheck/`
2023-01-12 13:30:53 +02:00
Tristan B. Velloza Kildaire 7224829fcb Parser
- Added support for n-ary pointer types in function parameters
- Added a test case for the above
- Updated current pointer test to test function type n-ary as well (return type)
2023-01-12 11:17:32 +02:00
Tristan B. Velloza Kildaire 5827f16e2a Instruction
- Added `getOperator()` and `getOperand()` methods to `UnaryOpInstr`
- Added new instruction `PointerDereferenceAssignmentInstruction` for pointer support

DGen

- Updated `transform()` to emit code for instruction type `UnaryOpInstr`
- Updated `transform()` to emit code for instruction type `PointerDereferenceAssignmentInstruction`
- Added testing emit code in `emitEntryPoint()` for pointer testing

Parser

- Updated `parseName()` to trigger `parseTypedDeclaration()` on occurene of `SymbolType.STAR` (for pointer type declarations)
- Added pointer-type support for function parameters (so far only single) in `parseFuncDef()`
- `parseExpression()` terminates on occurence of a single `=` (ASSIGN) operator
- Declaring of pointers of any depth implemented in `parseTypedDeclaration()`
- Added support for pointer dereferncing assignments with the addition of `parseDerefAssignment()`
- `parseStatement()` will now call `parseDerefAssignment()` on occurence of a `SymbolType.STAR`
- Added a unittest for testing pointers
- Finished unittest for for loops

Check

- Added backmapping for `SymbolType.ASSIGN` -> `&`

Data

- Added new parser node type `PointerDereferenceAssignment` for pointer support in the parser

TypeChecker

- Because function parameters are type che cked upon function call I had to add typechecking code for pointer support in the `UnaryOperatorExpression` case
- Added code generation support for `PointerDereferenceAssignment` type

Dependency

- Added support for `PointerDereferenceAssignment` type (pointer support) to `generalStatement()`

Tests

- Added pointer test `simple_pointer.t`
2023-01-12 10:53:48 +02:00
Tristan B. Velloza Kildaire 11b2d1d1ea - Updated `copyright` field in dub.json 2023-01-11 12:08:36 +02:00
Tristan B. Velloza Kildaire 7a0bbe6631 Updated `author` field in dub.json 2023-01-11 12:08:12 +02:00
Tristan B. Velloza Kildaire c78031a2e7 Merge branch 'loops' into vardec_varass_dependency 2023-01-11 12:05:12 +02:00
Tristan B. Velloza Kildaire 0d877f81a4 - Added a few more backmappings 2023-01-11 11:56:12 +02:00
Tristan B. Velloza Kildaire d7037136dc Merge branch 'loops' into vardec_varass_dependency 2023-01-11 11:35:20 +02:00
Tristan B. Velloza Kildaire c51712e275 - Added for future use 2023-01-11 11:34:55 +02:00
Tristan B. Velloza Kildaire edc81ee651 Merge branch 'loops' into vardec_varass_dependency 2023-01-11 11:33:37 +02:00
Tristan B. Velloza Kildaire 5722fe0825 - Removed now undeeded debug 2023-01-11 11:24:17 +02:00
Tristan B. Velloza Kildaire eabc300fd3 - Fixed bug in `parseBody()` which was caused by dead code (this has been removed)
- Removed testing code for `parseBody()`
- Removed unused `continue` (related to above)
2023-01-11 11:23:38 +02:00
Tristan B. Velloza Kildaire ec7d8cf424 Instruction
- Added a new instruction, `ForLoop`, which contains a pre-run Instruction and a `Branch` instruction, coupled with some flags

DGen

- Added a TODO for WhileLoops (we need to implement do-while loops)
- Implemented C code emitting in `emit()` for `ForLoop` instruction

Check

- Added missing back-mapping for `SymbolType.SMALLER_THAN`

Data

- Added new parser node type `ForLoop`

Parser

- Fixed typo in `parseWhile()`
- Implemented `parseDoWhile()` for do-while loops
- Implemented `parseFor()` for for-loops
- Implemented `parseStatement()` for singular statement parsing
- `parseStatement()` can now have the terminating symbol specified, defaults to `SymbolType.SEMICOLON`
- `parseName()` and `parseAssignment()` now also accept a terminating symbol parameter as per `parseStatement()`'s behavior
- `parseBody()` now makes multiple calls to `parseStatement()` for singular Statement parsing (dead code below still to be removed)
- Removed commented-out unittests
- Unittests that read from files now have the file source code embedded
- Added unit test for while loops, for-loops (unfinished) and some other smaller language constructs (roughly 70% coverage)

TypeChecker (CodeGen)

- Do-while loops will fail if used (for now)
- Added for-loop code generation

Dependency

- Implemented `generalStatement()` for statement processing
- `generalPass()` now makes calls to `generalStatement()`

Tests

- Added `simple_for_loops.t` to test for-loops
- Added `simple_do_while.t` to test do-while loops
2023-01-11 10:43:29 +02:00
Tristan B. Velloza Kildaire 22c4e8d5a1 Instruction
- Added new instruction `WhileLoopInstruction`

DGen

- Added support for emitting while-loops (so far just plain while loops) (`WhileLoopInstruction` in `emit()`)
- Added baked-in entry point testing code for while loops in `emitEntryPoint()`

Parsing

- Added missing plumbing for while loop parser nodes in `parseWhile()`

Data

- Fixed some typos
- Removed dead/unused "deps" code from `Entity`
- Added some documentation comments
- Added `WhileLoop` type for parser nodes

TypeChecker

- Removed TODO in comment for already-implemented/completed if-statements
- Added while-loop code generation support (only while-loops, no do-whiles)

Dependency

- Added while-loop dependency generation support (so far only while-loops, no do-whiles)

Tests

- Added new test case `simple_while.t` for testing while loops
2023-01-04 12:03:50 +02:00