lvm.js

changeset 123
f8518f015ec3
parent 122
b6956a682885
child 124
62354487e1ce
equal deleted inserted replaced
122:b6956a682885 123:f8518f015ec3
34 var OP_FORPREP = 32; 34 var OP_FORPREP = 32;
35 var OP_TFORLOOP = 33; 35 var OP_TFORLOOP = 33;
36 var OP_SETLIST = 34; 36 var OP_SETLIST = 34;
37 var OP_CLOSE = 35; 37 var OP_CLOSE = 35;
38 var OP_CLOSURE = 36; 38 var OP_CLOSURE = 36;
39 //var OP_VARARG = 37; 39 var OP_VARARG = 37;
40 40
41 var debugMode = false; 41 var debugMode = false;
42 42
43 function LValue(vm, type, value) 43 function LValue(vm, type, value)
44 { 44 {
479 break; 479 break;
480 case OP_SETTABLE: 480 case OP_SETTABLE:
481 var C = INS_C(instruction); 481 var C = INS_C(instruction);
482 var B = INS_B(instruction); 482 var B = INS_B(instruction);
483 frame.reg[INS_A(instruction)].setIndex(RK(frame, B), RK(frame, C)); 483 frame.reg[INS_A(instruction)].setIndex(RK(frame, B), RK(frame, C));
484 break;
485 case OP_VARARG:
486 var A = INS_A(instruction);
487 var prevframe = this.callstack[this.callstack.length-2];
488 var base = frame.retAt+frame.f.numParameters;
489 var available = prevframe.reg.length - base;
490 var wanted = INS_B(instruction)-1;
491 if(wanted < 0)
492 wanted = available;
493 for(var i = 0; i<wanted; i++)
494 {
495 if(i<available)
496 frame.reg[A+i] = prevframe.reg[base+i+1];
497 else
498 frame.reg[A+i] = new LValue(this, "nil", null);
499 }
484 break; 500 break;
485 case OP_CALL: 501 case OP_CALL:
486 var f = frame.reg[INS_A(instruction)].precall(); // return JS or LValue 502 var f = frame.reg[INS_A(instruction)].precall(); // return JS or LValue
487 var A = INS_A(instruction), B = INS_B(instruction), C = INS_C(instruction); 503 var A = INS_A(instruction), B = INS_B(instruction), C = INS_C(instruction);
488 var undefined; 504 var undefined;

mercurial