Commit Graph

13 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire d548a066a6 Check
- Corrected import path for `compiler.lexer` -> `compiler.lexer.core`

Parser

- Corrected import path for `compiler.lexer` -> `compiler.lexer.core`

TypeChecker

- Corrected import path for `compiler.lexer` -> `compiler.lexer.core`

Compiler

- Moved configuration code outside of it
- Renamed to `compiler.core`

DGen

- Check for any object files to link in, if so append them to the `cc` call

Lexer

- Moved from `compiler.lexer` to `compiler.lexer.core`

Configuration

- Overhauled configuration system

Mapper

- Added definition to `SymbolMappingTechnique`

Command-line

- Migrated to new configuration system
- Migrated `SymbolMappingTechnique` to Mapper module
- Added support for specifying object fils to link in using the `-ll` flag`

Tests

- Added `file_io.c` for testing `simple_extern.t` with `extern_test.sh`
- Added `extern_test.sh` for testing `simple_extern.t`
2023-01-28 18:12:49 +02:00
Tristan B. Velloza Kildaire d30ffb7684 Command-line
- All compilation stages now make use of the `Compiler` object

Compiler

- Added new exception type `CompilerException` complete with a sub-type enum, `CompilerError`
- `getConfig()` will now throw a `CompilerException` when a key is not found, rather than return false (which didn't work under different template types anyways)
- Implemented `hasConfig()` to check for the existence of a key in the configuration sub-system's key-value store
- The `Compiler` object now stores the `Token[] tokens` generated from the call to `doLex()`
- The `Compiler` object now stores the resulting container (`Module`) generated from the call to `doParse()`
- Set default symbol mapping technique to the hashmapper technique
- Implemented `dolex()` for performing tokenization, it will create and store a `Lexer` instance and the produced `Token[] tokens` into the `Compiler` object
- Added `getTokens()` to fetch the tokens generated by `doLex()`
- Implemented `doParse()`, `doTypeCheck()` and `doEmit()` in a similiar fashion to `doLex()`
- Implemented `getMdoule()` to get the container (`Module`) generated by `doParse()`
- Implemented `compile()` which calls `doLex()`, then `doParse()`, then `doTypeCheck()` and finally `doEmit()`

CodeEmitter

- The `CodeEmitter` constructor now takes in an instance of the chosen `SymbolMapper`

DGen

- Switched to the instance of the `mapper` inheited from the `CodeMapper` parent class for any `symbolMap` calls required
- Use the inherited `TypeChecker` instance and not an instance of it provided by `Context`

SymbolMapper

- Reworked this class into an abstract class which must have its children implement a `symbolMap(Entity)` interface, this provides us pluggable mapping techniques

HashMapper

- Moved hashing symbol-mapping technique into `HashMapper`

Lebanese

- Created a kind-of `SymbolMapper` which, unlike `HashMapper`, produces human-redable-yet-valid C symbols (by replacing the `.`'s with `_`'s)

TypeChecker

- Removed code for setting now-nonexistent `SymbolMapper.tc`
- Removed code for setting now-nonexistent `Context.tc`

Context

- Removed `static TypeChecker tc` field
2023-01-23 20:44:35 +02:00
Tristan B. Velloza Kildaire a987f114ac Compiler
- Moved configuration sub-system to its own class `CompilerConfiguration`
- `getConfig()` and `setConfig()` are now templatised to generate, at compile-time, type-specific versions which will fetch and convert using the requested type
- Added some more default configuration parameters for DGen

DGen

- Implemented configuration checking for `genTabs()` and `emitEntryPoint()` (both which have the default config value of `true`)
- Added commented-out testing code (see issue #88)
2023-01-19 21:06:20 +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 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 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 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 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. Kildaire ff9890437d Working code emitter and doing some code gen with it too 2021-11-02 15:13:44 +02:00
Tristan B. Kildaire 2d46eb4458 Removed unused (old) type 2021-11-02 13:58:36 +02:00
Tristan B. Velloza Kildaire 3dba481260 Refactored code emitter sub-system 2021-11-02 10:41:03 +02:00