瀏覽代碼

functions 'get_equalTM' and 'call_orderTM' moved to other files
to make 'lvm.c' smaller

Roberto Ierusalimschy 12 年之前
父節點
當前提交
9600c60df3
共有 3 個文件被更改,包括 36 次插入31 次删除
  1. 24 1
      ltm.c
  2. 6 1
      ltm.h
  3. 6 29
      lvm.c

+ 24 - 1
ltm.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ltm.c,v 2.15 2013/04/12 19:07:09 roberto Exp roberto $
+** $Id: ltm.c,v 2.16 2013/04/25 15:59:42 roberto Exp roberto $
 ** Tag methods
 ** See Copyright Notice in lua.h
 */
@@ -18,6 +18,7 @@
 #include "lstring.h"
 #include "ltable.h"
 #include "ltm.h"
+#include "lvm.h"
 
 
 static const char udatatypename[] = "userdata";
@@ -104,3 +105,25 @@ int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2,
   return 1;
 }
 
+
+const TValue *luaT_getequalTM (lua_State *L, Table *mt1, Table *mt2) {
+  const TValue *tm1 = fasttm(L, mt1, TM_EQ);
+  const TValue *tm2;
+  if (tm1 == NULL) return NULL;  /* no metamethod */
+  if (mt1 == mt2) return tm1;  /* same metatables => same metamethods */
+  tm2 = fasttm(L, mt2, TM_EQ);
+  if (tm2 == NULL) return NULL;  /* no metamethod */
+  if (luaV_rawequalobj(tm1, tm2))  /* same metamethods? */
+    return tm1;
+  return NULL;
+}
+
+
+int luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2,
+                      TMS event) {
+  if (!luaT_callbinTM(L, p1, p2, L->top, event))
+    return -1;  /* no metamethod */
+  else
+    return !l_isfalse(L->top);
+}
+

+ 6 - 1
ltm.h

@@ -1,5 +1,5 @@
 /*
-** $Id: ltm.h,v 2.12 2013/04/12 19:07:09 roberto Exp roberto $
+** $Id: ltm.h,v 2.13 2013/04/25 15:59:42 roberto Exp roberto $
 ** Tag methods
 ** See Copyright Notice in lua.h
 */
@@ -58,5 +58,10 @@ LUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1,
                             const TValue *p2, TValue *p3, int hasres);
 LUAI_FUNC int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2,
                               StkId res, TMS event);
+LUAI_FUNC const TValue *luaT_getequalTM (lua_State *L, Table *mt1, Table *mt2);
+LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1,
+                                const TValue *p2, TMS event);
+
+
 
 #endif

+ 6 - 29
lvm.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lvm.c,v 2.158 2013/04/16 18:43:05 roberto Exp roberto $
+** $Id: lvm.c,v 2.159 2013/04/25 15:59:42 roberto Exp roberto $
 ** Lua virtual machine
 ** See Copyright Notice in lua.h
 */
@@ -126,29 +126,6 @@ void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) {
 }
 
 
-static const TValue *get_equalTM (lua_State *L, Table *mt1, Table *mt2,
-                                  TMS event) {
-  const TValue *tm1 = fasttm(L, mt1, event);
-  const TValue *tm2;
-  if (tm1 == NULL) return NULL;  /* no metamethod */
-  if (mt1 == mt2) return tm1;  /* same metatables => same metamethods */
-  tm2 = fasttm(L, mt2, event);
-  if (tm2 == NULL) return NULL;  /* no metamethod */
-  if (luaV_rawequalobj(tm1, tm2))  /* same metamethods? */
-    return tm1;
-  return NULL;
-}
-
-
-static int call_orderTM (lua_State *L, const TValue *p1, const TValue *p2,
-                         TMS event) {
-  if (!luaT_callbinTM(L, p1, p2, L->top, event))
-    return -1;  /* no metamethod */
-  else
-    return !l_isfalse(L->top);
-}
-
-
 static int l_strcmp (const TString *ls, const TString *rs) {
   const char *l = getstr(ls);
   size_t ll = ls->tsv.len;
@@ -177,7 +154,7 @@ int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) {
     return luai_numlt(L, nvalue(l), nvalue(r));
   else if (ttisstring(l) && ttisstring(r))
     return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0;
-  else if ((res = call_orderTM(L, l, r, TM_LT)) < 0)
+  else if ((res = luaT_callorderTM(L, l, r, TM_LT)) < 0)
     luaG_ordererror(L, l, r);
   return res;
 }
@@ -189,9 +166,9 @@ int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) {
     return luai_numle(L, nvalue(l), nvalue(r));
   else if (ttisstring(l) && ttisstring(r))
     return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0;
-  else if ((res = call_orderTM(L, l, r, TM_LE)) >= 0)  /* first try `le' */
+  else if ((res = luaT_callorderTM(L, l, r, TM_LE)) >= 0)  /* first try `le' */
     return res;
-  else if ((res = call_orderTM(L, r, l, TM_LT)) < 0)  /* else try `lt' */
+  else if ((res = luaT_callorderTM(L, r, l, TM_LT)) < 0)  /* else try `lt' */
     luaG_ordererror(L, l, r);
   return !res;
 }
@@ -221,13 +198,13 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) {
     case LUA_TUSERDATA: {
       if (uvalue(t1) == uvalue(t2)) return 1;
       else if (L == NULL) return 0;
-      tm = get_equalTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable, TM_EQ);
+      tm = luaT_getequalTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable);
       break;  /* will try TM */
     }
     case LUA_TTABLE: {
       if (hvalue(t1) == hvalue(t2)) return 1;
       else if (L == NULL) return 0;
-      tm = get_equalTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable, TM_EQ);
+      tm = luaT_getequalTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable);
       break;  /* will try TM */
     }
     default: