Implement global bindings
[muddle-interpreter.git] / src / main.c
index 6c6124eb5bfacf2530675665342404db8f342819..126579f314f24eee260bf6863268df7456d606a3 100644 (file)
@@ -16,10 +16,12 @@ License along with this file. If not, see
 <http://www.gnu.org/licenses/>.
 */
 
+#include "atom.h"
 #include "read.h"
 #include "eval.h"
 #include "print.h"
 #include "object.h"
+#include "oblist.h"
 
 #include <stdio.h>
 #include <sys/mman.h>
@@ -28,8 +30,12 @@ License along with this file. If not, see
 // TODO: put these in interpreter-wide ctx object
 pool_object *pool;
 pool_ptr ptop;
-char *vhp_base;
-char *vhp;
+object *vhp_base;
+heap_ptr vhp;
+vector_object globals;
+
+// oblists (move to ASOCs once implemented)
+uvector_object root;
 
 // TODO: store these in current PROCESS
 frame *cf;
@@ -50,6 +56,8 @@ enum
   READER_OBJCT = 64
 };
 
+void init_standard_env ();
+
 int
 main ()
 {
@@ -71,7 +79,7 @@ main ()
   vhp_base =
     mmap (0, VECTOR_OBJCT * sizeof (object), PROT_READ | PROT_WRITE,
          MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
-  vhp = vhp_base;
+  vhp = 1;
 
   // Reader stack (TODO: dynamically allocate as VECTOR).
   object rst_base[READER_OBJCT];
@@ -85,7 +93,10 @@ main ()
     {
       // mock GC (no object persistence)
       ptop = 1;
-      vhp = vhp_base;
+      vhp = 1;
+      root = oblist_create (13);
+      globals = vector_create (64);
+      init_standard_env ();
       // terminate input
       assert (buf[n - 1] == '\n');
       buf[n - 1] = '\0';
@@ -105,13 +116,18 @@ main ()
       // Eval the thing
       cf->prevcst = cst;
       push_frame (eval, new_tuple (st.pos, 1), 0);
-      while (cf->cont.fn)
+      while (cf->cont.val.fn)
        {
-         cf->cont.fn ();
+         cf->cont.val.fn ();
        }
       // Print the thing
       print_object (&ret);
       printf ("\n");
+      /*
+         // debugging oblists...
+         print_object ((object*) &root);
+         printf ("\n");
+       */
       // Loop!
     }