diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-10-02 13:45:03 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-10-02 13:45:03 -0300 |
commit | 15462edb0ff86bf1904011b29635420451cab2c5 (patch) | |
tree | 9a626d34736b830f83fda3f1b2f3342990a05b1f /lobject.h | |
parent | 6f936bc7931662d0460d47ad73eca308ba5fab2f (diff) | |
download | lua-15462edb0ff86bf1904011b29635420451cab2c5.tar.gz lua-15462edb0ff86bf1904011b29635420451cab2c5.tar.bz2 lua-15462edb0ff86bf1904011b29635420451cab2c5.zip |
new definitions for closure structures
Diffstat (limited to 'lobject.h')
-rw-r--r-- | lobject.h | 54 |
1 files changed, 32 insertions, 22 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.h,v 1.112 2001/09/07 17:39:10 roberto Exp $ | 2 | ** $Id: lobject.h,v 1.113 2001/09/25 17:08:46 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 | */ |
@@ -38,7 +38,7 @@ | |||
38 | typedef union { | 38 | typedef union { |
39 | union TString *ts; | 39 | union TString *ts; |
40 | union Udata *u; | 40 | union Udata *u; |
41 | struct Closure *cl; | 41 | union Closure *cl; |
42 | struct Hash *h; | 42 | struct Hash *h; |
43 | struct UpVal *v; | 43 | struct UpVal *v; |
44 | lua_Number n; /* LUA_TNUMBER */ | 44 | lua_Number n; /* LUA_TNUMBER */ |
@@ -177,26 +177,38 @@ typedef struct UpVal { | |||
177 | /* | 177 | /* |
178 | ** Closures | 178 | ** Closures |
179 | */ | 179 | */ |
180 | typedef struct Closure { | 180 | |
181 | short isC; /* 0 for Lua functions, 1 for C functions */ | 181 | typedef struct CClosure { |
182 | short nupvalues; | 182 | lu_byte isC; /* 0 for Lua functions, 1 for C functions */ |
183 | struct Closure *next; | 183 | lu_byte nupvalues; |
184 | struct Closure *mark; /* marked closures (point to itself when not marked) */ | 184 | lu_byte marked; |
185 | union { | 185 | union Closure *next; |
186 | struct { /* C functions */ | 186 | lua_CFunction f; |
187 | lua_CFunction f; | 187 | TObject upvalue[1]; |
188 | TObject upvalue[1]; | 188 | } CClosure; |
189 | } c; | 189 | |
190 | struct { /* Lua functions */ | 190 | |
191 | struct Proto *p; | 191 | typedef struct LClosureEntry { |
192 | ls_bitup isopen; /* bitmap: bit==1 when upvals point to the stack */ | 192 | TObject *val; |
193 | TObject *upvals[1]; /* may point to the stack or to an UpVal */ | 193 | UpVal *heap; /* NULL when upvalue is still in the stack */ |
194 | } l; | 194 | } LClosureEntry; |
195 | } u; | 195 | |
196 | typedef struct LClosure { | ||
197 | lu_byte isC; | ||
198 | lu_byte nupvalues; | ||
199 | lu_byte marked; | ||
200 | union Closure *next; /* first four fields must be equal to CClosure!! */ | ||
201 | struct Proto *p; | ||
202 | LClosureEntry upvals[1]; | ||
203 | } LClosure; | ||
204 | |||
205 | typedef union Closure { | ||
206 | CClosure c; | ||
207 | LClosure l; | ||
196 | } Closure; | 208 | } Closure; |
197 | 209 | ||
198 | 210 | ||
199 | #define iscfunction(o) (ttype(o) == LUA_TFUNCTION && clvalue(o)->isC) | 211 | #define iscfunction(o) (ttype(o) == LUA_TFUNCTION && clvalue(o)->c.isC) |
200 | 212 | ||
201 | 213 | ||
202 | 214 | ||
@@ -223,9 +235,7 @@ typedef struct Hash { | |||
223 | } Hash; | 235 | } Hash; |
224 | 236 | ||
225 | 237 | ||
226 | /* unmarked tables and closures are represented by pointing `mark' to | 238 | /* unmarked tables are represented by pointing `mark' to themselves */ |
227 | ** themselves | ||
228 | */ | ||
229 | #define ismarked(x) ((x)->mark != (x)) | 239 | #define ismarked(x) ((x)->mark != (x)) |
230 | 240 | ||
231 | 241 | ||