revert prev commit

This commit is contained in:
Yuichi Nishiwaki 2014-02-17 23:31:12 +09:00
parent ad3aca95a3
commit c3d221f2da
1 changed files with 10 additions and 36 deletions

View File

@ -8,7 +8,7 @@
#include "picrin/blob.h" #include "picrin/blob.h"
#include "picrin/macro.h" #include "picrin/macro.h"
static void write_node(pic_state *, pic_value, XFILE *file); static void write(pic_state *, pic_value, XFILE *file);
static bool static bool
is_quote(pic_state *pic, pic_value pair) is_quote(pic_state *pic, pic_value pair)
@ -38,31 +38,21 @@ is_quasiquote(pic_state *pic, pic_value pair)
&& pic_eq_p(pic_car(pic, pair), pic_symbol_value(pic->sQUASIQUOTE)); && pic_eq_p(pic_car(pic, pair), pic_symbol_value(pic->sQUASIQUOTE));
} }
static int write_depth;
static const int write_max_depth = 50;
static void static void
write_pair(pic_state *pic, struct pic_pair *pair, XFILE *file) write_pair(pic_state *pic, struct pic_pair *pair, XFILE *file)
{ {
if (write_depth >= write_max_depth) { write(pic, pair->car, file);
xfprintf(file, "...");
return;
}
write_node(pic, pair->car, file);
if (pic_nil_p(pair->cdr)) { if (pic_nil_p(pair->cdr)) {
return; return;
} }
if (pic_pair_p(pair->cdr)) { if (pic_pair_p(pair->cdr)) {
xfprintf(file, " "); xfprintf(file, " ");
write_depth++;
write_pair(pic, pic_pair_ptr(pair->cdr), file); write_pair(pic, pic_pair_ptr(pair->cdr), file);
write_depth--;
return; return;
} }
xfprintf(file, " . "); xfprintf(file, " . ");
write_node(pic, pair->cdr, file); write(pic, pair->cdr, file);
} }
static void static void
@ -82,17 +72,10 @@ write_str(pic_state *pic, struct pic_string *str, XFILE *file)
} }
static void static void
write_node(pic_state *pic, pic_value obj, XFILE *file) write(pic_state *pic, pic_value obj, XFILE *file)
{ {
size_t i; size_t i;
if (write_depth >= write_max_depth) {
xfprintf(file, "...");
return;
}
write_depth++;
switch (pic_type(obj)) { switch (pic_type(obj)) {
case PIC_TT_NIL: case PIC_TT_NIL:
xfprintf(file, "()"); xfprintf(file, "()");
@ -106,22 +89,22 @@ write_node(pic_state *pic, pic_value obj, XFILE *file)
case PIC_TT_PAIR: case PIC_TT_PAIR:
if (is_quote(pic, obj)) { if (is_quote(pic, obj)) {
xfprintf(file, "'"); xfprintf(file, "'");
write_node(pic, pic_list_ref(pic, obj, 1), file); write(pic, pic_list_ref(pic, obj, 1), file);
break; break;
} }
else if (is_unquote(pic, obj)) { else if (is_unquote(pic, obj)) {
xfprintf(file, ","); xfprintf(file, ",");
write_node(pic, pic_list_ref(pic, obj, 1), file); write(pic, pic_list_ref(pic, obj, 1), file);
break; break;
} }
else if (is_unquote_splicing(pic, obj)) { else if (is_unquote_splicing(pic, obj)) {
xfprintf(file, ",@"); xfprintf(file, ",@");
write_node(pic, pic_list_ref(pic, obj, 1), file); write(pic, pic_list_ref(pic, obj, 1), file);
break; break;
} }
else if (is_quasiquote(pic, obj)) { else if (is_quasiquote(pic, obj)) {
xfprintf(file, "`"); xfprintf(file, "`");
write_node(pic, pic_list_ref(pic, obj, 1), file); write(pic, pic_list_ref(pic, obj, 1), file);
break; break;
} }
xfprintf(file, "("); xfprintf(file, "(");
@ -170,7 +153,7 @@ write_node(pic_state *pic, pic_value obj, XFILE *file)
case PIC_TT_VECTOR: case PIC_TT_VECTOR:
xfprintf(file, "#("); xfprintf(file, "#(");
for (i = 0; i < pic_vec_ptr(obj)->len; ++i) { for (i = 0; i < pic_vec_ptr(obj)->len; ++i) {
write_node(pic, pic_vec_ptr(obj)->data[i], file); write(pic, pic_vec_ptr(obj)->data[i], file);
if (i + 1 < pic_vec_ptr(obj)->len) { if (i + 1 < pic_vec_ptr(obj)->len) {
xfprintf(file, " "); xfprintf(file, " ");
} }
@ -204,7 +187,7 @@ write_node(pic_state *pic, pic_value obj, XFILE *file)
break; break;
case PIC_TT_SC: case PIC_TT_SC:
xfprintf(file, "#<sc %p: ", pic_ptr(obj)); xfprintf(file, "#<sc %p: ", pic_ptr(obj));
write_node(pic, pic_sc(obj)->expr, file); write(pic, pic_sc(obj)->expr, file);
xfprintf(file, ">"); xfprintf(file, ">");
break; break;
case PIC_TT_LIB: case PIC_TT_LIB:
@ -217,15 +200,6 @@ write_node(pic_state *pic, pic_value obj, XFILE *file)
xfprintf(file, "#<irep %p>", pic_ptr(obj)); xfprintf(file, "#<irep %p>", pic_ptr(obj));
break; break;
} }
write_depth--;
}
static void
write(pic_state *pic, pic_value obj, XFILE *file)
{
write_depth = 0;
write_node(pic, obj, file);
} }
pic_value pic_value