# HG changeset patch # User Matthew Wild # Date 1274578725 -3600 # Node ID d14b47c3870f4034bde991c5e2ad92df0c994969 # Parent 35a2203253a6047e3117c203c325baabc20996d5 Support for OP_NEWTABLE, OP_GETTABLE, OP_SETTABLE diff -r 35a2203253a6 -r d14b47c3870f lvm.js --- a/lvm.js Sun May 23 02:29:04 2010 +0100 +++ b/lvm.js Sun May 23 02:38:45 2010 +0100 @@ -4,8 +4,11 @@ var OP_LOADNIL = 3; var OP_GETUPVAL = 4; var OP_GETGLOBAL = 5; +var OP_GETTABLE = 6; var OP_SETGLOBAL = 7; var OP_SETUPVAL = 8; +var OP_SETTABLE = 9; +var OP_NEWTABLE = 10; var OP_CALL = 28; var OP_RETURN = 30; var OP_CLOSURE = 36; @@ -314,6 +317,26 @@ var value = this.frame.f.constants[INS_Bx(instruction)]; this.frame.reg[INS_A(instruction)] = value; break; + case OP_NEWTABLE: + this.frame.reg[INS_A(instruction)] = new LValue("table", {}); + break; + case OP_GETTABLE: + var C = INS_C(instruction); + var keysource = (C&256)?this.frame.f.constants:this.frame.reg; + var key = keysource[C&0xff]; + var value = this.frame.reg[INS_B(instruction)].index(key).value; + this.frame.reg[INS_A(instruction)] = new LValueFromValue(value); + break; + case OP_SETTABLE: + var C = INS_C(instruction); + var valuesource = (C&256)?this.frame.f.constants:this.frame.reg; + var value = valuesource[C&0xff]; + + var B = INS_B(instruction); + var keysource = (B&256)?this.frame.f.constants:this.frame.reg; + var key = keysource[B&0xff]; + this.frame.reg[INS_A(instruction)].setIndex(key, value); + break; case OP_CALL: var f = this.frame.reg[INS_A(instruction)].call(); // return JS or LValue var A = INS_A(instruction), B = INS_B(instruction), undefined;