mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-07 23:24:09 +00:00
Use 0/1 macro for Lua 5.2 compatibility.
This commit is contained in:
parent
039bf85e26
commit
23932a6c8b
@ -278,16 +278,12 @@ LJLIB_ASM(next)
|
||||
return FFH_UNREACHABLE;
|
||||
}
|
||||
|
||||
#if defined(LUAJIT_ENABLE_LUA52COMPAT) || LJ_HASFFI
|
||||
#if LJ_52 || LJ_HASFFI
|
||||
static int ffh_pairs(lua_State *L, MMS mm)
|
||||
{
|
||||
TValue *o = lj_lib_checkany(L, 1);
|
||||
cTValue *mo = lj_meta_lookup(L, o, mm);
|
||||
if (
|
||||
#if !defined(LUAJIT_ENABLE_LUA52COMPAT)
|
||||
tviscdata(o) &&
|
||||
#endif
|
||||
!tvisnil(mo)) {
|
||||
if ((LJ_52 || tviscdata(o)) && !tvisnil(mo)) {
|
||||
L->top = o+1; /* Only keep one argument. */
|
||||
copyTV(L, L->base-1, mo); /* Replace callable. */
|
||||
return FFH_TAILCALL;
|
||||
@ -542,7 +538,7 @@ LJLIB_CF(coroutine_status)
|
||||
|
||||
LJLIB_CF(coroutine_running)
|
||||
{
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
int ismain = lua_pushthread(L);
|
||||
setboolV(L->top++, ismain);
|
||||
return 2;
|
||||
|
@ -273,7 +273,7 @@ LJLIB_CF(table_sort)
|
||||
LUALIB_API int luaopen_table(lua_State *L)
|
||||
{
|
||||
LJ_LIB_REG(L, LUA_TABLIBNAME, table);
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
lua_getglobal(L, "unpack");
|
||||
lua_setfield(L, -2, "unpack");
|
||||
#endif
|
||||
|
@ -400,4 +400,11 @@
|
||||
#define LJ_NO_UNWIND 1
|
||||
#endif
|
||||
|
||||
/* Compatibility with Lua 5.1 vs. 5.2. */
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#define LJ_52 1
|
||||
#else
|
||||
#define LJ_52 0
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -353,10 +353,7 @@ static void LJ_FASTCALL recff_ipairs_aux(jit_State *J, RecordFFData *rd)
|
||||
|
||||
static void LJ_FASTCALL recff_ipairs(jit_State *J, RecordFFData *rd)
|
||||
{
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
if (!recff_metacall(J, rd, MM_ipairs))
|
||||
#endif
|
||||
{
|
||||
if (!(LJ_52 && recff_metacall(J, rd, MM_ipairs))) {
|
||||
TRef tab = J->base[0];
|
||||
if (tref_istab(tab)) {
|
||||
J->base[0] = lj_ir_kfunc(J, funcV(&J->fn->c.upvalue[0]));
|
||||
|
@ -315,19 +315,13 @@ TValue * LJ_FASTCALL lj_meta_len(lua_State *L, cTValue *o)
|
||||
{
|
||||
cTValue *mo = lj_meta_lookup(L, o, MM_len);
|
||||
if (tvisnil(mo)) {
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
if (tvistab(o))
|
||||
if (LJ_52 && tvistab(o))
|
||||
tabref(tabV(o)->metatable)->nomm |= (uint8_t)(1u<<MM_len);
|
||||
else
|
||||
#endif
|
||||
lj_err_optype(L, o, LJ_ERR_OPLEN);
|
||||
return NULL;
|
||||
}
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
return mmcall(L, lj_cont_ra, mo, o, o);
|
||||
#else
|
||||
return mmcall(L, lj_cont_ra, mo, o, niltv(L));
|
||||
#endif
|
||||
return mmcall(L, lj_cont_ra, mo, o, LJ_52 ? o : niltv(L));
|
||||
}
|
||||
|
||||
/* Helper for equality comparisons. __eq metamethod. */
|
||||
|
@ -447,7 +447,7 @@ enum {
|
||||
#define MMDEF_FFI(_)
|
||||
#endif
|
||||
|
||||
#if defined(LUAJIT_ENABLE_LUA52COMPAT) || LJ_HASFFI
|
||||
#if LJ_52 || LJ_HASFFI
|
||||
#define MMDEF_PAIRS(_) _(pairs) _(ipairs)
|
||||
#else
|
||||
#define MMDEF_PAIRS(_)
|
||||
|
@ -2495,7 +2495,7 @@ static int parse_stmt(LexState *ls)
|
||||
lj_lex_next(ls);
|
||||
parse_break(ls);
|
||||
return 1; /* Must be last. */
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
case ';':
|
||||
lj_lex_next(ls);
|
||||
break;
|
||||
|
@ -906,17 +906,15 @@ static TRef rec_mm_len(jit_State *J, TRef tr, TValue *tv)
|
||||
TValue *basev = J->L->base + func;
|
||||
base[0] = ix.mobj; copyTV(J->L, basev+0, &ix.mobjv);
|
||||
base[1] = tr; copyTV(J->L, basev+1, tv);
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
base[2] = tr; copyTV(J->L, basev+2, tv);
|
||||
#else
|
||||
base[2] = TREF_NIL; setnilV(basev+2);
|
||||
#endif
|
||||
lj_record_call(J, func, 2);
|
||||
} else {
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
if (tref_istab(tr))
|
||||
if (LJ_52 && tref_istab(tr))
|
||||
return lj_ir_call(J, IRCALL_lj_tab_len, tr);
|
||||
#endif
|
||||
lj_trace_err(J, LJ_TRERR_NOMM);
|
||||
}
|
||||
return 0; /* No result yet. */
|
||||
@ -1815,10 +1813,8 @@ void lj_record_ins(jit_State *J)
|
||||
case BC_LEN:
|
||||
if (tref_isstr(rc))
|
||||
rc = emitir(IRTI(IR_FLOAD), rc, IRFL_STR_LEN);
|
||||
#ifndef LUAJIT_ENABLE_LUA52COMPAT
|
||||
else if (tref_istab(rc))
|
||||
else if (!LJ_52 && tref_istab(rc))
|
||||
rc = lj_ir_call(J, IRCALL_lj_tab_len, rc);
|
||||
#endif
|
||||
else
|
||||
rc = rec_mm_len(J, rc, rcv);
|
||||
break;
|
||||
|
@ -793,7 +793,7 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
| bl extern lj_meta_len // (lua_State *L, TValue *o)
|
||||
| // Returns NULL (retry) or TValue * (metamethod base).
|
||||
| .IOS ldr BASE, L->base
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
| cmp CRET1, #0
|
||||
| bne ->vmeta_binop // Binop call for compatibility.
|
||||
| ldr TAB:CARG1, [BASE, RC]
|
||||
@ -1085,12 +1085,12 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
|
|
||||
|.ffunc_1 pairs
|
||||
| checktab CARG2, ->fff_fallback
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
| ldr TAB:RB, TAB:CARG1->metatable
|
||||
#endif
|
||||
| ldrd CFUNC:CARG34, CFUNC:CARG3->upvalue[0]
|
||||
| ldr PC, [BASE, FRAME_PC]
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
| cmp TAB:RB, #0
|
||||
| bne ->fff_fallback
|
||||
#endif
|
||||
@ -1135,12 +1135,12 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
|
|
||||
|.ffunc_1 ipairs
|
||||
| checktab CARG2, ->fff_fallback
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
| ldr TAB:RB, TAB:CARG1->metatable
|
||||
#endif
|
||||
| ldrd CFUNC:CARG34, CFUNC:CARG3->upvalue[0]
|
||||
| ldr PC, [BASE, FRAME_PC]
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
| cmp TAB:RB, #0
|
||||
| bne ->fff_fallback
|
||||
#endif
|
||||
@ -2906,7 +2906,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
|
||||
| ins_next3
|
||||
|2:
|
||||
| checktab CARG2, ->vmeta_len
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
| ldr TAB:CARG3, TAB:CARG1->metatable
|
||||
| cmp TAB:CARG3, #0
|
||||
| bne >9
|
||||
@ -2918,7 +2918,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
|
||||
| // Returns uint32_t (but less than 2^31).
|
||||
| .IOS mov BASE, RC
|
||||
| b <1
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
|9:
|
||||
| ldrb CARG4, TAB:CARG3->nomm
|
||||
| tst CARG4, #1<<MM_len
|
||||
|
@ -842,7 +842,7 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
|
|
||||
|->vmeta_len:
|
||||
| // CARG2 already set by BC_LEN.
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
| move MULTRES, CARG1
|
||||
#endif
|
||||
| load_got lj_meta_len
|
||||
@ -851,7 +851,7 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
| call_intern lj_meta_len // (lua_State *L, TValue *o)
|
||||
|. move CARG1, L
|
||||
| // Returns NULL (retry) or TValue * (metamethod base).
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
| bnez CRET1, ->vmeta_binop // Binop call for compatibility.
|
||||
|. nop
|
||||
| b ->BC_LEN_Z
|
||||
@ -1159,7 +1159,7 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
| li AT, LJ_TTAB
|
||||
| bne CARG3, AT, ->fff_fallback
|
||||
|. lw PC, FRAME_PC(BASE)
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
| lw TAB:TMP2, TAB:CARG1->metatable
|
||||
| ldc1 f0, CFUNC:RB->upvalue[0]
|
||||
| bnez TAB:TMP2, ->fff_fallback
|
||||
@ -1225,7 +1225,7 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
| li AT, LJ_TTAB
|
||||
| bne CARG3, AT, ->fff_fallback
|
||||
|. lw PC, FRAME_PC(BASE)
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
| lw TAB:TMP2, TAB:CARG1->metatable
|
||||
| ldc1 f0, CFUNC:RB->upvalue[0]
|
||||
| bnez TAB:TMP2, ->fff_fallback
|
||||
@ -2613,7 +2613,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
|
||||
|2:
|
||||
| bne TMP0, AT, ->vmeta_len
|
||||
|. nop
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
| lw TAB:TMP2, TAB:CARG1->metatable
|
||||
| bnez TAB:TMP2, >9
|
||||
|. nop
|
||||
@ -2626,7 +2626,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
|
||||
| // Returns uint32_t (but less than 2^31).
|
||||
| b <1
|
||||
|. nop
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
|9:
|
||||
| lbu TMP0, TAB:TMP2->nomm
|
||||
| andi TMP0, TMP0, 1<<MM_len
|
||||
|
@ -1057,7 +1057,7 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
| b ->vm_call_dispatch
|
||||
|
|
||||
|->vmeta_len:
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
| mr SAVE0, CARG1
|
||||
#endif
|
||||
| mr CARG2, RD
|
||||
@ -1066,7 +1066,7 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
| stw PC, SAVE_PC
|
||||
| bl extern lj_meta_len // (lua_State *L, TValue *o)
|
||||
| // Returns NULL (retry) or TValue * (metamethod base).
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
| cmplwi CRET1, 0
|
||||
| bne ->vmeta_binop // Binop call for compatibility.
|
||||
| mr CARG1, SAVE0
|
||||
@ -1364,7 +1364,7 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
| checktab CARG3
|
||||
| lwz PC, FRAME_PC(BASE)
|
||||
| bne ->fff_fallback
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
| lwz TAB:TMP2, TAB:CARG1->metatable
|
||||
| lfd f0, CFUNC:RB->upvalue[0]
|
||||
| cmplwi TAB:TMP2, 0
|
||||
@ -1450,7 +1450,7 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
| checktab CARG3
|
||||
| lwz PC, FRAME_PC(BASE)
|
||||
| bne ->fff_fallback
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
| lwz TAB:TMP2, TAB:CARG1->metatable
|
||||
| lfd f0, CFUNC:RB->upvalue[0]
|
||||
| cmplwi TAB:TMP2, 0
|
||||
@ -3297,7 +3297,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
|
||||
| ins_next2
|
||||
|2:
|
||||
| checktab TMP0; bne ->vmeta_len
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
| lwz TAB:TMP2, TAB:CARG1->metatable
|
||||
| cmplwi TAB:TMP2, 0
|
||||
| bne >9
|
||||
@ -3307,7 +3307,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
|
||||
| bl extern lj_tab_len // (GCtab *t)
|
||||
| // Returns uint32_t (but less than 2^31).
|
||||
| b <1
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
|9:
|
||||
| lbz TMP0, TAB:TMP2->nomm
|
||||
| andix. TMP0, TMP0, 1<<MM_len
|
||||
|
@ -811,7 +811,7 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
| b ->vm_call_dispatch
|
||||
|
|
||||
|->vmeta_len:
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
| mr SAVE0, CARG1
|
||||
#endif
|
||||
| add CARG2, BASE, RD
|
||||
@ -820,7 +820,7 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
| stw PC, SAVE_PC
|
||||
| bl extern lj_meta_len // (lua_State *L, TValue *o)
|
||||
| // Returns NULL (retry) or TValue * (metamethod base).
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
| cmplwi CRET1, 0
|
||||
| bne ->vmeta_binop // Binop call for compatibility.
|
||||
| mr CARG1, SAVE0
|
||||
@ -1103,7 +1103,7 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
| checktab TAB:CARG1
|
||||
| lwz PC, FRAME_PC(BASE)
|
||||
| checkfail ->fff_fallback
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
| lwz TAB:TMP2, TAB:CARG1->metatable
|
||||
| evldd CFUNC:TMP0, CFUNC:RB->upvalue[0]
|
||||
| cmplwi TAB:TMP2, 0
|
||||
@ -1162,7 +1162,7 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
| checktab TAB:CARG1
|
||||
| lwz PC, FRAME_PC(BASE)
|
||||
| checkfail ->fff_fallback
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
| lwz TAB:TMP2, TAB:CARG1->metatable
|
||||
| evldd CFUNC:TMP0, CFUNC:RB->upvalue[0]
|
||||
| cmplwi TAB:TMP2, 0
|
||||
@ -2327,7 +2327,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
|
||||
|2:
|
||||
| checktab CARG1
|
||||
| checkfail ->vmeta_len
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
| lwz TAB:TMP2, TAB:CARG1->metatable
|
||||
| cmplwi TAB:TMP2, 0
|
||||
| bne >9
|
||||
@ -2337,7 +2337,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
|
||||
| bl extern lj_tab_len // (GCtab *t)
|
||||
| // Returns uint32_t (but less than 2^31).
|
||||
| b <1
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
|9:
|
||||
| lbz TMP0, TAB:TMP2->nomm
|
||||
| andi. TMP0, TMP0, 1<<MM_len
|
||||
|
@ -1184,7 +1184,7 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
| call extern lj_meta_len@8 // (lua_State *L, TValue *o)
|
||||
| // NULL (retry) or TValue * (metamethod) returned in eax (RC).
|
||||
| mov BASE, L:RB->base
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
| test RC, RC
|
||||
| jne ->vmeta_binop // Binop call for compatibility.
|
||||
| movzx RD, PC_RD
|
||||
@ -1600,7 +1600,7 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
|.ffunc_1 pairs
|
||||
| mov TAB:RB, [BASE]
|
||||
| cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
| cmp dword TAB:RB->metatable, 0; jne ->fff_fallback
|
||||
#endif
|
||||
| mov CFUNC:RB, [BASE-8]
|
||||
@ -1674,7 +1674,7 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
|.ffunc_1 ipairs
|
||||
| mov TAB:RB, [BASE]
|
||||
| cmp dword [BASE+4], LJ_TTAB; jne ->fff_fallback
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
| cmp dword TAB:RB->metatable, 0; jne ->fff_fallback
|
||||
#endif
|
||||
| mov CFUNC:RB, [BASE-8]
|
||||
@ -4315,7 +4315,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
|
||||
|2:
|
||||
| checktab RD, ->vmeta_len
|
||||
| mov TAB:FCARG1, [BASE+RD*8]
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
| mov TAB:RB, TAB:FCARG1->metatable
|
||||
| cmp TAB:RB, 0
|
||||
| jnz >9
|
||||
@ -4336,7 +4336,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
|
||||
| mov BASE, RB // Restore BASE.
|
||||
| movzx RA, PC_RA
|
||||
| jmp <1
|
||||
#ifdef LUAJIT_ENABLE_LUA52COMPAT
|
||||
#if LJ_52
|
||||
|9: // Check for __len.
|
||||
| test byte TAB:RB->nomm, 1<<MM_len
|
||||
| jnz <3
|
||||
|
Loading…
Reference in New Issue
Block a user