3 ;; Copyright (C) 2012, 2013 David Vazquez
4 ;; Copyright (C) 2012 Raimon Grau
6 ;; This program is free software: you can redistribute it and/or
7 ;; modify it under the terms of the GNU General Public License as
8 ;; published by the Free Software Foundation, either version 3 of the
9 ;; License, or (at your option) any later version.
11 ;; This program is distributed in the hope that it will be useful, but
12 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ;; General Public License for more details.
16 ;; You should have received a copy of the GNU General Public License
17 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
19 ;;; This code is executed when ecmalisp compiles this file
20 ;;; itself. The compiler provides compilation of some special forms,
21 ;;; as well as funcalls and macroexpansion, but no functions. So, we
22 ;;; define the Lisp world from scratch. This code has to define enough
23 ;;; language to the compiler to be able to run.
28 (%compile-defmacro 'defmacro
29 '(lambda (name args &rest body)
31 (%compile-defmacro ',name
32 '(lambda ,(mapcar (lambda (x)
39 (defmacro declaim (&rest decls)
41 ,@(mapcar (lambda (decl) `(!proclaim ',decl)) decls)))
43 (declaim (constant nil t))
47 (defmacro when (condition &body body)
48 `(if ,condition (progn ,@body) nil))
50 (defmacro unless (condition &body body)
51 `(if ,condition nil (progn ,@body)))
53 (defmacro defvar (name value &optional docstring)
55 (unless (boundp ',name) (setq ,name ,value))
56 ,@(when (stringp docstring) `((oset ',name "vardoc" ,docstring)))
59 (defmacro defparameter (name value &optional docstring)
62 ,@(when (stringp docstring) `((oset ',name "vardoc" ,docstring)))
65 (defmacro named-lambda (name args &rest body)
66 (let ((x (gensym "FN")))
67 `(let ((,x (lambda ,args ,@body)))
68 (oset ,x "fname" ,name)
71 (defmacro defun (name args &rest body)
73 (declaim (non-overridable ,name))
75 (named-lambda ,(symbol-name name) ,args
76 ,@(if (and (stringp (car body)) (not (null (cdr body))))
77 `(,(car body) (block ,name ,@(cdr body)))
78 `((block ,name ,@body)))))
84 (defmacro return (&optional value)
85 `(return-from nil ,value))
87 (defmacro while (condition &body body)
88 `(block nil (%while ,condition ,@body)))
90 (defvar *gensym-counter* 0)
91 (defun gensym (&optional (prefix "G"))
92 (setq *gensym-counter* (+ *gensym-counter* 1))
93 (make-symbol (concat-two prefix (integer-to-string *gensym-counter*))))
99 (defun = (x y) (= x y))
100 (defun + (x y) (+ x y))
101 (defun - (x y) (- x y))
102 (defun * (x y) (* x y))
103 (defun / (x y) (/ x y))
104 (defun 1+ (x) (+ x 1))
105 (defun 1- (x) (- x 1))
106 (defun zerop (x) (= x 0))
107 (defun truncate (x y) (floor (/ x y)))
109 (defun eql (x y) (eq x y))
111 (defun not (x) (if x nil t))
113 (defun cons (x y ) (cons x y))
114 (defun consp (x) (consp x))
117 "Return the CAR part of a cons, or NIL if X is null."
120 (defun cdr (x) (cdr x))
121 (defun caar (x) (car (car x)))
122 (defun cadr (x) (car (cdr x)))
123 (defun cdar (x) (cdr (car x)))
124 (defun cddr (x) (cdr (cdr x)))
125 (defun caddr (x) (car (cdr (cdr x))))
126 (defun cdddr (x) (cdr (cdr (cdr x))))
127 (defun cadddr (x) (car (cdr (cdr (cdr x)))))
128 (defun first (x) (car x))
129 (defun second (x) (cadr x))
130 (defun third (x) (caddr x))
131 (defun fourth (x) (cadddr x))
133 (defun list (&rest args) args)
139 (defmacro incf (x &optional (delta 1))
140 `(setq ,x (+ ,x ,delta)))
142 (defmacro decf (x &optional (delta 1))
143 `(setq ,x (- ,x ,delta)))
145 (defmacro push (x place)
146 `(setq ,place (cons ,x ,place)))
148 (defmacro dolist (iter &body body)
149 (let ((var (first iter))
152 (let ((,g!list ,(second iter))
155 (setq ,var (car ,g!list))
157 (setq ,g!list (cdr ,g!list)))
160 (defmacro dotimes (iter &body body)
161 (let ((g!to (gensym))
164 (result (third iter)))
168 (%while (< ,var ,g!to)
173 (defmacro cond (&rest clausules)
176 (if (eq (caar clausules) t)
177 `(progn ,@(cdar clausules))
178 `(if ,(caar clausules)
179 (progn ,@(cdar clausules))
180 (cond ,@(cdr clausules))))))
182 (defmacro case (form &rest clausules)
183 (let ((!form (gensym)))
184 `(let ((,!form ,form))
186 ,@(mapcar (lambda (clausule)
187 (if (eq (car clausule) t)
189 `((eql ,!form ',(car clausule))
193 (defmacro ecase (form &rest clausules)
198 (error "ECASE expression failed."))))))
200 (defmacro and (&rest forms)
211 (defmacro or (&rest forms)
219 `(let ((,g ,(car forms)))
220 (if ,g ,g (or ,@(cdr forms))))))))
222 (defmacro prog1 (form &body body)
223 (let ((value (gensym)))
224 `(let ((,value ,form))
228 (defmacro prog2 (form1 result &body body)
229 `(prog1 (progn ,form1 ,result) ,@body)))
232 ;;; This couple of helper functions will be defined in both Common
233 ;;; Lisp and in Ecmalisp.
234 (defun ensure-list (x)
239 (defun !reduce (func list initial)
244 (funcall func initial (car list)))))
246 ;;; Go on growing the Lisp language in Ecmalisp, with more high
247 ;;; level utilities as well as correct versions of other
251 (defun append-two (list1 list2)
255 (append (cdr list1) list2))))
257 (defun append (&rest lists)
258 (!reduce #'append-two lists '()))
260 (defun revappend (list1 list2)
262 (push (car list1) list2)
263 (setq list1 (cdr list1)))
266 (defun reverse (list)
267 (revappend list '()))
269 (defun list-length (list)
271 (while (not (null list))
273 (setq list (cdr list)))
281 (defun concat-two (s1 s2)
284 (defun mapcar (func list)
287 (cons (funcall func (car list))
288 (mapcar func (cdr list)))))
290 (defun identity (x) x)
293 (mapcar #'identity x))
295 (defun code-char (x) x)
296 (defun char-code (x) x)
297 (defun char= (x y) (= x y))
300 (and (numberp x) (= (floor x) x)))
302 (defun plusp (x) (< 0 x))
303 (defun minusp (x) (< x 0))
306 (or (consp x) (null x)))
308 (defun nthcdr (n list)
309 (while (and (plusp n) list)
311 (setq list (cdr list)))
315 (car (nthcdr n list)))
318 (while (consp (cdr x))
324 (cons (car x) (butlast (cdr x)))))
326 (defun member (x list)
328 (when (eql x (car list))
330 (setq list (cdr list))))
332 (defun remove (x list)
337 (remove x (cdr list)))
339 (cons (car list) (remove x (cdr list))))))
341 (defun remove-if (func list)
345 ((funcall func (car list))
346 (remove-if func (cdr list)))
348 (cons (car list) (remove-if func (cdr list))))))
350 (defun remove-if-not (func list)
354 ((funcall func (car list))
355 (cons (car list) (remove-if-not func (cdr list))))
357 (remove-if-not func (cdr list)))))
359 (defun digit-char-p (x)
360 (if (and (<= #\0 x) (<= x #\9))
364 (defun subseq (seq a &optional b)
371 (error "Unsupported argument."))))
373 (defun parse-integer (string)
376 (size (length string)))
377 (while (< index size)
378 (setq value (+ (* value 10) (digit-char-p (char string index))))
382 (defun some (function seq)
387 (while (< index size)
388 (when (funcall function (char seq index))
389 (return-from some t))
394 (when (funcall function x)
397 (error "Unknown sequence."))))
399 (defun every (function seq)
404 (while (< index size)
405 (unless (funcall function (char seq index))
406 (return-from every nil))
411 (unless (funcall function x)
414 (error "Unknown sequence."))))
416 (defun assoc (x alist)
418 (if (eql x (caar alist))
420 (setq alist (cdr alist))))
424 (cond ((stringp x) x)
425 ((symbolp x) (symbol-name x))
426 (t (char-to-string x))))
428 (defun string= (s1 s2)
431 (defun fdefinition (x)
438 (error "Invalid function"))))
440 (defun disassemble (function)
441 (write-line (lambda-code (fdefinition function)))
444 (defun documentation (x type)
445 "Return the documentation of X. TYPE must be the symbol VARIABLE or FUNCTION."
448 (let ((func (fdefinition x)))
449 (oget func "docstring")))
452 (error "Wrong argument type! it should be a symbol"))
457 (defvar *package-list* nil)
459 (defun make-package (name &optional use)
460 (let ((package (new))
461 (use (mapcar #'find-package-or-fail use)))
462 (oset package "packageName" name)
463 (oset package "symbols" (new))
464 (oset package "exports" (new))
465 (oset package "use" use)
466 (push package *package-list*)
470 (and (objectp x) (in "symbols" x)))
472 (defun find-package (package-designator)
473 (when (packagep package-designator)
474 (return-from find-package package-designator))
475 (let ((name (string package-designator)))
476 (dolist (package *package-list*)
477 (when (string= (package-name package) name)
480 (defun find-package-or-fail (package-designator)
481 (or (find-package package-designator)
482 (error "Package unknown.")))
484 (defun package-name (package-designator)
485 (let ((package (find-package-or-fail package-designator)))
486 (oget package "packageName")))
488 (defun %package-symbols (package-designator)
489 (let ((package (find-package-or-fail package-designator)))
490 (oget package "symbols")))
492 (defun package-use-list (package-designator)
493 (let ((package (find-package-or-fail package-designator)))
494 (oget package "use")))
496 (defun %package-external-symbols (package-designator)
497 (let ((package (find-package-or-fail package-designator)))
498 (oget package "exports")))
500 (defvar *common-lisp-package*
503 (defvar *user-package*
504 (make-package "CL-USER" (list *common-lisp-package*)))
506 (defvar *package* *common-lisp-package*)
508 (defmacro in-package (package-designator)
510 (setq *package* (find-package-or-fail ,package-designator))))
512 ;; This function is used internally to initialize the CL package
513 ;; with the symbols built during bootstrap.
514 (defun %intern-symbol (symbol)
515 (let ((symbols (%package-symbols *common-lisp-package*)))
516 (oset symbol "package" *common-lisp-package*)
517 (oset symbols (symbol-name symbol) symbol)))
519 (defun %find-symbol (name package)
520 (let ((package (find-package-or-fail package)))
521 (let ((symbols (%package-symbols package)))
522 (if (in name symbols)
523 (cons (oget symbols name) t)
524 (dolist (used (package-use-list package) (cons nil nil))
525 (let ((exports (%package-external-symbols used)))
526 (when (in name exports)
527 (return (cons (oget exports name) t)))))))))
529 (defun find-symbol (name &optional (package *package*))
530 (car (%find-symbol name package)))
532 (defun intern (name &optional (package *package*))
533 (let ((result (%find-symbol name package)))
536 (let ((symbols (%package-symbols package)))
538 (let ((symbol (make-symbol name)))
539 (oset symbol "package" package)
540 (oset symbols name symbol))))))
542 (defun symbol-package (symbol)
543 (unless (symbolp symbol)
544 (error "it is not a symbol"))
545 (oget symbol "package"))
547 (defun export (symbols &optional (package *package*))
548 (let ((exports (%package-external-symbols package)))
549 (dolist (symb symbols t)
550 (oset exports (symbol-name symb) symb)))))
553 ;;; The compiler offers some primitives and special forms which are
554 ;;; not found in Common Lisp, for instance, while. So, we grow Common
555 ;;; Lisp a bit to it can execute the rest of the file.
558 (defmacro while (condition &body body)
563 (defmacro eval-when-compile (&body body)
564 `(eval-when (:compile-toplevel :load-toplevel :execute)
567 (defun concat-two (s1 s2)
568 (concatenate 'string s1 s2))
570 (defun setcar (cons new)
571 (setf (car cons) new))
572 (defun setcdr (cons new)
573 (setf (cdr cons) new)))
575 ;;; At this point, no matter if Common Lisp or ecmalisp is compiling
576 ;;; from here, this code will compile on both. We define some helper
577 ;;; functions now for string manipulation and so on. They will be
578 ;;; useful in the compiler, mostly.
580 (defvar *newline* (string (code-char 10)))
582 (defun concat (&rest strs)
583 (!reduce #'concat-two strs ""))
585 (defmacro concatf (variable &body form)
586 `(setq ,variable (concat ,variable (progn ,@form))))
588 ;;; Concatenate a list of strings, with a separator
589 (defun join (list &optional (separator ""))
598 (join (cdr list) separator)))))
600 (defun join-trailing (list &optional (separator ""))
603 (concat (car list) separator (join-trailing (cdr list) separator))))
605 (defun mapconcat (func list)
606 (join (mapcar func list)))
608 ;;; Like CONCAT, but prefix each line with four spaces. Two versions
609 ;;; of this function are available, because the Ecmalisp version is
610 ;;; very slow and bootstraping was annoying.
613 (defun indent (&rest string)
614 (let ((input (join string)))
617 (size (length input)))
618 (when (plusp (length input)) (concatf output " "))
619 (while (< index size)
621 (if (and (char= (char input index) #\newline)
623 (not (char= (char input (1+ index)) #\newline)))
624 (concat (string #\newline) " ")
625 (string (char input index)))))
626 (concatf output str))
631 (defun indent (&rest string)
632 (with-output-to-string (*standard-output*)
633 (with-input-from-string (input (join string))
635 for line = (read-line input nil)
637 do (write-string " ")
638 do (write-line line)))))
641 (defun integer-to-string (x)
646 (concat "-" (integer-to-string (- 0 x))))
649 (while (not (zerop x))
650 (push (mod x 10) digits)
651 (setq x (truncate x 10)))
652 (join (mapcar (lambda (d) (string (char "0123456789" d)))
656 ;;; Wrap X with a Javascript code to convert the result from
657 ;;; Javascript generalized booleans to T or NIL.
659 (concat "(" x "?" (ls-compile t) ": " (ls-compile nil) ")"))
661 ;;; Concatenate the arguments and wrap them with a self-calling
662 ;;; Javascript anonymous function. It is used to make some Javascript
663 ;;; statements valid expressions and provide a private scope as well.
664 ;;; It could be defined as function, but we could do some
665 ;;; preprocessing in the future.
666 (defmacro js!selfcall (&body body)
667 `(concat "(function(){" *newline* (indent ,@body) "})()"))
674 (defun prin1-to-string (form)
676 ((symbolp form) (symbol-name form))
677 ((integerp form) (integer-to-string form))
678 ((stringp form) (concat "\"" (escape-string form) "\""))
680 (let ((name (oget form "fname")))
682 (concat "#<FUNCTION " name ">")
683 (concat "#<FUNCTION>"))))
686 (join-trailing (mapcar #'prin1-to-string (butlast form)) " ")
687 (let ((last (last form)))
688 (if (null (cdr last))
689 (prin1-to-string (car last))
690 (concat (prin1-to-string (car last)) " . " (prin1-to-string (cdr last)))))
693 (concat "#<PACKAGE " (package-name form) ">"))))
695 (defun write-line (x)
697 (write-string *newline*)
701 (write-string "WARNING: ")
705 (write-line (prin1-to-string x))
711 ;;; The Lisp reader, parse strings and return Lisp objects. The main
712 ;;; entry points are `ls-read' and `ls-read-from-string'.
714 (defun make-string-stream (string)
717 (defun %peek-char (stream)
718 (and (< (cdr stream) (length (car stream)))
719 (char (car stream) (cdr stream))))
721 (defun %read-char (stream)
722 (and (< (cdr stream) (length (car stream)))
723 (prog1 (char (car stream) (cdr stream))
724 (setcdr stream (1+ (cdr stream))))))
726 (defun whitespacep (ch)
727 (or (char= ch #\space) (char= ch #\newline) (char= ch #\tab)))
729 (defun skip-whitespaces (stream)
731 (setq ch (%peek-char stream))
732 (while (and ch (whitespacep ch))
734 (setq ch (%peek-char stream)))))
736 (defun terminalp (ch)
737 (or (null ch) (whitespacep ch) (char= #\) ch) (char= #\( ch)))
739 (defun read-until (stream func)
742 (setq ch (%peek-char stream))
743 (while (and ch (not (funcall func ch)))
744 (setq string (concat string (string ch)))
746 (setq ch (%peek-char stream)))
749 (defun skip-whitespaces-and-comments (stream)
751 (skip-whitespaces stream)
752 (setq ch (%peek-char stream))
753 (while (and ch (char= ch #\;))
754 (read-until stream (lambda (x) (char= x #\newline)))
755 (skip-whitespaces stream)
756 (setq ch (%peek-char stream)))))
758 (defun %read-list (stream)
759 (skip-whitespaces-and-comments stream)
760 (let ((ch (%peek-char stream)))
763 (error "Unspected EOF"))
769 (prog1 (ls-read stream)
770 (skip-whitespaces-and-comments stream)
771 (unless (char= (%read-char stream) #\))
772 (error "')' was expected."))))
774 (cons (ls-read stream) (%read-list stream))))))
776 (defun read-string (stream)
779 (setq ch (%read-char stream))
780 (while (not (eql ch #\"))
782 (error "Unexpected EOF"))
784 (setq ch (%read-char stream)))
785 (setq string (concat string (string ch)))
786 (setq ch (%read-char stream)))
789 (defun read-sharp (stream)
791 (ecase (%read-char stream)
793 (list 'function (ls-read stream)))
796 (concat (string (%read-char stream))
797 (read-until stream #'terminalp))))
799 ((string= cname "space") (char-code #\space))
800 ((string= cname "tab") (char-code #\tab))
801 ((string= cname "newline") (char-code #\newline))
802 (t (char-code (char cname 0))))))
804 (let ((feature (read-until stream #'terminalp)))
806 ((string= feature "common-lisp")
807 (ls-read stream) ;ignore
809 ((string= feature "ecmalisp")
812 (error "Unknown reader form.")))))))
814 (defvar *eof* (make-symbol "EOF"))
815 (defun ls-read (stream)
816 (skip-whitespaces-and-comments stream)
817 (let ((ch (%peek-char stream)))
826 (list 'quote (ls-read stream)))
829 (list 'backquote (ls-read stream)))
832 (read-string stream))
835 (if (eql (%peek-char stream) #\@)
836 (progn (%read-char stream) (list 'unquote-splicing (ls-read stream)))
837 (list 'unquote (ls-read stream))))
841 (let ((string (read-until stream #'terminalp)))
842 (if (every #'digit-char-p string)
843 (parse-integer string)
844 (intern (string-upcase string))))))))
846 (defun ls-read-from-string (string)
847 (ls-read (make-string-stream string)))
852 ;;; Translate the Lisp code to Javascript. It will compile the special
853 ;;; forms. Some primitive functions are compiled as special forms
854 ;;; too. The respective real functions are defined in the target (see
855 ;;; the beginning of this file) as well as some primitive functions.
857 (defvar *compilation-unit-checks* '())
859 (defun make-binding (name type value &optional declarations)
860 (list name type value declarations))
862 (defun binding-name (b) (first b))
863 (defun binding-type (b) (second b))
864 (defun binding-value (b) (third b))
865 (defun binding-declarations (b) (fourth b))
867 (defun set-binding-value (b value)
868 (setcar (cddr b) value))
870 (defun set-binding-declarations (b value)
871 (setcar (cdddr b) value))
873 (defun push-binding-declaration (decl b)
874 (set-binding-declarations b (cons decl (binding-declarations b))))
877 (defun make-lexenv ()
878 (list nil nil nil nil))
880 (defun copy-lexenv (lexenv)
883 (defun push-to-lexenv (binding lexenv namespace)
885 (variable (setcar lexenv (cons binding (car lexenv))))
886 (function (setcar (cdr lexenv) (cons binding (cadr lexenv))))
887 (block (setcar (cddr lexenv) (cons binding (caddr lexenv))))
888 (gotag (setcar (cdddr lexenv) (cons binding (cadddr lexenv))))))
890 (defun extend-lexenv (bindings lexenv namespace)
891 (let ((env (copy-lexenv lexenv)))
892 (dolist (binding (reverse bindings) env)
893 (push-to-lexenv binding env namespace))))
895 (defun lookup-in-lexenv (name lexenv namespace)
896 (assoc name (ecase namespace
897 (variable (first lexenv))
898 (function (second lexenv))
899 (block (third lexenv))
900 (gotag (fourth lexenv)))))
902 (defvar *environment* (make-lexenv))
904 (defvar *variable-counter* 0)
905 (defun gvarname (symbol)
906 (concat "v" (integer-to-string (incf *variable-counter*))))
908 (defun translate-variable (symbol)
909 (binding-value (lookup-in-lexenv symbol *environment* 'variable)))
911 (defun extend-local-env (args)
912 (let ((new (copy-lexenv *environment*)))
913 (dolist (symbol args new)
914 (let ((b (make-binding symbol 'lexical-variable (gvarname symbol))))
915 (push-to-lexenv b new 'variable)))))
917 ;;; Toplevel compilations
918 (defvar *toplevel-compilations* nil)
920 (defun toplevel-compilation (string)
921 (push string *toplevel-compilations*))
923 (defun null-or-empty-p (x)
926 (defun get-toplevel-compilations ()
927 (reverse (remove-if #'null-or-empty-p *toplevel-compilations*)))
929 (defun %compile-defmacro (name lambda)
930 (toplevel-compilation (ls-compile `',name))
931 (push-to-lexenv (make-binding name 'macro lambda) *environment* 'function))
933 (defun global-binding (name type namespace)
934 (or (lookup-in-lexenv name *environment* namespace)
935 (let ((b (make-binding name type nil)))
936 (push-to-lexenv b *environment* namespace)
939 (defun claimp (symbol namespace claim)
940 (let ((b (lookup-in-lexenv symbol *environment* namespace)))
941 (and b (member claim (binding-declarations b)))))
943 (defun !proclaim (decl)
946 (dolist (name (cdr decl))
947 (let ((b (global-binding name 'function 'function)))
948 (push-binding-declaration 'notinline b))))
950 (dolist (name (cdr decl))
951 (let ((b (global-binding name 'variable 'variable)))
952 (push-binding-declaration 'constant b))))
954 (dolist (name (cdr decl))
955 (let ((b (global-binding name 'function 'function)))
956 (push-binding-declaration 'non-overridable b))))))
959 (fset 'proclaim #'!proclaim)
963 (defvar *compilations* nil)
965 (defmacro define-compilation (name args &body body)
966 ;; Creates a new primitive `name' with parameters args and
967 ;; @body. The body can access to the local environment through the
968 ;; variable *ENVIRONMENT*.
969 `(push (list ',name (lambda ,args (block ,name ,@body)))
972 (define-compilation if (condition true false)
973 (concat "(" (ls-compile condition) " !== " (ls-compile nil)
974 " ? " (ls-compile true)
975 " : " (ls-compile false)
978 (defvar *lambda-list-keywords* '(&optional &rest))
980 (defun list-until-keyword (list)
981 (if (or (null list) (member (car list) *lambda-list-keywords*))
983 (cons (car list) (list-until-keyword (cdr list)))))
985 (defun lambda-list-required-arguments (lambda-list)
986 (list-until-keyword lambda-list))
988 (defun lambda-list-optional-arguments-with-default (lambda-list)
989 (mapcar #'ensure-list (list-until-keyword (cdr (member '&optional lambda-list)))))
991 (defun lambda-list-optional-arguments (lambda-list)
992 (mapcar #'car (lambda-list-optional-arguments-with-default lambda-list)))
994 (defun lambda-list-rest-argument (lambda-list)
995 (let ((rest (list-until-keyword (cdr (member '&rest lambda-list)))))
997 (error "Bad lambda-list"))
1001 (defun lambda-docstring-wrapper (docstring &rest strs)
1004 "var func = " (join strs) ";" *newline*
1005 "func.docstring = '" docstring "';" *newline*
1006 "return func;" *newline*)
1009 (define-compilation lambda (lambda-list &rest body)
1010 (let ((required-arguments (lambda-list-required-arguments lambda-list))
1011 (optional-arguments (lambda-list-optional-arguments lambda-list))
1012 (rest-argument (lambda-list-rest-argument lambda-list))
1014 ;; Get the documentation string for the lambda function
1015 (when (and (stringp (car body))
1016 (not (null (cdr body))))
1017 (setq documentation (car body))
1018 (setq body (cdr body)))
1019 (let ((n-required-arguments (length required-arguments))
1020 (n-optional-arguments (length optional-arguments))
1021 (*environment* (extend-local-env
1022 (append (ensure-list rest-argument)
1024 optional-arguments))))
1025 (lambda-docstring-wrapper
1028 (join (mapcar #'translate-variable
1029 (append required-arguments optional-arguments))
1032 ;; Check number of arguments
1034 (if required-arguments
1035 (concat "if (arguments.length < " (integer-to-string n-required-arguments)
1036 ") throw 'too few arguments';" *newline*)
1038 (if (not rest-argument)
1039 (concat "if (arguments.length > "
1040 (integer-to-string (+ n-required-arguments n-optional-arguments))
1041 ") throw 'too many arguments';" *newline*)
1043 ;; Optional arguments
1044 (if optional-arguments
1045 (concat "switch(arguments.length){" *newline*
1046 (let ((optional-and-defaults
1047 (lambda-list-optional-arguments-with-default lambda-list))
1051 (while (< idx n-optional-arguments)
1052 (let ((arg (nth idx optional-and-defaults)))
1053 (push (concat "case "
1054 (integer-to-string (+ idx n-required-arguments)) ":" *newline*
1055 (translate-variable (car arg))
1057 (ls-compile (cadr arg))
1061 (push (concat "default: break;" *newline*) cases)
1062 (join (reverse cases))))
1065 ;; &rest/&body argument
1067 (let ((js!rest (translate-variable rest-argument)))
1068 (concat "var " js!rest "= " (ls-compile nil) ";" *newline*
1069 "for (var i = arguments.length-1; i>="
1070 (integer-to-string (+ n-required-arguments n-optional-arguments))
1072 (indent js!rest " = "
1073 "{car: arguments[i], cdr: ") js!rest "};"
1077 (ls-compile-block body t)) *newline*
1080 (define-compilation setq (var val)
1081 (let ((b (lookup-in-lexenv var *environment* 'variable)))
1082 (if (eq (binding-type b) 'lexical-variable)
1083 (concat (binding-value b) " = " (ls-compile val))
1084 (ls-compile `(set ',var ,val)))))
1086 ;;; FFI Variable accessors
1087 (define-compilation js-vref (var)
1090 (define-compilation js-vset (var val)
1091 (concat "(" var " = " (ls-compile val) ")"))
1095 (defun escape-string (string)
1098 (size (length string)))
1099 (while (< index size)
1100 (let ((ch (char string index)))
1101 (when (or (char= ch #\") (char= ch #\\))
1102 (setq output (concat output "\\")))
1103 (when (or (char= ch #\newline))
1104 (setq output (concat output "\\"))
1106 (setq output (concat output (string ch))))
1111 (defvar *literal-symbols* nil)
1112 (defvar *literal-counter* 0)
1115 (concat "l" (integer-to-string (incf *literal-counter*))))
1117 (defun literal (sexp &optional recursive)
1119 ((integerp sexp) (integer-to-string sexp))
1120 ((stringp sexp) (concat "\"" (escape-string sexp) "\""))
1122 (or (cdr (assoc sexp *literal-symbols*))
1124 (s #+common-lisp (concat "{name: \"" (escape-string (symbol-name sexp)) "\"}")
1125 #+ecmalisp (ls-compile `(intern ,(symbol-name sexp)))))
1126 (push (cons sexp v) *literal-symbols*)
1127 (toplevel-compilation (concat "var " v " = " s))
1130 (let ((c (concat "{car: " (literal (car sexp) t) ", "
1131 "cdr: " (literal (cdr sexp) t) "}")))
1135 (toplevel-compilation (concat "var " v " = " c))
1138 (define-compilation quote (sexp)
1141 (define-compilation %while (pred &rest body)
1143 "while(" (ls-compile pred) " !== " (ls-compile nil) "){" *newline*
1144 (indent (ls-compile-block body))
1146 "return " (ls-compile nil) ";" *newline*))
1148 (define-compilation function (x)
1150 ((and (listp x) (eq (car x) 'lambda))
1153 (ls-compile `(symbol-function ',x)))))
1155 (define-compilation eval-when-compile (&rest body)
1156 (eval (cons 'progn body))
1159 (defmacro define-transformation (name args form)
1160 `(define-compilation ,name ,args
1161 (ls-compile ,form)))
1163 (define-compilation progn (&rest body)
1164 (js!selfcall (ls-compile-block body t)))
1166 (defun dynamic-binding-wrapper (bindings body)
1172 "var tmp;" *newline*
1175 (let ((s (ls-compile `(quote ,(car b)))))
1176 (concat "tmp = " s ".value;" *newline*
1177 s ".value = " (cdr b) ";" *newline*
1178 (cdr b) " = tmp;" *newline*)))
1182 "finally {" *newline*
1186 (let ((s (ls-compile `(quote ,(car b)))))
1187 (concat s ".value" " = " (cdr b))))
1189 (concat ";" *newline*)))
1193 (define-compilation let (bindings &rest body)
1194 (let ((bindings (mapcar #'ensure-list bindings)))
1195 (let ((variables (mapcar #'first bindings))
1196 (values (mapcar #'second bindings)))
1197 (let ((cvalues (mapcar #'ls-compile values))
1198 (*environment* (extend-local-env (remove-if #'boundp variables)))
1200 (concat "(function("
1201 (join (mapcar (lambda (x)
1203 (let ((v (gvarname x)))
1204 (push (cons x v) dynamic-bindings)
1206 (translate-variable x)))
1210 (let ((body (ls-compile-block body t)))
1211 (indent (dynamic-binding-wrapper dynamic-bindings body)))
1212 "})(" (join cvalues ",") ")")))))
1215 (defvar *block-counter* 0)
1217 (define-compilation block (name &rest body)
1218 (let ((tr (integer-to-string (incf *block-counter*))))
1219 (let ((b (make-binding name 'block tr)))
1222 (let ((*environment* (extend-lexenv (list b) *environment* 'block)))
1223 (indent "return " (ls-compile `(progn ,@body)) ";" *newline*))
1225 "catch (cf){" *newline*
1226 " if (cf.type == 'block' && cf.id == " tr ")" *newline*
1227 " return cf.value;" *newline*
1229 " throw cf;" *newline*
1232 (define-compilation return-from (name &optional value)
1233 (let ((b (lookup-in-lexenv name *environment* 'block)))
1238 "id: " (binding-value b) ", "
1239 "value: " (ls-compile value) ", "
1240 "message: 'Return from unknown block " (symbol-name name) ".'"
1242 (error (concat "Unknown block `" (symbol-name name) "'.")))))
1245 (define-compilation catch (id &rest body)
1247 "var id = " (ls-compile id) ";" *newline*
1249 (indent "return " (ls-compile `(progn ,@body))
1252 "catch (cf){" *newline*
1253 " if (cf.type == 'catch' && cf.id == id)" *newline*
1254 " return cf.value;" *newline*
1256 " throw cf;" *newline*
1259 (define-compilation throw (id &optional value)
1263 "id: " (ls-compile id) ", "
1264 "value: " (ls-compile value) ", "
1265 "message: 'Throw uncatched.'"
1269 (defvar *tagbody-counter* 0)
1270 (defvar *go-tag-counter* 0)
1273 (or (integerp x) (symbolp x)))
1275 (defun declare-tagbody-tags (tbidx body)
1277 (mapcar (lambda (label)
1278 (let ((tagidx (integer-to-string (incf *go-tag-counter*))))
1279 (make-binding label 'gotag (list tbidx tagidx))))
1280 (remove-if-not #'go-tag-p body))))
1281 (extend-lexenv bindings *environment* 'gotag)))
1283 (define-compilation tagbody (&rest body)
1284 ;; Ignore the tagbody if it does not contain any go-tag. We do this
1285 ;; because 1) it is easy and 2) many built-in forms expand to a
1286 ;; implicit tagbody, so we save some space.
1287 (unless (some #'go-tag-p body)
1288 (return-from tagbody (ls-compile `(progn ,@body nil))))
1289 ;; The translation assumes the first form in BODY is a label
1290 (unless (go-tag-p (car body))
1291 (push (gensym "START") body))
1292 ;; Tagbody compilation
1293 (let ((tbidx (integer-to-string *tagbody-counter*)))
1294 (let ((*environment* (declare-tagbody-tags tbidx body))
1296 (let ((b (lookup-in-lexenv (first body) *environment* 'gotag)))
1297 (setq initag (second (binding-value b))))
1299 "var tagbody_" tbidx " = " initag ";" *newline*
1301 "while (true) {" *newline*
1302 (indent "try {" *newline*
1303 (indent (let ((content ""))
1304 (concat "switch(tagbody_" tbidx "){" *newline*
1305 "case " initag ":" *newline*
1306 (dolist (form (cdr body) content)
1308 (if (not (go-tag-p form))
1309 (indent (ls-compile form) ";" *newline*)
1310 (let ((b (lookup-in-lexenv form *environment* 'gotag)))
1311 (concat "case " (second (binding-value b)) ":" *newline*)))))
1312 "default:" *newline*
1313 " break tbloop;" *newline*
1316 "catch (jump) {" *newline*
1317 " if (jump.type == 'tagbody' && jump.id == " tbidx ")" *newline*
1318 " tagbody_" tbidx " = jump.label;" *newline*
1320 " throw(jump);" *newline*
1323 "return " (ls-compile nil) ";" *newline*))))
1325 (define-compilation go (label)
1326 (let ((b (lookup-in-lexenv label *environment* 'gotag))
1328 ((symbolp label) (symbol-name label))
1329 ((integerp label) (integer-to-string label)))))
1334 "id: " (first (binding-value b)) ", "
1335 "label: " (second (binding-value b)) ", "
1336 "message: 'Attempt to GO to non-existing tag " n "'"
1338 (error (concat "Unknown tag `" n "'.")))))
1341 (define-compilation unwind-protect (form &rest clean-up)
1343 "var ret = " (ls-compile nil) ";" *newline*
1345 (indent "ret = " (ls-compile form) ";" *newline*)
1346 "} finally {" *newline*
1347 (indent (ls-compile-block clean-up))
1349 "return ret;" *newline*))
1352 ;;; A little backquote implementation without optimizations of any
1353 ;;; kind for ecmalisp.
1354 (defun backquote-expand-1 (form)
1360 ((eq (car form) 'unquote)
1362 ((eq (car form) 'backquote)
1363 (backquote-expand-1 (backquote-expand-1 (cadr form))))
1368 ((and (listp s) (eq (car s) 'unquote))
1369 (list 'list (cadr s)))
1370 ((and (listp s) (eq (car s) 'unquote-splicing))
1373 (list 'list (backquote-expand-1 s)))))
1376 (defun backquote-expand (form)
1377 (if (and (listp form) (eq (car form) 'backquote))
1378 (backquote-expand-1 (cadr form))
1381 (defmacro backquote (form)
1382 (backquote-expand-1 form))
1384 (define-transformation backquote (form)
1385 (backquote-expand-1 form))
1389 (defvar *builtins* nil)
1391 (defmacro define-raw-builtin (name args &body body)
1392 ;; Creates a new primitive function `name' with parameters args and
1393 ;; @body. The body can access to the local environment through the
1394 ;; variable *ENVIRONMENT*.
1395 `(push (list ',name (lambda ,args (block ,name ,@body)))
1398 (defmacro define-builtin (name args &body body)
1400 (define-raw-builtin ,name ,args
1401 (let ,(mapcar (lambda (arg) `(,arg (ls-compile ,arg))) args)
1404 ;;; DECLS is a list of (JSVARNAME TYPE LISPFORM) declarations.
1405 (defmacro type-check (decls &body body)
1407 ,@(mapcar (lambda (decl)
1408 `(concat "var " ,(first decl) " = " ,(third decl) ";" *newline*))
1410 ,@(mapcar (lambda (decl)
1411 `(concat "if (typeof " ,(first decl) " != '" ,(second decl) "')" *newline*
1412 (indent "throw 'The value ' + "
1414 " + ' is not a type "
1419 (concat "return " (progn ,@body) ";" *newline*)))
1421 (defun num-op-num (x op y)
1422 (type-check (("x" "number" x) ("y" "number" y))
1423 (concat "x" op "y")))
1425 (define-builtin + (x y) (num-op-num x "+" y))
1426 (define-builtin - (x y) (num-op-num x "-" y))
1427 (define-builtin * (x y) (num-op-num x "*" y))
1428 (define-builtin / (x y) (num-op-num x "/" y))
1430 (define-builtin mod (x y) (num-op-num x "%" y))
1432 (define-builtin < (x y) (js!bool (num-op-num x "<" y)))
1433 (define-builtin > (x y) (js!bool (num-op-num x ">" y)))
1434 (define-builtin = (x y) (js!bool (num-op-num x "==" y)))
1435 (define-builtin <= (x y) (js!bool (num-op-num x "<=" y)))
1436 (define-builtin >= (x y) (js!bool (num-op-num x ">=" y)))
1438 (define-builtin numberp (x)
1439 (js!bool (concat "(typeof (" x ") == \"number\")")))
1441 (define-builtin floor (x)
1442 (type-check (("x" "number" x))
1445 (define-builtin cons (x y)
1446 (concat "({car: " x ", cdr: " y "})"))
1448 (define-builtin consp (x)
1451 "var tmp = " x ";" *newline*
1452 "return (typeof tmp == 'object' && 'car' in tmp);" *newline*)))
1454 (define-builtin car (x)
1456 "var tmp = " x ";" *newline*
1457 "return tmp === " (ls-compile nil)
1458 "? " (ls-compile nil)
1459 ": tmp.car;" *newline*))
1461 (define-builtin cdr (x)
1463 "var tmp = " x ";" *newline*
1464 "return tmp === " (ls-compile nil) "? "
1466 ": tmp.cdr;" *newline*))
1468 (define-builtin setcar (x new)
1469 (type-check (("x" "object" x))
1470 (concat "(x.car = " new ")")))
1472 (define-builtin setcdr (x new)
1473 (type-check (("x" "object" x))
1474 (concat "(x.cdr = " new ")")))
1476 (define-builtin symbolp (x)
1479 "var tmp = " x ";" *newline*
1480 "return (typeof tmp == 'object' && 'name' in tmp);" *newline*)))
1482 (define-builtin make-symbol (name)
1483 (type-check (("name" "string" name))
1486 (define-builtin symbol-name (x)
1487 (concat "(" x ").name"))
1489 (define-builtin set (symbol value)
1490 (concat "(" symbol ").value = " value))
1492 (define-builtin fset (symbol value)
1493 (concat "(" symbol ").function = " value))
1495 (define-builtin boundp (x)
1496 (js!bool (concat "(" x ".value !== undefined)")))
1498 (define-builtin symbol-value (x)
1500 "var symbol = " x ";" *newline*
1501 "var value = symbol.value;" *newline*
1502 "if (value === undefined) throw \"Variable `\" + symbol.name + \"' is unbound.\";" *newline*
1503 "return value;" *newline*))
1505 (define-builtin symbol-function (x)
1507 "var symbol = " x ";" *newline*
1508 "var func = symbol.function;" *newline*
1509 "if (func === undefined) throw \"Function `\" + symbol.name + \"' is undefined.\";" *newline*
1510 "return func;" *newline*))
1512 (define-builtin symbol-plist (x)
1513 (concat "((" x ").plist || " (ls-compile nil) ")"))
1515 (define-builtin lambda-code (x)
1516 (concat "(" x ").toString()"))
1519 (define-builtin eq (x y) (js!bool (concat "(" x " === " y ")")))
1520 (define-builtin equal (x y) (js!bool (concat "(" x " == " y ")")))
1522 (define-builtin char-to-string (x)
1523 (type-check (("x" "number" x))
1524 "String.fromCharCode(x)"))
1526 (define-builtin stringp (x)
1527 (js!bool (concat "(typeof(" x ") == \"string\")")))
1529 (define-builtin string-upcase (x)
1530 (type-check (("x" "string" x))
1533 (define-builtin string-length (x)
1534 (type-check (("x" "string" x))
1537 (define-raw-builtin slice (string a &optional b)
1539 "var str = " (ls-compile string) ";" *newline*
1540 "var a = " (ls-compile a) ";" *newline*
1543 (concat "b = " (ls-compile b) ";" *newline*)
1545 "return str.slice(a,b);" *newline*))
1547 (define-builtin char (string index)
1548 (type-check (("string" "string" string)
1549 ("index" "number" index))
1550 "string.charCodeAt(index)"))
1552 (define-builtin concat-two (string1 string2)
1553 (type-check (("string1" "string" string1)
1554 ("string2" "string" string2))
1555 "string1.concat(string2)"))
1557 (define-raw-builtin funcall (func &rest args)
1558 (concat "(" (ls-compile func) ")("
1559 (join (mapcar #'ls-compile args)
1563 (define-raw-builtin apply (func &rest args)
1565 (concat "(" (ls-compile func) ")()")
1566 (let ((args (butlast args))
1567 (last (car (last args))))
1569 "var f = " (ls-compile func) ";" *newline*
1570 "var args = [" (join (mapcar #'ls-compile args)
1573 "var tail = (" (ls-compile last) ");" *newline*
1574 "while (tail != " (ls-compile nil) "){" *newline*
1575 " args.push(tail.car);" *newline*
1576 " tail = tail.cdr;" *newline*
1578 "return f.apply(this, args);" *newline*))))
1580 (define-builtin js-eval (string)
1581 (type-check (("string" "string" string))
1582 "eval.apply(window, [string])"))
1584 (define-builtin error (string)
1585 (js!selfcall "throw " string ";" *newline*))
1587 (define-builtin new () "{}")
1589 (define-builtin objectp (x)
1590 (js!bool (concat "(typeof (" x ") === 'object')")))
1592 (define-builtin oget (object key)
1594 "var tmp = " "(" object ")[" key "];" *newline*
1595 "return tmp == undefined? " (ls-compile nil) ": tmp ;" *newline*))
1597 (define-builtin oset (object key value)
1598 (concat "((" object ")[" key "] = " value ")"))
1600 (define-builtin in (key object)
1601 (js!bool (concat "((" key ") in (" object "))")))
1603 (define-builtin functionp (x)
1604 (js!bool (concat "(typeof " x " == 'function')")))
1606 (define-builtin write-string (x)
1607 (type-check (("x" "string" x))
1612 (let ((b (lookup-in-lexenv x *environment* 'function)))
1613 (and (eq (binding-type b) 'macro)
1616 (defun ls-macroexpand-1 (form)
1617 (let ((macro-binding (macro (car form))))
1619 (let ((expander (binding-value macro-binding)))
1620 (when (listp expander)
1621 (let ((compiled (eval expander)))
1622 ;; The list representation are useful while
1623 ;; bootstrapping, as we can dump the definition of the
1624 ;; macros easily, but they are slow because we have to
1625 ;; evaluate them and compile them now and again. So, let
1626 ;; us replace the list representation version of the
1627 ;; function with the compiled one.
1629 #+ecmalisp (set-binding-value macro-binding compiled)
1630 (setq expander compiled)))
1631 (apply expander (cdr form)))
1634 (defun compile-funcall (function args)
1635 (if (and (symbolp function)
1636 (claimp function 'function 'non-overridable))
1637 (concat (ls-compile `',function) ".function("
1638 (join (mapcar #'ls-compile args)
1641 (concat (ls-compile `#',function) "("
1642 (join (mapcar #'ls-compile args)
1646 (defun ls-compile-block (sexps &optional return-last-p)
1648 (concat (ls-compile-block (butlast sexps))
1649 "return " (ls-compile (car (last sexps))) ";")
1651 (remove-if #'null-or-empty-p (mapcar #'ls-compile sexps))
1652 (concat ";" *newline*))))
1654 (defun ls-compile (sexp)
1657 (let ((b (lookup-in-lexenv sexp *environment* 'variable)))
1659 ((eq (binding-type b) 'lexical-variable)
1661 ((claimp sexp 'variable 'constant)
1662 (concat (ls-compile `',sexp) ".value"))
1664 (ls-compile `(symbol-value ',sexp))))))
1665 ((integerp sexp) (integer-to-string sexp))
1666 ((stringp sexp) (concat "\"" (escape-string sexp) "\""))
1668 (let ((name (car sexp))
1672 ((assoc name *compilations*)
1673 (let ((comp (second (assoc name *compilations*))))
1675 ;; Built-in functions
1676 ((and (assoc name *builtins*)
1677 (not (claimp name 'function 'notinline)))
1678 (let ((comp (second (assoc name *builtins*))))
1682 (ls-compile (ls-macroexpand-1 sexp))
1683 (compile-funcall name args))))))))
1685 (defun ls-compile-toplevel (sexp)
1686 (let ((*toplevel-compilations* nil))
1688 ((and (consp sexp) (eq (car sexp) 'progn))
1689 (let ((subs (mapcar #'ls-compile-toplevel (cdr sexp))))
1690 (join (remove-if #'null-or-empty-p subs))))
1692 (let ((code (ls-compile sexp)))
1693 (concat (join-trailing (get-toplevel-compilations)
1694 (concat ";" *newline*))
1696 (concat code ";" *newline*)
1700 ;;; Once we have the compiler, we define the runtime environment and
1701 ;;; interactive development (eval), which works calling the compiler
1702 ;;; and evaluating the Javascript result globally.
1706 (defmacro with-compilation-unit (&body body)
1709 (setq *compilation-unit-checks* nil)
1711 (dolist (check *compilation-unit-checks*)
1716 (with-compilation-unit
1717 (ls-compile-toplevel x))))
1720 (export '(* *gensym-counter* *package* + - / 1+ 1- < <= = = > >= and append
1721 apply assoc atom block boundp boundp butlast caar cadddr
1722 caddr cadr car car case catch cdar cdddr cddr cdr cdr char
1723 char-code char= code-char cond cons consp copy-list decf
1724 declaim defparameter defun defvar digit-char-p disassemble
1725 documentation dolist dotimes ecase eq eql equal error eval
1726 every export fdefinition find-package find-symbol first
1727 fourth fset funcall function functionp gensym go identity
1728 in-package incf integerp integerp intern lambda-code last
1729 length let list listp make-package make-symbol mapcar
1730 member minusp mod nil not nth nthcdr null numberp or
1731 package-name package-use-list packagep plusp
1732 prin1-to-string print proclaim prog1 prog2 pron push quote
1733 remove remove-if remove-if-not return return-from
1734 revappend reverse second set setq some string-upcase
1735 string string= stringp subseq symbol-function symbol-name
1736 symbol-package symbol-plist symbol-value symbolp t tagbody
1737 third throw truncate unless unwind-protect variable warn
1738 when write-line write-string zerop))
1740 (setq *package* *user-package*)
1742 (js-eval "var lisp")
1743 (js-vset "lisp" (new))
1744 (js-vset "lisp.read" #'ls-read-from-string)
1745 (js-vset "lisp.print" #'prin1-to-string)
1746 (js-vset "lisp.eval" #'eval)
1747 (js-vset "lisp.compile" #'ls-compile-toplevel)
1748 (js-vset "lisp.evalString" (lambda (str) (eval (ls-read-from-string str))))
1749 (js-vset "lisp.compileString" (lambda (str) (ls-compile-toplevel (ls-read-from-string str))))
1751 ;; Set the initial global environment to be equal to the host global
1752 ;; environment at this point of the compilation.
1754 (toplevel-compilation
1757 ,@(mapcar (lambda (s) `(%intern-symbol (js-vref ,(cdr s))))
1759 (setq *literal-symbols* ',*literal-symbols*)
1760 (setq *environment* ',*environment*)
1761 (setq *variable-counter* ,*variable-counter*)
1762 (setq *gensym-counter* ,*gensym-counter*)
1763 (setq *block-counter* ,*block-counter*)))))
1766 (toplevel-compilation
1768 `(setq *literal-counter* ,*literal-counter*)))))
1771 ;;; Finally, we provide a couple of functions to easily bootstrap
1772 ;;; this. It just calls the compiler with this file as input.
1776 (defun read-whole-file (filename)
1777 (with-open-file (in filename)
1778 (let ((seq (make-array (file-length in) :element-type 'character)))
1779 (read-sequence seq in)
1782 (defun ls-compile-file (filename output)
1783 (setq *compilation-unit-checks* nil)
1784 (with-open-file (out output :direction :output :if-exists :supersede)
1785 (let* ((source (read-whole-file filename))
1786 (in (make-string-stream source)))
1788 for x = (ls-read in)
1790 for compilation = (ls-compile-toplevel x)
1791 when (plusp (length compilation))
1792 do (write-string compilation out))
1793 (dolist (check *compilation-unit-checks*)
1795 (setq *compilation-unit-checks* nil))))
1798 (setq *environment* (make-lexenv))
1799 (setq *literal-symbols* nil)
1800 (setq *variable-counter* 0
1804 (ls-compile-file "ecmalisp.lisp" "ecmalisp.js")))