diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-11-06 15:09:27 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-11-06 15:09:27 -0200 |
commit | 2583bac3d3dbbe8e5f532c93f33e2c9358b850c1 (patch) | |
tree | 9dcd67de02ce6e69ce94ad31cd16b09343858b8d | |
parent | 63a3b1a1eb2fe8aca8315e28ac2c6d150b1ee218 (diff) | |
download | lua-2583bac3d3dbbe8e5f532c93f33e2c9358b850c1.tar.gz lua-2583bac3d3dbbe8e5f532c93f33e2c9358b850c1.tar.bz2 lua-2583bac3d3dbbe8e5f532c93f33e2c9358b850c1.zip |
several small changes to simplify changing TValue if needed
-rw-r--r-- | lobject.h | 36 |
1 files changed, 17 insertions, 19 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.h,v 2.30 2009/09/30 15:38:37 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 2.31 2009/11/05 17:43:54 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 | */ |
@@ -75,6 +75,10 @@ typedef struct lua_TValue { | |||
75 | } TValue; | 75 | } TValue; |
76 | 76 | ||
77 | 77 | ||
78 | /* macro defining a nil value to be used in definitions */ | ||
79 | #define NILCONSTANT {NULL}, LUA_TNIL | ||
80 | |||
81 | |||
78 | /* Macros to test type */ | 82 | /* Macros to test type */ |
79 | #define ttisnil(o) (ttype(o) == LUA_TNIL) | 83 | #define ttisnil(o) (ttype(o) == LUA_TNIL) |
80 | #define ttisnumber(o) (ttype(o) == LUA_TNUMBER) | 84 | #define ttisnumber(o) (ttype(o) == LUA_TNUMBER) |
@@ -85,6 +89,7 @@ typedef struct lua_TValue { | |||
85 | #define ttisuserdata(o) (ttype(o) == LUA_TUSERDATA) | 89 | #define ttisuserdata(o) (ttype(o) == LUA_TUSERDATA) |
86 | #define ttisthread(o) (ttype(o) == LUA_TTHREAD) | 90 | #define ttisthread(o) (ttype(o) == LUA_TTHREAD) |
87 | #define ttislightuserdata(o) (ttype(o) == LUA_TLIGHTUSERDATA) | 91 | #define ttislightuserdata(o) (ttype(o) == LUA_TLIGHTUSERDATA) |
92 | #define ttisdeadkey(o) (ttype(o) == LUA_TDEADKEY) | ||
88 | 93 | ||
89 | /* Macros to access values */ | 94 | /* Macros to access values */ |
90 | #define ttype(o) ((o)->tt_) | 95 | #define ttype(o) ((o)->tt_) |
@@ -105,12 +110,14 @@ typedef struct lua_TValue { | |||
105 | /* | 110 | /* |
106 | ** for internal debug only | 111 | ** for internal debug only |
107 | */ | 112 | */ |
108 | #define checkconsistency(obj) \ | 113 | #define iscollectable(o) (ttype(o) >= LUA_TSTRING) |
109 | lua_assert(!iscollectable(obj) || (ttype(obj) == (obj)->value_.gc->gch.tt)) | 114 | |
115 | #define righttt(obj) (ttype(obj) == gcvalue(obj)->gch.tt) | ||
116 | |||
117 | #define checkconsistency(obj) lua_assert(!iscollectable(obj) || righttt(obj)) | ||
110 | 118 | ||
111 | #define checkliveness(g,obj) \ | 119 | #define checkliveness(g,obj) \ |
112 | lua_assert(!iscollectable(obj) || \ | 120 | lua_assert(!iscollectable(obj) || (righttt(obj) && !isdead(g,gcvalue(obj)))) |
113 | ((ttype(obj) == (obj)->value_.gc->gch.tt) && !isdead(g, (obj)->value_.gc))) | ||
114 | 121 | ||
115 | 122 | ||
116 | /* Macros to set values */ | 123 | /* Macros to set values */ |
@@ -158,13 +165,12 @@ typedef struct lua_TValue { | |||
158 | i_o->value_.gc=cast(GCObject *, (x)); i_o->tt_=LUA_TPROTO; \ | 165 | i_o->value_.gc=cast(GCObject *, (x)); i_o->tt_=LUA_TPROTO; \ |
159 | checkliveness(G(L),i_o); } | 166 | checkliveness(G(L),i_o); } |
160 | 167 | ||
168 | #define setdeadvalue(obj) ((obj)->tt_=LUA_TDEADKEY) | ||
169 | |||
161 | 170 | ||
162 | 171 | ||
163 | 172 | ||
164 | #define setobj(L,obj1,obj2) \ | 173 | #define setobj(L,obj1,obj2) { *(obj1) = *(obj2); } |
165 | { const TValue *o2=(obj2); TValue *o1=(obj1); \ | ||
166 | o1->value_ = o2->value_; o1->tt_=o2->tt_; \ | ||
167 | checkliveness(G(L),o1); } | ||
168 | 174 | ||
169 | 175 | ||
170 | /* | 176 | /* |
@@ -186,11 +192,6 @@ typedef struct lua_TValue { | |||
186 | #define setobj2n setobj | 192 | #define setobj2n setobj |
187 | #define setsvalue2n setsvalue | 193 | #define setsvalue2n setsvalue |
188 | 194 | ||
189 | #define setttype(obj, tt_) (ttype(obj) = (tt_)) | ||
190 | |||
191 | |||
192 | #define iscollectable(o) (ttype(o) >= LUA_TSTRING) | ||
193 | |||
194 | 195 | ||
195 | 196 | ||
196 | typedef TValue *StkId; /* index to stack elements */ | 197 | typedef TValue *StkId; /* index to stack elements */ |
@@ -318,8 +319,8 @@ typedef union Closure { | |||
318 | } Closure; | 319 | } Closure; |
319 | 320 | ||
320 | 321 | ||
321 | #define iscfunction(o) (ttype(o) == LUA_TFUNCTION && clvalue(o)->c.isC) | 322 | #define iscfunction(o) (ttisfunction(o) && clvalue(o)->c.isC) |
322 | #define isLfunction(o) (ttype(o) == LUA_TFUNCTION && !clvalue(o)->c.isC) | 323 | #define isLfunction(o) (ttisfunction(o) && !clvalue(o)->c.isC) |
323 | 324 | ||
324 | #define getproto(o) (clvalue(o)->l.p) | 325 | #define getproto(o) (clvalue(o)->l.p) |
325 | 326 | ||
@@ -341,9 +342,6 @@ typedef struct Node { | |||
341 | TKey i_key; | 342 | TKey i_key; |
342 | } Node; | 343 | } Node; |
343 | 344 | ||
344 | #define setnodekey(nd,obj) { Node *n = (nd); const TValue *o = (obj); \ | ||
345 | n->i_key.nk.value_ = o->value_; n->i_key.nk.tt_ = o->tt_; } | ||
346 | |||
347 | 345 | ||
348 | typedef struct Table { | 346 | typedef struct Table { |
349 | CommonHeader; | 347 | CommonHeader; |