Merge branch 'vardec_varass_dependency' into feature/poolmngr

feature/poolmngr
Tristan B. V. Kildaire 3 months ago
parent 16e40c7b1e
commit 69bb8c05a8

@ -16,6 +16,8 @@ import std.container.slist;
import std.algorithm : reverse;
import tlang.compiler.typecheck.meta;
import tlang.compiler.configuration;
import tlang.compiler.typecheck.dependency.store.interfaces : IFuncDefStore;
import tlang.compiler.typecheck.dependency.store.impls : FuncDefStore;
/**
* The Parser only makes sure syntax
@ -107,14 +109,6 @@ public final class TypeChecker
/* TODO: Implement me */
checkClassInherit(modulle);
// TODO: Issue 88: Don't use static state
scope(exit)
{
/* Clear the FunctionData map (for next compilation) */
clearFuncDefs();
}
/**
* Dependency tree generation
*
@ -128,10 +122,12 @@ public final class TypeChecker
// Create a pooling mechanism
import tlang.compiler.typecheck.dependency.pool.interfaces;
import tlang.compiler.typecheck.dependency.pool.impls;
IPoolManager poolManager = new PoolManager();
/* Create the dependency generator */
DNodeGenerator dNodeGenerator = new DNodeGenerator(poolManager, this);
IPoolManager poolManager = new PoolManager();
IFuncDefStore funcDefStore = new FuncDefStore(this, poolManager);
DNodeGenerator dNodeGenerator = new DNodeGenerator(this, poolManager, funcDefStore);
/* Generate the dependency tree */
DNode rootNode = dNodeGenerator.generate(); /* TODO: This should make it acyclic */
@ -162,7 +158,7 @@ public final class TypeChecker
assert(codeQueue.empty() == true);
/* Grab functionData ??? */
FunctionData[string] functionDefinitions = grabFunctionDefs();
FunctionData[string] functionDefinitions = funcDefStore.grabFunctionDefs();
gprintln("Defined functions: "~to!(string)(functionDefinitions));
foreach(FunctionData funcData; functionDefinitions.values)
@ -213,8 +209,6 @@ public final class TypeChecker
gprintln("FUNCDEF DONE: "~to!(string)(functionBodyCodeQueues[funcData.name]));
}
// NOTE: Check scope guard for "exit routines" which run here
}

@ -15,6 +15,7 @@ import tlang.compiler.symbols.typing.builtins;
import tlang.compiler.typecheck.dependency.exceptions : DependencyException, DependencyError;
import tlang.compiler.typecheck.dependency.pool.interfaces;
import tlang.compiler.typecheck.dependency.pool.impls;
import tlang.compiler.typecheck.dependency.store.interfaces : IFuncDefStore;
/**
@ -93,72 +94,6 @@ public struct FunctionData
}
}
/**
* All declared functions
*/
private FunctionData[string] functions;
/**
* Returns the declared functions
*/
public FunctionData[string] grabFunctionDefs()
{
return functions;
}
/**
* Clars the `FunctionData[string]` map
*
* This is called normally after the
* typechecking and code generation such
* that the module-static field inside
* this module can be cleared and not
* persist across compilations
*/
public void clearFuncDefs()
{
foreach(string key; functions.keys())
{
functions.remove(key);
}
}
/**
* Creates a new FunctionData and adds it to the
* list of declared functions
*
* Requires a TypeChecker `tc`
*/
private void addFunctionDef(IPoolManager poolManager, TypeChecker tc, Function func)
{
/* (Sanity Check) This should never be called again */
foreach(string cFuncKey; functions.keys())
{
FunctionData cFuncData = functions[cFuncKey];
Function cFunc = cFuncData.func;
if(cFunc == func)
{
assert(false);
}
}
/**
* Create the FunctionData, coupled with it own DNodeGenerator
* context etc.
*/
FunctionData funcData;
funcData.ownGenerator = new DFunctionInnerGenerator(poolManager, tc, func);
funcData.name = func.getName();
funcData.func = func;
functions[funcData.name] = funcData;
}
/**
* DNode
*
@ -405,9 +340,9 @@ public final class DFunctionInnerGenerator : DNodeGenerator
{
private Function func;
this(IPoolManager poolManager, TypeChecker tc, Function func)
this(TypeChecker tc, IPoolManager poolManager, IFuncDefStore funcDefStore, Function func)
{
super(poolManager, tc);
super(tc, poolManager, funcDefStore);
this.func = func;
}
@ -438,35 +373,7 @@ public class DNodeGenerator
*/
private DNode[string] functionDefinitions;
/**
* Given a DNode generated by a Function (function definition)
* this will extract the name of the function and save the DNode
* into the map for later retrieval by `retrieveFunctionDefinitionNode`
*/
private void saveFunctionDefinitionNode(DNode funcDefNode)
{
gprintln("saveFunctionDefinitionNode: Implement me please");
// Extract the name of the function
Function functionDefinition = cast(Function)funcDefNode.getEntity();
assert(functionDefinition);
string functionNameAbsolutePath = resolver.generateName(cast(Container)root.getEntity(), cast(Entity)functionDefinition);
// Save to the map
functionDefinitions[functionNameAbsolutePath] = funcDefNode;
}
/**
* Given the absolute path to a function, this will retrieve the
* Function (function definition) DNode from the map
*/
private DNode retrieveFunctionDefinitionNode(string functionAbsolutePath)
{
gprintln("retrieveFunctionDefinitionNode: Implement me please");
// TODO: Add an assertion for failed lookup
return functionDefinitions[functionAbsolutePath];
}
private IFuncDefStore funcDefStore;
/**
* Dependency node pooling
@ -474,7 +381,7 @@ public class DNodeGenerator
*/
private IPoolManager poolManager;
this(IPoolManager poolManager, TypeChecker tc)
this(TypeChecker tc, IPoolManager poolManager, IFuncDefStore funcDefStore)
{
// /* NOTE: NEW STUFF 1st Oct 2022 */
// Module modulle = tc.getModule();
@ -488,6 +395,7 @@ public class DNodeGenerator
this.tc = tc;
this.resolver = tc.getResolver();
this.funcDefStore = funcDefStore;
/* TODO: Make this call in the TypeChecker instance */
//generate();
@ -1249,7 +1157,7 @@ public class DNodeGenerator
/* Add funtion definition */
gprintln("Hello");
addFunctionDef(poolManager, tc, func);
this.funcDefStore.addFunctionDef(func);
return null;
}

@ -0,0 +1,127 @@
/**
* Provides implementation of the `IFuncDefStore`
* interface
*/
module tlang.compiler.typecheck.dependency.store.impls;
import tlang.compiler.typecheck.dependency.store.interfaces;
import tlang.compiler.symbols.data : Function;
import tlang.compiler.typecheck.dependency.core : FunctionData, DFunctionInnerGenerator;
import tlang.compiler.typecheck.core : TypeChecker;
import tlang.compiler.typecheck.dependency.pool.interfaces : IPoolManager;
/**
* An implementation of the `IFuncDefStore`
* which provides us with a way to store
* function definitions and retrieve them
* later
*/
public final class FuncDefStore : IFuncDefStore
{
/**
* All declared functions
*/
private FunctionData[string] functions;
/**
* The type checker instance
*/
private TypeChecker tc;
/**
* The pool management
*/
private IPoolManager poolManager;
/**
* Constructs a new function
* definition store with
* the provided type
* checking instance
*
* Params:
* typeChecker = the `TypeChecker`
* poolManager = the `IPoolManager`
*/
this(TypeChecker typeChecker, IPoolManager poolManager)
{
this.tc = typeChecker;
this.poolManager = poolManager;
}
/**
* Adds the function definition
* to the store
*
* Params:
* func = the function to add
* Throws:
* FuncDefStoreException if the function
* has already been added
*/
public void addFunctionDef(Function func)
{
/* (Sanity Check) This should never be called again */
foreach(string cFuncKey; functions.keys())
{
FunctionData cFuncData = functions[cFuncKey];
Function cFunc = cFuncData.func;
if(cFunc == func)
{
throw new FuncDefStoreException("The provided Function already exists within the store");
}
}
/**
* Create the FunctionData, coupled with it own DNodeGenerator
* context etc.
*/
FunctionData funcData;
funcData.ownGenerator = new DFunctionInnerGenerator(tc, this.poolManager, this, func);
// TODO: Should we not generate a HELLA long name rather, to avoid duplication problems and overwrites of key values
funcData.name = tc.getResolver().generateName(tc.getModule(), func);
funcData.name = func.getName();
funcData.func = func;
functions[funcData.name] = funcData;
}
/**
* Grabs all of the function
* definitions currently stored
*
* Returns: a `FunctionData[string]`
* map
*/
public FunctionData[string] grabFunctionDefs()
{
return this.functions.dup;
}
/**
* Grabs a function definition by its
* name
*
* Params:
* name = the name of the function
* Returns: the `FunctionData`
* Throws:
* FuncDefStoreException if the function
* could not be found
*/
public FunctionData grabFunctionDef(string name)
{
if(name in this.functions)
{
return this.functions[name];
}
else
{
throw new FuncDefStoreException("Could not find function by name '"~name~"'");
}
}
}

@ -0,0 +1,70 @@
/**
* Provides the definition of a function definition
* store and retrieval system
*/
module tlang.compiler.typecheck.dependency.store.interfaces;
import tlang.compiler.symbols.data : Function;
import tlang.compiler.typecheck.dependency.core : FunctionData;
import misc.exceptions : TError;
/**
* Represents a storage mechanism
* which can store and retrieve
* function definition datas
*/
public interface IFuncDefStore
{
/**
* Adds the function definition
* to the store
*
* Params:
* func = the function to add
* Throws:
* FuncDefStoreException if the function
* has already been added
*/
public void addFunctionDef(Function func);
/**
* Grabs all of the function
* definitions currently stored
*
* Returns: a `FunctionData[string]`
* map
*/
public FunctionData[string] grabFunctionDefs();
/**
* Grabs a function definition by its
* name
*
* Params:
* name = the name of the function
* Returns: the `FunctionData`
* Throws:
* FuncDefStoreException if the function
* could not be found
*/
public FunctionData grabFunctionDef(string name);
}
/**
* Exception thrown when an error occurs
* with the `IFuncDefStore` system
*/
public final class FuncDefStoreException : TError
{
/**
* Constructs a new `FuncDefStoreException`
* with the given error message
*
* Params:
* msg = the error message
*/
this(string msg)
{
super(msg);
}
}
Loading…
Cancel
Save