(cos_print_object): New function.
authorMORIOKA Tomohiko <tomo.git@chise.org>
Tue, 16 Apr 2013 08:48:56 +0000 (17:48 +0900)
committerMORIOKA Tomohiko <tomo.git@chise.org>
Tue, 16 Apr 2013 08:48:56 +0000 (17:48 +0900)
print.c

diff --git a/print.c b/print.c
index 2698189..0a8952b 100644 (file)
--- 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;
     }
 }
       return i;
     }
 }
+
+
+void
+cos_print_object (COS_object obj)
+{
+  if ( obj == NULL )
+    printf ("#<NULL>", 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);
+}