-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsyntaxxformboot.scm
58 lines (45 loc) · 1.98 KB
/
syntaxxformboot.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
;;;============================================================================
;;; File: "syntaxxformboot.scm"
;;; Copyright (c) 2000-2014 by Marc Feeley, All Rights Reserved.
;;;============================================================================
;; This file implements a version of the (syntax ...) form that is
;; used for bootstrapping.
;;;----------------------------------------------------------------------------
(define (syn#syntax-form-transformer src inherited-pvars)
(include "syntaxtemplate.scm") ;; get definition of syn#compile-template
(include "syntaxcommon.scm") ;; get definition of syn#pvar-id
(let ((code (##source-code src)))
(if (and (= (length code) 4)
(eq? (##source-code (##sourcify (cadr code) src))
'##let-pattern-variables))
(let* ((pvars
(##desourcify (caddr code)))
(expr
(cadddr code))
(n
(length pvars))
(new-pvars
(append pvars
(map (lambda (x)
(let* ((id (car x))
(index (cadr x))
(rank (cddr x)))
(cons id
(cons (+ index n) rank))))
inherited-pvars))))
`(##let ()
(##define-syntax syntax
(##lambda (##src)
(##include "syntaxxformboot.scm")
(syn#syntax-form-transformer ##src ',new-pvars)))
,expr))
(let* ((template
(cadr code))
(ctemplate
(syn#compile-template
(##sourcify template src)
inherited-pvars)))
`(syn#expand-template
',ctemplate
(##vector ,@(map syn#pvar-id inherited-pvars)))))))
;;;============================================================================