The parenscript form EVAL-WHEN was broken due to macroexpansion issues. I have attached a patch that should fix this issue:<br><br>From 904be1cc2eee598491557132e8ed1569a90f27a3 Mon Sep 17 00:00:00 2001<br>From: Red Daly <<a href="mailto:reddaly@gmail.com">reddaly@gmail.com</a>><br>
Date: Sun, 26 Jul 2009 20:22:54 +0000<br>Subject: [PATCH] Fixed eval-when special form and added tests to prevent future breakage.<br><br>---<br> src/compiler.lisp | 50 ++++++++++++++++++++++++++++----------------------<br>
t/ps-tests.lisp | 40 ++++++++++++++++++++++++++++++++++++++++<br> 2 files changed, 68 insertions(+), 22 deletions(-)<br><br>diff --git a/src/compiler.lisp b/src/compiler.lisp<br>index 4fed094..e72fb4e 100644<br>--- a/src/compiler.lisp<br>
+++ b/src/compiler.lisp<br>@@ -162,17 +162,20 @@ compiled to an :expression (the default), a :statement, or a<br> :symbol."))<br> <br> (defun adjust-ps-compilation-level (form level)<br>- (cond ((or (and (consp form) (eq 'progn (car form)))<br>
- (and (symbolp form) (eq :toplevel level)))<br>- level)<br>- ((eq :toplevel level) :inside-toplevel-form)))<br>+ "Given the current *ps-compilation-level*, LEVEL, and the fully macroexpanded<br>
+form, FORM, returns the new value for *ps-compilation-level*."<br>+ (cond ((or (and (consp form) (member (car form)<br>+ '(progn locally macrolet symbol-macrolet compile-file)))<br>+ (and (symbolp form) (eq :toplevel level)))<br>
+ level)<br>+ ((eq :toplevel level) :inside-toplevel-form)))<br>+<br> <br> (defmethod compile-parenscript-form :around (form &key expecting)<br> (assert (if expecting (member expecting '(:expression :statement :symbol)) t))<br>
(if (eq expecting :symbol)<br> (compile-to-symbol form)<br>- (let ((*ps-compilation-level* (adjust-ps-compilation-level form *ps-compilation-level*)))<br>- (call-next-method))))<br>+ (call-next-method)))<br>
<br> (defun compile-to-symbol (form)<br> "Compiles the given Parenscript form and guarantees that the<br>@@ -226,22 +229,25 @@ the form cannot be compiled to a symbol."<br> (defmethod compile-parenscript-form ((form cons) &key (expecting :statement))<br>
(multiple-value-bind (form expanded-p)<br> (ps-macroexpand form)<br>- (cond (expanded-p (compile-parenscript-form form :expecting expecting))<br>- ((ps-special-form-p form) (apply (get-ps-special-form (car form)) (cons expecting (cdr form))))<br>
- ((op-form-p form)<br>- `(js:operator ,(ps-convert-op-name (compile-parenscript-form (car form) :expecting :symbol))<br>- ,@(mapcar (lambda (form)<br>- (compile-parenscript-form (ps-macroexpand form) :expecting :expression))<br>
- (cdr form))))<br>- ((funcall-form-p form)<br>- `(js:funcall ,(compile-parenscript-form (if (symbolp (car form))<br>- (maybe-rename-local-function (car form))<br>
- (ps-macroexpand (car form)))<br>- :expecting :expression)<br>- ,@(mapcar (lambda (arg)<br>- (compile-parenscript-form (ps-macroexpand arg) :expecting :expression))<br>
- (cdr form))))<br>- (t (error "Cannot compile ~S to a ParenScript form." form)))))<br>+ (let ((*ps-compilation-level* (if expanded-p<br>+ *ps-compilation-level*<br>
+ (adjust-ps-compilation-level form *ps-compilation-level*))))<br>+ (cond (expanded-p (compile-parenscript-form form :expecting expecting))<br>+ ((ps-special-form-p form) (apply (get-ps-special-form (car form)) (cons expecting (cdr form))))<br>
+ ((op-form-p form)<br>+ `(js:operator ,(ps-convert-op-name (compile-parenscript-form (car form) :expecting :symbol))<br>+ ,@(mapcar (lambda (form)<br>+ (compile-parenscript-form (ps-macroexpand form) :expecting :expression))<br>
+ (cdr form))))<br>+ ((funcall-form-p form)<br>+ `(js:funcall ,(compile-parenscript-form (if (symbolp (car form))<br>+ (maybe-rename-local-function (car form))<br>
+ (ps-macroexpand (car form)))<br>+ :expecting :expression)<br>+ ,@(mapcar (lambda (arg)<br>+ (compile-parenscript-form (ps-macroexpand arg) :expecting :expression))<br>
+ (cdr form))))<br>+ (t (error "Cannot compile ~S to a ParenScript form." form))))))<br> <br> (defvar *ps-gensym-counter* 0)<br> <br>diff --git a/t/ps-tests.lisp b/t/ps-tests.lisp<br>index cd9d4f2..0324c09 100644<br>
--- a/t/ps-tests.lisp<br>+++ b/t/ps-tests.lisp<br>@@ -1129,3 +1129,43 @@ x1 - x1;<br> --x1;<br> ++x1;")<br> <br>+(test-ps-js eval-when-ps-side<br>+ (eval-when (:execute)<br>+ 5)<br>+ "5;")<br>+<br>+(defvar *lisp-output* nil)<br>
+<br>+(test eval-when-lisp-side ()<br>+ (setf *lisp-output* 'original-value)<br>+ (let ((js-output (normalize-js-code <br>+ (ps-doc* `(eval-when (:compile-toplevel)<br>+ (setf *lisp-output* 'it-works))))))<br>
+ (is (eql 'it-works *lisp-output*))<br>+ (is (string= "" js-output))))<br>+<br>+(defpsmacro my-in-package (package-name)<br>+ `(eval-when (:compile-toplevel)<br>+ (setf *lisp-output* ,package-name)))<br>
+<br>+(test eval-when-macro-expansion ()<br>+ (setf *lisp-output* 'original-value)<br>+ (let ((js-output (normalize-js-code <br>+ (ps-doc* `(progn<br>+ (my-in-package :cl-user)<br>+ 3)))))<br>
+ (declare (ignore js-output))<br>+ (is (eql :cl-user *lisp-output*))))<br>+ ;(is (string= "" js-output))))<br>+<br>+(test eval-when-macrolet-expansion ()<br>+ (setf *lisp-output* 'original-value)<br>
+ (let ((js-output (normalize-js-code <br>+ (ps-doc* `(macrolet ((my-in-package2 (package-name)<br>+ `(eval-when (:compile-toplevel)<br>+ (setf *lisp-output* ,package-name))))<br>
+ (my-in-package2 :cl-user)<br>+ 3)))))<br>+ (declare (ignore js-output))<br>+ (is (eql :cl-user *lisp-output*))))<br>+ ;(is (string= "" js-output))))<br>-- <br>1.5.4.3<br>
<br><br>