Prechádzať zdrojové kódy

'isIT'/'isOT' turned from macros to functions

Roberto Ierusalimschy 1 rok pred
rodič
commit
6ac7219da3
6 zmenil súbory, kde vykonal 38 pridanie a 14 odobranie
  1. 3 1
      lcode.c
  2. 1 1
      ldebug.c
  3. 28 0
      lopcodes.c
  4. 3 9
      lopcodes.h
  5. 1 1
      ltable.c
  6. 2 2
      lvm.c

+ 3 - 1
lcode.c

@@ -1844,7 +1844,9 @@ void luaK_finish (FuncState *fs) {
   Proto *p = fs->f;
   for (i = 0; i < fs->pc; i++) {
     Instruction *pc = &p->code[i];
-    lua_assert(i == 0 || isOT(*(pc - 1)) == isIT(*pc));
+    /* avoid "not used" warnings when assert is off (for 'onelua.c') */
+    (void)luaP_isOT; (void)luaP_isIT;
+    lua_assert(i == 0 || luaP_isOT(*(pc - 1)) == luaP_isIT(*pc));
     switch (GET_OPCODE(*pc)) {
       case OP_RETURN0: case OP_RETURN1: {
         if (!(fs->needclose || (p->flag & PF_ISVARARG)))

+ 1 - 1
ldebug.c

@@ -939,7 +939,7 @@ int luaG_traceexec (lua_State *L, const Instruction *pc) {
     ci->callstatus &= ~CIST_HOOKYIELD;  /* erase mark */
     return 1;  /* do not call hook again (VM yielded, so it did not move) */
   }
-  if (!isIT(*(ci->u.l.savedpc - 1)))  /* top not being used? */
+  if (!luaP_isIT(*(ci->u.l.savedpc - 1)))  /* top not being used? */
     L->top.p = ci->top.p;  /* correct top */
   if (counthook)
     luaD_hook(L, LUA_HOOKCOUNT, -1, 0, 0);  /* call count hook */

+ 28 - 0
lopcodes.c

@@ -13,6 +13,10 @@
 #include "lopcodes.h"
 
 
+#define opmode(mm,ot,it,t,a,m)  \
+    (((mm) << 7) | ((ot) << 6) | ((it) << 5) | ((t) << 4) | ((a) << 3) | (m))
+
+
 /* ORDER OP */
 
 LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {
@@ -102,3 +106,27 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {
  ,opmode(0, 0, 0, 0, 0, iAx)		/* OP_EXTRAARG */
 };
 
+
+
+/*
+** Check whether instruction sets top for next instruction, that is,
+** it results in multiple values.
+*/
+int luaP_isOT (Instruction i) {
+  OpCode op = GET_OPCODE(i);
+  switch (op) {
+    case OP_TAILCALL: return 1;
+    default:
+      return testOTMode(op) && GETARG_C(i) == 0;
+  }
+}
+
+
+/*
+** Check whether instruction uses top from previous instruction, that is,
+** it accepts multiple results.
+*/
+int luaP_isIT (Instruction i) {
+  return testITMode(GET_OPCODE(i)) && GETARG_B(i) == 0;
+}
+

+ 3 - 9
lopcodes.h

@@ -8,6 +8,7 @@
 #define lopcodes_h
 
 #include "llimits.h"
+#include "lobject.h"
 
 
 /*===========================================================================
@@ -394,16 +395,9 @@ LUAI_DDEC(const lu_byte luaP_opmodes[NUM_OPCODES];)
 #define testOTMode(m)	(luaP_opmodes[m] & (1 << 6))
 #define testMMMode(m)	(luaP_opmodes[m] & (1 << 7))
 
-/* "out top" (set top for next instruction) */
-#define isOT(i)  \
-	((testOTMode(GET_OPCODE(i)) && GETARG_C(i) == 0) || \
-          GET_OPCODE(i) == OP_TAILCALL)
 
-/* "in top" (uses top from previous instruction) */
-#define isIT(i)		(testITMode(GET_OPCODE(i)) && GETARG_B(i) == 0)
-
-#define opmode(mm,ot,it,t,a,m)  \
-    (((mm) << 7) | ((ot) << 6) | ((it) << 5) | ((t) << 4) | ((a) << 3) | (m))
+LUAI_FUNC int luaP_isOT (Instruction i);
+LUAI_FUNC int luaP_isIT (Instruction i);
 
 
 #endif

+ 1 - 1
ltable.c

@@ -278,7 +278,7 @@ static int equalkey (const TValue *k1, const Node *n2, int deadok) {
 /*
 ** Returns the real size of the 'array' array
 */
-LUAI_FUNC unsigned int luaH_realasize (const Table *t) {
+unsigned int luaH_realasize (const Table *t) {
   if (limitequalsasize(t))
     return t->alimit;  /* this is the size */
   else {

+ 2 - 2
lvm.c

@@ -1180,8 +1180,8 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
     #endif
     lua_assert(base == ci->func.p + 1);
     lua_assert(base <= L->top.p && L->top.p <= L->stack_last.p);
-    /* invalidate top for instructions not expecting it */
-    lua_assert(isIT(i) || (cast_void(L->top.p = base), 1));
+    /* for tests, invalidate top for instructions not expecting it */
+    lua_assert(luaP_isIT(i) || (cast_void(L->top.p = base), 1));
     vmdispatch (GET_OPCODE(i)) {
       vmcase(OP_MOVE) {
         StkId ra = RA(i);