mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-24 12:20:20 +02:00
add separate expansion phase, to detwingle things a bit
* module/language/scheme/expand.scm: New module, implements a separate expansion phase, not interleaved with compilation. * module/language/scheme/amatch.scm: Helper for expand.scm, it's pmatch with support for annotated source. * module/ice-9/Makefile.am (SOURCES): Add annotate.scm to build list -- early on because it will be used in the compiler. * module/ice-9/annotate.scm: Fix the printer, default to unstripped (whatever that is), and add a deannotator. * module/system/base/compile.scm (call-with-compile-error-catch): Fix for new representation of source locations. * module/Makefile.am (SCHEME_LANG_SOURCES): Add amatch and expand.
This commit is contained in:
parent
fb0a63e879
commit
237f96e7f0
6 changed files with 361 additions and 12 deletions
37
module/language/scheme/amatch.scm
Normal file
37
module/language/scheme/amatch.scm
Normal file
|
@ -0,0 +1,37 @@
|
|||
(define-module (language scheme amatch)
|
||||
#:use-module (ice-9 syncase)
|
||||
#:export (amatch apat))
|
||||
;; FIXME: shouldn't have to export apat...
|
||||
|
||||
;; This is exactly the same as pmatch except that it unpacks annotations
|
||||
;; as needed.
|
||||
|
||||
(define-syntax amatch
|
||||
(syntax-rules (else guard)
|
||||
((_ (op arg ...) cs ...)
|
||||
(let ((v (op arg ...)))
|
||||
(amatch v cs ...)))
|
||||
((_ v) (if #f #f))
|
||||
((_ v (else e0 e ...)) (begin e0 e ...))
|
||||
((_ v (pat (guard g ...) e0 e ...) cs ...)
|
||||
(let ((fk (lambda () (amatch v cs ...))))
|
||||
(apat v pat
|
||||
(if (and g ...) (begin e0 e ...) (fk))
|
||||
(fk))))
|
||||
((_ v (pat e0 e ...) cs ...)
|
||||
(let ((fk (lambda () (amatch v cs ...))))
|
||||
(apat v pat (begin e0 e ...) (fk))))))
|
||||
|
||||
(define-syntax apat
|
||||
(syntax-rules (_ quote unquote)
|
||||
((_ v _ kt kf) kt)
|
||||
((_ v () kt kf) (if (null? v) kt kf))
|
||||
((_ v (quote lit) kt kf)
|
||||
(if (equal? v (quote lit)) kt kf))
|
||||
((_ v (unquote var) kt kf) (let ((var v)) kt))
|
||||
((_ v (x . y) kt kf)
|
||||
(if (apair? v)
|
||||
(let ((vx (acar v)) (vy (acdr v)))
|
||||
(apat vx x (apat vy y kt kf) kf))
|
||||
kf))
|
||||
((_ v lit kt kf) (if (eq? v (quote lit)) kt kf))))
|
Loading…
Add table
Add a link
Reference in a new issue