diff --git a/extlib/benz/include/picrin.h b/extlib/benz/include/picrin.h index b1483dd3..84df7381 100644 --- a/extlib/benz/include/picrin.h +++ b/extlib/benz/include/picrin.h @@ -53,7 +53,6 @@ typedef struct { struct pic_object; struct pic_symbol; -struct pic_pair; struct pic_string; struct pic_blob; struct pic_proc; @@ -64,7 +63,6 @@ struct pic_data; typedef struct pic_symbol pic_sym; typedef struct pic_id pic_id; -typedef struct pic_pair pic_pair; typedef void *(*pic_allocf)(void *userdata, void *ptr, size_t n); diff --git a/extlib/benz/include/picrin/object.h b/extlib/benz/include/picrin/object.h index 08acd36c..7e71ef38 100644 --- a/extlib/benz/include/picrin/object.h +++ b/extlib/benz/include/picrin/object.h @@ -120,11 +120,11 @@ struct pic_port { xFILE *file; }; +#define pic_pair_ptr(pic, o) ((struct pic_pair *)pic_obj_ptr(o)) #define pic_vec_ptr(pic, o) ((struct pic_vector *)pic_obj_ptr(o)) #define pic_dict_ptr(pic, v) ((struct pic_dict *)pic_obj_ptr(v)) #define pic_sym_ptr(v) ((pic_sym *)pic_obj_ptr(v)) #define pic_id_ptr(v) ((pic_id *)pic_obj_ptr(v)) -#define pic_pair_ptr(o) ((struct pic_pair *)pic_obj_ptr(o)) #define pic_blob_ptr(v) ((struct pic_blob *)pic_obj_ptr(v)) #define pic_str_ptr(o) ((struct pic_string *)pic_obj_ptr(o)) #define pic_weak_ptr(v) ((struct pic_weak *)pic_obj_ptr(v)) diff --git a/extlib/benz/pair.c b/extlib/benz/pair.c index 6507c49e..a58b6cc4 100644 --- a/extlib/benz/pair.c +++ b/extlib/benz/pair.c @@ -20,53 +20,37 @@ pic_cons(pic_state *pic, pic_value car, pic_value cdr) pic_value pic_car(pic_state *pic, pic_value obj) { - struct pic_pair *pair; - if (! pic_pair_p(pic, obj)) { pic_errorf(pic, "car: pair required, but got ~s", obj); } - pair = pic_pair_ptr(obj); - - return pair->car; + return pic_pair_ptr(pic, obj)->car; } pic_value pic_cdr(pic_state *pic, pic_value obj) { - struct pic_pair *pair; - if (! pic_pair_p(pic, obj)) { pic_errorf(pic, "cdr: pair required, but got ~s", obj); } - pair = pic_pair_ptr(obj); - - return pair->cdr; + return pic_pair_ptr(pic, obj)->cdr; } void pic_set_car(pic_state *pic, pic_value obj, pic_value val) { - struct pic_pair *pair; - if (! pic_pair_p(pic, obj)) { pic_errorf(pic, "pair required"); } - pair = pic_pair_ptr(obj); - - pair->car = val; + pic_pair_ptr(pic, obj)->car = val; } void pic_set_cdr(pic_state *pic, pic_value obj, pic_value val) { - struct pic_pair *pair; - if (! pic_pair_p(pic, obj)) { pic_errorf(pic, "pair required"); } - pair = pic_pair_ptr(obj); - - pair->cdr = val; + pic_pair_ptr(pic, obj)->cdr = val; } pic_value @@ -107,7 +91,7 @@ pic_list_p(pic_state *pic, pic_value obj) /* advance rapid fast-forward; runs 2x faster than local */ for (i = 0; i < 2; ++i) { if (pic_pair_p(pic, rapid)) { - rapid = pic_pair_ptr(rapid)->cdr; + rapid = pic_pair_ptr(pic, rapid)->cdr; } else { return pic_nil_p(pic, rapid); @@ -115,7 +99,7 @@ pic_list_p(pic_state *pic, pic_value obj) } /* advance local */ - local = pic_pair_ptr(local)->cdr; + local = pic_pair_ptr(pic, local)->cdr; if (pic_eq_p(pic, local, rapid)) { return false; @@ -169,7 +153,7 @@ pic_list_ref(pic_state *pic, pic_value list, int i) void pic_list_set(pic_state *pic, pic_value list, int i, pic_value obj) { - pic_pair_ptr(pic_list_tail(pic, list, i))->car = obj; + pic_pair_ptr(pic, pic_list_tail(pic, list, i))->car = obj; } pic_value diff --git a/extlib/benz/read.c b/extlib/benz/read.c index 2a7c99e5..4f26f86f 100644 --- a/extlib/benz/read.c +++ b/extlib/benz/read.c @@ -622,8 +622,8 @@ read_label_set(pic_state *pic, xFILE *file, int i) kh_val(h, it) = val = pic_cons(pic, pic_undef_value(pic), pic_undef_value(pic)); tmp = read(pic, file, c); - pic_pair_ptr(val)->car = pic_car(pic, tmp); - pic_pair_ptr(val)->cdr = pic_cdr(pic, tmp); + pic_pair_ptr(pic, val)->car = pic_car(pic, tmp); + pic_pair_ptr(pic, val)->cdr = pic_cdr(pic, tmp); return val; } diff --git a/extlib/benz/write.c b/extlib/benz/write.c index a65dc804..228bc3d9 100644 --- a/extlib/benz/write.c +++ b/extlib/benz/write.c @@ -119,7 +119,7 @@ write_float(pic_state *pic, double f, xFILE *file) static void write_core(struct writer_control *p, pic_value); static void -write_pair_help(struct writer_control *p, struct pic_pair *pair) +write_pair_help(struct writer_control *p, pic_value pair) { pic_state *pic = p->pic; khash_t(l) *lh = &p->labels; @@ -127,18 +127,18 @@ write_pair_help(struct writer_control *p, struct pic_pair *pair) khiter_t it; int ret; - write_core(p, pair->car); + write_core(p, pic_car(pic, pair)); - if (pic_nil_p(pic, pair->cdr)) { + if (pic_nil_p(pic, pic_cdr(pic, pair))) { return; } - else if (pic_pair_p(pic, pair->cdr)) { + else if (pic_pair_p(pic, pic_cdr(pic, pair))) { /* shared objects */ - if ((it = kh_get(l, lh, pic_obj_ptr(pair->cdr))) != kh_end(lh) && kh_val(lh, it) != -1) { + if ((it = kh_get(l, lh, pic_obj_ptr(pic_cdr(pic, pair)))) != kh_end(lh) && kh_val(lh, it) != -1) { xfprintf(pic, p->file, " . "); - kh_put(v, vh, pic_obj_ptr(pair->cdr), &ret); + kh_put(v, vh, pic_obj_ptr(pic_cdr(pic, pair)), &ret); if (ret == 0) { /* if exists */ xfprintf(pic, p->file, "#%d#", kh_val(lh, it)); return; @@ -149,11 +149,11 @@ write_pair_help(struct writer_control *p, struct pic_pair *pair) xfprintf(pic, p->file, " "); } - write_pair_help(p, pic_pair_ptr(pair->cdr)); + write_pair_help(p, pic_cdr(pic, pair)); if (p->op == OP_WRITE) { - if ((it = kh_get(l, lh, pic_obj_ptr(pair->cdr))) != kh_end(lh) && kh_val(lh, it) != -1) { - it = kh_get(v, vh, pic_obj_ptr(pair->cdr)); + if ((it = kh_get(l, lh, pic_obj_ptr(pic_cdr(pic, pair)))) != kh_end(lh) && kh_val(lh, it) != -1) { + it = kh_get(v, vh, pic_obj_ptr(pic_cdr(pic, pair))); kh_del(v, vh, it); } } @@ -161,57 +161,57 @@ write_pair_help(struct writer_control *p, struct pic_pair *pair) } else { xfprintf(pic, p->file, " . "); - write_core(p, pair->cdr); + write_core(p, pic_cdr(pic, pair)); } } static void -write_pair(struct writer_control *p, struct pic_pair *pair) +write_pair(struct writer_control *p, pic_value pair) { pic_state *pic = p->pic; xFILE *file = p->file; pic_sym *tag; - if (pic_pair_p(pic, pair->cdr) && pic_nil_p(pic, pic_cdr(pic, pair->cdr)) && pic_sym_p(pic, pair->car)) { - tag = pic_sym_ptr(pair->car); + if (pic_pair_p(pic, pic_cdr(pic, pair)) && pic_nil_p(pic, pic_cddr(pic, pair)) && pic_sym_p(pic, pic_car(pic, pair))) { + tag = pic_sym_ptr(pic_car(pic, pair)); if (tag == pic->sQUOTE) { xfprintf(pic, file, "'"); - write_core(p, pic_car(pic, pair->cdr)); + write_core(p, pic_cadr(pic, pair)); return; } else if (tag == pic->sUNQUOTE) { xfprintf(pic, file, ","); - write_core(p, pic_car(pic, pair->cdr)); + write_core(p, pic_cadr(pic, pair)); return; } else if (tag == pic->sUNQUOTE_SPLICING) { xfprintf(pic, file, ",@"); - write_core(p, pic_car(pic, pair->cdr)); + write_core(p, pic_cadr(pic, pair)); return; } else if (tag == pic->sQUASIQUOTE) { xfprintf(pic, file, "`"); - write_core(p, pic_car(pic, pair->cdr)); + write_core(p, pic_cadr(pic, pair)); return; } else if (tag == pic->sSYNTAX_QUOTE) { xfprintf(pic, file, "#'"); - write_core(p, pic_car(pic, pair->cdr)); + write_core(p, pic_cadr(pic, pair)); return; } else if (tag == pic->sSYNTAX_UNQUOTE) { xfprintf(pic, file, "#,"); - write_core(p, pic_car(pic, pair->cdr)); + write_core(p, pic_cadr(pic, pair)); return; } else if (tag == pic->sSYNTAX_UNQUOTE_SPLICING) { xfprintf(pic, file, "#,@"); - write_core(p, pic_car(pic, pair->cdr)); + write_core(p, pic_cadr(pic, pair)); return; } else if (tag == pic->sSYNTAX_QUASIQUOTE) { xfprintf(pic, file, "#`"); - write_core(p, pic_car(pic, pair->cdr)); + write_core(p, pic_cadr(pic, pair)); return; } } @@ -312,7 +312,7 @@ write_core(struct writer_control *p, pic_value obj) write_str(pic, pic_str_ptr(obj), file, p->mode); break; case PIC_TYPE_PAIR: - write_pair(p, pic_pair_ptr(obj)); + write_pair(p, obj); break; case PIC_TYPE_VECTOR: write_vec(p, obj);