From dee93e625984f3f92cb699a4e131eb34aee94874 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Sun, 24 Oct 2010 14:39:13 -0600 Subject: [PATCH] define-runtime-module-path-index and racket/gui/dynamic fixes --- collects/mred/private/wx/platform.rkt | 6 ++-- collects/mzlib/runtime-path.rkt | 4 +-- collects/racket/gui/dynamic.rkt | 24 ++++++++----- collects/racket/runtime-path.rkt | 34 +++++++++++++++++-- .../scribblings/reference/filesystem.scrbl | 26 ++++++++++++-- 5 files changed, 75 insertions(+), 19 deletions(-) diff --git a/collects/mred/private/wx/platform.rkt b/collects/mred/private/wx/platform.rkt index 735172bdaf..8ecb9b168c 100644 --- a/collects/mred/private/wx/platform.rkt +++ b/collects/mred/private/wx/platform.rkt @@ -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) diff --git a/collects/mzlib/runtime-path.rkt b/collects/mzlib/runtime-path.rkt index 2be5f33fe6..2c96054c32 100644 --- a/collects/mzlib/runtime-path.rkt +++ b/collects/mzlib/runtime-path.rkt @@ -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)])) diff --git a/collects/racket/gui/dynamic.rkt b/collects/racket/gui/dynamic.rkt index 8ed50b2ef6..c5453056ab 100644 --- a/collects/racket/gui/dynamic.rkt +++ b/collects/racket/gui/dynamic.rkt @@ -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) diff --git a/collects/racket/runtime-path.rkt b/collects/racket/runtime-path.rkt index eeda4ffb62..2781ef9bc8 100644 --- a/collects/racket/runtime-path.rkt +++ b/collects/racket/runtime-path.rkt @@ -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)))) diff --git a/collects/scribblings/reference/filesystem.scrbl b/collects/scribblings/reference/filesystem.scrbl index 36622fa720..c4f57c5b32 100644 --- a/collects/scribblings/reference/filesystem.scrbl +++ b/collects/scribblings/reference/filesystem.scrbl @@ -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