aboutsummaryrefslogtreecommitdiff
path: root/lobject.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-11-06 19:41:53 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-11-06 19:41:53 -0200
commit26bf2adaceb18877d836174226d2bfdc3f1fc512 (patch)
treeb23ccd2e297e7c5e732ce65e88f35145271f7faa /lobject.h
parentfd48dcc7c8734091181d8d0e54b0ba3d1770f4c3 (diff)
downloadlua-26bf2adaceb18877d836174226d2bfdc3f1fc512.tar.gz
lua-26bf2adaceb18877d836174226d2bfdc3f1fc512.tar.bz2
lua-26bf2adaceb18877d836174226d2bfdc3f1fc512.zip
optimizations for space in LClosures and time cleanning weak tables
Diffstat (limited to 'lobject.h')
-rw-r--r--lobject.h38
1 files changed, 20 insertions, 18 deletions
diff --git a/lobject.h b/lobject.h
index dbabc638..d8e6057f 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.h,v 1.114 2001/10/02 16:45:03 roberto Exp $ 2** $Id: lobject.h,v 1.115 2001/10/25 19:14:14 roberto Exp $
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*/
@@ -31,8 +31,13 @@
31#define NUM_TAGS 6 31#define NUM_TAGS 6
32 32
33 33
34/* extra tag: used locally when moving an upvalue from the stack to the heap */ 34/*
35** extra tags:
36** first is used locally when moving an upvalue from the stack to the heap;
37** second prefixes upvalues in the heap
38*/
35#define LUA_TUPVAL 6 39#define LUA_TUPVAL 6
40#define LUA_HEAPUPVAL 7
36 41
37 42
38typedef union { 43typedef union {
@@ -40,7 +45,7 @@ typedef union {
40 union Udata *u; 45 union Udata *u;
41 union Closure *cl; 46 union Closure *cl;
42 struct Table *h; 47 struct Table *h;
43 struct UpVal *v; 48 struct lua_TObject *v;
44 lua_Number n; /* LUA_TNUMBER */ 49 lua_Number n; /* LUA_TNUMBER */
45} Value; 50} Value;
46 51
@@ -81,8 +86,8 @@ typedef struct lua_TObject {
81 86
82#define setnilvalue(obj) ((obj)->tt=LUA_TNIL) 87#define setnilvalue(obj) ((obj)->tt=LUA_TNIL)
83 88
84#define setupvalue(obj,x) \ 89#define setupvalue(obj,x,t) \
85 { TObject *_o=(obj); _o->tt=LUA_TUPVAL; _o->value.v=(x); } 90 { TObject *_o=(obj); _o->tt=(t); _o->value.v=(x); }
86 91
87#define setobj(obj1,obj2) \ 92#define setobj(obj1,obj2) \
88 { TObject *o1=(obj1); const TObject *o2=(obj2); \ 93 { TObject *o1=(obj1); const TObject *o2=(obj2); \
@@ -165,13 +170,15 @@ typedef struct LocVar {
165 170
166 171
167/* 172/*
168** Upvalues in the heap 173** Upvalues in the heap. There is a small trick here: to allow a closure to
174** diferentiate between upvalues in the heap and in the stack, upvalues in
175** the heap always have another TObject before them (like those in the stack),
176** but those `prefix' objects have a tag that cannot happen in the stack.
177** Moreover, we use these extra `prexif' object to store GC-related
178** information.
169*/ 179*/
170typedef struct UpVal { 180
171 TObject val; 181#define isclosed(u) (ttype((u)-1) == LUA_HEAPUPVAL)
172 struct UpVal *next;
173 int marked;
174} UpVal;
175 182
176 183
177/* 184/*
@@ -188,20 +195,16 @@ typedef struct CClosure {
188} CClosure; 195} CClosure;
189 196
190 197
191typedef struct LClosureEntry {
192 TObject *val;
193 UpVal *heap; /* NULL when upvalue is still in the stack */
194} LClosureEntry;
195
196typedef struct LClosure { 198typedef struct LClosure {
197 lu_byte isC; 199 lu_byte isC;
198 lu_byte nupvalues; 200 lu_byte nupvalues;
199 lu_byte marked; 201 lu_byte marked;
200 union Closure *next; /* first four fields must be equal to CClosure!! */ 202 union Closure *next; /* first four fields must be equal to CClosure!! */
201 struct Proto *p; 203 struct Proto *p;
202 LClosureEntry upvals[1]; 204 TObject *upvals[1];
203} LClosure; 205} LClosure;
204 206
207
205typedef union Closure { 208typedef union Closure {
206 CClosure c; 209 CClosure c;
207 LClosure l; 210 LClosure l;
@@ -212,7 +215,6 @@ typedef union Closure {
212 215
213 216
214 217
215
216/* 218/*
217** Tables 219** Tables
218*/ 220*/