Upated backport so that it works on Racket 7 pre-release

This commit is contained in:
Georges Dupéron 2018-05-16 00:19:49 +02:00
parent 428642e899
commit 83bf770c8e
2 changed files with 55 additions and 1 deletions

View File

@ -1,4 +1,6 @@
#lang racket/base
(require version-case (for-syntax racket/base))
(version-case [(version< (version) "6.90.0.24") ;; not exactly the precise version number I think
(require (for-syntax racket/base
"dset.rkt"
racket/syntax
@ -658,3 +660,54 @@ instead of integers and integer vectors.
(cond [(zero? n) x]
[else (stx-drop (sub1 n) (stx-cdr x))]))
)
]
[else
(require (for-syntax racket/base)
(only-in racket/private/template
metafunction))
(provide (rename-out [syntax template]
[syntax/loc template/loc]
[quasisyntax quasitemplate]
[quasisyntax/loc quasitemplate/loc]
[~? ??]
[~@ ?@])
define-template-metafunction
syntax-local-template-metafunction-introduce)
;; ============================================================
;; Metafunctions
(define-syntax (define-template-metafunction stx)
(syntax-case stx ()
[(dsm (id arg ...) . body)
#'(dsm id (lambda (arg ...) . body))]
[(dsm id expr)
(identifier? #'id)
(with-syntax ([(internal-id) (generate-temporaries #'(id))])
#'(begin (define internal-id (make-hygienic-metafunction expr))
(define-syntax id (metafunction (quote-syntax internal-id)))))]))
(define current-template-metafunction-introducer
(make-parameter (lambda (stx) (if (syntax-transforming?) (syntax-local-introduce stx) stx))))
(define old-template-metafunction-introducer
(make-parameter #f))
(define ((make-hygienic-metafunction transformer) stx)
(define mark (make-syntax-introducer))
(define old-mark (current-template-metafunction-introducer))
(parameterize ((current-template-metafunction-introducer mark)
(old-template-metafunction-introducer old-mark))
(define r (call-with-continuation-barrier (lambda () (transformer (mark (old-mark stx))))))
(unless (syntax? r)
(raise-syntax-error #f "result of template metafunction was not syntax" stx))
(old-mark (mark r))))
(define (syntax-local-template-metafunction-introduce stx)
(let ([mark (current-template-metafunction-introducer)]
[old-mark (old-template-metafunction-introducer)])
(unless old-mark
(error 'syntax-local-template-metafunction-introduce
"must be called within the dynamic extent of a template metafunction"))
(mark (old-mark stx))))
])

View File

@ -1,7 +1,8 @@
#lang info
(define collection "backport-template-pr1514")
(define deps '("base"
"rackunit-lib"))
"rackunit-lib"
"version-case"))
(define build-deps '("scribble-lib" "racket-doc"))
(define scribblings '(("scribblings/backport-template-pr1514.scrbl" ())))
(define pkg-desc "Description Here")