Sun, 21 Nov 2010 16:27:18 +0000
Implement OP_TFORLOOP
lvm.js | file | annotate | diff | comparison | revisions |
--- a/lvm.js Sun Nov 21 16:25:08 2010 +0000 +++ b/lvm.js Sun Nov 21 16:27:18 2010 +0000 @@ -25,6 +25,7 @@ var OP_RETURN = 30; var OP_FORLOOP = 31; var OP_FORPREP = 32; +var OP_TFORLOOP = 33; var OP_CLOSURE = 36; var debugMode = false; @@ -555,6 +556,19 @@ frame.reg[A+3].value = RA.value; } break; + case OP_TFORLOOP: + var A = INS_A(instruction); + var C = INS_C(instruction); + var f = frame.reg[A].precall(); // Iterator function + var rets = this.call(f, [frame.reg[A+1], frame.reg[A+2]]); + frame.reg.length = A+3; + for(var i = 0; i<C; i++) + frame.reg[A+3+i] = rets[i]; + if(frame.reg[A+3].type != "nil") + frame.reg[A+2] = frame.reg[A+3]; + else + frame.pc++; // Skip JMP to start + continue; case OP_TEST: var RA = frame.reg[INS_A(instruction)]; var RA_bool = RA.type == "nil" || (RA.type == "boolean" && RA.value == false);