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