@ -120,23 +120,33 @@ public final class DCodeEmitter : CodeEmitter
gprintln ( "Wazza contect: " ~ to ! ( string ) ( context . container ) ) ;
auto typedEntityVariable = context . tc . getResolver ( ) . resolveBest ( context . getContainer ( ) , varAs . varName ) ; //TODO: Remove `auto`
string renamedSymbol = SymbolMapper . symbolLookup ( typedEntityVariable ) ;
// If we are needed as part of a VariabvleDeclaration-with-assignment
if ( varDecWantsConsumeVarAss )
/* If it is not external */
if ( ! typedEntityVariable . isExternal ( ) )
{
// Generate the code to emit (only the RHS of the = sign)
string emitCode = transform ( varAs . data ) ;
string renamedSymbol = SymbolMapper . 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 ;
// Reset flag
varDecWantsConsumeVarAss = false ;
return emitCode ;
}
return emitCode ;
}
return renamedSymbol ~ " = " ~ transform ( varAs . data ) ~ ";" ;
return renamedSymbol ~ " = " ~ transform ( varAs . data ) ~ ";" ;
}
/* If it is external */
else
{
return typedEntityVariable . getName ( ) ~ " = " ~ transform ( varAs . data ) ~ ";" ;
}
}
/* VariableDeclaration */
else if ( cast ( VariableDeclaration ) instruction )
@ -148,36 +158,44 @@ public final class DCodeEmitter : CodeEmitter
Variable typedEntityVariable = cast ( Variable ) context . tc . getResolver ( ) . resolveBest ( context . getContainer ( ) , varDecInstr . varName ) ; //TODO: Remove `auto`
//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)
//
//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 = SymbolMapper . symbolLookup ( typedEntityVariable ) ;
// Check to see if this declaration has an assignment attached
if ( typedEntityVariable . getAssignment ( ) )
/* If the variable is not external */
if ( ! typedEntityVariable . isExternal ( ) )
{
// 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 ( ) ;
//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)
//
//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 = SymbolMapper . symbolLookup ( typedEntityVariable ) ;
// Generate the code to emit
return typeTransform ( cast ( Type ) varDecInstr . varType ) ~ " " ~ renamedSymbol ~ " = " ~ transform ( varAssInstr ) ~ ";" ;
}
// 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 ( ) ;
// Generate the code to emit
return typeTransform ( cast ( Type ) varDecInstr . varType ) ~ " " ~ renamedSymbol ~ " = " ~ transform ( varAssInstr ) ~ ";" ;
}
return typeTransform ( cast ( Type ) varDecInstr . varType ) ~ " " ~ renamedSymbol ~ ";" ;
}
/* If the variable is external */
else
{
return "extern " ~ typeTransform ( cast ( Type ) varDecInstr . varType ) ~ " " ~ typedEntityVariable . getName ( ) ~ ";" ;
}
return typeTransform ( cast ( Type ) varDecInstr . varType ) ~ " " ~ renamedSymbol ~ ";" ;
}
/* LiteralValue */
else if ( cast ( LiteralValue ) instruction )
@ -198,12 +216,21 @@ public final class DCodeEmitter : CodeEmitter
Variable typedEntityVariable = cast ( Variable ) context . tc . getResolver ( ) . resolveBest ( context . getContainer ( ) , fetchValueVarInstr . varName ) ; //TODO: Remove `auto`
//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)
/* If it is not external */
if ( ! typedEntityVariable . isExternal ( ) )
{
//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 ) ;
string renamedSymbol = SymbolMapper . symbolLookup ( typedEntityVariable ) ;
return renamedSymbol ;
return renamedSymbol ;
}
/* If it is external */
else
{
return typedEntityVariable . getName ( ) ;
}
}
/* BinOpInstr */
else if ( cast ( BinOpInstr ) instruction )