From 5850699d75eda2047f6680422640dd45e65f3279 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 4 Nov 2013 23:37:08 -0500 Subject: [PATCH] force indirect reference to pic_value vtype --- include/picrin/value.h | 19 +++++++++++-------- src/gc.c | 4 ++-- src/port.c | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/include/picrin/value.h b/include/picrin/value.h index cdc47a2c..df451bd0 100644 --- a/include/picrin/value.h +++ b/include/picrin/value.h @@ -27,6 +27,9 @@ typedef struct { } u; } pic_value; +#define pic_vtype(v) \ + ((v).type) + enum pic_tt { /* immediate */ PIC_TT_NIL, @@ -100,14 +103,14 @@ pic_value pic_char_value(char c); #define pic_sym(v) ((v).u.sym) #define pic_char(v) ((v).u.c) -#define pic_nil_p(v) ((v).type == PIC_VTYPE_NIL) -#define pic_true_p(v) ((v).type == PIC_VTYPE_TRUE) -#define pic_false_p(v) ((v).type == PIC_VTYPE_FALSE) -#define pic_undef_p(v) ((v).type == PIC_VTYPE_UNDEF) -#define pic_float_p(v) ((v).type == PIC_VTYPE_FLOAT) -#define pic_int_p(v) ((v).type == PIC_VTYPE_INT) -#define pic_symbol_p(v) ((v).type == PIC_VTYPE_SYMBOL) -#define pic_char_p(v) ((v).type == PIC_VTYPE_CHAR) +#define pic_nil_p(v) (pic_vtype(v) == PIC_VTYPE_NIL) +#define pic_true_p(v) (pic_vtype(v) == PIC_VTYPE_TRUE) +#define pic_false_p(v) (pic_vtype(v) == PIC_VTYPE_FALSE) +#define pic_undef_p(v) (pic_vtype(v) == PIC_VTYPE_UNDEF) +#define pic_float_p(v) (pic_vtype(v) == PIC_VTYPE_FLOAT) +#define pic_int_p(v) (pic_vtype(v) == PIC_VTYPE_INT) +#define pic_symbol_p(v) (pic_vtype(v) == PIC_VTYPE_SYMBOL) +#define pic_char_p(v) (pic_vtype(v) == PIC_VTYPE_CHAR) #define pic_pair_p(v) (pic_type(v) == PIC_TT_PAIR) #define pic_str_p(v) (pic_type(v) == PIC_TT_STRING) #define pic_vec_p(v) (pic_type(v) == PIC_TT_VECTOR) diff --git a/src/gc.c b/src/gc.c index 1d0a3285..e0689e96 100644 --- a/src/gc.c +++ b/src/gc.c @@ -89,7 +89,7 @@ pic_gc_protect(pic_state *pic, pic_value v) { struct pic_object *obj; - if (v.type != PIC_VTYPE_HEAP) { + if (pic_vtype(v) != PIC_VTYPE_HEAP) { return; } obj = pic_obj_ptr(v); @@ -208,7 +208,7 @@ gc_mark(pic_state *pic, pic_value v) { struct pic_object *obj; - if (v.type != PIC_VTYPE_HEAP) + if (pic_vtype(v) != PIC_VTYPE_HEAP) return; obj = pic_obj_ptr(v); diff --git a/src/port.c b/src/port.c index 7c3c0157..a564e465 100644 --- a/src/port.c +++ b/src/port.c @@ -249,7 +249,7 @@ pic_port_eof_object_p(pic_state *pic) pic_get_args(pic, "o", &v); - if (v.type == PIC_VTYPE_EOF) { + if (pic_vtype(v) == PIC_VTYPE_EOF) { return pic_true_value(); } else {