Commit Graph

790 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire c39bc20d1c VariableDeclaration (WIP)
- Added `emit()` method to fetch name for now and emit a string
2022-12-11 18:40:12 +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 d19edef8f4 DGen
- Emit code by calling `emit()` on each Instruction object
2022-12-11 18:13:10 +02:00
Tristan B. Velloza Kildaire 1e2ef795d6 Instruction
- Added `emit()` method to base Instruction class
- Fixed typo in name of `StorageDeclaration` class
- WIP: `VariableDeclaration` emit()
2022-12-11 18:12:46 +02:00
Tristan B. Velloza Kildaire 5a22b184b7 DGen
- Don't write a blank line at the top of the header comment (see `emitHeaderComment()`)
2022-12-11 18:09:56 +02:00
Tristan B. Velloza Kildaire 15617e7ced DGen
- Added note to `emitCodeQueue()` that instructions will need recursive `emit()` methods
2022-12-11 18:08:52 +02:00
Tristan B. Velloza Kildaire f4797b79e2 DGenregs
- This file has been removed

DGen

- Removed unused import for `dgenregs.d`
2022-12-11 18:06:10 +02:00
Tristan B. Velloza Kildaire b8c99329aa DGen
- Added trailing newline to the comment emitted by `emitHeaderComment()`
2022-12-11 18:04:53 +02:00
Tristan B. Velloza Kildaire c91d72d0b9 DGen
- Added some NOTEs for potential TODOs
2022-12-11 18:01:54 +02:00
Tristan B. Velloza Kildaire e6b1de47f1 DGen
- Added docstring to `emitHeaderComment()`
2022-12-11 17:58:33 +02:00
Tristan B. Velloza Kildaire fe7390caa0 DGen
- The module name of the source file is now correctly added to the header comment (see `emitHeaderComment()`)
2022-12-11 17:57:16 +02:00
Tristan B. Velloza Kildaire 1f3bdd3279 DGen
- Added support for an additional string comment to be added to the emitted header comment via the `emitHeaderComment()` method
2022-12-11 17:55:18 +02:00
Tristan B. Velloza Kildaire c37b85b781 DGen
- Emit a header comment to the output C file containing information about the generated code (source file and destination file)
2022-12-11 17:52:36 +02:00
Tristan B. Velloza Kildaire b43e8de0ef Compiler
- Make output file `tlangout.c`
2022-12-11 17:43:24 +02:00
Tristan B. Velloza Kildaire 566a916a5a DCodeEmitter
- Removed old code generation code - starting anew
2022-12-11 17:38:58 +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
Tristan B. Velloza Kildaire 6253281f6f Typechecking
- Cleaned up imports
- Added TODOs and a stub `beginEmit(InitQueue, CodeQueue)` method to be used for the beginning of the code emit process
2022-12-11 17:33:18 +02:00
Tristan B. Velloza Kildaire ff20c28458 Added debug statements at each stage of DNode processing in the `doTypeCheck(DNode[])` method along with seperators for the final stage's InitQueue and CodeQueue print out 2022-11-26 16:31:33 +02:00
Tristan B. Velloza Kildaire b58c23bd9c Fixed typo 2022-11-26 16:28:27 +02:00
Tristan B. Velloza Kildaire ff51b2ded0 Cleaned up the `doTypeCheck(DNode[])` method 2022-11-26 16:26:51 +02:00
Tristan B. Velloza Kildaire 13a0a5057f Removed unused commented block of code 2022-11-26 16:25:23 +02:00
Tristan B. Velloza Kildaire 9151a46888 Cleaned up 2022-10-15 23:46:10 +02:00
Tristan B. Velloza Kildaire a122b674e2 Cleaned up ClassStaticNode handling code in the type checker. 2022-10-15 23:43:02 +02:00
Tristan B. Velloza Kildaire cac86d604e Added method documentation 2022-10-15 22:03:50 +02:00
Tristan B. Velloza Kildaire b09a247413 Removed unused SList 2022-10-15 22:01:41 +02:00
Tristan B. Velloza Kildaire 268f4bb48f Added `printInitQueue()` method to print all elements in the initialization queue
Print both the initialixation queue (and then) and the code queue at the end of typechecking the linearized list
2022-10-15 21:57:03 +02:00
Tristan B. Velloza Kildaire ae789c9114 Increased complexity of test case 2022-10-15 21:00:59 +02:00
Tristan B. Velloza Kildaire 0c94ece070 Initialization queue
This is a queue where all things such as:

- Class static initializations
- Module initializations (maybe)
- Struct static initializations

will go.

Added `addInit()` along `SList initQueue` to support such a queue.

- Whenever a ClassStaticNode is come across it is added to this queue (at the back - so as to maintain allocation order, not that allocation would matter - only initialization (which is already working))
2022-10-15 20:36:18 +02:00
Tristan B. Velloza Kildaire 47d1974f93 Just create a ClassStaticInitAllocate instruction but don't do anything with it 2022-10-15 20:25:38 +02:00
Tristan B. Velloza Kildaire 1b7cf42aa5 Disabled ClassStaticAllocate processing code in typechecker for now
Updated test case
2022-10-15 20:24:23 +02:00
Tristan B. Velloza Kildaire c9dcf58911 Updated test case to double check that complex examples would be correctly processed 2022-10-15 17:18:27 +02:00
Tristan B. Velloza Kildaire 31c52c0beb Potential fix for variable declarations and assignments (to them)
- The VarAssDNode processor on typechecker now adds to the back orf the code queue
- We removed all weird swapping code in typechecker
- Dependency wise, a variable declaration is depended-UPON its variable assignment which in turn a module depends ON.
- In the case of no assignments we simpyl make the module depend on the variable declaration dnode directly
- Added new test case to show this all
2022-10-15 17:15:03 +02:00
Tristan B. Velloza Kildaire cbe40e7184 Formatted code 2022-10-15 16:55:10 +02:00
Tristan B. Velloza Kildaire f4311b8e67 Added note for something to work on 2022-10-15 16:48:57 +02:00
Tristan B. Velloza Kildaire cd02bc2b66 Updated toString() for ClassStaticNode 2022-10-15 13:28:30 +02:00
Tristan B. Velloza Kildaire 3c65af06a0 Added note 2022-10-14 21:16:33 +02:00
Tristan B. Velloza Kildaire 3536e39f6f Found why we are crashing (dependency generation is ordered right but we need to maybe make different objects or add checks of a different sort) 2022-10-14 20:44:33 +02:00
Tristan B. Velloza Kildaire b30b6e0fe0 Disabled generation of unused Context object 2022-10-14 20:13:10 +02:00
Tristan B. Velloza Kildaire 2f586a10cd Updated test case 2022-10-14 20:12:33 +02:00
Tristan B. Velloza Kildaire 86905da623 Added TODO 2022-10-14 20:12:28 +02:00
Tristan B. Velloza Kildaire 2031a4645c Context should just be the same one passed in as we are not changing really. 2022-10-14 20:10:57 +02:00
Tristan B. Velloza Kildaire c85aba1f56 WIP 2022-10-14 19:58:33 +02:00
Tristan B. Velloza Kildaire e46950778b Fixes:
- The test case was broken -_-
- Full-path traversal now implemented somewhat, along with checks on the container if they require static initialization (such as for Classes)
2022-10-14 18:45:44 +02:00
Tristan B. Velloza Kildaire 0c104440ae Freeze for now 2022-10-14 18:01:35 +02:00
Tristan B. Velloza Kildaire 05d00ff58b WIP: Seems wrong the order we get back, might need to take some time to think about how to get about implementing this 2022-10-13 18:35:25 +02:00
Tristan B. Velloza Kildaire 15d2bf6b68 Dependency generation
Full path evaluation update

If the local segment is a Class-type-of Container then run
a class static allocation on it and make the current dnode
dependent on that ClassStaticAllocation dnode returned from
classStaticAllocate().
2022-10-13 18:32:33 +02:00
Tristan B. Velloza Kildaire 2d58d5f0d7 WIP: Full path dependency evaluation 2022-10-13 18:29:30 +02:00
Tristan B. Velloza Kildaire 8a82751a18 Added Gitea issue number #8 for ClassStaticAllocate node 2022-10-13 14:34:47 +02:00
Tristan B. Velloza Kildaire 4b36623861 Added Gitea issue note 2022-10-13 13:45:39 +02:00
Tristan B. Velloza Kildaire 96d8f0face WIP: Found a fix for context lookup failure 2022-10-13 13:21:35 +02:00
Tristan B. Velloza Kildaire e2e356da73 Added FIXME note 2022-10-01 21:02:51 +02:00
Tristan B. Velloza Kildaire 81f168e154 Removed unused commented-out code 2022-10-01 20:58:34 +02:00
Tristan B. Velloza Kildaire 69572ff02c Removed unused method (older method before generalPass()) 2022-10-01 20:56:42 +02:00
Tristan B. Velloza Kildaire a8630b5939 We need to do funciton definition dependency generation ALOGN with normal dependency generation
- Disabled seperate generate() calls to FuncDefs in core.d for typechecking
- Added `saveFunctionDefinitionNode()` and `retrieveFunctionDefinitionNode()` to core.d for dependency
- Added a generalPass() call (and fixed it to skip on things != STATIC for InitScope - temporary fix)
- Added test case to test with
2022-10-01 20:55:08 +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 77708b65be WIP: Linerization (typechecking and code generation) for defined functions 2022-10-01 16:35:23 +02:00
Tristan B. Velloza Kildaire e810f762bc Added while loop test case 2022-10-01 16:09:26 +02:00
Tristan B. Velloza Kildaire 5444bd55e8 Added support for comparators to parser 2022-10-01 16:08:21 +02:00
Tristan B. Velloza Kildaire 200149efdf Cleaned up core.d unittest 2022-10-01 15:39:26 +02:00
Tristan B. Velloza Kildaire c1efb0c819 Added unit test to test floating point empty string test in lexer 2022-10-01 15:26:13 +02:00
Tristan B. Velloza Kildaire 3fccf2fa5a Removed debug print 2022-09-29 22:44:48 +02:00
Tristan B. Velloza Kildaire 806814f01c Fixed bug whereby `isNumericalStr()` returned true for empty strings.
This fixes problems whereby if the current build up was empty and a field accessor was being attempted then lexing would fail.
2022-09-27 09:29:01 +02:00
Tristan B. Velloza Kildaire 3d54c4deee Removed assertions which are guaranteed to pass now (since the last fix of 449e878796) 2022-09-18 21:54:31 +02:00
Tristan B. Velloza Kildaire 449e878796 Fixed bug when processing the body of a class and a DNode was hit which was not one of the allowed types:
1. VariableDeclaration

Previously we added back the `varDecInstr` which is post-cast and if the cast failed (hence hitting this !varDecInstr branch) we didn't add back `instr` but rather added back `varDecInstr` which is 0 instead of being non-zero.

This later is incorrect.
2022-09-18 21:52:11 +02:00
Tristan B. Velloza Kildaire aae5dbabe8 Fixed compilation issue with jcli
Upgraded jcli
2022-08-23 16:33:49 +02:00
Tristan B. Velloza Kildaire a8f93e5817 Cleaned up comments for number literal code gen and type checking handling 2022-08-19 11:42:19 +02:00
Tristan B. Velloza Kildaire 7e49cf1d0a Added float support
- Added float constant support to the lexer
- Added float support to the typechecker to build the correct Instruction type

Unit tests

- Added unit test for a bad example of a malformed encoded floating point to test out the lexer
2022-08-11 10:26:30 +02:00
Tristan B. Velloza Kildaire 2dbe14b490 WIP: Floating pooint literal/constant support 2022-07-26 11:16:51 +02:00
Tristan B. Velloza Kildaire f49b0ce2b9 Added floating point constants to test 2022-07-26 10:34:53 +02:00
Tristan B. Velloza Kildaire c561060470 Added float and double types to builtin types
Added floating point test case
2022-07-26 10:27:55 +02:00
Tristan B. Velloza Kildaire e8ddb62152 Removed Double type
Refactored Float type
2022-07-26 10:27:12 +02:00
Tristan B. Velloza Kildaire f64c067184 Updated simple_string.t test 2022-07-26 10:12:35 +02:00
Tristan B. Velloza Kildaire 4488678d3e Code cleanup 2022-07-26 10:10:43 +02:00
Tristan B. Velloza Kildaire 18411c48c4 Removed TODO 2022-07-26 10:07:03 +02:00
Tristan B. Velloza Kildaire c8347fefba Updated simple_string.t to include string constants (literals) that test interning to the same pool ID 2022-07-26 09:59:59 +02:00
Tristan B. Velloza Kildaire d19512668a Pass StringLiteral instruction extracted string literal from StringExpression synmbol
Removed TODO
2022-07-26 09:59:27 +02:00
Tristan B. Velloza Kildaire e2157f428c Implemented `getStringLiteral()` for StringExpression symbol type 2022-07-26 09:58:45 +02:00
Tristan B. Velloza Kildaire 7e9e303a1c Implemented StringLiteral Value-kind-of instruction with string interning 2022-07-26 09:58:25 +02:00
Tristan B. Velloza Kildaire f9a8590604 Array type handling added to builtin-types handling 2022-07-26 09:57:57 +02:00
Tristan B. Velloza Kildaire e0feaac953 Added new test case 2022-07-25 19:34:57 +02:00
Tristan B. Velloza Kildaire 6cfca2cea2 Added `addInstr()` for StringExpression handling (String literals)
Bug fixed whenever a "" is encountered
2022-07-25 19:30:40 +02:00
Tristan B. Velloza Kildaire 415538f54a Added StringLiteral instruction 2022-07-25 19:30:07 +02:00
Tristan B. Velloza Kildaire ca2fa84057 Added support for Pointer type resolution via `getType()`. Now `char**` -> Pointer("char*"), which before construction of such a Pointer is recursively resolved, so nested Pointer(Pointer(...)) 2022-07-25 19:15:27 +02:00
Tristan B. Velloza Kildaire 88a48e1b3d FuncDecNode for the Dependecny Tree Generator added 2022-04-13 09:51:38 +02:00
Tristan B. Velloza Kildaire 35d71a0c25 WIP: FunctionHandle (reference to a funciton's name (NOT a FuncCall)) support (context may not be entirely right) 2022-04-13 09:51:23 +02:00
Tristan B. Velloza Kildaire f571115c23 Added some possible todos, might not need to do any of them but I also might 2022-04-13 09:50:24 +02:00
Tristan B. Velloza Kildaire 1322c0f790 BinaryOperatorExpression now has a proper toString() 2022-04-13 09:49:42 +02:00
Tristan B. Velloza Kildaire 1f8f248219 Added support for the ampersand operator 2022-04-13 09:49:20 +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 e9a60380b6 Pointer type now only requires you provide it the data type of the data being pointed to.
The name of the type will be automatically constructed as `dataType*` (if `dataType` was the type of the data being pointed to)
2022-04-13 09:35:46 +02:00
Tristan B. Velloza Kildaire 6412241185 Added a test case to test pointer handles 2022-04-12 16:17:40 +02:00
Tristan B. Velloza Kildaire 15826a2cab Updated test case to include a variable access 2022-04-12 16:17:29 +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 250d4997e9 Added unit test for simple_function_call 2022-04-12 11:12:02 +02:00
Tristan B. Velloza Kildaire 2ed6a4834d Cleaned up 2022-04-12 11:11:54 +02:00
Tristan B. Velloza Kildaire c02a574ffa Updated test case to test new unary operator expression support 2022-04-12 10:54:12 +02:00
Tristan B. Velloza Kildaire aff0da5116 Added codegen/typecheck support for unary operator expressions 2022-04-12 10:54:04 +02:00
Tristan B. Velloza Kildaire 1b51d9923e Added support to the dependency tree generator for unary operator expressions 2022-04-12 10:53:44 +02:00
Tristan B. Velloza Kildaire ef9018db89 Added UnaryOperatorExpression (finished it) 2022-04-12 10:53:17 +02:00
Tristan B. Velloza Kildaire 1e202fe788 Added Unary Oprator Instruction 2022-04-12 10:52:18 +02:00
Tristan B. Velloza Kildaire 414d9de902 Updated test case 2022-04-08 01:18:57 +02:00
Tristan B. Velloza Kildaire cd54753359 cleaned up 2022-04-08 01:18:12 +02:00
Tristan B. Velloza Kildaire 190f64c0e8 cleaned up 2022-04-08 01:15:31 +02:00
Tristan B. Velloza Kildaire b5c4ca44ee Updated test case 2022-04-08 01:12:55 +02:00
Tristan B. Velloza Kildaire d79b9eee5c Debugging things 2022-04-08 01:12:52 +02:00
Tristan B. Velloza Kildaire 1841ca48d9 Recursively descnend upon function argument expressions 2022-04-08 01:12:34 +02:00
Tristan B. Velloza Kildaire c28a297064 Added toString() to FunctionCall that includes uniqueness number AND funciton's name 2022-04-08 01:08:57 +02:00
Tristan B. Velloza Kildaire 1b002382d5 BinaryOperatorExpressions are meant to evaluate to a value, they MUST be ValueInstructions 2022-04-08 00:34:50 +02:00
Tristan B. Velloza Kildaire ba63f85df9 Binary operator expressions now work 2022-02-20 16:37:45 +02:00
Tristan B. Velloza Kildaire 6222aabc8b Pop types off for Binary Operator typechecking 2022-02-20 16:21:29 +02:00
Tristan B. Velloza Kildaire de31585bcc Cleaned up 2022-02-20 16:05:15 +02:00
Tristan B. Velloza Kildaire 475983dd95 Cleaned up 2022-02-20 16:04:53 +02:00
Tristan B. Velloza Kildaire da9bc742e5 Constrain FuncCallInstr evaluation (for arguyments) to only being value-deriving instructions 2022-02-20 15:36:22 +02:00
Tristan B. Velloza Kildaire 492074119d Added sub-instructions to FuncCallInstr being built 2022-02-20 15:35:34 +02:00
Tristan B. Velloza Kildaire 3cac1b496d Fixed addInfo for FuncCallInstr instruction 2022-02-20 15:35:18 +02:00
Tristan B. Velloza Kildaire 18eba51144 Remove uneeded reversal code 2022-02-20 14:28:31 +02:00
Tristan B. Velloza Kildaire 4677cacdf1 I think it works now as the types are in the same order as instructions
So I guess that works
2022-02-20 14:27:56 +02:00
Tristan B. Velloza Kildaire 76f0d6e1a9 Changed `addType(Type)` to add types to the front of the type queue
Added `addTypeB(Type)` to add Types to the end of the type queue
2022-02-20 14:24:05 +02:00
Tristan B. Velloza Kildaire 4b53823d9c Added `isTypesEmpty()` 2022-02-20 12:09:10 +02:00
Tristan B. Velloza Kildaire abe72f45a7 WIP 2022-02-19 11:54:00 +02:00
Tristan B. Velloza Kildaire a84e0dfe20 Some stuff, working on getting function calls working 2022-02-18 14:32:45 +02:00
Tristan B. Velloza Kildaire 71efb7ae8f Fixed dependency generation for function call paremeters (expressions) 2022-02-16 07:31:22 +02:00
Tristan B. Velloza Kildaire aa5e82fe09 Added stub funccallinstr add to sotp segmentation fault on funciton calls being processed 2022-02-15 15:04:16 +02:00
Tristan B. Velloza Kildaire 5641c7f164 Added the ability to perform ONLY tokenization (lexing) 2022-01-20 10:54:21 +02:00
Tristan B. Velloza Kildaire b5488d5c92 Stuff 2022-01-20 10:43:12 +02:00
Tristan B. Velloza Kildaire 49de425e45 Static initialization for classes, including class memory allocation and then static variable (member) initialization has now been implemented for the code generator 2021-11-11 12:48:49 +02:00
Tristan B. Velloza Kildaire 3a32ecfea5 Or do it like that 2021-11-11 12:31:42 +02:00
Tristan B. Velloza Kildaire a45d2bc30b Variable's name is full path so resolve from the module 2021-11-11 12:30:40 +02:00
Tristan B. Velloza Kildaire 263bf5edb7 Bug fixed
Should not be parent of, but rather should be the class itself
2021-11-11 10:07:25 +02:00
Tristan B. Velloza Kildaire 3da50e9eab Got some sort of class allocator node created, now to re-order it by using Context to be able to know when the StaticVariableDeclaration is within class.
This then generates code to allocate space for the class, once done we can be assured the declarations (placed after it now) will be assigning to properly allocated space (paged and maped for example)
2021-11-10 17:15:27 +02:00
Tristan B. Velloza Kildaire cae3cfe88c Updated 2021-11-10 17:01:17 +02:00
Tristan B. Velloza Kildaire c58bf07bb1 WIP: Trying to get literal encoding working (but it is currently broken) 2021-11-10 17:01:12 +02:00
Tristan B. Velloza Kildaire 6ed33a8051 Done with work for today, good refactoring, now to work on class static initoialization.
Instance initialization and unique-ness, and same for Functions with their "FunctionData" will come later
2021-11-10 17:00:56 +02:00
Tristan B. Velloza Kildaire cb6fb5f86f Removed unused commented blocks of code 2021-11-10 16:45:08 +02:00
Tristan B. Velloza Kildaire 020847cb76 Added nested class static initialization to test case 2021-11-10 16:44:46 +02:00
Tristan B. Velloza Kildaire d74f8cb046 Updated test case 2021-11-10 16:42:54 +02:00
Tristan B. Velloza Kildaire 47edb41e17 Seems like generalised generalPass() is working 2021-11-10 16:42:15 +02:00
Tristan B. Velloza Kildaire 3eddf73b7b Added some stuff
FunctionData adding, some generation stuff, but reworking to make a general pass function
2021-11-10 16:17:42 +02:00
Tristan B. Velloza Kildaire 60f490d8e8 Refactored dependency tree generation code (and all related modules) to its own directory 2021-11-09 19:16:51 +02:00
Tristan B. Velloza Kildaire fffcc953ab Refactored Context class 2021-11-09 19:00:23 +02:00
Tristan B. Velloza Kildaire 7dd8f2df75 Updated test case 2021-11-09 18:27:01 +02:00
Tristan B. Velloza Kildaire f0b0f83c45 Added note to be used later 2021-11-09 18:26:50 +02:00
Tristan B. Velloza Kildaire c9997c60d0 Made public 2021-11-09 18:26:39 +02:00
Tristan B. Velloza Kildaire beaad7e7f1 Added the thing 2021-11-09 18:26:30 +02:00
Tristan B. Velloza Kildaire 6499abb616 Fixed up all other `getStatements()` for other Container types 2021-11-09 16:54:00 +02:00
Tristan B. Velloza Kildaire b39fea5e10 Fixed `getStatements()` for Module container type to be stable. Not having it so caused bad affects and re-ordering that should have NOT happened 2021-11-09 16:50:04 +02:00
Tristan B. Kildaire 7fe3ea342c Added note on name resolution for correct stack offset mapping 2021-11-09 15:51:08 +02:00
Tristan B. Kildaire de261ec511 Copy Context information from the ParserNode across to the Instruction node (only so far for Module Variable Declaration DNodes' embedded PNode 2021-11-09 15:50:04 +02:00
Tristan B. Kildaire 3b36113a5b Added Context 2021-11-09 15:49:59 +02:00
Tristan B. Kildaire 8a8ddcee3a Added notes on ceogeneration 2021-11-09 15:40:35 +02:00