Commit Graph

1022 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire 4921141a9e Data
- Nah screw this
2024-03-18 17:49:44 +02:00
Tristan B. Velloza Kildaire 4f14efb720 Container
- Added
2024-03-18 17:49:33 +02:00
Tristan B. Velloza Kildaire a03b2b58df Merge branch 'vardec_varass_dependency' into feature/container_methods 2024-03-18 15:29:58 +02:00
Tristan B. Velloza Kildaire 7a2ea96140 Containers
- Added a TODO
2024-03-18 15:28:48 +02:00
Tristan B. Velloza Kildaire 9f9cc8a9ef Container
- Added new methods
2024-03-18 15:25:51 +02:00
Tristan B. Velloza Kildaire 48f078077b Container
- Documented
2024-03-18 15:05:17 +02:00
Tristan B. Velloza Kildaire 4424043ccb Parser
- Fixed the parsing of bodies of structs and classes. Previously they would call `parseName()` when hitting a `SymbolType.IDENT_NAME` however this would allow assignments and function calls, we don't want this. Switched to `parseTypedDeclaration()` + checking the symbol left in lexer after it (ensuring it was a semicolon) and then consuming it)
2024-02-29 19:41:38 +02:00
Tristan B. Velloza Kildaire df6dfe14d0
🧹🧼 Cleanup: Pool provider (#33)
* IPoolManager

- Added new interface

* Pool

- Added missing imports

* IPoolManager

- Moved to the `interfaces` module

* IPoolManager

- Updated API to take in a `DNodeGenerator` as the first argument to `pool(..., ...)`

* Revert "IPoolManager"

This reverts commit 4f92a29da2.

* PoolManager

- Added an implementation of the `IPoolManager` interface

* DNodeGenerator

- Now constructs a new `IPoolManager` on constructions

* IPoolManager

- Added a templatised variant of the `pool(Statement)` method

* PoolManager

- Added a templatised variant of the `pool(Statement)` method
- The `pool(Statement)` method now uses the `poolT!(DNodeType, EntityType)(EntityType)` method

* IPoolManager

- Removed the templatised `poolT!(DNodeType, EntityType)(EntityType)` method
- Added `poolExpression(Expression expression)`
- Added `poolVariable(Variable variable)`
- Added `poolStaticVariable(Variable variable)`
- Added `poolFuncDec(Function func)`

* IPoolManager

- Removed uneeded import

* PoolManager

- Removed the templatised `poolT!(DNodeType, EntityType)(EntityType)` method
- Implemented `poolExpression(Expression expression)`
- Implemented `poolVariable(Variable variable)`
- Implemented `poolStaticVariable(Variable variable)`
- Implemented `poolFuncDec(Function func)`

* ExpressionDNode

- No longer takes in a `DNodeGenerator`

AccessDNode

- No longer takes in a `DNodeGenerator`
- Save the incoming `Entity`
- Updated `initName()` to use the `toString()` of the `Entity`

ClassVirtualInit

- No longer takes in a `DNodeGenerator`
- Save the incoming `Clazz`
- Updated `initName()` to use the `toString()` of the `Clazz`

ClassStaticNode

- No longer takes in a `DNodeGenerator`
- Save the incoming `Clazz`
- Updated `initName()` to use the `toString()` of the `Clazz`

ObjectInitializationNode

- No longer takes in a `DNodeGenerator`

VariableNode

- No longer takes in a `DNodeGenerator`
- Updated `initName()` to use the `toString()` of the `Variable`

FuncDecNode

- No longer takes in a `DNodeGenerator`
- Updated `initName()` to use the `toString()` of the `Function`

ModuleVariableDeclaration

- No longer takes in a `DNodeGenerator`
- Updated `initName()` to use the `toString()` of the `Variable`

StaticVariableDeclaration

- No longer takes in a `DNodeGenerator`
- Updated `initName()` to use the `toString()` of the `Variable`

VariableAssignmentNode

- No longer takes in a `DNodeGenerator`
- Updated `initName()` to use the `toString()` of the `VariableAssignment`

* PoolManager

- No longer takes in a `DNodeGenerator` for its constructor
- We no longer require it
- No longer pass a `DNodeGenerator` to the `DNodeType(...)`s created in `poolT!(...)(...)`

PoolManager (unittests)

- Updated unittests

* Depencency (module)

- The `addFunctionDef(...)` method now takes in an extra first argument which is the `IPoolManager` it
should use when it constructs its `DFunctionInnerGenerator`

DNode

- Removed the `DNodeGenerator` instance (i.e. the `dnodegen` field)
- Removed the `Resolver` instance (i.e. the `resolver` field)
- Calling `pool(Statement entity)` will now forward that call to the `IPoolManager`'s `pool(Statement)`
- Calling `DNodeType poolT(DNodeType, EntityType)(EntityType entity)` will now forward that call to the `IPoolManager`'s `pool(Statement)` with the correct types decided at compile-time using static if's
- `objectInitialize(Clazz clazz, NewExpression newExpression)` now constructs a `ObjectInitializationNode` with
its new API
- `pool_module_vardec(Variable entity)` now constructs a `ModuleVariableDeclaration` with its new API
- When `generalStatement(Container c, Context context, Statement entity)` comes across a function definition
(i.e. a `Function`) and has to add its function definition it now uses the updated `addFunctionDef(...)`
- `poolClassStatic(Clazz clazz)` now constructs a `ClassStaticNode` with its new API

DFunctionInnerGenerator

- Constructor now accepts an `IPoolManager` instance

DNodeGenerator

- Constructor now accepts an `IPoolManager` instance
- We now use the `IPoolManager` as our pooling mechanism

* TypeChecker

- When we call `dependencyCheck()` we now first construct the pooling mechanism we want to use
by constructing some kind-of `IPoolManager`, we then pass this to the constructor for the
`DNodeGenerator`

* IPoolManager

- Added `poolModuleVariableDeclaration(Variable variable)`

* PoolManager

- Impemented `poolModuleVariableDeclaration(Variable variable)`

* DNodeGenerator

- `pool_module_vardec(Variable entity)` now calls `poolModuleVariableDeclaration(Variable)` from `IPoolManager`
- Removed the static `nodePool`

* IPoolManager

- Added some stuff

* IPoolManager

- Nah, removed that

* IPoolManager

- Added `poolClassStatic(Clazz clazz)`

* PoolManager

- Implemented `poolClassStatic(Clazz clazz)`

* DNodeGenerator

- Calling `poolClassStatic(Clazz clazz)` now calls `IPoolManager`'s `poolClassStatic(Clazz)`

* IPoolManager

- Documented module

* PoolManager

- Documented module

* Merge branch 'vardec_varass_dependency' into feature/poolmngr
2024-02-27 10:30:34 +02:00
Tristan B. Velloza Kildaire c55cd74596
🧹🧼 Cleanup: addFuncDef/clearFuncDefs should all use a non-static pool (#34)
* IFuncDefStore

- Added new interface

* FuncDefStore

- Implemented new `IFuncDefStore` type

* FuncDefStore

- The constructor now takes in a `TypeChecker` instance
- Implemented `addFunctionDef(Function func)`

* FuncDefStore

- Added a TODO + some code for a future naming setup I want to se

* IPoolManager

- Added documentation
- Added new method `grabFunctionDef(string name)` to the API

* FuncDefStoreException

- Added new exception type

* IPoolManager

- Added more docs for `grabFunctionDef(string name)`

* FuncDefStore

- Pass in ourselves (a `IFuncDefStore`) into the `DFunctionInnerGenerator` when adding a function definition
- Implemented `grabFunctionDef(string name)` from the updated `IFuncDefStore` API

* DNodeGenerator

- Constructor now takes in a `IFuncDefStore`
- When we encounter a `Function` we will add it to the store of function definitions
by using the new `IFuncDefStore` (instead of the old `addFunctionDef(TypeChecker, Function)`
- Removed unused method `saveFunctionDefinitionNode(DNode funcDefNode)`
- Removed unused method `retrieveFunctionDefinitionNode(string functionAbsolutePath)`
- Removed the old method `addFunctionDef(TypeChecker tc, Function func)` (as we are now using the `IFuncDefStore`)
- Removed the `clearFuncDefs()` as we are now using the `IFuncDefStore`
- Removed the `grabFunctionDefs()` as we are now using the `IFuncDefStore`
- Removed the `FunctionData[string]` as we are now using the `IFuncDefStore`

DFunctionInnerGenerator

- Constructor now takes in a `IFuncDefStore`

* TypeChecker

- `dependencyCheck()` no lomger calls the removed `clearFuncDefs()` from the `dependency.core` module
- `dependencyCheck()` now constructs a new `IFuncDefStore` and then passes it into the `DNodeGenerator`
when dependency generation needs to occur

* IFuncDefStore

- Added module-level documentation

* FuncDefStore

- Documented class
- Documented module

* FuncDefStoreException

- Documented constructor and class

* IFuncDefStore

- `addFunctionDef(Function func)` may now throw a `FuncDefStoreException` when you add a function that already exists

* FuncDefStore

- `addFunctionDef(Function func)` now throws a `FuncDefStoreException` when you provide a `Function` that has already been added

* IFuncDefStore

- Moved import to the top

* FuncDefStore

- Cleaned up
2024-02-27 09:33:18 +02:00
Tristan B. Velloza Kildaire ee537f2b25
Feature: Lexer improvements (#18)
* Created brsnch

* Created brsnch (removed placeholder)

* Lexer

- Added tab handling for the presence such as spaces would be in.
- Added unit tests for the new tab processing
- Resolved issues where whitepsace was allowed before and or after the
  '.' character
- Renamed isSpliter to isSplitter
- Some Code styling

* Check

- Added two new `SymbolType`s for comments
- `SINGLE_LINE_COMMENT` (for `//`) and `MULTI_LINE_COMMENT` (for `/*`)

* Parser

- Added a bogus `parseComment()` which returns nothing, prints out the comment, consumes the `Token` and returns
- `parseStatement()` now supports `parseComment()` whenever a single-line or multi-line comment is detected

* Parser

- Fixed token consumption code in `parseComment()`

* BasicLexer

- Fixed style mishaps

* ArrLexer

- Implemented dummy lexer

* Parser

- Added some comment related functions (for testing)
- Added `pushComment(Token)`, `hasCommentsOnStack() and `getCommentCount()`
- `parseComment()` now pushes the current comment-based `Token` onto the comment-stack
- Added a comment stack

Unit tests

- Added testing for various examples of comment-type `Token`s

* Lexer
- Replaced the characters with Enumerated type
- Working Comment lexing, single and multiline
- Working escape codes for strings
- Working Signage and Size Encoder indicators

- Removed floatMode in favour of float lexing function
- Added doComment for the comment lexing instead of comment mode
- Added doEscapeCode for escape codes in string

Testing
- Added unit tests for comments
- Added unit tests numerical encoders
- Added unit tests numerical encoders

TODO
- ADD unit tests for all valid escape sequences and some invalid

* Lexer
- Removed stringMode in favour of soString

TODO
- Decide on miltiline strings, currently not supported

* Parser

- Test comments which appear at a non-Module but rather statement lavel

* Parser

- Changed to using `BasicLexer` for comment tests now seeing as it is now implemented therein

* Basic

- Added `roll()` and `shourt()` to mark unittests

* Basic

- `shout()` now adds line number to print out

* Lexer rewrite
- flush
- underscores in numbers
- escape codes
- character escapes
- bug fixes

* Basic

- Fixed `shourt(int)`

* Basic

- Remved crashing (on purpose_ unittest

* Resolved bug where isSplitter evaluated to true every time

* Basic

- Removed `goggaWithLineInfo(...)`

* Basic

- Updated `shout()` to remove rolling
- Removed `roll()`
- Added function and module name as well

* Basic

- Documented `shout()`

* Lexer Done and 100% coverage

* LexerSymbols

- Documented
- Formatted

* Lexer (module)

- Added `LS` alias
- Added `isOperator(char c)`, `isSplitter(char c)`, `isNumericalEncoder_Size(char character)`, `isNumericalEncoder_Signage(char character)` and `isValidEscape_String(char character)`

* BasicLexer

- Documented constructor `hasToken()`, `performLex()`, `doIdentOrPath()`, `doChar()`, `doString()`, `doComment()`, `doEscapeCode()`, `doNumber()`, `doEncoder()`, `doFloat()`, `flush()`, `buildAdvance()`, `improvedAdvance()`, `advanceLine()`, `isOperator(char)`, `isSplitter(char)`, `isValidDotPrecede(char character)`, `isNumericalEncoder(char character)`, `isNumericalEncoder_Size(char character)`, `isNumericalEncoder_Signage(char character)` and `isValidEscape_String(char character)`
- Tried reformatting some of `doChar()`, `doString()`, `flush()`, `buildAdvance()`, `improvedAdvance()`, `advanceLine()`, `isOperator(char)`, `isSplitter(char)`

* Basic

- Removed `LS` alias

Lexer

- Made `LS` alias public

* BasicLexer

- Removed methods `isValidEscape_String(char character)`, `isNumericalEncoder_Signage(char character)`, `isNumericalEncoder_Size(char character)`, `isNumericalEncoder(char character)`, `isSplitter(char c)` and ` isOperator(char c)`

Lexer

- Added method `isNumericalEncoder(char character)`

* BasicLexer

- Documented `isValidDotPrecede(char character)`

* Lexer

- Added method `isValidDotPrecede(char character)`

* BasicLexer

- Removed method `isValidDotPrecede(char character)`

* BasicLexer (unittests)

- Documented the unittests
- Fixed formatting

* BasicLexer

- Typo fixes

* BasicLexer (unittests)

- Only compile-in `shourt(...)` when in unittest build mode

* BasicLexer

- Documented `isForward()` and `isBackward()`
- Made `isBackward()` private

---------

Co-authored-by: GMeyer <21568499@sun.ac.za>
Co-authored-by: GMeyer <gustav.meyer1999@gmail.com>
2023-12-27 08:18:17 +02:00
Tristan B. Velloza Kildaire 4c3a72b026 Pipelines
- Run `apt update` before doing an `apt install`
2023-12-08 18:27:42 +02:00
Tristan B. Velloza Kildaire 472ca36141 Pipelines
- Cleaned up
2023-09-24 18:10:18 +02:00
Tristan B. Velloza Kildaire c40cecf077 Pipelines
- Wrap in `""`
2023-09-24 18:07:46 +02:00
Tristan B. Velloza Kildaire 52d04de0b2 Pipelines
- Try this
2023-09-24 18:06:47 +02:00
Tristan B. Velloza Kildaire 202d7988d4 Pipelines
- Does this even work?
2023-09-24 18:05:18 +02:00
Tristan B. Velloza Kildaire c681206cef Pipelines
- Manually specify branches to run on for pull requests
2023-09-24 18:04:18 +02:00
Tristan B. Velloza Kildaire efb093319f Pipelines
- Try get builds to ALWAYS run on ANY branch AND for any pull requests
2023-09-24 18:03:22 +02:00
Tristan B. Velloza Kildaire e878ad4c90
Try fix Coveralls 2023-09-02 19:55:53 +02:00
Tristan B. Velloza Kildaire e1d034cbe0
🐞️ Bugfix: Module-level static members may cause consecutive compilation errors (#30)
* Compiler

- Re-enabled compilation tests (partially)

* Dependency

- Fixed comment
- Implemented `clearFuncDefs()`

* TypeChecker

- Clear the `FunctionData[string]` table after a batch of typechecking/codegen such that we don't have lingering data from previous compilations which gets reliniearzed resulting in an exception being thrown as it was marked as linearized from its first time from a previous compilation

* Compiler

- Re-enabled unit tests for compilation
- Added TODO relating to adding failing test cases as well

* Compiler

- Added unit test for failing tests

* TypeCheck

- Use a scopre guard to call `clearFuncDefs()` such that it is called even when exceptions are thrown during depgen, typecheck/codegen ensuring we have it cleared for the next run

* Compiler

- Added `gibeFileData(string)` to easily read the source text
- Added all `typecheck` (good and bad) tests

* Pipelines

- Updated name

* Compiler (unittests)

- Re-ordered the test cases
- Commented them out

* Compiler

- Added documentation for `gibFileData(string)`
- Made `gibFileData(string)` private

* Compiler (unit tests)

- Documented unit test

* Compiler

- Cleaned up imports

* Compiler (unit tests)

- Added TODO
- Added spacing
2023-08-27 12:53:18 +02:00
Tristan B. Velloza Kildaire 16caf6ebec
Update d.yml 2023-08-21 14:57:12 +02:00
Tristan B. Velloza Kildaire f62ec5667f
Update README.md 2023-08-21 14:41:22 +02:00
Tristan B. Velloza Kildaire 8831ea51de
Update d.yml 2023-08-21 14:38:19 +02:00
Tristan B. Velloza Kildaire a60ce2a66f
Update d.yml 2023-08-21 14:36:07 +02:00
Tristan B. Velloza Kildaire e66b7750ab
Update d.yml 2023-08-21 14:33:58 +02:00
Tristan B. Velloza Kildaire ef9a461de2
Update d.yml 2023-08-21 14:33:12 +02:00
Tristan B. Velloza Kildaire 706d5053db
Update d.yml 2023-08-21 14:30:20 +02:00
Tristan B. Velloza Kildaire a8e3dae81f
Update d.yml 2023-08-21 14:25:38 +02:00
Tristan B. Velloza Kildaire 1b9b688337
Update d.yml 2023-08-21 14:23:20 +02:00
Tristan B. Velloza Kildaire 8201718774
Update d.yml 2023-08-21 14:22:04 +02:00
Tristan B. Velloza Kildaire 2417a5afe8
Update d.yml 2023-08-21 14:20:15 +02:00
Tristan B. Velloza Kildaire 3cf280d128
Update d.yml 2023-08-21 14:18:19 +02:00
Tristan B. Velloza Kildaire d226cdf761
Update d.yml 2023-08-21 14:17:03 +02:00
Tristan B. Velloza Kildaire caaf5ff4c4
Update d.yml 2023-08-21 14:14:55 +02:00
Tristan B. Velloza Kildaire 02fe3347eb
Update d.yml 2023-08-21 14:12:32 +02:00
Tristan B. Velloza Kildaire f7a8631729
Update d.yml 2023-08-21 14:10:50 +02:00
Tristan B. Velloza Kildaire c1da2e6296 DGen
- Removed now-completed NOTE comment
- Print out the C compiler being used
2023-08-20 15:28:05 +02:00
Tristan B. Velloza Kildaire 12daee5c44 DGen
- Lookup the value of `dgen:compiler` from the config and use that as the C compiler

Configuration

- Set default value of `dgen:compiler` to `"clang"`

Commands

- Added a command to specify the C compile to use
- Transfer `-cccompiler`/`-cc` over to a config entry
2023-08-20 15:26:54 +02:00
Tristan B. Velloza Kildaire ef0c817217 DGen
- Instead of returning the generated C emit code, set it in a local scope but at the highest scope variable `emmmmit`
2023-08-17 08:46:59 +02:00
Tristan B. Velloza Kildaire fd31024a07 Compiler
- Now lookup `dgen:mapper` instead of `emit:mapper`

Configuration

- Now set `dgen:mapper` to `hashmapper` instead of `emit:mapper`
- Added `dgen_preinline_args` and set it to `false`

Commands

- Updated description for `symbol-mapper`/`sm` flag
- The `symbol-mapper`/`sm` flag now affects the `dgen:mapper` entry instead of the `emit:mapper` entry
- Transfer the flag value of `preinlineArguments`/`pia` to the `dgen:preinline_args` entry
2023-08-16 15:51:53 +02:00
Tristan B. Velloza Kildaire e5b0f4e0a1 Resolution
- Removed swear words
2023-08-16 11:10:02 +02:00
Tristan B. Velloza Kildaire 2ed7e9f490 Dependency
- Removed debug print as this is done
2023-08-16 11:09:03 +02:00
Tristan B. Velloza Kildaire a4c9a6cc27 Dependency
- Removed swear words
2023-08-16 11:08:20 +02:00
Tristan B. Velloza Kildaire d7b9a89552
🧹🧼 Hotfix: VariableExpression dependency node generaiton (#26)
* Dependency

- Removed crap for `VariableExpression` dependency node generation
- This is a work-in-progress clean up

* Dependency

- Added some comments

* Dependency

- Avoid path hopping by making this beanch constantly `true`

* Dependency

- Cleaned up some more, added link to issue regarding context sets

* Dependency

- Don't fetch-and-set context for `bruh` (the entity being referenced)

* Dependency

- Removed path-hopper code

* Dependency

- Checking iets

* Dependency

- Undid checking-iets

* Dependency

- Checking iets (fr)

* Revert "Dependency"

This reverts commit 5ddab9dd3d.

* Dependency

- No need to set it here if set above

* Dependency

- Removed no-op branch

* Dependency

- Cleaned up some more

* Dependency

- Refactored code

* Dependency

- Cleaned up
2023-08-16 10:50:57 +02:00
Tristan B. Velloza Kildaire 3d9bf28f3b Merge branch 'vardec_varass_dependency' of github.com:tbklang/tlang into vardec_varass_dependency 2023-08-14 22:30:26 +02:00
Tristan B. Velloza Kildaire 5e4049ffee
Hotfix/jcli upgrade fix (#25)
* Dub

- Upgraded `jcli` to version `0.25.0-beta.2`

* Dub

- Upgtraded package `jcli` to version `0.25.0-beta.3`

* - Try using latest version of `dmd`
2023-08-14 22:29:52 +02:00
Tristan B. Velloza Kildaire ef29cf018d - Try using latest version of `dmd` 2023-08-14 22:21:46 +02:00
Tristan B. Velloza Kildaire 330d0a2d96 Dub
- Upgtraded package `jcli` to version `0.25.0-beta.3`
2023-08-14 22:12:28 +02:00
Tristan B. Velloza Kildaire e2d54f1cb1 Dub
- Upgraded `jcli` to version `0.25.0-beta.2`
2023-08-10 22:55:44 +02:00
Tristan B. Velloza Kildaire b47a651caf
🧠️ Feature: Universal coercion and type enforcer (#9)
* TypeChecker

- Added `bool isSameType2(Value v1, Value v2, bool attemptCoercion = false)` for future implementation of universal coercion as per #115

* TypeChecker

- Renamed `isSameType2` to `typeEnforce`
- Updated `typeEnforce`'s default parameter documentation from `false` to `attemptCoercion` (as it should have been in the beginning)

* TypeCheckerException

- Save the `TypecheckError` coming in as `errType` and make it available via `getError()`

TypemMismatchException

- Save the original (expected) and attempted types and make them available via `getExpectedType()` and `getATtemptedType()` respectively

* TypeChecker

- Updated `typeEnforce` from taking in `Value v1, Value v2, bool` to `Type t1, Value v2, bool`.
- `typeEnforce()` will now extract the `Type` of `Value v2` and call `isSameType(t1, t2)`, if that fails and coercion is allowed then it is attempted, however if that fails then it causes an exception to be thrown. In the case coercion is not allowed, then a `TypeMismatchException` is thrown

Unit tests

- Tested the new `typeEnforce(Type t1, Value v2, bool)` and it seems to work, both a case of failing matching (coercion disallowed) and working coercion (coercion allowed)

* TypeChecker

- Documented existing unittest for `typeEnforce(Type, Value, bool)`
- Added new unit test for `typeEnforce(Type, Value, bool)` which tests when the types ARE the same

* TypeChecker

- Cleaned up `typeEnforce(Type, Value, bool)`

* TypeChecker

- Added a work-in-progress unit test to test how I would use `typeEnforce(Type t1, Value v2, bool coercion = false)` in practice
- Added TODOs in `attemptCoercion(Type, Type)` where I must add support

* TypeChecker

- Finished the unit test testing out the usage for `typeEnforce(Type, Value, bool coerce = false)`
- Added TODOs to `attemptCoercion(Type, Value)` for the changes required to it

* TypeChecker

- Removed incorrect TODOs from `attemptCoerce(Type, Value)` and updated the message when the coercion fails

Unit tests

- Updated first unit test for `typeEnforce()` to test failing coercion on a non-`LiteralValue` instruction
- Added a unit test where `typeEnforce()` WILL pass as it coerces a `LiteralValue` instruction

* Exceptions (`typechecker`)

- Added new exception type `CoercionException` to be thrown whenever a coercion cannot take place.

* TypeChecker

- Ensure that `attemptCoercion(Type, Value)` only throws instances of `CoercionException`

* Unit tests

- Fixed failing-coercion check by catching the correct exception when it fails `CoercionException` instead of `TypeMismatchException`)

* TypeChecker

- Added documentation for `isSameType(Type t1, Type t2)`

* TypeChecker

- Updated documentation for `isCoercibleRange(Type, Value)`
- Updated `attemptCoercion(Type, Value)` with new documentation and renamed parameters

* Unit tests (typechecker)

- Added comments

* TypeChecker

- Removed now-completed TODO in `typeEnforce(Type t1, Value v2, bool allowCoercion = false)`

* TypeChecker

- Removed unused `typeStatus` variable in `typeEnforce(Type, Value, bool)`

* TypeChecker

- Variable declarations (with assignments) now use the `typeEnforce()` method with coercion allowed in order to do the type checking and coercion changes
- Added a comment explaining a certain branch of `attemptCoercion(Type, Value)`

* TypeChecker

- If the to-type and provided-type are both numerical then use a size-based test

Test cases

- Added two test cases which test `typeEnforce()` on incoming `Value`-based instructions as part of variable declarations

* Test cases

- Fixed negative test case - it MUST have an error and that should be seen as a pass

* TypeChecker (unit tests)

- Disabled invalid unit test (marked for re-writing)
- I should re-write the below. It is now incorrect as I DO ALLOW coercion of non literal-based instructions now - so it fails because it is using an older specification of TLang

* TypeChecker

- Migrated the type checking of standalone variable assignments to using `typeEnforce()`

Test cases

- Added positive and negative test cases

* - Updated `.gitignore`

* Feature/type enforcer cast instr emit (#13)

* TypeChecker

- `typeEnforce()` now will not change the type of `Value`-based instruction `v2` but rather return, on successful coercion set a `ref`-based argument to a new instance of a `CastedValueInstruction`, if coercion fails or was disabled and types mismatched then an exeption is thrown as normal.
- If the types are an exact same match, a-la `isSameType(Type, Type)`, then this `ref` value is set to `v2` (makes programming easy) else we would have no way to know
- `attemptCoerce()` now, to go with the above changes to `typeEnforce()`, returns a `CatsedValueInstruction` to the to-type on successful coercion, else an exception is thrown as usual
- Updated two cases of `typeEnforce()` usage to the new method signature, also now add a sanity check assertion that the types now DO match as they should

* TypeChecker

- We need not set it again, look the value we use when we CALL `typeEnforce()` is that of the `fromInstruction` and if no changes occur we still have it, it is fine - if it changes via the call to `typeEnforce()` via the `ref` based argument thne same old
- No need for us to set it here in the event of no changes, we are writing back the exact same Instruction/object-reference

* TypeChecker (unit tests)

- Upgraded to the new `typeEnforcer()` method signature

* TypeChecker

- Improved documentation for `typeEnforce()`

* TypeChecker

- Added TODO regarding pointer coercion with integers in `Pointer + Integer` case (for pointer airthmetic)

* TypeChecker

- Added a new branch which currently throws an exception as it is unimplememted
- This branch (above) is in `attemptCoercion()` and is to handle the coercion of `Integer` to `Pointer` for pointer arithmetic
- When doing the typechecking/codegen for `BinaryOp`, disable the pointer coercion call to `attemptPointerAriehmeticCoercion()`, instead now make calls in those cases they apply, to `typeEnforce()`

- The above stuff is still broken, not yet implemented.

* TypeChecker

- Cannot use cast as that can return false positives for an all pointer case as all `Pointer`s are `Integer`s
- Added `isPointerType(Type)` to check the above
- Added then also `isIntegralTypeButNotPointer(Type)` which checks for an `Integer` type but excluding if it is a `Pointer`
- Updated the checks in the `BinaryOperator` branch of `typeCheckThing(DNode)` to do this

* TypeChecker

- Need to do the `Pointer` checks first in `attemptCoercion(Type, Value)`

* TypeChecker

- `attemptCoercion(Type, Value)` now returns a `CastedValueInstruction` to cast the `Integer` type to the `Pointer` type

* TypeCHecker

- Catch mis use of type enforcement by using `isIntegralTypeButNotPointer(Type)` and isPointerType`(Type)` for the previous commit

* TypeChecker

- Refresh the types after the potential calls to `typeEnforce(..., ..., ..., ...)`

* Pipeline

- Use `set -e` for `simple_pointer.t` test in emit stage

* Pipelines (emit stage)

- Previous compilation may have succeeded, meaning ./tlang.out never gets updated and exits fine with 0, but we only use the last commands exit status to check for a pass for a test.
- By setting this if COMPILATION fails then we exit with its code and the test status is set via that

* Pipelines

- Removed the `set -e` code as the correct `Exception` now causes a non-zero exit code from the changes made in `varass_vardec_dependency`

* DGen

- Added notice for issue #140

* TypeChecker

- Made `isIntegralTypeButNotPointer(Type)` public
- Made `isPointerType(Type)` public

* Instructions

- `CastedValueInstruction` now is unrelaxed by default but can be set (tis aids in how it can be emitted later for issue #140)

* DGen

- Added some checks for certain conditions whereby pointer coercion requires relaxing the casted operands (coerced operands)

* DGen

- Relax `CastedValueInstruction`(s) when appropriate in `BinaryOpInstr` handling code
- Removed panics

* DGen

- Added relaxation support to the code emitting code for `CastedValueInstruction`

* DGen

- make debug messages for when relaxation occurs for `CastedValueInstruction` emitting more clear

* TypeChecker

- Implemented `biggerOfTheTwo(Integer, Integer)` which determines the biggest of the two `Integer`-based types and returns that one.

* TypeChecker

- Fixed incorrect variable name in `biggerOfTheTwo(Integer, Integer)`

* TypeChecker

- Throw an error in the case where a `BinaryOperatorExpression` occurs with non-`Integer`-based instructions (at least for now)

* TypeChecker

- If both types are `Integral` (but not `Pointer`) then smaller coerces to bigger, if they however are equal then signed coerces to unsigned

* TypeChecker

- Removed now irrelevant comment

* TypeChecker

- Don't throw exception here, rather let the `isSameType(Type, Type)` check handle that
- We still keep the warning we print about missing cases implementation-wise

* TypeChecker

- Fixed explanation

* TypeChecker

- Marked related issue

* TypeChecker

- Implemented ` isStackArrayType(Type typeIn)`
- WIP: Added a check for handling `StackArray -> Pointer` coercion to `attemptCoercion(Type, Value)`

* TypeChecker

- `attemptCoercion(Type, Value)` will now ensure firstly that the `StackArray`'s component type matches that of the `Pointer`'s referred type, if not throw an exception, if so, then return a `CastedValueInstruction`

* TypeChecker

- Print out a debug message when attempting to coerce a `StackArray` to a `Pointer`
- Fixed the error message thrown when a `StackArray` could not be coerced to a `Pointer` due to the component type != ptr's referred type
- `FunctionCall` handling now has the `canCoerceStackArray()` code disabled and uses the `typeEnforce()` method

* TypeChecker

- Type checking code for `FunctionCall`

* TypeCheck

- Completed TODO comment

* TypeChecker

- Added a TODO

* TypeChecker

- Added FIXME where the `typeEnforce()` call need to be made for the `ReturnStmt`'s return expression's type to match or be checked-against the containing `Function`'s

* TypeChecker

- `ReturnStmt` now uses `typeEnforce()`

* Test cases

- Added two new checks for checking the return type of a function and matching a `ReturnStmt`'s expression's type to it

* TypeChecker

- Removed assertion check, rather let the exception thrown handle the error
- Only after we know the finally-parenting `Container` is a `Function` (should we reference `funcContainer`

* Test cases

- Removed explicit cast from `simple_function_recursion_factorial.t`

* TypeChecker

- If we have a `LiteralValue` and a non-`LiteralValue` then coerce the `LiteralValue` towards the non`-LiteralValue` via `typeEnforce()`
- This should allow the correct range checking of literal values within the range of the to-type and not require annoying explicit casts

* Test cases

- Removed now-unneeded explicit casts on literal values in `simple_function_recursion_factorial.t`

* TypeChecker

- Added comment describing the process used
- Removed now-completed TODO

* TypeChecker

- Removed some dead code
- Removed now-completed FIXME/TODO

* TypeChecker

- Removed old type checking code for variable declarations with assignments
- Removed old type checking code for standalone variable assignments
2023-08-10 19:42:11 +02:00
Tristan B. Velloza Kildaire 239832a74a Variable
- When calling `replace(Statement, Statement)`, if we hit the `variableAssignment` replacement check, first check and ensure it is not null`, try
2023-07-26 16:19:49 +02:00