diff --git a/source/tlang/compiler/codegen/instruction.d b/source/tlang/compiler/codegen/instruction.d index aeb50f2c..c927ff01 100644 --- a/source/tlang/compiler/codegen/instruction.d +++ b/source/tlang/compiler/codegen/instruction.d @@ -5,6 +5,8 @@ import compiler.typecheck.dependency.core : Context; import std.string : cmp; import misc.utils : symbolRename; import compiler.symbols.data : SymbolType; +import compiler.symbols.check : getCharacter; +import gogga; public class Instruction { @@ -69,7 +71,13 @@ public class VariableAssignmentInstr : Instruction public override string emit() { - return "=", tokenStr) == 0 || cmp("<=", tokenStr) == 0; } - +/** + * Returns the corresponding character for a given SymbolType + * + * For example SymbolType.ADD returns + + * + * Params: + * symbolIn = The symbol to lookup against + * Returns: The corresponding character + * + */ +public string getCharacter(SymbolType symbolIn) +{ + if(symbolIn == SymbolType.ADD) + { + return "+"; + } + else + { + gprintln("getCharacter: No back-mapping for "~to!(string)(symbolIn), DebugType.ERROR); + assert(false); + } +} /* Test: Character literal */ unittest diff --git a/source/tlang/compiler/typecheck/core.d b/source/tlang/compiler/typecheck/core.d index b2147fba..41aba079 100644 --- a/source/tlang/compiler/typecheck/core.d +++ b/source/tlang/compiler/typecheck/core.d @@ -613,6 +613,7 @@ public final class TypeChecker else if(cast(compiler.typecheck.dependency.variables.VariableAssignmentNode)dnode) { import compiler.typecheck.dependency.variables; + /* Get the variable's name */ string variableName; VariableAssignmentNode varAssignDNode = cast(compiler.typecheck.dependency.variables.VariableAssignmentNode)dnode; @@ -620,6 +621,9 @@ public final class TypeChecker variableName = resolver.generateName(modulle, assignTo); gprintln("VariableAssignmentNode: "~to!(string)(variableName)); + /* Get the Context of the Variable Assigmnent */ + Context variableAssignmentContext = (cast(VariableAssignment)varAssignDNode.getEntity()).context; + /** * FIXME: Now with ClassStaticAllocate we will have wrong instructoins for us @@ -633,11 +637,14 @@ public final class TypeChecker * 1. Get the variable's name * 2. Pop Value-instruction * 3. Generate VarAssignInstruction with Value-instruction + * 4. Set the VarAssignInstr's Context to that of the Variable assigning to */ Instruction valueInstr = popInstr(); gprintln("VaribleAssignmentNode(): Just popped off valInstr?: "~to!(string)(valueInstr), DebugType.WARNING); gprintln(valueInstr is null);/*TODO: FUnc calls not implemented? Then is null for simple_1.t */ VariableAssignmentInstr varAssInstr = new VariableAssignmentInstr(variableName, valueInstr); + varAssInstr.context = variableAssignmentContext; + addInstrB(varAssInstr); } /* TODO: Add support */ diff --git a/source/tlang/compiler/typecheck/dependency/core.d b/source/tlang/compiler/typecheck/dependency/core.d index a90256a8..60355f87 100644 --- a/source/tlang/compiler/typecheck/dependency/core.d +++ b/source/tlang/compiler/typecheck/dependency/core.d @@ -1186,7 +1186,7 @@ public class DNodeGenerator assert(variableType); /* TODO: Handle invalid variable type */ DNode variableDNode = poolT!(StaticVariableDeclaration, Variable)(variable); writeln("Hello"); - writeln("VarTyope: "~to!(string)(variableType)); + writeln("VarType: "~to!(string)(variableType)); /* Basic type */ if(cast(Primitive)variableType) @@ -1239,8 +1239,13 @@ public class DNodeGenerator /* If there is an assignment attached to this */ if(variable.getAssignment()) { - /* Extract the assignment and pool it to get a DNode */ + /* Extract the assignment */ VariableAssignment varAssign = variable.getAssignment(); + + /* Set the Context of the assignment to the current context */ + varAssign.setContext(context); + + /* Pool the assignment to get a DNode */ DNode expressionNode = expressionPass(varAssign.getExpression(), context); /* This assignment depends on an expression being evaluated */