Fixed symbol macro bug (thanks to Daniel Gackle for the bug report).
authorVladimir Sedach <vsedach@gmail.com>
Thu, 17 Sep 2009 18:18:51 +0000 (12:18 -0600)
committerVladimir Sedach <vsedach@gmail.com>
Thu, 17 Sep 2009 18:18:51 +0000 (12:18 -0600)
src/compiler.lisp
t/ps-tests.lisp

index 9fbba55..a7ae857 100644 (file)
@@ -195,17 +195,16 @@ the form cannot be compiled to a symbol."
   (ps-compile (string form)))
 
 (defmethod ps-compile ((symbol symbol))
-  (when (eq *ps-compilation-level* :toplevel)
-    (multiple-value-bind (expansion expanded-p)
-        (ps-macroexpand symbol)
-      (when expanded-p 
-        (return-from ps-compile (ps-compile expansion)))))
-  (cond ((keywordp symbol) symbol)
-        ((ps-special-form-p (list symbol))
-         (if (ps-reserved-symbol-p symbol)
-             (funcall (get-ps-special-form symbol))
-             (error "Attempting to use Parenscript special form ~a as variable" symbol)))
-        (t `(js:variable ,symbol))))
+  (multiple-value-bind (expansion expanded?)
+      (ps-macroexpand symbol)
+    (if expanded?
+        (ps-compile expansion)
+        (cond ((keywordp symbol) symbol)
+              ((ps-special-form-p (list symbol))
+               (if (ps-reserved-symbol-p symbol)
+                   (funcall (get-ps-special-form symbol))
+                   (error "Attempting to use Parenscript special form ~a as variable" symbol)))
+              (t `(js:variable ,symbol))))))
 
 ;;; operators
 
@@ -267,9 +266,9 @@ the form cannot be compiled to a symbol."
 
 (defun compile-funcall-form (form)
   `(js:funcall
-    ,(ps-compile-expression (if (symbolp (car form))
-                                (maybe-rename-local-function (car form))
-                                (ps-macroexpand (car form))))
+    ,(if (symbolp (car form))
+         `(js:variable ,(maybe-rename-local-function (car form)))
+         (ps-compile-expression (ps-macroexpand (car form))))
     ,@(mapcar #'ps-compile-expression (cdr form))))
 
 (defvar compile-expression?)
index 2350f03..13ec5ff 100644 (file)
@@ -595,6 +595,11 @@ __setf_someThing(_js1, _js2, _js3);")
          tst-sym-macro)
   "2;")
 
+(test-ps-js define-symbol-macro1
+  (progn (define-symbol-macro tst-sym-macro1 2)
+         (foo tst-sym-macro1))
+  "foo(2);")
+
 (test-ps-js expression-progn
   (defun f () (return (progn (foo) (if x 1 2))))
   "function f() {