Commit Graph

89 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire fe8e1403f0
Array support (#1)
* Parser

- Added ability for `parseName()` to recognize array types
- Added array type handling to `parseTypedDeclaration()`
- Removed unneeded `derefCount` and comment in `parseTypedDeclaration()`

Check

- Added new symbol types `OBRACKET` and `CBRACKET`

* Tets cases

- We will now be using `simple_arrays2.t` as our testing bench for array support

* Dependency

- When a variable declaration has a kind-of type we are unaware of then  print out an error message before asserting `false`

* Builtins

- `getBuiltInType(TypeChecker, string)` will now return a `Pointer` object for arrays of which the type was `<componentType>[]` (non-stack bound) as effectively they are pointers with a different syntax -doing it here means that it is transparent and typechecking, code gen and emit will just see a pointer type which makes life a lot easier

* Builtins

- Added information about the current bug faced in issue #81 (third sub-issue)

* Test cases

- Updated test case `simple_arrays2.t` to show case bug sub-issue 3 in issue #81

* Builtins

- Removed seperate handling of `<componentType>[]` and incorporated it into the pointer check, now we have fixed sub-issue 3 of issue #81

Test cases

- Updated test case `simple_arrays2.t` to showcase the aforementioned fix

* Builtins

- Updated TODO

* Builtins

- Removed comment as now fixed

* Array

- Added `getComponentType()` method which will return the array's element type

* Dependency

- When processing the `Array` type which is now to be seen  as a stack-based array (fixed size), error out in processing it during variable declarations

* Builtins

- Added `bool isStackArray(string)` in order to check if a given type string is designated as a stack-array type or not
- `Type getBuiltInType(TypeChecker, string)` now can generate the `StackArray` type including the component type and the size of the stack allocation

Parser

- Added support to`parseTypedDeclaration` to be able to parse stack-based array types
- Added terminator `]` to `parseExpression()`

DGen

- Added stack-based array type transformation support to `string typeTransform(Type)`
- Added transformation support for stack-based arrays for the `VariableDeclaration` instruction

StackArray

- Renamed `Array` type to `StackArray`
` The `StackArray` type now has an `arraySize` field and is included in the constructor's paremeters
- Added a `getAllocatedSize()` method to retrieve the `arraySize` field

Dependency

- Temporarily enabled the `StackArray` type in dependency processing for `VariableDeclarations` such that we can continue through the pipeline

Test cases

- Updated `simple_arrays.t` to test stack-based array types

* Tets cases

- Added new test case for testing (later) multi-dimensional stack-arrays

* Parser

- Working on adding array index assignment support

Test cases

- Added test case to test array assignments with

* Parser

- We can now detect when infact we are doing an array-indexed assignment and when not, we then flip` arrayIndexing` to `true` if that is the case and ensure that `=` SymbolType.ASSIGN is not triggering the varaible-declaration-with-assignment but rather eters a different branch based on this boolean
- Set the identifier being assigned to (in the array indexing case) to the `type` with the `[]...` stripped

Notes

- Added a TODO file `wip.txt` with notes about what is to be done for adding full array support

* Parser

- Handle the case whereby `SymbolType.ASSIGN` or `SymbolType.IDENT_TYPE` is not found by throwing an error

* Parser

- Moved logic for array assignments into the branch for it (deferred it)

* Data

- Added new work-in-progress parser node type `ArrayAssignment`

Parser

- Added TODO about the type of returned parse node needing to be updated down the line

Notes

- Updated `wip.txt` with more thoughts

* Expressions

- Added new parse node (a sub-type of `Expression`) for representing array indexing; `ArrayIndex`

Data

- Fixed compilation error caused by missing semi-colon

* Parser

- Added support for array accesses/indexing in `parseExpression()`
- Added a token-rerun mechanism that lets us replay the needed tokens which needed to be looked ahead in order to determine an array access was about to occur

* Parser

- Removed now-completed TODO relating to array accesses in `parseExpression()`

* Parser

- Added right-hand side expression parsing for array assignments

Test cases

- Updated test case to test both array expressions on the left-hand side of an assignment and as a free-standing expression on the right hand side

Data

- Implemeneted `ArrayAssignment` which is to be used for assigning into arrays

* Instruction

- Added new instruction for indexing into arrays, a new `Value`-type instruction called `ArrayIndexInstruction`

* DGen

- Handle `ArrayIndexInstruction` which is for whenever you index into a point-based array (an expression like `myArray[i]` is now being supported in emit (first steps))

* Instructions

- Added a new instruction type, `StackArrayINdexInstruction`, which is used to know when we are indexing into a stack-based array rather than a pointer-based array (just to be able to disambiguate between the two)
- Added a work-in-progress type `StackArrayIndexAssignmentInstruction` which will be used for assigning to stack arrays at a given index

* Instructions

- Added implementation for `StackArrayIndexAssignmentInstruction` which represents the assignment of some `Value` instruction to a stack-based array (indicated by the `arrayName` string field) at the index indicated by the provided `Value` instruction

* DGen

- Added a stub emitter for `ArrayIndexInstruction` (pointer-based array indexing)
- Added a stub emitter for `StackArrayINdexInstruction` (stack-array based array indexing)

* INstructions

- Added `getArrayName()`, `getIndexInstr()` and `getAssignedValue()` to `StackArrayIndexAssignmentInstruction`

* Instructions

- Added `ArrayIndexAssignmentInstruction` which is intended to be used for when one wants to assign into a pointer-based array
- It embeds a `Value` instruction which is what is to be assigned and then an `ArrayIndexInstruction` representing the base of the poiinter-based array (base address) coupled with an "index" (offset)

- Added a `toString()` override for `StackArrayIndexAssignmentInstruction`

* Test cases

- Added `complex_stack_arrays1.t`
- This tests a stack array of a fixed size of `int[]` (basically `int*`) and assigneing into it

* Test cases

- Added `simple_arrays4.t` which makes an `int[]` (which is an `int*`) and then assignes into it at `i` whilst referring to itself at `i` and doing a binary operation

* Test cases

- Added `simple_stack_arrays2.t` which tests a stack array of a fixed size and then assigns into it a value

* Test cases

- Added `simple_stack_arrays4.t` which just tests assigning to a stack array of a fixed size BUT referring to said stack array itself as part of the assignment expression

* DGen

- Removed TODO comment for `ArrayIndexInstruction` transformation branch
- Added a description for when the `ArrayIndexInstruction` branch is activated for a transformation
- Implemented transformation for `ArrayIndexInstruction`
- Added comment on when `ArrayIndexAssignmentInstruction` activates
- Implemented transformation for `ArrayIndexAssignmentInstruction`
- Added comment for when the `StackArrayIndexInstruction` branch activates
- Implemented transformation for `StackArrayIndexInstruction`
- Added comment for when `StackArrayIndexAssignmentInstruction` branch activates
- Implemented transformation for `StackArrayIndexAssignmentInstruction`

* Dependency

- Added dependency node generation for the `ArrayIndex`
- This will pool the `ArrayIndex` parser-node
- This will then set the context of the parser-node to the current context
- The index expression will be depended upon
- The indexed expression (the entity being indexed) will be depended upon

---

- Added dependency generation for `ArrayAssignment`
- The `ArrayAssignment` parser node will be pooled
- The `ArrayAssignment` will have its context set to the current context
- The assigned expression will be depended upon
- The entity being indexed will be depended upon
- The index expression will be depended upon

* Parser

- Added a branch to `parseName()` which handles array assignments's semicolon consumption and token cursor movement to the next token
- Updated `parseTypedDeclaration()` to return an object of type `Statement` rather than `TypedEntity`
- Disabled the intentional `assert(false)` when handling array assignments
- Assign the generated `ArrayAssignment` to the `generated` variable
- Updated `parseExtern()` to cast to `TypedEntity` to ensure that the `Statement` returned is of that sub-type (added an assertion to then check this fact)

* Typechecker/Codegen

- Implemented `isStackArray(Value)` which checks if the given `Value` instruction is a `FetchValueVar`, then extracts the `Variable` being referred to in said instruction and checks if its declared type is that of `StackArray`
- Implemented code generation for `ArrayAssignment`
- Implemented code generation for `ArrayIndex`

* Test cases

- WIP: Added `simple_stack_array_coerce.t` as we want to add coercion for this now

* Typecheck

- Added rudimentary check for checking if an argument is a stack array, and if the parameter (to a function call) is a pointer and if so then returns whether they have matching component types in a new function named `canCoerceStackArray(Type, Type)`

* Typecheck

- Fixed `canCoerceStackArray(Type, Type)` to actually coerce the first type first into a pointer type (coercing the stack array's component type to `<compType>*`) and THEN apply the `isSameType(Type, Type)` check

* Typecheck

- Hoisted up `canCoerceStackArray(Type, Type)` to the class-level of `TypeChecker`
- Removed debug prints from `canCoerceStackArray(Type, Type)`
- Added a TODO where the check should be done in the `FunctionCall` branch of the `DNode` processor

* TypeChecker

- Added a seperate check for function call `DNode` processing which now checks if we can coerce the stack-array-based argument to the pointer-based type parameter

Notes

- Emit now fails as we haven't implement an emit for this case, so we need to do that.
- Also, should we change the type of what is being passed in - perhaps that actually makes sense here - we haven't fully coerced it actually

* TypeChecker

- Updated `canCoerceStackArray(Type, Type)` to now take in `canCoerceStackArray(Type, Type, ref Type)` to set the newly created coerced type
- Fixed bug whereby if the coercion succeeded we didn't actually add to the list of evaluation-instructions in the `FuncCallInstr` object, hence there would be a `null` Instruction object appearing in the code emit phase.
- Added some NOTEs which we can clean up this code using

* TypeChecker

- Cleaned up commented-out code

* Added CI/CD test for 'simple_stack_array_coerce.t'

* Added CI/CD test for 'complex_stack_arrays1.t'

* Added CI/CD semantic tests (WIP) for 'simple_stack_array_coerce.t' and 'complex_stack_arrays1.t'

* Added CI/CD semantic tests (WIP) for 'simple_arrays2.t' and 'simple_arrays4.t'

* Added CI/CD semantic tests (WIP) for 'simple_arrays2.t' and 'simple_arrays4.t'

* Added CI/CD semantic tests (WIP) for 'simple_arrays2.t' and 'simple_arrays4.t'

* Fixed filepath for test 'simple_arrays.t'

* Fixed typechecking tests for arrays

* DGen

- Added instrumentation for `simple_stack_array_coerce.t`

Test cases

- Updated `simple_stack_array_coerce.t` to update the array passed in a manner such that we can sum the two elements later, return it and assert to ensure it is set correctly

* Parser

- Had to ensure the old identifier code was removed too, was too early; therefore this now-dead code was removed

* Test cases

- Added this test (even though it is a bad test, the syntax ie wrong)

* Test cases

- Update `simple_stack_arrsys4.t` to return an `int` such that we can verify it works.
- Also added more tests to it.

DGen

- Added semantic test code generation for `simple_stack_arrays4.t`

CI

- Re-organised tests for semantics in emit for arrays into those "Which have semantic tests" and "those which don't (yet)"
- Added semantic/emit test for `simple_stack_arrays4.t`

* Test cases

- Updated `simple_arrays2.t` to test casting of complex array types

* Test cases

- Updated `complex_stack_arrays1.t`

* Test cases

- Added new test for testing pointer syntax; `simple_stack_array_coerce_ptr_syntax.t`
- FIXME: It is broken as we don't have the latest pointer code - that must still be finished

* Test cases

- Added test case `simple_stack_array_ceorce_wrong.t` where coercion must fail

* Test cases

- Added `simple_pointer_array_syntax.t` which should test the `int[] == int*` stuff

* DGen

- Made semantic test for `simple_pointer_array_syntax.t`

Test cases

- Added a test for `simple_pointer_array_syntax.t.t`

* Branding

- Added logo here

* Test cases

- Addes semantic code emit instrucmentation for `simple_stack_array_coerce_ptr_syntax.t`

* Pipelines

- Added test case for `source/tlang/testing/simple_stack_array_coerce_wrong.t` for typechecking phase

* Test cases

- Added test case `complex_stack_array_coerce.t`

* Test cases

- Added extensive positive test case `complex_stack_array_coerce_permutation_good.t` which has a lot of different ways to write `int**` (think `int*[]` etc)
- Added negative test cases `complex_stack_array_coerce_bad1.t`, `complex_stack_array_coerce_bad2.t` and `complex_stack_array_coerce_bad3.t`
2023-04-20 11:21:50 +02:00
Tristan B. Velloza Kildaire fca2bac20e
🐞️ Bugfix: Function parameter types should use parseTypedDeclaration(onlyType=true) (#4)
* Praser

- Added TODO in `parseFuncDef(bool)` explaining where we should place the type deriving code

* Parser

- Attempt "Solution 1" of `#111`

* Parser

- Cleaned up `parseFuncDef()`
- Also commented-out incorrect code that expected old type code for pointer handling

* Parser

- In `parseFuncDef()` we have removed commented out code which was, as mentioned in the last commit, incorrect code that expected old type code for pointer handling
2023-04-17 16:34:52 +02:00
Tristan B. Velloza Kildaire 990b8a7d87 Parser
- Added a new default parameter to `parseTypedDeclaration()` which is `onlyType=false`. If one sets this to `true` then we will parse the type till the identifier (what would be it) but stopping on the identifier and returning a bogus `TypedEntity` with a fake name string but with the type string intact
- `parseCast()` now uses `parseTypedDeclaration(onlyType=true)` - this should help us when we want to cast for arrays or pointers (where all that logic is in `parseTypedDeclaration()`).

Test cases

- Added a complex `cast(<expr>)` with a pointer - this should work in upstream `pointers` branch
- File name is `simple_cast_complex_type.t`
2023-04-14 13:32:19 +02:00
Tristan B. Velloza Kildaire 3b4142f16b Parser
- Implemented `ulong getCursor()` which returns the parser's token pointer
2023-02-15 13:16:42 +02:00
Tristan B. Velloza Kildaire 37225c8484 Parser
- Added a TODO about a possible refactor to make things split out more
- Implemented `setCursor(ulong)` so that we can update the position of the token pointer
2023-02-15 13:13:42 +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 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 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 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 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 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 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 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 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 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 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
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 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 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 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 15a848756b Added support for binary/boolean operators in the unary and binary operator cases 2022-04-13 09:45:06 +02:00
Tristan B. Velloza Kildaire cc2cdf2c30 Throw a parsing error when attempting to use anything but a +, * or - as a unary operator 2022-04-12 13:03:40 +02:00
Tristan B. Velloza Kildaire 396ccdbc60 Moved token I/O statements toghether 2021-11-01 18:25:43 +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 c957845c66 Made `new` expression support more explicit to return a `NewExpression` with an embedded FunctionCall rather than a FunctionCall alone 2021-06-15 14:27:32 +02:00
Tristan B. Velloza Kildaire 8b1e1c1db5 Associate variable's and their assignment statements bidirectionally 2021-06-15 11:10:50 +02:00
Tristan B. Kildaire 6d19bd9b44 TODO added 2021-06-09 17:44:21 +02:00
Tristan B. Kildaire fb5de13895 Fixed bug whereby the semicolon after a `discard`'s expression was not expected and neither consumed 2021-06-09 12:57:43 +02:00
Tristan B. Kildaire dc162e7b03 Added support for discard statement 2021-06-09 12:55:59 +02:00
Tristan B. Kildaire 55b256565c Added support for `new` operator in expression parsing (not yet as a statement) 2021-06-09 12:44:26 +02:00
Tristan B. Velloza Kildaire 9b2468144b Ensure they are variables
Added variable to myClass1.myClass1_1 as `entity` and code to the unit test to test it
2021-06-08 13:03:46 +02:00
Tristan B. Velloza Kildaire 8feb055c86 Cleaned up 2021-06-08 13:00:21 +02:00
Tristan B. Velloza Kildaire 1e46615f81 Vice-versa of the above should not be true (unit test passes) 2021-06-08 12:58:36 +02:00
Tristan B. Velloza Kildaire ebc99584dd Fixed incorrect variable type being used 2021-06-08 12:57:58 +02:00
Tristan B. Velloza Kildaire dfe9d8e553 Ensure the inner and outer variables exist in the correct classes 2021-06-08 12:57:32 +02:00
Tristan B. Velloza Kildaire b51414eb02 Ensure name resolution is working (unit test passed) 2021-06-08 12:54:29 +02:00
Tristan B. Velloza Kildaire 92a11bf605 Assure that they are classes 2021-06-08 12:52:27 +02:00