* we can now import macros from other libraries. They are visited
before the macro is used.
This commit is contained in:
parent
57a269436a
commit
6b39f738a0
BIN
src/ikarus.boot
BIN
src/ikarus.boot
Binary file not shown.
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
(library (ikarus library-manager)
|
(library (ikarus library-manager)
|
||||||
(export imported-label->binding library-subst
|
(export imported-label->binding library-subst
|
||||||
installed-libraries
|
installed-libraries visit-library
|
||||||
find-library-by-name install-library
|
find-library-by-name install-library
|
||||||
library-spec invoke-library)
|
library-spec invoke-library)
|
||||||
(import (except (ikarus) installed-libraries))
|
(import (except (ikarus) installed-libraries))
|
||||||
|
@ -84,6 +84,8 @@
|
||||||
(case (car binding)
|
(case (car binding)
|
||||||
[(global)
|
[(global)
|
||||||
(cons 'global (cons lib (cdr binding)))]
|
(cons 'global (cons lib (cdr binding)))]
|
||||||
|
[(global-macro)
|
||||||
|
(cons 'global-macro (cons lib (cdr binding)))]
|
||||||
[else binding])])
|
[else binding])])
|
||||||
(put-hash-table! label->binding-table label binding))))
|
(put-hash-table! label->binding-table label binding))))
|
||||||
exp-env)
|
exp-env)
|
||||||
|
@ -103,6 +105,19 @@
|
||||||
(invoke)
|
(invoke)
|
||||||
(set-library-invoke-state! lib #t))))
|
(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)
|
(define (invoke-library-by-spec spec)
|
||||||
(invoke-library (find-library-by-spec/die spec)))
|
(invoke-library (find-library-by-spec/die spec)))
|
||||||
|
|
||||||
|
|
|
@ -358,7 +358,7 @@
|
||||||
(unless label
|
(unless label
|
||||||
(stx-error e "unbound identifier"))
|
(stx-error e "unbound identifier"))
|
||||||
(case type
|
(case type
|
||||||
[(lexical core-prim macro global local-macro)
|
[(lexical core-prim macro global local-macro global-macro)
|
||||||
(values type (binding-value b) id)]
|
(values type (binding-value b) id)]
|
||||||
[else (values 'other #f #f)])))]
|
[else (values 'other #f #f)])))]
|
||||||
[(syntax-pair? e)
|
[(syntax-pair? e)
|
||||||
|
@ -368,7 +368,8 @@
|
||||||
[b (label->binding label r)]
|
[b (label->binding label r)]
|
||||||
[type (binding-type b)])
|
[type (binding-type b)])
|
||||||
(case type
|
(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)]
|
(values type (binding-value b) id)]
|
||||||
[else
|
[else
|
||||||
(values 'call #f #f)]))
|
(values 'call #f #f)]))
|
||||||
|
@ -1614,6 +1615,17 @@
|
||||||
(lambda (p e)
|
(lambda (p e)
|
||||||
(let ([s ((local-macro-transformer p) (add-mark anti-mark e))])
|
(let ([s ((local-macro-transformer p) (add-mark anti-mark e))])
|
||||||
(add-mark (gen-mark) s))))
|
(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*
|
(define chi-expr*
|
||||||
(lambda (e* r mr)
|
(lambda (e* r mr)
|
||||||
;;; expand left to right
|
;;; expand left to right
|
||||||
|
@ -1649,6 +1661,8 @@
|
||||||
[(lexical)
|
[(lexical)
|
||||||
(let ([lex value])
|
(let ([lex value])
|
||||||
(build-lexical-reference no-source lex))]
|
(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)]
|
[(local-macro) (chi-expr (chi-local-macro value e) r mr)]
|
||||||
[(macro) (chi-expr (chi-macro value e) r mr)]
|
[(macro) (chi-expr (chi-macro value e) r mr)]
|
||||||
[(constant)
|
[(constant)
|
||||||
|
@ -2202,6 +2216,7 @@
|
||||||
(lambda () (visit! macro*))
|
(lambda () (visit! macro*))
|
||||||
(lambda () (eval-core invoke-code))
|
(lambda () (eval-core invoke-code))
|
||||||
#t)
|
#t)
|
||||||
|
(pretty-print (build-visit-code macro*))
|
||||||
(values invoke-code
|
(values invoke-code
|
||||||
(build-visit-code macro*)
|
(build-visit-code macro*)
|
||||||
export-subst export-env))))
|
export-subst export-env))))
|
||||||
|
|
Loading…
Reference in New Issue