aboutsummaryrefslogtreecommitdiff
path: root/lobject.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-03-18 15:56:32 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-03-18 15:56:32 -0300
commitce6f5502c99ce9a367e25b678e375db6f8164d73 (patch)
tree47f36dc2f6da96dfda325d7b587f3a20599e9317 /lobject.h
parentba710603811c68fe3a69b3bb98e9038d37489a79 (diff)
downloadlua-ce6f5502c99ce9a367e25b678e375db6f8164d73.tar.gz
lua-ce6f5502c99ce9a367e25b678e375db6f8164d73.tar.bz2
lua-ce6f5502c99ce9a367e25b678e375db6f8164d73.zip
'luaH_get' functions return 'TValue'
Instead of receiving a parameter telling them where to put the result of the query, these functions return the TValue directly. (That is, they return a structure.)
Diffstat (limited to 'lobject.h')
-rw-r--r--lobject.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/lobject.h b/lobject.h
index 81dfd475..69fa6260 100644
--- a/lobject.h
+++ b/lobject.h
@@ -75,6 +75,7 @@ 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_)
78 79
79/* tag with no variants (bits 0-3) */ 80/* tag with no variants (bits 0-3) */
80#define novariant(t) ((t) & 0x0F) 81#define novariant(t) ((t) & 0x0F)
@@ -82,14 +83,18 @@ typedef struct TValue {
82/* type tag of a TValue (bits 0-3 for tags + variant bits 4-5) */ 83/* type tag of a TValue (bits 0-3 for tags + variant bits 4-5) */
83#define withvariant(t) ((t) & 0x3F) 84#define withvariant(t) ((t) & 0x3F)
84#define ttypetag(o) withvariant(rawtt(o)) 85#define ttypetag(o) withvariant(rawtt(o))
86#define ttypetagV(o) withvariant(rawttV(o))
85 87
86/* type of a TValue */ 88/* type of a TValue */
87#define ttype(o) (novariant(rawtt(o))) 89#define ttype(o) (novariant(rawtt(o)))
90#define ttypeV(o) (novariant(rawttV(o)))
88 91
89 92
90/* Macros to test type */ 93/* Macros to test type */
91#define checktag(o,t) (rawtt(o) == (t)) 94#define checktag(o,t) (rawtt(o) == (t))
95#define checktagV(o,t) (rawttV(o) == (t))
92#define checktype(o,t) (ttype(o) == (t)) 96#define checktype(o,t) (ttype(o) == (t))
97#define checktypeV(o,t) (ttypeV(o) == (t))
93 98
94 99
95/* Macros for internal tests */ 100/* Macros for internal tests */
@@ -112,6 +117,7 @@ typedef struct TValue {
112 117
113/* set a value's tag */ 118/* set a value's tag */
114#define settt_(o,t) ((o)->tt_=(t)) 119#define settt_(o,t) ((o)->tt_=(t))
120#define setttV_(o,t) ((o).tt_=(t))
115 121
116 122
117/* main macro to copy values (from 'obj2' to 'obj1') */ 123/* main macro to copy values (from 'obj2' to 'obj1') */
@@ -120,6 +126,11 @@ typedef struct TValue {
120 io1->value_ = io2->value_; settt_(io1, io2->tt_); \ 126 io1->value_ = io2->value_; settt_(io1, io2->tt_); \
121 checkliveness(L,io1); lua_assert(!isnonstrictnil(io1)); } 127 checkliveness(L,io1); lua_assert(!isnonstrictnil(io1)); }
122 128
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
123/* 134/*
124** Different types of assignments, according to source and destination. 135** Different types of assignments, according to source and destination.
125** (They are mostly equal now, but may be different in the future.) 136** (They are mostly equal now, but may be different in the future.)
@@ -188,9 +199,15 @@ typedef union {
188/* Value returned for a key not found in a table (absent key) */ 199/* Value returned for a key not found in a table (absent key) */
189#define LUA_VABSTKEY makevariant(LUA_TNIL, 2) 200#define LUA_VABSTKEY makevariant(LUA_TNIL, 2)
190 201
202/* Special "value" to signal that a fast get is accessing a non-table */
203#define LUA_VNOTABLE makevariant(LUA_TNIL, 3)
204
205#define setnotableV(obj) setttV_(obj, LUA_VNOTABLE)
206
191 207
192/* macro to test for (any kind of) nil */ 208/* macro to test for (any kind of) nil */
193#define ttisnil(v) checktype((v), LUA_TNIL) 209#define ttisnil(v) checktype((v), LUA_TNIL)
210#define ttisnilV(v) checktypeV((v), LUA_TNIL)
194 211
195#define tagisempty(tag) (novariant(tag) == LUA_TNIL) 212#define tagisempty(tag) (novariant(tag) == LUA_TNIL)
196 213
@@ -217,6 +234,7 @@ typedef union {
217** be accepted as empty.) 234** be accepted as empty.)
218*/ 235*/
219#define isempty(v) ttisnil(v) 236#define isempty(v) ttisnil(v)
237#define isemptyV(v) checktypeV((v), LUA_TNIL)
220 238
221 239
222/* macro defining a value corresponding to an absent key */ 240/* macro defining a value corresponding to an absent key */
@@ -328,6 +346,7 @@ typedef struct GCObject {
328#define ttisnumber(o) checktype((o), LUA_TNUMBER) 346#define ttisnumber(o) checktype((o), LUA_TNUMBER)
329#define ttisfloat(o) checktag((o), LUA_VNUMFLT) 347#define ttisfloat(o) checktag((o), LUA_VNUMFLT)
330#define ttisinteger(o) checktag((o), LUA_VNUMINT) 348#define ttisinteger(o) checktag((o), LUA_VNUMINT)
349#define ttisintegerV(o) checktagV((o), LUA_VNUMINT)
331 350
332#define nvalue(o) check_exp(ttisnumber(o), \ 351#define nvalue(o) check_exp(ttisnumber(o), \
333 (ttisinteger(o) ? cast_num(ivalue(o)) : fltvalue(o))) 352 (ttisinteger(o) ? cast_num(ivalue(o)) : fltvalue(o)))