diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-07-26 12:53:23 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-07-26 12:53:23 -0300 |
commit | 78f9635111ec647719bb1b1622b1cb6f47ef1be1 (patch) | |
tree | 88aa47e4acb3c8adb142329c8f48cb5a1d4d7c88 | |
parent | 8b7cf8c62d0a3d20bfc8741a66d8c2447c847bd3 (diff) | |
download | lua-78f9635111ec647719bb1b1622b1cb6f47ef1be1.tar.gz lua-78f9635111ec647719bb1b1622b1cb6f47ef1be1.tar.bz2 lua-78f9635111ec647719bb1b1622b1cb6f47ef1be1.zip |
several new comments
-rw-r--r-- | lobject.h | 70 |
1 files changed, 43 insertions, 27 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.h,v 2.40 2010/05/07 18:44:46 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 2.41 2010/06/04 13:25:10 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 | */ |
@@ -56,17 +56,18 @@ typedef struct GCheader { | |||
56 | ** Union of all Lua values | 56 | ** Union of all Lua values |
57 | */ | 57 | */ |
58 | typedef union { | 58 | typedef union { |
59 | GCObject *gc; | 59 | GCObject *gc; /* collectable objects */ |
60 | void *p; | 60 | void *p; /* light userdata */ |
61 | lua_Number n; | 61 | lua_Number n; /* numbers */ |
62 | int b; | 62 | int b; /* booleans */ |
63 | lua_CFunction f; | 63 | lua_CFunction f; /* light C functions */ |
64 | } Value; | 64 | } Value; |
65 | 65 | ||
66 | 66 | ||
67 | 67 | ||
68 | /* | 68 | /* |
69 | ** Tagged Values | 69 | ** Tagged Values. This is the basic representation of values in Lua, |
70 | ** an actual value plus a tag with its type. | ||
70 | */ | 71 | */ |
71 | 72 | ||
72 | #define TValuefields Value value_; int tt_ | 73 | #define TValuefields Value value_; int tt_ |
@@ -76,7 +77,7 @@ typedef struct lua_TValue { | |||
76 | } TValue; | 77 | } TValue; |
77 | 78 | ||
78 | 79 | ||
79 | /* macro defining a nil value to be used in definitions */ | 80 | /* macro defining a nil value */ |
80 | #define NILCONSTANT {NULL}, LUA_TNIL | 81 | #define NILCONSTANT {NULL}, LUA_TNIL |
81 | 82 | ||
82 | 83 | ||
@@ -125,6 +126,8 @@ typedef struct lua_TValue { | |||
125 | 126 | ||
126 | #define iscollectable(o) (ttype(o) >= LUA_TSTRING) | 127 | #define iscollectable(o) (ttype(o) >= LUA_TSTRING) |
127 | 128 | ||
129 | |||
130 | /* Macros for internal tests */ | ||
128 | #define righttt(obj) (ttype(obj) == gcvalue(obj)->gch.tt) | 131 | #define righttt(obj) (ttype(obj) == gcvalue(obj)->gch.tt) |
129 | 132 | ||
130 | #define checkconsistency(obj) lua_assert(!iscollectable(obj) || righttt(obj)) | 133 | #define checkconsistency(obj) lua_assert(!iscollectable(obj) || righttt(obj)) |
@@ -191,7 +194,7 @@ typedef struct lua_TValue { | |||
191 | 194 | ||
192 | 195 | ||
193 | /* | 196 | /* |
194 | ** different types of sets, according to destination | 197 | ** different types of assignments, according to destination |
195 | */ | 198 | */ |
196 | 199 | ||
197 | /* from stack to (same) stack */ | 200 | /* from stack to (same) stack */ |
@@ -215,7 +218,7 @@ typedef TValue *StkId; /* index to stack elements */ | |||
215 | 218 | ||
216 | 219 | ||
217 | /* | 220 | /* |
218 | ** String headers for string table | 221 | ** Header for string value; string bytes follow the end of this structure |
219 | */ | 222 | */ |
220 | typedef union TString { | 223 | typedef union TString { |
221 | L_Umaxalign dummy; /* ensures maximum alignment for strings */ | 224 | L_Umaxalign dummy; /* ensures maximum alignment for strings */ |
@@ -228,11 +231,16 @@ typedef union TString { | |||
228 | } TString; | 231 | } TString; |
229 | 232 | ||
230 | 233 | ||
234 | /* get the actual string (array of bytes) from a TString */ | ||
231 | #define getstr(ts) cast(const char *, (ts) + 1) | 235 | #define getstr(ts) cast(const char *, (ts) + 1) |
232 | #define svalue(o) getstr(rawtsvalue(o)) | ||
233 | 236 | ||
237 | /* get the actual string (array of bytes) from a Lua value */ | ||
238 | #define svalue(o) getstr(rawtsvalue(o)) | ||
234 | 239 | ||
235 | 240 | ||
241 | /* | ||
242 | ** Header for userdata; memory area follows the end of this structure | ||
243 | */ | ||
236 | typedef union Udata { | 244 | typedef union Udata { |
237 | L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */ | 245 | L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */ |
238 | struct { | 246 | struct { |
@@ -246,16 +254,27 @@ typedef union Udata { | |||
246 | 254 | ||
247 | 255 | ||
248 | /* | 256 | /* |
249 | ** Upvalues from a function prototype | 257 | ** Description of an upvalue for function prototypes |
250 | */ | 258 | */ |
251 | typedef struct Upvaldesc { | 259 | typedef struct Upvaldesc { |
252 | TString *name; /* upvalue name (for debug information) */ | 260 | TString *name; /* upvalue name (for debug information) */ |
253 | lu_byte instack; | 261 | lu_byte instack; /* whether it is in stack */ |
254 | lu_byte idx; /* index of upvalue (in stack or in outer function's list) */ | 262 | lu_byte idx; /* index of upvalue (in stack or in outer function's list) */ |
255 | } Upvaldesc; | 263 | } Upvaldesc; |
256 | 264 | ||
257 | 265 | ||
258 | /* | 266 | /* |
267 | ** Description of a local variable for function prototypes | ||
268 | ** (used for debug information) | ||
269 | */ | ||
270 | typedef struct LocVar { | ||
271 | TString *varname; | ||
272 | int startpc; /* first point where variable is active */ | ||
273 | int endpc; /* first point where variable is dead */ | ||
274 | } LocVar; | ||
275 | |||
276 | |||
277 | /* | ||
259 | ** Function Prototypes | 278 | ** Function Prototypes |
260 | */ | 279 | */ |
261 | typedef struct Proto { | 280 | typedef struct Proto { |
@@ -264,7 +283,7 @@ typedef struct Proto { | |||
264 | Instruction *code; | 283 | Instruction *code; |
265 | struct Proto **p; /* functions defined inside the function */ | 284 | struct Proto **p; /* functions defined inside the function */ |
266 | int *lineinfo; /* map from opcodes to source lines */ | 285 | int *lineinfo; /* map from opcodes to source lines */ |
267 | struct LocVar *locvars; /* information about local variables */ | 286 | LocVar *locvars; /* information about local variables */ |
268 | Upvaldesc *upvalues; /* upvalue information */ | 287 | Upvaldesc *upvalues; /* upvalue information */ |
269 | union Closure *cache; /* last created closure with this prototype */ | 288 | union Closure *cache; /* last created closure with this prototype */ |
270 | TString *source; | 289 | TString *source; |
@@ -277,24 +296,16 @@ typedef struct Proto { | |||
277 | int linedefined; | 296 | int linedefined; |
278 | int lastlinedefined; | 297 | int lastlinedefined; |
279 | GCObject *gclist; | 298 | GCObject *gclist; |
280 | lu_byte numparams; | 299 | lu_byte numparams; /* number of fixed parameters */ |
281 | lu_byte is_vararg; | 300 | lu_byte is_vararg; |
282 | lu_byte maxstacksize; | 301 | lu_byte maxstacksize; /* maximum stack used by this function */ |
283 | } Proto; | 302 | } Proto; |
284 | 303 | ||
285 | 304 | ||
286 | typedef struct LocVar { | ||
287 | TString *varname; | ||
288 | int startpc; /* first point where variable is active */ | ||
289 | int endpc; /* first point where variable is dead */ | ||
290 | } LocVar; | ||
291 | |||
292 | |||
293 | 305 | ||
294 | /* | 306 | /* |
295 | ** Upvalues | 307 | ** Lua Upvalues |
296 | */ | 308 | */ |
297 | |||
298 | typedef struct UpVal { | 309 | typedef struct UpVal { |
299 | CommonHeader; | 310 | CommonHeader; |
300 | TValue *v; /* points to stack or to its own value */ | 311 | TValue *v; /* points to stack or to its own value */ |
@@ -318,14 +329,14 @@ typedef struct UpVal { | |||
318 | typedef struct CClosure { | 329 | typedef struct CClosure { |
319 | ClosureHeader; | 330 | ClosureHeader; |
320 | lua_CFunction f; | 331 | lua_CFunction f; |
321 | TValue upvalue[1]; | 332 | TValue upvalue[1]; /* list of upvalues */ |
322 | } CClosure; | 333 | } CClosure; |
323 | 334 | ||
324 | 335 | ||
325 | typedef struct LClosure { | 336 | typedef struct LClosure { |
326 | ClosureHeader; | 337 | ClosureHeader; |
327 | struct Proto *p; | 338 | struct Proto *p; |
328 | UpVal *upvals[1]; | 339 | UpVal *upvals[1]; /* list of upvalues */ |
329 | } LClosure; | 340 | } LClosure; |
330 | 341 | ||
331 | 342 | ||
@@ -339,6 +350,7 @@ typedef union Closure { | |||
339 | 350 | ||
340 | #define getproto(o) (clvalue(o)->l.p) | 351 | #define getproto(o) (clvalue(o)->l.p) |
341 | 352 | ||
353 | |||
342 | /* | 354 | /* |
343 | ** Tables | 355 | ** Tables |
344 | */ | 356 | */ |
@@ -383,8 +395,12 @@ typedef struct Table { | |||
383 | #define sizenode(t) (twoto((t)->lsizenode)) | 395 | #define sizenode(t) (twoto((t)->lsizenode)) |
384 | 396 | ||
385 | 397 | ||
398 | /* | ||
399 | ** (address of) a fixed nil value | ||
400 | */ | ||
386 | #define luaO_nilobject (&luaO_nilobject_) | 401 | #define luaO_nilobject (&luaO_nilobject_) |
387 | 402 | ||
403 | |||
388 | LUAI_DDEC const TValue luaO_nilobject_; | 404 | LUAI_DDEC const TValue luaO_nilobject_; |
389 | 405 | ||
390 | LUAI_FUNC int luaO_int2fb (unsigned int x); | 406 | LUAI_FUNC int luaO_int2fb (unsigned int x); |