Commit Graph

88 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire 5f81ac41db Pipelines
- Fixed Ubuntu APT issue
2024-04-24 14:34:41 +02:00
Tristan B. Velloza Kildaire ef78a15ae9
Feature: Multi-module support (#31)
* Parser

- `findModulesInDirectory(string directory)` now replaces all the `/` with `.`'s

* ModMan

- Added stub `ModuleManager`

* ModuleManager

- Added `validate(string searchPath)`
- Added `validate(string[] searchPaths)`
- Added a constructor

ModMan (unitests)

- Added a positive unittest

* ModMan (unittests)

- Added negative test case example

* ModMan

- Moved to new package

* ModMan

- Added exception class

ModuleManager

- Throw an exception ( a `ModuleManagerError`), if one of the search paths is invalid during construction

* ModMan

- Added a package for easy importing

* Configuration

- Calling `defaultConfig()` will now add an entry of type `ARRAY` with key `modman:path` and the starting value is just an array with a single element being the current working directory

* Compiler

- On construction of a `Compiler` we now construct a `ModuleManager` with the list of paths provided

* ModMan

- Cleaned up imports
- Added another TODO

* Parser

- Constructor now takes in an instance of `Program` (but by default it is `null`)

* Data

- Added a `toString()` for `Program`

* Compiler

- We now create an instance of `Program` on construction
- We pass a `Compiler` to the parser
- Added `getProgram()`

Parser

- Accept an instance of `Compiler`
- Print out some debug information about the program in `parseImport(string)`

* Compiler

- Added `getModMan()` method

* Modman (pacjage)

- Import `ModuleEntry`

ModMan

- Added `ModuleEntry`
- Added `getModulesInDirectory(string directory, bool recurse = false)` which can resolve all the `ModuleEntry`(s) in a given directory (with optional recursion)
- Added `search(string curModDir, string name, ref ModuleEntry found)` for searching for a module in a given directory (and then all search paths)

* ModuleManager

- If the compile-time flag of `DBG_MODMAN` is passed then only print debug text
- Added support for recursing down and fixed how it is done in `getModulesInDirectory(string directory, bool recurse = false)`

* Parser

- Removed old module searching code
- Added a TODO for ACTUAL parsing that is still to be done
- Added `ModuleManager`-based code for doing module lookups

Test cases

- Updated `modules/a.t`

* Parser

- Store current module globally (not sure if we need to)
- WIP: Work on module header name validation
- Removed `findModulesFromStartingPath(string startingModulePath)`
- Removed `findModulesInDirectory(string directory)`
- Removed `slashToDot(string strIn)`

ModuleManager

- Added `isValidModuleDeclaration(string, string, string)` (still a work-in-progress)
- Added `slashToDot(string strIn)`

* Test cases

- Updated testing files `a.t`, `b.t`, `z.t` and `niks/c.t`

* Configuration

- `defaultConfig()` now adds NOTHING to the default search path (just for now)

* ModuleManager

- The constructor now takes in an instance of the `Compiler`
- Added new method `entries()` which calls `entries(string[])` with the given search paths from the compiler config entry but also tacks on the current working directory
- Added `entriesWithInitial(string initialModulePath)` which, given a path to a module initially, will extract said module's containing directory and tack that onto the search paths and then call `entries(string[])` with that
- Implemented `entries(string[])` which currently recurses down the given directories discovering all files that end with `.t` and of which have a module header (if not an error is thrown) and then creates a `ModuleEntry` per each mapping their absolute path to their skimmed-off module name
- Added an `expect(SymbolType, Token)` so that we can throw `SyntaxError`'s (with a `null`-parser)
- Added `skimModuleDeclaredName(string, ref string)` which skims the module's header for the module's name, setting it in the `ref`-based parameter if parsed correcttly, else returns `false`
- (WIP) Made `isValidModuleDeclaration(string, string, string)` return `true`

* Compiker

- Now pass in the `Compiler` to the `ModuleManager` constructor

* Parser

- Added testing code to `parseImport(string)` which tests the new module discovery/mapping mechanism of `ModuleManager`
- It purposefully crashes at the end to prevent it from running the old code

* Commands

- Added a TODO regarding allowing multiple modules to be specified on the command-line in the future

* Parser

- Removed old code which made calls to the old `ModuleManager` methods in `parseImport(string)`

* Parser

- Removed purposeful crash in `parseImport(string)`

* ModuleManager

- Removed deprecated methods `search(...)`, `getModulesInDirectory(...)`

* Parser

- Removed module name checking in `parse(string)`

* ModuleManager

- Removed method `isValiddModuleDeclaration(string declaredName, string fileName, string curModDir)`

* Modman

- Documented `ModuleEntry`

* ModuleManager

- Cleaned up and corrected comments

* ModuleManager

- Implemented `addSearchPath(string)`

* ModuleManager

- Implemented `addSearchPaths(string[])`

* ModuleManager

- Switched to using the `addSearchPaths(string[])` method when taking the search paths from the `modman:path` compiler config entry so as to clean it of any duplicates (if any are provided)
- This also increases code re-use

* ModuleManager

- Calling `addSearchPath(string path)` will now validate the path before adding it

* ModuleManager

- Added TODOs for any debug prints
- Added `searchFrom(string searchQuery, string initialModulePath, ref ModuleEntry foundEntry)`

* Parser

- Added code to test the module searching method (in `parseImport(string)`)

* ModuleManager

- Implemented `searchFrom_throwable(string searchQuery, string initialModulePath)`

* Parser

- Switched to using `searchFrom_throwable(string, string)` when searching for the module being imported

* ModuleManager

- Added `readModuleData(ModuleEntry ent, ref string source)`

* ModuleManager

- On error or success close the file if it was opened for `readModuleData(ModuleEntry ent, ref string source)`

* MduleManager

- Added `readModuleData_throwable(ModuleEntry ent)` method

* Parser

- Read in the module's source

* Containers

- Added a `toString()` method for the `Module` container type

* Test cases

- Made `b.t` import module `ap` (useful for cycle detection testing)

* Dub

- Added `niknaks` dependency

* ModuleManager

- We now check for any possible duplicates by checking if the discovered module (or modules in the case of a directory-recurse) are present in the found list. This updates `entries(string[] directories)`

ModuleEntry

- Two `ModuleEntry`s are said to be equal if their file paths are equal

* ModuleEntry

- Added explicit constructor
- Made file private
- Added validity checker in the form of `isValid()`
- Added `getPath()` and `getName()`

* ModuleManager

- Removed old `entries()` method
- Switched to using `getName()` in `searchFrom(...)`
- Whenever a `ModuleEntry` is made assert that it is valid

* ModuleManager

- Removed debug output

* Compiler

- During construction add the containing directory of the module file specified on the command-line to the search paths of the `ModuleManager`
- `doParse()` now dumps some information from the `ModuleManager`

* Test cases

- Updated `niks/c.t` to import module `ap`

* Program

- Added `isModulePresent(ModuleEntry)`
- Added `markAsVisited(ModuleEnty)`
- Added `setModule(ModuleEntry, Module)`
- Added getMods()` and `getOMods()` (for insertion order for debugging purposes)
- Added `debugDump()`

* Parser

- `parseImport(string)` now searches for the module by the name and with the current module's path
- Return immediately if the module we found is already present in the `Program`
- If NOT, then mark as visited, open parse it and then add the parsed `Moudle` just imported to the `Program`

* Compiler

- The current directory should be added to the search path

* Compiler

- This was WRONG.
- DO NOT add the current working directory to the search path

* ModuleManager

- Added `findAllTFiles(string directory)`
- Working on new search methods now

* Parser

- Added testing code and panic to not progress

* ModuleManager

- Now implemenetd module-name-to-path mapping with fallback mechanism

* ModuleManager

- Added `find(string modName)`

* Test cases

- Fixed import statements such that the testing works

* Parser

- `parseImport(string)` now uses new `ModuleManager` code

* ModuleManager

- Removed `entriesWithInitial(string initialModulePath)`
- Removed `entries(string[] directories)`
- Removed `searchFrom(string searchQuery, string initialModulePath, ref ModuleEntry foundEntry)`

* Parser

- Switch to new Module manager system (for real this time)

* Dub

- Upgraded `niknaks` package
- Enable `DBG_MODMAN` when compiling

ModuleManager

- Added some useful debugging prints

* Dub

- Upgraded `niknaks` to version `0.6.0`

* ModuleManager

- Upgraded to new `niknaks` debug

* Program

- `debugDump()` needs something with a non-private field associated to correctly work it seems

* Parser

- Removed old code from `parseImport(string)`

* Parser

- Added some code to do the collecting of several modules in a single import statement

* Parser

- No longer pass in a value to `parseImport()`

* Parser

- Removed `getWorkingDirectory()`
- Removed unneeded imports

* TypeChecker

- Added a constructor which takes in a `Compiler`
- It also then extracts the `Program` from it

* TypeChecker (unittests)

- Pass in a `null` `Module` such that the constructor is selected correctly (old constructor)

* Program

- Made it a kind-of `Container`
- Made class final
- Added stub interface implementations
- Added `addStatement(Statement statement)` and `addStatements(Statement[] statements)`
- Added `getStatements()`

* Resolver

- Removed `Module` and replaced it with a `Program`
- Updated constructor to take in a `Program` and a `TypeChecker
- `resolveBest(Container c, string name)` will now loop through every `Module` of the `Program` checking to see if `path[0]` matches the name of any of those modules

* Resolver

- If there is no dot-path but the name matches one of the `Module`s attached to the `Program`, then return it
- This is an update for `resolveBest(Container c, string name)`

* Resolver

- Removed now-completed TODOs
- These wre done already for years but they may as well be removed now

* Compiler

- Now pass in the `Compiler` instance to the `TypeChecker` constructor

* Testing

- Fixed the shabang for `extern_test.sh`

* Resolution

- Updated the method `generateName(Container relativeTo, Entity entity)` to have a special case
which is when we pass in a `Container` of which is a `Program`. Because the `Entity` provided
may have been declared in some module at, for example a top-level of the `Module`, we then basically
have no way to know from the top-down where it belongs, _rather_ we must start **at** the `Entity`
itself and then ask the resolver to work its way up to the container of which _is_ a `Module` in
order to find its containing top-level container (i.e. a `Module`). After doing this we then call
the `generateName(Container, Entity)` method with said `Module` and the same `Entity` and return early.
- Some work is being done on `resolveBest(Container c, string name)` but so far no changes have been
necessary (through testing) but many might, so the code added is commented out for now and has no associated
commit message as I am still working on it.
- Added debugging messages to `findContainerOfType(TypeInfo_Class containerType, Statement startingNode)`

* Resolution

- Added some unittests just for testing my sanity when it coms to using `split(string, char)`

* Resolver

- Updated `resolveBest(Container c, string name)` to now include a check for a condition
whereby we pass in a `Container` which is not an `Entity` as well (i.e. it has no name).
The only case whereby this is the case (in our current code) is that of a `Program`
which is purposefully **not** an `Entity` (as I wanted it to be nameless) but it _is_
a `Container`. Therefore we don't want to continue to hit the code below which
does a cast to `Entity` in the form of `containerEntity`, as that would not work
(and the associated assertion would fail).
- What I wanted to accomplish with the two checks is to check if we are given a name
which then directly matches that of a `Module` that is _in_ the provided `Program`,
and in such a case return said `Module`
- Else, we have a case whereby we have `moduleName.<iets>` whereby we then want to
also similarly scan the `Program` for all its modules and then match to the `moduleName`,
as shown in the above example, we then look this `Module` up **but** we don't return yet.
No, what we do is now do a search for the incoming `name` but we _anchor it on_ the found
`Module` to then search therein

* Resolver

- Fixed the path array usage in `resolveBest(Container c, string name)`

* Resolver

- Added another unittest for my sanity

* Resolver

- Added an assertion that the result from `split(..., ...)` may not be an empty array
- This is an update to the `resolveBest(Container c, string name)` method

* Resolver

- Don't shadow global `Program` variable
- Updated `resolveBest(Container c, string name)`

* Program

- Renamed `debugDump()` to `debugDumpOrds()`
- Added `debugDump()` which dumps `modulesImported`

* Compiler

- Added a `setProgram(Program program)` method
- For now when we finish the call to `parse()` in the `Parser` in `doParse()` we will also add ourselves
to the list of modules. Simply done because as of right now we only add ourselves if we are visited via an
import which implies that you would need a cyclic import ot be visited - which isn't a constraint we obviously
would like to impose upon code writers using TLang. For now we manually add it at the end.
- At the end of `doParse()` call `debugDumpOrds()` on the `Program`
- Added a `getTypeChecker()` method

Compiler (unittests)

- Prints out more information during the exception catch

* TypeChecker

- Calling `getModule()` will now return the first `Module` in the `Program`'s list of modules
- Marked `getModule()` for removal
- The constructor now constructs a `Resolver` instance by also passing in the `TypeChecker` itself
- We have updated `dependencyCheck()` to call `checkDefinitionTypes()` on each `Module` of the current `Program`
- We have updated `dependencyCheck()` to call `checkClassInherit()` on each `Module` of the current `Program`
- When handling a `VariableExpression` we look up the `Variable` it referes to, then we must generate a name for it
rooted by its module, we now do this by anchoring at the `this.program` rather than the `modulle`
(what the deprecated `getModule()` would return), this would use the updated `Resolver` code to generate
the name we expect as with the implementation that came before
- When handling a `FunctionCall` we lookup the `Function` it refers to, then we must ask the resolver
to resolve the `Function` by its name using `resolveBest(Container, string)` and this should be best-effort
starting at the `Module` of which the `FunctionCall` is present in. If it happens to be that the `Module`
of the `Function` referred to is outside the provided starting anchor then it will be handled for us, that
is undert the assumption it is `otherModule.myFunc()` being called and present in `otherModule`, compared to
the first case of having `myFunc` being declared in `myModule` of which so is the `myFunc()` `FunctionCall`
statement
- When generating the name of a variable being assigned to for `StaticVariableDeclaration`, we now
anchor at `this.program` instead of `modulle` (the deprecated value returned by `getModule()`)
- Updated `beginCheck()` to now call the `MetaProcessor` with the instance of `this.program` rather than `modulle` (deprecated - as stated before)
- Updated `beginCheck()` such that it now calls `processPseudoEntities()` on each `Module` that is contained
within the current `Program`
- Updated `beginCheck()` such that it now calls `checkContainerCollision()` on each `Module` that is contained
within the current `Program`
- Updated `checkContainerCollision(Container c)` to do the following:
	* On each `Entity` we loop over we ensure that it never has a name which matches that of any `Module` that
is stored within our `Program` (exclusivity principle of module names)
	* Updated calls to `generateName(Container, Entity)` to use `this.program` as the anchor container (insead
of the deprecated `modulle`)

TypeChecker (unittests)

- Fixed a unittest to not spawn a `TypeChecker` using a `Module` but rather a dummy `Compiler` instance
- Fixed a unittest to not spawn a `TypeChecker` using a `Module` but rather a dummy `Compiler` instance
- Fixed a unittest to not spawn a `TypeChecker` using a `Module` but rather a dummy `Compiler` instance
AND to create a dummy `Program` of which we then add a dummy `Module` to
- Fixed remaining unittests to now use a `Compiler` instance

* Test cases

- Added `alone.t`

* Parser

- Updates for `parentToContainer(Container, Statement[])`:
	* We now have a default argument called `allowRecursivePainting` which is set to `true`
by default
	* What this does is handle special cases of `Statement`s which are not placed within
a `Container` and therefore can not be reached in a generic way (i.e. `getStatements()` with `Container`
types)
	* These special cases are:
		1. `Variable`
			* Declarations may have a `VariableAssignment` attached to them which has an `Expression`
		2. `BinaryOperatorExpression`
			* Left and right-hand side operands have `Expression`'s attached to them
		3. `VariableAssignmentStdAlone`
			* The assignment `Expression`
		4. `ReturnStmt`
			* It may have an `Expression` in it
		5. `FunctionCall`
			* We need to process each of its actual arguments, which comes in the form of a `Expression[]`
		6. `DiscardStatement`
			* This is like a `ReturnStmt` but it always has an `Expression`, therefore we must process it
		7. `IfStatement`
			* Contains an array of `Branch` (i.e. a `Branch[]`)
		8. `WhileLoop`
			* Contains a singular `Branch`
		9. `ForLoop`
			* Contains a singular `Branch`
		10. `Branch`
			* Contains a condition in the form of an `Expression` and a set of body statements
			in the form of a `Statement[]` array
	* What we then do for 1-6 (so-called normal cases):
		* These we will recurse upon and parent them to the same `Container` that came in in
		the original call which was what got us to enter into the cases of 1 to 6.
	* What we then do for 7 onwrads (so-called "maintain" cases):
		* Notice that each type mentioned in these are all a kind-of `Container`
		* We therefore call `parentToContainer(Container, Statement)` not with the incoming
		`Container` that came into the call that macthed to one of these cases but
		rather to that of this case's container itself
		* We do this because we want the scoping to be consistent and that is done by keeping
		the ancestry tree as it is expected when multiple calls are done for parenting, for example,
		the body `Statement[]` items to their respective `Branch` and then those `Branch[]` to their
		`IfStatement`.
	* "I said there would be special cases ;)"

Parser (unittests)

- Fixed unittests such that they run by using the `Compiler` object now

* TypeChecker

- Renamed `getModule()` to `deprecated_getModule()` so that we generate compilation errors now

* TypeChecker

- Implemented `getProgram()`

* Builtins

- Updated the `getBuiltInType(TypeChecker, string)` method to take in a `Container` as the second
argument

* TypeChecker

- `getType(Container c, string typeString)` always checks for built in types first and then if one
of such is found it then immediately returns, else does a search. We have now updated that inner
call to `getBuiltInType(TypeChecker, string)` to use the new API which is `getBuiltInType(TypeChecker, Container, string)`
- When processing a `ReturnStmt` and we need to check the return type of the `Function` it is contained within
and the type of its returned `Expression`, we need not call `getBuiltInType(TypeChecker, Containert, string)`, let's
just call `getType(Container, string)` as it does that call for us in any case
- With the above I also anchor it to search for the type based on the `funcContainer` `Container` as that is at the same level as the `ReturnStmt` itself

* Parser

- Fixed missing ending curly brace

* Scratch

- Playing with a way to build library objects without immediately linking
- I am then also seeing how to link it to an application which `_start_` can find its `main` symbol

* Makefile

- Added `-c` to ONLY compile but do NOT attempt to link and make an executable. If we try this it looks for a `main` symbol to satisfy the `_start` for linux-ld
- Updated the build instructions for being able to statically link against the library

* Makefile

- Added seperate stage to _create_ the `main.o` and then only later link with the intent of making an executable.
- This is BETTER because it means we could treat everything in the same way (nevermind a `main` or library)

* DGen

- Added some future code for `emit()` which will enumerate all `Module`(s) available in the current `Program` and then do an emit step per-each of them and have those go to the correct `File`(s)
- Added a comment for `finalize()` of which indicates where we should link all generated object files for all the modules. After this we should then link this against each other and generate an executable.

* tlang.compiler.codegen.mapper.api

- Added new module

SymbolMapperV2

- Added new interface

ScopeType

- Added new enum type

* SymbolMapperV2

- Added missing import for `Entity` type

* Implementations

- Added some stub types `LebanonMapper` and `HashMapper`

* LebanonMapper

- Implemented `map(Entity item, ScopeType type)`

* LebanonMapper

- Now respects the `type` field for `copeType.GLOBAL`
- `ScopeType.LOCAL` is still to be implemented

* LebanonMapper

- Fixed wrong variable name in `map(Entity item, ScopeType type)`

HashMapper

- Implemented `map(Entity item, ScopeType type)` for `ScopeType.GLOBAL`
- `ScopeType.LOCAL` is yet to be implemented

* LebanonMapper

- If called with `ScopeType.LOCAL` then the name will be generated in an absolute sense, however the module name will be stripped from the path
- For example `simple_module.a.b` would become `a.b` and then be mapped to `a_b`

* LebanonMapper

- Join with periods and let step afterwards do the replacement

* HashMapper

- Added support for `ScopeType.LOCAL` in a similar fashion to how it is done in `LebanonMapper`

* MetaProcessor

- When getting the type root everything on the `Program` rather than `tc.getModule()`. We therefore now use the `tc.getProgram()` in its place. This updates the `sizeOf_Literalize(string typeName)` method.

DGen

- `emit()` has been updated to enumerate all `Module[]` of the given `Program` and then calls the respecitve `emit(...)` methods with a (`File`, `Module`) which contains the file which emitting should be written to and also the `Module` being emitted.
- At the end of `emit()` we then try to find the `Module` which contains a function named `main` and then set that as the entrypoint. If such a `main` function cannot be found we then go and do a check whether or not the `dgen:emit_entrypoint_test` configuration option is `true`, if so we then try emit a testing entrypoint and assume that the tst uses only one `Module` (this is something to be cleaned up later; as in all tests should have a `main` method).
- Implemented `findEntrypoint(ref Module mainModule, ref Function mainFunc)` which does as the name implies and finds the containing `Module` which has a `Function` named `"main"` and if so sets both ref arguments and returns `true`, otherwise they are left unset and `false` is returned
- `emitHeaderComment(...)`, `emitStaticAllocations(...)`, `emitFunctionPrototypes(...)`, `emitFunctionDefinitions(...)`, `emitFunctionPrototype(...)`, `emitFunctionDefinition(...)`, `emitCodeQueue(...)`, `emitStdint(...)`, `emitEntrypoint(...)`, `emitTestingEntrypoint(...)` now takes in `File modOut` and `Module mod`
- Note the above have not YET been updated to select correct code queues, static init. queues and `emitEntrypoint(...)` has not yet been implemented
- Updated `emitTestingEntrypoint(...)` to check using the incoming `Module`'s name
- `finalize()` will now compile all sources files, then it will link all generated object files together; optionally cleaning up all but the final genersted excutable at the end

CollidingNameException

- Fixed up name generation (we now anchor on the `Program`)
- Fixed up how we detect if a module's name is in use. We now will check and ensure it doesn't match ANY of the modules contained within the `Program`

DNode

- Implemented `forceName(string)` to set the `name` field forcefully
- The `generate()` method now calls `generalPass(Module, Context)` on each of the `Program`'s `Module`s. We then get an array of `DNode[]` from them. After this we then create a root `DNode` to represent the program and then we make it `needs(DNode)` each `Module` `DNode` created previously.

DNodeGenerator

- When processing `VariableExpression` in `expressionPass(Expression exp, Context context)`, if we get a `Function` being referred to in the expression, then we now set the `Context`'s `Container` still to the `Module` containing the function's definition, _however_ we use a method from the resolver to ensure it is the correct module (because we are now using a multi-module setup).
- We have always set the **root** `Module` when entering `generalPass(Container c, Context context)` and processing a `Function` but, as with the last change mentioned above, we need to find that containing `Module` correctly. Therefore we use a method from the `Resolver` to do that.

* TypeChecker (unittests)

- Fixed up calls to `getBuiltInType(...)` which now require some `Container` to pivot on. We now pass in the `Program`
- Fixed up unittests which used `getModule()`, for such uni-modular tests we just use `program.getModules()[0]` now

* FuncDefStore

- Use `tc.getProgram()` in place of `tc.getModule()` when doing a name generation via the `Resolver`

* DGen

- Use `else` rather than hard coding all test cases. This will only be used if no main module is found AND testing is enabled - so it should be a safe bet

* DNodeGenerator

- Fixed `DNode` construction in `generate()` method

PoolManager (unitttests)

- Fixed unittests

* TypeChecker

- Removed `deprecated_getModule()`
- Removed old `modulle` field
- Cleaned up field definition section
- Removed old usages of `modulle` and now rooting at the now-new topmost `Container`; the `Program`

* LebanonMapper

-  Added unittest
- Seems like it completely works as expected for both `ScopeType`'s

* HashMapper

- Added unittests
- Looks like it works as expected as well

* HashMapper

-  Actually fixed unittest
- Added more debug-time debugging prints
- Had to use `dup` (BUG)!

* CodeEmitter

- Removed already-completed TODO

* TypeChecker

- Use `Module`, as no cast is needed
- Cleaned up

* TypeChecker

- Cleaned up some more

* DNodeGenerator

- Cleaned up the constructor
- Made `resolver` private

* DNodeGenerator

- Removed `functionDefinitions` as it is no longer used anymore, we now make use of the `IFuncDefStore`

* ProgramDepNode

- Added new type

* DNode

- Implemented `getDepCount()` and `getDeps()`

DNodeGenerator

- Now uses `ProgramDepNode`

* DNodeGenerator

- When calling `generate()` set a nice name for the dependency nodes of the `Module`(s)

* IFuncDefStore

- All methods now require an owner `Module`

* FuncDefStore

- Now conforms to the new `IFuncDefStore` API

* FunctionData

- Added `Module`-based ownership model
- Implemented methods `setOwner(Module mod)` and `getOwner()`
- Implemented method `getName()`

DNodeGenerator

- When processing a function definition (a `Function`) we now will call `addFunctionDef` with the owner of this `Function`, this is done by making use of the `Module root` which is set in such a case (and others) when entering the `generalPass(Module, Context)` method

* TypeChecker

- We now get all of the top-level `DNode` (dependency nodes) and then from there onwards we `performLinearization()` -> `getLinearizedNoes()` -> `doTypeCheck(DNode[])`, at each stage collecting the global code queue, the function definitions (each of their code queues) and the static init queues. These are then collected ina  `ModuleQueue` for the respective `Module` being processed
- Added methods `getModQueueFor(Module owner)`, `scratchToModQueue(Module owner)`, `funcScratchToModQueue(Module owner, FunctionData fd)` and `initsScratchToModQueue(Module owner)`
- Updated the following methods to make use of the `ModuleQueue`(s) available by selecting by an owner `Module`: `getGlobalCodeQueue(Module owner)`, `getFunctionBodyCodeQueues(Module owner)` and `getInitQueue(Module owner)`

ModuleQueue

- Added new type

* CodeEmitter

- Selecting a queue now requires an owner `Module` and it will also, when the `QueueType` is set to `FUNCTION_DEF_QUEUE`, copy over the correct `Instruction[][string]` and then, furthermore, select the correct `Instruction[]` out of it and set that as the current code queue
- Updated `getFunctionDefinitionsCount(Module owner)` and `getFunctionDefinitionNames(Module owner)` to select the correct `Instruction[][string]` when called

* DGen

- When we find an entrypoint use `a` mode when opening the file for it, `w` mode would wipe the previously written C source code
- Also added a note regarding this branch (if-else) above
- Updated error message when no entry point (and not a test file) is found
- Fixed `emitStaticAllocations(File modOut, Module mod)` to select the static init queue using the provided `Module`
- Fixed `emitFunctionPrototypes(File modOut, Module mod)` and `emitFunctionDefinitions(File modOut, Module mod)` to use the inheritted `CodeEmitter` methods correctly by passing in a `Module`, similar changes affecting the `TypeChecker` are now conformed to in s similar manner
- Fixed `emitFunctionPrototype(File modOut, Module mod, string functionName)` and `emitFunctionDefinition(File modOut, Module mod, string functionName)` to select the function definition queue of the given `functionName` by the given `Module`
- Fixed `emitCodeQueue(File modOut, Module mod)` to select the globals queue by `Module`
- Added some comments about future features to `emitEntrypoint(File modOut, Module mod)`

*  Feature: Pluggable predicate-based resolution method (#36)

* Dub

- Upgraded `niknaks` to version `0.9.7`

* Resolver

- Documented the class and some new and existing
- Implemented a version of `resolveWithin(...)` which now takes in a `Predicate!(Entity)` instead of a name and then uses that as the final matching step when iterating over the given `Container`'s `Statement[]` (the container's immediate body)
- Implemented `derive_nameMatch(string name)` which returns a `Predicate!(Entity)` closure which matches based on names
- Updated `resolveWithin(Container, string)` to make use of these above two changes
- A similar change including the above rework and predicate derivation has been done for `resolveUp(...)`, of which there is now a version available as `resolveUp(Container, Predicate!(Entity))`
- Stub version of `resolveBest(Container c, Predicate!(Entity) d)` added but not implemented yet
- Added some unsued types and methods, `SearchCtx` and `findFrom!(...)(...)` respectively
- Added `derive_functionAccMod(AccessorType)` (this is to be moved into `DGen` as that is where it is needed)

* Resolver

- Removed `derive_functionAccMod(AccessorType)`

DGen

- Added `derive_functionAccMod(AccessorType)`

* Resolver

- Removed the old code that was commented out in `resolveWithin(Container currentContainer, string name)`

* Resolver

- Cleaned up commented out code for `resolveUp(Container currentContainer, string name) and also documented it

* Resolver

- Removed unused things

* DGen

- Initial code for `emitExterns(File, Module)`

*  Feature: Collector-based resolution methods (#37)

* Resolver

- Added collector-based searching for `resolveWithin(..., ..., ...)`

* DGen

- Corrected `DGen` call to use new `Resolver` method

* Dub

- Upgraded `niknaks` to versoin `0.9.8`

* Resolver

- Fixed a bug in `resolveUp(Container currentContainer, Predicate!(Entity) predicate)` which would cause a segmentation fault when we had climbed to the top of the AST hierachy but we tried to find the `parentOf()` a `Program`. This would fail because only kind-of `Statement`(s) have the `parentOf()` method. We normally do a `cast(Entity)container` to therefore get such access to that method (as all `Entity`(s) are a kind-of `Statement`). However a `Program` is notably NOT an `Entity` and hence this would fail. Ths fix therefore was to add a check that if `entity` was `null` meaning that the `resolveWithin(Container, `Predicate!(Entity))` failed that we must not try to climb further. We do this by checking that with an intermediary else-if branch that, if the within-search failed AND we have a `cast(Program)container` which is non-`null` then we stop the search with zero-results by returning `null`

Program

- When one calls `setModule(ModuleEntry, Module)` then the incoming `Module` should be parented to the `Program` itself

* Test cases

- Updated `a.t` to have its own `main` method and try refer to something outside of its own module (something in `b.t`)
- Updated `b.t` to have a method named `doThing()`

* HashMapper

- Updated the mapping technique to prepend the characters `t_` or else the `DGen` gets very angry bevause the symbol names sometimes start with numbers of a sequencce of characters that meanns something else (an illegal symbol name).

HashMapper (unittest)

- Updated unittest to correspond with the fix)

* CodeEmitter

- Now makes use of `SymbolMapperV2` for the mapper

Compiler

- Now uses the new `HashMapper` and `LebanonMapper`.
- Along with this it also now uses the `SymbolmapperV2` API

* DGen

- Now takes in a `SymbolMapperV2`
- We now have made use of the new symbol mapping facilities and (for now) we are mapping everything with a `GLOBAL` `ScopeType`. n this case  have added comments above each mapping request to reconsider which scope type should be used on a case-by-case basis.
- We now first call `emitStdint(..., ...)` prior to `emitExterns(..., ...)` because the latter uses types defined in the former (think of well, the `uint32_t` types for example)
- Defined a new type `ModuleExternSet` which holds a `Module` and its respetcive publically accessible `Function`(s) and `Variable`(s)
- Implemented `generateExternsForModule(Module mod)` which generates a `ModuleExternSet` for the given `Module`
- Updated `emitExterns(File modOut, Module mod)` to now determine all `Module[]` except the incoming `mod` itself and then generate `ModuleExternSet`()s for each. These are then looped through and extern statements are generated for each `ModuleExternSet's `pubFns()` and (soon) we will also add support for the `pubVars()` of each

* TypeChecker

- When pro0cessing a `DNode` which contains a `Statement` of which is a `FunctionCall` we now will generate the corresponding `FuncCallInstr` using the name that is refered to in the `FunctionCall` (i.e. using `getname()` on the `FunctionCall`) INSTEAD of using the `getName()` method from the `Function` looked up CVIA the `FunctionCall`'s `getName()` method. This ensures that the full path expression is passed into the `FuncCallInstr`. Remember it is looked up later in the emitter but having this name fixed a lto of problems. i.e. having a `b.doThing()` call in module `a` now works. Previously it would look up just `doThng()` as that is all that was all whic was saved within the `FuncCallInstr`.
- Rule of thumb when deating any sort of `Instruction` whic refers to some entity using a name, save-what-you-see. Don't eaergly lookup stuff and re-generate names because the name y7ou see is normally syntactically correct from the user.

* Resolver

- Fixed up documentation
- `generateNameBest(Entity)` now has a WAY cleaner implementation that uses the `findContainerOfType(..., ...)` method
- Documented `isDescendant(Container, Entity)` and fixed it up for `Program` related things
- Updasted documentation and error messages which print when using `resolveBwest(Container, string)` with `Program` as the container and referring to a non-module-only name.

Resolver (unittests)

- Added one huge unittest to test EVERYTHING

* Compiler

- No longer store a global `Module`
- Removed `getModule()`

* Commands

- Removed all references to `getModule()` to the `Compiler` object

* Parser

- When calling `parse(string, bool)`, store a `ModuleEntry` corresponding to the just-created `Module` such that it is pre-visited

* Compiler

- Call `parse(string, bool)` with a flag to indicate this is an entrypoint call and the `Module` immediately parsed should be stored as visited (as we have access to its name now (after parsing the `module <x>;` header)) and the `Module` object itself (as per the instantiation of it PRIOR to any further `LexerInterface` calls but just late enough after the module header parsing in order to obtain its name

* Test cases (multi-module)

- Updated `a.t` and `b.t`

* test cases

- Updated `niks/c.t`

* Small documentation

- Added description of modules and programs along with example code, directory structure and then also usage

* Test cases

- made the multi-module test case more complicated to ensure it all works
- Also fixed the module name at module `niks/c.t` to be `c` and NOT `niks.c` which is incorrect

* Small docs

- Updated the docs to reflect current code

* DGen

- Show elapsed time per compiled unit

* DGen

- Show only milliseconds

* DGen

- Calculate and print out total compilation time at the end of compilation

* ModuleEntry

- Fully documented

* ModuleEntry

- Typo fix in documentation

* Small docs

- Working on implementation details now

* Small docs

- Added `ModuleEntry` documentation
- Working on `ModuleManager` docs now

* Smaol docs

- Updated docs

* Smol docs

- Typo fixes

* Small docs

- Updated

* ModuleManager

- Made many methods `private` which should have been from the start
- Optimized out calculations that were being done over and over again when they needed to only be calculated once
- Added some missing documentation

* ModMan

- Cleaned up

* ModuleManager

- Documented more methods

* ModuleManager

- Documented last item

* ModMan

- Removed unused unittest

* Small docs

- Removed unrelated section

* Small docs

- Updated

* Container

- Corrected typo

* Smol docs

- Working on the resolution docs

* Smol docs

- Updated docs

* Smol docs

- Finished section on program

* Program

- Cleaned up
- New method names

Parser

- Updated to use the new `Program` API

Compiler

- Cleaned up

* Container

- Added documentation

* Program

- made `addModule(Module)` public again

* Small docs

- Added some more on resolver

* Small doc

- Added more documentation on the `Resolver` API

* Small doc

- Added more documentation on the `Resolver`

* Small docs

- updated

* Small docs

- TYpo fix

* Resolver

- Fixed the typos in some documentation
- `generateNameBest(Entity entity)` now relies on `generateName(Container, Entity)`'s special handling of `Program`'s in order to achieve its goal.
- Cleaned up `generateName(Container, Entity)`
- `generateName_Internal(...)` is now `generateName0(...)`

* Small docsd

- Updated

* Small doc

- Added more information

* Small docs

- Added examples

* Samll docs

- netaened up

* Small docs

- Fixed run onlines

* Smal docs

- Updated

* Small docs

- Updated

* Small docs

- Finioshed resolver docs

* Small docs

- Added code excerpt

* Small docs

- Added code insertion

* Parser

- Cleaned up imports
- Removed unused global `curModule`
- Cleaned up in general

* Resolution

- Neatened up
- Removed check for `statement !is null` from `resolveWithin(..., ...)` because that should honestly never be the case. In the case it ever is stuff would still work, but it won't
- Formatted code
- Added docs

* Parser

- Refactored importing code into `doImport(string)`

* Parsing (unittests)

- Added a test which tests out the multi-module support by testing `a.t`/`b.t` and `niks/c.t` in a unittest itself

* Pipelines

- Added test for `a.t` (multi-module) test

* Pipelines

- Added test for `a.t` (multi-module) test

* Pipelines

- FIXED it (removed set e in wrong place)
- Added test for `a.t` (multi-module) test

* Pipelines

- No, actual fix is `-e` as we want to exit on first bad command (non-zero exit code)

* Pipelines

- Smh, fixed

* Pipelines

- But don't fail after running it lmao

* Pipelines

- try this?

* Pipelines

- test to make sure

* Revert "Pipelines"

This reverts commit 73efdf9d4c.

* Parser

- Updated `doImport(string)`

* Parser

- Make `doImport(string)` now use `doImports(string[])`
- `parseImport()` now supports multi-line imports

* test cases

- Updated `a.t` to use a multi-line import

* Parser

- Added doc

* Configuration

- Added default config option of `modman:strict_headers` and set it to `false`

* ModuleManager

- Removed `slashToDot(string strIn)`
- Removed `skimModuleDeclaredName(string modulePath, ref string skimmedName)`

* Parser (unittests)

- Comments unittests disabled for now

* Small docs

- Added new one to work on soon

* Parser

- `moduleFilePath` is no longer an optional argument

* ModuleManager

- Fixed bug in `findAllTFilesShallow(string directory)` whereby we would never check `directory` to be a valid path nor even a path (if valid) to a directory - which is required in order to run `dirEntries(...)` on it

* Configuration

- Cleaned up the configuration code which initially creates the `ConfigEntry` for `modman:path`

* Small docs

- Yebop

* Compiler

- Added documentation to `getModMan()`

* Commands

- Added `ParseBase` mixin template, this contains the support for `--paths` command-line option
- `compileCommand` now mixes in `ParseBase` and `TypeCheckerBase` and initializes the `ParseBaseInit()` as well
- `parseCommand` now mixes in `ParseBase` and initializes the `ParseBaseInit()` as well
- `typecheckCommand` now mixes in `ParseBase` and `TypeCheckerBase` and initializes the `ParseBaseInit()` as well

* ModuleManager

- Fixed bug in `validate(string searchPath)` which would not check if a path existed

* Parser

- Removed now-completed TODO

* Parser

- Removed unused method `doImport(string moduleName)`

* Dgen

- Added `generateSignature_Variable(Variable var)` which generates JUST a variable signature (with symbol mapping)
- `emitExterns(File modOut, Module mod)` now also generates extern statements for global variables

* Test cases

- Updated to show use of extern variables

* DGen

- Removed old commented-out code from `emitExterns(File modOut, Module mod)`

* TypeChecker (unittests)

- Fixed missing `sourceFile` argument to various `Compiler` constructors
- Fixed the module obtaining in one of the tests

* DGen

- Documented

* LebaneseMadpper

- Removed old mapper

* HashMapper

- Removed old mapper

* SymbolMapper

- Removed old definition

* SymbolMappingTechnique

- Documented

* SymbolMapperV2

- Renamed

* SymbolMapper

- Moved from `api.d` to `core.d`

* SymbolMapper

- Documented
- Cleaned up

* DGen

- When generating symbols for `Variable`, if it IS `isExternal()` then do not symbol map, else symbol map

* DGen

- When generating `extern ...` statements for a given `Module` only tack on the `extern` to the emit if it is NOT `isExternal()` (if it is not a TLang externed variable/function). This is because those would already have them via the call to the signature generation function. This updates the `emitxterns(Module, File)` method.
- When generating signatures for `Variable`(s) ensure that ones which have `isExternal()` return `true` have `extern ...` added to the front og the generated signature. This updates the `generateSignature_Variable(Variable var)` method.

* DGen

- Removed now-completed TODO

* Notes

- Removed random ass note

* Symbols

- Documented

HashMapper

- Removed `.dup` which is no longer needed

* HashMapper

- Cleaned up

* Mappers

- Documented
2024-04-08 12:43:22 +02:00
Tristan B. Velloza Kildaire 800f06da5f
Feature: Variable usage checker (#32)
* Dependency

- Added `varRefCounts` which maps a given `Variable` to its reference count. This includes the declaration thereof.
- Added `touch(Variable variable)` which Increments the given variable's reference count

* Dependency

- When handling a standalone assignment to a variable increment it's reference count
- This was updated in the handling of `VariableAssignmentStdAlone`

* Dependency

- Make variable declaration count as the first reference

* Dependency

- VAriables that appear in expressions must increase the ref count

* Dependency

- Added `getUnusedVariables()` which returns all variables which were declared but not used

* TypeChecker

- Moved the reference counting mechanism into the `TypeChecker` to avoid problem of seperate `DNodeGenerator` instances having their own seperate counts
- We now check the reference count values after function definition processing so as to get a proper count

Dependency

- Use the reference counting from `TypeChecker`
- Removed reference counting code

Test cases

- Added a positive case in the form of `unused_vars.t`
- Added a negative case in the form of `unused_vars_none.t`

* Commands

- Added commands to `TypeCheckerBase!()` mixin template
- Added `TypeCheckerInit(Compiler compiler)`
- Use the template in both `compile` command and the`typecheck` command

* TypeChecker

- We now respect the `typecheck:warnUnusedVars` option

* TypeChecker

- Added `doPostChecks()`
- Moved the reference counting code to `doPostChecks()`

* Configuration

- `defaultConfig()` now adds an entry for `typecheck:warnUnusedVars` set to `true`

* TypeChecker

- Use `getName()` on the `Variable` when printing out the names of unused variables

* Compiler

- Made `gibFileData(string sourceFile)` public
- Added `getTypeChecker()` to the `Compiler` class

* TypeChecker (unittests)

- Added a positive test case unittest for the unused variables detection mechanism

* TypeChecker (unittests)

- Check the variable is equal to the one we are looking for (`j`)

* TypeChecker (unittests)

- Added a negative test case for the unused variables detection mechanism

* Pipelines

- Added tests for `unused_vars.t` and `unused_vars_none.t`

* TypeChecker

- Fixed message which prints out when an unused variable is detected

* Merge branch 'vardec_varass_dependency' into feature/unused_vars_detection
2024-04-01 21:55:56 +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 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 ef29cf018d - Try using latest version of `dmd` 2023-08-14 22:21:46 +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 c0920f2fdb
🐞️ Functions: Expressionless return and enforcing requirement (#7)
* Parser

- Added a TODO in `parseReturn()` for issue #113

* Data

- The `ReturnStmt` now has a default constructor which is for cases where one doesn't want to provide an expression (for expressionless returns)

Parser

- `parseReturn()` now supports expressionless returns

Test cases

- Added `simple_return_expressionless.t` to test expressionless return statement

* Data

- Added a method `hasReturnExpression()` to `ReturnStmt` which returns `true` if the return statement has an expression attached, `false` otherwise

* Dependency

- When processing a `ReturnStmt` only run do dependency generation for the return statement's expression IF it has one

* Instruction

- Made `ReturnInstruction` have a constructor which takes in no `Value` instruction (intended for return expression)
- Added a `hasReturnExpInstr()` to `ReturnInstruction`such that during typechecking/codegen we can check for it

* TypeChecker

- Added a TODO regarding the missing typechecking for `ReturnStmt` typechecking. Added notes on how we'd go about this.
- Fixed crash due to assuming there was always an expression on the stack that could be popped off for generating a `ReturnInstruction` (this is not the case when the return statement is expressionless)

* Tests

- Added a typecheck test for `simple_return_expressionless.t`

* TypeChecker

- Update `isSameType(Type t1, Type t2)` to check if the actual types of both `Type` objects are the same as a last resort
- Added a `NOTE` comment on how `isSameType(Type t1, Type t2)` is implemented

- Added typechecking code for `ReturnStmt` and updated the code generation with it. We now do the following:
    1. We extract the container of the `ReturnStmt` and cast it to a `Function`; if it is not a `Function` we throw an error because you cannot have a `ReturnStmt` appear in a non-`Function` container
    2. We extract the function's name relative to it container (the function's container) for use of it in error messages
    3. Next, we get the return type of the function and do the following:
        a. If the return type is `void`
            i. If the return has an expression we throw an error
            ii. If the return has NO expression we pass typechecking and generate the `ReturnInstr`
        b. If the return type is non-`void`
            i. If the return has an expression we ensure that its type matches that of the function's return type and generate the `ReturnInstr`
            ii. If the return has NO expression we raise an exception as one is expected
    4. If we pass and got here then we set the `ReturnInstr`'s context and `addInstrB(returnInstr)`

* Test cases

- Added test case `simple_return_type.t` which is here to test our return type checking

* - Updated `.gitignore`

* Parser

- Use `lexer` for all `Token`-based operations
2023-07-11 21:43:21 +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 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 fe8e1403f0
Array support (#1)
* Parser

- Added ability for `parseName()` to recognize array types
- Added array type handling to `parseTypedDeclaration()`
- Removed unneeded `derefCount` and comment in `parseTypedDeclaration()`

Check

- Added new symbol types `OBRACKET` and `CBRACKET`

* Tets cases

- We will now be using `simple_arrays2.t` as our testing bench for array support

* Dependency

- When a variable declaration has a kind-of type we are unaware of then  print out an error message before asserting `false`

* Builtins

- `getBuiltInType(TypeChecker, string)` will now return a `Pointer` object for arrays of which the type was `<componentType>[]` (non-stack bound) as effectively they are pointers with a different syntax -doing it here means that it is transparent and typechecking, code gen and emit will just see a pointer type which makes life a lot easier

* Builtins

- Added information about the current bug faced in issue #81 (third sub-issue)

* Test cases

- Updated test case `simple_arrays2.t` to show case bug sub-issue 3 in issue #81

* Builtins

- Removed seperate handling of `<componentType>[]` and incorporated it into the pointer check, now we have fixed sub-issue 3 of issue #81

Test cases

- Updated test case `simple_arrays2.t` to showcase the aforementioned fix

* Builtins

- Updated TODO

* Builtins

- Removed comment as now fixed

* Array

- Added `getComponentType()` method which will return the array's element type

* Dependency

- When processing the `Array` type which is now to be seen  as a stack-based array (fixed size), error out in processing it during variable declarations

* Builtins

- Added `bool isStackArray(string)` in order to check if a given type string is designated as a stack-array type or not
- `Type getBuiltInType(TypeChecker, string)` now can generate the `StackArray` type including the component type and the size of the stack allocation

Parser

- Added support to`parseTypedDeclaration` to be able to parse stack-based array types
- Added terminator `]` to `parseExpression()`

DGen

- Added stack-based array type transformation support to `string typeTransform(Type)`
- Added transformation support for stack-based arrays for the `VariableDeclaration` instruction

StackArray

- Renamed `Array` type to `StackArray`
` The `StackArray` type now has an `arraySize` field and is included in the constructor's paremeters
- Added a `getAllocatedSize()` method to retrieve the `arraySize` field

Dependency

- Temporarily enabled the `StackArray` type in dependency processing for `VariableDeclarations` such that we can continue through the pipeline

Test cases

- Updated `simple_arrays.t` to test stack-based array types

* Tets cases

- Added new test case for testing (later) multi-dimensional stack-arrays

* Parser

- Working on adding array index assignment support

Test cases

- Added test case to test array assignments with

* Parser

- We can now detect when infact we are doing an array-indexed assignment and when not, we then flip` arrayIndexing` to `true` if that is the case and ensure that `=` SymbolType.ASSIGN is not triggering the varaible-declaration-with-assignment but rather eters a different branch based on this boolean
- Set the identifier being assigned to (in the array indexing case) to the `type` with the `[]...` stripped

Notes

- Added a TODO file `wip.txt` with notes about what is to be done for adding full array support

* Parser

- Handle the case whereby `SymbolType.ASSIGN` or `SymbolType.IDENT_TYPE` is not found by throwing an error

* Parser

- Moved logic for array assignments into the branch for it (deferred it)

* Data

- Added new work-in-progress parser node type `ArrayAssignment`

Parser

- Added TODO about the type of returned parse node needing to be updated down the line

Notes

- Updated `wip.txt` with more thoughts

* Expressions

- Added new parse node (a sub-type of `Expression`) for representing array indexing; `ArrayIndex`

Data

- Fixed compilation error caused by missing semi-colon

* Parser

- Added support for array accesses/indexing in `parseExpression()`
- Added a token-rerun mechanism that lets us replay the needed tokens which needed to be looked ahead in order to determine an array access was about to occur

* Parser

- Removed now-completed TODO relating to array accesses in `parseExpression()`

* Parser

- Added right-hand side expression parsing for array assignments

Test cases

- Updated test case to test both array expressions on the left-hand side of an assignment and as a free-standing expression on the right hand side

Data

- Implemeneted `ArrayAssignment` which is to be used for assigning into arrays

* Instruction

- Added new instruction for indexing into arrays, a new `Value`-type instruction called `ArrayIndexInstruction`

* DGen

- Handle `ArrayIndexInstruction` which is for whenever you index into a point-based array (an expression like `myArray[i]` is now being supported in emit (first steps))

* Instructions

- Added a new instruction type, `StackArrayINdexInstruction`, which is used to know when we are indexing into a stack-based array rather than a pointer-based array (just to be able to disambiguate between the two)
- Added a work-in-progress type `StackArrayIndexAssignmentInstruction` which will be used for assigning to stack arrays at a given index

* Instructions

- Added implementation for `StackArrayIndexAssignmentInstruction` which represents the assignment of some `Value` instruction to a stack-based array (indicated by the `arrayName` string field) at the index indicated by the provided `Value` instruction

* DGen

- Added a stub emitter for `ArrayIndexInstruction` (pointer-based array indexing)
- Added a stub emitter for `StackArrayINdexInstruction` (stack-array based array indexing)

* INstructions

- Added `getArrayName()`, `getIndexInstr()` and `getAssignedValue()` to `StackArrayIndexAssignmentInstruction`

* Instructions

- Added `ArrayIndexAssignmentInstruction` which is intended to be used for when one wants to assign into a pointer-based array
- It embeds a `Value` instruction which is what is to be assigned and then an `ArrayIndexInstruction` representing the base of the poiinter-based array (base address) coupled with an "index" (offset)

- Added a `toString()` override for `StackArrayIndexAssignmentInstruction`

* Test cases

- Added `complex_stack_arrays1.t`
- This tests a stack array of a fixed size of `int[]` (basically `int*`) and assigneing into it

* Test cases

- Added `simple_arrays4.t` which makes an `int[]` (which is an `int*`) and then assignes into it at `i` whilst referring to itself at `i` and doing a binary operation

* Test cases

- Added `simple_stack_arrays2.t` which tests a stack array of a fixed size and then assigns into it a value

* Test cases

- Added `simple_stack_arrays4.t` which just tests assigning to a stack array of a fixed size BUT referring to said stack array itself as part of the assignment expression

* DGen

- Removed TODO comment for `ArrayIndexInstruction` transformation branch
- Added a description for when the `ArrayIndexInstruction` branch is activated for a transformation
- Implemented transformation for `ArrayIndexInstruction`
- Added comment on when `ArrayIndexAssignmentInstruction` activates
- Implemented transformation for `ArrayIndexAssignmentInstruction`
- Added comment for when the `StackArrayIndexInstruction` branch activates
- Implemented transformation for `StackArrayIndexInstruction`
- Added comment for when `StackArrayIndexAssignmentInstruction` branch activates
- Implemented transformation for `StackArrayIndexAssignmentInstruction`

* Dependency

- Added dependency node generation for the `ArrayIndex`
- This will pool the `ArrayIndex` parser-node
- This will then set the context of the parser-node to the current context
- The index expression will be depended upon
- The indexed expression (the entity being indexed) will be depended upon

---

- Added dependency generation for `ArrayAssignment`
- The `ArrayAssignment` parser node will be pooled
- The `ArrayAssignment` will have its context set to the current context
- The assigned expression will be depended upon
- The entity being indexed will be depended upon
- The index expression will be depended upon

* Parser

- Added a branch to `parseName()` which handles array assignments's semicolon consumption and token cursor movement to the next token
- Updated `parseTypedDeclaration()` to return an object of type `Statement` rather than `TypedEntity`
- Disabled the intentional `assert(false)` when handling array assignments
- Assign the generated `ArrayAssignment` to the `generated` variable
- Updated `parseExtern()` to cast to `TypedEntity` to ensure that the `Statement` returned is of that sub-type (added an assertion to then check this fact)

* Typechecker/Codegen

- Implemented `isStackArray(Value)` which checks if the given `Value` instruction is a `FetchValueVar`, then extracts the `Variable` being referred to in said instruction and checks if its declared type is that of `StackArray`
- Implemented code generation for `ArrayAssignment`
- Implemented code generation for `ArrayIndex`

* Test cases

- WIP: Added `simple_stack_array_coerce.t` as we want to add coercion for this now

* Typecheck

- Added rudimentary check for checking if an argument is a stack array, and if the parameter (to a function call) is a pointer and if so then returns whether they have matching component types in a new function named `canCoerceStackArray(Type, Type)`

* Typecheck

- Fixed `canCoerceStackArray(Type, Type)` to actually coerce the first type first into a pointer type (coercing the stack array's component type to `<compType>*`) and THEN apply the `isSameType(Type, Type)` check

* Typecheck

- Hoisted up `canCoerceStackArray(Type, Type)` to the class-level of `TypeChecker`
- Removed debug prints from `canCoerceStackArray(Type, Type)`
- Added a TODO where the check should be done in the `FunctionCall` branch of the `DNode` processor

* TypeChecker

- Added a seperate check for function call `DNode` processing which now checks if we can coerce the stack-array-based argument to the pointer-based type parameter

Notes

- Emit now fails as we haven't implement an emit for this case, so we need to do that.
- Also, should we change the type of what is being passed in - perhaps that actually makes sense here - we haven't fully coerced it actually

* TypeChecker

- Updated `canCoerceStackArray(Type, Type)` to now take in `canCoerceStackArray(Type, Type, ref Type)` to set the newly created coerced type
- Fixed bug whereby if the coercion succeeded we didn't actually add to the list of evaluation-instructions in the `FuncCallInstr` object, hence there would be a `null` Instruction object appearing in the code emit phase.
- Added some NOTEs which we can clean up this code using

* TypeChecker

- Cleaned up commented-out code

* Added CI/CD test for 'simple_stack_array_coerce.t'

* Added CI/CD test for 'complex_stack_arrays1.t'

* Added CI/CD semantic tests (WIP) for 'simple_stack_array_coerce.t' and 'complex_stack_arrays1.t'

* Added CI/CD semantic tests (WIP) for 'simple_arrays2.t' and 'simple_arrays4.t'

* Added CI/CD semantic tests (WIP) for 'simple_arrays2.t' and 'simple_arrays4.t'

* Added CI/CD semantic tests (WIP) for 'simple_arrays2.t' and 'simple_arrays4.t'

* Fixed filepath for test 'simple_arrays.t'

* Fixed typechecking tests for arrays

* DGen

- Added instrumentation for `simple_stack_array_coerce.t`

Test cases

- Updated `simple_stack_array_coerce.t` to update the array passed in a manner such that we can sum the two elements later, return it and assert to ensure it is set correctly

* Parser

- Had to ensure the old identifier code was removed too, was too early; therefore this now-dead code was removed

* Test cases

- Added this test (even though it is a bad test, the syntax ie wrong)

* Test cases

- Update `simple_stack_arrsys4.t` to return an `int` such that we can verify it works.
- Also added more tests to it.

DGen

- Added semantic test code generation for `simple_stack_arrays4.t`

CI

- Re-organised tests for semantics in emit for arrays into those "Which have semantic tests" and "those which don't (yet)"
- Added semantic/emit test for `simple_stack_arrays4.t`

* Test cases

- Updated `simple_arrays2.t` to test casting of complex array types

* Test cases

- Updated `complex_stack_arrays1.t`

* Test cases

- Added new test for testing pointer syntax; `simple_stack_array_coerce_ptr_syntax.t`
- FIXME: It is broken as we don't have the latest pointer code - that must still be finished

* Test cases

- Added test case `simple_stack_array_ceorce_wrong.t` where coercion must fail

* Test cases

- Added `simple_pointer_array_syntax.t` which should test the `int[] == int*` stuff

* DGen

- Made semantic test for `simple_pointer_array_syntax.t`

Test cases

- Added a test for `simple_pointer_array_syntax.t.t`

* Branding

- Added logo here

* Test cases

- Addes semantic code emit instrucmentation for `simple_stack_array_coerce_ptr_syntax.t`

* Pipelines

- Added test case for `source/tlang/testing/simple_stack_array_coerce_wrong.t` for typechecking phase

* Test cases

- Added test case `complex_stack_array_coerce.t`

* Test cases

- Added extensive positive test case `complex_stack_array_coerce_permutation_good.t` which has a lot of different ways to write `int**` (think `int*[]` etc)
- Added negative test cases `complex_stack_array_coerce_bad1.t`, `complex_stack_array_coerce_bad2.t` and `complex_stack_array_coerce_bad3.t`
2023-04-20 11:21:50 +02:00
Tristan B. Velloza Kildaire 493da1a4e7
Pointer support (#2)
* Make branches not identical

* Removed temporary file

* Typecheck

- Added `attemptPointerAriehmeticCoercion(Value, Value)`

* Typechecker

- Moved `attemptPointerAriehmeticCoercion(Value, Value)` to class-level and made privately accessible

* Test cases

- Added pointer arithmetic in the form of `*(ptr+0)` to `simple_pointer.t` to start testing it out

* Typechecker

- When handling `BinaryOperatorExpression` call `attemptPointerAriehmeticCoercion(Value, Value)` with both `(vLhsInstr, vRhsInstr)` before we call `vLhsInstr.getInstrType()` and `vRhsInstr.getInstrType()` before `isSameType(vLhsType, vRhsType)`. By doing so we attempt to coerce the types of both instructions if one is a pointer and another is an integer, else do nothing

* DGen

- When emitting for `PointerDereferenceAssignmentInstruction` we didn't wrap `<expr>` with `()`. So instead of `*(<expre>)` we got `*<expr>` which doesn't work if you're doing pointer arithmetic

* Test cases

- Added `simple_pointer_cast.t` to test casting (currently broken parsing-wise)

DGen

- Added a todo for semantic tests for the `simple_pointer_cast.t` test case

* Parser

- Added a TODO - we need a `parseType()`

* Test cases

- Removed `simple_cast_complex_type.t` as it is wrong, syntax wise

* Test cases

- Removed coercion usage, I am only testing the casting here (explicit)

* Test cases

- Removed `simple_pointer_cast.t` and replace it with `simple_pointer_cast_le.t` which casts the integer pointer to a byte pointer and sets the lowest significant byte (little endian hence at base of integer) to `2+2`

DGen

- Added semantic test for `simple_pointer_cast_le.t`

* Test cases

- Update `simple_pointer_cast_le.t` to do some pointer airthmetic at the byte-level of the 32-bit integer

DGen

- Updated the semantic test code generation for `simple_pointer_cast_le.t` to check for new values

* Added 'simple_pointer_cast_le.t' to Emit tests

* TypeChecker

- Update `isSameType(Type t1, Type t2)` to now handle pointers explicitly and in a recursive manner based on their referred types
- This check occurs before the `Integer` type check therefore following the rule of most specific types to least

* Test cases

- Added new test case `simple_pointer_malloc.t`
- Added semantic code test generation for `simple_pointer_malloc.t`
- Added `malloc_test.sh` to compile and generate `mem.o` from `mem.c` to link it then with `simple_pointer_malloc.t`
- Added `mem.c`  external C file to generate the required `mem.o` for linking against `simple_pointer_malloc.t`

* Test cases

- Updated `malloc_test.sh` to look for any `brk()` system calls and fixed its interpreter path
2023-04-17 16:50:11 +02:00
Tristan B. Velloza Kildaire a346f60c2e Ensure that 'simple_literals4.t' fails as it tests a range violation during coercion 2023-04-12 11:42:21 +02:00
Tristan B. Velloza Kildaire ae038c4182 Ensure 'simple_float_constant_bad.t' passes as a failure as it checks for a bad floating point 2023-04-12 11:38:26 +02:00
Tristan B. Velloza Kildaire a8d244188e Ensure that a failure passes for 'simple_literals2.t' which checks for a failing to coerce due to incompatible types (actually) 2023-04-12 11:36:31 +02:00
Tristan B. Velloza Kildaire e80571758f Ensure that a failure passes for 'simple_literals2.t' which checks for a failing to coerce due to incompatible types 2023-04-12 11:33:34 +02:00
Tristan B. Velloza Kildaire d99b23d64c Disabled 'test3.t' as it is not the focus rn 2023-04-12 09:57:13 +02:00
Tristan B. Velloza Kildaire b4a02addcf Disabled 'simple_oop.t' as it is not the focus rn 2023-04-12 09:55:12 +02:00
Tristan B. Velloza Kildaire 5e298e599b Else without if test case should fail 2023-04-12 09:51:40 +02:00
Tristan B. Velloza Kildaire 6dc3c78792 All collision and precedence checks are failing-positives and should be treated as such 2023-04-12 09:49:08 +02:00
Tristan B. Velloza Kildaire 9ffd3425a0 Removed 'typecheck/simple_array.t' testing as that is old 2023-04-12 09:45:34 +02:00
Tristan B. Velloza Kildaire 8b97531b71 Try to fix falining-positive test case 'simple_function_call_1.t' 2023-04-12 09:42:44 +02:00
Tristan B. Velloza Kildaire 59f8b7c01a Try new technique 2023-04-12 09:39:30 +02:00
Tristan B. Velloza Kildaire ac2fbc86de Allow steps to run even if previous ones failed 2023-04-12 09:33:57 +02:00
Tristan B. Velloza Kildaire fefaa6e434 Renamed test case 2023-04-12 09:31:10 +02:00
Tristan B. Velloza Kildaire a973f60d54 When typechecking 'simple_function_call_1.t' we WANT it to fail, hence exiting with 255 is what we want, anything else is an error 2023-04-12 09:08:56 +02:00
Tristan B. Velloza Kildaire 4144c4accf Fixed emit test for 'Simple conditionals' 2023-04-12 09:04:11 +02:00
Tristan B. Velloza Kildaire 4d457c2eb3 Disabled 'simple_variables.t' as it uses the now-currently unsupported 'discard' keyword 2023-04-12 08:59:19 +02:00