+ do (let ((compilation (ls-compile-toplevel x)))
+ (when (plusp (length compilation))
+ (write-string compilation out)))))))
+
+(defun dump-global-environment (stream)
+ (flet ((late-compile (form)
+ (write-string (ls-compile-toplevel form) stream)))
+ ;; We assume that environments have a friendly list representation
+ ;; for the compiler and it can be dumped.
+ (dolist (b (lexenv-function *environment*))
+ (when (eq (binding-type b) 'macro)
+ (setf (binding-value b) `(,*magic-unquote-marker* ,(binding-value b)))))
+ (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))))
+ (remove-if-not #'symbolp *literal-table* :key #'car))
+ (setq *literal-table* ',*literal-table*)
+ (setq *variable-counter* ,*variable-counter*)
+ (setq *gensym-counter* ,*gensym-counter*)))
+ (late-compile `(setq *literal-counter* ,*literal-counter*))))
+