Skip to content

Instantly share code, notes, and snippets.

@tkihira
Created May 24, 2012 07:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkihira/2779981 to your computer and use it in GitHub Desktop.
Save tkihira/2779981 to your computer and use it in GitHub Desktop.
VM sample
while(offset >= 0) {
switch(offset) {
case 0: // "PUSH 10"
stack.push(10);
case 2: // "PUSH 8"
stack.push(8);
case 4: // "LESS"
var a = stack.pop();
var b = stack.pop();
stack.push((a < b)? 1: 0);
case 8: // "IF"
var a = stack.pop();
if(a) { offset = 0; break; } // want GOTO
case 10:
offset = -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment