mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
C: less code for virtual calls
This commit is contained in:
parent
8b3df6f730
commit
063a9f049e
|
@ -352,14 +352,18 @@ public class CodeGenerationVisitor implements ExprVisitor, StatementVisitor {
|
|||
@Override
|
||||
public void visit(VariableExpr expr) {
|
||||
pushLocation(expr.getLocation());
|
||||
if (expr.getIndex() == 0) {
|
||||
writer.print("teavm_this_");
|
||||
} else {
|
||||
writer.print("teavm_local_" + expr.getIndex());
|
||||
}
|
||||
writer.print(getVariableName(expr.getIndex()));
|
||||
popLocation(expr.getLocation());
|
||||
}
|
||||
|
||||
private String getVariableName(int index) {
|
||||
if (index == 0) {
|
||||
return "teavm_this_";
|
||||
} else {
|
||||
return "teavm_local_" + index;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(SubscriptExpr expr) {
|
||||
pushLocation(expr.getLocation());
|
||||
|
@ -504,12 +508,21 @@ public class CodeGenerationVisitor implements ExprVisitor, StatementVisitor {
|
|||
return;
|
||||
}
|
||||
|
||||
String receiver = allocTemporaryVariable(CVariableType.PTR);
|
||||
Expr receiverArg = arguments.get(0);
|
||||
boolean closingParenthesis = false;
|
||||
String receiver;
|
||||
if (receiverArg instanceof VariableExpr) {
|
||||
receiver = getVariableName(((VariableExpr) receiverArg).getIndex());
|
||||
} else {
|
||||
receiver = allocTemporaryVariable(CVariableType.PTR);
|
||||
writer.print("((").print(receiver).print(" = ");
|
||||
arguments.get(0).acceptVisitor(this);
|
||||
writer.print("), ");
|
||||
closingParenthesis = true;
|
||||
}
|
||||
|
||||
includes.includeClass(vtableClass);
|
||||
writer.print("), TEAVM_METHOD(")
|
||||
writer.print("TEAVM_METHOD(")
|
||||
.print(receiver).print(", ")
|
||||
.print(names.forClassClass(vtableClass)).print(", ")
|
||||
.print(names.forVirtualMethod(reference.getDescriptor()))
|
||||
|
@ -518,10 +531,12 @@ public class CodeGenerationVisitor implements ExprVisitor, StatementVisitor {
|
|||
writer.print(", ");
|
||||
arguments.get(i).acceptVisitor(this);
|
||||
}
|
||||
writer.print("))");
|
||||
|
||||
writer.print(")");
|
||||
if (closingParenthesis) {
|
||||
writer.print(")");
|
||||
freeTemporaryVariable(CVariableType.PTR);
|
||||
}
|
||||
}
|
||||
|
||||
private void generateNoMethodCall(MethodReference reference, List<? extends Expr> arguments) {
|
||||
writer.print("(");
|
||||
|
|
Loading…
Reference in New Issue
Block a user