commit 1350a2bcb59ffad48183241fa8f3f1cf31360f35
parent 217e67cb224cbb9bd68a1bce7454b60d50894f79
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Mon, 17 Oct 2011 12:45:49 -0200
more macros to try to make NaN trick work with other sizes of
IEEE float numbers. (It has not been tested with such different
sizes...)
Diffstat:
M | lobject.h | | | 56 | +++++++++++++++++++++++++++++++++++++++----------------- |
1 file changed, 39 insertions(+), 17 deletions(-)
diff --git a/lobject.h b/lobject.h
@@ -1,5 +1,5 @@
/*
-** $Id: lobject.h,v 2.61 2011/07/04 20:29:02 roberto Exp roberto $
+** $Id: lobject.h,v 2.62 2011/09/24 21:12:01 roberto Exp roberto $
** Type definitions for Lua objects
** See Copyright Notice in lua.h
*/
@@ -264,51 +264,73 @@ typedef struct lua_TValue TValue;
** =======================================================
*/
-#if defined(LUA_NANTRICKLE) || defined(LUA_NANTRICKBE)
+#if defined(LUA_NANTRICK) \
+ || defined(LUA_NANTRICK_LE) \
+ || defined(LUA_NANTRICK_BE)
/*
** numbers are represented in the 'd_' field. All other values have the
-** value (NNMARK | tag) in 'tt_'. A number with such pattern would be
+** value (NNMARK | tag) in 'tt__'. A number with such pattern would be
** a "signaled NaN", which is never generated by regular operations by
** the CPU (nor by 'strtod')
*/
#if !defined(NNMARK)
#define NNMARK 0x7FF7A500
+#define NNMASK 0x7FFFFF00
#endif
#undef TValuefields
#undef NILCONSTANT
-#if defined(LUA_NANTRICKLE)
+
+#if defined(LUA_NANTRICK_LE)
+
/* little endian */
#define TValuefields \
- union { struct { Value v_; int tt_; } i; double d_; } u
+ union { struct { Value v__; int tt__; } i; double d__; } u
#define NILCONSTANT {{{NULL}, tag2tt(LUA_TNIL)}}
-#else
+/* field-access macros */
+#define v_(o) ((o)->u.i.v__)
+#define d_(o) ((o)->u.d__)
+#define tt_(o) ((o)->u.i.tt__)
+
+#elif defined(LUA_NANTRICK_BE)
+
/* big endian */
#define TValuefields \
- union { struct { int tt_; Value v_; } i; double d_; } u
+ union { struct { int tt__; Value v__; } i; double d__; } u
#define NILCONSTANT {{tag2tt(LUA_TNIL), {NULL}}}
+/* field-access macros */
+#define v_(o) ((o)->u.i.v__)
+#define d_(o) ((o)->u.d__)
+#define tt_(o) ((o)->u.i.tt__)
+
+#elif !defined(TValuefields)
+#error option 'LUA_NANTRICK' needs declaration for 'TValuefields'
+
#endif
+
+/* correspondence with standard representation */
+#undef val_
+#define val_(o) v_(o)
+#undef num_
+#define num_(o) d_(o)
+
+
#undef numfield
#define numfield /* no such field; numbers are the entire struct */
/* basic check to distinguish numbers from non-numbers */
#undef ttisnumber
-#define ttisnumber(o) (((o)->u.i.tt_ & 0x7fffff00) != NNMARK)
+#define ttisnumber(o) ((tt_(o) & NNMASK) != NNMARK)
#define tag2tt(t) (NNMARK | (t))
-#undef val_
-#define val_(o) ((o)->u.i.v_)
-#undef num_
-#define num_(o) ((o)->u.d_)
-
#undef rttype
-#define rttype(o) (ttisnumber(o) ? LUA_TNUMBER : (o)->u.i.tt_ & 0xff)
+#define rttype(o) (ttisnumber(o) ? LUA_TNUMBER : tt_(o) & 0xff)
#undef settt_
-#define settt_(o,t) ((o)->u.i.tt_=tag2tt(t))
+#define settt_(o,t) (tt_(o) = tag2tt(t))
#undef setnvalue
#define setnvalue(obj,x) \
@@ -326,11 +348,11 @@ typedef struct lua_TValue TValue;
*/
#undef checktag
-#define checktag(o,t) ((o)->u.i.tt_ == tag2tt(t))
+#define checktag(o,t) (tt_(o) == tag2tt(t))
#undef ttisequal
#define ttisequal(o1,o2) \
- (ttisnumber(o1) ? ttisnumber(o2) : ((o1)->u.i.tt_ == (o2)->u.i.tt_))
+ (ttisnumber(o1) ? ttisnumber(o2) : (tt_(o1) == tt_(o2)))