-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype-check-Cany.rkt
84 lines (76 loc) · 3.17 KB
/
type-check-Cany.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#lang racket
(require "utilities.rkt")
(require "type-check-Cvar.rkt")
(require "type-check-Cif.rkt")
(require "type-check-Cwhile.rkt")
(require "type-check-Lvec.rkt")
(require "type-check-Cvec.rkt")
(require "type-check-Cfun.rkt")
(require "type-check-Clambda.rkt")
(require "type-check-Lany.rkt")
(provide type-check-Cany type-check-Cany-mixin type-check-Cany-class)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; type-check-Cany
(define (type-check-Cany-mixin super-class)
(class super-class
(super-new)
(inherit check-type-equal? join-types exp-ready?)
(define/override (free-vars-exp e)
(define (recur e) (send this free-vars-exp e))
(match e
[(ValueOf e ty) (recur e)]
[(Exit) (set)]
[else (super free-vars-exp e)]))
(define/override (type-check-exp env)
(lambda (e)
(debug 'type-check-exp "Cany" e)
(define recur (type-check-exp env))
(match e
[(ValueOf e ty)
(define-values (new-e e-ty) (recur e))
(values (ValueOf new-e ty) ty)]
[(Prim 'any-vector-length (list e1))
(define-values (e1^ t1) (recur e1))
(check-type-equal? t1 'Any e)
(values (Prim 'any-vector-length (list e1^)) 'Integer)]
[(Prim 'any-vector-ref (list e1 e2))
(define-values (e1^ t1) (recur e1))
(define-values (e2^ t2) (recur e2))
(check-type-equal? t1 'Any e)
(check-type-equal? t2 'Integer e)
(values (Prim 'any-vector-ref (list e1^ e2^)) 'Any)]
[(Prim 'any-vector-set! (list e1 e2 e3))
(define-values (e1^ t1) (recur e1))
(define-values (e2^ t2) (recur e2))
(define-values (e3^ t3) (recur e3))
(check-type-equal? t1 'Any e)
(check-type-equal? t2 'Integer e)
(check-type-equal? t3 'Any e)
(values (Prim 'any-vector-set! (list e1^ e2^ e3^)) 'Void)]
[else ((super type-check-exp env) e)])))
(define/override ((type-check-tail env block-env blocks) t)
(debug 'type-check-tail "Cany" t)
(match t
[(IfStmt cnd tail1 tail2)
(cond [(exp-ready? cnd env)
(define-values (c Tc) ((type-check-exp env) cnd))
(check-type-equal? Tc 'Boolean t)
])
(define T1 ((type-check-tail env block-env blocks) tail1))
(define T2 ((type-check-tail env block-env blocks) tail2))
(check-type-equal? T1 T2 t)
(join-types T1 T2)]
[(Exit) '_]
[else ((super type-check-tail env block-env blocks) t)]))
))
(define type-check-Cany-class (type-check-Cany-mixin
(type-check-Clambda-mixin
(type-check-Cfun-mixin
(type-check-Cvec-mixin
(type-check-Cwhile-mixin
(type-check-Cif-mixin
(type-check-Cvar-mixin
type-check-Lany-class
))))))))
(define (type-check-Cany p)
(send (new type-check-Cany-class) type-check-program p))