# HG changeset patch # User Matthew Wild # Date 1274702060 -3600 # Node ID 741b953fcc5ff1369f801199b320a5fa47e5b2ce # Parent 70eb0eb5e7e89be8e1261097c1991c95035f5745 Localize instructions and reg from frame diff -r 70eb0eb5e7e8 -r 741b953fcc5f lvm.js --- a/lvm.js Sun May 23 19:54:45 2010 +0100 +++ b/lvm.js Mon May 24 12:54:20 2010 +0100 @@ -289,74 +289,76 @@ }, run: function(frame) { + var instructions = frame.f.instructions; + var reg = frame.reg; var instruction; while(this.callstack.length>0) { - instruction = frame.f.instructions[frame.pc++]; + instruction = instructions[frame.pc++]; if(debugMode) { sys.puts("PC: "+(frame.pc-1)+" OP: "+instruction[0]); - sys.puts("STACK: "+sys.inspect(frame.reg)); + sys.puts("STACK: "+sys.inspect(reg)); } switch(INS_OPCODE(instruction)) { case OP_MOVE: - frame.reg[INS_A(instruction)] = frame.reg[INS_B(instruction)]; + reg[INS_A(instruction)] = reg[INS_B(instruction)]; break; case OP_LOADNIL: for(var i = INS_A(instruction);i<=INS_B(instruction);i++) - frame.reg[i] = new LValue("nil", null); + reg[i] = new LValue("nil", null); break; case OP_LOADBOOL: - frame.reg[INS_A(instruction)] = new LValue("boolean", INS_B(instruction)!=0); + reg[INS_A(instruction)] = new LValue("boolean", INS_B(instruction)!=0); if(INS_C(instruction)!=0) frame.pc++; break; case OP_GETUPVAL: - frame.reg[INS_A(instruction)] = frame.f.upvalues[INS_B(instruction)]; + reg[INS_A(instruction)] = frame.f.upvalues[INS_B(instruction)]; break; case OP_GETGLOBAL: var name = frame.f.constants[INS_Bx(instruction)]; - frame.reg[INS_A(instruction)] = frame.f.environment.index(name); + reg[INS_A(instruction)] = frame.f.environment.index(name); break; case OP_SETUPVAL: - var reg = frame.reg[INS_A(instruction)]; + var reg = reg[INS_A(instruction)]; var upvalue = frame.f.upvalues[INS_B(instruction)]; upvalue.type = reg.type; upvalue.value = reg.value; break; case OP_SETGLOBAL: var name = frame.f.constants[INS_Bx(instruction)]; - frame.f.environment.setIndex(name, frame.reg[instruction[1]]); + frame.f.environment.setIndex(name, reg[instruction[1]]); break; case OP_LOADK: var constant = frame.f.constants[INS_Bx(instruction)]; - frame.reg[INS_A(instruction)] = new LValue(constant.type, constant.value); + reg[INS_A(instruction)] = new LValue(constant.type, constant.value); break; case OP_NEWTABLE: - frame.reg[INS_A(instruction)] = new LValue("table", {}); + reg[INS_A(instruction)] = new LValue("table", {}); break; case OP_GETTABLE: var C = INS_C(instruction); - var keysource = (C&256)?frame.f.constants:frame.reg; + var keysource = (C&256)?frame.f.constants:reg; var key = keysource[C&0xff]; - var value = frame.reg[INS_B(instruction)].index(key).value; - frame.reg[INS_A(instruction)] = new LValueFromValue(value); + var value = reg[INS_B(instruction)].index(key).value; + reg[INS_A(instruction)] = new LValueFromValue(value); break; case OP_SETTABLE: var C = INS_C(instruction); - var valuesource = (C&256)?frame.f.constants:frame.reg; + var valuesource = (C&256)?frame.f.constants:reg; var value = valuesource[C&0xff]; var B = INS_B(instruction); - var keysource = (B&256)?frame.f.constants:frame.reg; + var keysource = (B&256)?frame.f.constants:reg; var key = keysource[B&0xff]; - frame.reg[INS_A(instruction)].setIndex(key, value); + reg[INS_A(instruction)].setIndex(key, value); break; case OP_CALL: - var f = frame.reg[INS_A(instruction)].call(); // return JS or LValue + var f = reg[INS_A(instruction)].call(); // return JS or LValue var A = INS_A(instruction), B = INS_B(instruction), undefined; - var args = frame.reg.slice(A+1, B==0?undefined:(A+B)); + var args = reg.slice(A+1, B==0?undefined:(A+B)); for(var i=args.length+1;i