Commit Graph

1012 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire d35d651b0d Fixed test case simple1_oop.t 2022-12-20 16:10:13 +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 beb068a33c Check
- Added `SymbolType.EQUALS`
- Added check for equality operator
2022-12-17 20:46:05 +02:00
Tristan B. Velloza Kildaire ed9aa3637c Lexer
- Update column position
2022-12-17 20:44:14 +02:00
Tristan B. Velloza Kildaire dc607cdcd0 Lexer
- Added support for equality operator `==` (fixes issue #65
2022-12-17 20:40:45 +02:00
Tristan B. Velloza Kildaire d1b3319a74 Instruction
- Added new instruction type `ReturnInstruction`

Data

- Adjusted return statement parser node weighting to 2 (makes it on the same level as normal body statements)

Dependency

- Added dependency generation for return statements
- Removed old commented-out code in the function-definition generation section of `generalPass()`

TypeChecker/Codegen

- Added code generation for return statements

DGen

- Added code emitting for return statements (`ReturnInstruction`)

Test cases

- Updated test case `simple_functions.t` to test return statements
2022-12-17 19:02:14 +02:00
Tristan B. Velloza Kildaire 2140747a36 Test cases
- Updated test case `simple_functions.t` to use `k` global via best effort resolution and top-down resolution to test both methods
2022-12-17 14:44:21 +02:00
Tristan B. Velloza Kildaire 9405c03e10 DGen
- Cleaned up emit() method
- New test case hashes inserted for entryPoint test code

Test cases

- Updated `simple_function_decls.t` to be exactly that, ONLY declarations with basic bodies
- Migrated advanced function usage testing code to a new unit test: `simple_functions.t`
2022-12-17 14:31:03 +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 ddea68a73d Dependency
- Bug fix (#57) - Undid hack (of #46) for Context setting of VariableStdAloneAssignments
- Bug fix (#54) in VariableExpression whereby global lookups failed because they used `resolveWithin()` and not `resolveBest()`

Resolution

- Implemented `generateNameBest(Entity)` which can generate the full absolute path of the given Entity
- Added debug statements to `isDescendant(Container, Entity)`
- Added a TODO for when isDescendant fails, the asserts should be removed and placed there

Mapper

- The `symbolLookup()` method now takes in only the Entity and provides a hash (by making use of `generateNameBest()`)

DGen

- Switched to using the new `symbolLookup(Entity)` in `transform()` wherever it was being used

Test cases

- Updated test case `simple_function_decls.t` to use a global variable reference in a VariableExpression to test the fix for #54
2022-12-17 13:41:00 +02:00
Tristan B. Velloza Kildaire 2a12c310a6 Instruction
- Make the name of the function const and public for FuncCallInstr

CodeEmitter

- Added methods `getCursor()`, `getSelectedQueueLength()` and `getQueueLength()`
- Removed old queue-specific methods

DGen

- Added emitting for FuncCallInstr instruction (function call support)
- Now emit globals first BEFORE function definitions
- Added debug prints per instruction to know what instruction is currently being transform()'d
- After emitting sections add newlines between each to make for neater C code
- `emitEntryPoint()` now adds a test for `simple_function_decls.t` (This should be removed soon)
- Removed incorrect TODO in `finalize()`

Dependency

- Make the `nodePool` static, to ensure pooling carries over across multiple `DNodeGenerator` instances
- Fixed handling of function calls in `expressionPass()` - do NOT add a so-called `FunctionDefNode` (remember functions are defined by `addFuncDef()`)
- Set the Context of standalone variable assignments to the Context of the Variable entity representing the variable being assigned to

TypeChecker

- Assign the Context object stored in the `FunctionCall` statement to the `FuncCallInstr`

Test cases

- Updated test case `simple_function_decls.t`
2022-12-16 14:53:33 +02:00
Tristan B. Velloza Kildaire 8a481fb0ac App
- Added newline to release info print
- Fixed module docstring

Commands

- Added new command-line options: `syntaxcheck`, `typecheck`
- Added todo to `help` command
- Re-ordered commands for order of appearance in help text

Compiler

- Added docstring to `beginCompilation(string[])` function

Mapper

- Added debug print of the Container being used for the symbol lookup

CodeEmitter

- Re-worked CodeEmitter class to use a single so-called "selected queue"
- Added methods to move back and forth between said "selected queue", get the length, etc.
- Remove old queue-specific methods

DGen

- Use the new CodeEmitter "selected-queue" functionality
- Emit function definitions now supported

Exceptions

- Added this keyword

Check

- Added support for SymbolTYpe.OCURLY and SymbolType.CCURLY to `getCharacter(SymbolType)`

Data

- Added a `hasParams()` method to the Function entity type

TypeChecker

- Added support for emitting function definitions (required DNode.poes = [] (cleaning), codeQueue cleaning etc.)
- Added `getInitQueue()` method to make a copy of the current "scratchpad" `codeQueue`
- Build up a copy of the global queue now (make a copy similiar to what we did for `getInitQueue()` but inline)
- Added a debug print

Dependency

- Added a FIXME note for issue #46
- Added a TODO relating to `static DNode[] poes`

Test cases

- Added test case `simple_function_decls.t` to test function definition code emit
- Updated test case `simple_variables.t` to note that the T code generates invalid C code

README

- Build instructions now generate coverage files (`.lst`s)
- Updated link to documentation
2022-12-14 19:49:08 +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 ffa2174172 Test cases
- Added note about compile-time constant violations that this code would generate C-wise to `simple_variables.t`
2022-12-13 11:53:23 +02:00
Tristan B. Velloza Kildaire 990f0ed1cc DGen
- Implemented code emit for variable expressions (fetching their values)

----

Test cases

- Updated test case `simple_variables.t` to be able to test the newly implemented `FetchValueInstr` code emit
2022-12-13 11:51:44 +02:00
Tristan B. Velloza Kildaire 3afdd5b05d TypeChecker
- Copy Context across from the `VariableExpression` to the `FetchValueVar` instruction
2022-12-13 11:50:54 +02:00
Tristan B. Velloza Kildaire 1e6d52c1fe DGen
- Actually implement last commit
2022-12-13 11:46:40 +02:00
Tristan B. Velloza Kildaire bd725dd2e5 DGen
- If an emit transform is missing then show the type is is missing for with the "Base emit"
2022-12-13 11:45:45 +02:00
Tristan B. Velloza Kildaire 8abfda42a4 DGen
- Removed some completed TODOs
- Refactored code
2022-12-13 11:43:00 +02:00
Tristan B. Velloza Kildaire 8978a74a21 Check
- Updated SymbolType mappings

----

Test cases

- Updated test case to test the above (`simple_variables.t`)
2022-12-13 11:41:25 +02:00
Tristan B. Velloza Kildaire 5364380e7c DGen
- Removed redundant imports

Dependency

- Set the context for the `VariableAssignmentStdAlone` entity
- Removed words that show I have the mental maturity of a 12 year old

----

 Test cases

 - Updated `simple_variables_decls_ass.t`
 - Updated `simples_variables.t`
2022-12-13 09:43:31 +02:00
Tristan B. Velloza Kildaire 908356c27b VariableAssignmentStdAlone
- Removed duplicate instance of `VariableAssignmentInstr`
- Set the context of the created `VariableAssignmentInstr` to be that of the `VariableAssignmentStdAlone`  entity
2022-12-12 21:10:58 +02:00
Tristan B. Velloza Kildaire 01bdb145e2 CoreEmitter
- All operations regarding moving through (iterating over) instructions are now to be done via the instructions provided by CodeEmitter, moveback, moveforward etc.

DGen

- Re-worked the system to use new CodeEmitter semantics
- Variable assignments in declarations are oneshot now which makes it more compact, semantically better and also valid C

---

Tests

- Updated the `simple_variables.t` test case to have many binary operations chained
2022-12-12 19:12:39 +02:00
Tristan B. Velloza Kildaire e64a9ef5d1 DGen
- Added `Variable` type import

CoreEmitter

- Added some testing code which (MAY) be used
2022-12-12 16:56:54 +02:00
Tristan B. Velloza Kildaire ca92e6f7bf Mapper
- Prefix generated names with `t`
2022-12-12 16:56:23 +02:00
Tristan B. Velloza Kildaire ee8d73e23b Instruction
- Removed import of (now) non-existent function
2022-12-12 16:41:27 +02:00
Tristan B. Velloza Kildaire 90a302826b DGen
- Added varAssStack (instance of Stack)
2022-12-12 16:40:45 +02:00
Tristan B. Velloza Kildaire 5ed48daab5 Disabled regex in .gitignore for now (it was causing issues) 2022-12-12 16:40:15 +02:00
Tristan B. Velloza Kildaire 997b378cc9 Utils
- Removed `symbolRename(string)` method
2022-12-12 16:39:57 +02:00
Tristan B. Velloza Kildaire 23b3e67f02 Utils
- Added template-based Stack implementation
2022-12-12 16:39:19 +02:00
Tristan B. Velloza Kildaire c870208118 DGen
- Use clang for now
2022-12-12 15:52:46 +02:00
Tristan B. Velloza Kildaire b0d9d2aabe Instruction
- Removed all `emit()` methods (this is now done in the language-specific emitter - DGen)

CoreEmitter

- Added docstrings
- Added required `transform(Instruction)` method which must transform each provided Instruction into a string (a.k.a. do the actual emit()-ting)

DGen

- Migrated C-emit code into the overrided `transform(Instruction)` method
2022-12-12 15:36:07 +02:00
Tristan B. Velloza Kildaire 092e4e4130 Reverted .gitignore change 2022-12-12 15:16:49 +02:00
Tristan B. Velloza Kildaire 39c8ed4afb Fixed .gitignore 2022-12-12 15:16:18 +02:00
Tristan B. Velloza Kildaire b2a3b40795 Instruction
- Added note about how we should change our approach to emitting code - it should not be done within the Instructions but rather in DGen somehow
2022-12-12 15:16:08 +02:00
Tristan B. Velloza Kildaire dfc90451bb Instruction
- Added `getContext()` to Instruction
2022-12-12 15:14:43 +02:00
Tristan B. Velloza Kildaire b51f38951a VariableAssignmentInstr
- Now emits correct assignment C code
2022-12-12 15:13:45 +02:00
Tristan B. Velloza Kildaire b767ddc8bf Removed build artefact 2022-12-12 13:33:29 +02:00
Tristan B. Velloza Kildaire 91d3f9c107 Updated .gitignore 2022-12-12 13:33:04 +02:00
Tristan B. Velloza Kildaire 50728d02d3 Dependency
- VariableAssignment entity now has its Context object set to the current Context (of the Variable being declared) (so this is a declare assignment case only (so far)) (fixes #36)

TypeChecker

- Extract the Context object from the VariableAssignment entity and then set it as the Context for the VariableAssigmnetInstr instruction (fixes #36)

VariableAssigmnentInstr

- The `emit()` method will now emit the assignment code

Check

- Added `getCharacter(SymbolType)` which maps a SymbolType to a maths operator (WIP)
2022-12-12 13:12:03 +02:00
Tristan B. Velloza Kildaire 18dbe5508f LiteralValue
- Implemented the correct emit for this instruction (just emits the string version of the ulong `data`

BinOpInstr

- Emit is almost correct, just missing a mapping from SymbolType to the maths operator required
2022-12-12 11:18:50 +02:00
Tristan B. Velloza Kildaire 74227fe560 BinOpInstr, UnaryOpInstr
- Fixed bug whereby the operator was not being stored on object construction

BinOpInstr, LiteralValue, VariableAssignmentInstr

- Added stub `emit()`
2022-12-12 11:13:38 +02:00
Tristan B. Velloza Kildaire d8e5f108e4 Mapper
- Added new SymbolMapper class with a static method which will take a Container and an entity name, resolve the Entity and then generate the hash of the absolute path to said entity and return this as the `symbol name`

TypeChecker

- Set the static field to refer to this instance of the TypeChecker (in the SymbolMapper class)

VariableDeclaration

- Use the `symbolLookup()` method to transform the name
2022-12-12 10:58:58 +02:00
Tristan B. Velloza Kildaire 6a64ed40c9 CodeEmitter
- Added `finalize()` method, this is to be called whenever the emitting is done and a compiler is to be called on the code

DGen

- Implemented a gcc-based finalization method
- Added `emitEntryPoint()` to emit a main() function which is to be called in libc's `_start` symbol

VariableDeclaration

- Added note we may need a symbol table lookup system actually, rather than just a simple `symbolRename`

Compiler

- Call the `finalize()` method on the DGen code emitter

----

Test cases

- Added `simple_variables_only_decs.t` to test code generation
2022-12-11 21:41:15 +02:00
Tristan B. Velloza Kildaire be95288855 Utils
- Added a method which will replace the `.`s in a symbol with underscores

Instruction

- The symbol names need to be valid in C so let's just make it a rule they will only have _'s (underscores) to replace any characters like `.`s
2022-12-11 21:14:31 +02:00
Tristan B. Velloza Kildaire 585405d9e9 DGen
- Made `emitHeaderComment()` correctly emit the optional `headerPhrase` with the correct structure (using *-prefixed comments)
2022-12-11 21:00:48 +02:00
Tristan B. Velloza Kildaire 272bfee124 VariableDeclaration
- Added docstring
- Cleaned up and refactored out into two separate statements (for variable name generation)
2022-12-11 19:36:31 +02:00
Tristan B. Velloza Kildaire 41e8db9a24 VariableDeclaration
- Prevent updating of the fields `varName`, `length` and `varType` after construction of the object
2022-12-11 19:10:29 +02:00
Tristan B. Velloza Kildaire 57a9e86d5f TypeChecker
- Pass in the type of the variable being declared to the `VariableDeclaration` instruction

VariableDeclaration

- Emitted code now contains the type of the variable being declared
2022-12-11 18:46:05 +02:00
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