diff options
Diffstat (limited to 'lobject.h')
| -rw-r--r-- | lobject.h | 31 |
1 files changed, 23 insertions, 8 deletions
| @@ -17,11 +17,12 @@ | |||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | /* | 19 | /* |
| 20 | ** Extra tags for non-values | 20 | ** Extra tags for collectable non-values |
| 21 | */ | 21 | */ |
| 22 | #define LUA_TUPVAL LUA_NUMTAGS /* upvalues */ | 22 | #define LUA_TUPVAL LUA_NUMTAGS /* upvalues */ |
| 23 | #define LUA_TPROTO (LUA_NUMTAGS+1) /* function prototypes */ | 23 | #define LUA_TPROTO (LUA_NUMTAGS+1) /* function prototypes */ |
| 24 | 24 | ||
| 25 | |||
| 25 | /* | 26 | /* |
| 26 | ** number of all possible tags (including LUA_TNONE) | 27 | ** number of all possible tags (including LUA_TNONE) |
| 27 | */ | 28 | */ |
| @@ -30,7 +31,7 @@ | |||
| 30 | 31 | ||
| 31 | /* | 32 | /* |
| 32 | ** tags for Tagged Values have the following use of bits: | 33 | ** tags for Tagged Values have the following use of bits: |
| 33 | ** bits 0-3: actual tag (a LUA_T* value) | 34 | ** bits 0-3: actual tag (a LUA_T* constant) |
| 34 | ** bits 4-5: variant bits | 35 | ** bits 4-5: variant bits |
| 35 | ** bit 6: whether value is collectable | 36 | ** bit 6: whether value is collectable |
| 36 | */ | 37 | */ |
| @@ -86,24 +87,35 @@ typedef struct TValue { | |||
| 86 | 87 | ||
| 87 | 88 | ||
| 88 | /* Macros for internal tests */ | 89 | /* Macros for internal tests */ |
| 90 | |||
| 91 | /* collectable object has the same tag as the original value */ | ||
| 89 | #define righttt(obj) (ttypetag(obj) == gcvalue(obj)->tt) | 92 | #define righttt(obj) (ttypetag(obj) == gcvalue(obj)->tt) |
| 90 | 93 | ||
| 94 | /* | ||
| 95 | ** Any value being manipulated by the program either is non | ||
| 96 | ** collectable, or the collectable object has the right tag | ||
| 97 | ** and it is not dead. | ||
| 98 | */ | ||
| 91 | #define checkliveness(L,obj) \ | 99 | #define checkliveness(L,obj) \ |
| 92 | ((void)L, lua_longassert(!iscollectable(obj) || \ | 100 | ((void)L, lua_longassert(!iscollectable(obj) || \ |
| 93 | (righttt(obj) && (L == NULL || !isdead(G(L),gcvalue(obj)))))) | 101 | (righttt(obj) && (L == NULL || !isdead(G(L),gcvalue(obj)))))) |
| 94 | 102 | ||
| 95 | 103 | ||
| 96 | /* Macros to set values */ | 104 | /* Macros to set values */ |
| 105 | |||
| 106 | /* set a value's tag */ | ||
| 97 | #define settt_(o,t) ((o)->tt_=(t)) | 107 | #define settt_(o,t) ((o)->tt_=(t)) |
| 98 | 108 | ||
| 99 | 109 | ||
| 110 | /* main macro to copy values (from 'obj1' to 'obj2') */ | ||
| 100 | #define setobj(L,obj1,obj2) \ | 111 | #define setobj(L,obj1,obj2) \ |
| 101 | { TValue *io1=(obj1); const TValue *io2=(obj2); \ | 112 | { TValue *io1=(obj1); const TValue *io2=(obj2); \ |
| 102 | io1->value_ = io2->value_; io1->tt_ = io2->tt_; \ | 113 | io1->value_ = io2->value_; settt_(io1, io2->tt_); \ |
| 103 | checkliveness(L,io1); lua_assert(!isreallyempty(io1)); } | 114 | checkliveness(L,io1); lua_assert(!isnonstrictnil(io1)); } |
| 104 | 115 | ||
| 105 | /* | 116 | /* |
| 106 | ** different types of assignments, according to destination | 117 | ** Different types of assignments, according to source and destination. |
| 118 | ** (They are mostly equal now, but may be different in the future.) | ||
| 107 | */ | 119 | */ |
| 108 | 120 | ||
| 109 | /* from stack to stack */ | 121 | /* from stack to stack */ |
| @@ -118,13 +130,16 @@ typedef struct TValue { | |||
| 118 | #define setobj2t setobj | 130 | #define setobj2t setobj |
| 119 | 131 | ||
| 120 | 132 | ||
| 121 | 133 | /* | |
| 134 | ** Entries in the Lua stack | ||
| 135 | */ | ||
| 122 | typedef union StackValue { | 136 | typedef union StackValue { |
| 123 | TValue val; | 137 | TValue val; |
| 124 | } StackValue; | 138 | } StackValue; |
| 125 | 139 | ||
| 126 | 140 | ||
| 127 | typedef StackValue *StkId; /* index to stack elements */ | 141 | /* index to stack elements */ |
| 142 | typedef StackValue *StkId; | ||
| 128 | 143 | ||
| 129 | /* convert a 'StackValue' to a 'TValue' */ | 144 | /* convert a 'StackValue' to a 'TValue' */ |
| 130 | #define s2v(o) (&(o)->val) | 145 | #define s2v(o) (&(o)->val) |
| @@ -166,7 +181,7 @@ typedef StackValue *StkId; /* index to stack elements */ | |||
| 166 | /* | 181 | /* |
| 167 | ** macro to detect non-standard nils (used only in assertions) | 182 | ** macro to detect non-standard nils (used only in assertions) |
| 168 | */ | 183 | */ |
| 169 | #define isreallyempty(v) (ttisnil(v) && !ttisstrictnil(v)) | 184 | #define isnonstrictnil(v) (ttisnil(v) && !ttisstrictnil(v)) |
| 170 | 185 | ||
| 171 | 186 | ||
| 172 | /* | 187 | /* |
