lvm.js

changeset 40
3a074ec1790f
parent 39
53d5bf6654ba
child 41
70eb0eb5e7e8
equal deleted inserted replaced
39:53d5bf6654ba 40:3a074ec1790f
9 var OP_SETGLOBAL = 7; 9 var OP_SETGLOBAL = 7;
10 var OP_SETUPVAL = 8; 10 var OP_SETUPVAL = 8;
11 var OP_SETTABLE = 9; 11 var OP_SETTABLE = 9;
12 var OP_NEWTABLE = 10; 12 var OP_NEWTABLE = 10;
13 var OP_SELF = 11; 13 var OP_SELF = 11;
14 var OP_JMP = 22;
15 var OP_TEST = 26;
14 var OP_CALL = 28; 16 var OP_CALL = 28;
15 var OP_RETURN = 30; 17 var OP_RETURN = 30;
16 var OP_FORLOOP = 31; 18 var OP_FORLOOP = 31;
17 var OP_FORPREP = 32; 19 var OP_FORPREP = 32;
18 var OP_CLOSURE = 36; 20 var OP_CLOSURE = 36;
426 { 428 {
427 this.frame.pc += INS_sBx(instruction); 429 this.frame.pc += INS_sBx(instruction);
428 this.frame.reg[A+3].value = RA.value; 430 this.frame.reg[A+3].value = RA.value;
429 } 431 }
430 break; 432 break;
433 case OP_TEST:
434 var RA = this.frame.reg[INS_A(instruction)];
435 var RA_bool = RA.type == "nil" || (RA.type == "boolean" && RA.value == false);
436 if(RA_bool == (INS_C(instruction)!=0))
437 this.frame.pc++;
438 break;
439 case OP_JMP:
440 this.frame.pc+=INS_sBx(instruction);
441 break;
431 default: 442 default:
432 throw "Unhandled opcode: "+INS_OPCODE(instruction); 443 throw "Unhandled opcode: "+INS_OPCODE(instruction);
433 } 444 }
434 } 445 }
435 } 446 }

mercurial