# HG changeset patch # User Matthew Wild # Date 1274617725 -3600 # Node ID 2c3d73c76d0f2c19b894e89776d0ed5175a6a631 # Parent 6cc1b0a8dd97aea0e6dc6da21d5c4654e510f9fa OP_FORPREP, OP_FORLOOP: Support for numerical for loops diff -r 6cc1b0a8dd97 -r 2c3d73c76d0f lvm.js --- a/lvm.js Sun May 23 13:28:23 2010 +0100 +++ b/lvm.js Sun May 23 13:28:45 2010 +0100 @@ -11,6 +11,8 @@ var OP_NEWTABLE = 10; var OP_CALL = 28; var OP_RETURN = 30; +var OP_FORLOOP = 31; +var OP_FORPREP = 32; var OP_CLOSURE = 36; var debugMode = false; @@ -391,6 +393,22 @@ this.frame.reg.splice(0,oldFrame.retAt+i); } break; + case OP_FORPREP: + this.frame.pc+=(INS_sBx(instruction)); + var A = INS_A(instruction); + this.frame.reg[A].value -= this.frame.reg[A+2].value; + this.frame.reg[A+3] = new LValue("number", null); + break; + case OP_FORLOOP: + var A = INS_A(instruction); + var RA = this.frame.reg[A]; + RA.value += this.frame.reg[A+2].value; + if(RA.value <= this.frame.reg[A+1].value) + { + this.frame.pc += INS_sBx(instruction); + this.frame.reg[A+3].value = RA.value; + } + break; default: throw "Unhandled opcode: "+INS_OPCODE(instruction); }