variable-reference->namespace: ensure that module is available
This commit is contained in:
parent
234e47a58f
commit
af4c23fa72
|
@ -89,7 +89,8 @@ Returns a namespace corresponding to the source of the anchor.
|
|||
If the anchor is from a @racket[define-namespace-anchor] form in a
|
||||
module context, then the result is a namespace for the module's body
|
||||
in the anchor's phase. The result is the same as a namespace obtained
|
||||
via @racket[module->namespace].
|
||||
via @racket[module->namespace], and the module is similarly made
|
||||
@tech{available} if it is not available already.
|
||||
|
||||
If the anchor is from a @racket[define-namespace-anchor] form in a
|
||||
top-level content, then the result is the namespace in which the
|
||||
|
@ -439,7 +440,8 @@ and with the same phase as @racket[varref].}
|
|||
If @racket[varref] refers to a @tech{module-level variable}, then the
|
||||
result is a namespace for the module's body in the referenced
|
||||
variable's @tech{phase}; the result is the same as a namespace
|
||||
obtained via @racket[module->namespace].
|
||||
obtained via @racket[module->namespace], and the module is similarly made
|
||||
@tech{available} if it is not available already.
|
||||
|
||||
If @racket[varref] refers to a @tech{top-level variable}, then the
|
||||
result is the namespace in which the referenced variable is defined.}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
top-level-module-path-index
|
||||
top-level-module-path-index?
|
||||
non-self-module-path-index?
|
||||
|
||||
resolve-module-path
|
||||
current-module-name-resolver
|
||||
|
@ -358,6 +359,9 @@
|
|||
(define (top-level-module-path-index? mpi)
|
||||
(eq? top-level-module-path-index mpi))
|
||||
|
||||
(define (non-self-module-path-index? mpi)
|
||||
(and (module-path-index-path mpi) #t))
|
||||
|
||||
;; ----------------------------------------
|
||||
|
||||
(define (resolve-module-path mod-path base)
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
"../common/contract.rkt"
|
||||
"../common/module-path.rkt"
|
||||
"../host/linklet.rkt"
|
||||
"module.rkt"
|
||||
"api-module.rkt")
|
||||
|
||||
(provide variable-reference? ; provided by linklet layer, along with `#%variable-reference`
|
||||
|
@ -24,6 +25,14 @@
|
|||
|
||||
(define/who (variable-reference->namespace vr)
|
||||
(check who variable-reference? vr)
|
||||
(define ns (variable-reference->namespace* vr))
|
||||
(define mpi (namespace-mpi ns))
|
||||
(when (non-self-module-path-index? mpi)
|
||||
;; Ensure that the module is available
|
||||
(namespace-module-make-available! ns mpi (namespace-0-phase ns)))
|
||||
ns)
|
||||
|
||||
(define (variable-reference->namespace* vr)
|
||||
(define inst (variable-reference->instance vr))
|
||||
(cond
|
||||
[(symbol? inst)
|
||||
|
@ -42,7 +51,7 @@
|
|||
|
||||
(define/who (variable-reference->module-path-index vr)
|
||||
(check who variable-reference? vr)
|
||||
(define mpi (namespace-mpi (variable-reference->namespace vr)))
|
||||
(define mpi (namespace-mpi (variable-reference->namespace* vr)))
|
||||
(if (top-level-module-path-index? mpi)
|
||||
#f
|
||||
mpi))
|
||||
|
@ -54,16 +63,16 @@
|
|||
|
||||
(define/who (variable-reference->module-source vr)
|
||||
(check who variable-reference? vr)
|
||||
(define ns (variable-reference->namespace vr))
|
||||
(define ns (variable-reference->namespace* vr))
|
||||
(namespace-source-name ns))
|
||||
|
||||
(define/who (variable-reference->phase vr)
|
||||
(check who variable-reference? vr)
|
||||
(namespace-phase (variable-reference->namespace vr)))
|
||||
(namespace-phase (variable-reference->namespace* vr)))
|
||||
|
||||
(define/who (variable-reference->module-base-phase vr)
|
||||
(check who variable-reference? vr)
|
||||
(namespace-0-phase (variable-reference->namespace vr)))
|
||||
(namespace-0-phase (variable-reference->namespace* vr)))
|
||||
|
||||
(define/who (variable-reference->module-declaration-inspector vr)
|
||||
(check who variable-reference? vr)
|
||||
|
@ -71,6 +80,6 @@
|
|||
(raise-arguments-error who
|
||||
"variable reference does not refer to an anonymous module variable"
|
||||
"variable reference" vr))
|
||||
(or (namespace-declaration-inspector (variable-reference->namespace vr))
|
||||
(or (namespace-declaration-inspector (variable-reference->namespace* vr))
|
||||
(raise-arguments-error who
|
||||
"given variable reference is not from a module")))
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user