Skip to content

Commit

Permalink
reorg to be extension of non-function VM
Browse files Browse the repository at this point in the history
  • Loading branch information
parrt committed May 13, 2014
1 parent 47b9f0a commit e75f5a1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
32 changes: 16 additions & 16 deletions src/vm/Bytecode.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ public Instruction(String name, int nargs) {
public static final short IMUL = 3;
public static final short ILT = 4; // int less than
public static final short IEQ = 5; // int equal
public static final short CALL = 6;
public static final short RET = 7; // return with/without value
public static final short BR = 8; // branch
public static final short BRT = 9; // branch if true
public static final short BRF = 10; // branch if true
public static final short ICONST = 11; // push constant integer
public static final short LOAD = 12; // load from local context
public static final short GLOAD = 13; // load from global memory
public static final short STORE = 14; // store in local context
public static final short GSTORE = 15; // store in global memory
public static final short PRINT = 16; // print stack top
public static final short POP = 17; // throw away top of stack
public static final short HALT = 18;
public static final short BR = 6; // branch
public static final short BRT = 7; // branch if true
public static final short BRF = 8; // branch if true
public static final short ICONST = 9; // push constant integer
public static final short LOAD = 10; // load from local context
public static final short GLOAD = 11; // load from global memory
public static final short STORE = 12; // store in local context
public static final short GSTORE = 13; // store in global memory
public static final short PRINT = 14; // print stack top
public static final short POP = 15; // throw away top of stack
public static final short HALT = 16;
public static final short CALL = 17;
public static final short RET = 18; // return with/without value

public static Instruction[] instructions = new Instruction[] {
null, // <INVALID>
Expand All @@ -38,8 +38,6 @@ public Instruction(String name, int nargs) {
new Instruction("imul"),
new Instruction("ilt"),
new Instruction("ieq"),
new Instruction("call", 2), // call addr, nargs
new Instruction("ret"),
new Instruction("br", 1),
new Instruction("brt", 1),
new Instruction("brf", 1),
Expand All @@ -50,6 +48,8 @@ public Instruction(String name, int nargs) {
new Instruction("gstore", 1),
new Instruction("print"),
new Instruction("pop"),
new Instruction("halt")
new Instruction("halt"),
new Instruction("call", 2), // call addr, nargs
new Instruction("ret")
};
}
9 changes: 1 addition & 8 deletions src/vm/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,13 @@ public class Test {
RET, // 21
//.DEF MAIN: ARGS=0, LOCALS=0
// PRINT FACT(10)
ICONST, 5, // 22
ICONST, 5, // 22 <-- MAIN METHOD!
CALL, 0, 1, // 24
PRINT, // 27
HALT // 28
};

public static void main(String[] args) {
// VM vm = new VM(hello, 0, 0);
// vm.exec();
//
// vm = new VM(loop, 0, 2);
// vm.trace = true;
// vm.exec();

VM vm = new VM(factorial, 22, 0);
vm.trace = true;
vm.exec();
Expand Down

0 comments on commit e75f5a1

Please sign in to comment.