Commit Graph

985 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire 4fda952a7c Parser
- Removed reference to `SymbolType.REPR` and `Repr` which was used for testing the `MetaProcessor` in early stages
2023-05-29 16:32:18 +02:00
Tristan B. Velloza Kildaire e8aedea34a Check
- Removed reference to `SymbolType.REPR` in checker
2023-05-29 16:30:40 +02:00
Tristan B. Velloza Kildaire 2b35c1b94a Mcro
- Removed `Repr` which was used for testing in the early stages of `MetaProcessor`
2023-05-29 16:30:03 +02:00
Tristan B. Velloza Kildaire cc12b48e9a Check
- Removed `SymbolType.REPR` which was used for testing early versions of the `MetaProcessor`
2023-05-29 16:29:25 +02:00
Tristan B. Velloza Kildaire 9e9712b345 - Updated `.gitignore` 2023-05-29 16:21:31 +02:00
Tristan B. Velloza Kildaire a8c3835a31 Test cases
- Added `simple_template_type_def.t` for future test cases
2023-05-29 16:18:43 +02:00
Tristan B. Velloza Kildaire 199a26c792 Containers
- `Module` now applies re-parenting in its `replace()`
- `Struct` now applies re-parenting in its `replace()`
- `Clazz` now applies re-parenting in its `replace()`

Data

- `Function` now applies re-parenting in its `replace()`
2023-05-29 16:05:16 +02:00
Tristan B. Velloza Kildaire 51f09bdbb1 MetaProcessor
- Updated comment before call to `doTypeAlias(Container, Statement)`
2023-05-29 12:23:24 +02:00
Tristan B. Velloza Kildaire f6ddff19ff MetaProcessor
- Removed now-completed TODO
2023-05-29 12:22:44 +02:00
Tristan B. Velloza Kildaire 6cf916c88c MetaProcessor
- Removed unused import
2023-05-29 12:13:38 +02:00
Tristan B. Velloza Kildaire 25bcbf4a7f MetaProcessor
- Cleaned up
2023-05-29 12:13:08 +02:00
Tristan B. Velloza Kildaire 162b030f6c - `typeRewrite(MTypeRewritable)` now makes use of `isTypeAlias(string)` and `getConcreteType(string)` 2023-05-29 12:09:31 +02:00
Tristan B. Velloza Kildaire 6c71fdc5ae MetaProcessor
- `doTypeAlias(Container, Statement)` now makes use of `isTypeAlias(string)` and `getConcreteType(string)`
2023-05-29 12:08:36 +02:00
Tristan B. Velloza Kildaire c73790a932 TypeChecker
- Clean up
2023-05-29 12:06:52 +02:00
Tristan B. Velloza Kildaire b0044a7c17 MetaProcessor
- Implemented `isTypeAlias(string)` which determines if the given type is a type alias.
- Implemented `getConcreteType(string typeAlias)` which transforms the type alias into its
concrete type; this method incorporates defensive programming in that it will only apply the transformation IF
the provided type alias is infact a type alias, otherwise it performs an identity transformation
and returns the "alias" untouched.
2023-05-29 12:05:08 +02:00
Tristan B. Velloza Kildaire 8ed0f8fba4 MetaProcessor
- Implemented `isSystemType(string)` which returns `true` if the provided type is a system type alias (such as `size_t` or `ssize_t`), `false` otherwise
2023-05-29 11:57:20 +02:00
Tristan B. Velloza Kildaire dc78da4dd5 TypeChecker
- No longer store a field for the `Compiler` but rather store a field for the `CompilerConfiguration`
- Removed single parameter constructor for `TypeChecker`
- Constructor now uses the default `CompilerConfiguration` if not specified; therefore fixing the issue with unit tests failing

MetaProcessor

- Extract the compiler configuration via `tc.getConfig()`
- Updated `typeRewrite(MTypeRewritable)` to use `getSystemType(string)` to lookup concrete types for `size_t`/`ssize_t`
- `doTypeAlias(Container, Statement)` now uses `getSsstemType(string)` to lookup the concrete types for alises such as `size_t`/`ssize_t`
2023-05-29 11:44:46 +02:00
Tristan B. Velloza Kildaire 2080fb240e Compiler
- Removed `defaultConfig()`
- During construction call `CompilerConfiguration.defaultConfig()` in order to generate the default config
- Pass the config into `TypeChecker` in `doTypeCheck()`
2023-05-26 16:44:29 +02:00
Tristan B. Velloza Kildaire e3a4793cf6 CompilerConfiguration
- Added `defaultConfig()`
2023-05-26 16:43:39 +02:00
Tristan B. Velloza Kildaire 9fa5b6b103 Compiler
- If the T compiler was built on `X86` then set the maximum width to 4 bytes
- If the T compiler was built on `X86_64` then set the maximum width to 8 bytes
- Pass in the `Compiler` instance to the `TypeChecker` in `doTypeCheck()`

TypeChecker

- Added `Compiler` field and now accept it in constructor
- If just single parameter constructor then pass in `null` as the `Compiler` instance
- Added `getCompiler()` to get the instance

MetaProcessor

- Extract the `CompilerConfiguration` via the `TypeChecker`'s `getCompiler()`
- Implemented `getSystemType(string)` which will map `size_t`/`ssize_t` to the correct maximum width'd type your system supports via the `types:max_width` config entry
2023-05-26 11:27:18 +02:00
Tristan B. Velloza Kildaire 04fc87d849 MetaProcessor
- Removed `break` which caused only one `sizeof()` function call to be replaced, we should have been looping over each `FunctionCall` found with `search` and then replacing ech that had a name of `sizeof` with a `NumberLiteral` expression
- Moved all type alias replacement code into a new method; `doTypeAlias(Container, Statement)`
- Added some rudiementary support for replacing any `IdentExpression` containing `size_t` with `uint`

IdentExpression

- Made it `MStatementSearchable` and `MStatementReplaceable`

Test cases

- Updated test case `meta/sizeof.t` to test the `sizeof(<expr>)` AST node in the `MetaProcessor`

Documentation

- Added diagram showing the `MStatementSearchable` and `MStatementReplaceable` in action
2023-05-21 13:19:31 +02:00
Tristan B. Velloza Kildaire 2ed89d7244 MetaProcessor
- Added a future TODO for occurence of certain types that are alises (i.e. `size_t` appearing in a expression context like `sizeof(size_t)`
- Now that all `Container`-based types are `MStatementReplaceable` we no longer need this check
2023-05-20 20:23:33 +02:00
Tristan B. Velloza Kildaire c2a20b8af7 Struct
- Implemented the `search` method for `MStatementSearchable`
- Implemented the `replace` method for `MStatementReplaceable`

Clazz

- Implemented the `search` method for `MStatementSearchable`
- Implemented the `replace` method for `MStatementReplaceable`

BinaryOperatorExpression

- Implemented the `search` method for `MStatementSearchable`
- Implemented the `replace` method for `MStatementReplaceable`

Function

- Implemented the `search` method for `MStatementSearchable`
- Implemented the `replace` method for `MStatementReplaceable`

Variable

- Fixed the `replace` method implementation which had a bug that would never replace the node `VariableAssignment` inside of it

VariableAssignmentStdAlone

- Implemented the `search` method for `MStatementSearchable`
- Implemented the `replace` method for `MStatementReplaceable`

IfStatement

- Implemented the `search` method for `MStatementSearchable`
- Implemented the `replace` method for `MStatementReplaceable`

WhileLoop

- Implemented the `search` method for `MStatementSearchable`
- Implemented the `replace` method for `MStatementReplaceable`

ForLoop

- Implemented the `search` method for `MStatementSearchable`
- Implemented the `replace` method for `MStatementReplaceable`

Branch

- Implemented the `search` method for `MStatementSearchable`
- Implemented the `replace` method for `MStatementReplaceable`
2023-05-20 20:21:41 +02:00
Tristan B. Velloza Kildaire e1a9be3fdf Containers
- Inherit from `MStatementSearchable` and `MStatementReplaceable`
- Removed direct interface inheritance of `MStatementSearchable, MStatementReplaceable` and `MStatementReplaceable`, rely on `Container` now
2023-05-15 15:48:14 +02:00
Tristan B. Velloza Kildaire 5ec4b552db MetaProcessor
- Removed old code for testing `MStatementSearchable` and `MStatementReplaceable`
- Added note that we will have to investigate a recursive `MTypeRewritable` to be able to support things like `sizeof(size_t)`
- Implemented module-level `sizeof(<ident_type>)` support
- Added `Number`-kind of types support to `sizeOf_Literalize`(string)`

Containers (`Module`)

- Added `MStatementSearchable` and `MStatementReplaceable` support to `Module` container type

Data

- Added `MStatementSearchable` and `MStatementReplaceable` support to `Variable`
- Added `MStatementSearchable` and `MStatementReplaceable` support to `VariableAssignment`
- Work-in-progress for adding `MStatementSearchable` and `MStatementReplaceable` support to `FunctionCall`
- Added a note to return `false` in `DiscardStatement` if the statement to be replaced is us (the `DiscardSTatement`) ourselves

Test cases

- Updated the `meta/sizeof.t` test case
2023-05-15 15:09:58 +02:00
Tristan B. Velloza Kildaire a2cdbdbb1f MetaProcessor
- Disabled `sizeOf_Literalize` for now
- Search for all `FunctionCall` statements in `process(Container)`
2023-05-15 09:27:03 +02:00
Tristan B. Velloza Kildaire 3dcdaf0a8f Mcro
- Removed `Sizeof`, we will let it be parsed as a normal `FunctionCall` and then inspect in `MetaProcessor`
2023-05-15 09:25:23 +02:00
Tristan B. Velloza Kildaire 7c2848db8b MetaProcessor
- Accept a new argument to the `MetaProcessor(TypeChecker)` constructor indicating whether or not the `MetaProcessor` is enabled or not

TypeChecker

- Enable the `MetaProcessor`
2023-05-15 09:22:56 +02:00
Tristan B. Velloza Kildaire 2e0e70f0b4 MetaProcessor
- Removed unused `replace` method
2023-05-15 09:18:52 +02:00
Tristan B. Velloza Kildaire d6dfa38356 Parsing
- Added the ability to parse a `Repr` statement

Check

- Added `GENERIC_TYPE_DECLARE` and `REPR` as new `SymbolType`(s)

Data

- `DiscardStatement` now implements the `bool replace(Statement, Statement)` method

MetaProcessor

- Added the ability to replace statements that occur within any _other_ statements which implement `MStatementSearchable` and `MStatementReplaceable`

Test cases

- Added `meta/simple_meta_replace.t` to test all of this

Diagrams

- Added diagram on how the meta system works
2023-05-15 09:09:51 +02:00
Tristan B. Velloza Kildaire ade5f39173 Mcro
- Updated `MStatementReplaceable` to have its `replace(Statement, Statement)` method return a boolean `true` if the replacement was successful, else `false`
2023-05-10 08:59:53 +02:00
Tristan B. Velloza Kildaire 151c53770f Data
- Made `DiscardStatement` searchabe via implementing `MStatementSearchable`
- Added a stub override for implementing `MStatementReplaceable` in `DiscardStatement`
2023-05-10 08:25:49 +02:00
Tristan B. Velloza Kildaire 82a71c4b20 Mcro
- Made `Repr` implement `MStatementSearchable`
- Added new interface `MCloneable` to represent PNode's which are deeply-cloneable
2023-05-10 08:22:21 +02:00
Tristan B. Velloza Kildaire 7bd31ae770 MStatementSearchable
- Added documentation for `search(TypeInfo_Class)` method
2023-05-09 17:35:35 +02:00
Tristan B. Velloza Kildaire 2d9e19d433 MStatementReplaceable
- Implemented `replace(Statement thiz, Statement that)` which replaces the `Statement` in the first argument with that of the `Statement` in the second argument
2023-05-09 17:15:52 +02:00
Tristan B. Velloza Kildaire b62da5f48b MStatementSearchable
- Added method `search(TypeInfo_Class clazzType)` which uses a `TypeInfo_Class` to search for all types matching that (and which are sub-types of `Statement` and then adds these to a list and returns it in the form of `Statement[]`
2023-05-09 16:41:32 +02:00
Tristan B. Velloza Kildaire 11d592c0fb Mcro
- Redefined `MStatementSearchable`
- Added `MStatementReplaceable`
- Added `Repr` (a kind-of `Expression`) which will be used as an example to test out the aforementioned two interfaces
2023-05-09 09:27:58 +02:00
Tristan B. Velloza Kildaire 66d600277d Mcro
- Added interface type `MStatementSearchable`
2023-04-28 15:43:59 +02:00
Tristan B. Velloza Kildaire 263b69d8f1 Merge branch 'vardec_varass_dependency' into feature/meta_programming 2023-04-28 11:08:57 +02:00
Tristan B. Velloza Kildaire c65c41eed2
🧠 Feature: Direct function calls (#11)
* Test cases

- Added `simple_direct_func_call.t` to test direct function calls

* Test cases

- Removed tabs which broke lexing

* AST nodes

- `FunctionCall` now has the ability to be marked as statement-level by calling `makeStatementLevel()`, this can then be queried later via `isStatementLevelFuncCall()`

* Parser

- Statement-level function calls were never actually returned, resulting in `null` being returned by `parseName()` - this has now been fixed.
- Along with this we now "mark" this `FunctionCall` AST node as statement-level when it occurs in `parseName()`

* Instruction

- Allow `FuncCallInstr` to be makred as statement-level and queired much in the same manner as its corresponding AST-node/parser-node `FunctionCall`

* Dependency

- Added support for `DNode` generation in `generalPass()` for `FunctionCall` AST nodes

* TypeChecker

- Handle `FunctionCall`s differently in terms of code generation dependent on whether or not rhe call is within an expression of statement-level

* DGen

- Handle statement-level function calls (`FuncCallInstr`s) differently by tacking on an additional `";"` to the emit string

* - Added `simple_direct_func_call.t` to GitHub pipeline

* DGen

- Added instrumentation for semantic code generation for `simple_function_recursion_factorial.t`
- Added TODO for future `simple_func_call_direct.t`

Test cases

- Added `simple_function_recursion_factorial.t` to test recursion

Pipelines

- Added `simple_function_recursion_factorial.t` to `emit` stage

* DGen

- Made `if` an `else if` - this wouldn't of affected anything but just to be correct

* DGen

- Added semantic code generation instrumentation for test case `simple_direct_func_call.t`

Test cases

- Updated test case `simple_direct_func_call.t`
2023-04-28 11:03:46 +02:00
Tristan B. Velloza Kildaire c46fc1a07c Mcro
- Added interface `MTypeRewritable` to represent any AST node which has a `setType(string)` and `string getType()` method for rewriting- Added `Sizeof` which is a kind-of `IntegerLiteral`

Data

- Made `TypedEntity` implement the `MTypeRewritable` interface

Expressions

- Made `IntegerLiteral` non-final such that we can inherit from it
- Added a final `setNumber(string)` method to `NumberLiteral` to update the literal

MetaProcessor

- The type rewriting mechanism now operates on `MTypeRewritable` AST nodes
- Work has begun on `sizeOf_Literalize(Sizeof)` which is to determine the `Type` of the `Sizeof` statement and then calculate the memory width and update its literal (as it is a kind-of `NunberLiteral`) to said size

Test cases

- Added `meta/sizeof.t` to test `sizeof` functionality
2023-04-24 12:05:26 +02:00
Tristan B. Velloza Kildaire 109d7cd1c9 MetaProcessor
- Added another FIXME
2023-04-24 10:51:01 +02:00
Tristan B. Velloza Kildaire 336fc509d6 MetaProcessor
- Updated the constructor to only take in an instance of the `TypeChecker`
- Updated the `process()` method to take in a `Container` such that it can be used recursively
- Commented code
- Added a recursive call to `process(Container)` when `curStmt` is a kind-of `Container` (this ensures that we reach the `VariableParameter`s of `Function` (die to them making up the `Statement[]` of `Function` type)
- Removed unused `cmp` import `std.string`
- Added type-rewrite for `ssize_t` -> `long`

TypeChecker

- Updated the constructor call to `MetaProcessor` to use its new API
- Updated call to `process()` to now be `process(modulle)`

Test cases

- Updated `types.t` to test re-writing of the `Function`'s parameters
2023-04-24 10:33:08 +02:00
Tristan B. Velloza Kildaire 07b637f38e MetaProcessor
- Added a type-re-writing facility via `typeRewrite(TypedEntity)` which will re-write the types such as `size_t`, `ssize_t` and so forth

Test cases

- Added a test case `meta/types.t` which tests this
2023-04-24 09:03:38 +02:00
Tristan B. Velloza Kildaire c0bc9580db TypedEntity
- Added a `setType(string)` method to update the internal `type` field
2023-04-24 09:02:34 +02:00
Tristan B. Velloza Kildaire 94d6b07b51 MetaProcessor
- Added the `MetaProcessor`

TypeChecker

- Added the `MetaProcessor` instance to the `TypeChecker`, it will be instantiated upon the `TypeChecker`'s construction and later have its `.process()` method called as the first call in `beginCheck()`
2023-04-24 08:51:42 +02:00
Tristan B. Velloza Kildaire e6d474090c Symbols
- Added new `Statement`-based type: `Macro` to support `Macro`(s)
2023-04-24 08:49:51 +02:00
Tristan B. Velloza Kildaire 3a06c49fe3 Parser
- Added new interface `Cloneable`
2023-04-24 08:45:09 +02:00
Tristan B. Velloza Kildaire a4c010f27f
🐞️ Functions: Return position enforcement (#6)
* Parser

- Added a TODO in `wantsBody == true` case in `parseFuncDef()` to check for the return keyword's position

* Parser

- Added a check in `parseFuncDef()` which, is a `ReturnStmt` is found, then crash the parser if it is found anywhere besides the last statement

* Test cases

- Added test cases to test the `return` statement position enforcement
2023-04-21 15:29:53 +02:00
Tristan B. Velloza Kildaire dad185f96f
🐞️ isSameType: Add a base case (#8)
* Core

- Added a TODO where we are meant to insert the fallback check in `isSameType(Type t1, Type t2)`

* TypeChecker

- Added backported `isSameType(Type 1, Type t2)` fix for #114
2023-04-21 15:23:24 +02:00