diff options
| -rw-r--r-- | lapi.c | 4 | ||||
| -rw-r--r-- | lcode.c | 5 | ||||
| -rw-r--r-- | lobject.c | 24 | ||||
| -rw-r--r-- | lobject.h | 4 | ||||
| -rw-r--r-- | ltable.c | 7 | ||||
| -rw-r--r-- | lvm.c | 13 | ||||
| -rw-r--r-- | lvm.h | 6 |
7 files changed, 27 insertions, 36 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 2.144 2010/12/29 18:00:23 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.145 2011/04/05 14:26:23 roberto Exp roberto $ |
| 3 | ** Lua API | 3 | ** Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -278,7 +278,7 @@ LUA_API int lua_rawequal (lua_State *L, int index1, int index2) { | |||
| 278 | StkId o1 = index2addr(L, index1); | 278 | StkId o1 = index2addr(L, index1); |
| 279 | StkId o2 = index2addr(L, index2); | 279 | StkId o2 = index2addr(L, index2); |
| 280 | return (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 | 280 | return (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 |
| 281 | : luaO_rawequalObj(o1, o2); | 281 | : luaV_rawequalObj(o1, o2); |
| 282 | } | 282 | } |
| 283 | 283 | ||
| 284 | 284 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lcode.c,v 2.53 2011/04/19 16:22:13 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 2.54 2011/04/28 14:00:11 roberto Exp roberto $ |
| 3 | ** Code generator for Lua | 3 | ** Code generator for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -23,6 +23,7 @@ | |||
| 23 | #include "lparser.h" | 23 | #include "lparser.h" |
| 24 | #include "lstring.h" | 24 | #include "lstring.h" |
| 25 | #include "ltable.h" | 25 | #include "ltable.h" |
| 26 | #include "lvm.h" | ||
| 26 | 27 | ||
| 27 | 28 | ||
| 28 | #define hasjumps(e) ((e)->t != (e)->f) | 29 | #define hasjumps(e) ((e)->t != (e)->f) |
| @@ -295,7 +296,7 @@ static int addk (FuncState *fs, TValue *key, TValue *v) { | |||
| 295 | if (ttisnumber(idx)) { | 296 | if (ttisnumber(idx)) { |
| 296 | lua_Number n = nvalue(idx); | 297 | lua_Number n = nvalue(idx); |
| 297 | lua_number2int(k, n); | 298 | lua_number2int(k, n); |
| 298 | if (luaO_rawequalObj(&f->k[k], v)) | 299 | if (luaV_rawequalObj(&f->k[k], v)) |
| 299 | return k; | 300 | return k; |
| 300 | /* else may be a collision (e.g., between 0.0 and "\0\0\0\0\0\0\0\0"); | 301 | /* else may be a collision (e.g., between 0.0 and "\0\0\0\0\0\0\0\0"); |
| 301 | go through and create a new entry for this value */ | 302 | go through and create a new entry for this value */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.c,v 2.47 2011/04/05 18:32:06 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 2.48 2011/05/03 16:01:57 roberto Exp roberto $ |
| 3 | ** Some generic functions over Lua objects | 3 | ** Some generic functions over Lua objects |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -70,28 +70,6 @@ int luaO_ceillog2 (unsigned int x) { | |||
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | 72 | ||
| 73 | int luaO_rawequalObj (const TValue *t1, const TValue *t2) { | ||
| 74 | if (!ttisequal(t1, t2)) return 0; | ||
| 75 | else switch (ttype(t1)) { | ||
| 76 | case LUA_TNIL: | ||
| 77 | return 1; | ||
| 78 | case LUA_TNUMBER: | ||
| 79 | return luai_numeq(nvalue(t1), nvalue(t2)); | ||
| 80 | case LUA_TBOOLEAN: | ||
| 81 | return bvalue(t1) == bvalue(t2); /* boolean true must be 1 !! */ | ||
| 82 | case LUA_TLIGHTUSERDATA: | ||
| 83 | return pvalue(t1) == pvalue(t2); | ||
| 84 | case LUA_TSTRING: | ||
| 85 | return rawtsvalue(t1) == rawtsvalue(t2); | ||
| 86 | case LUA_TLCF: | ||
| 87 | return fvalue(t1) == fvalue(t2); | ||
| 88 | default: | ||
| 89 | lua_assert(iscollectable(t1)); | ||
| 90 | return gcvalue(t1) == gcvalue(t2); | ||
| 91 | } | ||
| 92 | } | ||
| 93 | |||
| 94 | |||
| 95 | lua_Number luaO_arith (int op, lua_Number v1, lua_Number v2) { | 73 | lua_Number luaO_arith (int op, lua_Number v1, lua_Number v2) { |
| 96 | switch (op) { | 74 | switch (op) { |
| 97 | case LUA_OPADD: return luai_numadd(NULL, v1, v2); | 75 | case LUA_OPADD: return luai_numadd(NULL, v1, v2); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.h,v 2.53 2011/05/05 19:43:14 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 2.54 2011/05/26 17:12:31 roberto Exp roberto $ |
| 3 | ** Type definitions for Lua objects | 3 | ** Type definitions for Lua objects |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -431,11 +431,11 @@ typedef struct Table { | |||
| 431 | 431 | ||
| 432 | LUAI_DDEC const TValue luaO_nilobject_; | 432 | LUAI_DDEC const TValue luaO_nilobject_; |
| 433 | 433 | ||
| 434 | |||
| 434 | LUAI_FUNC int luaO_int2fb (unsigned int x); | 435 | LUAI_FUNC int luaO_int2fb (unsigned int x); |
| 435 | LUAI_FUNC int luaO_fb2int (int x); | 436 | LUAI_FUNC int luaO_fb2int (int x); |
| 436 | LUAI_FUNC int luaO_ceillog2 (unsigned int x); | 437 | LUAI_FUNC int luaO_ceillog2 (unsigned int x); |
| 437 | LUAI_FUNC lua_Number luaO_arith (int op, lua_Number v1, lua_Number v2); | 438 | LUAI_FUNC lua_Number luaO_arith (int op, lua_Number v1, lua_Number v2); |
| 438 | LUAI_FUNC int luaO_rawequalObj (const TValue *t1, const TValue *t2); | ||
| 439 | LUAI_FUNC int luaO_str2d (const char *s, size_t len, lua_Number *result); | 439 | LUAI_FUNC int luaO_str2d (const char *s, size_t len, lua_Number *result); |
| 440 | LUAI_FUNC int luaO_hexavalue (int c); | 440 | LUAI_FUNC int luaO_hexavalue (int c); |
| 441 | LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt, | 441 | LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt, |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltable.c,v 2.54 2011/04/05 18:32:28 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 2.55 2011/05/02 16:45:32 roberto Exp roberto $ |
| 3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -33,6 +33,7 @@ | |||
| 33 | #include "lstate.h" | 33 | #include "lstate.h" |
| 34 | #include "lstring.h" | 34 | #include "lstring.h" |
| 35 | #include "ltable.h" | 35 | #include "ltable.h" |
| 36 | #include "lvm.h" | ||
| 36 | 37 | ||
| 37 | 38 | ||
| 38 | /* | 39 | /* |
| @@ -148,7 +149,7 @@ static int findindex (lua_State *L, Table *t, StkId key) { | |||
| 148 | Node *n = mainposition(t, key); | 149 | Node *n = mainposition(t, key); |
| 149 | do { /* check whether `key' is somewhere in the chain */ | 150 | do { /* check whether `key' is somewhere in the chain */ |
| 150 | /* key may be dead already, but it is ok to use it in `next' */ | 151 | /* key may be dead already, but it is ok to use it in `next' */ |
| 151 | if (luaO_rawequalObj(gkey(n), key) || | 152 | if (luaV_rawequalObj(gkey(n), key) || |
| 152 | (ttisdeadkey(gkey(n)) && iscollectable(key) && | 153 | (ttisdeadkey(gkey(n)) && iscollectable(key) && |
| 153 | gcvalue(gkey(n)) == gcvalue(key))) { | 154 | gcvalue(gkey(n)) == gcvalue(key))) { |
| 154 | i = cast_int(n - gnode(t, 0)); /* key index in hash table */ | 155 | i = cast_int(n - gnode(t, 0)); /* key index in hash table */ |
| @@ -481,7 +482,7 @@ const TValue *luaH_get (Table *t, const TValue *key) { | |||
| 481 | default: { | 482 | default: { |
| 482 | Node *n = mainposition(t, key); | 483 | Node *n = mainposition(t, key); |
| 483 | do { /* check whether `key' is somewhere in the chain */ | 484 | do { /* check whether `key' is somewhere in the chain */ |
| 484 | if (luaO_rawequalObj(gkey(n), key)) | 485 | if (luaV_rawequalObj(gkey(n), key)) |
| 485 | return gval(n); /* that's it */ | 486 | return gval(n); /* that's it */ |
| 486 | else n = gnext(n); | 487 | else n = gnext(n); |
| 487 | } while (n); | 488 | } while (n); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 2.136 2011/04/19 16:22:13 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.137 2011/05/05 16:16:33 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 | */ |
| @@ -174,7 +174,7 @@ static const TValue *get_equalTM (lua_State *L, Table *mt1, Table *mt2, | |||
| 174 | if (mt1 == mt2) return tm1; /* same metatables => same metamethods */ | 174 | if (mt1 == mt2) return tm1; /* same metatables => same metamethods */ |
| 175 | tm2 = fasttm(L, mt2, event); | 175 | tm2 = fasttm(L, mt2, event); |
| 176 | if (tm2 == NULL) return NULL; /* no metamethod */ | 176 | if (tm2 == NULL) return NULL; /* no metamethod */ |
| 177 | if (luaO_rawequalObj(tm1, tm2)) /* same metamethods? */ | 177 | if (luaV_rawequalObj(tm1, tm2)) /* same metamethods? */ |
| 178 | return tm1; | 178 | return tm1; |
| 179 | return NULL; | 179 | return NULL; |
| 180 | } | 180 | } |
| @@ -237,6 +237,9 @@ int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) { | |||
| 237 | } | 237 | } |
| 238 | 238 | ||
| 239 | 239 | ||
| 240 | /* | ||
| 241 | ** equality of Lua values. L == NULL means raw equality (no metamethods) | ||
| 242 | */ | ||
| 240 | int luaV_equalval_ (lua_State *L, const TValue *t1, const TValue *t2) { | 243 | int luaV_equalval_ (lua_State *L, const TValue *t1, const TValue *t2) { |
| 241 | const TValue *tm; | 244 | const TValue *tm; |
| 242 | lua_assert(ttisequal(t1, t2)); | 245 | lua_assert(ttisequal(t1, t2)); |
| @@ -249,15 +252,19 @@ int luaV_equalval_ (lua_State *L, const TValue *t1, const TValue *t2) { | |||
| 249 | case LUA_TSTRING: return eqstr(rawtsvalue(t1), rawtsvalue(t2)); | 252 | case LUA_TSTRING: return eqstr(rawtsvalue(t1), rawtsvalue(t2)); |
| 250 | case LUA_TUSERDATA: { | 253 | case LUA_TUSERDATA: { |
| 251 | if (uvalue(t1) == uvalue(t2)) return 1; | 254 | if (uvalue(t1) == uvalue(t2)) return 1; |
| 255 | else if (L == NULL) return 0; | ||
| 252 | tm = get_equalTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable, TM_EQ); | 256 | tm = get_equalTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable, TM_EQ); |
| 253 | break; /* will try TM */ | 257 | break; /* will try TM */ |
| 254 | } | 258 | } |
| 255 | case LUA_TTABLE: { | 259 | case LUA_TTABLE: { |
| 256 | if (hvalue(t1) == hvalue(t2)) return 1; | 260 | if (hvalue(t1) == hvalue(t2)) return 1; |
| 261 | else if (L == NULL) return 0; | ||
| 257 | tm = get_equalTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable, TM_EQ); | 262 | tm = get_equalTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable, TM_EQ); |
| 258 | break; /* will try TM */ | 263 | break; /* will try TM */ |
| 259 | } | 264 | } |
| 260 | default: return gcvalue(t1) == gcvalue(t2); | 265 | default: |
| 266 | lua_assert(iscollectable(t1)); | ||
| 267 | return gcvalue(t1) == gcvalue(t2); | ||
| 261 | } | 268 | } |
| 262 | if (tm == NULL) return 0; /* no TM? */ | 269 | if (tm == NULL) return 0; /* no TM? */ |
| 263 | callTM(L, tm, t1, t2, L->top, 1); /* call TM */ | 270 | callTM(L, tm, t1, t2, L->top, 1); /* call TM */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.h,v 2.14 2009/12/17 16:20:01 roberto Exp roberto $ | 2 | ** $Id: lvm.h,v 2.15 2011/04/05 18:32:06 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 | */ |
| @@ -19,10 +19,14 @@ | |||
| 19 | 19 | ||
| 20 | #define equalobj(L,o1,o2) (ttisequal(o1, o2) && luaV_equalval_(L, o1, o2)) | 20 | #define equalobj(L,o1,o2) (ttisequal(o1, o2) && luaV_equalval_(L, o1, o2)) |
| 21 | 21 | ||
| 22 | #define luaV_rawequalObj(t1,t2) \ | ||
| 23 | (ttisequal(t1,t2) && luaV_equalval_(NULL,t1,t2)) | ||
| 24 | |||
| 22 | 25 | ||
| 23 | /* not to called directly */ | 26 | /* not to called directly */ |
| 24 | LUAI_FUNC int luaV_equalval_ (lua_State *L, const TValue *t1, const TValue *t2); | 27 | LUAI_FUNC int luaV_equalval_ (lua_State *L, const TValue *t1, const TValue *t2); |
| 25 | 28 | ||
| 29 | |||
| 26 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); | 30 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); |
| 27 | LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r); | 31 | LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r); |
| 28 | LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n); | 32 | LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n); |
