diff options
Diffstat (limited to 'src/lobject.h')
-rw-r--r-- | src/lobject.h | 68 |
1 files changed, 46 insertions, 22 deletions
diff --git a/src/lobject.h b/src/lobject.h index d69d6153..06246bfa 100644 --- a/src/lobject.h +++ b/src/lobject.h @@ -1,5 +1,5 @@ /* -** $Id: lobject.h,v 2.61 2011/07/04 20:29:02 roberto Exp $ +** $Id: lobject.h,v 2.64 2011/10/31 17:48:22 roberto Exp $ ** Type definitions for Lua objects ** See Copyright Notice in lua.h */ @@ -132,7 +132,7 @@ typedef struct lua_TValue TValue; #define ttislcf(o) checktag((o), LUA_TLCF) #define ttisuserdata(o) checktag((o), ctb(LUA_TUSERDATA)) #define ttisthread(o) checktag((o), ctb(LUA_TTHREAD)) -#define ttisdeadkey(o) checktag((o), ctb(LUA_TDEADKEY)) +#define ttisdeadkey(o) checktag((o), LUA_TDEADKEY) #define ttisequal(o1,o2) (rttype(o1) == rttype(o2)) @@ -151,6 +151,8 @@ typedef struct lua_TValue TValue; #define hvalue(o) check_exp(ttistable(o), &val_(o).gc->h) #define bvalue(o) check_exp(ttisboolean(o), val_(o).b) #define thvalue(o) check_exp(ttisthread(o), &val_(o).gc->th) +/* a dead value may get the 'gc' field, but cannot access its contents */ +#define deadvalue(o) check_exp(ttisdeadkey(o), cast(void *, val_(o).gc)) #define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0)) @@ -224,7 +226,7 @@ typedef struct lua_TValue TValue; val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TPROTO)); \ checkliveness(G(L),io); } -#define setdeadvalue(obj) settt_(obj, ctb(LUA_TDEADKEY)) +#define setdeadvalue(obj) settt_(obj, LUA_TDEADKEY) @@ -262,51 +264,73 @@ typedef struct lua_TValue TValue; ** ======================================================= */ -#if defined(LUA_NANTRICKLE) || defined(LUA_NANTRICKBE) +#if defined(LUA_NANTRICK) \ + || defined(LUA_NANTRICK_LE) \ + || defined(LUA_NANTRICK_BE) /* ** numbers are represented in the 'd_' field. All other values have the -** value (NNMARK | tag) in 'tt_'. A number with such pattern would be +** value (NNMARK | tag) in 'tt__'. A number with such pattern would be ** a "signaled NaN", which is never generated by regular operations by ** the CPU (nor by 'strtod') */ #if !defined(NNMARK) #define NNMARK 0x7FF7A500 +#define NNMASK 0x7FFFFF00 #endif #undef TValuefields #undef NILCONSTANT -#if defined(LUA_NANTRICKLE) + +#if defined(LUA_NANTRICK_LE) + /* little endian */ #define TValuefields \ - union { struct { Value v_; int tt_; } i; double d_; } u + union { struct { Value v__; int tt__; } i; double d__; } u #define NILCONSTANT {{{NULL}, tag2tt(LUA_TNIL)}} -#else +/* field-access macros */ +#define v_(o) ((o)->u.i.v__) +#define d_(o) ((o)->u.d__) +#define tt_(o) ((o)->u.i.tt__) + +#elif defined(LUA_NANTRICK_BE) + /* big endian */ #define TValuefields \ - union { struct { int tt_; Value v_; } i; double d_; } u + union { struct { int tt__; Value v__; } i; double d__; } u #define NILCONSTANT {{tag2tt(LUA_TNIL), {NULL}}} +/* field-access macros */ +#define v_(o) ((o)->u.i.v__) +#define d_(o) ((o)->u.d__) +#define tt_(o) ((o)->u.i.tt__) + +#elif !defined(TValuefields) +#error option 'LUA_NANTRICK' needs declaration for 'TValuefields' + #endif + +/* correspondence with standard representation */ +#undef val_ +#define val_(o) v_(o) +#undef num_ +#define num_(o) d_(o) + + #undef numfield #define numfield /* no such field; numbers are the entire struct */ /* basic check to distinguish numbers from non-numbers */ #undef ttisnumber -#define ttisnumber(o) (((o)->u.i.tt_ & 0x7fffff00) != NNMARK) +#define ttisnumber(o) ((tt_(o) & NNMASK) != NNMARK) #define tag2tt(t) (NNMARK | (t)) -#undef val_ -#define val_(o) ((o)->u.i.v_) -#undef num_ -#define num_(o) ((o)->u.d_) - #undef rttype -#define rttype(o) (ttisnumber(o) ? LUA_TNUMBER : (o)->u.i.tt_ & 0xff) +#define rttype(o) (ttisnumber(o) ? LUA_TNUMBER : tt_(o) & 0xff) #undef settt_ -#define settt_(o,t) ((o)->u.i.tt_=tag2tt(t)) +#define settt_(o,t) (tt_(o) = tag2tt(t)) #undef setnvalue #define setnvalue(obj,x) \ @@ -324,11 +348,11 @@ typedef struct lua_TValue TValue; */ #undef checktag -#define checktag(o,t) ((o)->u.i.tt_ == tag2tt(t)) +#define checktag(o,t) (tt_(o) == tag2tt(t)) #undef ttisequal #define ttisequal(o1,o2) \ - (ttisnumber(o1) ? ttisnumber(o2) : ((o1)->u.i.tt_ == (o2)->u.i.tt_)) + (ttisnumber(o1) ? ttisnumber(o2) : (tt_(o1) == tt_(o2))) @@ -435,11 +459,11 @@ typedef struct Proto { TValue *k; /* constants used by the function */ Instruction *code; struct Proto **p; /* functions defined inside the function */ - int *lineinfo; /* map from opcodes to source lines */ - LocVar *locvars; /* information about local variables */ + int *lineinfo; /* map from opcodes to source lines (debug information) */ + LocVar *locvars; /* information about local variables (debug information) */ Upvaldesc *upvalues; /* upvalue information */ union Closure *cache; /* last created closure with this prototype */ - TString *source; + TString *source; /* used for debug information */ int sizeupvalues; /* size of 'upvalues' */ int sizek; /* size of `k' */ int sizecode; |