diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-10-22 14:08:22 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-10-22 14:08:22 -0300 |
commit | e592f94a643de0bf8d62f6c6128fe752c673f5ac (patch) | |
tree | 50a4c591601eb5aaf53014c1c3039a8e2523ca45 /lobject.h | |
parent | 6e1aec7a677a9891f2f8ca57e039d9984fdc69bc (diff) | |
download | lua-e592f94a643de0bf8d62f6c6128fe752c673f5ac.tar.gz lua-e592f94a643de0bf8d62f6c6128fe752c673f5ac.tar.bz2 lua-e592f94a643de0bf8d62f6c6128fe752c673f5ac.zip |
Details (mostly comments)
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 | /* |