enable use of define-type-alias in language implementations

- using \tau.norm in define-type-alias implementation causes
  "invalid type" errors when the file is compiled
This commit is contained in:
Stephen Chang 2016-07-20 18:44:15 -04:00
parent f90c464a19
commit 3707d90531
8 changed files with 25 additions and 17 deletions

View File

@ -15,14 +15,15 @@
(define-base-type Int)
;; Using τ.norm leads to a "not valid type" error when file is compiled
(define-syntax define-primop
(syntax-parser #:datum-literals (:)
[(_ op:id : τ:type)
[(_ op:id : τ)
#:with op/tc (generate-temporary #'op)
#'(begin
(provide (rename-out [op/tc op]))
(define-primop op/tc op : τ))]
[(_ op/tc op : τ)
[(_ op/tc op : τ:type)
#'(begin
#;(define-syntax op/tc (make-rename-transformer (assign-type #'op #'τ)))
; rename transformer doesnt seem to expand at the right time

View File

@ -18,10 +18,11 @@
;; - define-type-alias
(provide define-type-alias)
;; Using τ.norm leads to a "not valid type" error when file is compiled
(define-syntax define-type-alias
(syntax-parser
[(_ alias:id τ:type)
#'(define-syntax alias (make-variable-like-transformer #'τ.norm) #;(syntax-parser [x:id #'τ.norm]))]
#'(define-syntax alias (make-variable-like-transformer #'τ))]
[(_ (f:id x:id ...) ty)
#'(define-syntax (f stx)
(syntax-parse stx

View File

@ -107,5 +107,5 @@
ref-stx]
[(id . args)
(let ([stx* (list* '#%app #'id (cdr (syntax-e stx)))])
(datum->syntax stx stx* stx))])))
(datum->syntax stx stx* stx stx))])))

View File

@ -595,7 +595,10 @@
(define-syntax τ
(syntax-parser
;[(~var _ id) (add-orig (assign-type #'τ-internal #'kind) #'τ)])))]))
[(~var _ id) (add-orig (assign-type #'(τ-internal) #'#%tag) #'τ)])))]))
[(~var _ id)
(add-orig
(assign-type
(syntax/loc this-syntax (τ-internal)) #'#%tag) #'τ)])))]))
; I use identifiers "τ" and "kind" but this form is not restricted to them.
; E.g., τ can be #'★ and kind can be #'#%kind (★'s type)

View File

@ -93,11 +93,6 @@
(define-base-type Stx)
#;(define-typed-syntax syntax
[(_ template)
--------
[ [[_ (syntax- template)] : Stx]]])
;; ----------------------------------------------------------------------------
;; BV stuff
@ -105,10 +100,14 @@
(define-base-type BV) ; represents actual bitvectors
; a predicate recognizing bv's of a certain size
#;(define-syntax BVPred
(make-variable-like-transformer
((current-type-eval) #'( BV Bool))))
(define-type-alias BVPred ( BV Bool))
;; TODO: fix me --- need subtyping?
(define-syntax Nat (make-rename-transformer #'Int))
;(define-syntax Nat (make-rename-transformer #'Int))
(define-type-alias Nat Int)
;; TODO: support higher order case --- need intersect types?
;(define-rosette-primop bv : (→ Int BVPred BV)

View File

@ -15,14 +15,15 @@
(define-base-type Int)
;; Using τ.norm leads to a "not valid type" error when file is compiled
(define-syntax define-primop
(syntax-parser #:datum-literals (:)
[(define-primop op:id : τ:type)
[(define-primop op:id : τ)
#:with op/tc (generate-temporary #'op)
#`(begin-
(provide- #,(syntax/loc this-syntax (rename-out- [op/tc op])))
(define-primop op/tc op : τ))]
[(define-primop op/tc op : τ)
[(define-primop op/tc op : τ:type)
#'(begin-
; rename transformer doesnt seem to expand at the right time
; - op still has no type in #%app

View File

@ -18,10 +18,11 @@
;; - define-type-alias
(provide define-type-alias)
;; Using τ.norm leads to a "not valid type" error when file is compiled
(define-syntax define-type-alias
(syntax-parser
[(define-type-alias alias:id τ:type)
#'(define-syntax alias (make-variable-like-transformer #'τ.norm))]
#'(define-syntax alias (make-variable-like-transformer #'τ))]
[(define-type-alias (f:id x:id ...) ty)
#'(define-syntax (f stx)
(syntax-parse stx

View File

@ -27,11 +27,13 @@
(require "fomega2-tests.rkt")
(require "fomega3-tests.rkt")
(require macrotypes/examples/tests/stlc+occurrence-tests)
(require macrotypes/examples/tests/stlc+overloading-tests)
;; these are not ported to turnstile yet
;; see macrotypes/examples/tests/run-all-tests.rkt
;(require macrotypes/examples/tests/stlc+occurrence-tests)
;(require macrotypes/examples/tests/stlc+overloading-tests)
;; type inference
(require macrotypes/examples/tests/infer-tests)
;(require macrotypes/examples/tests/infer-tests)
(require "tlb-infer-tests.rkt")
;; type and effects