writer writes lists in short form

This commit is contained in:
Yuichi Nishiwaki 2013-10-17 22:42:20 +09:00
parent f64f6bec97
commit e87f632327
3 changed files with 24 additions and 6 deletions

View File

@ -50,7 +50,7 @@ struct pic_symbol {
struct pic_proc;
#define pic_object_ptr(o) ((struct pic_object *)o.u.data)
#define pic_obj_ptr(o) ((struct pic_object *)o.u.data)
#define pic_pair_ptr(o) ((struct pic_pair *)o.u.data)
#define pic_symbol_ptr(o) ((struct pic_symbol *)o.u.data)
@ -70,5 +70,6 @@ pic_value pic_float_value(double);
#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_pair_p(v) (pic_type(v) == PIC_TT_PAIR)
#endif

View File

@ -78,7 +78,7 @@ pic_gc_protect(pic_state *pic, pic_value v)
if (v.type != PIC_VTYPE_HEAP) {
return;
}
obj = pic_object_ptr(v);
obj = pic_obj_ptr(v);
gc_protect(pic, obj);
}
@ -160,7 +160,7 @@ gc_mark(pic_state *pic, pic_value v)
if (v.type != PIC_VTYPE_HEAP)
return;
obj = pic_object_ptr(v);
obj = pic_obj_ptr(v);
gc_mark_object(pic, obj);
}

View File

@ -4,6 +4,8 @@
#include "picrin.h"
#include "picrin/proc.h"
static void write_pair(pic_state *pic, struct pic_pair *pair);
static void
write(pic_state *pic, pic_value obj)
{
@ -19,9 +21,7 @@ write(pic_state *pic, pic_value obj)
break;
case PIC_TT_PAIR:
printf("(");
write(pic, pic_car(pic, obj));
printf(" . ");
write(pic, pic_cdr(pic, obj));
write_pair(pic, pic_pair_ptr(obj));
printf(")");
break;
case PIC_TT_SYMBOL:
@ -39,6 +39,23 @@ write(pic_state *pic, pic_value obj)
}
}
static void
write_pair(pic_state *pic, struct pic_pair *pair)
{
write(pic, pair->car);
if (pic_nil_p(pair->cdr)) {
return;
}
if (pic_pair_p(pair->cdr)) {
printf(" ");
write_pair(pic, pic_pair_ptr(pair->cdr));
return;
}
printf(" . ");
write(pic, pair->cdr);
}
void
pic_debug(pic_state *pic, pic_value obj)
{