deprecated-interface.lisp 5.51 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
;;; Copyright 2005 Manuel Odendahl
;;; Copyright 2005-06 Edward Marco Baringer
;;; Copyright 2007 Red Daly
;;; Copyright 2007 Attila Lendvai
;;; Copyright 2007-2012 Vladimir Sedach
;;; Copyright 2008 Travis Cross
;;; Coypright 2010, 2013 Daniel Gackle

;;; SPDX-License-Identifier: BSD-3-Clause

;;; Redistribution and use in source and binary forms, with or
;;; without modification, are permitted provided that the following
;;; conditions are met:

;;; 1. Redistributions of source code must retain the above copyright
;;; notice, this list of conditions and the following disclaimer.

;;; 2. Redistributions in binary form must reproduce the above
;;; copyright notice, this list of conditions and the following
;;; disclaimer in the documentation and/or other materials provided
;;; with the distribution.

;;; 3. Neither the name of the copyright holder nor the names of its
;;; contributors may be used to endorse or promote products derived
;;; from this software without specific prior written permission.

;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
;;; CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
;;; INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
;;; MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
;;; BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
;;; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
;;; TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
;;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
;;; ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
;;; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
;;; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
;;; POSSIBILITY OF SUCH DAMAGE.
40

41
(in-package #:parenscript)
42
(in-readtable :parenscript)
Red Daly's avatar
Red Daly committed
43

44
(define-condition simple-style-warning (simple-warning style-warning)
45
46
47
  ())

(defun warn-deprecated (old-name &optional new-name)
48
49
50
51
  (unless *suppress-deprecation*
    (warn 'simple-style-warning
          :format-control "~:@(~a~) is deprecated~:[.~;, use ~:@(~a~) instead~]"
          :format-arguments (list old-name new-name new-name))))
52

53
54
(defmacro defun-js (old-name new-name args &body body)
  `(defun ,old-name ,args
55
    ,(when (and (stringp (car body)) (< 1 (length body))) ; docstring
56
57
           (car body))
    (warn-deprecated ',old-name ',new-name)
58
    ,@body))
59

60
;;; DEPRECATED INTERFACE
61

62
63
64
65
(defmacro define-script-symbol-macro (name &body body)
  (warn-deprecated 'define-script-symbol-macro 'define-ps-symbol-macro)
  `(define-ps-symbol-macro ,name ,@body))

66
67
68
(defun js-equal (ps-form1 ps-form2)
  (warn-deprecated 'js-equal)
  (equalp ps-form1 ps-form2))
Red Daly's avatar
Red Daly committed
69

70
(defun-js js-compile compile-script (form)
71
  (compile-script form))
Red Daly's avatar
Red Daly committed
72

73
(defun-js js-compile-list compile-script (form)
74
  (compile-script form))
Red Daly's avatar
Red Daly committed
75

76
(defmacro defjsmacro (&rest args)
77
  (warn-deprecated 'defjsmacro 'defpsmacro)
78
  `(defpsmacro ,@args))
79

80
(defmacro js-inline (&rest body)
81
  (warn-deprecated 'js-inline 'ps-inline)
82
83
  `(js-inline* '(progn ,@body)))

84
85
(defun-js js-inline* ps-inline* (&rest body)
  (apply #'ps-inline* body))
86
87

(defmacro with-unique-js-names (&rest args)
88
89
  (warn-deprecated 'with-unique-js-names 'with-ps-gensyms)
  `(with-ps-gensyms ,@args))
90

91
(defun-js gen-js-name ps-gensym (&optional (prefix "_JS_"))
92
  (ps-gensym prefix))
93

94
(defmacro js (&rest args)
95
  (warn-deprecated 'js 'ps)
96
97
  `(ps ,@args))

98
99
(defun-js js* ps* (&rest args)
  (apply #'ps* args))
100

101
(defun-js compile-script ps* (ps-form &key (output-stream nil))
102
103
104
  "Compiles the Parenscript form PS-FORM into Javascript.
If OUTPUT-STREAM is NIL, then the result is a string; otherwise code
is output to the OUTPUT-STREAM stream."
105
  (format output-stream "~A" (ps* ps-form)))
106
107
108

(defun-js symbol-to-js symbol-to-js-string (symbol)
  (symbol-to-js-string symbol))
109

110
111
112
113
(defmacro defmacro/ps (name args &body body)
  (warn-deprecated 'defmacro/ps 'defmacro+ps)
  `(progn (defmacro ,name ,args ,@body)
          (import-macros-from-lisp ',name)))
114

115
116
117
118
119
120
121
122
123
(defmacro defpsmacro-deprecated (old new)
  `(defpsmacro ,old (&rest args)
     (warn-deprecated ',old ',new)
     (cons ',new args)))

(defpsmacro-deprecated slot-value getprop)
(defpsmacro-deprecated === eql)
(defpsmacro-deprecated == equal)
(defpsmacro-deprecated % rem)
124
(defpsmacro-deprecated concat-string stringify)
125

126
127
128
129
130
131
132
133
(defpsmacro !== (&rest args)
  (warn-deprecated '!==)
  `(not (eql ,@args)))

(defpsmacro != (&rest args)
  (warn-deprecated '!=)
  `(not (equal ,@args)))

134
135
136
(defpsmacro labeled-for (label init-forms cond-forms step-forms &rest body)
  (warn-deprecated 'labeled-for 'label)
  `(label ,label (for ,init-forms ,cond-forms ,step-forms ,@body)))
Vladimir Sedach's avatar
Vladimir Sedach committed
137
138
139
140

(defpsmacro do-set-timeout ((timeout) &body body)
  (warn-deprecated 'do-set-timeout 'set-timeout)
  `(set-timeout (lambda () ,@body) ,timeout))
141
142

(defun concat-string (&rest things)
143
144
  (warn-deprecated 'concat-string 'stringify)
  (apply #'stringify things))
145
146
147

(define-statement-operator with (expression &rest body)
  (warn-deprecated 'with '|LET or WITH-SLOTS|)
148
  `(ps-js:with ,(compile-expression expression)
149
150
151
152
153
154
155
156
157
158
               ,(compile-statement `(progn ,@body))))

(define-statement-operator while (test &rest body)
  (warn-deprecated 'while '|LOOP WHILE|)
  `(ps-js:while ,(compile-expression test)
     ,(compile-loop-body () body)))

(defmacro while (test &body body)
  (warn-deprecated 'while '|LOOP WHILE|)
  `(loop while ,test do (progn ,@body)))
159
160
161
162

(defpsmacro label (&rest args)
  (warn-deprecated 'label 'block)
  `(block ,@args))
163

164
165
(define-ps-symbol-macro f ps-js:false)

166
(setf %compiling-reserved-forms-p% nil)