Dependency
- VariableAssignment entity now has its Context object set to the current Context (of the Variable being declared) (so this is a declare assignment case only (so far)) (fixes #36) TypeChecker - Extract the Context object from the VariableAssignment entity and then set it as the Context for the VariableAssigmnetInstr instruction (fixes #36) VariableAssigmnentInstr - The `emit()` method will now emit the assignment code Check - Added `getCharacter(SymbolType)` which maps a SymbolType to a maths operator (WIP)
This commit is contained in:
parent
18dbe5508f
commit
50728d02d3
|
@ -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 "<TODO: VarAssAssignment ("~data.emit()~")";
|
||||
gprintln("Is ContextNull?: "~to!(string)(context is null));
|
||||
auto typedEntityVariable = context.tc.getResolver().resolveBest(context.getContainer(), varName); //TODO: Remove `auto`
|
||||
string typedEntityVariableName = context.tc.getResolver().generateName(context.getContainer(), typedEntityVariable);
|
||||
|
||||
|
||||
return typedEntityVariableName~" = "~data.emit()~";";
|
||||
// return "<TODO: VarAssAssignment ("~data.emit()~")";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -246,8 +254,7 @@ public class BinOpInstr : Value
|
|||
|
||||
public override string emit()
|
||||
{
|
||||
//TODO: Map SymbolType to maths operator (add support in the check.d module)
|
||||
return lhs.emit()~to!(string)(operator)~rhs.emit();
|
||||
return lhs.emit()~to!(string)(getCharacter(operator))~rhs.emit();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import compiler.lexer : Token;
|
|||
import std.conv : to;
|
||||
import std.string : isNumeric, cmp;
|
||||
import misc.utils;
|
||||
import gogga;
|
||||
|
||||
/**
|
||||
* All allowed symbols
|
||||
|
@ -453,7 +454,28 @@ public bool isBinaryOp(Token token)
|
|||
cmp(">=", tokenStr) == 0 || cmp("<=", tokenStr) == 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the corresponding character for a given SymbolType
|
||||
*
|
||||
* For example <code>SymbolType.ADD</code> 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
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in New Issue