diff --git a/src/lobject.c b/src/lobject.c index 4ff5073..08515e9 100644 --- a/src/lobject.c +++ b/src/lobject.c @@ -24,7 +24,7 @@ -const TValue luaO_nilobject_ = {{NULL}, LUA_TNIL}; +const TValue luaO_nilobject_ = {LUA_TVALUE_NIL}; /* diff --git a/src/lobject.h b/src/lobject.h index f1e447e..bb88912 100644 --- a/src/lobject.h +++ b/src/lobject.h @@ -63,19 +63,44 @@ typedef union { int b; } Value; - /* ** Tagged Values */ +#if LUA_PACK_VALUE == 0 + #define TValuefields Value value; int tt +#define LUA_TVALUE_NIL {NULL}, LUA_TNIL typedef struct lua_TValue { TValuefields; } TValue; +#else + +#define TValuefields union { \ + struct { \ + int _pad0; \ + int tt_sig; \ + } _ts; \ + struct { \ + int _pad; \ + short tt; \ + short sig; \ + } _t; \ + Value value; \ +} +#define LUA_NOTNUMBER_SIG (-1) +#define add_sig(tt) ( 0xffff0000 | (tt) ) +#define LUA_TVALUE_NIL {0, add_sig(LUA_TNIL)} + +typedef TValuefields TValue; + +#endif /* Macros to test type */ +#if LUA_PACK_VALUE == 0 + #define ttisnil(o) (ttype(o) == LUA_TNIL) #define ttisnumber(o) (ttype(o) == LUA_TNUMBER) #define ttisstring(o) (ttype(o) == LUA_TSTRING) @@ -86,8 +111,28 @@ typedef struct lua_TValue { #define ttisthread(o) (ttype(o) == LUA_TTHREAD) #define ttislightuserdata(o) (ttype(o) == LUA_TLIGHTUSERDATA) +#else + +#define ttisnil(o) (ttype_sig(o) == add_sig(LUA_TNIL)) +#define ttisnumber(o) ((o)->_t.sig != LUA_NOTNUMBER_SIG) +#define ttisstring(o) (ttype_sig(o) == add_sig(LUA_TSTRING)) +#define ttistable(o) (ttype_sig(o) == add_sig(LUA_TTABLE)) +#define ttisfunction(o) (ttype_sig(o) == add_sig(LUA_TFUNCTION)) +#define ttisboolean(o) (ttype_sig(o) == add_sig(LUA_TBOOLEAN)) +#define ttisuserdata(o) (ttype_sig(o) == add_sig(LUA_TUSERDATA)) +#define ttisthread(o) (ttype_sig(o) == add_sig(LUA_TTHREAD)) +#define ttislightuserdata(o) (ttype_sig(o) == add_sig(LUA_TLIGHTUSERDATA)) + +#endif + + /* Macros to access values */ +#if LUA_PACK_VALUE == 0 #define ttype(o) ((o)->tt) +#else +#define ttype(o) ((o)->_t.sig == LUA_NOTNUMBER_SIG ? (o)->_t.tt : LUA_TNUMBER) +#define ttype_sig(o) ((o)->_ts.tt_sig) +#endif #define gcvalue(o) check_exp(iscollectable(o), (o)->value.gc) #define pvalue(o) check_exp(ttislightuserdata(o), (o)->value.p) #define nvalue(o) check_exp(ttisnumber(o), (o)->value.n) @@ -105,15 +150,25 @@ typedef struct lua_TValue { /* ** for internal debug only */ +#if LUA_PACK_VALUE == 0 #define checkconsistency(obj) \ lua_assert(!iscollectable(obj) || (ttype(obj) == (obj)->value.gc->gch.tt)) #define checkliveness(g,obj) \ lua_assert(!iscollectable(obj) || \ ((ttype(obj) == (obj)->value.gc->gch.tt) && !isdead(g, (obj)->value.gc))) +#else +#define checkconsistency(obj) \ + lua_assert(!iscollectable(obj) || (ttype(obj) == (obj)->value.gc->gch._t.tt)) +#define checkliveness(g,obj) \ + lua_assert(!iscollectable(obj) || \ + ((ttype(obj) == (obj)->value.gc->gch._t.tt) && !isdead(g, (obj)->value.gc))) +#endif /* Macros to set values */ +#if LUA_PACK_VALUE == 0 + #define setnilvalue(obj) ((obj)->tt=LUA_TNIL) #define setnvalue(obj,x) \ @@ -163,7 +218,58 @@ typedef struct lua_TValue { o1->value = o2->value; o1->tt=o2->tt; \ checkliveness(G(L),o1); } +#else /* LUA_PACK_VALUE != 0 */ + +#define setnilvalue(obj) ( ttype_sig(obj) = add_sig(LUA_TNIL) ) +#define setnvalue(obj,x) \ + { TValue *i_o=(obj); i_o->value.n=(x); } + +#define setpvalue(obj,x) \ + { TValue *i_o=(obj); i_o->value.p=(x); i_o->_ts.tt_sig=add_sig(LUA_TLIGHTUSERDATA);} + +#define setbvalue(obj,x) \ + { TValue *i_o=(obj); i_o->value.b=(x); i_o->_ts.tt_sig=add_sig(LUA_TBOOLEAN);} + +#define setsvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->_ts.tt_sig=add_sig(LUA_TSTRING); \ + checkliveness(G(L),i_o); } + +#define setuvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->_ts.tt_sig=add_sig(LUA_TUSERDATA); \ + checkliveness(G(L),i_o); } + +#define setthvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->_ts.tt_sig=add_sig(LUA_TTHREAD); \ + checkliveness(G(L),i_o); } + +#define setclvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->_ts.tt_sig=add_sig(LUA_TFUNCTION); \ + checkliveness(G(L),i_o); } + +#define sethvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->_ts.tt_sig=add_sig(LUA_TTABLE); \ + checkliveness(G(L),i_o); } + +#define setptvalue(L,obj,x) \ + { TValue *i_o=(obj); \ + i_o->value.gc=cast(GCObject *, (x)); i_o->_ts.tt_sig=add_sig(LUA_TPROTO); \ + checkliveness(G(L),i_o); } + + + + +#define setobj(L,obj1,obj2) \ + { const TValue *o2=(obj2); TValue *o1=(obj1); \ + o1->value = o2->value; \ + checkliveness(G(L),o1); } + +#endif /* ** different types of sets, according to destination */ @@ -183,8 +289,13 @@ typedef struct lua_TValue { #define setobj2n setobj #define setsvalue2n setsvalue +#if LUA_PACK_VALUE == 0 #define setttype(obj, tt) (ttype(obj) = (tt)) - +#else +/* considering it used only in lgc to set LUA_TDEADKEY */ +/* we could define it this way */ +#define setttype(obj, _tt) ( ttype_sig(obj) = add_sig(_tt) ) +#endif #define iscollectable(o) (ttype(o)>= LUA_TSTRING) @@ -320,6 +431,8 @@ typedef union Closure { ** Tables */ +#if LUA_PACK_VALUE == 0 + typedef union TKey { struct { TValuefields; @@ -328,6 +441,20 @@ typedef union TKey { TValue tvk; } TKey; +#define LUA_TKEY_NIL {LUA_TVALUE_NIL, NULL} + +#else + +typedef struct TKey { + TValue tvk; + struct { + struct Node *next; /* for chaining */ + } nk; +} TKey; + +#define LUA_TKEY_NIL {LUA_TVALUE_NIL}, {NULL} + +#endif typedef struct Node { TValue i_val; diff --git a/src/ltable.c b/src/ltable.c index ec84f4f..efc51da 100644 --- a/src/ltable.c +++ b/src/ltable.c @@ -73,8 +73,8 @@ #define dummynode (&dummynode_) static const Node dummynode_ = { - {{NULL}, LUA_TNIL}, /* value */ - {{{NULL}, LUA_TNIL, NULL}} /* key */ + {LUA_TVALUE_NIL}, /* value */ + {LUA_TKEY_NIL} /* key */ }; @@ -422,7 +422,7 @@ static TValue *newkey (lua_State *L, Table *t, const TValue *key) { mp = n; } } - gkey(mp)->value = key->value; gkey(mp)->tt = key->tt; + setobj2t(L, gkey(mp), key); luaC_barriert(L, t, key); lua_assert(ttisnil(gval(mp))); return gval(mp); diff --git a/src/ltable.h b/src/ltable.h index f5b9d5e..8d5a47f 100644 --- a/src/ltable.h +++ b/src/ltable.h @@ -11,7 +11,7 @@ #define gnode(t,i) (&(t)->node[i]) -#define gkey(n) (&(n)->i_key.nk) +#define gkey(n) (&(n)->i_key.tvk) #define gval(n) (&(n)->i_val) #define gnext(n) ((n)->i_key.nk.next) diff --git a/src/luaconf.h b/src/luaconf.h index e2cb261..7a67eac 100644 --- a/src/luaconf.h +++ b/src/luaconf.h @@ -582,6 +582,15 @@ union luai_Cast { double l_d; long l_l; }; #endif +#if !defined(LUA_PACK_VALUE) +/* on platform with lua number double we could use nan packing for value */ +#if (defined(__i386) || defined (_M_IX86) || defined(__i386__)) && defined(LUA_NUMBER_DOUBLE) +/* currently try it on known little endian platform :) */ +#define LUA_PACK_VALUE 1 +#else +#define LUA_PACK_VALUE 0 +#endif +#endif /* }================================================================== */

AltStyle によって変換されたページ (->オリジナル) /