update IFEQ

This commit is contained in:
wangxiang
2023-07-27 11:17:06 +08:00
parent ecbcda6e51
commit 8bee052a78
3 changed files with 37 additions and 4 deletions

View File

@@ -19,16 +19,24 @@ public class IFEQ extends Instruction {
@Override @Override
public void execute(Frame frame) { public void execute(Frame frame) {
StackValue v1 = frame.pop(); StackValue v1 = frame.pop();
if ((int) v1.getValue() == 0) { if (v1.getValue() instanceof Boolean) {
super.setOffSet(offSet); if (!((boolean) v1.getValue())) {
super.setOffSet(offSet);
} else {
super.setOffSet(3);
}
} else { } else {
super.setOffSet(3); if ((int) v1.getValue() == 0) {
super.setOffSet(offSet);
} else {
super.setOffSet(3);
}
} }
} }
@Override @Override
public String toString() { public String toString() {
return super.index() + " " + this.getClass().getSimpleName() + " " + offSet; return super.index() + " " + this.getClass().getSimpleName() + " " + offSet;
} }
} }

View File

@@ -92,6 +92,11 @@ public class TestJVM {
runMainClass(demo_foreach.class); runMainClass(demo_foreach.class);
} }
@Test
public void demo_foreach_2() throws Exception {
runMainClass(demo_foreach_2.class);
}
@Test @Test
public void test_8() throws Exception { public void test_8() throws Exception {
runMainClass(Demo8.class); runMainClass(Demo8.class);

View File

@@ -0,0 +1,20 @@
package haidnor.jvm.test.demo;
import java.util.ArrayList;
/**
* 需要添加启动参数
* --add-opens java.base/java.util=ALL-UNNAMED
*/
public class demo_foreach_2 {
public static void main(String[] args) {
ArrayList<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
for (Integer integer : list) {
System.out.println(integer);
}
}
}