diff --git a/source/tlang/compiler/codegen/instruction.d b/source/tlang/compiler/codegen/instruction.d index be56e8de..f205313b 100644 --- a/source/tlang/compiler/codegen/instruction.d +++ b/source/tlang/compiler/codegen/instruction.d @@ -106,8 +106,12 @@ public final class VariableDeclaration : StorageDeclaration //simple_variables.x -> simple_variables_x //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 = symbolRename(typedEntityVariableName); + import compiler.codegen.mapper : SymbolMapper; + renamedSymbol = SymbolMapper.symbolLookup(context.getContainer(), varName); + return varType~" "~renamedSymbol~";"; } } diff --git a/source/tlang/compiler/codegen/mapper.d b/source/tlang/compiler/codegen/mapper.d new file mode 100644 index 00000000..b944625c --- /dev/null +++ b/source/tlang/compiler/codegen/mapper.d @@ -0,0 +1,44 @@ +module compiler.codegen.mapper; + +import compiler.typecheck.core; +import compiler.symbols.data; + +/** + * SymbolMapper + * + * Maps Entity's to consistent but unique symbol + * names (strings) + */ +public final class SymbolMapper +{ + // Used to map names to entities + public static TypeChecker tc; + + // Entity map + // private string[Entity] symbolMap; + + // this(TypeChecker tc) + // { + // this.tc = tc; + // } + + public static string symbolLookup(Container container, string entityNameIn) + { + // 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); + + // Hash the absolute path name + // FIXME: Ensure these hashes are unique (use the smbyol table!) + import std.digest : toHexString, LetterCase; + import std.digest.md : md5Of; + + // Generate the name as `_` + string symbolName = toHexString!(LetterCase.lower)(md5Of(entityNameAbsolute)); + symbolName="_"~symbolName; + + return symbolName; + } + + +} \ No newline at end of file diff --git a/source/tlang/compiler/typecheck/core.d b/source/tlang/compiler/typecheck/core.d index d7491619..b2147fba 100644 --- a/source/tlang/compiler/typecheck/core.d +++ b/source/tlang/compiler/typecheck/core.d @@ -71,6 +71,10 @@ public final class TypeChecker // Allow Context class access to the type checker (used in Instruction where only Context is available) Context.tc = this; + // Allow the SymbolMapper class to access the type checker + import compiler.codegen.mapper : SymbolMapper; + SymbolMapper.tc = this; + // DNodeGenerator.staticTC = this;