From 5bccb7e18630391bfb2e65a39627899daf4d2edf Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20V=C3=A1zquez?= Date: Fri, 5 Jul 2013 17:32:45 +0200 Subject: [PATCH] Migrate literals --- jscl.lisp | 2 +- src/compiler.lisp | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/jscl.lisp b/jscl.lisp index 7abeb3e..e613f7b 100644 --- a/jscl.lisp +++ b/jscl.lisp @@ -100,7 +100,7 @@ ;; not collide with the compiler itself. (late-compile `(progn - (progn ,@(mapcar (lambda (s) `(%intern-symbol (%js-vref ,(cdr s)))) + (progn ,@(mapcar (lambda (s) `(%intern-symbol (%js-vref ,(string (cdr s))))) (remove-if-not #'symbolp *literal-table* :key #'car))) (setq *literal-table* ',*literal-table*) (setq *variable-counter* ,*variable-counter*) diff --git a/src/compiler.lisp b/src/compiler.lisp index 931e9a2..a0879b9 100644 --- a/src/compiler.lisp +++ b/src/compiler.lisp @@ -1,6 +1,6 @@ ;;; compiler.lisp --- -;; copyright (C) 2012, 2013 David Vazquez +;; Copyright (C) 2012, 2013 David Vazquez ;; Copyright (C) 2012 Raimon Grau ;; JSCL is free software: you can redistribute it and/or @@ -510,23 +510,24 @@ (let ((head (butlast cons)) (tail (last cons))) `(call |QIList| - ,@(mapcar (lambda (x) `(code ,(literal x t))) head) - (code ,(literal (car tail) t)) - (code ,(literal (cdr tail) t))))) + ,@(mapcar (lambda (x) (literal x t)) head) + ,(literal (car tail) t) + ,(literal (cdr tail) t)))) (defun dump-array (array) (let ((elements (vector-to-list array))) - (list-to-vector (mapcar (lambda (x) `(code ,(literal x))) - elements)))) + (list-to-vector (mapcar #'literal elements)))) (defun dump-string (string) `(call |make_lisp_string| ,string)) (defun literal (sexp &optional recursive) (cond - ((integerp sexp) (integer-to-string sexp)) - ((floatp sexp) (float-to-string sexp)) - ((characterp sexp) (js-escape-string (string sexp))) + ((integerp sexp) sexp) + ((floatp sexp) sexp) + ((characterp sexp) + ;; TODO: Remove selfcall after migration + `(selfcall (return ,(string sexp)))) (t (or (cdr (assoc sexp *literal-table* :test #'eql)) (let ((dumped (typecase sexp @@ -544,11 +545,11 @@ (if (and recursive (not (symbolp sexp))) dumped (let ((jsvar (genlit))) - (push (cons sexp jsvar) *literal-table*) + (push (cons sexp (make-symbol jsvar)) *literal-table*) (toplevel-compilation `(var (,(make-symbol jsvar) ,dumped))) (when (keywordp sexp) (toplevel-compilation `(= ,(get (make-symbol jsvar) "value") ,(make-symbol jsvar)))) - jsvar))))))) + (make-symbol jsvar)))))))) (define-compilation quote (sexp) -- 1.7.10.4