diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-10-25 17:05:28 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-10-25 17:05:28 -0300 |
commit | 96e15b8501e5d8fc40c475cbac573f910ab5853b (patch) | |
tree | 2c8efededa6849704f0db3075d0cbe0efaa40b2d /lobject.h | |
parent | 0fd91b1b087b478fffa36f96bc0f608d86627a4b (diff) | |
download | lua-96e15b8501e5d8fc40c475cbac573f910ab5853b.tar.gz lua-96e15b8501e5d8fc40c475cbac573f910ab5853b.tar.bz2 lua-96e15b8501e5d8fc40c475cbac573f910ab5853b.zip |
threads now are real Lua objects, subject to garbage collection
Diffstat (limited to 'lobject.h')
-rw-r--r-- | lobject.h | 67 |
1 files changed, 29 insertions, 38 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.h,v 1.148 2002/10/16 20:40:58 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 1.149 2002/10/22 17:18:28 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 | */ |
@@ -13,7 +13,7 @@ | |||
13 | 13 | ||
14 | 14 | ||
15 | /* tags for values visible from Lua */ | 15 | /* tags for values visible from Lua */ |
16 | #define NUM_TAGS LUA_TUSERDATA | 16 | #define NUM_TAGS LUA_TTHREAD |
17 | 17 | ||
18 | 18 | ||
19 | /* | 19 | /* |
@@ -24,22 +24,33 @@ | |||
24 | 24 | ||
25 | 25 | ||
26 | /* | 26 | /* |
27 | ** Union of all collectable objects | ||
28 | */ | ||
29 | typedef union GCObject GCObject; | ||
30 | |||
31 | |||
32 | /* | ||
27 | ** Common header for all collectable objects | 33 | ** Common header for all collectable objects |
28 | */ | 34 | */ |
29 | typedef struct GCheader { | 35 | typedef struct GCheader { |
30 | union GCObject *next; /* pointer to next object */ | 36 | GCObject *next; /* pointer to next object */ |
31 | lu_byte tt; /* object type */ | 37 | lu_byte tt; /* object type */ |
32 | lu_byte marked; /* GC informations */ | 38 | lu_byte marked; /* GC informations */ |
33 | } GCheader; | 39 | } GCheader; |
34 | 40 | ||
35 | 41 | ||
42 | /* | ||
43 | ** common header in macro form, to be included in other objects | ||
44 | */ | ||
45 | #define CommonHeader GCObject *next; lu_byte tt; lu_byte marked | ||
46 | |||
36 | 47 | ||
37 | 48 | ||
38 | /* | 49 | /* |
39 | ** Union of all Lua values | 50 | ** Union of all Lua values |
40 | */ | 51 | */ |
41 | typedef union { | 52 | typedef union { |
42 | union GCObject *gc; | 53 | GCObject *gc; |
43 | void *p; | 54 | void *p; |
44 | lua_Number n; | 55 | lua_Number n; |
45 | int b; | 56 | int b; |
@@ -63,6 +74,7 @@ typedef struct lua_TObject { | |||
63 | #define ttisfunction(o) (ttype(o) == LUA_TFUNCTION) | 74 | #define ttisfunction(o) (ttype(o) == LUA_TFUNCTION) |
64 | #define ttisboolean(o) (ttype(o) == LUA_TBOOLEAN) | 75 | #define ttisboolean(o) (ttype(o) == LUA_TBOOLEAN) |
65 | #define ttisuserdata(o) (ttype(o) == LUA_TUSERDATA) | 76 | #define ttisuserdata(o) (ttype(o) == LUA_TUSERDATA) |
77 | #define ttisthread(o) (ttype(o) == LUA_TTHREAD) | ||
66 | #define ttislightuserdata(o) (ttype(o) == LUA_TLIGHTUSERDATA) | 78 | #define ttislightuserdata(o) (ttype(o) == LUA_TLIGHTUSERDATA) |
67 | 79 | ||
68 | /* Macros to access values */ | 80 | /* Macros to access values */ |
@@ -75,6 +87,7 @@ typedef struct lua_TObject { | |||
75 | #define clvalue(o) check_exp(ttisfunction(o), &(o)->value.gc->cl) | 87 | #define clvalue(o) check_exp(ttisfunction(o), &(o)->value.gc->cl) |
76 | #define hvalue(o) check_exp(ttistable(o), &(o)->value.gc->h) | 88 | #define hvalue(o) check_exp(ttistable(o), &(o)->value.gc->h) |
77 | #define bvalue(o) check_exp(ttisboolean(o), (o)->value.b) | 89 | #define bvalue(o) check_exp(ttisboolean(o), (o)->value.b) |
90 | #define thvalue(o) check_exp(ttisthread(o), &(o)->value.gc->th) | ||
78 | 91 | ||
79 | #define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0)) | 92 | #define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0)) |
80 | 93 | ||
@@ -101,6 +114,11 @@ typedef struct lua_TObject { | |||
101 | i_o->value.gc=cast(GCObject *, (x)); \ | 114 | i_o->value.gc=cast(GCObject *, (x)); \ |
102 | lua_assert(i_o->value.gc->gch.tt == LUA_TUSERDATA); } | 115 | lua_assert(i_o->value.gc->gch.tt == LUA_TUSERDATA); } |
103 | 116 | ||
117 | #define setthvalue(obj,x) \ | ||
118 | { TObject *i_o=(obj); i_o->tt=LUA_TTHREAD; \ | ||
119 | i_o->value.gc=cast(GCObject *, (x)); \ | ||
120 | lua_assert(i_o->value.gc->gch.tt == LUA_TTHREAD); } | ||
121 | |||
104 | #define setclvalue(obj,x) \ | 122 | #define setclvalue(obj,x) \ |
105 | { TObject *i_o=(obj); i_o->tt=LUA_TFUNCTION; \ | 123 | { TObject *i_o=(obj); i_o->tt=LUA_TFUNCTION; \ |
106 | i_o->value.gc=cast(GCObject *, (x)); \ | 124 | i_o->value.gc=cast(GCObject *, (x)); \ |
@@ -142,9 +160,7 @@ typedef TObject *StkId; /* index to stack elements */ | |||
142 | typedef union TString { | 160 | typedef union TString { |
143 | L_Umaxalign dummy; /* ensures maximum alignment for strings */ | 161 | L_Umaxalign dummy; /* ensures maximum alignment for strings */ |
144 | struct { | 162 | struct { |
145 | union GCObject *next; /* pointer to next object */ | 163 | CommonHeader; |
146 | lu_byte tt; /* object type */ | ||
147 | lu_byte marked; /* GC informations */ | ||
148 | lu_byte reserved; | 164 | lu_byte reserved; |
149 | lu_hash hash; | 165 | lu_hash hash; |
150 | size_t len; | 166 | size_t len; |
@@ -160,9 +176,7 @@ typedef union TString { | |||
160 | typedef union Udata { | 176 | typedef union Udata { |
161 | L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */ | 177 | L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */ |
162 | struct { | 178 | struct { |
163 | union GCObject *next; /* pointer to next object */ | 179 | CommonHeader; |
164 | lu_byte tt; /* object type */ | ||
165 | lu_byte marked; /* GC informations */ | ||
166 | struct Table *metatable; | 180 | struct Table *metatable; |
167 | size_t len; | 181 | size_t len; |
168 | } uv; | 182 | } uv; |
@@ -175,9 +189,7 @@ typedef union Udata { | |||
175 | ** Function Prototypes | 189 | ** Function Prototypes |
176 | */ | 190 | */ |
177 | typedef struct Proto { | 191 | typedef struct Proto { |
178 | union GCObject *next; /* pointer to next object */ | 192 | CommonHeader; |
179 | lu_byte tt; /* object type */ | ||
180 | lu_byte marked; /* GC informations */ | ||
181 | TObject *k; /* constants used by the function */ | 193 | TObject *k; /* constants used by the function */ |
182 | Instruction *code; | 194 | Instruction *code; |
183 | struct Proto **p; /* functions defined inside the function */ | 195 | struct Proto **p; /* functions defined inside the function */ |
@@ -210,9 +222,7 @@ typedef struct LocVar { | |||
210 | */ | 222 | */ |
211 | 223 | ||
212 | typedef struct UpVal { | 224 | typedef struct UpVal { |
213 | union GCObject *next; /* pointer to next object */ | 225 | CommonHeader; |
214 | lu_byte tt; /* object type */ | ||
215 | lu_byte marked; /* GC informations */ | ||
216 | TObject *v; /* points to stack or to its own value */ | 226 | TObject *v; /* points to stack or to its own value */ |
217 | TObject value; /* the value (when closed) */ | 227 | TObject value; /* the value (when closed) */ |
218 | } UpVal; | 228 | } UpVal; |
@@ -223,9 +233,7 @@ typedef struct UpVal { | |||
223 | */ | 233 | */ |
224 | 234 | ||
225 | typedef struct CClosure { | 235 | typedef struct CClosure { |
226 | union GCObject *next; /* pointer to next object */ | 236 | CommonHeader; |
227 | lu_byte tt; /* object type */ | ||
228 | lu_byte marked; /* GC informations */ | ||
229 | lu_byte isC; /* 0 for Lua functions, 1 for C functions */ | 237 | lu_byte isC; /* 0 for Lua functions, 1 for C functions */ |
230 | lu_byte nupvalues; | 238 | lu_byte nupvalues; |
231 | lua_CFunction f; | 239 | lua_CFunction f; |
@@ -234,9 +242,7 @@ typedef struct CClosure { | |||
234 | 242 | ||
235 | 243 | ||
236 | typedef struct LClosure { | 244 | typedef struct LClosure { |
237 | union GCObject *next; /* pointer to next object */ | 245 | CommonHeader; |
238 | lu_byte tt; /* object type */ | ||
239 | lu_byte marked; /* GC informations */ | ||
240 | lu_byte isC; | 246 | lu_byte isC; |
241 | lu_byte nupvalues; /* first five fields must be equal to CClosure!! */ | 247 | lu_byte nupvalues; /* first five fields must be equal to CClosure!! */ |
242 | struct Proto *p; | 248 | struct Proto *p; |
@@ -267,9 +273,7 @@ typedef struct Node { | |||
267 | 273 | ||
268 | 274 | ||
269 | typedef struct Table { | 275 | typedef struct Table { |
270 | union GCObject *next; /* pointer to next object */ | 276 | CommonHeader; |
271 | lu_byte tt; /* object type */ | ||
272 | lu_byte marked; /* GC informations */ | ||
273 | lu_byte flags; /* 1<<p means tagmethod(p) is not present */ | 277 | lu_byte flags; /* 1<<p means tagmethod(p) is not present */ |
274 | lu_byte mode; | 278 | lu_byte mode; |
275 | lu_byte lsizenode; /* log2 of size of `node' array */ | 279 | lu_byte lsizenode; /* log2 of size of `node' array */ |
@@ -298,19 +302,6 @@ typedef struct Table { | |||
298 | #define sizearray(t) ((t)->sizearray) | 302 | #define sizearray(t) ((t)->sizearray) |
299 | 303 | ||
300 | 304 | ||
301 | /* | ||
302 | ** Union of all collectable objects | ||
303 | */ | ||
304 | typedef union GCObject { | ||
305 | GCheader gch; | ||
306 | union TString ts; | ||
307 | union Udata u; | ||
308 | union Closure cl; | ||
309 | struct Table h; | ||
310 | struct Proto p; | ||
311 | struct UpVal uv; | ||
312 | } GCObject; | ||
313 | |||
314 | 305 | ||
315 | extern const TObject luaO_nilobject; | 306 | extern const TObject luaO_nilobject; |
316 | 307 | ||