define-runtime-module-path-index and racket/gui/dynamic fixes

This commit is contained in:
Matthew Flatt 2010-10-24 14:39:13 -06:00
parent a7426c1c27
commit dee93e6259
5 changed files with 75 additions and 19 deletions

View File

@ -1,8 +1,8 @@
#lang scheme/base
(require scheme/runtime-path (for-syntax scheme/base))
#lang racket/base
(require racket/runtime-path (for-syntax racket/base))
(provide (all-defined-out))
(define-runtime-module-path platform-lib
(define-runtime-module-path-index platform-lib
(let ([gtk-lib
'(lib "mred/private/wx/gtk/platform.rkt")])
(case (system-type)

View File

@ -11,7 +11,7 @@
(provide define-runtime-path
define-runtime-paths
define-runtime-path-list
define-runtime-module-path
define-runtime-module-path-index
runtime-paths)
(define-for-syntax ext-file-table (make-hasheq))
@ -147,7 +147,7 @@
(syntax-case stx ()
[(_ id expr) #`(-define-runtime-path #,stx (id) expr values list)]))
(define-syntax (define-runtime-module-path stx)
(define-syntax (define-runtime-module-path-index stx)
(syntax-case stx ()
[(_ id expr) #`(-define-runtime-path #,stx (id) `(module ,expr ,(#%variable-reference)) list values)]))

View File

@ -1,17 +1,25 @@
#lang scheme/base
(require ffi/unsafe)
(provide gui-available?
gui-dynamic-require)
(define scheme_register_process_global
(get-ffi-obj 'scheme_register_process_global #f (_fun _string _pointer -> _pointer)))
(define (gui-available?)
(and (zero? (variable-reference->phase (#%variable-reference)))
(with-handlers ([exn:fail? (lambda (exn) #f)])
;; Fails if `mred/private/dynamic' is not declared
;; (without loading it if not):
(module->language-info 'mred/private/dynamic #f)
;; Double check that it seems to have started ok:
(eq? (dynamic-require 'mred/private/dynamic 'kernel-initialized)
'done))))
(and
;; Never available in non-0 phases:
(zero? (variable-reference->phase (#%variable-reference)))
;; Must be instantiated:
(scheme_register_process_global "GRacket-support-initialized" #f)
(with-handlers ([exn:fail? (lambda (exn) #f)])
;; Fails if `mred/private/dynamic' is not declared
;; (without loading it if not):
(module->language-info 'mred/private/dynamic #f)
;; Double check that it seems to have started ok:
(eq? (dynamic-require 'mred/private/dynamic 'kernel-initialized)
'done))))
(define-namespace-anchor anchor)

View File

@ -1,6 +1,34 @@
#lang scheme/base
(require (for-syntax scheme/base))
#lang racket/base
(require (for-syntax racket/base))
(require mzlib/runtime-path)
(provide (all-from-out mzlib/runtime-path)
(for-syntax #%datum))
(for-syntax #%datum)
define-runtime-module-path)
(define-syntax (define-runtime-module-path stx)
(syntax-case stx ()
[(_ id mod-path)
(begin
(unless (memq (syntax-local-context) '(top-level module module-begin))
(raise-syntax-error #f
"allowed only in a module top-level or top-level context"
stx))
(unless (identifier? #'id)
(raise-syntax-error #f
"expected an identifier to bind"
stx
#'id))
(unless (module-path? (syntax->datum #'mod-path))
(raise-syntax-error #f
"expected a literal module path"
stx
#'mod-path))
#`(begin
(require (only-in (for-label mod-path)))
(define id (combine-module-path (#%variable-reference) 'mod-path))))]))
(define (combine-module-path vr mod-path)
(module-path-index-resolve (module-path-index-join
mod-path
(variable-reference->resolved-module-path vr))))

View File

@ -550,11 +550,11 @@ Like @racket[define-runtime-path], but @racket[expr] should produce a
list of paths.}
@defform[(define-runtime-module-path id module-path)]{
@defform[(define-runtime-module-path-index id module-path-expr)]{
Similar to @racket[define-runtime-path], but @racket[id] is bound to a
@tech{module path index} that encapsulates @racket[module-path]
relative to the enclosing module.
@tech{module path index} that encapsulates the result of
@racket[module-path-expr] relative to the enclosing module.
Use @racket[define-runtime-module-path] to bind a module path that is
passed to a reflective function like @racket[dynamic-require] while
@ -562,6 +562,26 @@ also creating a module dependency for building and distributing
executables.}
@defform[(define-runtime-module-path id module-path)]{
Similar to @racket[define-runtime-path], but @racket[id] is bound to a
@tech{resolved module path}. The @tech{resolved module path} for
@racket[id] corresponds to @racket[module-path] (with the same syntax
as a module path for @racket[require]), which can be relative to the
enclosing module.
The @racket[define-runtime-module-path-index] form is usually
preferred, because it creates a weaker link to the referenced module.
Unlike @racket[define-runtime-module-path-index], the
@racket[define-runtime-module-path] form creates a @racket[for-label]
dependency from an enclosing module to @racket[module-path]. Since the
dependency is merely @racket[for-label], @racket[module-path] is not
@tech{instantiate}d or @tech{visit}ed when the enclosing module is
@tech{instantiate}d or @tech{visit}ed (unless such a dependency is
created by other @racket[require]s), but the code for the referenced
module is loaded when the enclosing module is loaded.}
@defform[(runtime-paths module-path)]{
This form is mainly for use by tools such as executable builders. It