Commit Graph

224 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire 493da1a4e7
Pointer support (#2)
* Make branches not identical

* Removed temporary file

* Typecheck

- Added `attemptPointerAriehmeticCoercion(Value, Value)`

* Typechecker

- Moved `attemptPointerAriehmeticCoercion(Value, Value)` to class-level and made privately accessible

* Test cases

- Added pointer arithmetic in the form of `*(ptr+0)` to `simple_pointer.t` to start testing it out

* Typechecker

- When handling `BinaryOperatorExpression` call `attemptPointerAriehmeticCoercion(Value, Value)` with both `(vLhsInstr, vRhsInstr)` before we call `vLhsInstr.getInstrType()` and `vRhsInstr.getInstrType()` before `isSameType(vLhsType, vRhsType)`. By doing so we attempt to coerce the types of both instructions if one is a pointer and another is an integer, else do nothing

* DGen

- When emitting for `PointerDereferenceAssignmentInstruction` we didn't wrap `<expr>` with `()`. So instead of `*(<expre>)` we got `*<expr>` which doesn't work if you're doing pointer arithmetic

* Test cases

- Added `simple_pointer_cast.t` to test casting (currently broken parsing-wise)

DGen

- Added a todo for semantic tests for the `simple_pointer_cast.t` test case

* Parser

- Added a TODO - we need a `parseType()`

* Test cases

- Removed `simple_cast_complex_type.t` as it is wrong, syntax wise

* Test cases

- Removed coercion usage, I am only testing the casting here (explicit)

* Test cases

- Removed `simple_pointer_cast.t` and replace it with `simple_pointer_cast_le.t` which casts the integer pointer to a byte pointer and sets the lowest significant byte (little endian hence at base of integer) to `2+2`

DGen

- Added semantic test for `simple_pointer_cast_le.t`

* Test cases

- Update `simple_pointer_cast_le.t` to do some pointer airthmetic at the byte-level of the 32-bit integer

DGen

- Updated the semantic test code generation for `simple_pointer_cast_le.t` to check for new values

* Added 'simple_pointer_cast_le.t' to Emit tests

* TypeChecker

- Update `isSameType(Type t1, Type t2)` to now handle pointers explicitly and in a recursive manner based on their referred types
- This check occurs before the `Integer` type check therefore following the rule of most specific types to least

* Test cases

- Added new test case `simple_pointer_malloc.t`
- Added semantic code test generation for `simple_pointer_malloc.t`
- Added `malloc_test.sh` to compile and generate `mem.o` from `mem.c` to link it then with `simple_pointer_malloc.t`
- Added `mem.c`  external C file to generate the required `mem.o` for linking against `simple_pointer_malloc.t`

* Test cases

- Updated `malloc_test.sh` to look for any `brk()` system calls and fixed its interpreter path
2023-04-17 16:50:11 +02:00
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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 2a12c310a6 Instruction
- Make the name of the function const and public for FuncCallInstr

CodeEmitter

- Added methods `getCursor()`, `getSelectedQueueLength()` and `getQueueLength()`
- Removed old queue-specific methods

DGen

- Added emitting for FuncCallInstr instruction (function call support)
- Now emit globals first BEFORE function definitions
- Added debug prints per instruction to know what instruction is currently being transform()'d
- After emitting sections add newlines between each to make for neater C code
- `emitEntryPoint()` now adds a test for `simple_function_decls.t` (This should be removed soon)
- Removed incorrect TODO in `finalize()`

Dependency

- Make the `nodePool` static, to ensure pooling carries over across multiple `DNodeGenerator` instances
- Fixed handling of function calls in `expressionPass()` - do NOT add a so-called `FunctionDefNode` (remember functions are defined by `addFuncDef()`)
- Set the Context of standalone variable assignments to the Context of the Variable entity representing the variable being assigned to

TypeChecker

- Assign the Context object stored in the `FunctionCall` statement to the `FuncCallInstr`

Test cases

- Updated test case `simple_function_decls.t`
2022-12-16 14:53:33 +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 3afdd5b05d TypeChecker
- Copy Context across from the `VariableExpression` to the `FetchValueVar` instruction
2022-12-13 11:50:54 +02:00
Tristan B. Velloza Kildaire 908356c27b VariableAssignmentStdAlone
- Removed duplicate instance of `VariableAssignmentInstr`
- Set the context of the created `VariableAssignmentInstr` to be that of the `VariableAssignmentStdAlone`  entity
2022-12-12 21:10:58 +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 d8e5f108e4 Mapper
- Added new SymbolMapper class with a static method which will take a Container and an entity name, resolve the Entity and then generate the hash of the absolute path to said entity and return this as the `symbol name`

TypeChecker

- Set the static field to refer to this instance of the TypeChecker (in the SymbolMapper class)

VariableDeclaration

- Use the `symbolLookup()` method to transform the name
2022-12-12 10:58:58 +02:00
Tristan B. Velloza Kildaire 57a9e86d5f TypeChecker
- Pass in the type of the variable being declared to the `VariableDeclaration` instruction

VariableDeclaration

- Emitted code now contains the type of the variable being declared
2022-12-11 18:46:05 +02:00
Tristan B. Velloza Kildaire 42fac8020a Context
- Added static field for a TypeChecker instance

TypeChecker

- Set the static field of `Context` class to hold a reference to the TypeChecker instance
2022-12-11 18:18:50 +02:00
Tristan B. Velloza Kildaire 99224cbb80 Type checker
- Added `getInitQueue()`
- Removed the `beginEmit(initQueue, codeQueue)` method (as this is done for us in compiler.d

CodeEmitter

- Extract init queue as well
2022-12-11 17:37:27 +02:00