Compute the version number dynamically
[muddle-interpreter.git] / src / print.c
index 9cadda721e44624df77c33f868df69dfe977b379..942ad0d783e4c71d93e13b9a3bfc94ce09be6b48 100644 (file)
@@ -16,6 +16,7 @@ License along with this file. If not, see
 <http://www.gnu.org/licenses/>.
 */
 
+#include "atom.h"
 #include "print.h"
 #include "object.h"
 
@@ -27,22 +28,44 @@ License along with this file. If not, see
 static void
 print_vector_body (const vector_object * o)
 {
-  const object *p = OBJECT_OF_HEAP_PTR (o->body);
+  const object *p = HEAP_OBJECT (o->val.body);
   if (!p)
     return;
-  if (o->len)
+  if (o->val.len)
     print_object (&p[0]);
-  for (uint32_t i = 1; i < o->len; i++)
+  for (uint32_t i = 1; i < o->val.len; i++)
     {
       printf (" ");
       print_object (&p[i]);
     }
 }
 
+static void
+print_uvector_body (const uvector_object * o)
+{
+  const uv_val *p = UV_VAL (o->val.body);
+  if (!p)
+    return;
+  pool_object x;
+  x.type = utype (o);
+  x.rest = 0;
+  if (o->val.len)
+    {
+      x.val = p[0];
+      print_object ((object *) & x);
+    }
+  for (uint32_t i = 1; i < o->val.len; i++)
+    {
+      printf (" ");
+      x.val = p[i];
+      print_object ((object *) & x);
+    }
+}
+
 static void
 print_list_body (const list_object * o)
 {
-  const pool_object *p = POOL_OBJECT (o->head);
+  const pool_object *p = POOL_OBJECT (o->val.head);
   if (!p)
     return;
   print_object ((const object *) p);
@@ -59,11 +82,15 @@ print_object (const object * o)
   switch (o->type)
     {
     case EVALTYPE_FIX32:
-      printf ("%d", o->fix32.val);
+      printf ("%d", o->fix32.val.n);
       break;
     case EVALTYPE_FIX64:
-      printf ("%ld", o->fix64.val);
+      printf ("%ld", o->fix64.val.n);
       break;
+    case EVALTYPE_FALSE:
+      // for now, handle non-primtype print as special case (cf. OBLIST)
+      printf ("#FALSE ");
+      // FALLTHROUGH
     case EVALTYPE_LIST:
       printf ("(");
       print_list_body (&o->list);
@@ -79,7 +106,20 @@ print_object (const object * o)
       print_vector_body (&o->vector);
       printf ("]");
       break;
+    case EVALTYPE_OBLIST:
+      // for now, handle non-primtype print as special case
+      printf ("#OBLIST ");
+      // FALLTHROUGH
+    case EVALTYPE_UVECTOR:
+      printf ("![");
+      print_uvector_body (&o->uvector);
+      printf ("!]");
+      break;
+    case EVALTYPE_ATOM:
+      printf ("%s", atom_pname (o->atom));
+      break;
     default:
+      fprintf (stderr, "Tried to print the unprintable: 0x%x\n", o->type);
       assert (0 && "I don't know how to print that");
     }
 }