# HG changeset patch # User Matthew Wild # Date 1290375427 0 # Node ID 5318bb31b0ac511975fd024b28ae6331727303a8 # Parent cb1ef8a51da46d786fa3bd2d5fbdc3a1061b9f45 Implement OP_MOD, OP_POW, OP_UNM, OP_NOT (no metamethods yet) diff -r cb1ef8a51da4 -r 5318bb31b0ac lvm.js --- 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));