Commit Graph

61 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire e5610be6f2 Merge branch 'master' of github.com:tbklang/tlang 2023-04-20 11:31:01 +02:00
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 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 a346f60c2e Ensure that 'simple_literals4.t' fails as it tests a range violation during coercion 2023-04-12 11:42:21 +02:00
Tristan B. Velloza Kildaire ae038c4182 Ensure 'simple_float_constant_bad.t' passes as a failure as it checks for a bad floating point 2023-04-12 11:38:26 +02:00
Tristan B. Velloza Kildaire a8d244188e Ensure that a failure passes for 'simple_literals2.t' which checks for a failing to coerce due to incompatible types (actually) 2023-04-12 11:36:31 +02:00
Tristan B. Velloza Kildaire e80571758f Ensure that a failure passes for 'simple_literals2.t' which checks for a failing to coerce due to incompatible types 2023-04-12 11:33:34 +02:00
Tristan B. Velloza Kildaire d99b23d64c Disabled 'test3.t' as it is not the focus rn 2023-04-12 09:57:13 +02:00
Tristan B. Velloza Kildaire b4a02addcf Disabled 'simple_oop.t' as it is not the focus rn 2023-04-12 09:55:12 +02:00
Tristan B. Velloza Kildaire 5e298e599b Else without if test case should fail 2023-04-12 09:51:40 +02:00
Tristan B. Velloza Kildaire 6dc3c78792 All collision and precedence checks are failing-positives and should be treated as such 2023-04-12 09:49:08 +02:00
Tristan B. Velloza Kildaire 9ffd3425a0 Removed 'typecheck/simple_array.t' testing as that is old 2023-04-12 09:45:34 +02:00
Tristan B. Velloza Kildaire 8b97531b71 Try to fix falining-positive test case 'simple_function_call_1.t' 2023-04-12 09:42:44 +02:00
Tristan B. Velloza Kildaire 59f8b7c01a Try new technique 2023-04-12 09:39:30 +02:00
Tristan B. Velloza Kildaire ac2fbc86de Allow steps to run even if previous ones failed 2023-04-12 09:33:57 +02:00
Tristan B. Velloza Kildaire fefaa6e434 Renamed test case 2023-04-12 09:31:10 +02:00
Tristan B. Velloza Kildaire a973f60d54 When typechecking 'simple_function_call_1.t' we WANT it to fail, hence exiting with 255 is what we want, anything else is an error 2023-04-12 09:08:56 +02:00
Tristan B. Velloza Kildaire 4144c4accf Fixed emit test for 'Simple conditionals' 2023-04-12 09:04:11 +02:00
Tristan B. Velloza Kildaire 4d457c2eb3 Disabled 'simple_variables.t' as it uses the now-currently unsupported 'discard' keyword 2023-04-12 08:59:19 +02:00
Tristan B. Velloza Kildaire 95084ec639
Disabled deployment for now
Permissions problems.
2023-03-26 14:11:43 +02:00
Tristan B. Velloza Kildaire dd31ae1263
Update d.yml 2023-03-26 14:01:59 +02:00
Tristan B. Velloza Kildaire 42fe576d33
Update d.yml 2023-03-26 13:57:42 +02:00
Tristan B. Velloza Kildaire 1e65b2caee
Update d.yml 2023-03-26 13:51:35 +02:00
Tristan B. Velloza Kildaire 8c588ab52f
Update d.yml 2023-03-26 13:45:30 +02:00
Tristan B. Velloza Kildaire 98b954009d
Update d.yml 2023-03-26 13:43:45 +02:00
Tristan B. Velloza Kildaire a734347a89
Update d.yml 2023-03-26 13:41:22 +02:00
Tristan B. Velloza Kildaire 009c4cf560
Update d.yml 2023-03-26 13:39:19 +02:00
Tristan B. Velloza Kildaire ea7699bc36
Update d.yml 2023-03-26 13:37:10 +02:00
Tristan B. Velloza Kildaire 3a8d856fbc
Update d.yml 2023-03-26 13:32:22 +02:00
Tristan B. Velloza Kildaire 5bdd985428
Update d.yml 2023-03-26 13:31:01 +02:00
Tristan B. Velloza Kildaire d5e5880f7f
Update d.yml 2023-03-26 13:29:36 +02:00
Tristan B. Velloza Kildaire 695d7a5045
Update d.yml 2023-03-26 13:28:56 +02:00
Tristan B. Velloza Kildaire 215f301557
Added 2 more tests for code emit
- Added do-while test
- Added for-loop test
2023-03-26 13:27:24 +02:00
Tristan B. Velloza Kildaire 4e37078276
Update d.yml 2023-03-26 13:23:54 +02:00
Tristan B. Velloza Kildaire 64500ea2d2
Update d.yml 2023-03-26 13:23:16 +02:00
Tristan B. Velloza Kildaire 73b9d8332a
Update d.yml 2023-03-26 13:22:11 +02:00
Tristan B. Velloza Kildaire 9eeacdb3c4
Update d.yml 2023-03-26 13:21:30 +02:00
Tristan B. Velloza Kildaire 43677cbcfb
Added code emit tests 2023-03-26 13:18:50 +02:00
Tristan B. Velloza Kildaire 91e389c4ff
Finished typechecking tests 2023-03-26 13:15:43 +02:00
Tristan B. Velloza Kildaire 464d30b06c
Update d.yml 2023-03-26 13:12:12 +02:00
Tristan B. Velloza Kildaire 899f832b36
Added more tests 2023-03-26 13:09:49 +02:00
Tristan B. Velloza Kildaire 8d86f3618a
Update d.yml 2023-03-26 13:02:30 +02:00
Tristan B. Velloza Kildaire 46e963e98a
Update d.yml 2023-03-26 13:01:07 +02:00
Tristan B. Velloza Kildaire 3069878aa6
Update d.yml 2023-03-26 12:58:47 +02:00
Tristan B. Velloza Kildaire 713d491727
Update d.yml 2023-03-26 12:57:38 +02:00
Tristan B. Velloza Kildaire c90e25da4e
Update d.yml 2023-03-26 12:56:44 +02:00
Tristan B. Velloza Kildaire 8675cd0a1c
Update d.yml 2023-03-26 12:56:24 +02:00
Tristan B. Velloza Kildaire 14c18fd2b4
Update d.yml 2023-03-26 12:54:32 +02:00
Tristan B. Velloza Kildaire 01a3011c23
Update d.yml 2023-03-26 12:52:55 +02:00
Tristan B. Velloza Kildaire 6c219d87dd
Update d.yml 2023-03-26 12:47:56 +02:00