diff --git a/source/tlang/compiler/codegen/emit/dgen.d b/source/tlang/compiler/codegen/emit/dgen.d
index b0f4f029..4c4089e5 100644
--- a/source/tlang/compiler/codegen/emit/dgen.d
+++ b/source/tlang/compiler/codegen/emit/dgen.d
@@ -48,9 +48,8 @@ public final class DCodeEmitter : CodeEmitter
gprintln("Is ContextNull?: "~to!(string)(context is null));
gprintln("Wazza contect: "~to!(string)(context.container));
auto typedEntityVariable = context.tc.getResolver().resolveBest(context.getContainer(), varAs.varName); //TODO: Remove `auto`
- string typedEntityVariableName = context.tc.getResolver().generateName(context.getContainer(), typedEntityVariable);
- string renamedSymbol = SymbolMapper.symbolLookup(context.getContainer(), typedEntityVariableName);
+ string renamedSymbol = SymbolMapper.symbolLookup(typedEntityVariable);
// If we are needed as part of a VariabvleDeclaration-with-assignment
@@ -77,7 +76,6 @@ public final class DCodeEmitter : CodeEmitter
Context context = varDecInstr.getContext();
Variable typedEntityVariable = cast(Variable)context.tc.getResolver().resolveBest(context.getContainer(), varDecInstr.varName); //TODO: Remove `auto`
- string typedEntityVariableName = context.tc.getResolver().generateName(context.getContainer(), typedEntityVariable);
//NOTE: We should remove all dots from generated symbol names as it won't be valid C (I don't want to say C because
// a custom CodeEmitter should be allowed, so let's call it a general rule)
@@ -86,7 +84,7 @@ public final class DCodeEmitter : CodeEmitter
//NOTE: We may need to create a symbol table actually and add to that and use that as these names
//could get out of hand (too long)
// NOTE: Best would be identity-mapping Entity's to a name
- string renamedSymbol = SymbolMapper.symbolLookup(context.getContainer(), varDecInstr.varName);
+ string renamedSymbol = SymbolMapper.symbolLookup(typedEntityVariable);
// Check to see if this declaration has an assignment attached
@@ -126,9 +124,11 @@ public final class DCodeEmitter : CodeEmitter
Context context = fetchValueVarInstr.getContext();
Variable typedEntityVariable = cast(Variable)context.tc.getResolver().resolveBest(context.getContainer(), fetchValueVarInstr.varName); //TODO: Remove `auto`
- string typedEntityVariableName = context.tc.getResolver().generateName(context.getContainer(), typedEntityVariable);
- string renamedSymbol = SymbolMapper.symbolLookup(context.getContainer(), typedEntityVariableName);
+ //TODO: THis is giving me kak (see issue #54), it's generating name but trying to do it for the given container, relative to it
+ //TODO: We might need a version of generateName that is like generatenamebest (currently it acts like generatename, within)
+
+ string renamedSymbol = SymbolMapper.symbolLookup(typedEntityVariable);
return renamedSymbol;
}
diff --git a/source/tlang/compiler/codegen/mapper.d b/source/tlang/compiler/codegen/mapper.d
index 730d5154..9811a7da 100644
--- a/source/tlang/compiler/codegen/mapper.d
+++ b/source/tlang/compiler/codegen/mapper.d
@@ -24,13 +24,20 @@ public final class SymbolMapper
// this.tc = tc;
// }
- public static string symbolLookup(Container container, string entityNameIn)
+ /**
+ * Given an Entity this will generate a unique (but consistent)
+ * symbol name for it by taking the md5 hash of the full absolute
+ * path to the Entity and finally prefixing it with t_
.
+ *
+ * Params:
+ * entityIn = The Entity to generate a hash for
+ *
+ * Returns: The symbol hash
+ */
+ public static string symbolLookup(Entity entityIn)
{
- // Firstly translate the entity name to the full absolute path
- auto entity = tc.getResolver().resolveBest(container, entityNameIn); //TODO: Remove `auto`
- string entityNameAbsolute = tc.getResolver().generateName(tc.getModule(), entity);
-
- gprintln("symbolLookup(): "~to!(string)(container));
+ // Generate the absolute full path of the Entity
+ string absoluteFullPath = tc.getResolver().generateNameBest(entityIn);
// Hash the absolute path name
// FIXME: Ensure these hashes are unique (use the smbyol table!)
@@ -38,11 +45,9 @@ public final class SymbolMapper
import std.digest.md : md5Of;
// Generate the name as `_`
- string symbolName = toHexString!(LetterCase.lower)(md5Of(entityNameAbsolute));
+ string symbolName = toHexString!(LetterCase.lower)(md5Of(absoluteFullPath));
symbolName="t_"~symbolName;
return symbolName;
}
-
-
}
\ No newline at end of file
diff --git a/source/tlang/compiler/typecheck/dependency/core.d b/source/tlang/compiler/typecheck/dependency/core.d
index 905585f0..b45e36f9 100644
--- a/source/tlang/compiler/typecheck/dependency/core.d
+++ b/source/tlang/compiler/typecheck/dependency/core.d
@@ -723,7 +723,7 @@ public class DNodeGenerator
nearestName = path;
/* Resolve the Entity */
- Entity namedEntity = tc.getResolver().resolveWithin(context.getContainer(), nearestName);
+ Entity namedEntity = tc.getResolver().resolveBest(context.getContainer(), nearestName);
@@ -1284,6 +1284,7 @@ public class DNodeGenerator
else if(cast(VariableAssignmentStdAlone)entity)
{
VariableAssignmentStdAlone vAsStdAl = cast(VariableAssignmentStdAlone)entity;
+ vAsStdAl.setContext(context);
/* TODO: CHeck avriable name even */
gprintln("YEAST ENJOYER");
@@ -1297,8 +1298,6 @@ public class DNodeGenerator
Variable variable = cast(Variable)tc.getResolver().resolveBest(c, vAsStdAl.getVariableName());
assert(variable);
- /* Set the context of the assignment to the Context of the Variable being assigned to */
- vAsStdAl.setContext(variable.getContext());
/* Pool the variable */
DNode varDecDNode = pool(variable);
diff --git a/source/tlang/compiler/typecheck/resolution.d b/source/tlang/compiler/typecheck/resolution.d
index a51b5a96..3afbaf16 100644
--- a/source/tlang/compiler/typecheck/resolution.d
+++ b/source/tlang/compiler/typecheck/resolution.d
@@ -16,9 +16,48 @@ public final class Resolver
this.typeChecker = typeChecker;
}
+ /**
+ * Generate the absolute full path of the given Entity
+ *
+ * Params:
+ * entity = The Entity to generate the full absolute path for
+ *
+ * Returns: The absolute full path
+ */
+ public string generateNameBest(Entity entity)
+ {
+ string absoluteFullPath;
+
+ assert(entity);
+
+ /**
+ * Search till we get to the top-most Container
+ * then generate a name relative to that with `generateName(topMostContainer, entity)`
+ */
+ Entity parentingEntity = entity;
+
+ while(true)
+ {
+ parentingEntity = cast(Entity)parentingEntity.parentOf();
+
+ if(parentingEntity.parentOf() is null)
+ {
+ break;
+ }
+ }
+
+ absoluteFullPath = generateName(cast(Container)parentingEntity, entity);
+
+
+ return absoluteFullPath;
+ }
+
+
/**
* Given an Entity generate it's full path relative to a given
- * container
+ * container, this is akin to `generateNameWithin()` in the
+ * sense that it will fail if the entity prvided is not
+ * contained by `relativeTo` - returning null
*/
public string generateName(Container relativeTo, Entity entity)
{
@@ -89,6 +128,7 @@ public final class Resolver
/* If not */
else
{
+ //TODO: technically an assert should be here and the one in isDescdant removed
return null;
}
}
@@ -115,6 +155,10 @@ public final class Resolver
do
{
+ gprintln("c isdecsenat: "~to!(string)(c));
+ gprintln("currentEntity: "~to!(string)(currentEntity));
+ gprintln("currentEntity(parent): "~to!(string)(currentEntity.parentOf()));
+
/**
* TODO: Make sure this condition holds
*
diff --git a/source/tlang/testing/simple_function_decls.t b/source/tlang/testing/simple_function_decls.t
index 3f78bdc1..d75fc1f8 100644
--- a/source/tlang/testing/simple_function_decls.t
+++ b/source/tlang/testing/simple_function_decls.t
@@ -12,6 +12,6 @@ int banana(int j)
{
int h = 64;
- k=1+h+apple(1, apple(2, 3));
+ k=1+h+apple(1, apple(2, 3))+k;
}
\ No newline at end of file