From: MORIOKA Tomohiko Date: Tue, 16 Apr 2013 08:48:56 +0000 (+0900) Subject: (cos_print_object): New function. X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7011b75694bb02fff7f98defbc11ea7260235685;p=chise%2Fconcord.git (cos_print_object): New function. --- diff --git a/print.c b/print.c index 2698189..0a8952b 100644 --- a/print.c +++ b/print.c @@ -234,3 +234,50 @@ cos_utf8_print_char (COS_object character, unsigned char *dest, size_t size) return i; } } + + +void +cos_print_object (COS_object obj) +{ + if ( obj == NULL ) + printf ("#", obj); + else if ( COS_OBJECT_INT_P (obj) ) + printf ("%d", cos_int_value (obj)); + else if ( COS_OBJECT_CHAR_P (obj) ) + { + char id_buf[256]; + + cos_utf8_print_char (obj, id_buf, 256); + printf ("?%s", id_buf); + } + else if ( COS_OBJECT_STRING_P (obj) ) + { + printf ("\"%s\"", cos_string_data (obj)); + } + else if ( COS_OBJECT_SYMBOL_P (obj) ) + { + printf ("%s", cos_string_data (cos_symbol_name (obj))); + } + else if ( COS_OBJECT_CONS_P (obj) ) + { + COS_object rest = COS_CDR (obj); + + printf ("("); + cos_print_object (COS_CAR (obj)); + while ( COS_OBJECT_CONS_P (rest) ) + { + printf (" "); + cos_print_object (COS_CAR (rest)); + rest = COS_CDR (rest); + } + if ( rest != cos_Qnil ) + { + printf (" . "); + cos_print_object (rest); + } + printf (")"); + } + else + printf ("Object[0x%lX] is a fat object.\n", + obj); +}