trying to get module name resolution more deterministic.
This commit is contained in:
parent
ac678fba7b
commit
08b5273a9b
|
@ -30,9 +30,9 @@
|
||||||
(lambda (mpi relative-to)
|
(lambda (mpi relative-to)
|
||||||
(cond
|
(cond
|
||||||
[(eq? mpi #f)
|
[(eq? mpi #f)
|
||||||
'self]
|
(current-module-path)]
|
||||||
[(self-module-path-index? mpi)
|
[(self-module-path-index? mpi)
|
||||||
'self]
|
(current-module-path)]
|
||||||
[else
|
[else
|
||||||
(resolve-module-path-index mpi relative-to)]))))
|
(resolve-module-path-index mpi relative-to)]))))
|
||||||
|
|
||||||
|
@ -122,6 +122,11 @@
|
||||||
(let ([compilation-top (zo-parse in)])
|
(let ([compilation-top (zo-parse in)])
|
||||||
(parse-top compilation-top)))]
|
(parse-top compilation-top)))]
|
||||||
|
|
||||||
|
[(compiled-expression? in)
|
||||||
|
(let ([op (open-output-bytes)])
|
||||||
|
(write in op)
|
||||||
|
(parse-bytecode (open-input-bytes (get-output-bytes op))))]
|
||||||
|
|
||||||
[(path? in)
|
[(path? in)
|
||||||
(let*-values ([(normal-path) (normalize-path in)]
|
(let*-values ([(normal-path) (normalize-path in)]
|
||||||
[(base file-path dir?) (split-path normal-path)])
|
[(base file-path dir?) (split-path normal-path)])
|
||||||
|
@ -144,8 +149,32 @@
|
||||||
(define (parse-top a-top)
|
(define (parse-top a-top)
|
||||||
(match a-top
|
(match a-top
|
||||||
[(struct compilation-top (max-let-depth prefix code))
|
[(struct compilation-top (max-let-depth prefix code))
|
||||||
|
(maybe-fix-module-name
|
||||||
(make-Top (parse-prefix prefix)
|
(make-Top (parse-prefix prefix)
|
||||||
(parse-top-code code))]))
|
(parse-top-code code)))]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
;; maybe-fix-module-name: expression -> expression
|
||||||
|
;; When we're compiling a module directly from memory, it doesn't have a file path.
|
||||||
|
;; We rewrite the ModuleName to its given name.
|
||||||
|
(define (maybe-fix-module-name exp)
|
||||||
|
(match exp
|
||||||
|
[(struct Top (top-prefix
|
||||||
|
(struct Module ((and name (? symbol?))
|
||||||
|
(struct ModuleName ('self 'self))
|
||||||
|
module-prefix
|
||||||
|
module-requires
|
||||||
|
module-code))))
|
||||||
|
(make-Top top-prefix
|
||||||
|
(make-Module name
|
||||||
|
(make-ModuleName name name) (current-module-path)
|
||||||
|
module-prefix
|
||||||
|
module-requires
|
||||||
|
module-code))]
|
||||||
|
[else
|
||||||
|
exp]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(define (parse-prefix a-prefix)
|
(define (parse-prefix a-prefix)
|
||||||
|
@ -197,7 +226,8 @@
|
||||||
(make-ModuleName (rewrite-path resolved-path-name)
|
(make-ModuleName (rewrite-path resolved-path-name)
|
||||||
(normalize-path resolved-path-name))]
|
(normalize-path resolved-path-name))]
|
||||||
[else
|
[else
|
||||||
(error 'wrap-module-name "Unable to resolve module path ~s" resolved-path-name)]))]))
|
(error 'wrap-module-name "Unable to resolve module path ~s."
|
||||||
|
resolved-path-name)]))]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,15 @@
|
||||||
(require compiler/zo-parse
|
(require compiler/zo-parse
|
||||||
rackunit
|
rackunit
|
||||||
racket/match
|
racket/match
|
||||||
|
racket/path
|
||||||
"../parameters.rkt"
|
"../parameters.rkt"
|
||||||
"../parse-bytecode.rkt"
|
"../parse-bytecode.rkt"
|
||||||
"../lexical-structs.rkt"
|
"../lexical-structs.rkt"
|
||||||
"../expression-structs.rkt"
|
"../expression-structs.rkt"
|
||||||
|
racket/runtime-path
|
||||||
(for-syntax racket/base))
|
(for-syntax racket/base))
|
||||||
|
|
||||||
|
(define-runtime-path this-test-path ".")
|
||||||
|
|
||||||
(define (run-zo-parse stx)
|
(define (run-zo-parse stx)
|
||||||
(parameterize ([current-namespace (make-base-namespace)]
|
(parameterize ([current-namespace (make-base-namespace)]
|
||||||
|
@ -398,7 +401,30 @@
|
||||||
(#%provide f))))
|
(#%provide f))))
|
||||||
|
|
||||||
|
|
||||||
|
(parameterize ([current-root-path this-test-path]
|
||||||
|
[current-module-path (build-path this-test-path "foo.rkt")])
|
||||||
(check-true
|
(check-true
|
||||||
|
(match (run-my-parse #'(module foo racket/base))
|
||||||
|
[(struct Top ((? Prefix?)
|
||||||
|
(struct Module ('foo
|
||||||
|
(struct ModuleName
|
||||||
|
('whalesong/tests/foo.rkt
|
||||||
|
(? (lambda (p)
|
||||||
|
(and (path? p)
|
||||||
|
(equal? (normalize-path p)
|
||||||
|
(normalize-path
|
||||||
|
(build-path this-test-path "foo.rkt"))))))))
|
||||||
|
|
||||||
|
(struct Prefix (list))
|
||||||
|
(list (struct ModuleName ('collects/racket/base.rkt
|
||||||
|
_)))
|
||||||
|
(struct Splice ('()))))))
|
||||||
|
#t]
|
||||||
|
[else
|
||||||
|
#f])))
|
||||||
|
|
||||||
|
|
||||||
|
#;(check-true
|
||||||
(match (parameterize ([current-root-path (build-path "/blah")]
|
(match (parameterize ([current-root-path (build-path "/blah")]
|
||||||
[current-module-path (build-path "/blah" "foo" "bar.rkt")])
|
[current-module-path (build-path "/blah" "foo" "bar.rkt")])
|
||||||
(run-my-parse '(module foo '#%kernel
|
(run-my-parse '(module foo '#%kernel
|
||||||
|
|
Loading…
Reference in New Issue
Block a user