diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-04-25 13:07:52 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-04-25 13:07:52 -0300 |
| commit | 9600c60df3e5a971ca642734470901775ef67ff9 (patch) | |
| tree | e53e526676be089fde966143599f22c4a5e862fb | |
| parent | 32bf6c9b277d04a35591ca6420cf1518ebc1a7f3 (diff) | |
| download | lua-9600c60df3e5a971ca642734470901775ef67ff9.tar.gz lua-9600c60df3e5a971ca642734470901775ef67ff9.tar.bz2 lua-9600c60df3e5a971ca642734470901775ef67ff9.zip | |
functions 'get_equalTM' and 'call_orderTM' moved to other files
to make 'lvm.c' smaller
| -rw-r--r-- | ltm.c | 25 | ||||
| -rw-r--r-- | ltm.h | 7 | ||||
| -rw-r--r-- | lvm.c | 35 |
3 files changed, 36 insertions, 31 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltm.c,v 2.15 2013/04/12 19:07:09 roberto Exp roberto $ | 2 | ** $Id: ltm.c,v 2.16 2013/04/25 15:59:42 roberto Exp roberto $ |
| 3 | ** Tag methods | 3 | ** Tag methods |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -18,6 +18,7 @@ | |||
| 18 | #include "lstring.h" | 18 | #include "lstring.h" |
| 19 | #include "ltable.h" | 19 | #include "ltable.h" |
| 20 | #include "ltm.h" | 20 | #include "ltm.h" |
| 21 | #include "lvm.h" | ||
| 21 | 22 | ||
| 22 | 23 | ||
| 23 | static const char udatatypename[] = "userdata"; | 24 | static const char udatatypename[] = "userdata"; |
| @@ -104,3 +105,25 @@ int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2, | |||
| 104 | return 1; | 105 | return 1; |
| 105 | } | 106 | } |
| 106 | 107 | ||
| 108 | |||
| 109 | const TValue *luaT_getequalTM (lua_State *L, Table *mt1, Table *mt2) { | ||
| 110 | const TValue *tm1 = fasttm(L, mt1, TM_EQ); | ||
| 111 | const TValue *tm2; | ||
| 112 | if (tm1 == NULL) return NULL; /* no metamethod */ | ||
| 113 | if (mt1 == mt2) return tm1; /* same metatables => same metamethods */ | ||
| 114 | tm2 = fasttm(L, mt2, TM_EQ); | ||
| 115 | if (tm2 == NULL) return NULL; /* no metamethod */ | ||
| 116 | if (luaV_rawequalobj(tm1, tm2)) /* same metamethods? */ | ||
| 117 | return tm1; | ||
| 118 | return NULL; | ||
| 119 | } | ||
| 120 | |||
| 121 | |||
| 122 | int luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2, | ||
| 123 | TMS event) { | ||
| 124 | if (!luaT_callbinTM(L, p1, p2, L->top, event)) | ||
| 125 | return -1; /* no metamethod */ | ||
| 126 | else | ||
| 127 | return !l_isfalse(L->top); | ||
| 128 | } | ||
| 129 | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltm.h,v 2.12 2013/04/12 19:07:09 roberto Exp roberto $ | 2 | ** $Id: ltm.h,v 2.13 2013/04/25 15:59:42 roberto Exp roberto $ |
| 3 | ** Tag methods | 3 | ** Tag methods |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -58,5 +58,10 @@ LUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, | |||
| 58 | const TValue *p2, TValue *p3, int hasres); | 58 | const TValue *p2, TValue *p3, int hasres); |
| 59 | LUAI_FUNC int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2, | 59 | LUAI_FUNC int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2, |
| 60 | StkId res, TMS event); | 60 | StkId res, TMS event); |
| 61 | LUAI_FUNC const TValue *luaT_getequalTM (lua_State *L, Table *mt1, Table *mt2); | ||
| 62 | LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1, | ||
| 63 | const TValue *p2, TMS event); | ||
| 64 | |||
| 65 | |||
| 61 | 66 | ||
| 62 | #endif | 67 | #endif |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 2.158 2013/04/16 18:43:05 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.159 2013/04/25 15:59:42 roberto Exp roberto $ |
| 3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -126,29 +126,6 @@ void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) { | |||
| 126 | } | 126 | } |
| 127 | 127 | ||
| 128 | 128 | ||
| 129 | static const TValue *get_equalTM (lua_State *L, Table *mt1, Table *mt2, | ||
| 130 | TMS event) { | ||
| 131 | const TValue *tm1 = fasttm(L, mt1, event); | ||
| 132 | const TValue *tm2; | ||
| 133 | if (tm1 == NULL) return NULL; /* no metamethod */ | ||
| 134 | if (mt1 == mt2) return tm1; /* same metatables => same metamethods */ | ||
| 135 | tm2 = fasttm(L, mt2, event); | ||
| 136 | if (tm2 == NULL) return NULL; /* no metamethod */ | ||
| 137 | if (luaV_rawequalobj(tm1, tm2)) /* same metamethods? */ | ||
| 138 | return tm1; | ||
| 139 | return NULL; | ||
| 140 | } | ||
| 141 | |||
| 142 | |||
| 143 | static int call_orderTM (lua_State *L, const TValue *p1, const TValue *p2, | ||
| 144 | TMS event) { | ||
| 145 | if (!luaT_callbinTM(L, p1, p2, L->top, event)) | ||
| 146 | return -1; /* no metamethod */ | ||
| 147 | else | ||
| 148 | return !l_isfalse(L->top); | ||
| 149 | } | ||
| 150 | |||
| 151 | |||
| 152 | static int l_strcmp (const TString *ls, const TString *rs) { | 129 | static int l_strcmp (const TString *ls, const TString *rs) { |
| 153 | const char *l = getstr(ls); | 130 | const char *l = getstr(ls); |
| 154 | size_t ll = ls->tsv.len; | 131 | size_t ll = ls->tsv.len; |
| @@ -177,7 +154,7 @@ int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) { | |||
| 177 | return luai_numlt(L, nvalue(l), nvalue(r)); | 154 | return luai_numlt(L, nvalue(l), nvalue(r)); |
| 178 | else if (ttisstring(l) && ttisstring(r)) | 155 | else if (ttisstring(l) && ttisstring(r)) |
| 179 | return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0; | 156 | return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0; |
| 180 | else if ((res = call_orderTM(L, l, r, TM_LT)) < 0) | 157 | else if ((res = luaT_callorderTM(L, l, r, TM_LT)) < 0) |
| 181 | luaG_ordererror(L, l, r); | 158 | luaG_ordererror(L, l, r); |
| 182 | return res; | 159 | return res; |
| 183 | } | 160 | } |
| @@ -189,9 +166,9 @@ int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) { | |||
| 189 | return luai_numle(L, nvalue(l), nvalue(r)); | 166 | return luai_numle(L, nvalue(l), nvalue(r)); |
| 190 | else if (ttisstring(l) && ttisstring(r)) | 167 | else if (ttisstring(l) && ttisstring(r)) |
| 191 | return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0; | 168 | return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0; |
| 192 | else if ((res = call_orderTM(L, l, r, TM_LE)) >= 0) /* first try `le' */ | 169 | else if ((res = luaT_callorderTM(L, l, r, TM_LE)) >= 0) /* first try `le' */ |
| 193 | return res; | 170 | return res; |
| 194 | else if ((res = call_orderTM(L, r, l, TM_LT)) < 0) /* else try `lt' */ | 171 | else if ((res = luaT_callorderTM(L, r, l, TM_LT)) < 0) /* else try `lt' */ |
| 195 | luaG_ordererror(L, l, r); | 172 | luaG_ordererror(L, l, r); |
| 196 | return !res; | 173 | return !res; |
| 197 | } | 174 | } |
| @@ -221,13 +198,13 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { | |||
| 221 | case LUA_TUSERDATA: { | 198 | case LUA_TUSERDATA: { |
| 222 | if (uvalue(t1) == uvalue(t2)) return 1; | 199 | if (uvalue(t1) == uvalue(t2)) return 1; |
| 223 | else if (L == NULL) return 0; | 200 | else if (L == NULL) return 0; |
| 224 | tm = get_equalTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable, TM_EQ); | 201 | tm = luaT_getequalTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable); |
| 225 | break; /* will try TM */ | 202 | break; /* will try TM */ |
| 226 | } | 203 | } |
| 227 | case LUA_TTABLE: { | 204 | case LUA_TTABLE: { |
| 228 | if (hvalue(t1) == hvalue(t2)) return 1; | 205 | if (hvalue(t1) == hvalue(t2)) return 1; |
| 229 | else if (L == NULL) return 0; | 206 | else if (L == NULL) return 0; |
| 230 | tm = get_equalTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable, TM_EQ); | 207 | tm = luaT_getequalTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable); |
| 231 | break; /* will try TM */ | 208 | break; /* will try TM */ |
| 232 | } | 209 | } |
| 233 | default: | 210 | default: |
