diff --git a/src/vm/Bytecode.java b/src/vm/Bytecode.java index f9f760d..c5d5c12 100644 --- a/src/vm/Bytecode.java +++ b/src/vm/Bytecode.java @@ -36,7 +36,6 @@ public Instruction(String name, int nargs) { new Instruction("imul"), new Instruction("ilt"), new Instruction("ieq"), - new Instruction("ret"), new Instruction("br", 1), new Instruction("brt", 1), new Instruction("brf", 1), diff --git a/src/vm/Test.java b/src/vm/Test.java index 6549430..fdfb4db 100644 --- a/src/vm/Test.java +++ b/src/vm/Test.java @@ -12,7 +12,9 @@ public class Test { static int[] hello = { - ICONST, 1234, + ICONST, 1, + ICONST, 2, + IADD, PRINT, HALT }; @@ -44,6 +46,7 @@ public class Test { public static void main(String[] args) { VM vm = new VM(hello, 0, 0); + vm.trace = true; vm.exec(); vm = new VM(loop, 0, 2); diff --git a/src/vm/VM.java b/src/vm/VM.java index bf75f1b..4330603 100644 --- a/src/vm/VM.java +++ b/src/vm/VM.java @@ -57,7 +57,7 @@ protected void cpu() { int opcode = code[ip]; int a,b,addr,offset; while (opcode!= HALT && ip < code.length) { - if ( trace ) System.out.printf("%-35s", disInstr()); + if ( trace ) System.err.printf("%-35s", disInstr()); ip++; //jump to next instruction or to operand switch (opcode) { case IADD: @@ -124,11 +124,11 @@ protected void cpu() { default : throw new Error("invalid opcode: "+opcode+" at ip="+(ip-1)); } - if ( trace ) System.out.println(stackString()); + if ( trace ) System.err.println(stackString()); opcode = code[ip]; } - if ( trace ) System.out.printf("%-35s", disInstr()); - if ( trace ) System.out.println(stackString()); + if ( trace ) System.err.printf("%-35s", disInstr()); + if ( trace ) System.err.println(stackString()); if ( trace ) dumpDataMemory(); } @@ -165,12 +165,12 @@ protected String disInstr() { } protected void dumpDataMemory() { - System.out.println("Data memory:"); + System.err.println("Data memory:"); int addr = 0; for (int o : globals) { - System.out.printf("%04d: %s\n", addr, o); + System.err.printf("%04d: %s\n", addr, o); addr++; } - System.out.println(); + System.err.println(); } }