From 222e3618eec7bbbd07683213a41718f3859b3516 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 24 Mar 2014 10:49:20 +0900 Subject: [PATCH 1/2] use uint**_t for nan-boxing --- include/picrin/value.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/picrin/value.h b/include/picrin/value.h index 628259fc..1317cca5 100644 --- a/include/picrin/value.h +++ b/include/picrin/value.h @@ -50,14 +50,14 @@ typedef struct { pic_sym sym; char c; }; - unsigned int type_; + uint32_t type_; }; } u; } pic_value; -#define pic_ptr(v) ((void *)((long long)0xffffffffffff & (long long)(v).u.data)) -#define pic_vtype(v) (((unsigned)0xfff00000 >= (v).u.type_) ? PIC_VTYPE_FLOAT : (((v).u.type_ & 0xf0000)>>16)) -#define pic_init_value(v,vtype) (((v).u.type_ = ((unsigned int)0xfff00000|(unsigned int)((vtype)<<16))), (v).u.i = 0) +#define pic_ptr(v) ((void *)((uint64_t)0xffffffffffff & (uint64_t)(v).u.data)) +#define pic_vtype(v) (((uint32_t)0xfff00000 >= (v).u.type_) ? PIC_VTYPE_FLOAT : (((v).u.type_ & 0xf0000)>>16)) +#define pic_init_value(v,vtype) (((v).u.type_ = (((uint32_t)0xfff00000)|((uint32_t)((vtype)<<16)))), (v).u.i = 0) #else From d5d721f9dd2b676973638df0dc2894aaf111002a Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 24 Mar 2014 10:55:03 +0900 Subject: [PATCH 2/2] pic_vtype should not evaluate the argument twice --- include/picrin/value.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/picrin/value.h b/include/picrin/value.h index 1317cca5..69bf2139 100644 --- a/include/picrin/value.h +++ b/include/picrin/value.h @@ -56,9 +56,16 @@ typedef struct { } pic_value; #define pic_ptr(v) ((void *)((uint64_t)0xffffffffffff & (uint64_t)(v).u.data)) -#define pic_vtype(v) (((uint32_t)0xfff00000 >= (v).u.type_) ? PIC_VTYPE_FLOAT : (((v).u.type_ & 0xf0000)>>16)) #define pic_init_value(v,vtype) (((v).u.type_ = (((uint32_t)0xfff00000)|((uint32_t)((vtype)<<16)))), (v).u.i = 0) +static inline enum pic_vtype +pic_vtype(pic_value v) +{ + return 0xfff00000 >= v.u.type_ + ? PIC_VTYPE_FLOAT + : (v.u.type_ & 0xf0000)>>16; +} + #else typedef struct {