DGen
- Removed the `varDecWantsConsumeVarAss` as it is not used anymore - The transformation of the `VariableAssignmentInstr` instruction (which is generated by a corresponding `VariableStdAloneAss` parser node) does not check for `varDecWantsConsumeVarAss` anymore and will directly `transform(varAss.data)` (the embedded `Value` instruction in the `VariableAssignmentInstr` - If a `VariableDeclaration` instruction has an assignment then we extract the `Value` instruction from it and perform a `transform(Value)` - no longer do we have an intermediary `VariableAssignmentInstr` Instruction - `VariableDeclaration` now uses a `Value`-based instruction rather than a `VariableAssignmentInstr` as the embedded `varAssInstr` Dependency - The creation of a `StaticVariableDeclaration` DNode for `Variable`-declarations that happen to have assignments will now process such assignments by pooling the expression being assigned (via `expressionPass()` and then make the `VarDecNode` depend on it, therefore removing the intermediary `VariableAssignmentNode` dependency-node Typechecker/Codegen - When processing a variable declaration (a `StaticVariableDeclaration` dependency-node) we now pop an instruction which would be directly the `Value`-based instruction that we `need()`'d in the dependency generation (this links up with the changes made to the dependency generation for variable declarations)
This commit is contained in:
parent
4ed6b2a18b
commit
e919dcc8e4
|
@ -21,13 +21,7 @@ import compiler.symbols.typing.core : Type, Primitive, Integer, Void, Pointer;
|
|||
import compiler.configuration : CompilerConfiguration;
|
||||
|
||||
public final class DCodeEmitter : CodeEmitter
|
||||
{
|
||||
// Set to true when processing a variable declaration
|
||||
// which expects an assignment. Set to false when
|
||||
// said variable assignment has been processed
|
||||
private bool varDecWantsConsumeVarAss = false;
|
||||
|
||||
|
||||
{
|
||||
// NOTE: In future store the mapper in the config please
|
||||
this(TypeChecker typeChecker, File file, CompilerConfiguration config, SymbolMapper mapper)
|
||||
{
|
||||
|
@ -141,20 +135,6 @@ public final class DCodeEmitter : CodeEmitter
|
|||
{
|
||||
string renamedSymbol = mapper.symbolLookup(typedEntityVariable);
|
||||
|
||||
|
||||
// If we are needed as part of a VariabvleDeclaration-with-assignment
|
||||
if(varDecWantsConsumeVarAss)
|
||||
{
|
||||
// Generate the code to emit (only the RHS of the = sign)
|
||||
string emitCode = transform(varAs.data);
|
||||
|
||||
// Reset flag
|
||||
varDecWantsConsumeVarAss = false;
|
||||
|
||||
return emitCode;
|
||||
}
|
||||
|
||||
|
||||
return renamedSymbol~" = "~transform(varAs.data)~";";
|
||||
}
|
||||
/* If it is external */
|
||||
|
@ -189,15 +169,7 @@ public final class DCodeEmitter : CodeEmitter
|
|||
// Check to see if this declaration has an assignment attached
|
||||
if(typedEntityVariable.getAssignment())
|
||||
{
|
||||
// Set flag to expect different transform generation for VariableAssignment
|
||||
varDecWantsConsumeVarAss = true;
|
||||
|
||||
// Fetch the variable assignment instruction
|
||||
// gprintln("Before crash: "~to!(string)(getCurrentInstruction()));
|
||||
// nextInstruction();
|
||||
// Instruction varAssInstr = getCurrentInstruction();
|
||||
|
||||
VariableAssignmentInstr varAssInstr = varDecInstr.getAssignmentInstr();
|
||||
Value varAssInstr = varDecInstr.getAssignmentInstr();
|
||||
|
||||
// Generate the code to emit
|
||||
return typeTransform(cast(Type)varDecInstr.varType)~" "~renamedSymbol~" = "~transform(varAssInstr)~";";
|
||||
|
|
|
@ -97,11 +97,11 @@ public final class VariableDeclaration : StorageDeclaration
|
|||
/* Type of the variable being declared */
|
||||
public const Type varType;
|
||||
|
||||
/* VariableAssignmentInstr-instruction to be assigned */
|
||||
private VariableAssignmentInstr varAssInstr;
|
||||
/* Value-instruction to be assigned */
|
||||
private Value varAssInstr;
|
||||
|
||||
//TODO: This must take in type information
|
||||
this(string varName, byte len, Type varType, VariableAssignmentInstr varAssInstr)
|
||||
this(string varName, byte len, Type varType, Value varAssInstr)
|
||||
{
|
||||
this.varName = varName;
|
||||
this.length = len;
|
||||
|
@ -112,7 +112,7 @@ public final class VariableDeclaration : StorageDeclaration
|
|||
addInfo = "varName: "~varName;
|
||||
}
|
||||
|
||||
public VariableAssignmentInstr getAssignmentInstr()
|
||||
public Value getAssignmentInstr()
|
||||
{
|
||||
return varAssInstr;
|
||||
}
|
||||
|
|
|
@ -824,20 +824,18 @@ public final class TypeChecker
|
|||
Type variableDeclarationType = getType(variablePNode.context.container, variablePNode.getType());
|
||||
|
||||
|
||||
// CHeck if this variable declaration has an assignment attached
|
||||
VariableAssignmentInstr assignmentInstr;
|
||||
// Check if this variable declaration has an assignment attached
|
||||
Value assignmentInstr;
|
||||
if(variablePNode.getAssignment())
|
||||
{
|
||||
Instruction poppedInstr = popInstr();
|
||||
assert(poppedInstr);
|
||||
assignmentInstr = cast(VariableAssignmentInstr)poppedInstr;
|
||||
assert(assignmentInstr);
|
||||
|
||||
// Obtain the embedded instruction of the variable assignment instruction
|
||||
// ... along with said embedded instruction's type
|
||||
assert(assignmentInstr.data);
|
||||
Value embeddedInstruction = cast(Value)assignmentInstr.data;
|
||||
Type assignmentType = embeddedInstruction.getInstrType();
|
||||
// Obtain the value instruction of the variable assignment
|
||||
// ... along with the assignment's type
|
||||
assignmentInstr = cast(Value)poppedInstr;
|
||||
assert(assignmentInstr);
|
||||
Type assignmentType = assignmentInstr.getInstrType();
|
||||
|
||||
|
||||
// TODO: We should add a typecheck here where we update the type of the valInstr if it is of
|
||||
|
@ -852,7 +850,7 @@ public final class TypeChecker
|
|||
else
|
||||
{
|
||||
// If it is a LiteralValue (integer literal) (support for issue #94)
|
||||
if(cast(LiteralValue)embeddedInstruction)
|
||||
if(cast(LiteralValue)assignmentInstr)
|
||||
{
|
||||
// TODO: Add a check for if these types are both atleast integral (as in the Variable's type)
|
||||
// ... THEN (TODO): Check if range makes sense
|
||||
|
@ -867,7 +865,7 @@ public final class TypeChecker
|
|||
// TODO: Coerce here by changing the embedded instruction's type (I think this makes sense)
|
||||
// ... as during code emit that is what will be hoisted out and checked regarding its type
|
||||
// NOTE: Referrring to same type should not be a problem (see #96 Question 1)
|
||||
embeddedInstruction.setInstrType(variableDeclarationType);
|
||||
assignmentInstr.setInstrType(variableDeclarationType);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -883,7 +881,7 @@ public final class TypeChecker
|
|||
|
||||
}
|
||||
// If it is a LiteralFloatingValue (support for issue #94)
|
||||
else if(cast(LiteralValue)embeddedInstruction)
|
||||
else if(cast(LiteralValue)assignmentInstr)
|
||||
{
|
||||
gprintln("Coercion not yet supported for floating point literals", DebugType.ERROR);
|
||||
assert(false);
|
||||
|
|
|
@ -1290,12 +1290,8 @@ public class DNodeGenerator
|
|||
/* Pool the assignment to get a DNode */
|
||||
DNode expressionNode = expressionPass(varAssign.getExpression(), context);
|
||||
|
||||
/* This assignment depends on an expression being evaluated */
|
||||
VariableAssignmentNode varAssignNode = new VariableAssignmentNode(this, varAssign);
|
||||
varAssignNode.needs(expressionNode);
|
||||
|
||||
/* The variable declaration is dependant on the assignment */
|
||||
variableDNode.needs(varAssignNode);
|
||||
/* The variable declaration is dependant on the assigne expression */
|
||||
variableDNode.needs(expressionNode);
|
||||
}
|
||||
|
||||
/* The current container is dependent on this variable declaration */
|
||||
|
@ -1331,10 +1327,8 @@ public class DNodeGenerator
|
|||
{
|
||||
/* Pool varass stdalone */
|
||||
DNode vStdAlDNode = pool(vAsStdAl);
|
||||
// node.needs(vStdAlDNode);
|
||||
|
||||
// FIXME: Convert to using a VariableAssignmentNode (for the sake of uniformity)
|
||||
|
||||
/* Pool the expression and make the vAStdAlDNode depend on it */
|
||||
DNode expression = expressionPass(vAsStdAl.getExpression(), context);
|
||||
vStdAlDNode.needs(expression);
|
||||
|
||||
|
|
Loading…
Reference in New Issue