-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.scm
76 lines (67 loc) · 2.23 KB
/
input.scm
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
#|
Gradual Type System
Khayyam Saleem, Ramana Nagasamudram
|#
(load "pmatch.scm")
(load "types.scm")
(load "caster.scm")
(define initial-type-environment
(alist->te predefined-types))
(define (system-type-environment)
(alist->te predefined-types))
(define (should-check? expr te)
(if (te/lookup te expr)
#t
(pmatch
expr
((define ,body . ,rest) #f)
((let ,body . ,rest) #f)
((lambda (,v . ,vs) ,body) #f)
((if ,p ,t ,s) #f)
((listof (: ,t) . ,items) #t)
((fn (: ,v ,t) . ,body) #t)
((defvar (: ,v ,t) . ,body) #t)
((,rator ,rand) (or (should-check? rator te)
(should-check? rand te)))
((,rator . ,rands) (or (should-check? rator te)
(should-check? rands te)))
(else #f))))
(define (sc? expr te)
(should-check? expr (alist->te te)))
(define (type-checker expr te)
(if (should-check? expr te)
(check expr te)
'no-check))
;; (define (check-file filename)
;; (let ((in (open-input-file filename)))
;; (let loop ((n 0) (e (read in)) (te (system-type-environment)))
;; (begin (display "Checking ") (display e) (display " in ") (display (te->alist te)) (newline))
;; (if (eof-object? e)
;; 'done
;; (loop (+ n 1) (read in) (te/merge (tj/te (type-checker e te)) te))))))
(define (check-file filename)
(let ((in (open-input-file filename)))
(let loop ((n 0) (e (read in)) (te (system-type-environment)))
;; (begin (display "Checking ") (display e) (display " in ") (display (te->alist te)) (newline))
(if (eof-object? e)
(list 'done n)
(let ((tc (type-checker e te)))
(if (equal? tc 'no-check)
(loop n (read in) te)
(begin (display "Checked ") (display e) (newline)
(display "in : ") (newline)
(display (te->alist (te/nremove (te/copy te)
(map car
(te->alist
(system-type-environment))))))
(newline)
(loop (+ n 1) (read in) (te/merge (tj/te tc) te)))))))))
(define (type-check filename)
(let ((in (open-input-file filename)))
(let loop ((n 0) (e (read in)) (te (system-type-environment)))
(if (eof-object? e)
(list 'done n)
(let ((tc (type-checker e te)))
(if (equal? tc 'no-check)
(loop n (read in) te)
(loop (+ n 1) (read in) (te/merge (tj/te tc) te))))))))