On 2/1/10, Vladimir Sedach <[email protected]> wrote:
> I just pushed a patch that should do the right thing; take a look.

That works, but the functionality is missing from ps-compile-stream
(and therefore ps-compile-file), so I've added this too (see patch for
inspiration, or if it's acceptable/modifiable, merge?).

I also wonder if (in case I wasn't clear in my original email) this
actually makes more "sense" for parenscript?

(lambda () nil) => function () {return null;}

(lambda () (values)) => function () { }

(lambda () (values 1 2 3)) => function () { ok, nevermind??? }

Not sure either way.

I don't think my changes have broken anything in the meantime :)
However, while all the tests passed, there's a warning too:

Running other tests:
...........................................................................................................................................;
in: LAMBDA NIL
;     (PARENSCRIPT::PS-COMPILE PARENSCRIPT-TEST::X)
;
; caught WARNING:
;   undefined variable: X
;
; compilation unit finished
;   Undefined variable:
;     X
;   caught 1 WARNING condition
.................................................................................

I could not hunt down (quickly) the cause of this warning, so I
haven't done anything.

Thanks for the good work!

Yong

> Vladimir
>
> 2010/1/27 szergling <[email protected]>:
>> On 1/27/10, Vladimir Sedach <[email protected]> wrote:
>>> I've also found that annoying about macros. I'm going to see what can be
>>> done.
>>>
>>> Vladimir
>>
>> Thank you. Look forward to it.
>>
>> By the way, I think implicit return is a very useful feature.
>>
>> Yong.
>>
>>
>>> 2010/1/26 szergling <[email protected]>:
>>>> Hi folks,
>>>>
>>>> I was wondering if there's an idiom for skipping the generation of a
>>>> form completely at the top-level. This is mildly related to the
>>>> implicit return feature currently being trialled. Here's an example:
>>>> suppose I'm trying to skip over this form:
>>>>
>>>> (in-package :something-something)
>>>>
>>>> by using
>>>>
>>>> (defpsmacro in-package (x) nil)
>>>>
>>>> An in-package form then compiles to "null;"
>>>>
>>>> This spurious output may result in errors (I'm using ps to convert
>>>> my Lisp code to Actionscript).
>>>>
>>>> How about using (values) to indicate explicitly that something
>>>> doesn't have any return values?
>>>>
From a0a1b4c4306dd49f37897eb3f6f5580a5480cd7e Mon Sep 17 00:00:00 2001
From: TY Chew <[email protected]>
Date: Thu, 4 Feb 2010 08:00:12 +1300
Subject: [PATCH] Refactored top-level null handling for use in ps-compile-stream.

---
 src/compilation-interface.lisp |   10 ++++++----
 src/special-forms.lisp         |   23 ++++++++++++-----------
 2 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/src/compilation-interface.lisp b/src/compilation-interface.lisp
index b2afb38..d52a81d 100644
--- a/src/compilation-interface.lisp
+++ b/src/compilation-interface.lisp
@@ -75,10 +75,12 @@ a user-supplied reader instead of the default lisp reader.")
 	      (do ((form (read-form) (read-form))
 		   (compiled-forms nil))
 		  ((eql form end-read-form)
-		     (format nil "~{~A~^;~%~}"
-			     (remove-if
-			      #'(lambda (x) (or (null x) (= 0 (length x))))
-			      (mapcar 'compiled-form-to-string (nreverse compiled-forms)))))
+                   (format nil "~{~A~^;~%~}"
+                           (remove-if
+                            #'(lambda (x) (or (null x) (= 0 (length x))))
+                            (mapcar 'compiled-form-to-string
+                                    (tidy-up-block
+                                     (nreverse compiled-forms))))))
 		(push (ps-compile-statement form) compiled-forms))))
 	js-string))))
 
diff --git a/src/special-forms.lisp b/src/special-forms.lisp
index 22e6b5c..1a43f38 100644
--- a/src/special-forms.lisp
+++ b/src/special-forms.lisp
@@ -242,22 +242,23 @@
       (and (listp form)
            (eq 'js:literal (car form)))))
 
+(defun tidy-up-block (compiled-forms)
+  (let* ((block (flatten-blocks
+                 (remove nil compiled-forms)))
+         (last (last block)))
+    (append (remove-if #'constant-literal-form-p
+                       (butlast block))
+            (if (and (eq *ps-compilation-level* :toplevel)
+                     (equal (car last) '(js:literal "null")))
+                nil
+                (last block)))))
+
 (define-ps-special-form progn (&rest body)
   (let ((body (mapcar #'ps-macroexpand body)))
     (if (and compile-expression? (= 1 (length body)))
         (ps-compile-expression (car body))
         `(,(if compile-expression? 'js:|,| 'js:block)
-           ,@(let* ((block (flatten-blocks
-                            (remove nil (mapcar #'ps-compile body))))
-                    (last (last block)))
-               (append (remove-if #'constant-literal-form-p
-                                  (butlast block))
-                       (if (and (eq *ps-compilation-level* :toplevel)
-                                (listp (car last))
-                                (eq 'js:literal (caar last))
-                                (equal "null" (cadar last)))
-                           nil
-                           (last block))))))))
+           ,@(tidy-up-block (mapcar #'ps-compile body))))))
 
 (define-ps-special-form cond (&rest clauses)
   (if compile-expression?
-- 
1.6.0.4

_______________________________________________
parenscript-devel mailing list
[email protected]
http://common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel

Reply via email to