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