:output-spec output-spec
:pretty-print pretty-print)))))
-(defun compile-script-file (source-file
- &key
- (output-spec :javascript)
- (comp-env (non-nil-comp-env))
- (pretty-print t)
- (output-stream *standard-output*))
- "Compiles the given Parenscript source file and outputs the results
-to the given output stream."
- (setf (comp-env-compiling-toplevel-p comp-env) t)
- (with-open-file (input source-file :direction :input)
- (let ((end-read-form '#:unique))
- (flet ((read-form ()
- (parenscript.reader:read input nil end-read-form)))
- (macrolet ((with-output-stream ((var) &body body)
- `(if (null output-stream)
- (with-output-to-string (,var)
- ,@body)
- (let ((,var output-stream))
- ,@body))))
- (let* ((*compilation-environment* comp-env)
- (compiled
- (do ((form (read-form) (read-form))
- (compiled-forms nil))
- ((eql form end-read-form)
- (progn
- (setf (comp-env-compiling-toplevel-p comp-env) nil)
- (compile-parenscript-form
- comp-env
- `(progn ,@(nreverse compiled-forms)))))
- (let ((tl-compiled-form
- (compile-parenscript-form comp-env form)))
- (push tl-compiled-form compiled-forms)))))
- (with-output-stream (output)
- (translate-ast
- compiled
- :comp-env comp-env
- :output-stream output
- :output-spec output-spec
- :pretty-print pretty-print))))))))
-
-;(defun compile-script-asdf-component (component
-; &key
-; (output-spec :javascript)
-; (pretty-print t)
-; (output-to-stream t)
-; (output-stream *standard-output*)
-; output-to-files ;; currently ignored
-; (comp-env (non-nil-comp-env)))
-; "Compiles any ASDF:COMPONENT and its dependencies "
-
-(defun compile-script-system (system
- &key
- (output-spec :javascript)
- (pretty-print t)
- (output-to-stream t)
- (output-stream *standard-output*)
- output-to-files ;; currently ignored
- (comp-env (non-nil-comp-env)))
- "Compiles a collection of parenscripts as described by an ASDF system into files or
-a specified output stream."
- (asdf:operate 'asdf::parenscript-compile-op system
- :output-spec output-spec
- :pretty-print pretty-print
-; :output-to-stream t
- :output-stream output-stream
- :comp-env comp-env
- :force-p t
- ))
-
-
-;(defun compile-script-system-component (system-designator
-
-;(defun compile-script-file (script-src-file
-; &key
-; (output-spec :javascript)
-; (output-stream *standard-out*)
-; (comp-env *compilation-environment*))
-
-
-;;; old file compilation functions:
-(defun compile-parenscript-file-to-string (source-file)
- "Compile SOURCE-FILE (a parenscript file) to a javascript string. (in-package ...) forms
-behave as expected and all other forms are evaluated according to the value of
-EVAL-FORMS-P. If the result of the evaluation is not nil then it's compiled with
-js:js* and written to the output."
- (compile-script-file source-file :output-stream nil))
-
-(defun compile-parenscript-file (source-file &rest args &key destination-file &allow-other-keys)
- "Compile SOURCE-FILE (a parenscript file) to a javascript file with
-compile-parenscript-file-to-string. When DESTINATION-FILE is omitted,
-then it will be named the same as SOURCE-FILE but with js extension."
- (setf args (copy-list args))
- (remf args :destination-file)
- (unless destination-file
- (setf destination-file (merge-pathnames (make-pathname :type "js")
- source-file)))
- (with-open-file (output destination-file :if-exists :supersede :direction :output)
- (write-string (apply #'compile-parenscript-file-to-string source-file args) output)))
-
(defun ps-to-string (expr)
"Given an AST node, compiles it to a Javascript string."
(string-join