blob: 45d5b19ee710434a83883c0bf16bde254ff1390f (
plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
|
;;; bytecomp-testsuite.el
;; Copyright (C) 2008-2011 Free Software Foundation, Inc.
;; Author: Shigeru Fukaya <shigeru.fukaya@gmail.com>
;; Created: November 2008
;; Keywords: internal
;; Human-Keywords: internal
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
(require 'ert)
;;; Code:
(defconst byte-opt-testsuite-arith-data
'(
;; some functional tests
(let ((a most-positive-fixnum) (b 1) (c 1.0)) (+ a b c))
(let ((a most-positive-fixnum) (b -2) (c 1.0)) (- a b c))
(let ((a most-positive-fixnum) (b 2) (c 1.0)) (* a b c))
(let ((a 3) (b 2) (c 1.0)) (/ a b c))
(let ((a (+ 1 (expt 2 -64))) (b (expt 2 -65))) (+ a -1 b))
(let ((a (+ 1 (expt 2 -64))) (b (expt 2 -65))) (- a 1 (- b)))
;; This fails. Should it be a bug?
;; (let ((a (expt 2 -1074)) (b 0.125)) (* a 8 b))
(let ((a 1.0)) (* a 0))
(let ((a 1.0)) (* a 2.0 0))
(let ((a 1.0)) (/ 0 a))
(let ((a 1.0)) (/ 3 a 2))
(let ((a most-positive-fixnum) (b 2.0)) (* a 2 b))
(let ((a 3) (b 2)) (/ a b 1.0))
(/ 3 -1)
(+ 4 3 2 1)
(+ 4 3 2.0 1)
(- 4 3 2 1) ; not new, for reference
(- 4 3 2.0 1) ; not new, for reference
(* 4 3 2 1)
(* 4 3 2.0 1)
(/ 4 3 2 1)
(/ 4 3 2.0 1)
(let ((a 3) (b 2)) (+ a b 1))
(let ((a 3) (b 2)) (+ a b -1))
(let ((a 3) (b 2)) (- a b 1))
(let ((a 3) (b 2)) (- a b -1))
(let ((a 3) (b 2)) (+ a b a 1))
(let ((a 3) (b 2)) (+ a b a -1))
(let ((a 3) (b 2)) (- a b a 1))
(let ((a 3) (b 2)) (- a b a -1))
(let ((a 3) (b 2)) (* a b -1))
(let ((a 3) (b 2)) (* a -1))
(let ((a 3) (b 2)) (/ a b 1))
(let ((a 3) (b 2)) (/ (+ a b) 1))
;; coverage test
(let ((a 3) (b 2) (c 1.0)) (+))
(let ((a 3) (b 2) (c 1.0)) (+ 2))
(let ((a 3) (b 2) (c 1.0)) (+ 2 0))
(let ((a 3) (b 2) (c 1.0)) (+ 2 0.0))
(let ((a 3) (b 2) (c 1.0)) (+ 2.0))
(let ((a 3) (b 2) (c 1.0)) (+ 2.0 0))
(let ((a 3) (b 2) (c 1.0)) (+ 2.0 0.0))
(let ((a 3) (b 2) (c 1.0)) (+ 0 2))
(let ((a 3) (b 2) (c 1.0)) (+ 0 2.0))
(let ((a 3) (b 2) (c 1.0)) (+ 0.0 2))
(let ((a 3) (b 2) (c 1.0)) (+ 0.0 2.0))
(let ((a 3) (b 2) (c 1.0)) (+ a))
(let ((a 3) (b 2) (c 1.0)) (+ a 0))
(let ((a 3) (b 2) (c 1.0)) (+ a 0.0))
(let ((a 3) (b 2) (c 1.0)) (+ 0 a))
(let ((a 3) (b 2) (c 1.0)) (+ 0.0 a))
(let ((a 3) (b 2) (c 1.0)) (+ c 0))
(let ((a 3) (b 2) (c 1.0)) (+ c 0.0))
(let ((a 3) (b 2) (c 1.0)) (+ 0 c))
(let ((a 3) (b 2) (c 1.0)) (+ 0.0 c))
(let ((a 3) (b 2) (c 1.0)) (+ a b 0 c 0))
(let ((a 3) (b 2) (c 1.0)) (+ 0 a))
(let ((a 3) (b 2) (c 1.0)) (+ 0 a b))
(let ((a 3) (b 2) (c 1.0)) (+ 0 a b c))
(let ((a 3) (b 2) (c 1.0)) (+ 1 2 3))
(let ((a 3) (b 2) (c 1.0)) (+ 3.0 2.0 1))
(let ((a 3) (b 2) (c 1.0)) (+ 3.0 2.0 1 4))
(let ((a 3) (b 2) (c 1.0)) (+ a 1))
(let ((a 3) (b 2) (c 1.0)) (+ a -1))
(let ((a 3) (b 2) (c 1.0)) (+ 1 a))
(let ((a 3) (b 2) (c 1.0)) (+ -1 a))
(let ((a 3) (b 2) (c 1.0)) (+ c 1))
(let ((a 3) (b 2) (c 1.0)) (+ c -1))
(let ((a 3) (b 2) (c 1.0)) (+ 1 c))
(let ((a 3) (b 2) (c 1.0)) (+ -1 c))
(let ((a 3) (b 2) (c 1.0)) (+ a b 0))
(let ((a 3) (b 2) (c 1.0)) (+ a b 1))
(let ((a 3) (b 2) (c 1.0)) (+ a b -1))
(let ((a 3) (b 2) (c 1.0)) (+ a b 2))
(let ((a 3) (b 2) (c 1.0)) (+ 1 a b c))
(let ((a 3) (b 2) (c 1.0)) (+ a b c 0))
(let ((a 3) (b 2) (c 1.0)) (+ a b c 1))
(let ((a 3) (b 2) (c 1.0)) (+ a b c -1))
(let ((a 3) (b 2) (c 1.0)) (-))
(let ((a 3) (b 2) (c 1.0)) (- 2))
(let ((a 3) (b 2) (c 1.0)) (- 2 0))
(let ((a 3) (b 2) (c 1.0)) (- 2 0.0))
(let ((a 3) (b 2) (c 1.0)) (- 2.0))
(let ((a 3) (b 2) (c 1.0)) (- 2.0 0))
(let ((a 3) (b 2) (c 1.0)) (- 2.0 0.0))
(let ((a 3) (b 2) (c 1.0)) (- 0 2))
(let ((a 3) (b 2) (c 1.0)) (- 0 2.0))
(let ((a 3) (b 2) (c 1.0)) (- 0.0 2))
(let ((a 3) (b 2) (c 1.0)) (- 0.0 2.0))
(let ((a 3) (b 2) (c 1.0)) (- a))
(let ((a 3) (b 2) (c 1.0)) (- a 0))
(let ((a 3) (b 2) (c 1.0)) (- a 0.0))
(let ((a 3) (b 2) (c 1.0)) (- 0 a))
(let ((a 3) (b 2) (c 1.0)) (- 0.0 a))
(let ((a 3) (b 2) (c 1.0)) (- c 0))
(let ((a 3) (b 2) (c 1.0)) (- c 0.0))
(let ((a 3) (b 2) (c 1.0)) (- 0 c))
(let ((a 3) (b 2) (c 1.0)) (- 0.0 c))
(let ((a 3) (b 2) (c 1.0)) (- a b 0 c 0))
(let ((a 3) (b 2) (c 1.0)) (- 0 a))
(let ((a 3) (b 2) (c 1.0)) (- 0 a b))
(let ((a 3) (b 2) (c 1.0)) (- 0 a b c))
(let ((a 3) (b 2) (c 1.0)) (- 1 2 3))
(let ((a 3) (b 2) (c 1.0)) (- 3.0 2.0 1))
(let ((a 3) (b 2) (c 1.0)) (- 3.0 2.0 1 4))
(let ((a 3) (b 2) (c 1.0)) (- a 1))
(let ((a 3) (b 2) (c 1.0)) (- a -1))
(let ((a 3) (b 2) (c 1.0)) (- 1 a))
(let ((a 3) (b 2) (c 1.0)) (- -1 a))
(let ((a 3) (b 2) (c 1.0)) (- c 1))
(let ((a 3) (b 2) (c 1.0)) (- c -1))
(let ((a 3) (b 2) (c 1.0)) (- 1 c))
(let ((a 3) (b 2) (c 1.0)) (- -1 c))
(let ((a 3) (b 2) (c 1.0)) (- a b 0))
(let ((a 3) (b 2) (c 1.0)) (- a b 1))
(let ((a 3) (b 2) (c 1.0)) (- a b -1))
(let ((a 3) (b 2) (c 1.0)) (- a b 2))
(let ((a 3) (b 2) (c 1.0)) (- 1 a b c))
(let ((a 3) (b 2) (c 1.0)) (- a b c 0))
(let ((a 3) (b 2) (c 1.0)) (- a b c 1))
(let ((a 3) (b 2) (c 1.0)) (- a b c -1))
(let ((a 3) (b 2) (c 1.0)) (*))
(let ((a 3) (b 2) (c 1.0)) (* 2))
(let ((a 3) (b 2) (c 1.0)) (* 2 0))
(let ((a 3) (b 2) (c 1.0)) (* 2 0.0))
(let ((a 3) (b 2) (c 1.0)) (* 2.0))
(let ((a 3) (b 2) (c 1.0)) (* 2.0 0))
(let ((a 3) (b 2) (c 1.0)) (* 2.0 0.0))
(let ((a 3) (b 2) (c 1.0)) (* 0 2))
(let ((a 3) (b 2) (c 1.0)) (* 0 2.0))
(let ((a 3) (b 2) (c 1.0)) (* 0.0 2))
(let ((a 3) (b 2) (c 1.0)) (* 0.0 2.0))
(let ((a 3) (b 2) (c 1.0)) (* a))
(let ((a 3) (b 2) (c 1.0)) (* a 0))
(let ((a 3) (b 2) (c 1.0)) (* a 0.0))
(let ((a 3) (b 2) (c 1.0)) (* 0 a))
(let ((a 3) (b 2) (c 1.0)) (* 0.0 a))
(let ((a 3) (b 2) (c 1.0)) (* c 0))
(let ((a 3) (b 2) (c 1.0)) (* c 0.0))
(let ((a 3) (b 2) (c 1.0)) (* 0 c))
(let ((a 3) (b 2) (c 1.0)) (* 0.0 c))
(let ((a 3) (b 2) (c 1.0)) (* a b 0 c 0))
(let ((a 3) (b 2) (c 1.0)) (* 0 a))
(let ((a 3) (b 2) (c 1.0)) (* 0 a b))
(let ((a 3) (b 2) (c 1.0)) (* 0 a b c))
(let ((a 3) (b 2) (c 1.0)) (* 1 2 3))
(let ((a 3) (b 2) (c 1.0)) (* 3.0 2.0 1))
(let ((a 3) (b 2) (c 1.0)) (* 3.0 2.0 1 4))
(let ((a 3) (b 2) (c 1.0)) (* a 1))
(let ((a 3) (b 2) (c 1.0)) (* a -1))
(let ((a 3) (b 2) (c 1.0)) (* 1 a))
(let ((a 3) (b 2) (c 1.0)) (* -1 a))
(let ((a 3) (b 2) (c 1.0)) (* c 1))
(let ((a 3) (b 2) (c 1.0)) (* c -1))
(let ((a 3) (b 2) (c 1.0)) (* 1 c))
(let ((a 3) (b 2) (c 1.0)) (* -1 c))
(let ((a 3) (b 2) (c 1.0)) (* a b 0))
(let ((a 3) (b 2) (c 1.0)) (* a b 1))
(let ((a 3) (b 2) (c 1.0)) (* a b -1))
(let ((a 3) (b 2) (c 1.0)) (* a b 2))
(let ((a 3) (b 2) (c 1.0)) (* 1 a b c))
(let ((a 3) (b 2) (c 1.0)) (* a b c 0))
(let ((a 3) (b 2) (c 1.0)) (* a b c 1))
(let ((a 3) (b 2) (c 1.0)) (* a b c -1))
(let ((a 3) (b 2) (c 1.0)) (/))
(let ((a 3) (b 2) (c 1.0)) (/ 2))
(let ((a 3) (b 2) (c 1.0)) (/ 2 0))
(let ((a 3) (b 2) (c 1.0)) (/ 2 0.0))
(let ((a 3) (b 2) (c 1.0)) (/ 2.0))
(let ((a 3) (b 2) (c 1.0)) (/ 2.0 0))
(let ((a 3) (b 2) (c 1.0)) (/ 2.0 0.0))
(let ((a 3) (b 2) (c 1.0)) (/ 0 2))
(let ((a 3) (b 2) (c 1.0)) (/ 0 2.0))
(let ((a 3) (b 2) (c 1.0)) (/ 0.0 2))
(let ((a 3) (b 2) (c 1.0)) (/ 0.0 2.0))
(let ((a 3) (b 2) (c 1.0)) (/ a))
(let ((a 3) (b 2) (c 1.0)) (/ a 0))
(let ((a 3) (b 2) (c 1.0)) (/ a 0.0))
(let ((a 3) (b 2) (c 1.0)) (/ 0 a))
(let ((a 3) (b 2) (c 1.0)) (/ 0.0 a))
(let ((a 3) (b 2) (c 1.0)) (/ c 0))
(let ((a 3) (b 2) (c 1.0)) (/ c 0.0))
(let ((a 3) (b 2) (c 1.0)) (/ 0 c))
(let ((a 3) (b 2) (c 1.0)) (/ 0.0 c))
(let ((a 3) (b 2) (c 1.0)) (/ a b 0 c 0))
(let ((a 3) (b 2) (c 1.0)) (/ 0 a))
(let ((a 3) (b 2) (c 1.0)) (/ 0 a b))
(let ((a 3) (b 2) (c 1.0)) (/ 0 a b c))
(let ((a 3) (b 2) (c 1.0)) (/ 1 2 3))
(let ((a 3) (b 2) (c 1.0)) (/ 3.0 2.0 1))
(let ((a 3) (b 2) (c 1.0)) (/ 3.0 2.0 1 4))
(let ((a 3) (b 2) (c 1.0)) (/ a 1))
(let ((a 3) (b 2) (c 1.0)) (/ a -1))
(let ((a 3) (b 2) (c 1.0)) (/ 1 a))
(let ((a 3) (b 2) (c 1.0)) (/ -1 a))
(let ((a 3) (b 2) (c 1.0)) (/ c 1))
(let ((a 3) (b 2) (c 1.0)) (/ c -1))
(let ((a 3) (b 2) (c 1.0)) (/ 1 c))
(let ((a 3) (b 2) (c 1.0)) (/ -1 c))
(let ((a 3) (b 2) (c 1.0)) (/ a b 0))
(let ((a 3) (b 2) (c 1.0)) (/ a b 1))
(let ((a 3) (b 2) (c 1.0)) (/ a b -1))
(let ((a 3) (b 2) (c 1.0)) (/ a b 2))
(let ((a 3) (b 2) (c 1.0)) (/ 1 a b c))
(let ((a 3) (b 2) (c 1.0)) (/ a b c 0))
(let ((a 3) (b 2) (c 1.0)) (/ a b c 1))
(let ((a 3) (b 2) (c 1.0)) (/ a b c -1)))
"List of expression for test.
Each element will be executed by interpreter and with
bytecompiled code, and their results compared.")
(defun bytecomp-check-1 (pat)
"Return non-nil if PAT is the same whether directly evalled or compiled."
(let ((warning-minimum-log-level :emergency)
(byte-compile-warnings nil)
(v0 (condition-case nil
(eval pat)
(error nil)))
(v1 (condition-case nil
(funcall (byte-compile (list 'lambda nil pat)))
(error nil))))
(equal v0 v1)))
(put 'bytecomp-check-1 'ert-explainer 'bytecomp-explain-1)
(defun bytecomp-explain-1 (pat)
(let ((v0 (condition-case nil
(eval pat)
(error nil)))
(v1 (condition-case nil
(funcall (byte-compile (list 'lambda nil pat)))
(error nil))))
(format "Expression `%s' gives `%s' if directly evalled, `%s' if compiled."
pat v0 v1)))
(ert-deftest bytecomp-tests ()
"Test the Emacs byte compiler."
(dolist (pat byte-opt-testsuite-arith-data)
(should (bytecomp-check-1 pat))))
(defun test-byte-opt-arithmetic (&optional arg)
"Unit test for byte-opt arithmetic operations.
Subtests signal errors if something goes wrong."
(interactive "P")
(switch-to-buffer (generate-new-buffer "*Font Pase Test*"))
(let ((warning-minimum-log-level :emergency)
(byte-compile-warnings nil)
(pass-face '((t :foreground "green")))
(fail-face '((t :foreground "red")))
(print-escape-nonascii t)
(print-escape-newlines t)
(print-quoted t)
v0 v1)
(dolist (pat byte-opt-testsuite-arith-data)
(condition-case nil
(setq v0 (eval pat))
(error (setq v0 nil)))
(condition-case nil
(setq v1 (funcall (byte-compile (list 'lambda nil pat))))
(error (setq v1 nil)))
(insert (format "%s" pat))
(indent-to-column 65)
(if (equal v0 v1)
(insert (propertize "OK" 'face pass-face))
(insert (propertize "FAIL\n" 'face fail-face))
(indent-to-column 55)
(insert (propertize (format "[%s] vs [%s]" v0 v1)
'face fail-face)))
(insert "\n"))))
;; Local Variables:
;; no-byte-compile: t
;; End:
(provide 'byte-opt-testsuite)
|