shithub: femtolisp

Download patch

ref: 1259c178373aa959a7bd0b7037b6ded11c46c47e
parent: 909b91ffccf636de9cd6f8d65544bd0268c97a92
author: JeffBezanson <jeff.bezanson@gmail.com>
date: Wed Apr 22 20:55:03 EDT 2009

updating interpreter to work better for bootstrapping
adding program mkboot0, which can be run in the interpreter to compile
source files into a stage-0 boot image.


--- /dev/null
+++ b/femtolisp/mkboot0.lsp
@@ -1,0 +1,19 @@
+; -*- scheme -*-
+
+(if (not (bound? 'top-level-value)) (set! top-level-value %eval))
+(if (not (bound? 'set-top-level-value!)) (set! set-top-level-value! set))
+
+(load "compiler.lsp")
+
+(define (compile-file inf)
+  (let ((in  (file inf :read)))
+    (let next ((E (read in)))
+      (if (not (io.eof? in))
+	  (begin (print (compile-thunk (expand E)))
+		 (princ "\n")
+		 (next (read in)))))
+    (io.close in)))
+
+(for-each (lambda (file)
+	    (compile-file file))
+	  (cdr *argv*))
--- a/femtolisp/read.c
+++ b/femtolisp/read.c
@@ -575,8 +575,14 @@
         // cannot see pending labels. in other words:
         // (... #2=#.#0# ... )    OK
         // (... #2=#.(#2#) ... )  DO NOT WANT
-        v = do_read_sexpr(UNBOUND);
-        return toplevel_eval(v);
+        sym = do_read_sexpr(UNBOUND);
+        if (issymbol(sym)) {
+            v = symbol_value(sym);
+            if (v == UNBOUND)
+                raise(list2(UnboundError, sym));
+            return v;
+        }
+        return toplevel_eval(sym);
     case TOK_LABEL:
         // create backreference label
         if (ptrhash_has(&readstate->backrefs, (void*)tokval))