feature/add-enum-support #1

Merged
nitrix merged 16 commits from feature/add-enum-support into master 2023-03-20 21:19:54 +01:00
Showing only changes of commit e835bd0f06 - Show all commits

View File

@@ -567,6 +567,13 @@ public class GenASM implements Visitor<Void> {
@Override @Override
public Void visit(FunctionDefinition e) { public Void visit(FunctionDefinition e) {
// If the user chooses "main" as one of his function names then
// rename it and hope that they didn't use the renamed function name
// as well :D
if (e.name.equals("main")) {
e.name = "main_by_user";
}
int lblStart = ++lCount; int lblStart = ++lCount;
this.currentFunctionStartLabel = lblStart; this.currentFunctionStartLabel = lblStart;
this.currentFunctionParams = e.parameters; this.currentFunctionParams = e.parameters;
@@ -744,7 +751,8 @@ public class GenASM implements Visitor<Void> {
asm.add("q", stackStartOffset, "%rsp"); asm.add("q", stackStartOffset, "%rsp");
} }
asm.call(e.name); // We rename a function name if it is "main"
asm.call(e.name.equals("main") ? "main_by_user": e.name);
return null; return null;
} }
@@ -769,7 +777,7 @@ public class GenASM implements Visitor<Void> {
@Override @Override
public Void visit(Parameter e) { public Void visit(Parameter e) {
// The work for a paremeter node is implement // The work for a parameter node is implement
// in the function definition visitor // in the function definition visitor
return null; return null;
} }
@@ -824,6 +832,9 @@ public class GenASM implements Visitor<Void> {
@Override @Override
public Void visit(EnumAccessExpression e) { public Void visit(EnumAccessExpression e) {
// Since the access to an enum simply results in an integer (i.e. the index
// of the enum value), we can just let IntegerExpression handle the expected behaviour.
new IntegerExpression(e.enumValue.index).welcome(this);
return null; return null;
} }