From 46fccff806c32ca7acaa2d658ce9c11b9d3db799 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Tue, 5 Nov 2013 00:27:59 -0500 Subject: [PATCH] cleanup --- include/picrin/blob.h | 2 +- include/picrin/port.h | 2 +- include/picrin/proc.h | 4 ++-- include/picrin/value.h | 14 +++++++------- src/pair.c | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/picrin/blob.h b/include/picrin/blob.h index 6c37c2ce..1face9e6 100644 --- a/include/picrin/blob.h +++ b/include/picrin/blob.h @@ -8,7 +8,7 @@ struct pic_blob { }; #define pic_blob_p(v) (pic_type(v) == PIC_TT_BLOB) -#define pic_blob_ptr(v) ((struct pic_blob *)(v).u.data) +#define pic_blob_ptr(v) ((struct pic_blob *)pic_ptr(v)) struct pic_blob *pic_blob_new(pic_state *, char *, int len); diff --git a/include/picrin/port.h b/include/picrin/port.h index c421bb11..d5b2eaee 100644 --- a/include/picrin/port.h +++ b/include/picrin/port.h @@ -23,6 +23,6 @@ struct pic_port { }; #define pic_port_p(v) (pic_type(v) == PIC_TT_PORT) -#define pic_port_ptr(v) ((struct pic_port *)(v).u.data) +#define pic_port_ptr(v) ((struct pic_port *)pic_ptr(v)) #endif diff --git a/include/picrin/proc.h b/include/picrin/proc.h index d1ca2aab..03046abb 100644 --- a/include/picrin/proc.h +++ b/include/picrin/proc.h @@ -21,8 +21,8 @@ struct pic_proc { #define pic_proc_p(o) (pic_type(o) == PIC_TT_PROC) #define pic_env_p(o) (pic_type(o) == PIC_TT_ENV) -#define pic_proc_ptr(o) ((struct pic_proc *)(o).u.data) -#define pic_env_ptr(o) ((struct pic_env *)(o).u.data) +#define pic_proc_ptr(o) ((struct pic_proc *)pic_ptr(o)) +#define pic_env_ptr(o) ((struct pic_env *)pic_ptr(o)) #define pic_proc_cfunc_p(o) (pic_proc_ptr(o)->cfunc_p) diff --git a/include/picrin/value.h b/include/picrin/value.h index df451bd0..4f8caddb 100644 --- a/include/picrin/value.h +++ b/include/picrin/value.h @@ -4,7 +4,7 @@ typedef int pic_sym; enum pic_vtype { - PIC_VTYPE_NIL, + PIC_VTYPE_NIL = 1, PIC_VTYPE_TRUE, PIC_VTYPE_FALSE, PIC_VTYPE_UNDEF, @@ -27,8 +27,8 @@ typedef struct { } u; } pic_value; -#define pic_vtype(v) \ - ((v).type) +#define pic_ptr(v) ((v).u.data) +#define pic_vtype(v) ((v).type) enum pic_tt { /* immediate */ @@ -79,10 +79,10 @@ struct pic_proc; struct pic_port; struct pic_blob; -#define pic_obj_ptr(o) ((struct pic_object *)(o).u.data) -#define pic_pair_ptr(o) ((struct pic_pair *)(o).u.data) -#define pic_str_ptr(o) ((struct pic_string *)(o).u.data) -#define pic_vec_ptr(o) ((struct pic_vector *)(o).u.data) +#define pic_obj_ptr(o) ((struct pic_object *)pic_ptr(o)) +#define pic_pair_ptr(o) ((struct pic_pair *)pic_ptr(o)) +#define pic_str_ptr(o) ((struct pic_string *)pic_ptr(o)) +#define pic_vec_ptr(o) ((struct pic_vector *)pic_ptr(o)) enum pic_tt pic_type(pic_value); const char *pic_type_repr(enum pic_tt); diff --git a/src/pair.c b/src/pair.c index 2f522891..231912cc 100644 --- a/src/pair.c +++ b/src/pair.c @@ -23,7 +23,7 @@ pic_car(pic_state *pic, pic_value obj) if (! pic_pair_p(obj)) { pic_error(pic, "pair required"); } - pair = (struct pic_pair *)obj.u.data; + pair = pic_pair_ptr(obj); return pair->car; } @@ -36,7 +36,7 @@ pic_cdr(pic_state *pic, pic_value obj) if (! pic_pair_p(obj)) { pic_error(pic, "pair required"); } - pair = (struct pic_pair *)obj.u.data; + pair = pic_pair_ptr(obj); return pair->cdr; }