Sun, 23 May 2010 17:31:57 +0100
Implement OP_TEST and OP_JMP
lvm.js | file | annotate | diff | comparison | revisions |
--- a/lvm.js Sun May 23 17:31:41 2010 +0100 +++ b/lvm.js Sun May 23 17:31:57 2010 +0100 @@ -11,6 +11,8 @@ var OP_SETTABLE = 9; var OP_NEWTABLE = 10; var OP_SELF = 11; +var OP_JMP = 22; +var OP_TEST = 26; var OP_CALL = 28; var OP_RETURN = 30; var OP_FORLOOP = 31; @@ -428,6 +430,15 @@ this.frame.reg[A+3].value = RA.value; } break; + case OP_TEST: + var RA = this.frame.reg[INS_A(instruction)]; + var RA_bool = RA.type == "nil" || (RA.type == "boolean" && RA.value == false); + if(RA_bool == (INS_C(instruction)!=0)) + this.frame.pc++; + break; + case OP_JMP: + this.frame.pc+=INS_sBx(instruction); + break; default: throw "Unhandled opcode: "+INS_OPCODE(instruction); }