Fri, 19 Nov 2010 03:37:51 +0000
Implement OP_ADD, OP_SUB, OP_LT
lvm.js | file | annotate | diff | comparison | revisions |
--- a/lvm.js Tue Oct 26 10:43:56 2010 +0100 +++ b/lvm.js Fri Nov 19 03:37:51 2010 +0000 @@ -11,7 +11,10 @@ var OP_SETTABLE = 9; var OP_NEWTABLE = 10; var OP_SELF = 11; +var OP_ADD = 12; +var OP_SUB = 13; var OP_JMP = 22; +var OP_LT = 24; var OP_TEST = 26; var OP_CALL = 28; var OP_RETURN = 30; @@ -481,6 +484,22 @@ case OP_JMP: frame.pc+=INS_sBx(instruction); break; + case OP_ADD: + var RB = frame.reg[INS_B(instruction)]; + var RC = frame.reg[INS_C(instruction)]; + frame.reg[INS_A(instruction)] = new LValue("number", RB.value + RC.value); + break; + case OP_SUB: + var RB = frame.reg[INS_B(instruction)]; + var RC = frame.reg[INS_C(instruction)]; + frame.reg[INS_A(instruction)] = new LValue("number", RB.value - RC.value); + break; + case OP_LT: + var RB = frame.reg[INS_B(instruction)]; + var RC = frame.reg[INS_C(instruction)]; + if(RB.value < RC.value) + frame.pc++; + break; default: throw "Unhandled opcode: "+INS_OPCODE(instruction); }