[parenscript-devel] ps-compile-file and eval-when, patch included
Red Daly
reddaly at gmail.com
Mon Apr 27 21:06:08 UTC 2009
I have had Parenscript file compilation working in a local version of
Parenscript for a long time, but this feature is still missing from the
official Parenscript. It seems like a logical feature to place into the
main Parenscript project.
Parenscript is useful for creating large Javascript applications and where
there are large software projects there is a need for files. Some
Parenscript interacts with Lisp code, but other Parenscript is written
purely for the front-end. This sort of code belongs in a standalone
Parenscript file.
A naiive file compiler for Parenscript looks like this:
(defun ps-compile-file (source-file)
(with-open-file (input source-file :direction :input)
(let ((end-read-form '#:unique))
(flet ((read-form () (read input nil
end-read-form)))
(do ((form (read-form) (read-form))
(forms nil))
((eql form
end-read-form)
(ps:ps* `(progn ,@(nreverse forms)))))))
However, just as in Lisp, it is helpful to have a little more control when
compiling files than just creating a PROGN with the form and compiling as
if it were any other code. It is useful to have EVAL-WHEN forms to
manipulate the reader and so on. Therefore I have added the idea of
top-level forms, including the EVAL-WHEN special form, to address this
issue.
EVAL-WHEN in Parenscript is similar to EVAL-WHEN in lisp but it takes into
account the fact that when compiling the relevant language is LISP, but when
executing the relevant language is Parenscript. An example of using
EVAL-WHEN to define an IN-PACKAGE macro to manipulate the reader:
(defpsmacro in-package (package-designator)
`(eval-when (:compile-toplevel)
(setf cl:*package* (find-package ,package-designator))))
Attached is a patch against the current git repository with this change and
another bug fix.
Best regards,
Red
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/parenscript-devel/attachments/20090427/82e1384a/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ps-compile-file-eval-when-patch.diff
Type: text/x-diff
Size: 8833 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/parenscript-devel/attachments/20090427/82e1384a/attachment.diff>
More information about the parenscript-devel
mailing list