lvm.js

changeset 15
5240eaff785f
parent 14
21a2fce50931
child 16
9c8710ea2a5a
equal deleted inserted replaced
14:21a2fce50931 15:5240eaff785f
4 var OP_LOADNIL = 3; 4 var OP_LOADNIL = 3;
5 var OP_GETGLOBAL = 5; 5 var OP_GETGLOBAL = 5;
6 var OP_SETGLOBAL = 7; 6 var OP_SETGLOBAL = 7;
7 var OP_CALL = 28; 7 var OP_CALL = 28;
8 var OP_RETURN = 30; 8 var OP_RETURN = 30;
9 var OP_CLOSURE = 36;
9 10
10 var debugMode = false; 11 var debugMode = false;
11 12
12 function LValue(type, value) 13 function LValue(type, value)
13 { 14 {
292 else 293 else
293 { 294 {
294 // Lua function 295 // Lua function
295 } 296 }
296 break; 297 break;
298 case OP_CLOSURE:
299 var prototype_id = INS_Bx(instruction);
300 var chunk = this.frame.f.chunk.prototypes[prototype_id];
301 if(chunk.numUpvalues>0)
302 throw "Upvalues not yet implemented, sorry :)";
303 var f = new LFunction(chunk, this.frame.f.environment);
304 this.frame.reg[INS_A(instruction)] = new LValue("function", f);
305 break;
297 case OP_RETURN: 306 case OP_RETURN:
298 this.callstack.pop(); 307 this.callstack.pop();
299 break; 308 break;
300 default: 309 default:
301 throw "Unhandled opcode: "+INS_OPCODE(instruction); 310 throw "Unhandled opcode: "+INS_OPCODE(instruction);

mercurial