aboutsummaryrefslogtreecommitdiff
path: root/lobject.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-12-10 10:13:36 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-12-10 10:13:36 -0200
commit47fc57a2529c83376883f36954082cfe80ae588f (patch)
treec2e57e2f9f7d78279144bfd9cbd04a3b1b131f12 /lobject.h
parent4d5fe1f54bc00850f77a7c42f9e95d0ff3f1ab5b (diff)
downloadlua-47fc57a2529c83376883f36954082cfe80ae588f.tar.gz
lua-47fc57a2529c83376883f36954082cfe80ae588f.tar.bz2
lua-47fc57a2529c83376883f36954082cfe80ae588f.zip
`TObject' renamed to `TValue' + other name changes and better assertions
for incremental garbage collection
Diffstat (limited to 'lobject.h')
-rw-r--r--lobject.h103
1 files changed, 55 insertions, 48 deletions
diff --git a/lobject.h b/lobject.h
index b2987429..fa5364c2 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.h,v 1.161 2003/08/27 21:01:44 roberto Exp roberto $ 2** $Id: lobject.h,v 1.162 2003/11/18 14:55:11 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*/
@@ -58,12 +58,12 @@ typedef union {
58 58
59 59
60/* 60/*
61** Lua values (or `tagged objects') 61** Tagged Values
62*/ 62*/
63typedef struct lua_TObject { 63typedef struct lua_TValue {
64 int tt; 64 int tt;
65 Value value; 65 Value value;
66} TObject; 66} TValue;
67 67
68 68
69/* Macros to test type */ 69/* Macros to test type */
@@ -82,8 +82,10 @@ typedef struct lua_TObject {
82#define gcvalue(o) check_exp(iscollectable(o), (o)->value.gc) 82#define gcvalue(o) check_exp(iscollectable(o), (o)->value.gc)
83#define pvalue(o) check_exp(ttislightuserdata(o), (o)->value.p) 83#define pvalue(o) check_exp(ttislightuserdata(o), (o)->value.p)
84#define nvalue(o) check_exp(ttisnumber(o), (o)->value.n) 84#define nvalue(o) check_exp(ttisnumber(o), (o)->value.n)
85#define tsvalue(o) check_exp(ttisstring(o), &(o)->value.gc->ts) 85#define rawtsvalue(o) check_exp(ttisstring(o), &(o)->value.gc->ts)
86#define uvalue(o) check_exp(ttisuserdata(o), &(o)->value.gc->u) 86#define tsvalue(o) (&rawtsvalue(o)->tsv)
87#define rawuvalue(o) check_exp(ttisuserdata(o), &(o)->value.gc->u)
88#define uvalue(o) (&rawuvalue(o)->uv)
87#define clvalue(o) check_exp(ttisfunction(o), &(o)->value.gc->cl) 89#define clvalue(o) check_exp(ttisfunction(o), &(o)->value.gc->cl)
88#define hvalue(o) check_exp(ttistable(o), &(o)->value.gc->h) 90#define hvalue(o) check_exp(ttistable(o), &(o)->value.gc->h)
89#define bvalue(o) check_exp(ttisboolean(o), (o)->value.b) 91#define bvalue(o) check_exp(ttisboolean(o), (o)->value.b)
@@ -91,64 +93,69 @@ typedef struct lua_TObject {
91 93
92#define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0)) 94#define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0))
93 95
96/*
97** for internal debug only
98*/
99#define checkconsistency(obj) \
100 lua_assert(!iscollectable(obj) || (ttype(obj) == (obj)->value.gc->gch.tt))
101
102#define checkliveness(L,obj) \
103 lua_assert(!iscollectable(obj) || \
104 ((ttype(obj) == (obj)->value.gc->gch.tt) && !isdead(G(L), (obj)->value.gc)))
105
106
94/* Macros to set values */ 107/* Macros to set values */
95#define setnilvalue(obj) ((obj)->tt=LUA_TNIL) 108#define setnilvalue(obj) ((obj)->tt=LUA_TNIL)
96 109
97#define setnvalue(obj,x) \ 110#define setnvalue(obj,x) \
98 { TObject *i_o=(obj); i_o->value.n=(x); i_o->tt=LUA_TNUMBER; } 111 { TValue *i_o=(obj); i_o->value.n=(x); i_o->tt=LUA_TNUMBER; }
99 112
100#define chgnvalue(obj,x) \ 113#define chgnvalue(obj,x) \
101 check_exp(ttype(obj)==LUA_TNUMBER, (obj)->value.n=(x)) 114 check_exp(ttype(obj)==LUA_TNUMBER, (obj)->value.n=(x))
102 115
103#define setpvalue(obj,x) \ 116#define setpvalue(obj,x) \
104 { TObject *i_o=(obj); i_o->value.p=(x); i_o->tt=LUA_TLIGHTUSERDATA; } 117 { TValue *i_o=(obj); i_o->value.p=(x); i_o->tt=LUA_TLIGHTUSERDATA; }
105 118
106#define setbvalue(obj,x) \ 119#define setbvalue(obj,x) \
107 { TObject *i_o=(obj); i_o->value.b=(x); i_o->tt=LUA_TBOOLEAN; } 120 { TValue *i_o=(obj); i_o->value.b=(x); i_o->tt=LUA_TBOOLEAN; }
108 121
109#define setsvalue(obj,x) \ 122#define setsvalue(L,obj,x) \
110 { TObject *i_o=(obj); \ 123 { TValue *i_o=(obj); \
111 i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TSTRING; \ 124 i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TSTRING; \
112 lua_assert(i_o->value.gc->gch.tt == LUA_TSTRING); } 125 checkliveness(L,i_o); }
113 126
114#define setuvalue(obj,x) \ 127#define setuvalue(L,obj,x) \
115 { TObject *i_o=(obj); \ 128 { TValue *i_o=(obj); \
116 i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TUSERDATA; \ 129 i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TUSERDATA; \
117 lua_assert(i_o->value.gc->gch.tt == LUA_TUSERDATA); } 130 checkliveness(L,i_o); }
118 131
119#define setthvalue(obj,x) \ 132#define setthvalue(L,obj,x) \
120 { TObject *i_o=(obj); \ 133 { TValue *i_o=(obj); \
121 i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTHREAD; \ 134 i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTHREAD; \
122 lua_assert(i_o->value.gc->gch.tt == LUA_TTHREAD); } 135 checkliveness(L,i_o); }
123 136
124#define setclvalue(obj,x) \ 137#define setclvalue(L,obj,x) \
125 { TObject *i_o=(obj); \ 138 { TValue *i_o=(obj); \
126 i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TFUNCTION; \ 139 i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TFUNCTION; \
127 lua_assert(i_o->value.gc->gch.tt == LUA_TFUNCTION); } 140 checkliveness(L,i_o); }
128 141
129#define sethvalue(obj,x) \ 142#define sethvalue(L,obj,x) \
130 { TObject *i_o=(obj); \ 143 { TValue *i_o=(obj); \
131 i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTABLE; \ 144 i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTABLE; \
132 lua_assert(i_o->value.gc->gch.tt == LUA_TTABLE); } 145 checkliveness(L,i_o); }
133 146
134#define setptvalue(obj,x) \ 147#define setptvalue(L,obj,x) \
135 { TObject *i_o=(obj); \ 148 { TValue *i_o=(obj); \
136 i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TPROTO; \ 149 i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TPROTO; \
137 lua_assert(i_o->value.gc->gch.tt == LUA_TPROTO); } 150 checkliveness(L,i_o); }
138
139 151
140 152
141/*
142** for internal debug only
143*/
144#define checkconsistency(obj) \
145 lua_assert(!iscollectable(obj) || (ttype(obj) == (obj)->value.gc->gch.tt))
146 153
147 154
148#define setobj(obj1,obj2) \ 155#define setobj(L,obj1,obj2) \
149 { const TObject *o2=(obj2); TObject *o1=(obj1); \ 156 { const TValue *o2=(obj2); TValue *o1=(obj1); \
150 checkconsistency(o2); \ 157 o1->tt=o2->tt; o1->value = o2->value; \
151 o1->tt=o2->tt; o1->value = o2->value; } 158 checkliveness(L,o1); }
152 159
153 160
154/* 161/*
@@ -177,7 +184,7 @@ typedef struct lua_TObject {
177 184
178 185
179 186
180typedef TObject *StkId; /* index to stack elements */ 187typedef TValue *StkId; /* index to stack elements */
181 188
182 189
183/* 190/*
@@ -216,7 +223,7 @@ typedef union Udata {
216*/ 223*/
217typedef struct Proto { 224typedef struct Proto {
218 CommonHeader; 225 CommonHeader;
219 TObject *k; /* constants used by the function */ 226 TValue *k; /* constants used by the function */
220 Instruction *code; 227 Instruction *code;
221 struct Proto **p; /* functions defined inside the function */ 228 struct Proto **p; /* functions defined inside the function */
222 int *lineinfo; /* map from opcodes to source lines */ 229 int *lineinfo; /* map from opcodes to source lines */
@@ -253,8 +260,8 @@ typedef struct LocVar {
253typedef struct UpVal { 260typedef struct UpVal {
254 CommonHeader; 261 CommonHeader;
255 GCObject *gclist; 262 GCObject *gclist;
256 TObject *v; /* points to stack or to its own value */ 263 TValue *v; /* points to stack or to its own value */
257 TObject value; /* the value (when closed) */ 264 TValue value; /* the value (when closed) */
258} UpVal; 265} UpVal;
259 266
260 267
@@ -268,14 +275,14 @@ typedef struct UpVal {
268typedef struct CClosure { 275typedef struct CClosure {
269 ClosureHeader; 276 ClosureHeader;
270 lua_CFunction f; 277 lua_CFunction f;
271 TObject upvalue[1]; 278 TValue upvalue[1];
272} CClosure; 279} CClosure;
273 280
274 281
275typedef struct LClosure { 282typedef struct LClosure {
276 ClosureHeader; 283 ClosureHeader;
277 struct Proto *p; 284 struct Proto *p;
278 TObject g; /* global table for this closure */ 285 TValue g; /* global table for this closure */
279 UpVal *upvals[1]; 286 UpVal *upvals[1];
280} LClosure; 287} LClosure;
281 288
@@ -295,8 +302,8 @@ typedef union Closure {
295*/ 302*/
296 303
297typedef struct Node { 304typedef struct Node {
298 TObject i_key; 305 TValue i_key;
299 TObject i_val; 306 TValue i_val;
300 struct Node *next; /* for chaining */ 307 struct Node *next; /* for chaining */
301} Node; 308} Node;
302 309
@@ -306,7 +313,7 @@ typedef struct Table {
306 lu_byte flags; /* 1<<p means tagmethod(p) is not present */ 313 lu_byte flags; /* 1<<p means tagmethod(p) is not present */
307 lu_byte lsizenode; /* log2 of size of `node' array */ 314 lu_byte lsizenode; /* log2 of size of `node' array */
308 struct Table *metatable; 315 struct Table *metatable;
309 TObject *array; /* array part */ 316 TValue *array; /* array part */
310 Node *node; 317 Node *node;
311 Node *firstfree; /* this position is free; all positions after it are full */ 318 Node *firstfree; /* this position is free; all positions after it are full */
312 GCObject *gclist; 319 GCObject *gclist;
@@ -327,13 +334,13 @@ typedef struct Table {
327 334
328 335
329 336
330extern const TObject luaO_nilobject; 337extern const TValue luaO_nilobject;
331 338
332int luaO_log2 (unsigned int x); 339int luaO_log2 (unsigned int x);
333int luaO_int2fb (unsigned int x); 340int luaO_int2fb (unsigned int x);
334#define fb2int(x) (((x) & 7) << ((x) >> 3)) 341#define fb2int(x) (((x) & 7) << ((x) >> 3))
335 342
336int luaO_rawequalObj (const TObject *t1, const TObject *t2); 343int luaO_rawequalObj (const TValue *t1, const TValue *t2);
337int luaO_str2d (const char *s, lua_Number *result); 344int luaO_str2d (const char *s, lua_Number *result);
338 345
339const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp); 346const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp);