* we can now import macros from other libraries. They are visited

before the macro is used.
This commit is contained in:
Abdulaziz Ghuloum 2007-05-07 20:58:12 -04:00
parent 57a269436a
commit 6b39f738a0
3 changed files with 33 additions and 3 deletions

Binary file not shown.

View File

@ -3,7 +3,7 @@
(library (ikarus library-manager)
(export imported-label->binding library-subst
installed-libraries
installed-libraries visit-library
find-library-by-name install-library
library-spec invoke-library)
(import (except (ikarus) installed-libraries))
@ -84,6 +84,8 @@
(case (car binding)
[(global)
(cons 'global (cons lib (cdr binding)))]
[(global-macro)
(cons 'global-macro (cons lib (cdr binding)))]
[else binding])])
(put-hash-table! label->binding-table label binding))))
exp-env)
@ -103,6 +105,19 @@
(invoke)
(set-library-invoke-state! lib #t))))
(define (visit-library lib)
(let ([visit (library-visit-state lib)])
(when (procedure? visit)
(set-library-visit-state! lib
(lambda () (error 'visit "circularity detected for ~s" lib)))
(for-each invoke-library (library-vis* lib))
(set-library-visit-state! lib
(lambda () (error 'invoke "first visit did not return for ~s" lib)))
(visit)
(set-library-visit-state! lib #t))))
(define (invoke-library-by-spec spec)
(invoke-library (find-library-by-spec/die spec)))

View File

@ -358,7 +358,7 @@
(unless label
(stx-error e "unbound identifier"))
(case type
[(lexical core-prim macro global local-macro)
[(lexical core-prim macro global local-macro global-macro)
(values type (binding-value b) id)]
[else (values 'other #f #f)])))]
[(syntax-pair? e)
@ -368,7 +368,8 @@
[b (label->binding label r)]
[type (binding-type b)])
(case type
[(define define-syntax core-macro begin macro local-macro module set!)
[(define define-syntax core-macro begin macro
local-macro global-macro module set!)
(values type (binding-value b) id)]
[else
(values 'call #f #f)]))
@ -1614,6 +1615,17 @@
(lambda (p e)
(let ([s ((local-macro-transformer p) (add-mark anti-mark e))])
(add-mark (gen-mark) s))))
(define (chi-global-macro p e)
(let ([lib (car p)]
[loc (cdr p)])
(visit-library lib)
(let ([x (symbol-value loc)])
(let ([transformer
(cond
[(procedure? x) x]
[else (error 'chi-global-macro "~s is not a procedure")])])
(let ([s (transformer (add-mark anti-mark e))])
(add-mark (gen-mark) s))))))
(define chi-expr*
(lambda (e* r mr)
;;; expand left to right
@ -1649,6 +1661,8 @@
[(lexical)
(let ([lex value])
(build-lexical-reference no-source lex))]
[(global-macro)
(chi-expr (chi-global-macro value e) r mr)]
[(local-macro) (chi-expr (chi-local-macro value e) r mr)]
[(macro) (chi-expr (chi-macro value e) r mr)]
[(constant)
@ -2202,6 +2216,7 @@
(lambda () (visit! macro*))
(lambda () (eval-core invoke-code))
#t)
(pretty-print (build-visit-code macro*))
(values invoke-code
(build-visit-code macro*)
export-subst export-env))))