Implement CAT.

Allows the use of the '..' operator, for example:

x = "hello"
y = " "
z = "world!"
print(x..y..z) -- prints 'hello world!'
This commit is contained in:
Michael Munday 2016-12-29 11:23:45 -05:00
parent 29223bb979
commit e8ca7b8799

View File

@ -2078,8 +2078,28 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
break; break;
case BC_CAT: case BC_CAT:
| stg r0, 0(r0) | ins_ABC // RA = dst, RB = src_start, RC = src_end
| stg r0, 0(r0) | lg L:CARG1, SAVE_L
| stg BASE, L:CARG1->base
| lgr CARG3, RC
| sgr CARG3, RB
| sllg RC, RC, 3(r0)
| la CARG2, 0(RC, BASE)
|->BC_CAT_Z:
| lgr L:RB, L:CARG1
| stg PC, SAVE_PC
| brasl r14, extern lj_meta_cat // (lua_State *L, TValue *top, int left)
| // NULL (finished) or TValue * (metamethod) returned in r2 (CRET1).
| lg BASE, L:RB->base
| ltgr RC, CRET1
| jne ->vmeta_binop
| llgc RB, PC_RB // Copy result to Stk[RA] from Stk[RB].
| sllg RB, RB, 3(r0)
| llgc RA, PC_RA
| sllg RA, RA, 3(r0)
| lg RC, 0(RB, BASE)
| stg RC, 0(RA, BASE)
| ins_next
break; break;
/* -- Constant ops ------------------------------------------------------ */ /* -- Constant ops ------------------------------------------------------ */