Add new RK() helper and fix OP_ADD to use it (so it loads constants properly)

Fri, 19 Nov 2010 16:06:12 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Fri, 19 Nov 2010 16:06:12 +0000
changeset 77
ab8ff064d808
parent 76
d7d7a6bb90cd
child 78
a856f1c3364f

Add new RK() helper and fix OP_ADD to use it (so it loads constants properly)

lvm.js file | annotate | diff | comparison | revisions
--- a/lvm.js	Fri Nov 19 16:05:36 2010 +0000
+++ b/lvm.js	Fri Nov 19 16:06:12 2010 +0000
@@ -294,6 +294,12 @@
 	return (INS_Bx(ins)-0x1FFFF);
 }
 
+function RK(frame, R)
+{
+	var keysource = (R&0x100)?frame.f.constants:frame.reg;
+	return keysource[R&0xff];
+}
+
 function LFunction(vm, chunk, env)
 {
 	function F() {};
@@ -531,8 +537,8 @@
 				frame.pc+=INS_sBx(instruction);
 				break;
 			case OP_ADD:
-				var RB = frame.reg[INS_B(instruction)];
-				var RC = frame.reg[INS_C(instruction)];
+				var RB = RK(frame, INS_B(instruction));
+				var RC = RK(frame, INS_C(instruction));
 				frame.reg[INS_A(instruction)] = RB.add(RC);
 				break;
 			case OP_SUB:

mercurial