tlang/source/tlang/testing/simple_pointer.t

17 lines
192 B
Perl
Raw Normal View History

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 08:53:48 +00:00
module simple_pointer;
int j;
int function(int* ptr)
{
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 15:50:11 +01:00
*(ptr+0) = 2+2;
return (*ptr)+1*2;
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 08:53:48 +00:00
}
int thing()
{
int discardExpr = function(&j);
int** l;
return discardExpr;
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 08:53:48 +00:00
}