Fix @ and @@ to not capture lexicals; new @@ @@ form for R6RS libraries
[bpt/guile.git] / module / ice-9 / psyntax-pp.scm
1 (eval-when (compile) (set-current-module (resolve-module (quote (guile)))))
2 (if #f #f)
3
4 (letrec*
5 ((make-void
6 (lambda (src) (make-struct (vector-ref %expanded-vtables 0) 0 src)))
7 (make-const
8 (lambda (src exp)
9 (make-struct (vector-ref %expanded-vtables 1) 0 src exp)))
10 (make-primitive-ref
11 (lambda (src name)
12 (make-struct (vector-ref %expanded-vtables 2) 0 src name)))
13 (make-lexical-ref
14 (lambda (src name gensym)
15 (make-struct (vector-ref %expanded-vtables 3) 0 src name gensym)))
16 (make-lexical-set
17 (lambda (src name gensym exp)
18 (make-struct (vector-ref %expanded-vtables 4) 0 src name gensym exp)))
19 (make-module-ref
20 (lambda (src mod name public?)
21 (make-struct (vector-ref %expanded-vtables 5) 0 src mod name public?)))
22 (make-module-set
23 (lambda (src mod name public? exp)
24 (make-struct
25 (vector-ref %expanded-vtables 6)
26 0
27 src
28 mod
29 name
30 public?
31 exp)))
32 (make-toplevel-ref
33 (lambda (src name)
34 (make-struct (vector-ref %expanded-vtables 7) 0 src name)))
35 (make-toplevel-set
36 (lambda (src name exp)
37 (make-struct (vector-ref %expanded-vtables 8) 0 src name exp)))
38 (make-toplevel-define
39 (lambda (src name exp)
40 (make-struct (vector-ref %expanded-vtables 9) 0 src name exp)))
41 (make-conditional
42 (lambda (src test consequent alternate)
43 (make-struct
44 (vector-ref %expanded-vtables 10)
45 0
46 src
47 test
48 consequent
49 alternate)))
50 (make-application
51 (lambda (src proc args)
52 (make-struct (vector-ref %expanded-vtables 11) 0 src proc args)))
53 (make-sequence
54 (lambda (src exps)
55 (make-struct (vector-ref %expanded-vtables 12) 0 src exps)))
56 (make-lambda
57 (lambda (src meta body)
58 (make-struct (vector-ref %expanded-vtables 13) 0 src meta body)))
59 (make-lambda-case
60 (lambda (src req opt rest kw inits gensyms body alternate)
61 (make-struct
62 (vector-ref %expanded-vtables 14)
63 0
64 src
65 req
66 opt
67 rest
68 kw
69 inits
70 gensyms
71 body
72 alternate)))
73 (make-let
74 (lambda (src names gensyms vals body)
75 (make-struct
76 (vector-ref %expanded-vtables 15)
77 0
78 src
79 names
80 gensyms
81 vals
82 body)))
83 (make-letrec
84 (lambda (src in-order? names gensyms vals body)
85 (make-struct
86 (vector-ref %expanded-vtables 16)
87 0
88 src
89 in-order?
90 names
91 gensyms
92 vals
93 body)))
94 (make-dynlet
95 (lambda (src fluids vals body)
96 (make-struct
97 (vector-ref %expanded-vtables 17)
98 0
99 src
100 fluids
101 vals
102 body)))
103 (lambda?
104 (lambda (x)
105 (and (struct? x)
106 (eq? (struct-vtable x) (vector-ref %expanded-vtables 13)))))
107 (lambda-meta (lambda (x) (struct-ref x 1)))
108 (set-lambda-meta! (lambda (x v) (struct-set! x 1 v)))
109 (top-level-eval-hook (lambda (x mod) (primitive-eval x)))
110 (local-eval-hook (lambda (x mod) (primitive-eval x)))
111 (session-id
112 (let ((v (module-variable (current-module) 'syntax-session-id)))
113 (lambda () ((variable-ref v)))))
114 (put-global-definition-hook
115 (lambda (symbol type val)
116 (module-define!
117 (current-module)
118 symbol
119 (make-syntax-transformer symbol type val))))
120 (get-global-definition-hook
121 (lambda (symbol module)
122 (if (and (not module) (current-module))
123 (warn "module system is booted, we should have a module" symbol))
124 (let ((v (module-variable
125 (if module (resolve-module (cdr module)) (current-module))
126 symbol)))
127 (and v
128 (variable-bound? v)
129 (let ((val (variable-ref v)))
130 (and (macro? val)
131 (macro-type val)
132 (cons (macro-type val) (macro-binding val))))))))
133 (decorate-source
134 (lambda (e s)
135 (if (and s (supports-source-properties? e))
136 (set-source-properties! e s))
137 e))
138 (maybe-name-value!
139 (lambda (name val)
140 (if (lambda? val)
141 (let ((meta (lambda-meta val)))
142 (if (not (assq 'name meta))
143 (set-lambda-meta! val (acons 'name name meta)))))))
144 (build-void (lambda (source) (make-void source)))
145 (build-application
146 (lambda (source fun-exp arg-exps)
147 (make-application source fun-exp arg-exps)))
148 (build-conditional
149 (lambda (source test-exp then-exp else-exp)
150 (make-conditional source test-exp then-exp else-exp)))
151 (build-dynlet
152 (lambda (source fluids vals body)
153 (make-dynlet source fluids vals body)))
154 (build-lexical-reference
155 (lambda (type source name var) (make-lexical-ref source name var)))
156 (build-lexical-assignment
157 (lambda (source name var exp)
158 (maybe-name-value! name exp)
159 (make-lexical-set source name var exp)))
160 (analyze-variable
161 (lambda (mod var modref-cont bare-cont)
162 (if (not mod)
163 (bare-cont var)
164 (let ((kind (car mod)) (mod (cdr mod)))
165 (let ((key kind))
166 (cond ((memv key '(public)) (modref-cont mod var #t))
167 ((memv key '(private))
168 (if (not (equal? mod (module-name (current-module))))
169 (modref-cont mod var #f)
170 (bare-cont var)))
171 ((memv key '(bare)) (bare-cont var))
172 ((memv key '(hygiene))
173 (if (and (not (equal? mod (module-name (current-module))))
174 (module-variable (resolve-module mod) var))
175 (modref-cont mod var #f)
176 (bare-cont var)))
177 (else (syntax-violation #f "bad module kind" var mod))))))))
178 (build-global-reference
179 (lambda (source var mod)
180 (analyze-variable
181 mod
182 var
183 (lambda (mod var public?) (make-module-ref source mod var public?))
184 (lambda (var) (make-toplevel-ref source var)))))
185 (build-global-assignment
186 (lambda (source var exp mod)
187 (maybe-name-value! var exp)
188 (analyze-variable
189 mod
190 var
191 (lambda (mod var public?)
192 (make-module-set source mod var public? exp))
193 (lambda (var) (make-toplevel-set source var exp)))))
194 (build-global-definition
195 (lambda (source var exp)
196 (maybe-name-value! var exp)
197 (make-toplevel-define source var exp)))
198 (build-simple-lambda
199 (lambda (src req rest vars meta exp)
200 (make-lambda
201 src
202 meta
203 (make-lambda-case src req #f rest #f '() vars exp #f))))
204 (build-case-lambda
205 (lambda (src meta body) (make-lambda src meta body)))
206 (build-lambda-case
207 (lambda (src req opt rest kw inits vars body else-case)
208 (make-lambda-case src req opt rest kw inits vars body else-case)))
209 (build-primref
210 (lambda (src name)
211 (if (equal? (module-name (current-module)) '(guile))
212 (make-toplevel-ref src name)
213 (make-module-ref src '(guile) name #f))))
214 (build-data (lambda (src exp) (make-const src exp)))
215 (build-sequence
216 (lambda (src exps)
217 (if (null? (cdr exps)) (car exps) (make-sequence src exps))))
218 (build-let
219 (lambda (src ids vars val-exps body-exp)
220 (for-each maybe-name-value! ids val-exps)
221 (if (null? vars) body-exp (make-let src ids vars val-exps body-exp))))
222 (build-named-let
223 (lambda (src ids vars val-exps body-exp)
224 (let ((f (car vars)) (f-name (car ids)) (vars (cdr vars)) (ids (cdr ids)))
225 (let ((proc (build-simple-lambda src ids #f vars '() body-exp)))
226 (maybe-name-value! f-name proc)
227 (for-each maybe-name-value! ids val-exps)
228 (make-letrec
229 src
230 #f
231 (list f-name)
232 (list f)
233 (list proc)
234 (build-application
235 src
236 (build-lexical-reference 'fun src f-name f)
237 val-exps))))))
238 (build-letrec
239 (lambda (src in-order? ids vars val-exps body-exp)
240 (if (null? vars)
241 body-exp
242 (begin
243 (for-each maybe-name-value! ids val-exps)
244 (make-letrec src in-order? ids vars val-exps body-exp)))))
245 (make-syntax-object
246 (lambda (expression wrap module)
247 (vector 'syntax-object expression wrap module)))
248 (syntax-object?
249 (lambda (x)
250 (and (vector? x)
251 (= (vector-length x) 4)
252 (eq? (vector-ref x 0) 'syntax-object))))
253 (syntax-object-expression (lambda (x) (vector-ref x 1)))
254 (syntax-object-wrap (lambda (x) (vector-ref x 2)))
255 (syntax-object-module (lambda (x) (vector-ref x 3)))
256 (set-syntax-object-expression!
257 (lambda (x update) (vector-set! x 1 update)))
258 (set-syntax-object-wrap!
259 (lambda (x update) (vector-set! x 2 update)))
260 (set-syntax-object-module!
261 (lambda (x update) (vector-set! x 3 update)))
262 (source-annotation
263 (lambda (x)
264 (let ((props (source-properties
265 (if (syntax-object? x) (syntax-object-expression x) x))))
266 (and (pair? props) props))))
267 (extend-env
268 (lambda (labels bindings r)
269 (if (null? labels)
270 r
271 (extend-env
272 (cdr labels)
273 (cdr bindings)
274 (cons (cons (car labels) (car bindings)) r)))))
275 (extend-var-env
276 (lambda (labels vars r)
277 (if (null? labels)
278 r
279 (extend-var-env
280 (cdr labels)
281 (cdr vars)
282 (cons (cons (car labels) (cons 'lexical (car vars))) r)))))
283 (macros-only-env
284 (lambda (r)
285 (if (null? r)
286 '()
287 (let ((a (car r)))
288 (if (eq? (cadr a) 'macro)
289 (cons a (macros-only-env (cdr r)))
290 (macros-only-env (cdr r)))))))
291 (lookup
292 (lambda (x r mod)
293 (let ((t (assq x r)))
294 (cond (t (cdr t))
295 ((symbol? x) (or (get-global-definition-hook x mod) '(global)))
296 (else '(displaced-lexical))))))
297 (global-extend
298 (lambda (type sym val) (put-global-definition-hook sym type val)))
299 (nonsymbol-id?
300 (lambda (x)
301 (and (syntax-object? x) (symbol? (syntax-object-expression x)))))
302 (id? (lambda (x)
303 (if (symbol? x)
304 #t
305 (and (syntax-object? x) (symbol? (syntax-object-expression x))))))
306 (id-sym-name&marks
307 (lambda (x w)
308 (if (syntax-object? x)
309 (values
310 (syntax-object-expression x)
311 (join-marks (car w) (car (syntax-object-wrap x))))
312 (values x (car w)))))
313 (gen-label
314 (lambda ()
315 (string-append "l-" (session-id) (symbol->string (gensym "-")))))
316 (gen-labels
317 (lambda (ls)
318 (if (null? ls) '() (cons (gen-label) (gen-labels (cdr ls))))))
319 (make-ribcage
320 (lambda (symnames marks labels)
321 (vector 'ribcage symnames marks labels)))
322 (ribcage?
323 (lambda (x)
324 (and (vector? x)
325 (= (vector-length x) 4)
326 (eq? (vector-ref x 0) 'ribcage))))
327 (ribcage-symnames (lambda (x) (vector-ref x 1)))
328 (ribcage-marks (lambda (x) (vector-ref x 2)))
329 (ribcage-labels (lambda (x) (vector-ref x 3)))
330 (set-ribcage-symnames! (lambda (x update) (vector-set! x 1 update)))
331 (set-ribcage-marks! (lambda (x update) (vector-set! x 2 update)))
332 (set-ribcage-labels! (lambda (x update) (vector-set! x 3 update)))
333 (anti-mark
334 (lambda (w) (cons (cons #f (car w)) (cons 'shift (cdr w)))))
335 (extend-ribcage!
336 (lambda (ribcage id label)
337 (set-ribcage-symnames!
338 ribcage
339 (cons (syntax-object-expression id) (ribcage-symnames ribcage)))
340 (set-ribcage-marks!
341 ribcage
342 (cons (car (syntax-object-wrap id)) (ribcage-marks ribcage)))
343 (set-ribcage-labels! ribcage (cons label (ribcage-labels ribcage)))))
344 (make-binding-wrap
345 (lambda (ids labels w)
346 (if (null? ids)
347 w
348 (cons (car w)
349 (cons (let* ((labelvec (list->vector labels)) (n (vector-length labelvec)))
350 (let ((symnamevec (make-vector n)) (marksvec (make-vector n)))
351 (let f ((ids ids) (i 0))
352 (if (not (null? ids))
353 (call-with-values
354 (lambda () (id-sym-name&marks (car ids) w))
355 (lambda (symname marks)
356 (vector-set! symnamevec i symname)
357 (vector-set! marksvec i marks)
358 (f (cdr ids) (+ i 1))))))
359 (make-ribcage symnamevec marksvec labelvec)))
360 (cdr w))))))
361 (smart-append (lambda (m1 m2) (if (null? m2) m1 (append m1 m2))))
362 (join-wraps
363 (lambda (w1 w2)
364 (let ((m1 (car w1)) (s1 (cdr w1)))
365 (if (null? m1)
366 (if (null? s1) w2 (cons (car w2) (smart-append s1 (cdr w2))))
367 (cons (smart-append m1 (car w2)) (smart-append s1 (cdr w2)))))))
368 (join-marks (lambda (m1 m2) (smart-append m1 m2)))
369 (same-marks?
370 (lambda (x y)
371 (or (eq? x y)
372 (and (not (null? x))
373 (not (null? y))
374 (eq? (car x) (car y))
375 (same-marks? (cdr x) (cdr y))))))
376 (id-var-name
377 (lambda (id w)
378 (letrec*
379 ((search
380 (lambda (sym subst marks)
381 (if (null? subst)
382 (values #f marks)
383 (let ((fst (car subst)))
384 (if (eq? fst 'shift)
385 (search sym (cdr subst) (cdr marks))
386 (let ((symnames (ribcage-symnames fst)))
387 (if (vector? symnames)
388 (search-vector-rib sym subst marks symnames fst)
389 (search-list-rib sym subst marks symnames fst))))))))
390 (search-list-rib
391 (lambda (sym subst marks symnames ribcage)
392 (let f ((symnames symnames) (i 0))
393 (cond ((null? symnames) (search sym (cdr subst) marks))
394 ((and (eq? (car symnames) sym)
395 (same-marks? marks (list-ref (ribcage-marks ribcage) i)))
396 (values (list-ref (ribcage-labels ribcage) i) marks))
397 (else (f (cdr symnames) (+ i 1)))))))
398 (search-vector-rib
399 (lambda (sym subst marks symnames ribcage)
400 (let ((n (vector-length symnames)))
401 (let f ((i 0))
402 (cond ((= i n) (search sym (cdr subst) marks))
403 ((and (eq? (vector-ref symnames i) sym)
404 (same-marks? marks (vector-ref (ribcage-marks ribcage) i)))
405 (values (vector-ref (ribcage-labels ribcage) i) marks))
406 (else (f (+ i 1)))))))))
407 (cond ((symbol? id) (or (search id (cdr w) (car w)) id))
408 ((syntax-object? id)
409 (let ((id (syntax-object-expression id)) (w1 (syntax-object-wrap id)))
410 (let ((marks (join-marks (car w) (car w1))))
411 (call-with-values
412 (lambda () (search id (cdr w) marks))
413 (lambda (new-id marks) (or new-id (search id (cdr w1) marks) id))))))
414 (else (syntax-violation 'id-var-name "invalid id" id))))))
415 (locally-bound-identifiers
416 (lambda (w mod)
417 (letrec*
418 ((scan (lambda (subst results)
419 (if (null? subst)
420 results
421 (let ((fst (car subst)))
422 (if (eq? fst 'shift)
423 (scan (cdr subst) results)
424 (let ((symnames (ribcage-symnames fst)) (marks (ribcage-marks fst)))
425 (if (vector? symnames)
426 (scan-vector-rib subst symnames marks results)
427 (scan-list-rib subst symnames marks results))))))))
428 (scan-list-rib
429 (lambda (subst symnames marks results)
430 (let f ((symnames symnames) (marks marks) (results results))
431 (if (null? symnames)
432 (scan (cdr subst) results)
433 (f (cdr symnames)
434 (cdr marks)
435 (cons (wrap (car symnames) (anti-mark (cons (car marks) subst)) mod)
436 results))))))
437 (scan-vector-rib
438 (lambda (subst symnames marks results)
439 (let ((n (vector-length symnames)))
440 (let f ((i 0) (results results))
441 (if (= i n)
442 (scan (cdr subst) results)
443 (f (+ i 1)
444 (cons (wrap (vector-ref symnames i)
445 (anti-mark (cons (vector-ref marks i) subst))
446 mod)
447 results))))))))
448 (scan (cdr w) '()))))
449 (resolve-identifier
450 (lambda (id w r mod)
451 (letrec*
452 ((resolve-global
453 (lambda (var mod)
454 (let ((b (or (get-global-definition-hook var mod) '(global))))
455 (if (eq? (car b) 'global)
456 (values 'global var mod)
457 (values (car b) (cdr b) mod)))))
458 (resolve-lexical
459 (lambda (label mod)
460 (let ((b (or (assq-ref r label) '(displaced-lexical))))
461 (values (car b) (cdr b) mod)))))
462 (let ((n (id-var-name id w)))
463 (cond ((symbol? n)
464 (resolve-global
465 n
466 (if (syntax-object? id) (syntax-object-module id) mod)))
467 ((string? n)
468 (resolve-lexical
469 n
470 (if (syntax-object? id) (syntax-object-module id) mod)))
471 (else (error "unexpected id-var-name" id w n)))))))
472 (transformer-environment
473 (make-fluid
474 (lambda (k)
475 (error "called outside the dynamic extent of a syntax transformer"))))
476 (with-transformer-environment
477 (lambda (k) ((fluid-ref transformer-environment) k)))
478 (free-id=?
479 (lambda (i j)
480 (and (eq? (let ((x i)) (if (syntax-object? x) (syntax-object-expression x) x))
481 (let ((x j)) (if (syntax-object? x) (syntax-object-expression x) x)))
482 (eq? (id-var-name i '(())) (id-var-name j '(()))))))
483 (bound-id=?
484 (lambda (i j)
485 (if (and (syntax-object? i) (syntax-object? j))
486 (and (eq? (syntax-object-expression i) (syntax-object-expression j))
487 (same-marks?
488 (car (syntax-object-wrap i))
489 (car (syntax-object-wrap j))))
490 (eq? i j))))
491 (valid-bound-ids?
492 (lambda (ids)
493 (and (let all-ids? ((ids ids))
494 (or (null? ids) (and (id? (car ids)) (all-ids? (cdr ids)))))
495 (distinct-bound-ids? ids))))
496 (distinct-bound-ids?
497 (lambda (ids)
498 (let distinct? ((ids ids))
499 (or (null? ids)
500 (and (not (bound-id-member? (car ids) (cdr ids)))
501 (distinct? (cdr ids)))))))
502 (bound-id-member?
503 (lambda (x list)
504 (and (not (null? list))
505 (or (bound-id=? x (car list)) (bound-id-member? x (cdr list))))))
506 (wrap (lambda (x w defmod)
507 (cond ((and (null? (car w)) (null? (cdr w))) x)
508 ((syntax-object? x)
509 (make-syntax-object
510 (syntax-object-expression x)
511 (join-wraps w (syntax-object-wrap x))
512 (syntax-object-module x)))
513 ((null? x) x)
514 (else (make-syntax-object x w defmod)))))
515 (source-wrap
516 (lambda (x w s defmod) (wrap (decorate-source x s) w defmod)))
517 (expand-sequence
518 (lambda (body r w s mod)
519 (build-sequence
520 s
521 (let dobody ((body body) (r r) (w w) (mod mod))
522 (if (null? body)
523 '()
524 (let ((first (expand (car body) r w mod)))
525 (cons first (dobody (cdr body) r w mod))))))))
526 (expand-top-sequence
527 (lambda (body r w s m esew mod)
528 (letrec*
529 ((scan (lambda (body r w s m esew mod exps)
530 (if (null? body)
531 exps
532 (call-with-values
533 (lambda ()
534 (call-with-values
535 (lambda ()
536 (let ((e (car body)))
537 (syntax-type e r w (or (source-annotation e) s) #f mod #f)))
538 (lambda (type value form e w s mod)
539 (let ((key type))
540 (cond ((memv key '(begin-form))
541 (let* ((tmp e) (tmp-1 ($sc-dispatch tmp '(_))))
542 (if tmp-1
543 (apply (lambda () exps) tmp-1)
544 (let ((tmp-1 ($sc-dispatch tmp '(_ any . each-any))))
545 (if tmp-1
546 (apply (lambda (e1 e2) (scan (cons e1 e2) r w s m esew mod exps))
547 tmp-1)
548 (syntax-violation
549 #f
550 "source expression failed to match any pattern"
551 tmp))))))
552 ((memv key '(local-syntax-form))
553 (expand-local-syntax
554 value
555 e
556 r
557 w
558 s
559 mod
560 (lambda (body r w s mod) (scan body r w s m esew mod exps))))
561 ((memv key '(eval-when-form))
562 (let* ((tmp-1 e) (tmp ($sc-dispatch tmp-1 '(_ each-any any . each-any))))
563 (if tmp
564 (apply (lambda (x e1 e2)
565 (let ((when-list (parse-when-list e x)) (body (cons e1 e2)))
566 (cond ((eq? m 'e)
567 (if (memq 'eval when-list)
568 (scan body
569 r
570 w
571 s
572 (if (memq 'expand when-list) 'c&e 'e)
573 '(eval)
574 mod
575 exps)
576 (begin
577 (if (memq 'expand when-list)
578 (top-level-eval-hook
579 (expand-top-sequence body r w s 'e '(eval) mod)
580 mod))
581 (values exps))))
582 ((memq 'load when-list)
583 (cond ((or (memq 'compile when-list)
584 (memq 'expand when-list)
585 (and (eq? m 'c&e) (memq 'eval when-list)))
586 (scan body r w s 'c&e '(compile load) mod exps))
587 ((memq m '(c c&e))
588 (scan body r w s 'c '(load) mod exps))
589 (else (values exps))))
590 ((or (memq 'compile when-list)
591 (memq 'expand when-list)
592 (and (eq? m 'c&e) (memq 'eval when-list)))
593 (top-level-eval-hook
594 (expand-top-sequence body r w s 'e '(eval) mod)
595 mod)
596 (values exps))
597 (else (values exps)))))
598 tmp)
599 (syntax-violation
600 #f
601 "source expression failed to match any pattern"
602 tmp-1))))
603 ((memv key '(define-syntax-form define-syntax-parameter-form))
604 (let ((n (id-var-name value w)) (r (macros-only-env r)))
605 (let ((key m))
606 (cond ((memv key '(c))
607 (cond ((memq 'compile esew)
608 (let ((e (expand-install-global n (expand e r w mod))))
609 (top-level-eval-hook e mod)
610 (if (memq 'load esew) (values (cons e exps)) (values exps))))
611 ((memq 'load esew)
612 (values
613 (cons (expand-install-global n (expand e r w mod)) exps)))
614 (else (values exps))))
615 ((memv key '(c&e))
616 (let ((e (expand-install-global n (expand e r w mod))))
617 (top-level-eval-hook e mod)
618 (values (cons e exps))))
619 (else
620 (if (memq 'eval esew)
621 (top-level-eval-hook
622 (expand-install-global n (expand e r w mod))
623 mod))
624 (values exps))))))
625 ((memv key '(define-form))
626 (let* ((n (id-var-name value w)) (type (car (lookup n r mod))) (key type))
627 (cond ((memv key '(global core macro module-ref))
628 (if (and (memq m '(c c&e))
629 (not (module-local-variable (current-module) n))
630 (current-module))
631 (let ((old (module-variable (current-module) n)))
632 (if (and (variable? old) (variable-bound? old))
633 (module-define! (current-module) n (variable-ref old))
634 (module-add! (current-module) n (make-undefined-variable)))))
635 (values
636 (cons (if (eq? m 'c&e)
637 (let ((x (build-global-definition s n (expand e r w mod))))
638 (top-level-eval-hook x mod)
639 x)
640 (lambda () (build-global-definition s n (expand e r w mod))))
641 exps)))
642 ((memv key '(displaced-lexical))
643 (syntax-violation
644 #f
645 "identifier out of context"
646 (source-wrap form w s mod)
647 (wrap value w mod)))
648 (else
649 (syntax-violation
650 #f
651 "cannot define keyword at top level"
652 (source-wrap form w s mod)
653 (wrap value w mod))))))
654 (else
655 (values
656 (cons (if (eq? m 'c&e)
657 (let ((x (expand-expr type value form e r w s mod)))
658 (top-level-eval-hook x mod)
659 x)
660 (lambda () (expand-expr type value form e r w s mod)))
661 exps))))))))
662 (lambda (exps) (scan (cdr body) r w s m esew mod exps)))))))
663 (call-with-values
664 (lambda () (scan body r w s m esew mod '()))
665 (lambda (exps)
666 (if (null? exps)
667 (build-void s)
668 (build-sequence
669 s
670 (let lp ((in exps) (out '()))
671 (if (null? in)
672 out
673 (let ((e (car in)))
674 (lp (cdr in) (cons (if (procedure? e) (e) e) out))))))))))))
675 (expand-install-global
676 (lambda (name e)
677 (build-global-definition
678 #f
679 name
680 (build-application
681 #f
682 (build-primref #f 'make-syntax-transformer)
683 (list (build-data #f name) (build-data #f 'macro) e)))))
684 (parse-when-list
685 (lambda (e when-list)
686 (let ((result (strip when-list '(()))))
687 (let lp ((l result))
688 (cond ((null? l) result)
689 ((memq (car l) '(compile load eval expand)) (lp (cdr l)))
690 (else (syntax-violation 'eval-when "invalid situation" e (car l))))))))
691 (syntax-type
692 (lambda (e r w s rib mod for-car?)
693 (cond ((symbol? e)
694 (let* ((n (id-var-name e w))
695 (b (lookup n r mod))
696 (type (car b))
697 (key type))
698 (cond ((memv key '(lexical)) (values type (cdr b) e e w s mod))
699 ((memv key '(global)) (values type n e e w s mod))
700 ((memv key '(macro))
701 (if for-car?
702 (values type (cdr b) e e w s mod)
703 (syntax-type
704 (expand-macro (cdr b) e r w s rib mod)
705 r
706 '(())
707 s
708 rib
709 mod
710 #f)))
711 (else (values type (cdr b) e e w s mod)))))
712 ((pair? e)
713 (let ((first (car e)))
714 (call-with-values
715 (lambda () (syntax-type first r w s rib mod #t))
716 (lambda (ftype fval fform fe fw fs fmod)
717 (let ((key ftype))
718 (cond ((memv key '(lexical)) (values 'lexical-call fval e e w s mod))
719 ((memv key '(global))
720 (values 'global-call (make-syntax-object fval w fmod) e e w s mod))
721 ((memv key '(macro))
722 (syntax-type
723 (expand-macro fval e r w s rib mod)
724 r
725 '(())
726 s
727 rib
728 mod
729 for-car?))
730 ((memv key '(module-ref))
731 (call-with-values
732 (lambda () (fval e r w))
733 (lambda (e r w s mod) (syntax-type e r w s rib mod for-car?))))
734 ((memv key '(core)) (values 'core-form fval e e w s mod))
735 ((memv key '(local-syntax))
736 (values 'local-syntax-form fval e e w s mod))
737 ((memv key '(begin)) (values 'begin-form #f e e w s mod))
738 ((memv key '(eval-when)) (values 'eval-when-form #f e e w s mod))
739 ((memv key '(define))
740 (let* ((tmp e) (tmp-1 ($sc-dispatch tmp '(_ any any))))
741 (if (and tmp-1 (apply (lambda (name val) (id? name)) tmp-1))
742 (apply (lambda (name val) (values 'define-form name e val w s mod))
743 tmp-1)
744 (let ((tmp-1 ($sc-dispatch tmp '(_ (any . any) any . each-any))))
745 (if (and tmp-1
746 (apply (lambda (name args e1 e2)
747 (and (id? name) (valid-bound-ids? (lambda-var-list args))))
748 tmp-1))
749 (apply (lambda (name args e1 e2)
750 (values
751 'define-form
752 (wrap name w mod)
753 (wrap e w mod)
754 (decorate-source
755 (cons '#(syntax-object lambda ((top)) (hygiene guile))
756 (wrap (cons args (cons e1 e2)) w mod))
757 s)
758 '(())
759 s
760 mod))
761 tmp-1)
762 (let ((tmp-1 ($sc-dispatch tmp '(_ any))))
763 (if (and tmp-1 (apply (lambda (name) (id? name)) tmp-1))
764 (apply (lambda (name)
765 (values
766 'define-form
767 (wrap name w mod)
768 (wrap e w mod)
769 '(#(syntax-object if ((top)) (hygiene guile)) #f #f)
770 '(())
771 s
772 mod))
773 tmp-1)
774 (syntax-violation
775 #f
776 "source expression failed to match any pattern"
777 tmp))))))))
778 ((memv key '(define-syntax))
779 (let* ((tmp-1 e) (tmp ($sc-dispatch tmp-1 '(_ any any))))
780 (if (and tmp (apply (lambda (name val) (id? name)) tmp))
781 (apply (lambda (name val) (values 'define-syntax-form name e val w s mod))
782 tmp)
783 (syntax-violation
784 #f
785 "source expression failed to match any pattern"
786 tmp-1))))
787 ((memv key '(define-syntax-parameter))
788 (let* ((tmp-1 e) (tmp ($sc-dispatch tmp-1 '(_ any any))))
789 (if (and tmp (apply (lambda (name val) (id? name)) tmp))
790 (apply (lambda (name val)
791 (values 'define-syntax-parameter-form name e val w s mod))
792 tmp)
793 (syntax-violation
794 #f
795 "source expression failed to match any pattern"
796 tmp-1))))
797 (else (values 'call #f e e w s mod))))))))
798 ((syntax-object? e)
799 (syntax-type
800 (syntax-object-expression e)
801 r
802 (join-wraps w (syntax-object-wrap e))
803 (or (source-annotation e) s)
804 rib
805 (or (syntax-object-module e) mod)
806 for-car?))
807 ((self-evaluating? e) (values 'constant #f e e w s mod))
808 (else (values 'other #f e e w s mod)))))
809 (expand
810 (lambda (e r w mod)
811 (call-with-values
812 (lambda () (syntax-type e r w (source-annotation e) #f mod #f))
813 (lambda (type value form e w s mod)
814 (expand-expr type value form e r w s mod)))))
815 (expand-expr
816 (lambda (type value form e r w s mod)
817 (let ((key type))
818 (cond ((memv key '(lexical)) (build-lexical-reference 'value s e value))
819 ((memv key '(core core-form)) (value e r w s mod))
820 ((memv key '(module-ref))
821 (call-with-values
822 (lambda () (value e r w))
823 (lambda (e r w s mod) (expand e r w mod))))
824 ((memv key '(lexical-call))
825 (expand-application
826 (let ((id (car e)))
827 (build-lexical-reference
828 'fun
829 (source-annotation id)
830 (if (syntax-object? id) (syntax->datum id) id)
831 value))
832 e
833 r
834 w
835 s
836 mod))
837 ((memv key '(global-call))
838 (expand-application
839 (build-global-reference
840 (source-annotation (car e))
841 (if (syntax-object? value) (syntax-object-expression value) value)
842 (if (syntax-object? value) (syntax-object-module value) mod))
843 e
844 r
845 w
846 s
847 mod))
848 ((memv key '(constant))
849 (build-data s (strip (source-wrap e w s mod) '(()))))
850 ((memv key '(global)) (build-global-reference s value mod))
851 ((memv key '(call))
852 (expand-application (expand (car e) r w mod) e r w s mod))
853 ((memv key '(begin-form))
854 (let* ((tmp e) (tmp-1 ($sc-dispatch tmp '(_ any . each-any))))
855 (if tmp-1
856 (apply (lambda (e1 e2) (expand-sequence (cons e1 e2) r w s mod))
857 tmp-1)
858 (let ((tmp-1 ($sc-dispatch tmp '(_))))
859 (if tmp-1
860 (apply (lambda ()
861 (if (include-deprecated-features)
862 (begin
863 (issue-deprecation-warning
864 "Sequences of zero expressions are deprecated. Use *unspecified*.")
865 (expand-void))
866 (syntax-violation
867 #f
868 "sequence of zero expressions"
869 (source-wrap e w s mod))))
870 tmp-1)
871 (syntax-violation
872 #f
873 "source expression failed to match any pattern"
874 tmp))))))
875 ((memv key '(local-syntax-form))
876 (expand-local-syntax value e r w s mod expand-sequence))
877 ((memv key '(eval-when-form))
878 (let* ((tmp-1 e) (tmp ($sc-dispatch tmp-1 '(_ each-any any . each-any))))
879 (if tmp
880 (apply (lambda (x e1 e2)
881 (let ((when-list (parse-when-list e x)))
882 (if (memq 'eval when-list)
883 (expand-sequence (cons e1 e2) r w s mod)
884 (expand-void))))
885 tmp)
886 (syntax-violation
887 #f
888 "source expression failed to match any pattern"
889 tmp-1))))
890 ((memv key
891 '(define-form define-syntax-form define-syntax-parameter-form))
892 (syntax-violation
893 #f
894 "definition in expression context, where definitions are not allowed,"
895 (source-wrap form w s mod)))
896 ((memv key '(syntax))
897 (syntax-violation
898 #f
899 "reference to pattern variable outside syntax form"
900 (source-wrap e w s mod)))
901 ((memv key '(displaced-lexical))
902 (syntax-violation
903 #f
904 "reference to identifier outside its scope"
905 (source-wrap e w s mod)))
906 (else
907 (syntax-violation #f "unexpected syntax" (source-wrap e w s mod)))))))
908 (expand-application
909 (lambda (x e r w s mod)
910 (let* ((tmp-1 e) (tmp ($sc-dispatch tmp-1 '(any . each-any))))
911 (if tmp
912 (apply (lambda (e0 e1)
913 (build-application s x (map (lambda (e) (expand e r w mod)) e1)))
914 tmp)
915 (syntax-violation
916 #f
917 "source expression failed to match any pattern"
918 tmp-1)))))
919 (expand-macro
920 (lambda (p e r w s rib mod)
921 (letrec*
922 ((rebuild-macro-output
923 (lambda (x m)
924 (cond ((pair? x)
925 (decorate-source
926 (cons (rebuild-macro-output (car x) m)
927 (rebuild-macro-output (cdr x) m))
928 s))
929 ((syntax-object? x)
930 (let ((w (syntax-object-wrap x)))
931 (let ((ms (car w)) (ss (cdr w)))
932 (if (and (pair? ms) (eq? (car ms) #f))
933 (make-syntax-object
934 (syntax-object-expression x)
935 (cons (cdr ms) (if rib (cons rib (cdr ss)) (cdr ss)))
936 (syntax-object-module x))
937 (make-syntax-object
938 (decorate-source (syntax-object-expression x) s)
939 (cons (cons m ms)
940 (if rib (cons rib (cons 'shift ss)) (cons 'shift ss)))
941 (syntax-object-module x))))))
942 ((vector? x)
943 (let* ((n (vector-length x)) (v (decorate-source (make-vector n) s)))
944 (let loop ((i 0))
945 (if (= i n)
946 (begin (if #f #f) v)
947 (begin
948 (vector-set! v i (rebuild-macro-output (vector-ref x i) m))
949 (loop (+ i 1)))))))
950 ((symbol? x)
951 (syntax-violation
952 #f
953 "encountered raw symbol in macro output"
954 (source-wrap e w (cdr w) mod)
955 x))
956 (else (decorate-source x s))))))
957 (with-fluids
958 ((transformer-environment (lambda (k) (k e r w s rib mod))))
959 (rebuild-macro-output
960 (p (source-wrap e (anti-mark w) s mod))
961 (gensym (string-append "m-" (session-id) "-")))))))
962 (expand-body
963 (lambda (body outer-form r w mod)
964 (let* ((r (cons '("placeholder" placeholder) r))
965 (ribcage (make-ribcage '() '() '()))
966 (w (cons (car w) (cons ribcage (cdr w)))))
967 (let parse ((body (map (lambda (x) (cons r (wrap x w mod))) body))
968 (ids '())
969 (labels '())
970 (var-ids '())
971 (vars '())
972 (vals '())
973 (bindings '()))
974 (if (null? body)
975 (syntax-violation #f "no expressions in body" outer-form)
976 (let ((e (cdar body)) (er (caar body)))
977 (call-with-values
978 (lambda ()
979 (syntax-type e er '(()) (source-annotation er) ribcage mod #f))
980 (lambda (type value form e w s mod)
981 (let ((key type))
982 (cond ((memv key '(define-form))
983 (let ((id (wrap value w mod)) (label (gen-label)))
984 (let ((var (gen-var id)))
985 (extend-ribcage! ribcage id label)
986 (parse (cdr body)
987 (cons id ids)
988 (cons label labels)
989 (cons id var-ids)
990 (cons var vars)
991 (cons (cons er (wrap e w mod)) vals)
992 (cons (cons 'lexical var) bindings)))))
993 ((memv key '(define-syntax-form define-syntax-parameter-form))
994 (let ((id (wrap value w mod)) (label (gen-label)))
995 (extend-ribcage! ribcage id label)
996 (parse (cdr body)
997 (cons id ids)
998 (cons label labels)
999 var-ids
1000 vars
1001 vals
1002 (cons (cons 'macro (cons er (wrap e w mod))) bindings))))
1003 ((memv key '(begin-form))
1004 (let* ((tmp-1 e) (tmp ($sc-dispatch tmp-1 '(_ . each-any))))
1005 (if tmp
1006 (apply (lambda (e1)
1007 (parse (let f ((forms e1))
1008 (if (null? forms)
1009 (cdr body)
1010 (cons (cons er (wrap (car forms) w mod)) (f (cdr forms)))))
1011 ids
1012 labels
1013 var-ids
1014 vars
1015 vals
1016 bindings))
1017 tmp)
1018 (syntax-violation
1019 #f
1020 "source expression failed to match any pattern"
1021 tmp-1))))
1022 ((memv key '(local-syntax-form))
1023 (expand-local-syntax
1024 value
1025 e
1026 er
1027 w
1028 s
1029 mod
1030 (lambda (forms er w s mod)
1031 (parse (let f ((forms forms))
1032 (if (null? forms)
1033 (cdr body)
1034 (cons (cons er (wrap (car forms) w mod)) (f (cdr forms)))))
1035 ids
1036 labels
1037 var-ids
1038 vars
1039 vals
1040 bindings))))
1041 ((null? ids)
1042 (build-sequence
1043 #f
1044 (map (lambda (x) (expand (cdr x) (car x) '(()) mod))
1045 (cons (cons er (source-wrap e w s mod)) (cdr body)))))
1046 (else
1047 (if (not (valid-bound-ids? ids))
1048 (syntax-violation
1049 #f
1050 "invalid or duplicate identifier in definition"
1051 outer-form))
1052 (let loop ((bs bindings) (er-cache #f) (r-cache #f))
1053 (if (not (null? bs))
1054 (let ((b (car bs)))
1055 (if (eq? (car b) 'macro)
1056 (let* ((er (cadr b))
1057 (r-cache (if (eq? er er-cache) r-cache (macros-only-env er))))
1058 (set-cdr!
1059 b
1060 (eval-local-transformer (expand (cddr b) r-cache '(()) mod) mod))
1061 (loop (cdr bs) er r-cache))
1062 (loop (cdr bs) er-cache r-cache)))))
1063 (set-cdr! r (extend-env labels bindings (cdr r)))
1064 (build-letrec
1065 #f
1066 #t
1067 (reverse (map syntax->datum var-ids))
1068 (reverse vars)
1069 (map (lambda (x) (expand (cdr x) (car x) '(()) mod)) (reverse vals))
1070 (build-sequence
1071 #f
1072 (map (lambda (x) (expand (cdr x) (car x) '(()) mod))
1073 (cons (cons er (source-wrap e w s mod)) (cdr body))))))))))))))))
1074 (expand-local-syntax
1075 (lambda (rec? e r w s mod k)
1076 (let* ((tmp e)
1077 (tmp ($sc-dispatch tmp '(_ #(each (any any)) any . each-any))))
1078 (if tmp
1079 (apply (lambda (id val e1 e2)
1080 (let ((ids id))
1081 (if (not (valid-bound-ids? ids))
1082 (syntax-violation #f "duplicate bound keyword" e)
1083 (let* ((labels (gen-labels ids)) (new-w (make-binding-wrap ids labels w)))
1084 (k (cons e1 e2)
1085 (extend-env
1086 labels
1087 (let ((w (if rec? new-w w)) (trans-r (macros-only-env r)))
1088 (map (lambda (x)
1089 (cons 'macro (eval-local-transformer (expand x trans-r w mod) mod)))
1090 val))
1091 r)
1092 new-w
1093 s
1094 mod)))))
1095 tmp)
1096 (syntax-violation
1097 #f
1098 "bad local syntax definition"
1099 (source-wrap e w s mod))))))
1100 (eval-local-transformer
1101 (lambda (expanded mod)
1102 (let ((p (local-eval-hook expanded mod)))
1103 (if (procedure? p)
1104 p
1105 (syntax-violation #f "nonprocedure transformer" p)))))
1106 (expand-void (lambda () (build-void #f)))
1107 (ellipsis?
1108 (lambda (x)
1109 (and (nonsymbol-id? x)
1110 (free-id=? x '#(syntax-object ... ((top)) (hygiene guile))))))
1111 (lambda-formals
1112 (lambda (orig-args)
1113 (letrec*
1114 ((req (lambda (args rreq)
1115 (let* ((tmp args) (tmp-1 ($sc-dispatch tmp '())))
1116 (if tmp-1
1117 (apply (lambda () (check (reverse rreq) #f)) tmp-1)
1118 (let ((tmp-1 ($sc-dispatch tmp '(any . any))))
1119 (if (and tmp-1 (apply (lambda (a b) (id? a)) tmp-1))
1120 (apply (lambda (a b) (req b (cons a rreq))) tmp-1)
1121 (let ((tmp-1 (list tmp)))
1122 (if (and tmp-1 (apply (lambda (r) (id? r)) tmp-1))
1123 (apply (lambda (r) (check (reverse rreq) r)) tmp-1)
1124 (let ((else tmp))
1125 (syntax-violation 'lambda "invalid argument list" orig-args args))))))))))
1126 (check (lambda (req rest)
1127 (if (distinct-bound-ids? (if rest (cons rest req) req))
1128 (values req #f rest #f)
1129 (syntax-violation
1130 'lambda
1131 "duplicate identifier in argument list"
1132 orig-args)))))
1133 (req orig-args '()))))
1134 (expand-simple-lambda
1135 (lambda (e r w s mod req rest meta body)
1136 (let* ((ids (if rest (append req (list rest)) req))
1137 (vars (map gen-var ids))
1138 (labels (gen-labels ids)))
1139 (build-simple-lambda
1140 s
1141 (map syntax->datum req)
1142 (and rest (syntax->datum rest))
1143 vars
1144 meta
1145 (expand-body
1146 body
1147 (source-wrap e w s mod)
1148 (extend-var-env labels vars r)
1149 (make-binding-wrap ids labels w)
1150 mod)))))
1151 (lambda*-formals
1152 (lambda (orig-args)
1153 (letrec*
1154 ((req (lambda (args rreq)
1155 (let* ((tmp args) (tmp-1 ($sc-dispatch tmp '())))
1156 (if tmp-1
1157 (apply (lambda () (check (reverse rreq) '() #f '())) tmp-1)
1158 (let ((tmp-1 ($sc-dispatch tmp '(any . any))))
1159 (if (and tmp-1 (apply (lambda (a b) (id? a)) tmp-1))
1160 (apply (lambda (a b) (req b (cons a rreq))) tmp-1)
1161 (let ((tmp-1 ($sc-dispatch tmp '(any . any))))
1162 (if (and tmp-1
1163 (apply (lambda (a b) (eq? (syntax->datum a) #:optional)) tmp-1))
1164 (apply (lambda (a b) (opt b (reverse rreq) '())) tmp-1)
1165 (let ((tmp-1 ($sc-dispatch tmp '(any . any))))
1166 (if (and tmp-1
1167 (apply (lambda (a b) (eq? (syntax->datum a) #:key)) tmp-1))
1168 (apply (lambda (a b) (key b (reverse rreq) '() '())) tmp-1)
1169 (let ((tmp-1 ($sc-dispatch tmp '(any any))))
1170 (if (and tmp-1
1171 (apply (lambda (a b) (eq? (syntax->datum a) #:rest)) tmp-1))
1172 (apply (lambda (a b) (rest b (reverse rreq) '() '())) tmp-1)
1173 (let ((tmp-1 (list tmp)))
1174 (if (and tmp-1 (apply (lambda (r) (id? r)) tmp-1))
1175 (apply (lambda (r) (rest r (reverse rreq) '() '())) tmp-1)
1176 (let ((else tmp))
1177 (syntax-violation
1178 'lambda*
1179 "invalid argument list"
1180 orig-args
1181 args))))))))))))))))
1182 (opt (lambda (args req ropt)
1183 (let* ((tmp args) (tmp-1 ($sc-dispatch tmp '())))
1184 (if tmp-1
1185 (apply (lambda () (check req (reverse ropt) #f '())) tmp-1)
1186 (let ((tmp-1 ($sc-dispatch tmp '(any . any))))
1187 (if (and tmp-1 (apply (lambda (a b) (id? a)) tmp-1))
1188 (apply (lambda (a b) (opt b req (cons (cons a '(#f)) ropt))) tmp-1)
1189 (let ((tmp-1 ($sc-dispatch tmp '((any any) . any))))
1190 (if (and tmp-1 (apply (lambda (a init b) (id? a)) tmp-1))
1191 (apply (lambda (a init b) (opt b req (cons (list a init) ropt)))
1192 tmp-1)
1193 (let ((tmp-1 ($sc-dispatch tmp '(any . any))))
1194 (if (and tmp-1
1195 (apply (lambda (a b) (eq? (syntax->datum a) #:key)) tmp-1))
1196 (apply (lambda (a b) (key b req (reverse ropt) '())) tmp-1)
1197 (let ((tmp-1 ($sc-dispatch tmp '(any any))))
1198 (if (and tmp-1
1199 (apply (lambda (a b) (eq? (syntax->datum a) #:rest)) tmp-1))
1200 (apply (lambda (a b) (rest b req (reverse ropt) '())) tmp-1)
1201 (let ((tmp-1 (list tmp)))
1202 (if (and tmp-1 (apply (lambda (r) (id? r)) tmp-1))
1203 (apply (lambda (r) (rest r req (reverse ropt) '())) tmp-1)
1204 (let ((else tmp))
1205 (syntax-violation
1206 'lambda*
1207 "invalid optional argument list"
1208 orig-args
1209 args))))))))))))))))
1210 (key (lambda (args req opt rkey)
1211 (let* ((tmp args) (tmp-1 ($sc-dispatch tmp '())))
1212 (if tmp-1
1213 (apply (lambda () (check req opt #f (cons #f (reverse rkey)))) tmp-1)
1214 (let ((tmp-1 ($sc-dispatch tmp '(any . any))))
1215 (if (and tmp-1 (apply (lambda (a b) (id? a)) tmp-1))
1216 (apply (lambda (a b)
1217 (let* ((tmp (symbol->keyword (syntax->datum a))) (k tmp))
1218 (key b req opt (cons (cons k (cons a '(#f))) rkey))))
1219 tmp-1)
1220 (let ((tmp-1 ($sc-dispatch tmp '((any any) . any))))
1221 (if (and tmp-1 (apply (lambda (a init b) (id? a)) tmp-1))
1222 (apply (lambda (a init b)
1223 (let* ((tmp (symbol->keyword (syntax->datum a))) (k tmp))
1224 (key b req opt (cons (list k a init) rkey))))
1225 tmp-1)
1226 (let ((tmp-1 ($sc-dispatch tmp '((any any any) . any))))
1227 (if (and tmp-1
1228 (apply (lambda (a init k b) (and (id? a) (keyword? (syntax->datum k))))
1229 tmp-1))
1230 (apply (lambda (a init k b) (key b req opt (cons (list k a init) rkey)))
1231 tmp-1)
1232 (let ((tmp-1 ($sc-dispatch tmp '(any))))
1233 (if (and tmp-1
1234 (apply (lambda (aok) (eq? (syntax->datum aok) #:allow-other-keys))
1235 tmp-1))
1236 (apply (lambda (aok) (check req opt #f (cons #t (reverse rkey))))
1237 tmp-1)
1238 (let ((tmp-1 ($sc-dispatch tmp '(any any any))))
1239 (if (and tmp-1
1240 (apply (lambda (aok a b)
1241 (and (eq? (syntax->datum aok) #:allow-other-keys)
1242 (eq? (syntax->datum a) #:rest)))
1243 tmp-1))
1244 (apply (lambda (aok a b) (rest b req opt (cons #t (reverse rkey))))
1245 tmp-1)
1246 (let ((tmp-1 ($sc-dispatch tmp '(any . any))))
1247 (if (and tmp-1
1248 (apply (lambda (aok r)
1249 (and (eq? (syntax->datum aok) #:allow-other-keys) (id? r)))
1250 tmp-1))
1251 (apply (lambda (aok r) (rest r req opt (cons #t (reverse rkey))))
1252 tmp-1)
1253 (let ((tmp-1 ($sc-dispatch tmp '(any any))))
1254 (if (and tmp-1
1255 (apply (lambda (a b) (eq? (syntax->datum a) #:rest)) tmp-1))
1256 (apply (lambda (a b) (rest b req opt (cons #f (reverse rkey))))
1257 tmp-1)
1258 (let ((tmp-1 (list tmp)))
1259 (if (and tmp-1 (apply (lambda (r) (id? r)) tmp-1))
1260 (apply (lambda (r) (rest r req opt (cons #f (reverse rkey))))
1261 tmp-1)
1262 (let ((else tmp))
1263 (syntax-violation
1264 'lambda*
1265 "invalid keyword argument list"
1266 orig-args
1267 args))))))))))))))))))))))
1268 (rest (lambda (args req opt kw)
1269 (let* ((tmp-1 args) (tmp (list tmp-1)))
1270 (if (and tmp (apply (lambda (r) (id? r)) tmp))
1271 (apply (lambda (r) (check req opt r kw)) tmp)
1272 (let ((else tmp-1))
1273 (syntax-violation 'lambda* "invalid rest argument" orig-args args))))))
1274 (check (lambda (req opt rest kw)
1275 (if (distinct-bound-ids?
1276 (append
1277 req
1278 (map car opt)
1279 (if rest (list rest) '())
1280 (if (pair? kw) (map cadr (cdr kw)) '())))
1281 (values req opt rest kw)
1282 (syntax-violation
1283 'lambda*
1284 "duplicate identifier in argument list"
1285 orig-args)))))
1286 (req orig-args '()))))
1287 (expand-lambda-case
1288 (lambda (e r w s mod get-formals clauses)
1289 (letrec*
1290 ((parse-req
1291 (lambda (req opt rest kw body)
1292 (let ((vars (map gen-var req)) (labels (gen-labels req)))
1293 (let ((r* (extend-var-env labels vars r))
1294 (w* (make-binding-wrap req labels w)))
1295 (parse-opt
1296 (map syntax->datum req)
1297 opt
1298 rest
1299 kw
1300 body
1301 (reverse vars)
1302 r*
1303 w*
1304 '()
1305 '())))))
1306 (parse-opt
1307 (lambda (req opt rest kw body vars r* w* out inits)
1308 (cond ((pair? opt)
1309 (let* ((tmp-1 (car opt)) (tmp ($sc-dispatch tmp-1 '(any any))))
1310 (if tmp
1311 (apply (lambda (id i)
1312 (let* ((v (gen-var id))
1313 (l (gen-labels (list v)))
1314 (r** (extend-var-env l (list v) r*))
1315 (w** (make-binding-wrap (list id) l w*)))
1316 (parse-opt
1317 req
1318 (cdr opt)
1319 rest
1320 kw
1321 body
1322 (cons v vars)
1323 r**
1324 w**
1325 (cons (syntax->datum id) out)
1326 (cons (expand i r* w* mod) inits))))
1327 tmp)
1328 (syntax-violation
1329 #f
1330 "source expression failed to match any pattern"
1331 tmp-1))))
1332 (rest
1333 (let* ((v (gen-var rest))
1334 (l (gen-labels (list v)))
1335 (r* (extend-var-env l (list v) r*))
1336 (w* (make-binding-wrap (list rest) l w*)))
1337 (parse-kw
1338 req
1339 (and (pair? out) (reverse out))
1340 (syntax->datum rest)
1341 (if (pair? kw) (cdr kw) kw)
1342 body
1343 (cons v vars)
1344 r*
1345 w*
1346 (and (pair? kw) (car kw))
1347 '()
1348 inits)))
1349 (else
1350 (parse-kw
1351 req
1352 (and (pair? out) (reverse out))
1353 #f
1354 (if (pair? kw) (cdr kw) kw)
1355 body
1356 vars
1357 r*
1358 w*
1359 (and (pair? kw) (car kw))
1360 '()
1361 inits)))))
1362 (parse-kw
1363 (lambda (req opt rest kw body vars r* w* aok out inits)
1364 (if (pair? kw)
1365 (let* ((tmp-1 (car kw)) (tmp ($sc-dispatch tmp-1 '(any any any))))
1366 (if tmp
1367 (apply (lambda (k id i)
1368 (let* ((v (gen-var id))
1369 (l (gen-labels (list v)))
1370 (r** (extend-var-env l (list v) r*))
1371 (w** (make-binding-wrap (list id) l w*)))
1372 (parse-kw
1373 req
1374 opt
1375 rest
1376 (cdr kw)
1377 body
1378 (cons v vars)
1379 r**
1380 w**
1381 aok
1382 (cons (list (syntax->datum k) (syntax->datum id) v) out)
1383 (cons (expand i r* w* mod) inits))))
1384 tmp)
1385 (syntax-violation
1386 #f
1387 "source expression failed to match any pattern"
1388 tmp-1)))
1389 (parse-body
1390 req
1391 opt
1392 rest
1393 (and (or aok (pair? out)) (cons aok (reverse out)))
1394 body
1395 (reverse vars)
1396 r*
1397 w*
1398 (reverse inits)
1399 '()))))
1400 (parse-body
1401 (lambda (req opt rest kw body vars r* w* inits meta)
1402 (let* ((tmp body) (tmp-1 ($sc-dispatch tmp '(any any . each-any))))
1403 (if (and tmp-1
1404 (apply (lambda (docstring e1 e2) (string? (syntax->datum docstring)))
1405 tmp-1))
1406 (apply (lambda (docstring e1 e2)
1407 (parse-body
1408 req
1409 opt
1410 rest
1411 kw
1412 (cons e1 e2)
1413 vars
1414 r*
1415 w*
1416 inits
1417 (append meta (list (cons 'documentation (syntax->datum docstring))))))
1418 tmp-1)
1419 (let ((tmp-1 ($sc-dispatch tmp '(#(vector #(each (any . any))) any . each-any))))
1420 (if tmp-1
1421 (apply (lambda (k v e1 e2)
1422 (parse-body
1423 req
1424 opt
1425 rest
1426 kw
1427 (cons e1 e2)
1428 vars
1429 r*
1430 w*
1431 inits
1432 (append meta (syntax->datum (map cons k v)))))
1433 tmp-1)
1434 (let ((tmp-1 ($sc-dispatch tmp '(any . each-any))))
1435 (if tmp-1
1436 (apply (lambda (e1 e2)
1437 (values
1438 meta
1439 req
1440 opt
1441 rest
1442 kw
1443 inits
1444 vars
1445 (expand-body (cons e1 e2) (source-wrap e w s mod) r* w* mod)))
1446 tmp-1)
1447 (syntax-violation
1448 #f
1449 "source expression failed to match any pattern"
1450 tmp))))))))))
1451 (let* ((tmp clauses) (tmp-1 ($sc-dispatch tmp '())))
1452 (if tmp-1
1453 (apply (lambda () (values '() #f)) tmp-1)
1454 (let ((tmp-1 ($sc-dispatch
1455 tmp
1456 '((any any . each-any) . #(each (any any . each-any))))))
1457 (if tmp-1
1458 (apply (lambda (args e1 e2 args* e1* e2*)
1459 (call-with-values
1460 (lambda () (get-formals args))
1461 (lambda (req opt rest kw)
1462 (call-with-values
1463 (lambda () (parse-req req opt rest kw (cons e1 e2)))
1464 (lambda (meta req opt rest kw inits vars body)
1465 (call-with-values
1466 (lambda ()
1467 (expand-lambda-case
1468 e
1469 r
1470 w
1471 s
1472 mod
1473 get-formals
1474 (map (lambda (tmp-2 tmp-1 tmp) (cons tmp (cons tmp-1 tmp-2)))
1475 e2*
1476 e1*
1477 args*)))
1478 (lambda (meta* else*)
1479 (values
1480 (append meta meta*)
1481 (build-lambda-case s req opt rest kw inits vars body else*)))))))))
1482 tmp-1)
1483 (syntax-violation
1484 #f
1485 "source expression failed to match any pattern"
1486 tmp))))))))
1487 (strip (lambda (x w)
1488 (if (memq 'top (car w))
1489 x
1490 (let f ((x x))
1491 (cond ((syntax-object? x)
1492 (strip (syntax-object-expression x) (syntax-object-wrap x)))
1493 ((pair? x)
1494 (let ((a (f (car x))) (d (f (cdr x))))
1495 (if (and (eq? a (car x)) (eq? d (cdr x))) x (cons a d))))
1496 ((vector? x)
1497 (let* ((old (vector->list x)) (new (map f old)))
1498 (let lp ((l1 old) (l2 new))
1499 (cond ((null? l1) x)
1500 ((eq? (car l1) (car l2)) (lp (cdr l1) (cdr l2)))
1501 (else (list->vector new))))))
1502 (else x))))))
1503 (gen-var
1504 (lambda (id)
1505 (let ((id (if (syntax-object? id) (syntax-object-expression id) id)))
1506 (gensym (string-append (symbol->string id) "-")))))
1507 (lambda-var-list
1508 (lambda (vars)
1509 (let lvl ((vars vars) (ls '()) (w '(())))
1510 (cond ((pair? vars) (lvl (cdr vars) (cons (wrap (car vars) w #f) ls) w))
1511 ((id? vars) (cons (wrap vars w #f) ls))
1512 ((null? vars) ls)
1513 ((syntax-object? vars)
1514 (lvl (syntax-object-expression vars)
1515 ls
1516 (join-wraps w (syntax-object-wrap vars))))
1517 (else (cons vars ls)))))))
1518 (global-extend 'local-syntax 'letrec-syntax #t)
1519 (global-extend 'local-syntax 'let-syntax #f)
1520 (global-extend
1521 'core
1522 'syntax-parameterize
1523 (lambda (e r w s mod)
1524 (let* ((tmp e)
1525 (tmp ($sc-dispatch tmp '(_ #(each (any any)) any . each-any))))
1526 (if (and tmp (apply (lambda (var val e1 e2) (valid-bound-ids? var)) tmp))
1527 (apply (lambda (var val e1 e2)
1528 (let ((names (map (lambda (x) (id-var-name x w)) var)))
1529 (for-each
1530 (lambda (id n)
1531 (let ((key (car (lookup n r mod))))
1532 (if (memv key '(displaced-lexical))
1533 (syntax-violation
1534 'syntax-parameterize
1535 "identifier out of context"
1536 e
1537 (source-wrap id w s mod)))))
1538 var
1539 names)
1540 (expand-body
1541 (cons e1 e2)
1542 (source-wrap e w s mod)
1543 (extend-env
1544 names
1545 (let ((trans-r (macros-only-env r)))
1546 (map (lambda (x)
1547 (cons 'macro (eval-local-transformer (expand x trans-r w mod) mod)))
1548 val))
1549 r)
1550 w
1551 mod)))
1552 tmp)
1553 (syntax-violation
1554 'syntax-parameterize
1555 "bad syntax"
1556 (source-wrap e w s mod))))))
1557 (global-extend
1558 'core
1559 'quote
1560 (lambda (e r w s mod)
1561 (let* ((tmp e) (tmp ($sc-dispatch tmp '(_ any))))
1562 (if tmp
1563 (apply (lambda (e) (build-data s (strip e w))) tmp)
1564 (syntax-violation 'quote "bad syntax" (source-wrap e w s mod))))))
1565 (global-extend
1566 'core
1567 'syntax
1568 (letrec*
1569 ((gen-syntax
1570 (lambda (src e r maps ellipsis? mod)
1571 (if (id? e)
1572 (let* ((label (id-var-name e '(()))) (b (lookup label r mod)))
1573 (cond ((eq? (car b) 'syntax)
1574 (call-with-values
1575 (lambda ()
1576 (let ((var.lev (cdr b)))
1577 (gen-ref src (car var.lev) (cdr var.lev) maps)))
1578 (lambda (var maps) (values (list 'ref var) maps))))
1579 ((ellipsis? e) (syntax-violation 'syntax "misplaced ellipsis" src))
1580 (else (values (list 'quote e) maps))))
1581 (let* ((tmp e) (tmp-1 ($sc-dispatch tmp '(any any))))
1582 (if (and tmp-1 (apply (lambda (dots e) (ellipsis? dots)) tmp-1))
1583 (apply (lambda (dots e) (gen-syntax src e r maps (lambda (x) #f) mod))
1584 tmp-1)
1585 (let ((tmp-1 ($sc-dispatch tmp '(any any . any))))
1586 (if (and tmp-1 (apply (lambda (x dots y) (ellipsis? dots)) tmp-1))
1587 (apply (lambda (x dots y)
1588 (let f ((y y)
1589 (k (lambda (maps)
1590 (call-with-values
1591 (lambda () (gen-syntax src x r (cons '() maps) ellipsis? mod))
1592 (lambda (x maps)
1593 (if (null? (car maps))
1594 (syntax-violation 'syntax "extra ellipsis" src)
1595 (values (gen-map x (car maps)) (cdr maps))))))))
1596 (let* ((tmp y) (tmp ($sc-dispatch tmp '(any . any))))
1597 (if (and tmp (apply (lambda (dots y) (ellipsis? dots)) tmp))
1598 (apply (lambda (dots y)
1599 (f y
1600 (lambda (maps)
1601 (call-with-values
1602 (lambda () (k (cons '() maps)))
1603 (lambda (x maps)
1604 (if (null? (car maps))
1605 (syntax-violation 'syntax "extra ellipsis" src)
1606 (values (gen-mappend x (car maps)) (cdr maps))))))))
1607 tmp)
1608 (call-with-values
1609 (lambda () (gen-syntax src y r maps ellipsis? mod))
1610 (lambda (y maps)
1611 (call-with-values
1612 (lambda () (k maps))
1613 (lambda (x maps) (values (gen-append x y) maps)))))))))
1614 tmp-1)
1615 (let ((tmp-1 ($sc-dispatch tmp '(any . any))))
1616 (if tmp-1
1617 (apply (lambda (x y)
1618 (call-with-values
1619 (lambda () (gen-syntax src x r maps ellipsis? mod))
1620 (lambda (x maps)
1621 (call-with-values
1622 (lambda () (gen-syntax src y r maps ellipsis? mod))
1623 (lambda (y maps) (values (gen-cons x y) maps))))))
1624 tmp-1)
1625 (let ((tmp ($sc-dispatch tmp '#(vector (any . each-any)))))
1626 (if tmp
1627 (apply (lambda (e1 e2)
1628 (call-with-values
1629 (lambda () (gen-syntax src (cons e1 e2) r maps ellipsis? mod))
1630 (lambda (e maps) (values (gen-vector e) maps))))
1631 tmp)
1632 (values (list 'quote e) maps))))))))))))
1633 (gen-ref
1634 (lambda (src var level maps)
1635 (cond ((= level 0) (values var maps))
1636 ((null? maps) (syntax-violation 'syntax "missing ellipsis" src))
1637 (else
1638 (call-with-values
1639 (lambda () (gen-ref src var (- level 1) (cdr maps)))
1640 (lambda (outer-var outer-maps)
1641 (let ((b (assq outer-var (car maps))))
1642 (if b
1643 (values (cdr b) maps)
1644 (let ((inner-var (gen-var 'tmp)))
1645 (values
1646 inner-var
1647 (cons (cons (cons outer-var inner-var) (car maps)) outer-maps)))))))))))
1648 (gen-mappend
1649 (lambda (e map-env)
1650 (list 'apply '(primitive append) (gen-map e map-env))))
1651 (gen-map
1652 (lambda (e map-env)
1653 (let ((formals (map cdr map-env))
1654 (actuals (map (lambda (x) (list 'ref (car x))) map-env)))
1655 (cond ((eq? (car e) 'ref) (car actuals))
1656 ((and-map
1657 (lambda (x) (and (eq? (car x) 'ref) (memq (cadr x) formals)))
1658 (cdr e))
1659 (cons 'map
1660 (cons (list 'primitive (car e))
1661 (map (let ((r (map cons formals actuals)))
1662 (lambda (x) (cdr (assq (cadr x) r))))
1663 (cdr e)))))
1664 (else (cons 'map (cons (list 'lambda formals e) actuals)))))))
1665 (gen-cons
1666 (lambda (x y)
1667 (let ((key (car y)))
1668 (cond ((memv key '(quote))
1669 (cond ((eq? (car x) 'quote) (list 'quote (cons (cadr x) (cadr y))))
1670 ((eq? (cadr y) '()) (list 'list x))
1671 (else (list 'cons x y))))
1672 ((memv key '(list)) (cons 'list (cons x (cdr y))))
1673 (else (list 'cons x y))))))
1674 (gen-append (lambda (x y) (if (equal? y ''()) x (list 'append x y))))
1675 (gen-vector
1676 (lambda (x)
1677 (cond ((eq? (car x) 'list) (cons 'vector (cdr x)))
1678 ((eq? (car x) 'quote) (list 'quote (list->vector (cadr x))))
1679 (else (list 'list->vector x)))))
1680 (regen (lambda (x)
1681 (let ((key (car x)))
1682 (cond ((memv key '(ref))
1683 (build-lexical-reference 'value #f (cadr x) (cadr x)))
1684 ((memv key '(primitive)) (build-primref #f (cadr x)))
1685 ((memv key '(quote)) (build-data #f (cadr x)))
1686 ((memv key '(lambda))
1687 (if (list? (cadr x))
1688 (build-simple-lambda #f (cadr x) #f (cadr x) '() (regen (caddr x)))
1689 (error "how did we get here" x)))
1690 (else
1691 (build-application #f (build-primref #f (car x)) (map regen (cdr x)))))))))
1692 (lambda (e r w s mod)
1693 (let* ((e (source-wrap e w s mod))
1694 (tmp e)
1695 (tmp ($sc-dispatch tmp '(_ any))))
1696 (if tmp
1697 (apply (lambda (x)
1698 (call-with-values
1699 (lambda () (gen-syntax e x r '() ellipsis? mod))
1700 (lambda (e maps) (regen e))))
1701 tmp)
1702 (syntax-violation 'syntax "bad `syntax' form" e))))))
1703 (global-extend
1704 'core
1705 'lambda
1706 (lambda (e r w s mod)
1707 (let* ((tmp e) (tmp ($sc-dispatch tmp '(_ any any . each-any))))
1708 (if tmp
1709 (apply (lambda (args e1 e2)
1710 (call-with-values
1711 (lambda () (lambda-formals args))
1712 (lambda (req opt rest kw)
1713 (let lp ((body (cons e1 e2)) (meta '()))
1714 (let* ((tmp-1 body) (tmp ($sc-dispatch tmp-1 '(any any . each-any))))
1715 (if (and tmp
1716 (apply (lambda (docstring e1 e2) (string? (syntax->datum docstring)))
1717 tmp))
1718 (apply (lambda (docstring e1 e2)
1719 (lp (cons e1 e2)
1720 (append meta (list (cons 'documentation (syntax->datum docstring))))))
1721 tmp)
1722 (let ((tmp ($sc-dispatch tmp-1 '(#(vector #(each (any . any))) any . each-any))))
1723 (if tmp
1724 (apply (lambda (k v e1 e2)
1725 (lp (cons e1 e2) (append meta (syntax->datum (map cons k v)))))
1726 tmp)
1727 (expand-simple-lambda e r w s mod req rest meta body)))))))))
1728 tmp)
1729 (syntax-violation 'lambda "bad lambda" e)))))
1730 (global-extend
1731 'core
1732 'lambda*
1733 (lambda (e r w s mod)
1734 (let* ((tmp e) (tmp ($sc-dispatch tmp '(_ any any . each-any))))
1735 (if tmp
1736 (apply (lambda (args e1 e2)
1737 (call-with-values
1738 (lambda ()
1739 (expand-lambda-case
1740 e
1741 r
1742 w
1743 s
1744 mod
1745 lambda*-formals
1746 (list (cons args (cons e1 e2)))))
1747 (lambda (meta lcase) (build-case-lambda s meta lcase))))
1748 tmp)
1749 (syntax-violation 'lambda "bad lambda*" e)))))
1750 (global-extend
1751 'core
1752 'case-lambda
1753 (lambda (e r w s mod)
1754 (let* ((tmp e)
1755 (tmp ($sc-dispatch
1756 tmp
1757 '(_ (any any . each-any) . #(each (any any . each-any))))))
1758 (if tmp
1759 (apply (lambda (args e1 e2 args* e1* e2*)
1760 (call-with-values
1761 (lambda ()
1762 (expand-lambda-case
1763 e
1764 r
1765 w
1766 s
1767 mod
1768 lambda-formals
1769 (cons (cons args (cons e1 e2))
1770 (map (lambda (tmp-2 tmp-1 tmp) (cons tmp (cons tmp-1 tmp-2)))
1771 e2*
1772 e1*
1773 args*))))
1774 (lambda (meta lcase) (build-case-lambda s meta lcase))))
1775 tmp)
1776 (syntax-violation 'case-lambda "bad case-lambda" e)))))
1777 (global-extend
1778 'core
1779 'case-lambda*
1780 (lambda (e r w s mod)
1781 (let* ((tmp e)
1782 (tmp ($sc-dispatch
1783 tmp
1784 '(_ (any any . each-any) . #(each (any any . each-any))))))
1785 (if tmp
1786 (apply (lambda (args e1 e2 args* e1* e2*)
1787 (call-with-values
1788 (lambda ()
1789 (expand-lambda-case
1790 e
1791 r
1792 w
1793 s
1794 mod
1795 lambda*-formals
1796 (cons (cons args (cons e1 e2))
1797 (map (lambda (tmp-2 tmp-1 tmp) (cons tmp (cons tmp-1 tmp-2)))
1798 e2*
1799 e1*
1800 args*))))
1801 (lambda (meta lcase) (build-case-lambda s meta lcase))))
1802 tmp)
1803 (syntax-violation 'case-lambda "bad case-lambda*" e)))))
1804 (global-extend
1805 'core
1806 'let
1807 (letrec*
1808 ((expand-let
1809 (lambda (e r w s mod constructor ids vals exps)
1810 (if (not (valid-bound-ids? ids))
1811 (syntax-violation 'let "duplicate bound variable" e)
1812 (let ((labels (gen-labels ids)) (new-vars (map gen-var ids)))
1813 (let ((nw (make-binding-wrap ids labels w))
1814 (nr (extend-var-env labels new-vars r)))
1815 (constructor
1816 s
1817 (map syntax->datum ids)
1818 new-vars
1819 (map (lambda (x) (expand x r w mod)) vals)
1820 (expand-body exps (source-wrap e nw s mod) nr nw mod))))))))
1821 (lambda (e r w s mod)
1822 (let* ((tmp-1 e)
1823 (tmp ($sc-dispatch tmp-1 '(_ #(each (any any)) any . each-any))))
1824 (if (and tmp (apply (lambda (id val e1 e2) (and-map id? id)) tmp))
1825 (apply (lambda (id val e1 e2)
1826 (expand-let e r w s mod build-let id val (cons e1 e2)))
1827 tmp)
1828 (let ((tmp ($sc-dispatch tmp-1 '(_ any #(each (any any)) any . each-any))))
1829 (if (and tmp
1830 (apply (lambda (f id val e1 e2) (and (id? f) (and-map id? id))) tmp))
1831 (apply (lambda (f id val e1 e2)
1832 (expand-let e r w s mod build-named-let (cons f id) val (cons e1 e2)))
1833 tmp)
1834 (syntax-violation 'let "bad let" (source-wrap e w s mod)))))))))
1835 (global-extend
1836 'core
1837 'letrec
1838 (lambda (e r w s mod)
1839 (let* ((tmp e)
1840 (tmp ($sc-dispatch tmp '(_ #(each (any any)) any . each-any))))
1841 (if (and tmp (apply (lambda (id val e1 e2) (and-map id? id)) tmp))
1842 (apply (lambda (id val e1 e2)
1843 (let ((ids id))
1844 (if (not (valid-bound-ids? ids))
1845 (syntax-violation 'letrec "duplicate bound variable" e)
1846 (let ((labels (gen-labels ids)) (new-vars (map gen-var ids)))
1847 (let ((w (make-binding-wrap ids labels w))
1848 (r (extend-var-env labels new-vars r)))
1849 (build-letrec
1850 s
1851 #f
1852 (map syntax->datum ids)
1853 new-vars
1854 (map (lambda (x) (expand x r w mod)) val)
1855 (expand-body (cons e1 e2) (source-wrap e w s mod) r w mod)))))))
1856 tmp)
1857 (syntax-violation 'letrec "bad letrec" (source-wrap e w s mod))))))
1858 (global-extend
1859 'core
1860 'letrec*
1861 (lambda (e r w s mod)
1862 (let* ((tmp e)
1863 (tmp ($sc-dispatch tmp '(_ #(each (any any)) any . each-any))))
1864 (if (and tmp (apply (lambda (id val e1 e2) (and-map id? id)) tmp))
1865 (apply (lambda (id val e1 e2)
1866 (let ((ids id))
1867 (if (not (valid-bound-ids? ids))
1868 (syntax-violation 'letrec* "duplicate bound variable" e)
1869 (let ((labels (gen-labels ids)) (new-vars (map gen-var ids)))
1870 (let ((w (make-binding-wrap ids labels w))
1871 (r (extend-var-env labels new-vars r)))
1872 (build-letrec
1873 s
1874 #t
1875 (map syntax->datum ids)
1876 new-vars
1877 (map (lambda (x) (expand x r w mod)) val)
1878 (expand-body (cons e1 e2) (source-wrap e w s mod) r w mod)))))))
1879 tmp)
1880 (syntax-violation 'letrec* "bad letrec*" (source-wrap e w s mod))))))
1881 (global-extend
1882 'core
1883 'set!
1884 (lambda (e r w s mod)
1885 (let* ((tmp-1 e) (tmp ($sc-dispatch tmp-1 '(_ any any))))
1886 (if (and tmp (apply (lambda (id val) (id? id)) tmp))
1887 (apply (lambda (id val)
1888 (let ((n (id-var-name id w))
1889 (id-mod (if (syntax-object? id) (syntax-object-module id) mod)))
1890 (let* ((b (lookup n r id-mod)) (key (car b)))
1891 (cond ((memv key '(lexical))
1892 (build-lexical-assignment
1893 s
1894 (syntax->datum id)
1895 (cdr b)
1896 (expand val r w mod)))
1897 ((memv key '(global))
1898 (build-global-assignment s n (expand val r w mod) id-mod))
1899 ((memv key '(macro))
1900 (let ((p (cdr b)))
1901 (if (procedure-property p 'variable-transformer)
1902 (expand (expand-macro p e r w s #f mod) r '(()) mod)
1903 (syntax-violation
1904 'set!
1905 "not a variable transformer"
1906 (wrap e w mod)
1907 (wrap id w id-mod)))))
1908 ((memv key '(displaced-lexical))
1909 (syntax-violation 'set! "identifier out of context" (wrap id w mod)))
1910 (else (syntax-violation 'set! "bad set!" (source-wrap e w s mod)))))))
1911 tmp)
1912 (let ((tmp ($sc-dispatch tmp-1 '(_ (any . each-any) any))))
1913 (if tmp
1914 (apply (lambda (head tail val)
1915 (call-with-values
1916 (lambda () (syntax-type head r '(()) #f #f mod #t))
1917 (lambda (type value formform ee ww ss modmod)
1918 (let ((key type))
1919 (if (memv key '(module-ref))
1920 (let ((val (expand val r w mod)))
1921 (call-with-values
1922 (lambda () (value (cons head tail) r w))
1923 (lambda (e r w s* mod)
1924 (let* ((tmp-1 e) (tmp (list tmp-1)))
1925 (if (and tmp (apply (lambda (e) (id? e)) tmp))
1926 (apply (lambda (e) (build-global-assignment s (syntax->datum e) val mod))
1927 tmp)
1928 (syntax-violation
1929 #f
1930 "source expression failed to match any pattern"
1931 tmp-1))))))
1932 (build-application
1933 s
1934 (expand
1935 (list '#(syntax-object setter ((top)) (hygiene guile)) head)
1936 r
1937 w
1938 mod)
1939 (map (lambda (e) (expand e r w mod)) (append tail (list val)))))))))
1940 tmp)
1941 (syntax-violation 'set! "bad set!" (source-wrap e w s mod))))))))
1942 (global-extend
1943 'module-ref
1944 '@
1945 (lambda (e r w)
1946 (let* ((tmp-1 e) (tmp ($sc-dispatch tmp-1 '(_ each-any any))))
1947 (if (and tmp
1948 (apply (lambda (mod id) (and (and-map id? mod) (id? id))) tmp))
1949 (apply (lambda (mod id)
1950 (values
1951 (syntax->datum id)
1952 r
1953 '((top))
1954 #f
1955 (syntax->datum
1956 (cons '#(syntax-object public ((top)) (hygiene guile)) mod))))
1957 tmp)
1958 (syntax-violation
1959 #f
1960 "source expression failed to match any pattern"
1961 tmp-1)))))
1962 (global-extend
1963 'module-ref
1964 '@@
1965 (lambda (e r w)
1966 (letrec*
1967 ((remodulate
1968 (lambda (x mod)
1969 (cond ((pair? x) (cons (remodulate (car x) mod) (remodulate (cdr x) mod)))
1970 ((syntax-object? x)
1971 (make-syntax-object
1972 (remodulate (syntax-object-expression x) mod)
1973 (syntax-object-wrap x)
1974 mod))
1975 ((vector? x)
1976 (let* ((n (vector-length x)) (v (make-vector n)))
1977 (let loop ((i 0))
1978 (if (= i n)
1979 (begin (if #f #f) v)
1980 (begin
1981 (vector-set! v i (remodulate (vector-ref x i) mod))
1982 (loop (+ i 1)))))))
1983 (else x)))))
1984 (let* ((tmp-1 e) (tmp ($sc-dispatch tmp-1 '(_ each-any any))))
1985 (if (and tmp
1986 (apply (lambda (mod id) (and (and-map id? mod) (id? id))) tmp))
1987 (apply (lambda (mod id)
1988 (values
1989 (syntax->datum id)
1990 r
1991 '((top))
1992 #f
1993 (syntax->datum
1994 (cons '#(syntax-object private ((top)) (hygiene guile)) mod))))
1995 tmp)
1996 (let ((tmp ($sc-dispatch
1997 tmp-1
1998 '(_ #(free-id #(syntax-object @@ ((top)) (hygiene guile)))
1999 each-any
2000 any))))
2001 (if (and tmp (apply (lambda (mod exp) (and-map id? mod)) tmp))
2002 (apply (lambda (mod exp)
2003 (let ((mod (syntax->datum
2004 (cons '#(syntax-object private ((top)) (hygiene guile)) mod))))
2005 (values (remodulate exp mod) r w (source-annotation exp) mod)))
2006 tmp)
2007 (syntax-violation
2008 #f
2009 "source expression failed to match any pattern"
2010 tmp-1))))))))
2011 (global-extend
2012 'core
2013 'if
2014 (lambda (e r w s mod)
2015 (let* ((tmp e) (tmp-1 ($sc-dispatch tmp '(_ any any))))
2016 (if tmp-1
2017 (apply (lambda (test then)
2018 (build-conditional
2019 s
2020 (expand test r w mod)
2021 (expand then r w mod)
2022 (build-void #f)))
2023 tmp-1)
2024 (let ((tmp-1 ($sc-dispatch tmp '(_ any any any))))
2025 (if tmp-1
2026 (apply (lambda (test then else)
2027 (build-conditional
2028 s
2029 (expand test r w mod)
2030 (expand then r w mod)
2031 (expand else r w mod)))
2032 tmp-1)
2033 (syntax-violation
2034 #f
2035 "source expression failed to match any pattern"
2036 tmp)))))))
2037 (global-extend
2038 'core
2039 'with-fluids
2040 (lambda (e r w s mod)
2041 (let* ((tmp-1 e)
2042 (tmp ($sc-dispatch tmp-1 '(_ #(each (any any)) any . each-any))))
2043 (if tmp
2044 (apply (lambda (fluid val b b*)
2045 (build-dynlet
2046 s
2047 (map (lambda (x) (expand x r w mod)) fluid)
2048 (map (lambda (x) (expand x r w mod)) val)
2049 (expand-body (cons b b*) (source-wrap e w s mod) r w mod)))
2050 tmp)
2051 (syntax-violation
2052 #f
2053 "source expression failed to match any pattern"
2054 tmp-1)))))
2055 (global-extend 'begin 'begin '())
2056 (global-extend 'define 'define '())
2057 (global-extend 'define-syntax 'define-syntax '())
2058 (global-extend 'define-syntax-parameter 'define-syntax-parameter '())
2059 (global-extend 'eval-when 'eval-when '())
2060 (global-extend
2061 'core
2062 'syntax-case
2063 (letrec*
2064 ((convert-pattern
2065 (lambda (pattern keys)
2066 (letrec*
2067 ((cvt* (lambda (p* n ids)
2068 (if (not (pair? p*))
2069 (cvt p* n ids)
2070 (call-with-values
2071 (lambda () (cvt* (cdr p*) n ids))
2072 (lambda (y ids)
2073 (call-with-values
2074 (lambda () (cvt (car p*) n ids))
2075 (lambda (x ids) (values (cons x y) ids))))))))
2076 (v-reverse
2077 (lambda (x)
2078 (let loop ((r '()) (x x))
2079 (if (not (pair? x)) (values r x) (loop (cons (car x) r) (cdr x))))))
2080 (cvt (lambda (p n ids)
2081 (if (id? p)
2082 (cond ((bound-id-member? p keys) (values (vector 'free-id p) ids))
2083 ((free-id=? p '#(syntax-object _ ((top)) (hygiene guile)))
2084 (values '_ ids))
2085 (else (values 'any (cons (cons p n) ids))))
2086 (let* ((tmp p) (tmp-1 ($sc-dispatch tmp '(any any))))
2087 (if (and tmp-1 (apply (lambda (x dots) (ellipsis? dots)) tmp-1))
2088 (apply (lambda (x dots)
2089 (call-with-values
2090 (lambda () (cvt x (+ n 1) ids))
2091 (lambda (p ids)
2092 (values (if (eq? p 'any) 'each-any (vector 'each p)) ids))))
2093 tmp-1)
2094 (let ((tmp-1 ($sc-dispatch tmp '(any any . any))))
2095 (if (and tmp-1 (apply (lambda (x dots ys) (ellipsis? dots)) tmp-1))
2096 (apply (lambda (x dots ys)
2097 (call-with-values
2098 (lambda () (cvt* ys n ids))
2099 (lambda (ys ids)
2100 (call-with-values
2101 (lambda () (cvt x (+ n 1) ids))
2102 (lambda (x ids)
2103 (call-with-values
2104 (lambda () (v-reverse ys))
2105 (lambda (ys e) (values (vector 'each+ x ys e) ids))))))))
2106 tmp-1)
2107 (let ((tmp-1 ($sc-dispatch tmp '(any . any))))
2108 (if tmp-1
2109 (apply (lambda (x y)
2110 (call-with-values
2111 (lambda () (cvt y n ids))
2112 (lambda (y ids)
2113 (call-with-values
2114 (lambda () (cvt x n ids))
2115 (lambda (x ids) (values (cons x y) ids))))))
2116 tmp-1)
2117 (let ((tmp-1 ($sc-dispatch tmp '())))
2118 (if tmp-1
2119 (apply (lambda () (values '() ids)) tmp-1)
2120 (let ((tmp-1 ($sc-dispatch tmp '#(vector each-any))))
2121 (if tmp-1
2122 (apply (lambda (x)
2123 (call-with-values
2124 (lambda () (cvt x n ids))
2125 (lambda (p ids) (values (vector 'vector p) ids))))
2126 tmp-1)
2127 (let ((x tmp)) (values (vector 'atom (strip p '(()))) ids))))))))))))))))
2128 (cvt pattern 0 '()))))
2129 (build-dispatch-call
2130 (lambda (pvars exp y r mod)
2131 (let ((ids (map car pvars)) (levels (map cdr pvars)))
2132 (let ((labels (gen-labels ids)) (new-vars (map gen-var ids)))
2133 (build-application
2134 #f
2135 (build-primref #f 'apply)
2136 (list (build-simple-lambda
2137 #f
2138 (map syntax->datum ids)
2139 #f
2140 new-vars
2141 '()
2142 (expand
2143 exp
2144 (extend-env
2145 labels
2146 (map (lambda (var level) (cons 'syntax (cons var level)))
2147 new-vars
2148 (map cdr pvars))
2149 r)
2150 (make-binding-wrap ids labels '(()))
2151 mod))
2152 y))))))
2153 (gen-clause
2154 (lambda (x keys clauses r pat fender exp mod)
2155 (call-with-values
2156 (lambda () (convert-pattern pat keys))
2157 (lambda (p pvars)
2158 (cond ((not (distinct-bound-ids? (map car pvars)))
2159 (syntax-violation 'syntax-case "duplicate pattern variable" pat))
2160 ((not (and-map (lambda (x) (not (ellipsis? (car x)))) pvars))
2161 (syntax-violation 'syntax-case "misplaced ellipsis" pat))
2162 (else
2163 (let ((y (gen-var 'tmp)))
2164 (build-application
2165 #f
2166 (build-simple-lambda
2167 #f
2168 (list 'tmp)
2169 #f
2170 (list y)
2171 '()
2172 (let ((y (build-lexical-reference 'value #f 'tmp y)))
2173 (build-conditional
2174 #f
2175 (let* ((tmp fender) (tmp ($sc-dispatch tmp '#(atom #t))))
2176 (if tmp
2177 (apply (lambda () y) tmp)
2178 (build-conditional
2179 #f
2180 y
2181 (build-dispatch-call pvars fender y r mod)
2182 (build-data #f #f))))
2183 (build-dispatch-call pvars exp y r mod)
2184 (gen-syntax-case x keys clauses r mod))))
2185 (list (if (eq? p 'any)
2186 (build-application #f (build-primref #f 'list) (list x))
2187 (build-application
2188 #f
2189 (build-primref #f '$sc-dispatch)
2190 (list x (build-data #f p)))))))))))))
2191 (gen-syntax-case
2192 (lambda (x keys clauses r mod)
2193 (if (null? clauses)
2194 (build-application
2195 #f
2196 (build-primref #f 'syntax-violation)
2197 (list (build-data #f #f)
2198 (build-data #f "source expression failed to match any pattern")
2199 x))
2200 (let* ((tmp-1 (car clauses)) (tmp ($sc-dispatch tmp-1 '(any any))))
2201 (if tmp
2202 (apply (lambda (pat exp)
2203 (if (and (id? pat)
2204 (and-map
2205 (lambda (x) (not (free-id=? pat x)))
2206 (cons '#(syntax-object ... ((top)) (hygiene guile)) keys)))
2207 (if (free-id=? pat '#(syntax-object _ ((top)) (hygiene guile)))
2208 (expand exp r '(()) mod)
2209 (let ((labels (list (gen-label))) (var (gen-var pat)))
2210 (build-application
2211 #f
2212 (build-simple-lambda
2213 #f
2214 (list (syntax->datum pat))
2215 #f
2216 (list var)
2217 '()
2218 (expand
2219 exp
2220 (extend-env labels (list (cons 'syntax (cons var 0))) r)
2221 (make-binding-wrap (list pat) labels '(()))
2222 mod))
2223 (list x))))
2224 (gen-clause x keys (cdr clauses) r pat #t exp mod)))
2225 tmp)
2226 (let ((tmp ($sc-dispatch tmp-1 '(any any any))))
2227 (if tmp
2228 (apply (lambda (pat fender exp)
2229 (gen-clause x keys (cdr clauses) r pat fender exp mod))
2230 tmp)
2231 (syntax-violation 'syntax-case "invalid clause" (car clauses))))))))))
2232 (lambda (e r w s mod)
2233 (let* ((e (source-wrap e w s mod))
2234 (tmp-1 e)
2235 (tmp ($sc-dispatch tmp-1 '(_ any each-any . each-any))))
2236 (if tmp
2237 (apply (lambda (val key m)
2238 (if (and-map (lambda (x) (and (id? x) (not (ellipsis? x)))) key)
2239 (let ((x (gen-var 'tmp)))
2240 (build-application
2241 s
2242 (build-simple-lambda
2243 #f
2244 (list 'tmp)
2245 #f
2246 (list x)
2247 '()
2248 (gen-syntax-case
2249 (build-lexical-reference 'value #f 'tmp x)
2250 key
2251 m
2252 r
2253 mod))
2254 (list (expand val r '(()) mod))))
2255 (syntax-violation 'syntax-case "invalid literals list" e)))
2256 tmp)
2257 (syntax-violation
2258 #f
2259 "source expression failed to match any pattern"
2260 tmp-1))))))
2261 (set! macroexpand
2262 (lambda* (x #:optional (m 'e) (esew '(eval)))
2263 (expand-top-sequence
2264 (list x)
2265 '()
2266 '((top))
2267 #f
2268 m
2269 esew
2270 (cons 'hygiene (module-name (current-module))))))
2271 (set! identifier? (lambda (x) (nonsymbol-id? x)))
2272 (set! datum->syntax
2273 (lambda (id datum)
2274 (make-syntax-object
2275 datum
2276 (syntax-object-wrap id)
2277 (syntax-object-module id))))
2278 (set! syntax->datum (lambda (x) (strip x '(()))))
2279 (set! syntax-source (lambda (x) (source-annotation x)))
2280 (set! generate-temporaries
2281 (lambda (ls)
2282 (let ((x ls))
2283 (if (not (list? x))
2284 (syntax-violation 'generate-temporaries "invalid argument" x)))
2285 (let ((mod (cons 'hygiene (module-name (current-module)))))
2286 (map (lambda (x) (wrap (gensym "t-") '((top)) mod)) ls))))
2287 (set! free-identifier=?
2288 (lambda (x y)
2289 (let ((x x))
2290 (if (not (nonsymbol-id? x))
2291 (syntax-violation 'free-identifier=? "invalid argument" x)))
2292 (let ((x y))
2293 (if (not (nonsymbol-id? x))
2294 (syntax-violation 'free-identifier=? "invalid argument" x)))
2295 (free-id=? x y)))
2296 (set! bound-identifier=?
2297 (lambda (x y)
2298 (let ((x x))
2299 (if (not (nonsymbol-id? x))
2300 (syntax-violation 'bound-identifier=? "invalid argument" x)))
2301 (let ((x y))
2302 (if (not (nonsymbol-id? x))
2303 (syntax-violation 'bound-identifier=? "invalid argument" x)))
2304 (bound-id=? x y)))
2305 (set! syntax-violation
2306 (lambda* (who message form #:optional (subform #f))
2307 (let ((x who))
2308 (if (not (let ((x x)) (or (not x) (string? x) (symbol? x))))
2309 (syntax-violation 'syntax-violation "invalid argument" x)))
2310 (let ((x message))
2311 (if (not (string? x))
2312 (syntax-violation 'syntax-violation "invalid argument" x)))
2313 (throw 'syntax-error
2314 who
2315 message
2316 (or (source-annotation subform) (source-annotation form))
2317 (strip form '(()))
2318 (and subform (strip subform '(()))))))
2319 (letrec*
2320 ((syntax-module
2321 (lambda (id)
2322 (let ((x id))
2323 (if (not (nonsymbol-id? x))
2324 (syntax-violation 'syntax-module "invalid argument" x)))
2325 (cdr (syntax-object-module id))))
2326 (syntax-local-binding
2327 (lambda (id)
2328 (let ((x id))
2329 (if (not (nonsymbol-id? x))
2330 (syntax-violation 'syntax-local-binding "invalid argument" x)))
2331 (with-transformer-environment
2332 (lambda (e r w s rib mod)
2333 (letrec*
2334 ((strip-anti-mark
2335 (lambda (w)
2336 (let ((ms (car w)) (s (cdr w)))
2337 (if (and (pair? ms) (eq? (car ms) #f))
2338 (cons (cdr ms) (if rib (cons rib (cdr s)) (cdr s)))
2339 (cons ms (if rib (cons rib s) s)))))))
2340 (call-with-values
2341 (lambda ()
2342 (resolve-identifier
2343 (syntax-object-expression id)
2344 (strip-anti-mark (syntax-object-wrap id))
2345 r
2346 (syntax-object-module id)))
2347 (lambda (type value mod)
2348 (let ((key type))
2349 (cond ((memv key '(lexical)) (values 'lexical value))
2350 ((memv key '(macro)) (values 'macro value))
2351 ((memv key '(syntax)) (values 'pattern-variable value))
2352 ((memv key '(displaced-lexical)) (values 'displaced-lexical #f))
2353 ((memv key '(global)) (values 'global (cons value (cdr mod))))
2354 (else (values 'other #f)))))))))))
2355 (syntax-locally-bound-identifiers
2356 (lambda (id)
2357 (let ((x id))
2358 (if (not (nonsymbol-id? x))
2359 (syntax-violation
2360 'syntax-locally-bound-identifiers
2361 "invalid argument"
2362 x)))
2363 (locally-bound-identifiers
2364 (syntax-object-wrap id)
2365 (syntax-object-module id)))))
2366 (define! 'syntax-module syntax-module)
2367 (define! 'syntax-local-binding syntax-local-binding)
2368 (define!
2369 'syntax-locally-bound-identifiers
2370 syntax-locally-bound-identifiers))
2371 (letrec*
2372 ((match-each
2373 (lambda (e p w mod)
2374 (cond ((pair? e)
2375 (let ((first (match (car e) p w '() mod)))
2376 (and first
2377 (let ((rest (match-each (cdr e) p w mod)))
2378 (and rest (cons first rest))))))
2379 ((null? e) '())
2380 ((syntax-object? e)
2381 (match-each
2382 (syntax-object-expression e)
2383 p
2384 (join-wraps w (syntax-object-wrap e))
2385 (syntax-object-module e)))
2386 (else #f))))
2387 (match-each+
2388 (lambda (e x-pat y-pat z-pat w r mod)
2389 (let f ((e e) (w w))
2390 (cond ((pair? e)
2391 (call-with-values
2392 (lambda () (f (cdr e) w))
2393 (lambda (xr* y-pat r)
2394 (if r
2395 (if (null? y-pat)
2396 (let ((xr (match (car e) x-pat w '() mod)))
2397 (if xr (values (cons xr xr*) y-pat r) (values #f #f #f)))
2398 (values '() (cdr y-pat) (match (car e) (car y-pat) w r mod)))
2399 (values #f #f #f)))))
2400 ((syntax-object? e)
2401 (f (syntax-object-expression e) (join-wraps w e)))
2402 (else (values '() y-pat (match e z-pat w r mod)))))))
2403 (match-each-any
2404 (lambda (e w mod)
2405 (cond ((pair? e)
2406 (let ((l (match-each-any (cdr e) w mod)))
2407 (and l (cons (wrap (car e) w mod) l))))
2408 ((null? e) '())
2409 ((syntax-object? e)
2410 (match-each-any
2411 (syntax-object-expression e)
2412 (join-wraps w (syntax-object-wrap e))
2413 mod))
2414 (else #f))))
2415 (match-empty
2416 (lambda (p r)
2417 (cond ((null? p) r)
2418 ((eq? p '_) r)
2419 ((eq? p 'any) (cons '() r))
2420 ((pair? p) (match-empty (car p) (match-empty (cdr p) r)))
2421 ((eq? p 'each-any) (cons '() r))
2422 (else
2423 (let ((key (vector-ref p 0)))
2424 (cond ((memv key '(each)) (match-empty (vector-ref p 1) r))
2425 ((memv key '(each+))
2426 (match-empty
2427 (vector-ref p 1)
2428 (match-empty
2429 (reverse (vector-ref p 2))
2430 (match-empty (vector-ref p 3) r))))
2431 ((memv key '(free-id atom)) r)
2432 ((memv key '(vector)) (match-empty (vector-ref p 1) r))))))))
2433 (combine
2434 (lambda (r* r)
2435 (if (null? (car r*)) r (cons (map car r*) (combine (map cdr r*) r)))))
2436 (match*
2437 (lambda (e p w r mod)
2438 (cond ((null? p) (and (null? e) r))
2439 ((pair? p)
2440 (and (pair? e)
2441 (match (car e) (car p) w (match (cdr e) (cdr p) w r mod) mod)))
2442 ((eq? p 'each-any)
2443 (let ((l (match-each-any e w mod))) (and l (cons l r))))
2444 (else
2445 (let ((key (vector-ref p 0)))
2446 (cond ((memv key '(each))
2447 (if (null? e)
2448 (match-empty (vector-ref p 1) r)
2449 (let ((l (match-each e (vector-ref p 1) w mod)))
2450 (and l
2451 (let collect ((l l))
2452 (if (null? (car l)) r (cons (map car l) (collect (map cdr l)))))))))
2453 ((memv key '(each+))
2454 (call-with-values
2455 (lambda ()
2456 (match-each+
2457 e
2458 (vector-ref p 1)
2459 (vector-ref p 2)
2460 (vector-ref p 3)
2461 w
2462 r
2463 mod))
2464 (lambda (xr* y-pat r)
2465 (and r
2466 (null? y-pat)
2467 (if (null? xr*) (match-empty (vector-ref p 1) r) (combine xr* r))))))
2468 ((memv key '(free-id))
2469 (and (id? e) (free-id=? (wrap e w mod) (vector-ref p 1)) r))
2470 ((memv key '(atom)) (and (equal? (vector-ref p 1) (strip e w)) r))
2471 ((memv key '(vector))
2472 (and (vector? e) (match (vector->list e) (vector-ref p 1) w r mod)))))))))
2473 (match (lambda (e p w r mod)
2474 (cond ((not r) #f)
2475 ((eq? p '_) r)
2476 ((eq? p 'any) (cons (wrap e w mod) r))
2477 ((syntax-object? e)
2478 (match*
2479 (syntax-object-expression e)
2480 p
2481 (join-wraps w (syntax-object-wrap e))
2482 r
2483 (syntax-object-module e)))
2484 (else (match* e p w r mod))))))
2485 (set! $sc-dispatch
2486 (lambda (e p)
2487 (cond ((eq? p 'any) (list e))
2488 ((eq? p '_) '())
2489 ((syntax-object? e)
2490 (match*
2491 (syntax-object-expression e)
2492 p
2493 (syntax-object-wrap e)
2494 '()
2495 (syntax-object-module e)))
2496 (else (match* e p '(()) '() #f)))))))
2497
2498 (define with-syntax
2499 (make-syntax-transformer
2500 'with-syntax
2501 'macro
2502 (lambda (x)
2503 (let ((tmp x))
2504 (let ((tmp-1 ($sc-dispatch tmp '(_ () any . each-any))))
2505 (if tmp-1
2506 (apply (lambda (e1 e2)
2507 (cons '#(syntax-object let ((top)) (hygiene guile))
2508 (cons '() (cons e1 e2))))
2509 tmp-1)
2510 (let ((tmp-1 ($sc-dispatch tmp '(_ ((any any)) any . each-any))))
2511 (if tmp-1
2512 (apply (lambda (out in e1 e2)
2513 (list '#(syntax-object syntax-case ((top)) (hygiene guile))
2514 in
2515 '()
2516 (list out
2517 (cons '#(syntax-object let ((top)) (hygiene guile))
2518 (cons '() (cons e1 e2))))))
2519 tmp-1)
2520 (let ((tmp-1 ($sc-dispatch tmp '(_ #(each (any any)) any . each-any))))
2521 (if tmp-1
2522 (apply (lambda (out in e1 e2)
2523 (list '#(syntax-object syntax-case ((top)) (hygiene guile))
2524 (cons '#(syntax-object list ((top)) (hygiene guile)) in)
2525 '()
2526 (list out
2527 (cons '#(syntax-object let ((top)) (hygiene guile))
2528 (cons '() (cons e1 e2))))))
2529 tmp-1)
2530 (syntax-violation
2531 #f
2532 "source expression failed to match any pattern"
2533 tmp)))))))))))
2534
2535 (define syntax-rules
2536 (make-syntax-transformer
2537 'syntax-rules
2538 'macro
2539 (lambda (xx)
2540 (let ((tmp-1 xx))
2541 (let ((tmp ($sc-dispatch tmp-1 '(_ each-any . #(each ((any . any) any))))))
2542 (if tmp
2543 (apply (lambda (k keyword pattern template)
2544 (list '#(syntax-object lambda ((top)) (hygiene guile))
2545 '(#(syntax-object x ((top)) (hygiene guile)))
2546 (vector
2547 '(#(syntax-object macro-type ((top)) (hygiene guile))
2548 .
2549 #(syntax-object syntax-rules ((top)) (hygiene guile)))
2550 (cons '#(syntax-object patterns ((top)) (hygiene guile)) pattern))
2551 (cons '#(syntax-object syntax-case ((top)) (hygiene guile))
2552 (cons '#(syntax-object x ((top)) (hygiene guile))
2553 (cons k
2554 (map (lambda (tmp-1 tmp)
2555 (list (cons '#(syntax-object dummy ((top)) (hygiene guile)) tmp)
2556 (list '#(syntax-object syntax ((top)) (hygiene guile))
2557 tmp-1)))
2558 template
2559 pattern))))))
2560 tmp)
2561 (let ((tmp ($sc-dispatch tmp-1 '(_ each-any any . #(each ((any . any) any))))))
2562 (if (if tmp
2563 (apply (lambda (k docstring keyword pattern template)
2564 (string? (syntax->datum docstring)))
2565 tmp)
2566 #f)
2567 (apply (lambda (k docstring keyword pattern template)
2568 (list '#(syntax-object lambda ((top)) (hygiene guile))
2569 '(#(syntax-object x ((top)) (hygiene guile)))
2570 docstring
2571 (vector
2572 '(#(syntax-object macro-type ((top)) (hygiene guile))
2573 .
2574 #(syntax-object syntax-rules ((top)) (hygiene guile)))
2575 (cons '#(syntax-object patterns ((top)) (hygiene guile)) pattern))
2576 (cons '#(syntax-object syntax-case ((top)) (hygiene guile))
2577 (cons '#(syntax-object x ((top)) (hygiene guile))
2578 (cons k
2579 (map (lambda (tmp-1 tmp)
2580 (list (cons '#(syntax-object dummy ((top)) (hygiene guile)) tmp)
2581 (list '#(syntax-object syntax ((top)) (hygiene guile))
2582 tmp-1)))
2583 template
2584 pattern))))))
2585 tmp)
2586 (syntax-violation
2587 #f
2588 "source expression failed to match any pattern"
2589 tmp-1)))))))))
2590
2591 (define define-syntax-rule
2592 (make-syntax-transformer
2593 'define-syntax-rule
2594 'macro
2595 (lambda (x)
2596 (let ((tmp-1 x))
2597 (let ((tmp ($sc-dispatch tmp-1 '(_ (any . any) any))))
2598 (if tmp
2599 (apply (lambda (name pattern template)
2600 (list '#(syntax-object define-syntax ((top)) (hygiene guile))
2601 name
2602 (list '#(syntax-object syntax-rules ((top)) (hygiene guile))
2603 '()
2604 (list (cons '#(syntax-object _ ((top)) (hygiene guile)) pattern)
2605 template))))
2606 tmp)
2607 (let ((tmp ($sc-dispatch tmp-1 '(_ (any . any) any any))))
2608 (if (if tmp
2609 (apply (lambda (name pattern docstring template)
2610 (string? (syntax->datum docstring)))
2611 tmp)
2612 #f)
2613 (apply (lambda (name pattern docstring template)
2614 (list '#(syntax-object define-syntax ((top)) (hygiene guile))
2615 name
2616 (list '#(syntax-object syntax-rules ((top)) (hygiene guile))
2617 '()
2618 docstring
2619 (list (cons '#(syntax-object _ ((top)) (hygiene guile)) pattern)
2620 template))))
2621 tmp)
2622 (syntax-violation
2623 #f
2624 "source expression failed to match any pattern"
2625 tmp-1)))))))))
2626
2627 (define let*
2628 (make-syntax-transformer
2629 'let*
2630 'macro
2631 (lambda (x)
2632 (let ((tmp-1 x))
2633 (let ((tmp ($sc-dispatch tmp-1 '(any #(each (any any)) any . each-any))))
2634 (if (if tmp
2635 (apply (lambda (let* x v e1 e2) (and-map identifier? x)) tmp)
2636 #f)
2637 (apply (lambda (let* x v e1 e2)
2638 (let f ((bindings (map list x v)))
2639 (if (null? bindings)
2640 (cons '#(syntax-object let ((top)) (hygiene guile))
2641 (cons '() (cons e1 e2)))
2642 (let ((tmp-1 (list (f (cdr bindings)) (car bindings))))
2643 (let ((tmp ($sc-dispatch tmp-1 '(any any))))
2644 (if tmp
2645 (apply (lambda (body binding)
2646 (list '#(syntax-object let ((top)) (hygiene guile))
2647 (list binding)
2648 body))
2649 tmp)
2650 (syntax-violation
2651 #f
2652 "source expression failed to match any pattern"
2653 tmp-1)))))))
2654 tmp)
2655 (syntax-violation
2656 #f
2657 "source expression failed to match any pattern"
2658 tmp-1)))))))
2659
2660 (define quasiquote
2661 (make-syntax-transformer
2662 'quasiquote
2663 'macro
2664 (letrec*
2665 ((quasi (lambda (p lev)
2666 (let ((tmp p))
2667 (let ((tmp-1 ($sc-dispatch
2668 tmp
2669 '(#(free-id #(syntax-object unquote ((top)) (hygiene guile))) any))))
2670 (if tmp-1
2671 (apply (lambda (p)
2672 (if (= lev 0)
2673 (list "value" p)
2674 (quasicons
2675 '("quote" #(syntax-object unquote ((top)) (hygiene guile)))
2676 (quasi (list p) (- lev 1)))))
2677 tmp-1)
2678 (let ((tmp-1 ($sc-dispatch
2679 tmp
2680 '(#(free-id #(syntax-object quasiquote ((top)) (hygiene guile))) any))))
2681 (if tmp-1
2682 (apply (lambda (p)
2683 (quasicons
2684 '("quote" #(syntax-object quasiquote ((top)) (hygiene guile)))
2685 (quasi (list p) (+ lev 1))))
2686 tmp-1)
2687 (let ((tmp-1 ($sc-dispatch tmp '(any . any))))
2688 (if tmp-1
2689 (apply (lambda (p q)
2690 (let ((tmp-1 p))
2691 (let ((tmp ($sc-dispatch
2692 tmp-1
2693 '(#(free-id #(syntax-object unquote ((top)) (hygiene guile)))
2694 .
2695 each-any))))
2696 (if tmp
2697 (apply (lambda (p)
2698 (if (= lev 0)
2699 (quasilist*
2700 (map (lambda (tmp) (list "value" tmp)) p)
2701 (quasi q lev))
2702 (quasicons
2703 (quasicons
2704 '("quote" #(syntax-object unquote ((top)) (hygiene guile)))
2705 (quasi p (- lev 1)))
2706 (quasi q lev))))
2707 tmp)
2708 (let ((tmp ($sc-dispatch
2709 tmp-1
2710 '(#(free-id
2711 #(syntax-object unquote-splicing ((top)) (hygiene guile)))
2712 .
2713 each-any))))
2714 (if tmp
2715 (apply (lambda (p)
2716 (if (= lev 0)
2717 (quasiappend
2718 (map (lambda (tmp) (list "value" tmp)) p)
2719 (quasi q lev))
2720 (quasicons
2721 (quasicons
2722 '("quote"
2723 #(syntax-object
2724 unquote-splicing
2725 ((top))
2726 (hygiene guile)))
2727 (quasi p (- lev 1)))
2728 (quasi q lev))))
2729 tmp)
2730 (quasicons (quasi p lev) (quasi q lev))))))))
2731 tmp-1)
2732 (let ((tmp-1 ($sc-dispatch tmp '#(vector each-any))))
2733 (if tmp-1
2734 (apply (lambda (x) (quasivector (vquasi x lev))) tmp-1)
2735 (let ((p tmp)) (list "quote" p)))))))))))))
2736 (vquasi
2737 (lambda (p lev)
2738 (let ((tmp p))
2739 (let ((tmp-1 ($sc-dispatch tmp '(any . any))))
2740 (if tmp-1
2741 (apply (lambda (p q)
2742 (let ((tmp-1 p))
2743 (let ((tmp ($sc-dispatch
2744 tmp-1
2745 '(#(free-id #(syntax-object unquote ((top)) (hygiene guile)))
2746 .
2747 each-any))))
2748 (if tmp
2749 (apply (lambda (p)
2750 (if (= lev 0)
2751 (quasilist* (map (lambda (tmp) (list "value" tmp)) p) (vquasi q lev))
2752 (quasicons
2753 (quasicons
2754 '("quote" #(syntax-object unquote ((top)) (hygiene guile)))
2755 (quasi p (- lev 1)))
2756 (vquasi q lev))))
2757 tmp)
2758 (let ((tmp ($sc-dispatch
2759 tmp-1
2760 '(#(free-id #(syntax-object unquote-splicing ((top)) (hygiene guile)))
2761 .
2762 each-any))))
2763 (if tmp
2764 (apply (lambda (p)
2765 (if (= lev 0)
2766 (quasiappend
2767 (map (lambda (tmp) (list "value" tmp)) p)
2768 (vquasi q lev))
2769 (quasicons
2770 (quasicons
2771 '("quote" #(syntax-object unquote-splicing ((top)) (hygiene guile)))
2772 (quasi p (- lev 1)))
2773 (vquasi q lev))))
2774 tmp)
2775 (quasicons (quasi p lev) (vquasi q lev))))))))
2776 tmp-1)
2777 (let ((tmp-1 ($sc-dispatch tmp '())))
2778 (if tmp-1
2779 (apply (lambda () '("quote" ())) tmp-1)
2780 (syntax-violation
2781 #f
2782 "source expression failed to match any pattern"
2783 tmp))))))))
2784 (quasicons
2785 (lambda (x y)
2786 (let ((tmp-1 (list x y)))
2787 (let ((tmp ($sc-dispatch tmp-1 '(any any))))
2788 (if tmp
2789 (apply (lambda (x y)
2790 (let ((tmp y))
2791 (let ((tmp-1 ($sc-dispatch tmp '(#(atom "quote") any))))
2792 (if tmp-1
2793 (apply (lambda (dy)
2794 (let ((tmp x))
2795 (let ((tmp ($sc-dispatch tmp '(#(atom "quote") any))))
2796 (if tmp
2797 (apply (lambda (dx) (list "quote" (cons dx dy))) tmp)
2798 (if (null? dy) (list "list" x) (list "list*" x y))))))
2799 tmp-1)
2800 (let ((tmp-1 ($sc-dispatch tmp '(#(atom "list") . any))))
2801 (if tmp-1
2802 (apply (lambda (stuff) (cons "list" (cons x stuff))) tmp-1)
2803 (let ((tmp ($sc-dispatch tmp '(#(atom "list*") . any))))
2804 (if tmp
2805 (apply (lambda (stuff) (cons "list*" (cons x stuff))) tmp)
2806 (list "list*" x y)))))))))
2807 tmp)
2808 (syntax-violation
2809 #f
2810 "source expression failed to match any pattern"
2811 tmp-1))))))
2812 (quasiappend
2813 (lambda (x y)
2814 (let ((tmp y))
2815 (let ((tmp ($sc-dispatch tmp '(#(atom "quote") ()))))
2816 (if tmp
2817 (apply (lambda ()
2818 (if (null? x)
2819 '("quote" ())
2820 (if (null? (cdr x))
2821 (car x)
2822 (let ((tmp-1 x))
2823 (let ((tmp ($sc-dispatch tmp-1 'each-any)))
2824 (if tmp
2825 (apply (lambda (p) (cons "append" p)) tmp)
2826 (syntax-violation
2827 #f
2828 "source expression failed to match any pattern"
2829 tmp-1)))))))
2830 tmp)
2831 (if (null? x)
2832 y
2833 (let ((tmp-1 (list x y)))
2834 (let ((tmp ($sc-dispatch tmp-1 '(each-any any))))
2835 (if tmp
2836 (apply (lambda (p y) (cons "append" (append p (list y)))) tmp)
2837 (syntax-violation
2838 #f
2839 "source expression failed to match any pattern"
2840 tmp-1))))))))))
2841 (quasilist*
2842 (lambda (x y)
2843 (let f ((x x)) (if (null? x) y (quasicons (car x) (f (cdr x)))))))
2844 (quasivector
2845 (lambda (x)
2846 (let ((tmp x))
2847 (let ((tmp ($sc-dispatch tmp '(#(atom "quote") each-any))))
2848 (if tmp
2849 (apply (lambda (x) (list "quote" (list->vector x))) tmp)
2850 (let f ((y x)
2851 (k (lambda (ls)
2852 (let ((tmp-1 ls))
2853 (let ((tmp ($sc-dispatch tmp-1 'each-any)))
2854 (if tmp
2855 (apply (lambda (t) (cons "vector" t)) tmp)
2856 (syntax-violation
2857 #f
2858 "source expression failed to match any pattern"
2859 tmp-1)))))))
2860 (let ((tmp y))
2861 (let ((tmp-1 ($sc-dispatch tmp '(#(atom "quote") each-any))))
2862 (if tmp-1
2863 (apply (lambda (y) (k (map (lambda (tmp) (list "quote" tmp)) y)))
2864 tmp-1)
2865 (let ((tmp-1 ($sc-dispatch tmp '(#(atom "list") . each-any))))
2866 (if tmp-1
2867 (apply (lambda (y) (k y)) tmp-1)
2868 (let ((tmp-1 ($sc-dispatch tmp '(#(atom "list*") . #(each+ any (any) ())))))
2869 (if tmp-1
2870 (apply (lambda (y z) (f z (lambda (ls) (k (append y ls))))) tmp-1)
2871 (let ((else tmp))
2872 (let ((tmp x)) (let ((t tmp)) (list "list->vector" t)))))))))))))))))
2873 (emit (lambda (x)
2874 (let ((tmp x))
2875 (let ((tmp-1 ($sc-dispatch tmp '(#(atom "quote") any))))
2876 (if tmp-1
2877 (apply (lambda (x) (list '#(syntax-object quote ((top)) (hygiene guile)) x))
2878 tmp-1)
2879 (let ((tmp-1 ($sc-dispatch tmp '(#(atom "list") . each-any))))
2880 (if tmp-1
2881 (apply (lambda (x)
2882 (let ((tmp-1 (map emit x)))
2883 (let ((tmp ($sc-dispatch tmp-1 'each-any)))
2884 (if tmp
2885 (apply (lambda (t) (cons '#(syntax-object list ((top)) (hygiene guile)) t))
2886 tmp)
2887 (syntax-violation
2888 #f
2889 "source expression failed to match any pattern"
2890 tmp-1)))))
2891 tmp-1)
2892 (let ((tmp-1 ($sc-dispatch tmp '(#(atom "list*") . #(each+ any (any) ())))))
2893 (if tmp-1
2894 (apply (lambda (x y)
2895 (let f ((x* x))
2896 (if (null? x*)
2897 (emit y)
2898 (let ((tmp-1 (list (emit (car x*)) (f (cdr x*)))))
2899 (let ((tmp ($sc-dispatch tmp-1 '(any any))))
2900 (if tmp
2901 (apply (lambda (t-1 t)
2902 (list '#(syntax-object cons ((top)) (hygiene guile)) t-1 t))
2903 tmp)
2904 (syntax-violation
2905 #f
2906 "source expression failed to match any pattern"
2907 tmp-1)))))))
2908 tmp-1)
2909 (let ((tmp-1 ($sc-dispatch tmp '(#(atom "append") . each-any))))
2910 (if tmp-1
2911 (apply (lambda (x)
2912 (let ((tmp-1 (map emit x)))
2913 (let ((tmp ($sc-dispatch tmp-1 'each-any)))
2914 (if tmp
2915 (apply (lambda (t)
2916 (cons '#(syntax-object append ((top)) (hygiene guile)) t))
2917 tmp)
2918 (syntax-violation
2919 #f
2920 "source expression failed to match any pattern"
2921 tmp-1)))))
2922 tmp-1)
2923 (let ((tmp-1 ($sc-dispatch tmp '(#(atom "vector") . each-any))))
2924 (if tmp-1
2925 (apply (lambda (x)
2926 (let ((tmp-1 (map emit x)))
2927 (let ((tmp ($sc-dispatch tmp-1 'each-any)))
2928 (if tmp
2929 (apply (lambda (t)
2930 (cons '#(syntax-object vector ((top)) (hygiene guile)) t))
2931 tmp)
2932 (syntax-violation
2933 #f
2934 "source expression failed to match any pattern"
2935 tmp-1)))))
2936 tmp-1)
2937 (let ((tmp-1 ($sc-dispatch tmp '(#(atom "list->vector") any))))
2938 (if tmp-1
2939 (apply (lambda (x)
2940 (let ((tmp (emit x)))
2941 (let ((t tmp))
2942 (list '#(syntax-object list->vector ((top)) (hygiene guile)) t))))
2943 tmp-1)
2944 (let ((tmp-1 ($sc-dispatch tmp '(#(atom "value") any))))
2945 (if tmp-1
2946 (apply (lambda (x) x) tmp-1)
2947 (syntax-violation
2948 #f
2949 "source expression failed to match any pattern"
2950 tmp)))))))))))))))))))
2951 (lambda (x)
2952 (let ((tmp-1 x))
2953 (let ((tmp ($sc-dispatch tmp-1 '(_ any))))
2954 (if tmp
2955 (apply (lambda (e) (emit (quasi e 0))) tmp)
2956 (syntax-violation
2957 #f
2958 "source expression failed to match any pattern"
2959 tmp-1))))))))
2960
2961 (define include
2962 (make-syntax-transformer
2963 'include
2964 'macro
2965 (lambda (x)
2966 (letrec*
2967 ((read-file
2968 (lambda (fn k)
2969 (let ((p (open-input-file fn)))
2970 (let f ((x (read p)) (result '()))
2971 (if (eof-object? x)
2972 (begin (close-input-port p) (reverse result))
2973 (f (read p) (cons (datum->syntax k x) result))))))))
2974 (let ((tmp-1 x))
2975 (let ((tmp ($sc-dispatch tmp-1 '(any any))))
2976 (if tmp
2977 (apply (lambda (k filename)
2978 (let ((fn (syntax->datum filename)))
2979 (let ((tmp-1 (read-file fn filename)))
2980 (let ((tmp ($sc-dispatch tmp-1 'each-any)))
2981 (if tmp
2982 (apply (lambda (exp)
2983 (cons '#(syntax-object begin ((top)) (hygiene guile)) exp))
2984 tmp)
2985 (syntax-violation
2986 #f
2987 "source expression failed to match any pattern"
2988 tmp-1))))))
2989 tmp)
2990 (syntax-violation
2991 #f
2992 "source expression failed to match any pattern"
2993 tmp-1))))))))
2994
2995 (define include-from-path
2996 (make-syntax-transformer
2997 'include-from-path
2998 'macro
2999 (lambda (x)
3000 (let ((tmp-1 x))
3001 (let ((tmp ($sc-dispatch tmp-1 '(any any))))
3002 (if tmp
3003 (apply (lambda (k filename)
3004 (let ((fn (syntax->datum filename)))
3005 (let ((tmp (datum->syntax
3006 filename
3007 (let ((t (%search-load-path fn)))
3008 (if t
3009 t
3010 (syntax-violation
3011 'include-from-path
3012 "file not found in path"
3013 x
3014 filename))))))
3015 (let ((fn tmp))
3016 (list '#(syntax-object include ((top)) (hygiene guile)) fn)))))
3017 tmp)
3018 (syntax-violation
3019 #f
3020 "source expression failed to match any pattern"
3021 tmp-1)))))))
3022
3023 (define unquote
3024 (make-syntax-transformer
3025 'unquote
3026 'macro
3027 (lambda (x)
3028 (syntax-violation
3029 'unquote
3030 "expression not valid outside of quasiquote"
3031 x))))
3032
3033 (define unquote-splicing
3034 (make-syntax-transformer
3035 'unquote-splicing
3036 'macro
3037 (lambda (x)
3038 (syntax-violation
3039 'unquote-splicing
3040 "expression not valid outside of quasiquote"
3041 x))))
3042
3043 (define make-variable-transformer
3044 (lambda (proc)
3045 (if (procedure? proc)
3046 (let ((trans (lambda (x) (proc x))))
3047 (set-procedure-property! trans 'variable-transformer #t)
3048 trans)
3049 (error "variable transformer not a procedure" proc))))
3050
3051 (define identifier-syntax
3052 (make-syntax-transformer
3053 'identifier-syntax
3054 'macro
3055 (lambda (xx)
3056 (let ((tmp-1 xx))
3057 (let ((tmp ($sc-dispatch tmp-1 '(_ any))))
3058 (if tmp
3059 (apply (lambda (e)
3060 (list '#(syntax-object lambda ((top)) (hygiene guile))
3061 '(#(syntax-object x ((top)) (hygiene guile)))
3062 '#((#(syntax-object macro-type ((top)) (hygiene guile))
3063 .
3064 #(syntax-object identifier-syntax ((top)) (hygiene guile))))
3065 (list '#(syntax-object syntax-case ((top)) (hygiene guile))
3066 '#(syntax-object x ((top)) (hygiene guile))
3067 '()
3068 (list '#(syntax-object id ((top)) (hygiene guile))
3069 '(#(syntax-object identifier? ((top)) (hygiene guile))
3070 (#(syntax-object syntax ((top)) (hygiene guile))
3071 #(syntax-object id ((top)) (hygiene guile))))
3072 (list '#(syntax-object syntax ((top)) (hygiene guile)) e))
3073 (list '(#(syntax-object _ ((top)) (hygiene guile))
3074 #(syntax-object x ((top)) (hygiene guile))
3075 #(syntax-object ... ((top)) (hygiene guile)))
3076 (list '#(syntax-object syntax ((top)) (hygiene guile))
3077 (cons e
3078 '(#(syntax-object x ((top)) (hygiene guile))
3079 #(syntax-object ... ((top)) (hygiene guile)))))))))
3080 tmp)
3081 (let ((tmp ($sc-dispatch
3082 tmp-1
3083 '(_ (any any)
3084 ((#(free-id #(syntax-object set! ((top)) (hygiene guile))) any any)
3085 any)))))
3086 (if (if tmp
3087 (apply (lambda (id exp1 var val exp2)
3088 (if (identifier? id) (identifier? var) #f))
3089 tmp)
3090 #f)
3091 (apply (lambda (id exp1 var val exp2)
3092 (list '#(syntax-object make-variable-transformer ((top)) (hygiene guile))
3093 (list '#(syntax-object lambda ((top)) (hygiene guile))
3094 '(#(syntax-object x ((top)) (hygiene guile)))
3095 '#((#(syntax-object macro-type ((top)) (hygiene guile))
3096 .
3097 #(syntax-object variable-transformer ((top)) (hygiene guile))))
3098 (list '#(syntax-object syntax-case ((top)) (hygiene guile))
3099 '#(syntax-object x ((top)) (hygiene guile))
3100 '(#(syntax-object set! ((top)) (hygiene guile)))
3101 (list (list '#(syntax-object set! ((top)) (hygiene guile)) var val)
3102 (list '#(syntax-object syntax ((top)) (hygiene guile)) exp2))
3103 (list (cons id
3104 '(#(syntax-object x ((top)) (hygiene guile))
3105 #(syntax-object ... ((top)) (hygiene guile))))
3106 (list '#(syntax-object syntax ((top)) (hygiene guile))
3107 (cons exp1
3108 '(#(syntax-object x ((top)) (hygiene guile))
3109 #(syntax-object ... ((top)) (hygiene guile))))))
3110 (list id
3111 (list '#(syntax-object identifier? ((top)) (hygiene guile))
3112 (list '#(syntax-object syntax ((top)) (hygiene guile)) id))
3113 (list '#(syntax-object syntax ((top)) (hygiene guile)) exp1))))))
3114 tmp)
3115 (syntax-violation
3116 #f
3117 "source expression failed to match any pattern"
3118 tmp-1)))))))))
3119
3120 (define define*
3121 (make-syntax-transformer
3122 'define*
3123 'macro
3124 (lambda (x)
3125 (let ((tmp-1 x))
3126 (let ((tmp ($sc-dispatch tmp-1 '(_ (any . any) any . each-any))))
3127 (if tmp
3128 (apply (lambda (id args b0 b1)
3129 (list '#(syntax-object define ((top)) (hygiene guile))
3130 id
3131 (cons '#(syntax-object lambda* ((top)) (hygiene guile))
3132 (cons args (cons b0 b1)))))
3133 tmp)
3134 (let ((tmp ($sc-dispatch tmp-1 '(_ any any))))
3135 (if (if tmp (apply (lambda (id val) (identifier? id)) tmp) #f)
3136 (apply (lambda (id val)
3137 (list '#(syntax-object define ((top)) (hygiene guile)) id val))
3138 tmp)
3139 (syntax-violation
3140 #f
3141 "source expression failed to match any pattern"
3142 tmp-1)))))))))
3143