Commit Graph

934 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 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 dbfea00f09 Test cases
- Removed `simple_cast_complex_type.t` as it is just syntactically wrong
2023-04-14 17:49:38 +02:00
Tristan B. Velloza Kildaire b84bee5b06 Merge branch 'vardec_varass_dependency' into casting 2023-04-14 17:49:13 +02:00
Tristan B. Velloza Kildaire 2ae780ce2d Test cases
- Removed `simple_cast_complex_type.t` as it is just syntactically wrong
2023-04-14 17:49:00 +02:00
Tristan B. Velloza Kildaire 814f595cd5
Casting improvement (#3)
* d

* Removed placeholder

* 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:38:44 +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 f3957c8d05 Removed placeholder 2023-04-14 13:02:05 +02:00
Tristan B. Velloza Kildaire fbc88d63e0 d 2023-04-14 13:01:56 +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 53062f5ebc Commands
- If the `lex`, `syntaxcheck` or `typecheck` commands fail then exit with an exit status of `-1`
2023-04-12 09:02:39 +02:00
Tristan B. Velloza Kildaire 3830dd45bc Commands
- On any `ErrnoException` exit with exit code `-2`
2023-04-12 09:01:47 +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 715efb1b14 Compiler
- On `compile` command failure exit with a status of `-1`
2023-04-12 08:55:42 +02:00
Tristan B. Velloza Kildaire f9e1a28296 Compiler
- Documented `CompilerError` and all of its enums
2023-04-12 08:46:26 +02:00
Tristan B. Velloza Kildaire bf2ad84b28
Update README.md 2023-03-26 14:13:56 +02:00
Tristan B. Velloza Kildaire c78679c297
Update README.md 2023-03-26 14:13:16 +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