- ((symbolp sexp) (ls-compile `(intern ,(escape-string (symbol-name sexp))) *environment*))
- ((consp sexp) (concat "{car: "
- (literal->js (car sexp))
- ", cdr: "
- (literal->js (cdr sexp)) "}"))))
-
-(defvar *literal-counter* 0)
-(defun literal (form)
- (let ((var (concat "l" (integer-to-string (incf *literal-counter*)))))
- (push (concat "var " var " = " (literal->js form)) *toplevel-compilations*)
- var))
+ ((symbolp sexp)
+ #+common-lisp
+ (or (cdr (assoc sexp *literal-symbols*))
+ (let ((v (genlit))
+ (s (concat "{name: \"" (escape-string (symbol-name sexp)) "\"}")))
+ (push (cons sexp v) *literal-symbols*)
+ (push (concat "var " v " = " s) *toplevel-compilations*)
+ v))
+ #+ecmalisp
+ (let ((v (genlit)))
+ (push (concat "var " v " = " (ls-compile `(intern ,(symbol-name sexp))))
+ *toplevel-compilations*)
+ v))
+ ((consp sexp)
+ (let ((c (concat "{car: " (literal (car sexp) t) ", "
+ "cdr: " (literal (cdr sexp) t) "}")))
+ (if recursive
+ c
+ (let ((v (genlit)))
+ (push (concat "var " v " = " c) *toplevel-compilations*)
+ v))))))