Sun, 21 Nov 2010 21:37:07 +0000
Implement OP_MOD, OP_POW, OP_UNM, OP_NOT (no metamethods yet)
lvm.js | file | annotate | diff | comparison | revisions |
--- a/lvm.js Sun Nov 21 21:36:26 2010 +0000 +++ b/lvm.js Sun Nov 21 21:37:07 2010 +0000 @@ -15,10 +15,10 @@ var OP_SUB = 13; var OP_MUL = 14; var OP_DIV = 15; -//var OP_MOD = 16; -//var OP_POW = 17; -//var OP_UNM = 18; -//var OP_NOT = 19; +var OP_MOD = 16; +var OP_POW = 17; +var OP_UNM = 18; +var OP_NOT = 19; //VAR OP_LEN = 20; var OP_CONCAT = 21; var OP_JMP = 22; @@ -630,6 +630,24 @@ var RC = RK(frame, INS_C(instruction)); frame.reg[INS_A(instruction)] = new LValue(this, "number", RB.value / RC.value); break; + case OP_MOD: + var RB = RK(frame, INS_B(instruction)); + var RC = RK(frame, INS_C(instruction)); + frame.reg[INS_A(instruction)] = new LValue(this, "number", RB.value % RC.value); + break; + case OP_POW: + var RB = RK(frame, INS_B(instruction)); + var RC = RK(frame, INS_C(instruction)); + frame.reg[INS_A(instruction)] = new LValue(this, "number", Math.pow(RB.value, RC.value)); + break; + case OP_UNM: + var RB = frame.reg[INS_B(instruction)]; + frame.reg[INS_A(instruction)] = new LValue(this, "number", -RB.value); + break; + case OP_NOT: + var RB = frame.reg[INS_B(instruction)]; + frame.reg[INS_A(instruction)] = new LValue(this, "boolean", !RB.truth()); + break; case OP_EQ: var A = INS_A(instruction); var RB = RK(frame, INS_B(instruction));