1 ;;; Copyright 2005 Manuel Odendahl
2 ;;; Copyright 2005-06 Edward Marco Baringer
3 ;;; Copyright 2007 Red Daly
4 ;;; Copyright 2007 Attila Lendvai
5 ;;; Copyright 2007-2012 Vladimir Sedach
6 ;;; Copyright 2008 Travis Cross
7 ;;; Coypright 2010, 2013 Daniel Gackle
9 ;;; SPDX-License-Identifier: BSD-3-Clause
11 ;;; Redistribution and use in source and binary forms, with or
12 ;;; without modification, are permitted provided that the following
13 ;;; conditions are met:
15 ;;; 1. Redistributions of source code must retain the above copyright
16 ;;; notice, this list of conditions and the following disclaimer.
18 ;;; 2. Redistributions in binary form must reproduce the above
19 ;;; copyright notice, this list of conditions and the following
20 ;;; disclaimer in the documentation and/or other materials provided
21 ;;; with the distribution.
23 ;;; 3. Neither the name of the copyright holder nor the names of its
24 ;;; contributors may be used to endorse or promote products derived
25 ;;; from this software without specific prior written permission.
27 ;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
28 ;;; CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
29 ;;; INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
30 ;;; MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31 ;;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
32 ;;; BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33 ;;; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
34 ;;; TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 ;;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
36 ;;; ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
37 ;;; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 ;;; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 ;;; POSSIBILITY OF SUCH DAMAGE.
41 (in-package #:parenscript
)
42 (in-readtable :parenscript
)
44 (define-condition simple-style-warning
(simple-warning style-warning
)
47 (defun warn-deprecated (old-name &optional new-name
)
48 (warn 'simple-style-warning
49 :format-control
"~:@(~a~) is deprecated~:[.~;, use ~:@(~a~) instead~]"
50 :format-arguments
(list old-name new-name new-name
)))
52 (defmacro defun-js
(old-name new-name args
&body body
)
53 `(defun ,old-name
,args
54 ,(when (and (stringp (car body
)) (< 1 (length body
))) ; docstring
56 (warn-deprecated ',old-name
',new-name
)
59 ;;; DEPRECATED INTERFACE
61 (defmacro define-script-symbol-macro
(name &body body
)
62 (warn-deprecated 'define-script-symbol-macro
'define-ps-symbol-macro
)
63 `(define-ps-symbol-macro ,name
,@body
))
65 (defun js-equal (ps-form1 ps-form2
)
66 (warn-deprecated 'js-equal
)
67 (equalp ps-form1 ps-form2
))
69 (defun-js js-compile compile-script
(form)
70 (compile-script form
))
72 (defun-js js-compile-list compile-script
(form)
73 (compile-script form
))
75 (defmacro defjsmacro
(&rest args
)
76 (warn-deprecated 'defjsmacro
'defpsmacro
)
79 (defmacro js-inline
(&rest body
)
80 (warn-deprecated 'js-inline
'ps-inline
)
81 `(js-inline* '(progn ,@body
)))
83 (defun-js js-inline
* ps-inline
* (&rest body
)
84 (apply #'ps-inline
* body
))
86 (defmacro with-unique-js-names
(&rest args
)
87 (warn-deprecated 'with-unique-js-names
'with-ps-gensyms
)
88 `(with-ps-gensyms ,@args
))
90 (defun-js gen-js-name ps-gensym
(&optional
(prefix "_JS_"))
93 (defmacro js
(&rest args
)
94 (warn-deprecated 'js
'ps
)
97 (defun-js js
* ps
* (&rest args
)
100 (defun-js compile-script ps
* (ps-form &key
(output-stream nil
))
101 "Compiles the Parenscript form PS-FORM into Javascript.
102 If OUTPUT-STREAM is NIL, then the result is a string; otherwise code
103 is output to the OUTPUT-STREAM stream."
104 (format output-stream
"~A" (ps* ps-form
)))
106 (defun-js symbol-to-js symbol-to-js-string
(symbol)
107 (symbol-to-js-string symbol
))
109 (defmacro defmacro
/ps
(name args
&body body
)
110 (warn-deprecated 'defmacro
/ps
'defmacro
+ps
)
111 `(progn (defmacro ,name
,args
,@body
)
112 (import-macros-from-lisp ',name
)))
114 (defmacro defpsmacro-deprecated
(old new
)
115 `(defpsmacro ,old
(&rest args
)
116 (warn-deprecated ',old
',new
)
119 (defpsmacro-deprecated slot-value getprop
)
120 (defpsmacro-deprecated === eql
)
121 (defpsmacro-deprecated == equal
)
122 (defpsmacro-deprecated % rem
)
123 (defpsmacro-deprecated concat-string stringify
)
125 (defpsmacro !== (&rest args
)
126 (warn-deprecated '!==)
129 (defpsmacro != (&rest args
)
130 (warn-deprecated '!=)
131 `(not (equal ,@args
)))
133 (defpsmacro labeled-for
(label init-forms cond-forms step-forms
&rest body
)
134 (warn-deprecated 'labeled-for
'label
)
135 `(label ,label
(for ,init-forms
,cond-forms
,step-forms
,@body
)))
137 (defpsmacro do-set-timeout
((timeout) &body body
)
138 (warn-deprecated 'do-set-timeout
'set-timeout
)
139 `(set-timeout (lambda () ,@body
) ,timeout
))
141 (defun concat-string (&rest things
)
142 (warn-deprecated 'concat-string
'stringify
)
143 (apply #'stringify things
))
145 (define-statement-operator with
(expression &rest body
)
146 (warn-deprecated 'with
'|LET or WITH-SLOTS|
)
147 `(ps-js:with
,(compile-expression expression
)
148 ,(compile-statement `(progn ,@body
))))
150 (define-statement-operator while
(test &rest body
)
151 (warn-deprecated 'while
'|LOOP WHILE|
)
152 `(ps-js:while
,(compile-expression test
)
153 ,(compile-loop-body () body
)))
155 (defmacro while
(test &body body
)
156 (warn-deprecated 'while
'|LOOP WHILE|
)
157 `(loop while
,test do
(progn ,@body
)))
159 (defpsmacro label
(&rest args
)
160 (warn-deprecated 'label
'block
)
163 (define-ps-symbol-macro f ps-js
:false
)
165 (setf %compiling-reserved-forms-p% nil
)