Implement LOOP.

Allows for while and repeat loops, for example:

x = 0
while x < 5 do
  print(x)
  x = x + 1
end

-- prints:
-- 0
-- 1
-- 2
-- 3
-- 4
This commit is contained in:
Michael Munday 2016-12-28 14:13:08 -05:00
parent 6673652fd9
commit 5dc644ad89

View File

@ -2844,14 +2844,22 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
| stg r0, 0(r0) | stg r0, 0(r0)
| stg r0, 0(r0) | stg r0, 0(r0)
break; break;
case BC_LOOP: case BC_LOOP:
| stg r0, 0(r0) | ins_A // RA = base, RD = target (loop extent)
| stg r0, 0(r0) | // Note: RA/RD is only used by trace recorder to determine scope/extent
| // This opcode does NOT jump, it's only purpose is to detect a hot loop.
|.if JIT
| hotloop RBd
|.endif
| // Fall through. Assumes BC_ILOOP follows and ins_A is a no-op.
break; break;
case BC_ILOOP: case BC_ILOOP:
| stg r0, 0(r0) | ins_A // RA = base, RD = target (loop extent)
| stg r0, 0(r0) | ins_next
break; break;
case BC_JLOOP: case BC_JLOOP:
| stg r0, 0(r0) | stg r0, 0(r0)
| stg r0, 0(r0) | stg r0, 0(r0)