Created
July 22, 2019 19:00
-
-
Save michaelballantyne/e0c73d32a345e29067362798fd4868d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(require | |
(for-syntax | |
ee-lib | |
syntax/parse)) | |
(begin-for-syntax | |
(define lift-binds! (make-parameter #f)) | |
(define lift-syntaxes! (make-parameter #f)) | |
(define lift-expression! (make-parameter #f))) | |
(define-syntax (block stx) | |
(syntax-parse stx | |
[(_ body ...) | |
(define defs '()) | |
(define stxs '()) | |
(define tail-exprs '()) | |
(define (this-lift-binds! binders e) | |
) | |
(define (this-lift-syntaxes! binders e) | |
) | |
(define (this-lift-expression! e) | |
) | |
(ee-lib-boundary | |
(parameterize ([lift-binds! this-lift-binds!] | |
[lift-syntaxes! this-lift-syntaxes!] | |
[lift-expression! this-lift-expression!]) | |
(let loop ([todo (syntax->list #'(body ...))]) | |
(unless (null? todo) | |
(define expanded (local-expand (first todo) | |
(list (current-ctx-id)) | |
(list #'begin #'define-syntaxes #'define-values) | |
(cons (current-def-ctx) (current-local-def-ctxs)))) | |
(syntax-parse expanded | |
#:literals (begin define-syntaxes define-values) | |
[(begin e ...) | |
(loop (append (syntax->list #'(e ...)) todo))] | |
[(define-values (x ...) e) | |
(lift-binds! #'(x ...) #'e)] | |
[(define-syntaxes (x ...) e) | |
(lift-syntaxes! #'(x ...) #'e)] | |
[e | |
(lift-expression! #'e)]))) | |
))])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment