code-generator #13
@ -23,9 +23,4 @@ public class AssignableNode implements IStatementExpressionNode {
|
||||
return visitor.analyze(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(MethodVisitor methodVisitor) {
|
||||
methodVisitor.visit(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -72,7 +72,6 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
|
||||
statementNode.accept(this);
|
||||
}
|
||||
|
||||
methodVisitor.visitInsn(RETURN);
|
||||
methodVisitor.visitMaxs(0, 0);
|
||||
methodVisitor.visitEnd();
|
||||
}
|
||||
@ -386,17 +385,61 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
|
||||
|
||||
@Override
|
||||
public void visit(WhileNode whileNode) {
|
||||
Label loopLabel = new Label();
|
||||
Label endOfLoopLabel = new Label();
|
||||
|
||||
methodVisitor.visitLabel(loopLabel);
|
||||
// while loop
|
||||
whileNode.expression.accept(this);
|
||||
methodVisitor.visitJumpInsn(IFEQ, endOfLoopLabel); // if condition is false, jump out of loop
|
||||
|
||||
whileNode.block.accept(this);
|
||||
methodVisitor.visitJumpInsn(GOTO, loopLabel);
|
||||
|
||||
methodVisitor.visitLabel(endOfLoopLabel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(DecrementNode decrementNode) {
|
||||
switch (decrementNode.crementType) {
|
||||
case PREFIX: // --i
|
||||
if(decrementNode.assignableExpression.memberAccess == null) { // local Var
|
||||
methodVisitor.visitIincInsn(localVaribales.indexOf(decrementNode.assignableExpression.identifier), -1);
|
||||
} else { // Field or var from other object
|
||||
|
||||
}
|
||||
break;
|
||||
case SUFFIX: // i--
|
||||
if(decrementNode.assignableExpression.memberAccess == null) { // local Var
|
||||
methodVisitor.visitIincInsn(localVaribales.indexOf(decrementNode.assignableExpression.identifier), -1);
|
||||
} else { // Field or var from other object
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(IncrementNode incrementNode) {
|
||||
switch (incrementNode.crementType) {
|
||||
case PREFIX: // ++i
|
||||
if(incrementNode.assignableExpression.memberAccess == null) { // local Var
|
||||
methodVisitor.visitIincInsn(localVaribales.indexOf(incrementNode.assignableExpression.identifier), 1);
|
||||
methodVisitor.visitVarInsn(ISTORE, localVaribales.indexOf(incrementNode.assignableExpression.identifier));
|
||||
|
||||
} else { // Field or var from other object
|
||||
|
||||
}
|
||||
break;
|
||||
case SUFFIX: // i++
|
||||
if(incrementNode.assignableExpression.memberAccess == null) { // local Var
|
||||
methodVisitor.visitVarInsn(ISTORE, localVaribales.indexOf(incrementNode.assignableExpression.identifier));
|
||||
methodVisitor.visitIincInsn(localVaribales.indexOf(incrementNode.assignableExpression.identifier), 1);
|
||||
} else { // Field or var from other object
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -413,9 +456,4 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
|
||||
public void visit(TargetNode targetNode) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(AssignableNode assignableNode) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,6 @@ public interface MethodVisitor {
|
||||
void visit(MethodCallNode methodCallNode);
|
||||
void visit(TargetNode targetNode);
|
||||
|
||||
void visit(AssignableNode assignableNode);
|
||||
void visit(AssignNode assignNode);
|
||||
void visit(NewDeclarationNode newDeclarationNode);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user