lvm.js

changeset 28
d14b47c3870f
parent 27
35a2203253a6
child 29
62f3df8ed204
equal deleted inserted replaced
27:35a2203253a6 28:d14b47c3870f
2 var OP_MOVE = 0; 2 var OP_MOVE = 0;
3 var OP_LOADK = 1; 3 var OP_LOADK = 1;
4 var OP_LOADNIL = 3; 4 var OP_LOADNIL = 3;
5 var OP_GETUPVAL = 4; 5 var OP_GETUPVAL = 4;
6 var OP_GETGLOBAL = 5; 6 var OP_GETGLOBAL = 5;
7 var OP_GETTABLE = 6;
7 var OP_SETGLOBAL = 7; 8 var OP_SETGLOBAL = 7;
8 var OP_SETUPVAL = 8; 9 var OP_SETUPVAL = 8;
10 var OP_SETTABLE = 9;
11 var OP_NEWTABLE = 10;
9 var OP_CALL = 28; 12 var OP_CALL = 28;
10 var OP_RETURN = 30; 13 var OP_RETURN = 30;
11 var OP_CLOSURE = 36; 14 var OP_CLOSURE = 36;
12 15
13 var debugMode = false; 16 var debugMode = false;
311 this.frame.f.environment.setIndex(name, this.frame.reg[instruction[1]]); 314 this.frame.f.environment.setIndex(name, this.frame.reg[instruction[1]]);
312 break; 315 break;
313 case OP_LOADK: 316 case OP_LOADK:
314 var value = this.frame.f.constants[INS_Bx(instruction)]; 317 var value = this.frame.f.constants[INS_Bx(instruction)];
315 this.frame.reg[INS_A(instruction)] = value; 318 this.frame.reg[INS_A(instruction)] = value;
319 break;
320 case OP_NEWTABLE:
321 this.frame.reg[INS_A(instruction)] = new LValue("table", {});
322 break;
323 case OP_GETTABLE:
324 var C = INS_C(instruction);
325 var keysource = (C&256)?this.frame.f.constants:this.frame.reg;
326 var key = keysource[C&0xff];
327 var value = this.frame.reg[INS_B(instruction)].index(key).value;
328 this.frame.reg[INS_A(instruction)] = new LValueFromValue(value);
329 break;
330 case OP_SETTABLE:
331 var C = INS_C(instruction);
332 var valuesource = (C&256)?this.frame.f.constants:this.frame.reg;
333 var value = valuesource[C&0xff];
334
335 var B = INS_B(instruction);
336 var keysource = (B&256)?this.frame.f.constants:this.frame.reg;
337 var key = keysource[B&0xff];
338 this.frame.reg[INS_A(instruction)].setIndex(key, value);
316 break; 339 break;
317 case OP_CALL: 340 case OP_CALL:
318 var f = this.frame.reg[INS_A(instruction)].call(); // return JS or LValue 341 var f = this.frame.reg[INS_A(instruction)].call(); // return JS or LValue
319 var A = INS_A(instruction), B = INS_B(instruction), undefined; 342 var A = INS_A(instruction), B = INS_B(instruction), undefined;
320 var args = this.frame.reg.slice(A+1, B==0?undefined:(A+B)); 343 var args = this.frame.reg.slice(A+1, B==0?undefined:(A+B));

mercurial