diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8097c07 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +compiled/ +doc/ +*~ diff --git a/tapl/stlc+lit.rkt b/tapl/stlc+lit.rkt index a675b7d..6041fa4 100644 --- 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 index 7a6b1b6..d3061c3 100644 --- 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))]))) +