Skip to content

Commit

Permalink
Change make-*-req/prov-tr to take id-(un)manglers to lift out repeate…
Browse files Browse the repository at this point in the history
…d code
  • Loading branch information
iitalics committed Jun 4, 2018
1 parent 5a83945 commit 21aaffb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 34 deletions.
18 changes: 15 additions & 3 deletions hackett-lib/hackett/private/mangle/mangle-identifier.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
(provide make-id-mangler
or/unmangler
prefix/unmangler
id-mangler)
no-introduce/unmangler
id-mangler
no-introduce/mangler)

(require racket/syntax
(require racket/match
racket/syntax
"mangle-string.rkt")

;; An IdMangler is an (id-mangler StxIntroducer StringMangler)
Expand Down Expand Up @@ -49,6 +52,16 @@
(format-id unmangled "~a~a" pre unmangled
#:source unmangled #:props unmangled)))

;; IdUnmangler -> IdUnmangler
(define ((no-introduce/unmangler id-un) x)
(define unmangled (id-un x))
(and unmangled
(datum->syntax x (syntax-e unmangled) x x)))

;; IdUnmangler -> IdUnmangler
(define (no-introduce/mangler id-mangler*)
(match-define (id-mangler _ string-mangler) id-mangler*)
(id-mangler values string-mangler))

;; ---------------------------------------------------------

Expand All @@ -65,4 +78,3 @@
#false]))

;; ---------------------------------------------------------

38 changes: 12 additions & 26 deletions hackett-lib/hackett/private/mangle/mangle-reqprov.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,7 @@
;; #:introducer StxIntroducer
;; ->
;; RequireTransformer
(define (make-unmangling-require-transformer #:mangle-prefix mangle-prefix
#:introducer intro)

(define-values [id-mangler id-unmangler]
(make-id-mangler #:prefix mangle-prefix #:introducer intro))
(define-values [id-mangler/no-intro id-unmangler/no-intro]
(make-id-mangler #:prefix mangle-prefix #:introducer identity))

(define (make-unmangling-require-transformer id-unmangler)
(make-require-transformer
(syntax-parser
[(_ {~alt {~optional {~or {~and #:no-introduce no-introduce?}
Expand All @@ -36,19 +29,20 @@
...
require-spec ...)
#:do [(define id-unmangler*
(if (or (@ no-introduce?) (@ prefix))
id-unmangler/no-intro
id-unmangler))
(define id-unmangler**
(if (@ prefix)
(prefix/unmangler (syntax-e (@ prefix)) id-unmangler*)
id-unmangler*))
(let* ([unm id-unmangler]
[unm (if (or (@ no-introduce?) (@ prefix))
(no-introduce/unmangler unm)
unm)]
[unm (if (@ prefix)
(prefix/unmangler (syntax-e (@ prefix)) unm)
unm)])
unm))

(define-values [imports sources]
(expand-import #'(combine-in require-spec ...)))]

(values (for*/list ([i (in-list imports)]
[i* (in-value (unmangle-import i id-unmangler**))]
[i* (in-value (unmangle-import i id-unmangler*))]
#:when (if (@ only?) i* #t))
(or i* i))
sources)])))
Expand All @@ -57,21 +51,14 @@
;; #:introducer StxIntroducer
;; ->
;; ProvideTransformer
(define (make-mangling-provide-transformer #:mangle-prefix mangle-prefix
#:introducer intro)

(define-values [id-mangler id-unmangler]
(make-id-mangler #:prefix mangle-prefix #:introducer intro))
(define-values [id-mangler/no-intro id-unmangler/no-intro]
(make-id-mangler #:prefix mangle-prefix #:introducer identity))

(define (make-mangling-provide-transformer id-mangler)
(make-provide-transformer
(λ (stx modes)
(syntax-parse stx
[(_ {~optional {~and #:no-introduce no-introduce?}} provide-spec ...)
#:do [(define id-mangler*
(if (@ no-introduce?)
id-mangler/no-intro
(no-introduce/mangler id-mangler)
id-mangler))

(define exports
Expand All @@ -88,4 +75,3 @@
(define (unzip xs/ys)
(values (map first xs/ys)
(map second xs/ys)))

11 changes: 6 additions & 5 deletions hackett-lib/hackett/private/type-reqprov.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,18 @@
syntax/parse/define

(for-syntax hackett/private/typecheck
"mangle/mangle-identifier.rkt"
"mangle/mangle-reqprov.rkt"))

(provide for-type unmangle-types-in)

(begin-for-syntax
(define type-prefix "#%hackett-type:"))
(define-values [type-id-mangler type-id-unmangler]
(make-id-mangler #:prefix "#%hackett-type:"
#:introducer type-namespace-introduce)))

(define-syntax for-type
(make-mangling-provide-transformer #:mangle-prefix type-prefix
#:introducer type-namespace-introduce))
(make-mangling-provide-transformer type-id-mangler))

(define-syntax unmangle-types-in
(make-unmangling-require-transformer #:mangle-prefix type-prefix
#:introducer type-namespace-introduce))
(make-unmangling-require-transformer type-id-unmangler))

0 comments on commit 21aaffb

Please sign in to comment.