42:741b953fcc5f | 43:ecfa7896af35 |
---|---|
258 function INS_sBx(ins) | 258 function INS_sBx(ins) |
259 { | 259 { |
260 return (INS_Bx(ins)-0x1FFFF); | 260 return (INS_Bx(ins)-0x1FFFF); |
261 } | 261 } |
262 | 262 |
263 function LFunction(chunk, env) | 263 function LFunction(vm, chunk, env) |
264 { | 264 { |
265 function F() {}; | 265 function F() {}; |
266 F.prototype = chunk; | 266 F.prototype = chunk; |
267 var o = new F(); | 267 var o = new F(); |
268 o.vm = vm; | |
268 o.environment = env; | 269 o.environment = env; |
269 o.chunk = chunk; | 270 o.chunk = chunk; |
270 o.upvalues = []; | 271 o.upvalues = []; |
271 return o; | 272 return o; |
272 } | 273 } |
375 } | 376 } |
376 break; | 377 break; |
377 case OP_CLOSURE: | 378 case OP_CLOSURE: |
378 var prototype_id = INS_Bx(instruction); | 379 var prototype_id = INS_Bx(instruction); |
379 var chunk = frame.f.chunk.prototypes[prototype_id]; | 380 var chunk = frame.f.chunk.prototypes[prototype_id]; |
380 var f = new LFunction(chunk, frame.f.environment); | 381 var f = new LFunction(this, chunk, frame.f.environment); |
381 reg[INS_A(instruction)] = new LValue("function", f); | 382 reg[INS_A(instruction)] = new LValue("function", f); |
382 for(var i=0;i<chunk.numUpvalues;i++) | 383 for(var i=0;i<chunk.numUpvalues;i++) |
383 { | 384 { |
384 var upval_instruction = instructions[frame.pc++]; | 385 var upval_instruction = instructions[frame.pc++]; |
385 switch(INS_OPCODE(upval_instruction)) | 386 switch(INS_OPCODE(upval_instruction)) |
466 else | 467 else |
467 print = require("sys").puts; // Nodejs | 468 print = require("sys").puts; // Nodejs |
468 | 469 |
469 default_environment.setIndex(LValueFromString("print"), LValueFromFunction(print)); | 470 default_environment.setIndex(LValueFromString("print"), LValueFromFunction(print)); |
470 | 471 |
471 var f = new LFunction(c, default_environment); | 472 var f = new LFunction(this, c, default_environment); |
472 | 473 |
473 try{ | 474 try{ |
474 testvm.call(f); | 475 testvm.call(f); |
475 } | 476 } |
476 catch(e) | 477 catch(e) |