Skip to content

Commit

Permalink
race information to standard output; change simple example.
Browse files Browse the repository at this point in the history
  • Loading branch information
parrt committed May 13, 2014
1 parent 8999e1f commit 4eea301
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
1 change: 0 additions & 1 deletion src/vm/Bytecode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
5 changes: 4 additions & 1 deletion src/vm/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

public class Test {
static int[] hello = {
ICONST, 1234,
ICONST, 1,
ICONST, 2,
IADD,
PRINT,
HALT
};
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions src/vm/VM.java
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}
}

0 comments on commit 4eea301

Please sign in to comment.