# HG changeset patch # User Matthew Wild # Date 1274640885 -3600 # Node ID 70eb0eb5e7e89be8e1261097c1991c95035f5745 # Parent 3a074ec1790fc58f09306ee1ddb047f5bb855385 Split LVM.run() into LVM.call()/LVM.run() diff -r 3a074ec1790f -r 70eb0eb5e7e8 lvm.js --- a/lvm.js Sun May 23 17:31:57 2010 +0100 +++ b/lvm.js Sun May 23 19:54:45 2010 +0100 @@ -279,80 +279,84 @@ } LVM.prototype = { - run: function (lfFunction) + call: function (lfFunction) { - this.frame = {f:lfFunction,pc:0,reg:[]}; - this.callstack.push(this.frame); + var frame = {f:lfFunction,pc:0,reg:[]}; + this.callstack.push(frame); for(var i=0;i0) { - instruction = this.frame.f.instructions[this.frame.pc++]; + instruction = frame.f.instructions[frame.pc++]; if(debugMode) { - sys.puts("PC: "+(this.frame.pc-1)+" OP: "+instruction[0]); - sys.puts("STACK: "+sys.inspect(this.frame.reg)); + sys.puts("PC: "+(frame.pc-1)+" OP: "+instruction[0]); + sys.puts("STACK: "+sys.inspect(frame.reg)); } switch(INS_OPCODE(instruction)) { case OP_MOVE: - this.frame.reg[INS_A(instruction)] = this.frame.reg[INS_B(instruction)]; + frame.reg[INS_A(instruction)] = frame.reg[INS_B(instruction)]; break; case OP_LOADNIL: for(var i = INS_A(instruction);i<=INS_B(instruction);i++) - this.frame.reg[i] = new LValue("nil", null); + frame.reg[i] = new LValue("nil", null); break; case OP_LOADBOOL: - this.frame.reg[INS_A(instruction)] = new LValue("boolean", INS_B(instruction)!=0); + frame.reg[INS_A(instruction)] = new LValue("boolean", INS_B(instruction)!=0); if(INS_C(instruction)!=0) - this.frame.pc++; + frame.pc++; break; case OP_GETUPVAL: - this.frame.reg[INS_A(instruction)] = this.frame.f.upvalues[INS_B(instruction)]; + frame.reg[INS_A(instruction)] = frame.f.upvalues[INS_B(instruction)]; break; case OP_GETGLOBAL: - var name = this.frame.f.constants[INS_Bx(instruction)]; - this.frame.reg[INS_A(instruction)] = this.frame.f.environment.index(name); + var name = frame.f.constants[INS_Bx(instruction)]; + frame.reg[INS_A(instruction)] = frame.f.environment.index(name); break; case OP_SETUPVAL: - var reg = this.frame.reg[INS_A(instruction)]; - var upvalue = this.frame.f.upvalues[INS_B(instruction)]; + var reg = frame.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 = this.frame.f.constants[INS_Bx(instruction)]; - this.frame.f.environment.setIndex(name, this.frame.reg[instruction[1]]); + var name = frame.f.constants[INS_Bx(instruction)]; + frame.f.environment.setIndex(name, frame.reg[instruction[1]]); break; case OP_LOADK: - var constant = this.frame.f.constants[INS_Bx(instruction)]; - this.frame.reg[INS_A(instruction)] = new LValue(constant.type, constant.value); + var constant = frame.f.constants[INS_Bx(instruction)]; + frame.reg[INS_A(instruction)] = new LValue(constant.type, constant.value); break; case OP_NEWTABLE: - this.frame.reg[INS_A(instruction)] = new LValue("table", {}); + 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 keysource = (C&256)?frame.f.constants: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); + var value = frame.reg[INS_B(instruction)].index(key).value; + 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 valuesource = (C&256)?frame.f.constants:frame.reg; var value = valuesource[C&0xff]; var B = INS_B(instruction); - var keysource = (B&256)?this.frame.f.constants:this.frame.reg; + var keysource = (B&256)?frame.f.constants:frame.reg; var key = keysource[B&0xff]; - this.frame.reg[INS_A(instruction)].setIndex(key, value); + 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 f = frame.reg[INS_A(instruction)].call(); // return JS or LValue var A = INS_A(instruction), B = INS_B(instruction), undefined; - var args = this.frame.reg.slice(A+1, B==0?undefined:(A+B)); + var args = frame.reg.slice(A+1, B==0?undefined:(A+B)); for(var i=args.length+1;i