diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-02-22 14:28:10 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-02-22 14:28:10 -0300 |
commit | 477ca2fe8ceaf79038972977915987adbef0e425 (patch) | |
tree | 6f682521c161dc6511ea257156c06ecac8a13db6 /lobject.h | |
parent | c72ac048b989bea0f66f8532ab00a598da71e46d (diff) | |
download | lua-477ca2fe8ceaf79038972977915987adbef0e425.tar.gz lua-477ca2fe8ceaf79038972977915987adbef0e425.tar.bz2 lua-477ca2fe8ceaf79038972977915987adbef0e425.zip |
some reorganization in 'lobject.h'
(just moving stuff around)
Diffstat (limited to 'lobject.h')
-rw-r--r-- | lobject.h | 405 |
1 files changed, 218 insertions, 187 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.h,v 2.134 2018/02/20 16:52:50 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 2.135 2018/02/21 16:28:12 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 | */ |
@@ -36,63 +36,12 @@ | |||
36 | */ | 36 | */ |
37 | 37 | ||
38 | 38 | ||
39 | /* | ||
40 | ** LUA_TFUNCTION variants: | ||
41 | ** 0 - Lua function | ||
42 | ** 1 - light C function | ||
43 | ** 2 - regular C function (closure) | ||
44 | */ | ||
45 | |||
46 | /* Variant tags for functions */ | ||
47 | #define LUA_TLCL (LUA_TFUNCTION | (0 << 4)) /* Lua closure */ | ||
48 | #define LUA_TLCF (LUA_TFUNCTION | (1 << 4)) /* light C function */ | ||
49 | #define LUA_TCCL (LUA_TFUNCTION | (2 << 4)) /* C closure */ | ||
50 | |||
51 | |||
52 | /* Variant tags for strings */ | ||
53 | #define LUA_TSHRSTR (LUA_TSTRING | (0 << 4)) /* short strings */ | ||
54 | #define LUA_TLNGSTR (LUA_TSTRING | (1 << 4)) /* long strings */ | ||
55 | |||
56 | |||
57 | /* Variant tags for numbers */ | ||
58 | #define LUA_TNUMFLT (LUA_TNUMBER | (0 << 4)) /* float numbers */ | ||
59 | #define LUA_TNUMINT (LUA_TNUMBER | (1 << 4)) /* integer numbers */ | ||
60 | |||
61 | |||
62 | /* Bit mark for collectable types */ | ||
63 | #define BIT_ISCOLLECTABLE (1 << 6) | ||
64 | |||
65 | /* mark a tag as collectable */ | ||
66 | #define ctb(t) ((t) | BIT_ISCOLLECTABLE) | ||
67 | |||
68 | |||
69 | /* | ||
70 | ** Common type for all collectable objects | ||
71 | */ | ||
72 | typedef struct GCObject GCObject; | ||
73 | |||
74 | |||
75 | /* | ||
76 | ** Common Header for all collectable objects (in macro form, to be | ||
77 | ** included in other objects) | ||
78 | */ | ||
79 | #define CommonHeader GCObject *next; lu_byte tt; lu_byte marked | ||
80 | |||
81 | |||
82 | /* | ||
83 | ** Common type has only the common header | ||
84 | */ | ||
85 | struct GCObject { | ||
86 | CommonHeader; | ||
87 | }; | ||
88 | |||
89 | |||
90 | 39 | ||
91 | /* | 40 | /* |
92 | ** Union of all Lua values | 41 | ** Union of all Lua values |
93 | */ | 42 | */ |
94 | typedef union Value { | 43 | typedef union Value { |
95 | GCObject *gc; /* collectable objects */ | 44 | struct GCObject *gc; /* collectable objects */ |
96 | void *p; /* light userdata */ | 45 | void *p; /* light userdata */ |
97 | int b; /* booleans */ | 46 | int b; /* booleans */ |
98 | lua_CFunction f; /* light C functions */ | 47 | lua_CFunction f; /* light C functions */ |
@@ -113,11 +62,6 @@ typedef struct TValue { | |||
113 | } TValue; | 62 | } TValue; |
114 | 63 | ||
115 | 64 | ||
116 | |||
117 | /* macro defining a nil value */ | ||
118 | #define NILCONSTANT {NULL}, LUA_TNIL | ||
119 | |||
120 | |||
121 | #define val_(o) ((o)->value_) | 65 | #define val_(o) ((o)->value_) |
122 | #define valraw(o) (&val_(o)) | 66 | #define valraw(o) (&val_(o)) |
123 | 67 | ||
@@ -139,176 +83,187 @@ typedef struct TValue { | |||
139 | /* Macros to test type */ | 83 | /* Macros to test type */ |
140 | #define checktag(o,t) (rttype(o) == (t)) | 84 | #define checktag(o,t) (rttype(o) == (t)) |
141 | #define checktype(o,t) (ttnov(o) == (t)) | 85 | #define checktype(o,t) (ttnov(o) == (t)) |
142 | #define ttisnumber(o) checktype((o), LUA_TNUMBER) | ||
143 | #define ttisfloat(o) checktag((o), LUA_TNUMFLT) | ||
144 | #define ttisinteger(o) checktag((o), LUA_TNUMINT) | ||
145 | #define ttisnil(o) checktag((o), LUA_TNIL) | ||
146 | #define ttisboolean(o) checktag((o), LUA_TBOOLEAN) | ||
147 | #define ttislightuserdata(o) checktag((o), LUA_TLIGHTUSERDATA) | ||
148 | #define ttisstring(o) checktype((o), LUA_TSTRING) | ||
149 | #define ttisshrstring(o) checktag((o), ctb(LUA_TSHRSTR)) | ||
150 | #define ttislngstring(o) checktag((o), ctb(LUA_TLNGSTR)) | ||
151 | #define ttistable(o) checktag((o), ctb(LUA_TTABLE)) | ||
152 | #define ttisfunction(o) checktype(o, LUA_TFUNCTION) | ||
153 | #define ttisclosure(o) ((rttype(o) & 0x1F) == LUA_TFUNCTION) | ||
154 | #define ttisCclosure(o) checktag((o), ctb(LUA_TCCL)) | ||
155 | #define ttisLclosure(o) checktag((o), ctb(LUA_TLCL)) | ||
156 | #define ttislcf(o) checktag((o), LUA_TLCF) | ||
157 | #define ttisfulluserdata(o) checktag((o), ctb(LUA_TUSERDATA)) | ||
158 | #define ttisthread(o) checktag((o), ctb(LUA_TTHREAD)) | ||
159 | 86 | ||
160 | 87 | ||
88 | /* Macros for internal tests */ | ||
89 | #define righttt(obj) (ttype(obj) == gcvalue(obj)->tt) | ||
90 | |||
91 | #define checkliveness(L,obj) \ | ||
92 | lua_longassert(!iscollectable(obj) || \ | ||
93 | (righttt(obj) && (L == NULL || !isdead(G(L),gcvalue(obj))))) | ||
94 | |||
95 | |||
96 | /* Macros to set values */ | ||
97 | #define settt_(o,t) ((o)->tt_=(t)) | ||
98 | |||
99 | |||
100 | #define setobj(L,obj1,obj2) \ | ||
101 | { TValue *io1=(obj1); const TValue *io2=(obj2); \ | ||
102 | io1->value_ = io2->value_; io1->tt_ = io2->tt_; \ | ||
103 | (void)L; checkliveness(L,io1); } | ||
104 | |||
161 | /* | 105 | /* |
162 | ** Macros to access unstructured values (may come both from | 106 | ** different types of assignments, according to destination |
163 | ** 'TValue's and table keys) | ||
164 | */ | 107 | */ |
165 | #define ivalueraw(v) ((v).i) | 108 | |
166 | #define fltvalueraw(v) ((v).n) | 109 | /* from stack to stack */ |
167 | #define gcvalueraw(v) ((v).gc) | 110 | #define setobjs2s(L,o1,o2) setobj(L,s2v(o1),s2v(o2)) |
168 | #define pvalueraw(v) ((v).p) | 111 | /* to stack (not from same stack) */ |
169 | #define tsvalueraw(v) (gco2ts((v).gc)) | 112 | #define setobj2s(L,o1,o2) setobj(L,s2v(o1),o2) |
170 | #define fvalueraw(v) ((v).f) | 113 | /* from table to same table */ |
171 | #define bvalueraw(v) ((v).b) | 114 | #define setobjt2t setobj |
115 | /* to new object */ | ||
116 | #define setobj2n setobj | ||
117 | /* to table */ | ||
118 | #define setobj2t setobj | ||
172 | 119 | ||
173 | 120 | ||
174 | /* Macros to access values */ | ||
175 | #define ivalue(o) check_exp(ttisinteger(o), val_(o).i) | ||
176 | #define fltvalue(o) check_exp(ttisfloat(o), val_(o).n) | ||
177 | #define nvalue(o) check_exp(ttisnumber(o), \ | ||
178 | (ttisinteger(o) ? cast_num(ivalue(o)) : fltvalue(o))) | ||
179 | #define gcvalue(o) check_exp(iscollectable(o), val_(o).gc) | ||
180 | #define pvalue(o) check_exp(ttislightuserdata(o), val_(o).p) | ||
181 | #define tsvalue(o) check_exp(ttisstring(o), gco2ts(val_(o).gc)) | ||
182 | #define uvalue(o) check_exp(ttisfulluserdata(o), gco2u(val_(o).gc)) | ||
183 | #define clvalue(o) check_exp(ttisclosure(o), gco2cl(val_(o).gc)) | ||
184 | #define clLvalue(o) check_exp(ttisLclosure(o), gco2lcl(val_(o).gc)) | ||
185 | #define clCvalue(o) check_exp(ttisCclosure(o), gco2ccl(val_(o).gc)) | ||
186 | #define fvalue(o) check_exp(ttislcf(o), val_(o).f) | ||
187 | #define hvalue(o) check_exp(ttistable(o), gco2t(val_(o).gc)) | ||
188 | #define bvalue(o) check_exp(ttisboolean(o), val_(o).b) | ||
189 | #define thvalue(o) check_exp(ttisthread(o), gco2th(val_(o).gc)) | ||
190 | 121 | ||
191 | #define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0)) | 122 | typedef union StackValue { |
123 | TValue val; | ||
124 | } StackValue; | ||
192 | 125 | ||
193 | 126 | ||
194 | #define iscollectable(o) (rttype(o) & BIT_ISCOLLECTABLE) | 127 | typedef StackValue *StkId; /* index to stack elements */ |
128 | |||
129 | /* convert a 'StackValue' to a 'TValue' */ | ||
130 | #define s2v(o) (&(o)->val) | ||
131 | |||
195 | 132 | ||
196 | 133 | ||
197 | /* | 134 | /* |
198 | ** Protected access to objects in values | 135 | ** {================================================================== |
136 | ** Nil | ||
137 | ** =================================================================== | ||
199 | */ | 138 | */ |
200 | #define gcvalueN(o) (iscollectable(o) ? gcvalue(o) : NULL) | ||
201 | 139 | ||
140 | #define ttisnil(o) checktag((o), LUA_TNIL) | ||
202 | 141 | ||
203 | /* Macros for internal tests */ | 142 | /* macro defining a nil value */ |
204 | #define righttt(obj) (ttype(obj) == gcvalue(obj)->tt) | 143 | #define NILCONSTANT {NULL}, LUA_TNIL |
205 | 144 | ||
206 | #define checkliveness(L,obj) \ | 145 | #define setnilvalue(obj) settt_(obj, LUA_TNIL) |
207 | lua_longassert(!iscollectable(obj) || \ | ||
208 | (righttt(obj) && (L == NULL || !isdead(G(L),gcvalue(obj))))) | ||
209 | 146 | ||
210 | 147 | ||
211 | /* Macros to set values */ | 148 | /* (address of) a fixed nil value */ |
212 | #define settt_(o,t) ((o)->tt_=(t)) | 149 | #define luaO_nilobject (&luaO_nilobject_) |
213 | 150 | ||
214 | #define setfltvalue(obj,x) \ | 151 | /* }================================================================== */ |
215 | { TValue *io=(obj); val_(io).n=(x); settt_(io, LUA_TNUMFLT); } | ||
216 | 152 | ||
217 | #define chgfltvalue(obj,x) \ | ||
218 | { TValue *io=(obj); lua_assert(ttisfloat(io)); val_(io).n=(x); } | ||
219 | 153 | ||
220 | #define setivalue(obj,x) \ | 154 | /* |
221 | { TValue *io=(obj); val_(io).i=(x); settt_(io, LUA_TNUMINT); } | 155 | ** {================================================================== |
156 | ** Booleans | ||
157 | ** =================================================================== | ||
158 | */ | ||
222 | 159 | ||
223 | #define chgivalue(obj,x) \ | 160 | #define ttisboolean(o) checktag((o), LUA_TBOOLEAN) |
224 | { TValue *io=(obj); lua_assert(ttisinteger(io)); val_(io).i=(x); } | ||
225 | 161 | ||
226 | #define setnilvalue(obj) settt_(obj, LUA_TNIL) | 162 | #define bvalue(o) check_exp(ttisboolean(o), val_(o).b) |
227 | 163 | ||
228 | #define setfvalue(obj,x) \ | 164 | #define bvalueraw(v) ((v).b) |
229 | { TValue *io=(obj); val_(io).f=(x); settt_(io, LUA_TLCF); } | ||
230 | 165 | ||
231 | #define setpvalue(obj,x) \ | 166 | #define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0)) |
232 | { TValue *io=(obj); val_(io).p=(x); settt_(io, LUA_TLIGHTUSERDATA); } | ||
233 | 167 | ||
234 | #define setbvalue(obj,x) \ | 168 | #define setbvalue(obj,x) \ |
235 | { TValue *io=(obj); val_(io).b=(x); settt_(io, LUA_TBOOLEAN); } | 169 | { TValue *io=(obj); val_(io).b=(x); settt_(io, LUA_TBOOLEAN); } |
236 | 170 | ||
237 | #define setgcovalue(L,obj,x) \ | 171 | /* }================================================================== */ |
238 | { TValue *io = (obj); GCObject *i_g=(x); \ | ||
239 | val_(io).gc = i_g; settt_(io, ctb(i_g->tt)); } | ||
240 | 172 | ||
241 | #define setsvalue(L,obj,x) \ | ||
242 | { TValue *io = (obj); TString *x_ = (x); \ | ||
243 | val_(io).gc = obj2gco(x_); settt_(io, ctb(x_->tt)); \ | ||
244 | checkliveness(L,io); } | ||
245 | 173 | ||
246 | #define setuvalue(L,obj,x) \ | 174 | /* |
247 | { TValue *io = (obj); Udata *x_ = (x); \ | 175 | ** {================================================================== |
248 | val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TUSERDATA)); \ | 176 | ** Threads |
249 | checkliveness(L,io); } | 177 | ** =================================================================== |
178 | */ | ||
179 | |||
180 | #define ttisthread(o) checktag((o), ctb(LUA_TTHREAD)) | ||
181 | |||
182 | #define thvalue(o) check_exp(ttisthread(o), gco2th(val_(o).gc)) | ||
250 | 183 | ||
251 | #define setthvalue(L,obj,x) \ | 184 | #define setthvalue(L,obj,x) \ |
252 | { TValue *io = (obj); lua_State *x_ = (x); \ | 185 | { TValue *io = (obj); lua_State *x_ = (x); \ |
253 | val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TTHREAD)); \ | 186 | val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TTHREAD)); \ |
254 | checkliveness(L,io); } | 187 | checkliveness(L,io); } |
255 | 188 | ||
256 | #define setclLvalue(L,obj,x) \ | 189 | #define setthvalue2s(L,o,t) setthvalue(L,s2v(o),t) |
257 | { TValue *io = (obj); LClosure *x_ = (x); \ | ||
258 | val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TLCL)); \ | ||
259 | checkliveness(L,io); } | ||
260 | 190 | ||
261 | #define setclCvalue(L,obj,x) \ | 191 | /* }================================================================== */ |
262 | { TValue *io = (obj); CClosure *x_ = (x); \ | ||
263 | val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TCCL)); \ | ||
264 | checkliveness(L,io); } | ||
265 | 192 | ||
266 | #define sethvalue(L,obj,x) \ | ||
267 | { TValue *io = (obj); Table *x_ = (x); \ | ||
268 | val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TTABLE)); \ | ||
269 | checkliveness(L,io); } | ||
270 | 193 | ||
194 | /* | ||
195 | ** {================================================================== | ||
196 | ** Collectable Objects | ||
197 | ** =================================================================== | ||
198 | */ | ||
199 | |||
200 | /* | ||
201 | ** Common Header for all collectable objects (in macro form, to be | ||
202 | ** included in other objects) | ||
203 | */ | ||
204 | #define CommonHeader struct GCObject *next; lu_byte tt; lu_byte marked | ||
271 | 205 | ||
272 | 206 | ||
273 | #define setobj(L,obj1,obj2) \ | 207 | /* Common type for all collectable objects */ |
274 | { TValue *io1=(obj1); const TValue *io2=(obj2); \ | 208 | typedef struct GCObject { |
275 | io1->value_ = io2->value_; io1->tt_ = io2->tt_; \ | 209 | CommonHeader; |
276 | (void)L; checkliveness(L,io1); } | 210 | } GCObject; |
211 | |||
212 | |||
213 | /* Bit mark for collectable types */ | ||
214 | #define BIT_ISCOLLECTABLE (1 << 6) | ||
215 | |||
216 | #define iscollectable(o) (rttype(o) & BIT_ISCOLLECTABLE) | ||
217 | |||
218 | /* mark a tag as collectable */ | ||
219 | #define ctb(t) ((t) | BIT_ISCOLLECTABLE) | ||
220 | |||
221 | #define gcvalue(o) check_exp(iscollectable(o), val_(o).gc) | ||
222 | |||
223 | #define gcvalueraw(v) ((v).gc) | ||
224 | |||
225 | #define setgcovalue(L,obj,x) \ | ||
226 | { TValue *io = (obj); GCObject *i_g=(x); \ | ||
227 | val_(io).gc = i_g; settt_(io, ctb(i_g->tt)); } | ||
228 | |||
229 | /* }================================================================== */ | ||
277 | 230 | ||
278 | 231 | ||
279 | /* | 232 | /* |
280 | ** different types of assignments, according to destination | 233 | ** {================================================================== |
234 | ** Numbers | ||
235 | ** =================================================================== | ||
281 | */ | 236 | */ |
282 | 237 | ||
283 | /* from stack to stack */ | 238 | /* Variant tags for numbers */ |
284 | #define setobjs2s(L,o1,o2) setobj(L,s2v(o1),s2v(o2)) | 239 | #define LUA_TNUMFLT (LUA_TNUMBER | (0 << 4)) /* float numbers */ |
285 | /* to stack (not from same stack) */ | 240 | #define LUA_TNUMINT (LUA_TNUMBER | (1 << 4)) /* integer numbers */ |
286 | #define setobj2s(L,o1,o2) setobj(L,s2v(o1),o2) | ||
287 | #define setsvalue2s(L,o,s) setsvalue(L,s2v(o),s) | ||
288 | #define sethvalue2s(L,o,h) sethvalue(L,s2v(o),h) | ||
289 | #define setthvalue2s(L,o,t) setthvalue(L,s2v(o),t) | ||
290 | #define setptvalue2s(L,o,p) setptvalue(L,s2v(o),p) | ||
291 | #define setclLvalue2s(L,o,cl) setclLvalue(L,s2v(o),cl) | ||
292 | /* from table to same table */ | ||
293 | #define setobjt2t setobj | ||
294 | /* to new object */ | ||
295 | #define setobj2n setobj | ||
296 | #define setsvalue2n setsvalue | ||
297 | /* to table */ | ||
298 | #define setobj2t setobj | ||
299 | 241 | ||
242 | #define ttisnumber(o) checktype((o), LUA_TNUMBER) | ||
243 | #define ttisfloat(o) checktag((o), LUA_TNUMFLT) | ||
244 | #define ttisinteger(o) checktag((o), LUA_TNUMINT) | ||
300 | 245 | ||
246 | #define nvalue(o) check_exp(ttisnumber(o), \ | ||
247 | (ttisinteger(o) ? cast_num(ivalue(o)) : fltvalue(o))) | ||
248 | #define fltvalue(o) check_exp(ttisfloat(o), val_(o).n) | ||
249 | #define ivalue(o) check_exp(ttisinteger(o), val_(o).i) | ||
301 | 250 | ||
302 | typedef union StackValue { | 251 | #define fltvalueraw(v) ((v).n) |
303 | TValue val; | 252 | #define ivalueraw(v) ((v).i) |
304 | } StackValue; | ||
305 | 253 | ||
254 | #define setfltvalue(obj,x) \ | ||
255 | { TValue *io=(obj); val_(io).n=(x); settt_(io, LUA_TNUMFLT); } | ||
306 | 256 | ||
307 | typedef StackValue *StkId; /* index to stack elements */ | 257 | #define chgfltvalue(obj,x) \ |
258 | { TValue *io=(obj); lua_assert(ttisfloat(io)); val_(io).n=(x); } | ||
308 | 259 | ||
309 | /* convert a 'StackValue' to a 'TValue' */ | 260 | #define setivalue(obj,x) \ |
310 | #define s2v(o) (&(o)->val) | 261 | { TValue *io=(obj); val_(io).i=(x); settt_(io, LUA_TNUMINT); } |
262 | |||
263 | #define chgivalue(obj,x) \ | ||
264 | { TValue *io=(obj); lua_assert(ttisinteger(io)); val_(io).i=(x); } | ||
311 | 265 | ||
266 | /* }================================================================== */ | ||
312 | 267 | ||
313 | 268 | ||
314 | /* | 269 | /* |
@@ -317,6 +272,30 @@ typedef StackValue *StkId; /* index to stack elements */ | |||
317 | ** =================================================================== | 272 | ** =================================================================== |
318 | */ | 273 | */ |
319 | 274 | ||
275 | /* Variant tags for strings */ | ||
276 | #define LUA_TSHRSTR (LUA_TSTRING | (0 << 4)) /* short strings */ | ||
277 | #define LUA_TLNGSTR (LUA_TSTRING | (1 << 4)) /* long strings */ | ||
278 | |||
279 | #define ttisstring(o) checktype((o), LUA_TSTRING) | ||
280 | #define ttisshrstring(o) checktag((o), ctb(LUA_TSHRSTR)) | ||
281 | #define ttislngstring(o) checktag((o), ctb(LUA_TLNGSTR)) | ||
282 | |||
283 | #define tsvalueraw(v) (gco2ts((v).gc)) | ||
284 | |||
285 | #define tsvalue(o) check_exp(ttisstring(o), gco2ts(val_(o).gc)) | ||
286 | |||
287 | #define setsvalue(L,obj,x) \ | ||
288 | { TValue *io = (obj); TString *x_ = (x); \ | ||
289 | val_(io).gc = obj2gco(x_); settt_(io, ctb(x_->tt)); \ | ||
290 | checkliveness(L,io); } | ||
291 | |||
292 | /* set a string to the stack */ | ||
293 | #define setsvalue2s(L,o,s) setsvalue(L,s2v(o),s) | ||
294 | |||
295 | /* set a string to a new object */ | ||
296 | #define setsvalue2n setsvalue | ||
297 | |||
298 | |||
320 | /* | 299 | /* |
321 | ** Header for string value; string bytes follow the end of this structure | 300 | ** Header for string value; string bytes follow the end of this structure |
322 | ** (aligned according to 'UTString'; see next). | 301 | ** (aligned according to 'UTString'; see next). |
@@ -368,6 +347,23 @@ typedef union UTString { | |||
368 | ** =================================================================== | 347 | ** =================================================================== |
369 | */ | 348 | */ |
370 | 349 | ||
350 | #define ttislightuserdata(o) checktag((o), LUA_TLIGHTUSERDATA) | ||
351 | #define ttisfulluserdata(o) checktag((o), ctb(LUA_TUSERDATA)) | ||
352 | |||
353 | #define pvalue(o) check_exp(ttislightuserdata(o), val_(o).p) | ||
354 | #define uvalue(o) check_exp(ttisfulluserdata(o), gco2u(val_(o).gc)) | ||
355 | |||
356 | #define pvalueraw(v) ((v).p) | ||
357 | |||
358 | #define setpvalue(obj,x) \ | ||
359 | { TValue *io=(obj); val_(io).p=(x); settt_(io, LUA_TLIGHTUSERDATA); } | ||
360 | |||
361 | #define setuvalue(L,obj,x) \ | ||
362 | { TValue *io = (obj); Udata *x_ = (x); \ | ||
363 | val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TUSERDATA)); \ | ||
364 | checkliveness(L,io); } | ||
365 | |||
366 | |||
371 | /* Ensures that addresses after this type are always fully aligned. */ | 367 | /* Ensures that addresses after this type are always fully aligned. */ |
372 | typedef union UValue { | 368 | typedef union UValue { |
373 | TValue uv; | 369 | TValue uv; |
@@ -483,6 +479,42 @@ typedef struct Proto { | |||
483 | ** =================================================================== | 479 | ** =================================================================== |
484 | */ | 480 | */ |
485 | 481 | ||
482 | /* Variant tags for functions */ | ||
483 | #define LUA_TLCL (LUA_TFUNCTION | (0 << 4)) /* Lua closure */ | ||
484 | #define LUA_TLCF (LUA_TFUNCTION | (1 << 4)) /* light C function */ | ||
485 | #define LUA_TCCL (LUA_TFUNCTION | (2 << 4)) /* C closure */ | ||
486 | |||
487 | #define ttisfunction(o) checktype(o, LUA_TFUNCTION) | ||
488 | #define ttisclosure(o) ((rttype(o) & 0x1F) == LUA_TFUNCTION) | ||
489 | #define ttisLclosure(o) checktag((o), ctb(LUA_TLCL)) | ||
490 | #define ttislcf(o) checktag((o), LUA_TLCF) | ||
491 | #define ttisCclosure(o) checktag((o), ctb(LUA_TCCL)) | ||
492 | |||
493 | #define isLfunction(o) ttisLclosure(o) | ||
494 | |||
495 | #define clvalue(o) check_exp(ttisclosure(o), gco2cl(val_(o).gc)) | ||
496 | #define clLvalue(o) check_exp(ttisLclosure(o), gco2lcl(val_(o).gc)) | ||
497 | #define fvalue(o) check_exp(ttislcf(o), val_(o).f) | ||
498 | #define clCvalue(o) check_exp(ttisCclosure(o), gco2ccl(val_(o).gc)) | ||
499 | |||
500 | #define fvalueraw(v) ((v).f) | ||
501 | |||
502 | #define setclLvalue(L,obj,x) \ | ||
503 | { TValue *io = (obj); LClosure *x_ = (x); \ | ||
504 | val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TLCL)); \ | ||
505 | checkliveness(L,io); } | ||
506 | |||
507 | #define setclLvalue2s(L,o,cl) setclLvalue(L,s2v(o),cl) | ||
508 | |||
509 | #define setfvalue(obj,x) \ | ||
510 | { TValue *io=(obj); val_(io).f=(x); settt_(io, LUA_TLCF); } | ||
511 | |||
512 | #define setclCvalue(L,obj,x) \ | ||
513 | { TValue *io = (obj); CClosure *x_ = (x); \ | ||
514 | val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TCCL)); \ | ||
515 | checkliveness(L,io); } | ||
516 | |||
517 | |||
486 | /* | 518 | /* |
487 | ** Upvalues for Lua closures | 519 | ** Upvalues for Lua closures |
488 | */ | 520 | */ |
@@ -499,11 +531,6 @@ typedef struct UpVal { | |||
499 | } UpVal; | 531 | } UpVal; |
500 | 532 | ||
501 | 533 | ||
502 | |||
503 | /* | ||
504 | ** Closures | ||
505 | */ | ||
506 | |||
507 | #define ClosureHeader \ | 534 | #define ClosureHeader \ |
508 | CommonHeader; lu_byte nupvalues; GCObject *gclist | 535 | CommonHeader; lu_byte nupvalues; GCObject *gclist |
509 | 536 | ||
@@ -527,8 +554,6 @@ typedef union Closure { | |||
527 | } Closure; | 554 | } Closure; |
528 | 555 | ||
529 | 556 | ||
530 | #define isLfunction(o) ttisLclosure(o) | ||
531 | |||
532 | #define getproto(o) (clLvalue(o)->p) | 557 | #define getproto(o) (clLvalue(o)->p) |
533 | 558 | ||
534 | /* }================================================================== */ | 559 | /* }================================================================== */ |
@@ -540,6 +565,18 @@ typedef union Closure { | |||
540 | ** =================================================================== | 565 | ** =================================================================== |
541 | */ | 566 | */ |
542 | 567 | ||
568 | #define ttistable(o) checktag((o), ctb(LUA_TTABLE)) | ||
569 | |||
570 | #define hvalue(o) check_exp(ttistable(o), gco2t(val_(o).gc)) | ||
571 | |||
572 | #define sethvalue(L,obj,x) \ | ||
573 | { TValue *io = (obj); Table *x_ = (x); \ | ||
574 | val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TTABLE)); \ | ||
575 | checkliveness(L,io); } | ||
576 | |||
577 | #define sethvalue2s(L,o,h) sethvalue(L,s2v(o),h) | ||
578 | |||
579 | |||
543 | /* | 580 | /* |
544 | ** Nodes for Hash tables: A pack of two TValue's (key-value pairs) | 581 | ** Nodes for Hash tables: A pack of two TValue's (key-value pairs) |
545 | ** plus a 'next' field to link colliding entries. The distribution | 582 | ** plus a 'next' field to link colliding entries. The distribution |
@@ -629,12 +666,6 @@ typedef struct Table { | |||
629 | #define sizenode(t) (twoto((t)->lsizenode)) | 666 | #define sizenode(t) (twoto((t)->lsizenode)) |
630 | 667 | ||
631 | 668 | ||
632 | /* | ||
633 | ** (address of) a fixed nil value | ||
634 | */ | ||
635 | #define luaO_nilobject (&luaO_nilobject_) | ||
636 | |||
637 | |||
638 | LUAI_DDEC const TValue luaO_nilobject_; | 669 | LUAI_DDEC const TValue luaO_nilobject_; |
639 | 670 | ||
640 | /* size of buffer for 'luaO_utf8esc' function */ | 671 | /* size of buffer for 'luaO_utf8esc' function */ |