OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-binutils/] [binutils-2.19.1/] [cgen/] [testsuite/] [pmacros-1.test] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 jlechner
# pmacro testcase #1 -*- shell-script -*-
2
 
3
test=pmacros-1
4
 
5
source ./test-utils.sh
6
 
7
cpu_file=${test}.test.cpu
8
rm -f ${cpu_file}
9
 
10
cat > ${cpu_file} <
11
(include "${srcdir}/../cpu/simplify.inc")
12
(include "${srcdir}/testsuite.cpu")
13
 
14
(define-pmacro sym-const name1)
15
(define-pmacro str-const "string1")
16
(define-pmacro int-const 1)
17
 
18
(define-pmacro list-const
19
  (
20
   (name1 "string1" 1)
21
   (name2 "string2" 2)
22
   (name3 "string3" 3)
23
   )
24
)
25
(.print list-const "\n")
26
 
27
(test-name ".ref, .car")
28
(.if (.not (.equals (.ref (.car list-const) 2) 1))
29
     (.print "FAIL (.not (.equals (.ref (.car list-const) 2) 1))\n"))
30
 
31
(test-name ".for-each, nested .pmacros")
32
(print-match "adgbehcfi")
33
(print-thunk (.pmacro ()
34
               (.begin
35
                 (.for-each (.pmacro (x y z)
36
                              (.print x y z))
37
                            (a b c) (d e f) (g h i)))))
38
(test-name "nested .pmacros with bindings")
39
(print-match "(+ 4 3)")
40
(print-thunk (.pmacro ()
41
               (.dump ((.pmacro (arg1 arg2)
42
                         ((.pmacro (bar) (+ arg2 bar)) arg1))
43
                       3 4))))
44
 
45
(test-name ".dump")
46
(print-match "(name1 \"string1\" 1)(name2 \"string2\" 2)(name3 \"string3\" 3)\n")
47
(.print "EXPR: ")
48
(.for-each (.pmacro (a) (.dump a)) list-const)
49
(newline)
50
 
51
(test-name ".sym")
52
(print-match "abc\n")
53
(print-expr (.sym a "b" c))
54
 
55
(test-name ".str")
56
(print-match "\"def\"\n")
57
(print-expr (.str d "e" f))
58
 
59
(test-name ".hex")
60
(print-match "\"2a\"")
61
(print-expr (.hex 42))
62
 
63
(test-name ".upcase")
64
(print-match "\"UPPER\"")
65
(print-expr (.upcase "upper"))
66
(print-match "UPPER")
67
(print-expr (.upcase upper))
68
 
69
(test-name ".downcase")
70
(print-match "\"downer\"")
71
(print-expr (.downcase "DOWNER"))
72
(print-match "downer")
73
(print-expr (.downcase DOWNER))
74
 
75
(test-name ".substring")
76
(print-match "\"zz\"")
77
(print-expr (.substring "xyzzy" 2 4))
78
(print-match "zz")
79
(print-expr (.substring xyzzy 2 4))
80
 
81
(test-name ".splice")
82
(print-match "(now is the time)")
83
(print-expr (.splice now (.unsplice (is the time))))
84
 
85
(test-name ".iota")
86
(print-match "(0 1 2 3)")
87
(print-expr (.iota 4))
88
(print-match "(1 2 3 4)")
89
(print-expr (.iota 4 1))
90
(print-match "(2 4 6 8)")
91
(print-expr (.iota 4 2 2))
92
 
93
(test-name ".map")
94
(print-match "(\"a\" \"b\" \"c\")")
95
(print-expr (.map .hex (10 11 12)))
96
(print-match "(\"a\" \"b\" \"c\")")
97
(print-expr (.map (.pmacro (x) (.hex x)) (10 11 12)))
98
 
99
(test-name ".apply")
100
(print-match "ABC")
101
(print-expr (.apply .upcase (abc)))
102
 
103
(test-name ".pmacro?")
104
(print-match "#t")
105
(print-expr (.pmacro? .pmacro?))
106
(print-match "#t")
107
(print-expr (.pmacro? test-name))
108
(print-match "#t")
109
(print-expr (.pmacro? (.pmacro (a) (add a 1))))
110
(print-match "#f")
111
(print-expr (.pmacro? 42))
112
 
113
(test-name ".eval")
114
(print-match "(explicitly-undefined 42)")
115
(define-pmacro (eval-test1 a) (explicitly-undefined a))
116
(print-expr (.eval (.splice eval-test1 (.unsplice (42)))))
117
 
118
(test-name ".let")
119
(print-match "xyzzy")
120
(print-expr (.let ((x xyzzy)) x))
121
;; FIXME: This is the currently defined behaviour, but it's somewhat
122
;; unintuitive.
123
;; pmacro expansion re-evaluates the result if it's also a pmacro,
124
;; so x -> y -> x and y -> x -> y.
125
(print-match "(x y)")
126
(print-expr (.let ((x y) (y x)) (.list x y)))
127
 
128
(test-name ".let*")
129
(print-match "(1 2)")
130
(print-expr (.let* ((x 1) (y (.add x 1))) (.list x y)))
131
 
132
(test-name ".if")
133
(print-match "then")
134
(print-expr (.if #t then else))
135
(print-match "else")
136
(print-expr (.if #f then else))
137
 
138
(test-name ".case")
139
(print-match "123")
140
(print-expr (.case seba ((seba beach) 123) (else 456)))
141
(print-match "123")
142
(print-expr (.case beach ((seba beach) 123) (else 456)))
143
(print-match "456")
144
(print-expr (.case 0 ((seba beach) 123) (else 456)))
145
 
146
(test-name ".cond")
147
(print-match "yep")
148
(print-expr (.cond ((.eq 1 1) yep) (else nope)))
149
(print-match "nope")
150
(print-expr (.cond ((.eq 1 2) yep) (else nope)))
151
 
152
(test-name ".begin")
153
(print-match "xyz")
154
(print-thunk (.pmacro () (.begin (.print "x") (.print "y") (.print "z"))))
155
 
156
(test-name ".list, .ref")
157
(print-match "grief")
158
(print-expr (.ref (.list good grief) 1))
159
 
160
(test-name ".length")
161
(print-match "6")
162
(print-expr (.length snoopy))
163
(print-match "9")
164
(print-expr (.length "woodstock"))
165
(print-match "4")
166
(print-expr (.length (good grief charlie brown)))
167
 
168
(test-name ".replicate")
169
(print-match "(no no no no)")
170
(print-expr (.replicate 4 no))
171
 
172
(test-name ".find")
173
(print-match "(0 1)")
174
(print-expr (.find (.pmacro (n) (.lt n 2)) (.iota 4)))
175
 
176
(test-name ".equals")
177
(print-match "#t")
178
(print-expr (.equals (yo yo) (yo yo)))
179
(print-match "#f")
180
(print-expr (.equals (yo yo) (yo x)))
181
 
182
(test-name ".andif")
183
(print-match "andif")
184
(print-expr (.andif 1 #t andif))
185
(print-match "#f")
186
(print-expr (.andif 1 #f andif))
187
(print-match "#t")
188
(print-expr (.andif))
189
 
190
(test-name ".orif")
191
(print-match "orif")
192
(print-expr (.orif #f orif))
193
(print-match "#f")
194
(print-expr (.orif #f #f))
195
(print-match "#f")
196
(print-expr (.orif))
197
 
198
(test-name ".not")
199
(print-match "yep")
200
(print-expr (.if (.not #f) yep nope))
201
(print-match "nope")
202
(print-expr (.if (.not #t) yep nope))
203
 
204
(test-name ".eq")
205
(print-match "eq")
206
(print-expr (.if (.eq foo foo) eq ne))
207
(print-match "eq2")
208
(print-expr (.if (.eq 1 1) eq2 ne2))
209
 
210
(test-name ".ne")
211
(print-match "ne")
212
(print-expr (.if (.ne foo bar) ne eq))
213
(print-match "ne2")
214
(print-expr (.if (.ne 1 2) ne2 eq2))
215
 
216
(test-name ".lt")
217
(print-match "lt")
218
(print-expr (.if (.lt 1 2) lt nope))
219
 
220
(test-name ".gt")
221
(print-match "gt")
222
(print-expr (.if (.gt 1 0) gt nope))
223
 
224
(test-name ".le")
225
(print-match "le1")
226
(print-expr (.if (.le 1 1) le1 nope))
227
(print-match "le2")
228
(print-expr (.if (.le 1 2) le2 nope))
229
 
230
(test-name ".ge")
231
(print-match "ge1")
232
(print-expr (.if (.ge 1 1) ge1 nope))
233
(print-match "ge2")
234
(print-expr (.if (.ge 1 0) ge2 nope))
235
 
236
(test-name ".add")
237
(print-match "3")
238
(print-expr (.add 1 2))
239
 
240
(test-name ".sub")
241
(print-match "-1")
242
(print-expr (.sub 1 2))
243
 
244
(test-name ".mul")
245
(print-match "6")
246
(print-expr (.mul 2 3))
247
 
248
(test-name ".div")
249
(print-match "4")
250
(print-expr (.div 8 2))
251
 
252
(test-name ".rem")
253
(print-match "0")
254
(print-expr (.rem 8 2))
255
 
256
(test-name ".sll")
257
(print-match "8")
258
(print-expr (.sll 1 3))
259
(print-match "4")
260
(print-expr (.sll 4 0))
261
 
262
(test-name ".srl")
263
(print-match "1")
264
(print-expr (.srl 8 3))
265
(print-match "4")
266
(print-expr (.srl 4 0))
267
 
268
(test-name ".sra")
269
(print-match "-1")
270
(print-expr (.sra -1 0))
271
(print-match "-1")
272
(print-expr (.sra -1 1))
273
(print-match "-2")
274
(print-expr (.sra -3 1))
275
 
276
(test-name ".and")
277
(print-match "8")
278
(print-expr (.and 15 8))
279
 
280
(test-name ".or")
281
(print-match "15")
282
(print-expr (.or 15 8))
283
 
284
(test-name ".xor")
285
(print-match "7")
286
(print-expr (.xor 15 8))
287
 
288
(test-name ".inv")
289
(print-match "-6")
290
(print-expr (.inv 5))
291
 
292
(test-name ".car")
293
(print-match "car")
294
(print-expr (.car (car cdr)))
295
 
296
(test-name ".cdr")
297
(print-match "(cdr)")
298
(print-expr (.cdr (car cdr)))
299
 
300
(test-name ".caar")
301
(print-match "caar")
302
(print-expr (.caar ((caar cdar) cadr cddr)))
303
 
304
(test-name ".cadr")
305
(print-match "cadr")
306
(print-expr (.cadr ((caar cdar) cadr cddr)))
307
 
308
(test-name ".cdar")
309
(print-match "(cdar)")
310
(print-expr (.cdar ((caar cdar) cadr cddr)))
311
 
312
(test-name ".cddr")
313
(print-match "(cddr)")
314
(print-expr (.cddr ((caar cdar) cadr cddr)))
315
 
316
EOF
317
 
318
run_cgen ${cpu_file}
319
 
320
post_process
321
 
322
finish

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.