aboutsummaryrefslogtreecommitdiff
path: root/lobject.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-01-06 11:38:31 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-01-06 11:38:31 -0300
commit5ff408d2189c6c24fdf8908db4a31432bbdd6f15 (patch)
treebcd83d7547dab0d5418116eb10f9c601f2f2d3b9 /lobject.h
parente3c83835e7b396ab7db538fb3b052f02d7807dee (diff)
downloadlua-5ff408d2189c6c24fdf8908db4a31432bbdd6f15.tar.gz
lua-5ff408d2189c6c24fdf8908db4a31432bbdd6f15.tar.bz2
lua-5ff408d2189c6c24fdf8908db4a31432bbdd6f15.zip
Changed internal representation of booleans
Instead of an explicit value (field 'b'), true and false use different tag variants. This avoids reading an extra field and results in more direct code. (Most code that uses booleans needs to distinguish between true and false anyway.)
Diffstat (limited to 'lobject.h')
-rw-r--r--lobject.h17
1 files changed, 10 insertions, 7 deletions
diff --git a/lobject.h b/lobject.h
index 7d30b46f..a529ceba 100644
--- a/lobject.h
+++ b/lobject.h
@@ -44,7 +44,6 @@
44typedef union Value { 44typedef union Value {
45 struct GCObject *gc; /* collectable objects */ 45 struct GCObject *gc; /* collectable objects */
46 void *p; /* light userdata */ 46 void *p; /* light userdata */
47 int b; /* booleans */
48 lua_CFunction f; /* light C functions */ 47 lua_CFunction f; /* light C functions */
49 lua_Integer i; /* integer numbers */ 48 lua_Integer i; /* integer numbers */
50 lua_Number n; /* float numbers */ 49 lua_Number n; /* float numbers */
@@ -210,16 +209,20 @@ typedef StackValue *StkId;
210** =================================================================== 209** ===================================================================
211*/ 210*/
212 211
213#define ttisboolean(o) checktag((o), LUA_TBOOLEAN)
214 212
215#define bvalue(o) check_exp(ttisboolean(o), val_(o).b) 213#define LUA_TFALSE (LUA_TBOOLEAN | (1 << 4))
214#define LUA_TTRUE (LUA_TBOOLEAN | (2 << 4))
216 215
217#define bvalueraw(v) ((v).b) 216#define ttisboolean(o) checktype((o), LUA_TBOOLEAN)
217#define ttisfalse(o) checktag((o), LUA_TFALSE)
218#define ttistrue(o) checktag((o), LUA_TTRUE)
218 219
219#define l_isfalse(o) (ttisboolean(o) ? bvalue(o) == 0 : ttisnil(o))
220 220
221#define setbvalue(obj,x) \ 221#define l_isfalse(o) (ttisfalse(o) || ttisnil(o))
222 { TValue *io=(obj); val_(io).b=(x); settt_(io, LUA_TBOOLEAN); } 222
223
224#define setbfvalue(obj) settt_(obj, LUA_TFALSE)
225#define setbtvalue(obj) settt_(obj, LUA_TTRUE)
223 226
224/* }================================================================== */ 227/* }================================================================== */
225 228