Sat, 22 May 2010 20:07:05 +0100
It's required to insert the new function into the stack before processing its upvalue instructions, in case it refers to itself.
lvm.js | file | annotate | diff | comparison | revisions |
--- a/lvm.js Sat May 22 20:05:58 2010 +0100 +++ b/lvm.js Sat May 22 20:07:05 2010 +0100 @@ -312,6 +312,7 @@ var prototype_id = INS_Bx(instruction); var chunk = this.frame.f.chunk.prototypes[prototype_id]; var f = new LFunction(chunk, this.frame.f.environment); + this.frame.reg[INS_A(instruction)] = new LValue("function", f); for(var i=0;i<chunk.numUpvalues;i++) { var upval_instruction = this.frame.f.instructions[this.frame.pc++]; @@ -327,7 +328,6 @@ throw "Invalid upvalue opcode following OP_CLOSURE"; } } - this.frame.reg[INS_A(instruction)] = new LValue("function", f); break; case OP_RETURN: var oldFrame = this.callstack.pop();