- (defmacro with-compilation-unit (&body body)
- `(prog1
- (progn
- (setq *compilation-unit-checks* nil)
- (setq *env* (remove-if-not #'binding-declared *env*))
- (setq *fenv* (remove-if-not #'binding-declared *fenv*))
- ,@body)
- (dolist (check *compilation-unit-checks*)
- (funcall check))))
-
- (defun eval (x)
- (let ((code
- (with-compilation-unit
- (ls-compile-toplevel x))))
- (js-eval code)))
-
- ;; Set the initial global environment to be equal to the host global
- ;; environment at this point of the compilation.
- (eval-when-compile
- (let ((c1 (ls-compile `(setq *fenv* ',*fenv*) nil nil))
- (c2 (ls-compile `(setq *env* ',*env*) nil nil))
- (c3 (ls-compile `(setq *variable-counter* ',*variable-counter*) nil nil))
- (c4 (ls-compile `(setq *function-counter* ',*function-counter*) nil nil))
- (c5 (ls-compile `(setq *literal-counter* ',*literal-counter*) nil nil))
- (c6 (ls-compile `(setq *gensym-counter* ',*gensym-counter*) nil nil)))
- (setq *toplevel-compilations*
- (append *toplevel-compilations* (list c1 c2 c3 c4 c5 c6)))))
-
- (js-eval
- (concat "var lisp = {};"
- "lisp.read = " (lookup-function-translation 'ls-read-from-string nil) ";" *newline*
- "lisp.print = " (lookup-function-translation 'print-to-string nil) ";" *newline*
- "lisp.eval = " (lookup-function-translation 'eval nil) ";" *newline*
- "lisp.compile = " (lookup-function-translation 'ls-compile-toplevel nil) ";" *newline*
- "lisp.evalString = function(str){" *newline*
- " return lisp.eval(lisp.read(str));" *newline*
- "}" *newline*
- "lisp.compileString = function(str){" *newline*
- " return lisp.compile(lisp.read(str));" *newline*
- "}" *newline*)))
+ (defmacro with-compilation-unit (&body body)
+ `(prog1
+ (progn
+ (setq *compilation-unit-checks* nil)
+ (clear-undeclared-global-bindings)
+ ,@body)
+ (dolist (check *compilation-unit-checks*)
+ (funcall check))))
+
+ (defun eval (x)
+ (let ((code
+ (with-compilation-unit
+ (ls-compile-toplevel x))))
+ (js-eval code)))
+
+ ;; Set the initial global environment to be equal to the host global
+ ;; environment at this point of the compilation.
+ (eval-when-compile
+ (let ((tmp (ls-compile
+ `(progn
+ (setq *environment* ',*environment*)
+ (setq *variable-counter* ',*variable-counter*)
+ (setq *function-counter* ',*function-counter*)
+ (setq *literal-counter* ',*literal-counter*)
+ (setq *gensym-counter* ',*gensym-counter*)
+ (setq *block-counter* ',*block-counter*)))))
+ (setq *toplevel-compilations*
+ (append *toplevel-compilations* (list tmp)))))
+
+ (js-eval
+ (concat "var lisp = {};"
+ "lisp.read = " (lookup-function-translation 'ls-read-from-string nil) ";" *newline*
+ "lisp.print = " (lookup-function-translation 'print-to-string nil) ";" *newline*
+ "lisp.eval = " (lookup-function-translation 'eval nil) ";" *newline*
+ "lisp.compile = " (lookup-function-translation 'ls-compile-toplevel nil) ";" *newline*
+ "lisp.evalString = function(str){" *newline*
+ " return lisp.eval(lisp.read(str));" *newline*
+ "}" *newline*
+ "lisp.compileString = function(str){" *newline*
+ " return lisp.compile(lisp.read(str));" *newline*
+ "}" *newline*)))