Ver código fonte

Use 0/1 macro for Lua 5.2 compatibility.

Mike Pall 13 anos atrás
pai
commit
23932a6c8b
13 arquivos alterados com 49 adições e 59 exclusões
  1. 3 7
      src/lib_base.c
  2. 1 1
      src/lib_table.c
  3. 7 0
      src/lj_arch.h
  4. 1 4
      src/lj_ffrecord.c
  5. 2 8
      src/lj_meta.c
  6. 1 1
      src/lj_obj.h
  7. 1 1
      src/lj_parse.c
  8. 3 7
      src/lj_record.c
  9. 7 7
      src/vm_arm.dasc
  10. 6 6
      src/vm_mips.dasc
  11. 6 6
      src/vm_ppc.dasc
  12. 6 6
      src/vm_ppcspe.dasc
  13. 5 5
      src/vm_x86.dasc

+ 3 - 7
src/lib_base.c

@@ -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;

+ 1 - 1
src/lib_table.c

@@ -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

+ 7 - 0
src/lj_arch.h

@@ -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

+ 1 - 4
src/lj_ffrecord.c

@@ -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]));

+ 2 - 8
src/lj_meta.c

@@ -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. */

+ 1 - 1
src/lj_obj.h

@@ -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(_)

+ 1 - 1
src/lj_parse.c

@@ -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;

+ 3 - 7
src/lj_record.c

@@ -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;

+ 7 - 7
src/vm_arm.dasc

@@ -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

+ 6 - 6
src/vm_mips.dasc

@@ -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

+ 6 - 6
src/vm_ppc.dasc

@@ -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

+ 6 - 6
src/vm_ppcspe.dasc

@@ -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

+ 5 - 5
src/vm_x86.dasc

@@ -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