Support for OP_NEWTABLE, OP_GETTABLE, OP_SETTABLE

Sun, 23 May 2010 02:38:45 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Sun, 23 May 2010 02:38:45 +0100
changeset 28
d14b47c3870f
parent 27
35a2203253a6
child 29
62f3df8ed204

Support for OP_NEWTABLE, OP_GETTABLE, OP_SETTABLE

lvm.js file | annotate | diff | comparison | revisions
--- 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;

mercurial