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
(style-warning simple-warning
)
47 (defun warn-deprecated (old-name &optional new-name
)
48 (unless *suppress-deprecation
*
49 (warn 'simple-style-warning
50 :format-control
"~:@(~a~) is deprecated~:[.~;, use ~:@(~a~) instead~]"
51 :format-arguments
(list old-name new-name new-name
))))
53 (defmacro defun-js
(old-name new-name args
&body body
)
54 `(defun ,old-name
,args
55 ,(when (and (stringp (car body
)) (< 1 (length body
))) ; docstring
57 (warn-deprecated ',old-name
',new-name
)
60 ;;; DEPRECATED INTERFACE
62 (defmacro define-script-symbol-macro
(name &body body
)
63 (warn-deprecated 'define-script-symbol-macro
'define-ps-symbol-macro
)
64 `(define-ps-symbol-macro ,name
,@body
))
66 (defun js-equal (ps-form1 ps-form2
)
67 (warn-deprecated 'js-equal
)
68 (equalp ps-form1 ps-form2
))
70 (defun-js js-compile compile-script
(form)
71 (compile-script form
))
73 (defun-js js-compile-list compile-script
(form)
74 (compile-script form
))
76 (defmacro defjsmacro
(&rest args
)
77 (warn-deprecated 'defjsmacro
'defpsmacro
)
80 (defmacro js-inline
(&rest body
)
81 (warn-deprecated 'js-inline
'ps-inline
)
82 `(js-inline* '(progn ,@body
)))
84 (defun-js js-inline
* ps-inline
* (&rest body
)
85 (apply #'ps-inline
* body
))
87 (defmacro with-unique-js-names
(&rest args
)
88 (warn-deprecated 'with-unique-js-names
'with-ps-gensyms
)
89 `(with-ps-gensyms ,@args
))
91 (defun-js gen-js-name ps-gensym
(&optional
(prefix "_JS_"))
94 (defmacro js
(&rest args
)
95 (warn-deprecated 'js
'ps
)
98 (defun-js js
* ps
* (&rest args
)
101 (defun-js compile-script ps
* (ps-form &key
(output-stream nil
))
102 "Compiles the Parenscript form PS-FORM into Javascript.
103 If OUTPUT-STREAM is NIL, then the result is a string; otherwise code
104 is output to the OUTPUT-STREAM stream."
105 (format output-stream
"~A" (ps* ps-form
)))
107 (defun-js symbol-to-js symbol-to-js-string
(symbol)
108 (symbol-to-js-string symbol
))
110 (defmacro defmacro
/ps
(name args
&body body
)
111 (warn-deprecated 'defmacro
/ps
'defmacro
+ps
)
112 `(progn (defmacro ,name
,args
,@body
)
113 (import-macros-from-lisp ',name
)))
115 (defmacro defpsmacro-deprecated
(old new
)
116 `(defpsmacro ,old
(&rest args
)
117 (warn-deprecated ',old
',new
)
120 (defpsmacro-deprecated slot-value getprop
)
121 (defpsmacro-deprecated === eql
)
122 (defpsmacro-deprecated == equal
)
123 (defpsmacro-deprecated % rem
)
124 (defpsmacro-deprecated concat-string stringify
)
126 (defpsmacro !== (&rest args
)
127 (warn-deprecated '!==)
130 (defpsmacro != (&rest args
)
131 (warn-deprecated '!=)
132 `(not (equal ,@args
)))
134 (defpsmacro labeled-for
(label init-forms cond-forms step-forms
&rest body
)
135 (warn-deprecated 'labeled-for
'label
)
136 `(label ,label
(for ,init-forms
,cond-forms
,step-forms
,@body
)))
138 (defpsmacro do-set-timeout
((timeout) &body body
)
139 (warn-deprecated 'do-set-timeout
'set-timeout
)
140 `(set-timeout (lambda () ,@body
) ,timeout
))
142 (defun concat-string (&rest things
)
143 (warn-deprecated 'concat-string
'stringify
)
144 (apply #'stringify things
))
146 (define-statement-operator with
(expression &rest body
)
147 (warn-deprecated 'with
'|LET or WITH-SLOTS|
)
148 `(ps-js:with
,(compile-expression expression
)
149 ,(compile-statement `(progn ,@body
))))
151 (defpsmacro label
(&rest args
)
152 (warn-deprecated 'label
'block
)
155 (define-ps-symbol-macro f ps-js
:false
)
157 (setf %compiling-reserved-forms-p% nil
)