From 5bf4b1c9300d9e3e9d2ab985b4185eaa7ea7622a Mon Sep 17 00:00:00 2001 From: Ryan Culpepper Date: Fri, 10 Jun 2011 01:58:42 -0600 Subject: [PATCH] moved phase-of-enclosing-module to unstable/syntax closes PR 11970 --- collects/syntax/parse/private/litconv.rkt | 3 ++- collects/syntax/parse/private/rep.rkt | 3 ++- collects/syntax/parse/private/runtime.rkt | 13 ------------- collects/unstable/scribblings/syntax.scrbl | 19 +++++++++++++++++++ collects/unstable/syntax.rkt | 15 +++++++++++++-- 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/collects/syntax/parse/private/litconv.rkt b/collects/syntax/parse/private/litconv.rkt index 4a29f83613..29085e7202 100644 --- a/collects/syntax/parse/private/litconv.rkt +++ b/collects/syntax/parse/private/litconv.rkt @@ -7,7 +7,8 @@ "rep-data.rkt" "rep.rkt" "kws.rkt") - "runtime.rkt") + "runtime.rkt" + (only-in unstable/syntax phase-of-enclosing-module)) (provide define-conventions define-literal-set literal-set->predicate diff --git a/collects/syntax/parse/private/rep.rkt b/collects/syntax/parse/private/rep.rkt index fadbb9ac6d..99fe2fff55 100644 --- a/collects/syntax/parse/private/rep.rkt +++ b/collects/syntax/parse/private/rep.rkt @@ -2,7 +2,8 @@ (require (for-template racket/base racket/stxparam "keywords.rkt" - "runtime.rkt") + "runtime.rkt" + (only-in unstable/syntax phase-of-enclosing-module)) racket/contract/base "minimatch.rkt" syntax/id-table diff --git a/collects/syntax/parse/private/runtime.rkt b/collects/syntax/parse/private/runtime.rkt index 5c4d54747a..d8beb8e6f0 100644 --- a/collects/syntax/parse/private/runtime.rkt +++ b/collects/syntax/parse/private/runtime.rkt @@ -369,16 +369,3 @@ ;; For now, let #%app handle it. (with-syntax ([((kw-part ...) ...) #'((kw kwarg) ...)]) #'(proc kw-part ... ... extra-parg ... parg ...))])) - -;; ---- - -(provide phase-of-enclosing-module) - -(define-syntax (phase-of-enclosing-module stx) - (syntax-case stx () - [(poem) - (let ([phase-within-module (syntax-local-phase-level)]) - #`(let ([phase-of-this-expression - (variable-reference->phase (#%variable-reference))]) - (- phase-of-this-expression - #,(if (zero? phase-within-module) 0 1))))])) diff --git a/collects/unstable/scribblings/syntax.scrbl b/collects/unstable/scribblings/syntax.scrbl index 308e6cc86f..7addbf003f 100644 --- a/collects/unstable/scribblings/syntax.scrbl +++ b/collects/unstable/scribblings/syntax.scrbl @@ -26,6 +26,25 @@ resolved module path or @racket[#f] for the ``self'' module. ] } +@defform[(phase-of-enclosing-module)]{ + +Returns the phase level of the module in which the form occurs (and +for the instantiation of the module in which the form is +executed). For example, if a module is required directly by the +``main'' module (or the top level), its phase level is 0. If a module +is required for-syntax by the ``main'' module (or the top level), its +phase level is 1. + +@examples[#:eval the-eval +(module helper racket + (require unstable/syntax) + (displayln (phase-of-enclosing-module))) +(require 'helper) +(require (for-meta 1 'helper)) +] +} + + @;{----} @addition{@author+email["Vincent St-Amour" "stamourv@racket-lang.org"]} diff --git a/collects/unstable/syntax.rkt b/collects/unstable/syntax.rkt index bb0ff6b23a..ea28a5bf8b 100644 --- a/collects/unstable/syntax.rkt +++ b/collects/unstable/syntax.rkt @@ -1,7 +1,8 @@ #lang racket/base ;; owner: ryanc (and cce and stamourv, where noted) (require racket/syntax - syntax/stx) + syntax/stx + (for-syntax racket/base)) (provide (rename-out [stx-map syntax-map]) syntax-list @@ -15,7 +16,8 @@ syntax-within? ;; by ryanc - explode-module-path-index) + explode-module-path-index + phase-of-enclosing-module) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; @@ -82,3 +84,12 @@ (if (module-path-index? y) (explode-module-path-index y) (list y))))) + +(define-syntax (phase-of-enclosing-module stx) + (syntax-case stx () + [(poem) + (let ([phase-within-module (syntax-local-phase-level)]) + #`(let ([phase-of-this-expression + (variable-reference->phase (#%variable-reference))]) + (- phase-of-this-expression + #,(if (zero? phase-within-module) 0 1))))]))