www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit a3831adae2ab77c33f5798b615297bcdc86669f0
parent fc2150dc0de92035ce45818062a044ee8ad34c3c
Author: stchang <stchang@ccs.neu.edu>
Date:   Mon, 21 Sep 2015 18:16:40 -0400

Merged in make-var-like-trans (pull request #1)

add version of make-variable-like-transformer

Diffstat:
A.gitignore | 3+++
Mtapl/stlc+lit.rkt | 9++-------
Mtapl/stx-utils.rkt | 18++++++++++++++++--
3 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1,3 @@ +compiled/ +doc/ +*~ diff --git a/tapl/stlc+lit.rkt b/tapl/stlc+lit.rkt @@ -29,13 +29,8 @@ #;(define-syntax op/tc (make-rename-transformer (assign-type #'op #'τ))) ; rename transformer doesnt seem to expand at the right time ; - op still has no type in #%app - (define-syntax (op/tc stx) - (syntax-parse stx - [f:id (⊢ #,(syntax/loc stx op) : τ)] ; HO case - [(o . rst) - #:with app (datum->syntax #'o '#%app) - #:with opp (format-id #'o "~a" #'op) - (syntax/loc stx (app opp . rst))])))])) + (define-syntax op/tc + (make-variable-like-transformer (assign-type #'op #'τ))))])) (define-primop + : (→ Int Int Int)) diff --git a/tapl/stx-utils.rkt b/tapl/stx-utils.rkt @@ -47,4 +47,19 @@ (define (stx-append stx1 stx2) (append (if (syntax? stx1) (syntax->list stx1) stx1) - (if (syntax? stx2) (syntax->list stx2) stx2))) -\ No newline at end of file + (if (syntax? stx2) (syntax->list stx2) stx2))) + +;; based on make-variable-like-transformer from syntax/transformer, +;; but using (#%app id ...) instead of ((#%expression id) ...) +(define (make-variable-like-transformer ref-stx) + (unless (syntax? ref-stx) + (raise-type-error 'make-variable-like-transformer "syntax?" ref-stx)) + (lambda (stx) + (syntax-case stx () + [id + (identifier? #'id) + ref-stx] + [(id . args) + (let ([stx* (list* '#%app #'id (cdr (syntax-e stx)))]) + (datum->syntax stx stx* stx))]))) +