2021-06-07 02:38:03 +00:00
|
|
|
#lang racket/base
|
|
|
|
|
2021-06-07 03:09:23 +00:00
|
|
|
(require racket/base racket/format racket/list racket/match racket/string
|
2021-06-07 02:38:03 +00:00
|
|
|
syntax/parse syntax/parse/define
|
|
|
|
(for-syntax racket/base racket/match racket/set))
|
|
|
|
|
|
|
|
(provide (rename-out [x:#%module-begin #%module-begin]
|
|
|
|
[x:#%top #%top])
|
2021-06-07 03:09:23 +00:00
|
|
|
(except-out (all-from-out racket/base racket/format racket/list racket/match racket/string)
|
2021-06-07 02:38:03 +00:00
|
|
|
#%module-begin #%top))
|
|
|
|
|
|
|
|
(define-for-syntax *unbound-prop* 'xtemplate:unbound)
|
|
|
|
|
|
|
|
(define-for-syntax (collect-unbounds stx)
|
|
|
|
(define (next stx)
|
|
|
|
(match (syntax->list stx)
|
|
|
|
[#f (set)]
|
|
|
|
[lst (foldr set-union (set) (map collect-unbounds lst))]))
|
|
|
|
(match (syntax-property stx *unbound-prop*)
|
|
|
|
[#f (next stx)]
|
|
|
|
[result (set-add (next stx) result)]))
|
|
|
|
|
|
|
|
(define-syntax-parse-rule (x:#%top . id:id)
|
|
|
|
#:with #%template-args (datum->syntax #'id '#%template-args)
|
|
|
|
#:with propped-id (syntax-property #'(quote id) *unbound-prop* (syntax->datum #'id))
|
|
|
|
(hash-ref #%template-args propped-id))
|
|
|
|
|
|
|
|
(define-syntax-parse-rule (x:#%module-begin body)
|
|
|
|
#:with #%template-args (datum->syntax #'body '#%template-args)
|
|
|
|
#:with execute-fn #'(λ (#%template-args) body)
|
2021-06-07 03:09:23 +00:00
|
|
|
#:with expanded-execute-fn #'execute-fn
|
2021-06-07 03:33:18 +00:00
|
|
|
; #:with expanded-execute-fn (local-expand #'execute-fn (syntax-local-context) '())
|
2021-06-07 03:09:23 +00:00
|
|
|
; #:with (unbound-ids ...)
|
2021-06-07 03:33:18 +00:00
|
|
|
; (map (λ (stx) #`(quote #,stx)) (set->list (collect-unbounds #'expanded-execute-fn)))
|
2021-06-07 02:38:03 +00:00
|
|
|
(#%module-begin
|
2021-06-07 03:33:18 +00:00
|
|
|
; (provide required-ids)
|
|
|
|
; (define required-ids (list unbound-ids ...))
|
2021-06-07 03:09:23 +00:00
|
|
|
(provide execute)
|
2021-06-07 02:38:03 +00:00
|
|
|
(define execute expanded-execute-fn)))
|