Easier bootstrap
authorDavid Vázquez <davazp@gmail.com>
Fri, 3 May 2013 14:59:37 +0000 (15:59 +0100)
committerDavid Vázquez <davazp@gmail.com>
Fri, 3 May 2013 14:59:37 +0000 (15:59 +0100)
jscl.lisp
src/toplevel.lisp

index 6d907a3..7a31191 100644 (file)
--- a/jscl.lisp
+++ b/jscl.lisp
          when (plusp (length compilation))
          do (write-string compilation out)))))
 
+(defun dump-global-environment (stream)
+  (flet ((late-compile (form)
+           (write-string (ls-compile-toplevel form) stream)))
+    ;; Set the initial global environment to be equal to the host global
+    ;; environment at this point of the compilation.
+    (late-compile `(setq *environment* ',*environment*))
+    ;; Set some counter variable properly, so user compiled code will
+    ;; not collide with the compiler itself.
+    (late-compile
+     `(progn
+        ,@(mapcar (lambda (s) `(%intern-symbol (%js-vref ,(cdr s)))) *literal-table*)
+        (setq *literal-table* ',*literal-table*)
+        (setq *variable-counter* ,*variable-counter*)
+        (setq *gensym-counter* ,*gensym-counter*)))
+    (late-compile `(setq *literal-counter* ,*literal-counter*))))
+
 (defun bootstrap ()
   (setq *environment* (make-lexenv))
   (setq *literal-table* nil)
@@ -78,7 +94,8 @@
     (write-string (read-whole-file (source-pathname "prelude.js")) out)
     (dolist (input *source*)
       (when (member (cadr input) '(:target :both))
-        (ls-compile-file (source-pathname (car input) :type "lisp") out))))
+        (ls-compile-file (source-pathname (car input) :type "lisp") out)))
+    (dump-global-environment out))
   ;; Tests
   (with-open-file (out "tests.js" :direction :output :if-exists :supersede)
     (dolist (input (append (directory "tests.lisp")
index d6f8cb4..1fb9d1b 100644 (file)
@@ -79,6 +79,8 @@
 
 (setq *package* *user-package*)
 
+;;; Set some external entry point to the Lisp implementation to the
+;;; console. It would not be necessary when FFI is finished.
 (js-eval "var lisp")
 (%js-vset "lisp" (new))
 (%js-vset "lisp.read" #'ls-read-from-string)
 (%js-vset "lisp.evalString" (lambda (str) (eval (ls-read-from-string str))))
 (%js-vset "lisp.evalInput" (lambda (str) (eval-interactive (ls-read-from-string str))))
 (%js-vset "lisp.compileString" (lambda (str) (ls-compile-toplevel (ls-read-from-string str) t)))
-
-;; Set the initial global environment to be equal to the host global
-;; environment at this point of the compilation.
-(eval-when-compile
-  (toplevel-compilation
-   (ls-compile `(setq *environment* ',*environment*))))
-
-(eval-when-compile
-  (toplevel-compilation
-   (ls-compile
-    `(progn
-       ,@(mapcar (lambda (s) `(%intern-symbol (%js-vref ,(cdr s))))
-                 *literal-table*)
-       (setq *literal-table* ',*literal-table*)
-       (setq *variable-counter* ,*variable-counter*)
-       (setq *gensym-counter* ,*gensym-counter*)))))
-
-(eval-when-compile
-  (toplevel-compilation
-   (ls-compile
-    `(setq *literal-counter* ,*literal-counter*))))