diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-03-21 11:23:21 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-03-21 11:23:21 -0300 |
| commit | 0593256707ceddb1bc9cd4b25b822a7fbcfedd66 (patch) | |
| tree | 6c6859b94086b71b27409b565ed34c114f03e7f8 /lobject.h | |
| parent | ce6f5502c99ce9a367e25b678e375db6f8164d73 (diff) | |
| download | lua-0593256707ceddb1bc9cd4b25b822a7fbcfedd66.tar.gz lua-0593256707ceddb1bc9cd4b25b822a7fbcfedd66.tar.bz2 lua-0593256707ceddb1bc9cd4b25b822a7fbcfedd66.zip | |
'luaH_get' functions return tag of the result
Undoing previous commit. Returning TValue increases code size without
any visible gains. Returning the tag is a little simpler than returning
a special code (HOK/HNOTFOUND) and the tag is useful by itself in
some cases.
Diffstat (limited to 'lobject.h')
| -rw-r--r-- | lobject.h | 26 |
1 files changed, 8 insertions, 18 deletions
| @@ -75,7 +75,6 @@ typedef struct TValue { | |||
| 75 | 75 | ||
| 76 | /* raw type tag of a TValue */ | 76 | /* raw type tag of a TValue */ |
| 77 | #define rawtt(o) ((o)->tt_) | 77 | #define rawtt(o) ((o)->tt_) |
| 78 | #define rawttV(o) ((o).tt_) | ||
| 79 | 78 | ||
| 80 | /* tag with no variants (bits 0-3) */ | 79 | /* tag with no variants (bits 0-3) */ |
| 81 | #define novariant(t) ((t) & 0x0F) | 80 | #define novariant(t) ((t) & 0x0F) |
| @@ -83,18 +82,14 @@ typedef struct TValue { | |||
| 83 | /* type tag of a TValue (bits 0-3 for tags + variant bits 4-5) */ | 82 | /* type tag of a TValue (bits 0-3 for tags + variant bits 4-5) */ |
| 84 | #define withvariant(t) ((t) & 0x3F) | 83 | #define withvariant(t) ((t) & 0x3F) |
| 85 | #define ttypetag(o) withvariant(rawtt(o)) | 84 | #define ttypetag(o) withvariant(rawtt(o)) |
| 86 | #define ttypetagV(o) withvariant(rawttV(o)) | ||
| 87 | 85 | ||
| 88 | /* type of a TValue */ | 86 | /* type of a TValue */ |
| 89 | #define ttype(o) (novariant(rawtt(o))) | 87 | #define ttype(o) (novariant(rawtt(o))) |
| 90 | #define ttypeV(o) (novariant(rawttV(o))) | ||
| 91 | 88 | ||
| 92 | 89 | ||
| 93 | /* Macros to test type */ | 90 | /* Macros to test type */ |
| 94 | #define checktag(o,t) (rawtt(o) == (t)) | 91 | #define checktag(o,t) (rawtt(o) == (t)) |
| 95 | #define checktagV(o,t) (rawttV(o) == (t)) | ||
| 96 | #define checktype(o,t) (ttype(o) == (t)) | 92 | #define checktype(o,t) (ttype(o) == (t)) |
| 97 | #define checktypeV(o,t) (ttypeV(o) == (t)) | ||
| 98 | 93 | ||
| 99 | 94 | ||
| 100 | /* Macros for internal tests */ | 95 | /* Macros for internal tests */ |
| @@ -117,7 +112,6 @@ typedef struct TValue { | |||
| 117 | 112 | ||
| 118 | /* set a value's tag */ | 113 | /* set a value's tag */ |
| 119 | #define settt_(o,t) ((o)->tt_=(t)) | 114 | #define settt_(o,t) ((o)->tt_=(t)) |
| 120 | #define setttV_(o,t) ((o).tt_=(t)) | ||
| 121 | 115 | ||
| 122 | 116 | ||
| 123 | /* main macro to copy values (from 'obj2' to 'obj1') */ | 117 | /* main macro to copy values (from 'obj2' to 'obj1') */ |
| @@ -126,11 +120,6 @@ typedef struct TValue { | |||
| 126 | io1->value_ = io2->value_; settt_(io1, io2->tt_); \ | 120 | io1->value_ = io2->value_; settt_(io1, io2->tt_); \ |
| 127 | checkliveness(L,io1); lua_assert(!isnonstrictnil(io1)); } | 121 | checkliveness(L,io1); lua_assert(!isnonstrictnil(io1)); } |
| 128 | 122 | ||
| 129 | #define setobjV(L,obj1,obj2) \ | ||
| 130 | { TValue *io1=(obj1); const TValue io2=(obj2); \ | ||
| 131 | io1->value_ = io2.value_; settt_(io1, io2.tt_); \ | ||
| 132 | checkliveness(L,io1); lua_assert(!isnonstrictnil(io1)); } | ||
| 133 | |||
| 134 | /* | 123 | /* |
| 135 | ** Different types of assignments, according to source and destination. | 124 | ** Different types of assignments, according to source and destination. |
| 136 | ** (They are mostly equal now, but may be different in the future.) | 125 | ** (They are mostly equal now, but may be different in the future.) |
| @@ -199,16 +188,19 @@ typedef union { | |||
| 199 | /* Value returned for a key not found in a table (absent key) */ | 188 | /* Value returned for a key not found in a table (absent key) */ |
| 200 | #define LUA_VABSTKEY makevariant(LUA_TNIL, 2) | 189 | #define LUA_VABSTKEY makevariant(LUA_TNIL, 2) |
| 201 | 190 | ||
| 202 | /* Special "value" to signal that a fast get is accessing a non-table */ | 191 | /* Special variant to signal that a fast get is accessing a non-table */ |
| 203 | #define LUA_VNOTABLE makevariant(LUA_TNIL, 3) | 192 | #define LUA_VNOTABLE makevariant(LUA_TNIL, 3) |
| 204 | |||
| 205 | #define setnotableV(obj) setttV_(obj, LUA_VNOTABLE) | ||
| 206 | 193 | ||
| 207 | 194 | ||
| 208 | /* macro to test for (any kind of) nil */ | 195 | /* macro to test for (any kind of) nil */ |
| 209 | #define ttisnil(v) checktype((v), LUA_TNIL) | 196 | #define ttisnil(v) checktype((v), LUA_TNIL) |
| 210 | #define ttisnilV(v) checktypeV((v), LUA_TNIL) | ||
| 211 | 197 | ||
| 198 | /* | ||
| 199 | ** Macro to test the result of a table access. Formally, it should | ||
| 200 | ** distinguish between LUA_VEMPTY/LUA_VABSTKEY/LUA_VNOTABLE and | ||
| 201 | ** other tags. As currently nil is equivalent to LUA_VEMPTY, it is | ||
| 202 | ** simpler to just test whether the value is nil. | ||
| 203 | */ | ||
| 212 | #define tagisempty(tag) (novariant(tag) == LUA_TNIL) | 204 | #define tagisempty(tag) (novariant(tag) == LUA_TNIL) |
| 213 | 205 | ||
| 214 | 206 | ||
| @@ -234,7 +226,6 @@ typedef union { | |||
| 234 | ** be accepted as empty.) | 226 | ** be accepted as empty.) |
| 235 | */ | 227 | */ |
| 236 | #define isempty(v) ttisnil(v) | 228 | #define isempty(v) ttisnil(v) |
| 237 | #define isemptyV(v) checktypeV((v), LUA_TNIL) | ||
| 238 | 229 | ||
| 239 | 230 | ||
| 240 | /* macro defining a value corresponding to an absent key */ | 231 | /* macro defining a value corresponding to an absent key */ |
| @@ -346,7 +337,6 @@ typedef struct GCObject { | |||
| 346 | #define ttisnumber(o) checktype((o), LUA_TNUMBER) | 337 | #define ttisnumber(o) checktype((o), LUA_TNUMBER) |
| 347 | #define ttisfloat(o) checktag((o), LUA_VNUMFLT) | 338 | #define ttisfloat(o) checktag((o), LUA_VNUMFLT) |
| 348 | #define ttisinteger(o) checktag((o), LUA_VNUMINT) | 339 | #define ttisinteger(o) checktag((o), LUA_VNUMINT) |
| 349 | #define ttisintegerV(o) checktagV((o), LUA_VNUMINT) | ||
| 350 | 340 | ||
| 351 | #define nvalue(o) check_exp(ttisnumber(o), \ | 341 | #define nvalue(o) check_exp(ttisnumber(o), \ |
| 352 | (ttisinteger(o) ? cast_num(ivalue(o)) : fltvalue(o))) | 342 | (ttisinteger(o) ? cast_num(ivalue(o)) : fltvalue(o))) |
