mirror of
https://github.com/FranzHaidnor/haidnorJVM.git
synced 2026-03-14 06:03:50 +08:00
update README.md
This commit is contained in:
@@ -6,9 +6,7 @@ import haidnor.jvm.runtime.StackValue;
|
||||
import haidnor.jvm.util.CodeStream;
|
||||
|
||||
public class IFEQ extends Instruction {
|
||||
/**
|
||||
* 下次再执行的偏移量
|
||||
*/
|
||||
|
||||
private final int offSet;
|
||||
|
||||
public IFEQ(CodeStream codeStream) {
|
||||
|
||||
@@ -19,11 +19,20 @@ public class IFNE extends Instruction {
|
||||
@Override
|
||||
public void execute(Frame frame) {
|
||||
StackValue v1 = frame.pop();
|
||||
if ((int) v1.getValue() != 0) {
|
||||
super.setOffSet(offSet);
|
||||
if (v1.getValue() instanceof Boolean) {
|
||||
if (((boolean) v1.getValue())) {
|
||||
super.setOffSet(offSet);
|
||||
} else {
|
||||
super.setOffSet(3);
|
||||
}
|
||||
} else {
|
||||
super.setOffSet(3);
|
||||
if ((int) v1.getValue() != 0) {
|
||||
super.setOffSet(offSet);
|
||||
} else {
|
||||
super.setOffSet(3);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -30,7 +30,6 @@ public class TestJVM {
|
||||
Klass mainMeteKlass = bootClassLoader.loadClass(mainClass.getName().replace('.', '/'));
|
||||
KlassMethod mainKlassMethod = JavaClassUtil.getMainMethod(mainMeteKlass);
|
||||
Metaspace.registerJavaClass(mainMeteKlass);
|
||||
|
||||
JavaExecutionEngine.callMainMethod(mainKlassMethod);
|
||||
}
|
||||
|
||||
@@ -148,6 +147,10 @@ public class TestJVM {
|
||||
runMainClass(demo_finally_3.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void demo_enum_1() throws Exception {
|
||||
runMainClass(demo_enum_1.class); // TODO support enum
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_NEW() throws Exception {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package haidnor.jvm.test.clazz;
|
||||
|
||||
public class Human implements Organism {
|
||||
public abstract class Human implements Organism {
|
||||
|
||||
public static final String HUMAN_NAME = "123";
|
||||
|
||||
|
||||
23
src/test/java/haidnor/jvm/test/clazz/StudentEnum.java
Normal file
23
src/test/java/haidnor/jvm/test/clazz/StudentEnum.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package haidnor.jvm.test.clazz;
|
||||
|
||||
public enum StudentEnum {
|
||||
|
||||
ZHANG_SAN(1,"张三");
|
||||
|
||||
private int age;
|
||||
private String name;
|
||||
|
||||
StudentEnum(int age, String name) {
|
||||
this.age = age;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import haidnor.jvm.test.clazz.Student;
|
||||
public class Demo8 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Human organism1 = new Human();
|
||||
Human organism1 = new Student();
|
||||
Organism0 organism = new Student();
|
||||
organism.die();
|
||||
}
|
||||
|
||||
11
src/test/java/haidnor/jvm/test/demo/demo_enum_1.java
Normal file
11
src/test/java/haidnor/jvm/test/demo/demo_enum_1.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package haidnor.jvm.test.demo;
|
||||
|
||||
import haidnor.jvm.test.clazz.StudentEnum;
|
||||
|
||||
public class demo_enum_1 {
|
||||
public static void main(String[] args) {
|
||||
StudentEnum studentEnum = StudentEnum.ZHANG_SAN;
|
||||
System.out.println(studentEnum.getAge());
|
||||
System.out.println(studentEnum.getName());
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package haidnor.jvm.test.demo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 需要添加启动参数
|
||||
@@ -9,9 +10,13 @@ import java.util.ArrayList;
|
||||
public class demo_foreach_2 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
ArrayList<Integer> list = new ArrayList<>();
|
||||
List<Integer> list = new ArrayList<>();
|
||||
list.add(1);
|
||||
list.add(2);
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
list.add(i);
|
||||
}
|
||||
|
||||
for (Integer integer : list) {
|
||||
System.out.println(integer);
|
||||
}
|
||||
|
||||
@@ -10,9 +10,11 @@ public class demo_foreach_3 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
List<Integer> list = List.of(1, 2, 3, 4, 5);
|
||||
for (Integer integer : list) {
|
||||
System.out.println(integer);
|
||||
}
|
||||
list.add(6);
|
||||
|
||||
// for (Integer integer : list) {
|
||||
// System.out.println(integer);
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user