diff --git a/simple-virtual-machine.ipr b/simple-virtual-machine.ipr index 837e224..393f27d 100644 --- a/simple-virtual-machine.ipr +++ b/simple-virtual-machine.ipr @@ -1,8 +1,6 @@ - - - - + + + + + + + @@ -154,7 +154,7 @@ - + diff --git a/src/vm/Test.java b/src/vm/Test.java index 89c176b..644292a 100644 --- a/src/vm/Test.java +++ b/src/vm/Test.java @@ -120,7 +120,7 @@ public class Test { public static void main(String[] args) { VM vm = new VM(factorial, 0, factorial_metadata); - vm.trace = false; + vm.trace = true; vm.exec(factorial_metadata[0].address); vm = new VM(f, 2, f_metadata); diff --git a/src/vm/VM.java b/src/vm/VM.java index 6c3e063..87df7c9 100644 --- a/src/vm/VM.java +++ b/src/vm/VM.java @@ -111,8 +111,9 @@ protected void cpu() { case ICONST: stack[++sp] = code[ip++]; // push operand break; - case LOAD : // load local or arg; 1st local is fp+1, args are fp-3, fp-4, fp-5, ... - load(); + case LOAD : // load local or arg + regnum = code[ip++]; + stack[++sp] = ctx.locals[regnum]; break; case GLOAD :// load from global memory addr = code[ip++]; @@ -159,12 +160,6 @@ protected void cpu() { if ( trace ) dumpDataMemory(); } - private void load() { - int regnum; - regnum = code[ip++]; - stack[++sp] = ctx.locals[regnum]; - } - protected String stackString() { StringBuilder buf = new StringBuilder(); buf.append("stack=["); @@ -195,7 +190,10 @@ protected String disInstr() { StringBuilder buf = new StringBuilder(); buf.append(String.format("%04d:\t%-11s", ip, opName)); int nargs = Bytecode.instructions[opcode].n; - if ( nargs>0 ) { + if ( opcode==CALL ) { + buf.append(metadata[code[ip+1]].name); + } + else if ( nargs>0 ) { List operands = new ArrayList(); for (int i=ip+1; i<=ip+nargs; i++) { operands.add(String.valueOf(code[i]));