From 49b53c265e743d257fb2a5e33a75a07c4d7ef7bc Mon Sep 17 00:00:00 2001 From: Terence Parr Date: Mon, 13 Apr 2015 16:13:38 -0700 Subject: [PATCH 1/2] update readme --- README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 01bfc80..7fd16b3 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,12 @@ simple-virtual-machine ====================== -A simple VM for a talk on building VMs. +A simple VM for a talk on building VMs in Java. See [video](https://www.youtube.com/watch?v=OjaAToVkoTw) and [slides](http://www.slideshare.net/parrt/how-to-build-a-virtual-machine). -[A C implementation](https://github.com/codyebberson/vm) +There are two branches: + +* [master](https://github.com/parrt/simple-virtual-machine). Basic instructions only (no function calls). +* [add-functions](https://github.com/parrt/simple-virtual-machine/tree/add-functions). Includes CALL/RET instructions, runs factorial test function. +* [split-stack](https://github.com/parrt/simple-virtual-machine/tree/split-stack). Split into operand stack and function call stack. -This branch supports function call/return. +[A C implementation](https://github.com/codyebberson/vm) From 8a8b169e67bcca7addc56291926f9303bd148d73 Mon Sep 17 00:00:00 2001 From: Terence Parr Date: Tue, 14 Apr 2015 16:47:32 -0700 Subject: [PATCH 2/2] reorder bytecodes --- src/vm/Bytecode.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/vm/Bytecode.java b/src/vm/Bytecode.java index e3acfbc..facbd0c 100644 --- a/src/vm/Bytecode.java +++ b/src/vm/Bytecode.java @@ -27,9 +27,11 @@ public Instruction(String name, int nargs) { 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 final short CALL = 16; + public static final short RET = 17; // return with/without value + + + public static final short HALT = 19; public static Instruction[] instructions = new Instruction[] { null, // @@ -48,8 +50,8 @@ public Instruction(String name, int nargs) { new Instruction("gstore", 1), new Instruction("print"), new Instruction("pop"), - new Instruction("halt"), new Instruction("call", 2), // call addr, nargs - new Instruction("ret") + new Instruction("ret"), + new Instruction("halt") }; }