Implement UGET.

Allows simple closures, for example:

function f(x)
  return function() return x end
end

y = f(1)
print(y()) -- prints 1
This commit is contained in:
Michael Munday 2016-12-28 10:56:09 -05:00
parent 354b5c748b
commit aba9cfb2a8

View File

@ -1970,8 +1970,16 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
| stg r0, 0(r0) | stg r0, 0(r0)
break; break;
case BC_UGET: case BC_UGET:
| stg r0, 0(r0) | ins_AD // RA = dst, RD = upvalue #
| stg r0, 0(r0) | sllg RA, RA, 3(r0)
| sllg RD, RD, 3(r0)
| lg LFUNC:RB, -16(BASE)
| cleartp LFUNC:RB
| lg UPVAL:RB, (offsetof(GCfuncL, uvptr))(RD, LFUNC:RB)
| lg RB, UPVAL:RB->v
| lg RD, 0(RB)
| stg RD, 0(RA, BASE)
| ins_next
break; break;
case BC_USETV: case BC_USETV:
| stg r0, 0(r0) | stg r0, 0(r0)