1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-17 17:20:29 +02:00

houston, we have hygiene

* module/ice-9/expand-support.scm (strip-expansion-structures): Enable
  @/@@ substitution.

* module/ice-9/psyntax-pp.scm: Recompile.

* module/ice-9/psyntax.scm: Since syntax objects are quotable, make the
  module field the module name, not the module itself. Scope the operand
  of global calls appropriately. Thread modules through syntax-dispatch
  destructuring. Houston, we have hygiene.

* module/ice-9/syncase.scm: Adapt to module / module-name changes.
This commit is contained in:
Andy Wingo 2009-03-31 00:00:04 -07:00
parent 8e1d0d507a
commit d2b61fe0ff
4 changed files with 9521 additions and 49 deletions

View file

@ -151,8 +151,7 @@
((module-ref? e) ((module-ref? e)
(if (and (module-ref-modname e) (if (and (module-ref-modname e)
(not (eq? (module-ref-modname e) (not (eq? (module-ref-modname e)
(module-name (current-module)))) (module-name (current-module)))))
#f)
`(,(if (module-ref-public? e) '@ '@@) `(,(if (module-ref-public? e) '@ '@@)
,(module-ref-modname e) ,(module-ref-modname e)
,(module-ref-symbol e)) ,(module-ref-symbol e))

File diff suppressed because one or more lines are too long

View file

@ -320,11 +320,13 @@
(define top-level-eval-hook (define top-level-eval-hook
(lambda (x mod) (lambda (x mod)
(eval `(,noexpand ,x) (or mod (interaction-environment))))) (eval `(,noexpand ,x) (if mod (resolve-module mod)
(interaction-environment)))))
(define local-eval-hook (define local-eval-hook
(lambda (x mod) (lambda (x mod)
(eval `(,noexpand ,x) (or mod (interaction-environment))))) (eval `(,noexpand ,x) (if mod (resolve-module mod)
(interaction-environment)))))
(define error-hook (define error-hook
(lambda (who why what) (lambda (who why what)
@ -336,7 +338,9 @@
(define put-global-definition-hook (define put-global-definition-hook
(lambda (symbol binding module) (lambda (symbol binding module)
(let* ((module (or module (warn "wha" symbol (current-module)))) (let* ((module (if module
(resolve-module module)
(warn "wha" symbol (current-module))))
(v (or (module-variable module symbol) (v (or (module-variable module symbol)
(let ((v (make-variable sc-macro))) (let ((v (make-variable sc-macro)))
(module-add! module symbol v) (module-add! module symbol v)
@ -351,7 +355,9 @@
(define get-global-definition-hook (define get-global-definition-hook
(lambda (symbol module) (lambda (symbol module)
(let* ((module (or module (warn "wha" symbol (current-module)))) (let* ((module (if module
(resolve-module module)
(warn "wha" symbol (current-module))))
(v (module-variable module symbol))) (v (module-variable module symbol)))
(and v (and v
(or (object-property v '*sc-expander*) (or (object-property v '*sc-expander*)
@ -392,14 +398,13 @@
(syntax-rules () (syntax-rules ()
((_ source var mod) ((_ source var mod)
(build-annotated source (build-annotated source
(make-module-ref (and mod (module-name mod)) var #f))))) (make-module-ref mod var #f)))))
(define-syntax build-global-assignment (define-syntax build-global-assignment
(syntax-rules () (syntax-rules ()
((_ source var exp mod) ((_ source var exp mod)
(build-annotated source (build-annotated source
`(set! ,(make-module-ref (and mod (module-name mod)) var #f) `(set! ,(make-module-ref mod var #f) ,exp)))))
,exp)))))
(define-syntax build-global-definition (define-syntax build-global-definition
(syntax-rules () (syntax-rules ()
@ -588,7 +593,7 @@
(define global-extend (define global-extend
(lambda (type sym val) (lambda (type sym val)
(put-global-definition-hook sym (make-binding type val) (put-global-definition-hook sym (make-binding type val)
(current-module)))) (module-name (current-module)))))
;;; Conceptually, identifiers are always syntax objects. Internally, ;;; Conceptually, identifiers are always syntax objects. Internally,
@ -1128,7 +1133,10 @@
e r w s mod)) e r w s mod))
((global-call) ((global-call)
(chi-application (chi-application
(build-global-reference (source-annotation (car e)) value mod) (build-global-reference (source-annotation (car e)) value
(if (syntax-object? (car e))
(syntax-object-module (car e))
mod))
e r w s mod)) e r w s mod))
((constant) (build-data s (strip (source-wrap e w s mod) empty-wrap))) ((constant) (build-data s (strip (source-wrap e w s mod) empty-wrap)))
((global) (build-global-reference s value mod)) ((global) (build-global-reference s value mod))
@ -1185,7 +1193,7 @@
(if rib (if rib
(cons rib (cons 'shift s)) (cons rib (cons 'shift s))
(cons 'shift s))) (cons 'shift s)))
(procedure-module p)))))) ;; hither the hygiene (module-name (procedure-module p))))))) ;; hither the hygiene
((vector? x) ((vector? x)
(let* ((n (vector-length x)) (v (make-vector n))) (let* ((n (vector-length x)) (v (make-vector n)))
(do ((i 0 (fx+ i 1))) (do ((i 0 (fx+ i 1)))
@ -1920,7 +1928,8 @@
(lambda (x) (lambda (x)
(if (and (pair? x) (equal? (car x) noexpand)) (if (and (pair? x) (equal? (car x) noexpand))
(cadr x) (cadr x)
(chi-top x null-env top-wrap m esew (current-module)))))) (chi-top x null-env top-wrap m esew
(module-name (current-module)))))))
(set! sc-expand3 (set! sc-expand3
(let ((m 'e) (esew '(eval))) (let ((m 'e) (esew '(eval)))
@ -1934,7 +1943,7 @@
(if (or (null? rest) (null? (cdr rest))) (if (or (null? rest) (null? (cdr rest)))
esew esew
(cadr rest)) (cadr rest))
(current-module)))))) (module-name (current-module)))))))
(set! identifier? (set! identifier?
(lambda (x) (lambda (x)
@ -2006,34 +2015,36 @@
(let () (let ()
(define match-each (define match-each
(lambda (e p w) (lambda (e p w mod)
(cond (cond
((annotation? e) ((annotation? e)
(match-each (annotation-expression e) p w)) (match-each (annotation-expression e) p w mod))
((pair? e) ((pair? e)
(let ((first (match (car e) p w '()))) (let ((first (match (car e) p w '() mod)))
(and first (and first
(let ((rest (match-each (cdr e) p w))) (let ((rest (match-each (cdr e) p w mod)))
(and rest (cons first rest)))))) (and rest (cons first rest))))))
((null? e) '()) ((null? e) '())
((syntax-object? e) ((syntax-object? e)
(match-each (syntax-object-expression e) (match-each (syntax-object-expression e)
p p
(join-wraps w (syntax-object-wrap e)))) (join-wraps w (syntax-object-wrap e))
(syntax-object-module e)))
(else #f)))) (else #f))))
(define match-each-any (define match-each-any
(lambda (e w) (lambda (e w mod)
(cond (cond
((annotation? e) ((annotation? e)
(match-each-any (annotation-expression e) w)) (match-each-any (annotation-expression e) w mod))
((pair? e) ((pair? e)
(let ((l (match-each-any (cdr e) w))) (let ((l (match-each-any (cdr e) w mod)))
(and l (cons (wrap (car e) w #f) l)))) (and l (cons (wrap (car e) w mod) l))))
((null? e) '()) ((null? e) '())
((syntax-object? e) ((syntax-object? e)
(match-each-any (syntax-object-expression e) (match-each-any (syntax-object-expression e)
(join-wraps w (syntax-object-wrap e)))) (join-wraps w (syntax-object-wrap e))
mod))
(else #f)))) (else #f))))
(define match-empty (define match-empty
@ -2050,43 +2061,45 @@
((vector) (match-empty (vector-ref p 1) r))))))) ((vector) (match-empty (vector-ref p 1) r)))))))
(define match* (define match*
(lambda (e p w r) (lambda (e p w r mod)
(cond (cond
((null? p) (and (null? e) r)) ((null? p) (and (null? e) r))
((pair? p) ((pair? p)
(and (pair? e) (match (car e) (car p) w (and (pair? e) (match (car e) (car p) w
(match (cdr e) (cdr p) w r)))) (match (cdr e) (cdr p) w r mod)
mod)))
((eq? p 'each-any) ((eq? p 'each-any)
(let ((l (match-each-any e w))) (and l (cons l r)))) (let ((l (match-each-any e w mod))) (and l (cons l r))))
(else (else
(case (vector-ref p 0) (case (vector-ref p 0)
((each) ((each)
(if (null? e) (if (null? e)
(match-empty (vector-ref p 1) r) (match-empty (vector-ref p 1) r)
(let ((l (match-each e (vector-ref p 1) w))) (let ((l (match-each e (vector-ref p 1) w mod)))
(and l (and l
(let collect ((l l)) (let collect ((l l))
(if (null? (car l)) (if (null? (car l))
r r
(cons (map car l) (collect (map cdr l))))))))) (cons (map car l) (collect (map cdr l)))))))))
((free-id) (and (id? e) (free-id=? (wrap e w #f) (vector-ref p 1)) r)) ((free-id) (and (id? e) (free-id=? (wrap e w mod) (vector-ref p 1)) r))
((atom) (and (equal? (vector-ref p 1) (strip e w)) r)) ((atom) (and (equal? (vector-ref p 1) (strip e w)) r))
((vector) ((vector)
(and (vector? e) (and (vector? e)
(match (vector->list e) (vector-ref p 1) w r)))))))) (match (vector->list e) (vector-ref p 1) w r mod))))))))
(define match (define match
(lambda (e p w r) (lambda (e p w r mod)
(cond (cond
((not r) #f) ((not r) #f)
((eq? p 'any) (cons (wrap e w #f) r)) ((eq? p 'any) (cons (wrap e w mod) r))
((syntax-object? e) ((syntax-object? e)
(match* (match*
(unannotate (syntax-object-expression e)) (unannotate (syntax-object-expression e))
p p
(join-wraps w (syntax-object-wrap e)) (join-wraps w (syntax-object-wrap e))
r)) r
(else (match* (unannotate e) p w r))))) (syntax-object-module e)))
(else (match* (unannotate e) p w r mod)))))
(set! syntax-dispatch (set! syntax-dispatch
(lambda (e p) (lambda (e p)
@ -2094,8 +2107,8 @@
((eq? p 'any) (list e)) ((eq? p 'any) (list e))
((syntax-object? e) ((syntax-object? e)
(match* (unannotate (syntax-object-expression e)) (match* (unannotate (syntax-object-expression e))
p (syntax-object-wrap e) '())) p (syntax-object-wrap e) '() (syntax-object-module e)))
(else (match* (unannotate e) p empty-wrap '()))))) (else (match* (unannotate e) p empty-wrap '() #f)))))
(set! sc-chi chi) (set! sc-chi chi)
)) ))

View file

@ -108,7 +108,8 @@
(if (symbol? e) (if (symbol? e)
;; pass the expression through ;; pass the expression through
e e
(let ((m (module-ref mod (car e)))) (let* ((mod (resolve-module mod))
(m (module-ref mod (car e))))
(if (eq? (macro-type m) 'syntax) (if (eq? (macro-type m) 'syntax)
;; pass the expression through ;; pass the expression through
e e
@ -120,7 +121,7 @@
e e
(if (null? r) (if (null? r)
(sc-expand e) (sc-expand e)
(sc-chi e r w mod))))))))))) (sc-chi e r w (module-name mod))))))))))))
(define generated-symbols (make-weak-key-hash-table 1019)) (define generated-symbols (make-weak-key-hash-table 1019))