1 # pmacro testcase #1 -*- shell-script -*-
7 cpu_file=${test}.test.cpu
10 cat > ${cpu_file} <<EOF
11 (include "${srcdir}/../cpu/simplify.inc")
12 (include "${srcdir}/testsuite.cpu")
14 (define-pmacro sym-const name1)
15 (define-pmacro str-const "string1")
16 (define-pmacro int-const 1)
18 (define-pmacro list-const
25 (.print list-const "\n")
27 (test-name ".ref, .car")
28 (.if (.not (.equal? (.ref (.car list-const) 2) 1))
29 (.print "FAIL (.not (.equal? (.ref (.car list-const) 2) 1))\n"))
31 (test-name ".for-each, nested .pmacros")
32 (print-match "adgbehcfi")
33 (print-thunk (.pmacro ()
35 (.for-each (.pmacro (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))
46 (print-match "(name1 \"string1\" 1)(name2 \"string2\" 2)(name3 \"string3\" 3)\n")
48 (.for-each (.pmacro (a) (.dump a)) list-const)
53 (print-expr (.sym a "b" c))
56 (print-match "\"def\"\n")
57 (print-expr (.str d "e" f))
60 (print-match "\"2a\"")
61 (print-expr (.hex 42))
64 (print-match "\"UPPER\"")
65 (print-expr (.upcase "upper"))
67 (print-expr (.upcase upper))
69 (test-name ".downcase")
70 (print-match "\"downer\"")
71 (print-expr (.downcase "DOWNER"))
72 (print-match "downer")
73 (print-expr (.downcase DOWNER))
75 (test-name ".substring")
76 (print-match "\"zz\"")
77 (print-expr (.substring "xyzzy" 2 4))
79 (print-expr (.substring xyzzy 2 4))
81 (test-name ".splice1")
82 (print-match "(now is the time)")
83 (print-expr (.splice now (.unsplice (is the time))))
85 ;; Arguments to .splice/.unsplice are evaluated.
86 (test-name ".splice2")
87 (print-match "(now is the time)")
88 (define-pmacro splice2-piece now)
89 (print-expr (.splice splice2-piece (.unsplice (is the time))))
91 ;; Arguments to .splice/.unsplice are evaluated.
92 (test-name ".splice3")
93 (print-match "(now is the time)")
94 (define-pmacro splice3-piece the)
95 (print-expr (.splice now (.unsplice (is splice3-piece time))))
98 (print-match "(0 1 2 3)")
99 (print-expr (.iota 4))
100 (print-match "(1 2 3 4)")
101 (print-expr (.iota 4 1))
102 (print-match "(2 4 6 8)")
103 (print-expr (.iota 4 2 2))
106 (print-match "(\"a\" \"b\" \"c\")")
107 (print-expr (.map .hex (10 11 12)))
108 (print-match "(\"a\" \"b\" \"c\")")
109 (print-expr (.map (.pmacro (x) (.hex x)) (10 11 12)))
113 (print-expr (.apply .upcase (abc)))
115 (test-name ".pmacro?")
117 (print-expr (.pmacro? .pmacro?))
119 (print-expr (.pmacro? test-name))
121 (print-expr (.pmacro? (.pmacro (a) (add a 1))))
123 (print-expr (.pmacro? 42))
126 (print-match "(explicitly-undefined 42)")
127 (define-pmacro (eval-test1 a) (explicitly-undefined a))
128 (print-expr (.eval (.splice eval-test1 (.unsplice (42)))))
131 (print-match "xyzzy")
132 (print-expr (.let ((x xyzzy)) x))
133 ;; FIXME: This is the currently defined behaviour, but it's somewhat
135 ;; pmacro expansion re-evaluates the result if it's also a pmacro,
136 ;; so x -> y -> x and y -> x -> y.
137 (print-match "(x y)")
138 (print-expr (.let ((x y) (y x)) (.list x y)))
141 (print-match "(1 2)")
142 (print-expr (.let* ((x 1) (y (.add x 1))) (.list x y)))
146 (print-expr (.if #t then else))
148 (print-expr (.if #f then else))
152 (print-expr (.case seba ((seba beach) 123) (else 456)))
154 (print-expr (.case beach ((seba beach) 123) (else 456)))
156 (print-expr (.case 0 ((seba beach) 123) (else 456)))
160 (print-expr (.cond ((.eq 1 1) yep) (else nope)))
162 (print-expr (.cond ((.eq 1 2) yep) (else nope)))
166 (print-thunk (.pmacro () (.begin (.print "x") (.print "y") (.print "z"))))
168 (test-name ".list, .ref")
169 (print-match "grief")
170 (print-expr (.ref (.list good grief) 1))
172 (test-name ".length")
174 (print-expr (.length snoopy))
176 (print-expr (.length "woodstock"))
178 (print-expr (.length (good grief charlie brown)))
180 (test-name ".replicate")
181 (print-match "(no no no no)")
182 (print-expr (.replicate 4 no))
185 (print-match "(0 1)")
186 (print-expr (.find (.pmacro (n) (.lt n 2)) (.iota 4)))
188 (test-name ".equal?")
190 (print-expr (.equal? (yo yo) (yo yo)))
192 (print-expr (.equal? (yo yo) (yo x)))
195 (print-match "andif")
196 (print-expr (.andif 1 #t andif))
198 (print-expr (.andif 1 #f andif))
200 (print-expr (.andif))
204 (print-expr (.orif #f orif))
206 (print-expr (.orif #f #f))
212 (print-expr (.if (.not #f) yep nope))
214 (print-expr (.if (.not #t) yep nope))
218 (print-expr (.if (.eq foo foo) eq ne))
220 (print-expr (.if (.eq 1 1) eq2 ne2))
224 (print-expr (.if (.ne foo bar) ne eq))
226 (print-expr (.if (.ne 1 2) ne2 eq2))
230 (print-expr (.if (.lt 1 2) lt nope))
234 (print-expr (.if (.gt 1 0) gt nope))
238 (print-expr (.if (.le 1 1) le1 nope))
240 (print-expr (.if (.le 1 2) le2 nope))
244 (print-expr (.if (.ge 1 1) ge1 nope))
246 (print-expr (.if (.ge 1 0) ge2 nope))
250 (print-expr (.add 1 2))
254 (print-expr (.sub 1 2))
258 (print-expr (.mul 2 3))
262 (print-expr (.div 8 2))
266 (print-expr (.rem 8 2))
270 (print-expr (.sll 1 3))
272 (print-expr (.sll 4 0))
276 (print-expr (.srl 8 3))
278 (print-expr (.srl 4 0))
282 (print-expr (.sra -1 0))
284 (print-expr (.sra -1 1))
286 (print-expr (.sra -3 1))
290 (print-expr (.and 15 8))
294 (print-expr (.or 15 8))
298 (print-expr (.xor 15 8))
302 (print-expr (.inv 5))
306 (print-expr (.car (car cdr)))
309 (print-match "(cdr)")
310 (print-expr (.cdr (car cdr)))
314 (print-expr (.caar ((caar cdar) cadr cddr)))
318 (print-expr (.cadr ((caar cdar) cadr cddr)))
321 (print-match "(cdar)")
322 (print-expr (.cdar ((caar cdar) cadr cddr)))
325 (print-match "(cddr)")
326 (print-expr (.cddr ((caar cdar) cadr cddr)))