DGen works, D code can be generated

This commit is contained in:
Tristan B. Kildaire 2021-06-01 15:24:13 +02:00
parent d8f82e17de
commit 4b13c88c51
4 changed files with 29 additions and 3 deletions

View File

@ -17,6 +17,11 @@ public class CodeGenerator
{
this.modulle = modulle;
}
public string build()
{
return "";
}
}
public import compiler.codegen.dgen;

View File

@ -15,7 +15,7 @@ public class DCodeGenerator : CodeGenerator
super(modulle);
}
public void build()
public override string build()
{
Statement[] statements = modulle.getStatements();
@ -31,5 +31,7 @@ public class DCodeGenerator : CodeGenerator
}
}
return "";
}
}

View File

@ -64,7 +64,8 @@ void beginCompilation(string[] sourceFiles)
}
import compiler.codegen.core;
CodeGenerator codegen = new CodeGenerator(modulle);
CodeGenerator codegen = new DCodeGenerator(modulle);
codegen.build();
// typeChecker.check();
}

View File

@ -228,7 +228,9 @@ public class Function : TypedEntity
}
}
public class Variable : TypedEntity
import compiler.codegen.core;
public class Variable : TypedEntity, Emittable
{
/* TODO: Just make this an Expression */
private VariableAssignment assignment;
@ -254,6 +256,22 @@ public class Variable : TypedEntity
}
/* Code gen */
public string emit()
{
string emittedCode;
/* TODO: So far only emitting for non assignment */
if(!assignment)
{
/* TODO: Let's hope only primitive types */
emittedCode = type;
emittedCode ~= " ";
emittedCode ~= getName();
emittedCode ~= ";";
}
return emittedCode;
}
}