use of dyvilx.tools.compiler.ast.field.IVariable in project Dyvil by Dyvil.
the class ForStatement method writeStatement.
@Override
public void writeStatement(MethodWriter writer) throws BytecodeException {
dyvilx.tools.asm.Label startLabel = this.startLabel.getTarget();
dyvilx.tools.asm.Label updateLabel = this.updateLabel.getTarget();
dyvilx.tools.asm.Label endLabel = this.endLabel.getTarget();
IVariable var = this.variable;
int locals = writer.localCount();
// Variable
if (var != null) {
var.writeInit(writer);
}
writer.visitTargetLabel(startLabel);
// Condition
if (this.condition != null) {
this.condition.writeInvJump(writer, endLabel);
}
// Action
if (this.action != null) {
this.action.writeExpression(writer, Types.VOID);
}
// Update
writer.visitLabel(updateLabel);
if (this.update != null) {
this.update.writeExpression(writer, Types.VOID);
}
// Go back to Condition
writer.visitJumpInsn(Opcodes.GOTO, startLabel);
writer.resetLocals(locals);
writer.visitLabel(endLabel);
// Variable
if (var != null) {
var.writeLocal(writer, startLabel, endLabel);
}
}
use of dyvilx.tools.compiler.ast.field.IVariable in project Dyvil by Dyvil.
the class StatementList method writeExpression.
@Override
public void writeExpression(MethodWriter writer, IType type) throws BytecodeException {
int statementCount = this.valueCount - 1;
if (statementCount < 0) {
return;
}
dyvilx.tools.asm.Label start = new dyvilx.tools.asm.Label();
dyvilx.tools.asm.Label end = new dyvilx.tools.asm.Label();
writer.visitLabel(start);
int localCount = writer.localCount();
if (this.labels == null) {
// Write all statements except the last one
for (int i = 0; i < statementCount; i++) {
this.values[i].writeExpression(writer, Types.VOID);
}
// Write the last expression
this.values[statementCount].writeExpression(writer, type);
} else {
final int labelCount = this.labels.length;
Label label;
// Write all statements except the last one
for (int i = 0; i < statementCount; i++) {
if (i < labelCount && (label = this.labels[i]) != null) {
writer.visitLabel(label.getTarget());
}
this.values[i].writeExpression(writer, Types.VOID);
}
// Write last expression (and label)
if (statementCount < labelCount && (label = this.labels[statementCount]) != null) {
writer.visitLabel(label.getTarget());
}
this.values[statementCount].writeExpression(writer, type);
}
writer.resetLocals(localCount);
writer.visitLabel(end);
if (this.variables == null) {
return;
}
for (IVariable variable : this.variables) {
variable.writeLocal(writer, start, end);
}
}
Aggregations