373 } |
374 } |
374 break; |
375 break; |
375 case OP_CLOSURE: |
376 case OP_CLOSURE: |
376 var prototype_id = INS_Bx(instruction); |
377 var prototype_id = INS_Bx(instruction); |
377 var chunk = frame.f.chunk.prototypes[prototype_id]; |
378 var chunk = frame.f.chunk.prototypes[prototype_id]; |
378 var f = new LFunction(chunk, frame.f.environment); |
379 var f = new LFunction(this, chunk, frame.f.environment); |
379 frame.reg[INS_A(instruction)] = new LValue("function", f); |
380 frame.reg[INS_A(instruction)] = new LValue("function", f); |
380 for(var i=0;i<chunk.numUpvalues;i++) |
381 for(var i=0;i<chunk.numUpvalues;i++) |
381 { |
382 { |
382 var upval_instruction = frame.f.instructions[frame.pc++]; |
383 var upval_instruction = frame.f.instructions[frame.pc++]; |
383 switch(INS_OPCODE(upval_instruction)) |
384 switch(INS_OPCODE(upval_instruction)) |
464 else |
465 else |
465 print = require("sys").puts; // Nodejs |
466 print = require("sys").puts; // Nodejs |
466 |
467 |
467 default_environment.setIndex(LValueFromString("print"), LValueFromFunction(print)); |
468 default_environment.setIndex(LValueFromString("print"), LValueFromFunction(print)); |
468 |
469 |
469 var f = new LFunction(c, default_environment); |
470 var f = new LFunction(this, c, default_environment); |
470 |
471 |
471 try{ |
472 try{ |
472 testvm.call(f); |
473 testvm.call(f); |
473 } |
474 } |
474 catch(e) |
475 catch(e) |
475 { |
476 { |
476 print("Error: " + e); |
477 print("Error: " + e); |
477 if(typeof(e) == "object" && "stack" in e) |
478 if(typeof(e) == "object" && "stack" in e) |
478 print(e.stack); |
479 print(e.stack); |
479 } |
480 process.exit(1); |
|
481 } |