modified: src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java

new file:   src/de/dhbwstuttgart/bytecode/IfStatement.java
Bytecode für If statement wir erzeugt aber noch nicht vollständig.
	modified:   test/bytecode/javFiles/Faculty.jav
Test angepasst.
This commit is contained in:
Fayez Abu Alia 2018-09-19 15:52:29 +02:00
parent aeb8bb92ed
commit 673c249b68
3 changed files with 64 additions and 13 deletions

View File

@ -223,7 +223,7 @@ public class BytecodeGenMethod implements StatementVisitor {
}
Label endLabel = new Label();
// this case for while loops
// this case for while loops and If statements
if (statement instanceof LoopStmt)
mv.visitLabel(endLabel);
@ -270,6 +270,8 @@ public class BytecodeGenMethod implements StatementVisitor {
case LESSEQUAL:
case BIGGERTHAN:
case BIGGEREQUAL:
case EQUAL:
case NOTEQUAL:
Label branchLabel = new Label();
doVisitRelOpInsn(op, largerType, branchLabel, endLabel);
break;
@ -644,7 +646,10 @@ public class BytecodeGenMethod implements StatementVisitor {
@Override
public void visit(IfStmt ifStmt) {
System.out.println("If");
statement = new IfStatement(ifStmt.expr, ifStmt.then_block, ifStmt.else_block);
isBinaryExp = statement.isExprBinary();
ifStmt.expr.accept(this);
statement = null;
}
@Override

View File

@ -0,0 +1,31 @@
package de.dhbwstuttgart.bytecode;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import de.dhbwstuttgart.syntaxtree.statement.Expression;
import de.dhbwstuttgart.syntaxtree.statement.Statement;
public class IfStatement extends AStatement{
private Statement then_block;
private Statement else_block;
public IfStatement(Expression expr, Statement then_block, Statement else_block) {
super(expr);
this.then_block = then_block;
this.else_block = else_block;
}
@Override
public void genBCForRelOp(MethodVisitor mv,Label branchLabel, Label endLabel, BytecodeGenMethod bytecodeGenMethod) {
bytecodeGenMethod.isBinary(false);
this.then_block.accept(bytecodeGenMethod);
mv.visitLabel(branchLabel);
this.else_block.accept(bytecodeGenMethod);
// mv.visitLabel(endLabel);
// mv.visitJumpInsn(Opcodes.GOTO, endLabel);
}
}

View File

@ -1,17 +1,32 @@
import java.lang.Integer;
class Faculty {
public class Faculty {
m () {
m (x) {
var fact = (x) -> {
if (x == 1) {
// var fact = (x) -> {
// if (x == 1) {
// return x;
// }
// else {
// return x * (fact.apply(x-1));
// }
// };
// return fact;
// var x = 13;
// if(x>22) {
// return 0;
// }else if(x <1){
// return x;
// }else {
// return 1;
// }
if (x < 2) {
return x;
}
else {
return x * (fact.apply(x-1));
return x * m(x-1);
}
};
return fact;
}
}