Commit Graph

99 Commits

Author SHA1 Message Date
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 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 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 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 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 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 0d877f81a4 - Added a few more backmappings 2023-01-11 11:56:12 +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
Tristan B. Velloza Kildaire 4f899c69e2 Lexer
- Fixed missing flushing for issue #65 (see "Flushing fix ")
- Added unit test for flushing fix

VariableDeclaration (Instruction)

- Added support for the embedding of a VariableAssignmentInstr inside (added a getter too) (a part of issue #66)
- Conditional support for if statements: Added two new instructions (IfStatementInstruction and BranchInstruction). See issue #64

DGen

- Added depth increment/decrement on enter/leave scope of `transform()`
- Correct tabbing for nested if-statements using new method `genTabs(ulong)` (which uses the above mechanism). Makes code emitted for if statements (issue #64) look nicer.
- Updated VariableDeclarations (with assignments) handling in `transform()` in the manner similar to BinOpInstr (see issue #66)
- Added a TODO for formatting BinOpInstr's `transform()` a little more aesthetically nicer
- Added code emitting support for if statements (the `IfStatementInstruction` instruction) (see issue #64)
- Updated `emitEntryPoint()` to only emit testing C code for the correct input test file

Parser

- `parseIf()` now returns an instance of IfStatement which couples multiple `Branch` objects consisting of `Statement[]` and `Expression`
- Ensured that each `Statement` of the generated `Statement[]` from `parseBody()` for a given `Branch` is parented to said Branch using `parentToContainer()`
- Ensured each generated `Branch` in `Branch[]` is parented to the generated `IfStatement` using `parentToContainer()`
- `parseBody()` now adds to its `Statement[]` build-up array the generated `IfStatement` from the call to `parseIf()`

Check

- Added support for back-mapping `SymbolType.EQUALS` to `getCharacter(SymbolType)`

Data

- Added `Branch` parser node which is a Container for body statements (`Statement[]`)
- Added `IfStatement` parser node which is a Container of `Statement[]` which are actually `Branch[]`

TypeChecker

- Moved import for `reverse` to top of module
- Implemented `tailPopInstr()` method which will pop from the back of the `codeQueue` "scratchpad"
- Fixes handling of `StaticVariableDeclaration` and `VariableAssignmentNode` (fixes issue #66)
- Added handling for IfStatement entities (if statement support #64)

Resolution

- Added a debug statement to `resolveUp(Container, string)` to print out the container to lookup from and the name being looked up

Dependency

- Added a default `toString()` to the DNode class which prints `[DNode: <entity toString()]`
- Added a TODO and debug print related to issues #9
- Disabled InitScope.STATIC check for now as it caused issues with if statement parsing (probably due to VIRTUAL being default and therefore skipping if statment processing) - issue #69
- Cleaned up handling of Entity type `Variable` (variable declarations) - removed repeated code
- Undid the VarAss->(depends on)->VarDec, reverted back to VarDec->(depends on)->VarAss, fixed by #66 (and closes it and #11)
- Added support for `IfStatement` (if statements) in `generalPass(Container, Context)`

Test cases

- Added new test case testing nested if statements (`nested_conditions.t`)
- Added another test case for if statements, `simple_conditions.t`
2022-12-19 15:37:55 +02:00
Tristan B. Velloza Kildaire beb068a33c Check
- Added `SymbolType.EQUALS`
- Added check for equality operator
2022-12-17 20:46:05 +02:00
Tristan B. Velloza Kildaire d1b3319a74 Instruction
- Added new instruction type `ReturnInstruction`

Data

- Adjusted return statement parser node weighting to 2 (makes it on the same level as normal body statements)

Dependency

- Added dependency generation for return statements
- Removed old commented-out code in the function-definition generation section of `generalPass()`

TypeChecker/Codegen

- Added code generation for return statements

DGen

- Added code emitting for return statements (`ReturnInstruction`)

Test cases

- Updated test case `simple_functions.t` to test return statements
2022-12-17 19:02:14 +02:00
Tristan B. Velloza Kildaire f8a6fb0962 Merging of function_parameter_fix into vardec_varass codebase
DGen

- Updated function parameter symbol lookup to use new `symbolLookup9Entity)` mechanism

Test cases

- Updated test case `simple_function_decls.t` to use arguments referencing for tests
2022-12-17 14:00:16 +02:00
Tristan B. Velloza Kildaire 8a481fb0ac App
- Added newline to release info print
- Fixed module docstring

Commands

- Added new command-line options: `syntaxcheck`, `typecheck`
- Added todo to `help` command
- Re-ordered commands for order of appearance in help text

Compiler

- Added docstring to `beginCompilation(string[])` function

Mapper

- Added debug print of the Container being used for the symbol lookup

CodeEmitter

- Re-worked CodeEmitter class to use a single so-called "selected queue"
- Added methods to move back and forth between said "selected queue", get the length, etc.
- Remove old queue-specific methods

DGen

- Use the new CodeEmitter "selected-queue" functionality
- Emit function definitions now supported

Exceptions

- Added this keyword

Check

- Added support for SymbolTYpe.OCURLY and SymbolType.CCURLY to `getCharacter(SymbolType)`

Data

- Added a `hasParams()` method to the Function entity type

TypeChecker

- Added support for emitting function definitions (required DNode.poes = [] (cleaning), codeQueue cleaning etc.)
- Added `getInitQueue()` method to make a copy of the current "scratchpad" `codeQueue`
- Build up a copy of the global queue now (make a copy similiar to what we did for `getInitQueue()` but inline)
- Added a debug print

Dependency

- Added a FIXME note for issue #46
- Added a TODO relating to `static DNode[] poes`

Test cases

- Added test case `simple_function_decls.t` to test function definition code emit
- Updated test case `simple_variables.t` to note that the T code generates invalid C code

README

- Build instructions now generate coverage files (`.lst`s)
- Updated link to documentation
2022-12-14 19:49:08 +02:00
Tristan B. Velloza Kildaire f17d38b74e Parser
- Added support for return statements
- Fixed up SyntaxError to display informative messages
- `expect(SymbolType, Token)` will now use the new SyntaxError constructor

Data

- Added `ReturnStmt` type for return statement support
2022-12-13 14:17:40 +02:00
Tristan B. Velloza Kildaire 8978a74a21 Check
- Updated SymbolType mappings

----

Test cases

- Updated test case to test the above (`simple_variables.t`)
2022-12-13 11:41:25 +02:00
Tristan B. Velloza Kildaire 50728d02d3 Dependency
- VariableAssignment entity now has its Context object set to the current Context (of the Variable being declared) (so this is a declare assignment case only (so far)) (fixes #36)

TypeChecker

- Extract the Context object from the VariableAssignment entity and then set it as the Context for the VariableAssigmnetInstr instruction (fixes #36)

VariableAssigmnentInstr

- The `emit()` method will now emit the assignment code

Check

- Added `getCharacter(SymbolType)` which maps a SymbolType to a maths operator (WIP)
2022-12-12 13:12:03 +02:00
Tristan B. Velloza Kildaire 60a6f078a3 - Made Function a kind-of Container
- Ensure we set the parentOf all Statement's inside a Function (definition) whilst parsing - to prevent a runtime assertion (I believe, well all fixed now)
2022-10-01 20:54:50 +02:00
Tristan B. Velloza Kildaire 5444bd55e8 Added support for comparators to parser 2022-10-01 16:08:21 +02:00
Tristan B. Velloza Kildaire c561060470 Added float and double types to builtin types
Added floating point test case
2022-07-26 10:27:55 +02:00
Tristan B. Velloza Kildaire e8ddb62152 Removed Double type
Refactored Float type
2022-07-26 10:27:12 +02:00
Tristan B. Velloza Kildaire 4488678d3e Code cleanup 2022-07-26 10:10:43 +02:00
Tristan B. Velloza Kildaire e2157f428c Implemented `getStringLiteral()` for StringExpression symbol type 2022-07-26 09:58:45 +02:00
Tristan B. Velloza Kildaire f9a8590604 Array type handling added to builtin-types handling 2022-07-26 09:57:57 +02:00
Tristan B. Velloza Kildaire ca2fa84057 Added support for Pointer type resolution via `getType()`. Now `char**` -> Pointer("char*"), which before construction of such a Pointer is recursively resolved, so nested Pointer(Pointer(...)) 2022-07-25 19:15:27 +02:00
Tristan B. Velloza Kildaire 1322c0f790 BinaryOperatorExpression now has a proper toString() 2022-04-13 09:49:42 +02:00
Tristan B. Velloza Kildaire 1f8f248219 Added support for the ampersand operator 2022-04-13 09:49:20 +02:00
Tristan B. Velloza Kildaire e9a60380b6 Pointer type now only requires you provide it the data type of the data being pointed to.
The name of the type will be automatically constructed as `dataType*` (if `dataType` was the type of the data being pointed to)
2022-04-13 09:35:46 +02:00
Tristan B. Velloza Kildaire ef9018db89 Added UnaryOperatorExpression (finished it) 2022-04-12 10:53:17 +02:00
Tristan B. Velloza Kildaire c28a297064 Added toString() to FunctionCall that includes uniqueness number AND funciton's name 2022-04-08 01:08:57 +02:00
Tristan B. Velloza Kildaire a84e0dfe20 Some stuff, working on getting function calls working 2022-02-18 14:32:45 +02:00
Tristan B. Velloza Kildaire 71efb7ae8f Fixed dependency generation for function call paremeters (expressions) 2022-02-16 07:31:22 +02:00
Tristan B. Velloza Kildaire 60f490d8e8 Refactored dependency tree generation code (and all related modules) to its own directory 2021-11-09 19:16:51 +02:00
Tristan B. Velloza Kildaire fffcc953ab Refactored Context class 2021-11-09 19:00:23 +02:00
Tristan B. Velloza Kildaire c9997c60d0 Made public 2021-11-09 18:26:39 +02:00
Tristan B. Velloza Kildaire beaad7e7f1 Added the thing 2021-11-09 18:26:30 +02:00
Tristan B. Velloza Kildaire 6499abb616 Fixed up all other `getStatements()` for other Container types 2021-11-09 16:54:00 +02:00
Tristan B. Velloza Kildaire b39fea5e10 Fixed `getStatements()` for Module container type to be stable. Not having it so caused bad affects and re-ordering that should have NOT happened 2021-11-09 16:50:04 +02:00
Tristan B. Velloza Kildaire 3d79531978 Removed emitter code from data.d 2021-11-02 10:38:09 +02:00
Tristan B. Velloza Kildaire cf03601eec Removed unused field 2021-11-01 18:28:19 +02:00
Tristan B. Velloza Kildaire 8fed8fa4fb Removed unused methods for Statement 2021-11-01 18:25:53 +02:00
Tristan B. Velloza Kildaire bbf174b757 Added weighting such that `getStatements()` can be ordered more easily. Many weights are still missing but the things I am testing with now are atleast here.
Added check for standalone variable assignments to error (crash) the compiler when the variable has not yet been declared.

I still need to clean up the codegen and add back in typechecking, the thing has become weird with many weird function calls, but I can do it in one function call to be honest (and that makes most sense)

Standalone variable assignments are now in the dependency tree and therefore make it into the typechecking/codegen phase (of which code to handle them has also been added)
2021-10-27 20:57:30 +02:00
Tristan B. Velloza Kildaire 47375cbec4 Beginning to work on weighting system 2021-10-27 15:52:43 +02:00
Tristan B. Velloza Kildaire 0bceb16373 Added toString for VariableAssignment 2021-10-27 15:33:24 +02:00
Tristan B. Velloza Kildaire 975acc05a2 Added the following new SymbolTypes
SymbolType.ADD, SymbolType.MINUS, SymbolType.DIVIDE, SymbolType.STAR
2021-10-26 21:35:39 +02:00
Tristan B. Velloza Kildaire 129860fc37 WIP 2021-10-26 17:17:53 +02:00
Tristan B. Velloza Kildaire b9adbc6663 Yo, so I think I got this down 2021-10-25 22:31:07 +02:00
Tristan B. Velloza Kildaire 8bf3270de7 NumberLiteral now has its own custom toString 2021-10-25 20:49:58 +02:00