lvm.js

changeset 89
a9cef9e01154
parent 88
350a87c42b9b
child 90
40edbc05fbb9
equal deleted inserted replaced
88:350a87c42b9b 89:a9cef9e01154
22 var OP_RETURN = 30; 22 var OP_RETURN = 30;
23 var OP_FORLOOP = 31; 23 var OP_FORLOOP = 31;
24 var OP_FORPREP = 32; 24 var OP_FORPREP = 32;
25 var OP_CLOSURE = 36; 25 var OP_CLOSURE = 36;
26 26
27 var debugMode = false; 27 var debugMode = true;
28 28
29 function LValue(vm, type, value) 29 function LValue(vm, type, value)
30 { 30 {
31 this.vm = vm; 31 this.vm = vm;
32 this.type = type||"nil"; 32 this.type = type||"nil";
565 frame.reg[INS_A(instruction)] = RB; 565 frame.reg[INS_A(instruction)] = RB;
566 break; 566 break;
567 case OP_JMP: 567 case OP_JMP:
568 frame.pc+=INS_sBx(instruction); 568 frame.pc+=INS_sBx(instruction);
569 break; 569 break;
570 case OP_ADD:
571 var RB = RK(frame, INS_B(instruction));
572 var RC = RK(frame, INS_C(instruction));
573 frame.reg[INS_A(instruction)] = RB.add(RC);
574 break;
575 case OP_SUB:
576 var RB = frame.reg[INS_B(instruction)];
577 var RC = frame.reg[INS_C(instruction)];
578 frame.reg[INS_A(instruction)] = new LValue(this, "number", RB.value - RC.value);
579 break;
570 case OP_EQ: 580 case OP_EQ:
571 var A = INS_A(instruction); 581 var A = INS_A(instruction);
572 var RB = RK(frame, INS_B(instruction)); 582 var RB = RK(frame, INS_B(instruction));
573 var RC = RK(frame, INS_C(instruction)); 583 var RC = RK(frame, INS_C(instruction));
574 if(RB.equals(RC) != (A!=0)) 584 if(RB.equals(RC) != (A!=0))
575 frame.pc++; 585 frame.pc++;
576 break; 586 break;
577 case OP_ADD: 587 case OP_LT:
588 var A = INS_A(instruction);
578 var RB = RK(frame, INS_B(instruction)); 589 var RB = RK(frame, INS_B(instruction));
579 var RC = RK(frame, INS_C(instruction)); 590 var RC = RK(frame, INS_C(instruction));
580 frame.reg[INS_A(instruction)] = RB.add(RC); 591 if(RB.value < RC.value != (A!=0))
581 break;
582 case OP_SUB:
583 var RB = frame.reg[INS_B(instruction)];
584 var RC = frame.reg[INS_C(instruction)];
585 frame.reg[INS_A(instruction)] = new LValue(this, "number", RB.value - RC.value);
586 break;
587 case OP_LT:
588 var RB = RK(frame, INS_B(instruction));
589 var RC = RK(frame, INS_C(instruction));
590 if(RB.value < RC.value)
591 frame.pc++; 592 frame.pc++;
592 break; 593 break;
593 default: 594 default:
594 throw "Unhandled opcode: "+INS_OPCODE(instruction); 595 throw "Unhandled opcode: "+INS_OPCODE(instruction);
595 } 596 }

mercurial