Commit | Line | Data |
---|---|---|
9da682ca RD |
1 | (in-package :parenscript) |
2 | ||
3 | ;;; DEPRECATED INTERFACE ;;; | |
4 | (defun js-equal (a b) (script-equal a b)) | |
5 | ||
6 | (defun js-compile (form) | |
7 | (compile-script form :output-spec :javascript)) | |
8 | ||
9 | (defun js-compile-list (form) | |
10 | (compile-script form :output-spec :javascript)) | |
11 | ||
12 | (defun js-gensym (&rest args) | |
13 | (apply #'script-gensym args)) | |
14 | ||
15 | (defmacro defjsmacro (name args &rest body) | |
16 | "Define a ParenScript macro, and store it in the toplevel ParenScript macro environment. | |
17 | ||
18 | DEPRECATED" | |
5aa10005 RD |
19 | `(defscriptmacro ,name ,args ,@body)) |
20 | ||
21 | ;;; dual lisp/parenscript macro balderdash | |
22 | ;;; TODO: should probably move elsewhere ;;; | |
23 | #+nil | |
24 | (progn | |
25 | (defmacro defmacro/js (name args &body body) | |
26 | "Define a Lisp macro and import it into the ParenScript macro environment." | |
27 | `(progn (defmacro ,name ,args ,@body) | |
28 | (js:import-macros-from-lisp ',name))) | |
29 | ||
30 | (defmacro defmacro+js (name args &body body) | |
31 | "Define a Lisp macro and a ParenScript macro in their respective | |
32 | macro environments. This function should be used when you want to use | |
33 | the same macro in both Lisp and ParenScript, but the 'macroexpand' of | |
34 | that macro in Lisp makes the Lisp macro unsuitable to be imported into | |
35 | the ParenScript macro environment." | |
36 | `(progn (defmacro ,name ,args ,@body) | |
37 | (defscriptmacro ,name ,args ,@body))) | |
38 | ||
39 | (defun import-macros-from-lisp (&rest names) | |
40 | "Import the named Lisp macros into the ParenScript macro environment." | |
41 | (dolist (name names) | |
42 | (let ((name name)) | |
43 | (undefine-js-special-form name) | |
44 | (setf (get-macro-spec name *script-macro-toplevel*) | |
45 | (cons nil (lambda (&rest args) | |
46 | (macroexpand `(,name ,@args)))))))) | |
47 | ||
48 | (defmacro js-file (&rest body) | |
49 | `(html | |
50 | (:princ | |
51 | (js ,@body)))) | |
52 | ||
53 | (defmacro js-script (&rest body) | |
54 | `((:script :type "text/javascript") | |
55 | (:princ (format nil "~%// <![CDATA[~%")) | |
56 | (:princ (js ,@body)) | |
57 | (:princ (format nil "~%// ]]>~%")))) | |
58 | ||
59 | (defmacro js-inline (&rest body) | |
60 | `(js-inline* '(progn ,@body))) | |
61 | ||
62 | (defmacro js-inline* (&rest body) | |
63 | "Just like JS-INLINE except that BODY is evaluated before being | |
64 | converted to javascript." | |
65 | `(concatenate 'string "javascript:" | |
66 | (string-join (js-to-statement-strings (compile-script-form (list 'progn ,@body)) 0) " "))) | |
67 | ) |