fix lazy-require for local submod module-paths

This commit is contained in:
Ryan Culpepper 2012-12-03 18:54:34 -05:00
parent 3075b4d285
commit 33f3574f7e

View File

@ -12,6 +12,29 @@
(define-for-syntax counter 0)
(begin-for-syntax
;; like (collapse-module-path modpath '(submod "..")), but avoids
;; the dependencies of syntax/modcollapse
(define (module-path-add-submod-up modpath)
(let ([d (syntax->list modpath)])
(cond [(and d (list? d) (>= (length d) 2) (eq? (syntax-e (car d)) 'submod))
;; was a submod module-path
(let ([parts (cdr d)]) ;; length >= 1
(cond [(or (equal? (syntax-e (car parts)) ".")
(equal? (syntax-e (car parts)) ".."))
;; (submod "." part ...) => (submod "." ".." part ...)
;; (submod ".." part ...) => (submod ".." ".." part ...)
(datum->syntax modpath
(list* (car d) (car parts) ".." (cdr parts))
modpath)]
[else
;; wasn't relative
;; FIXME: what about 'mod = (submod "." mod) abbreviation?
modpath]))]
[else
;; wasn't a submod module-path
modpath]))))
(define-syntax (lazy-require1 stx)
(syntax-case stx ()
[(lazy-require1 modpath (name ...) orig-stx)
@ -36,14 +59,18 @@
(string->symbol
(format "lazy-require-path-~a-~a"
phase
counter))])
counter))]
;; May need to adjust modpath, since we're interpreting it
;; relative to a *submodule* of the original context.
;; ie, module-path interpretation is not hygienic!
[modpath* (module-path-add-submod-up #'modpath)])
(set! counter (add1 counter))
#'(begin
(module lazy-require-path-n racket/base
(require racket/runtime-path
(for-syntax racket/base))
(provide mpi-var)
(define-runtime-module-path-index mpi-var (quote modpath)))
(define-runtime-module-path-index mpi-var (quote modpath*)))
(require 'lazy-require-path-n)))))])
#'(begin
define-mpi-var