bar))
'(abs a a))
+(test-types (typecheck '(let ([foo 3]
+ [bar (+ foo baz)]
+ [baz (- bar 1)])
+ bar))
+ 'int)
+
+(test-types (typecheck '(let ([foo 3]
+ [bar (baz foo)]
+ [baz (lambda (x) x)])
+ baz))
+ '(abs a a))
+
+(test-types (typecheck '(let ([foo 3]
+ [bar (baz foo)]
+ [baz (lambda (x) x)])
+ bar))
+ 'int)
+
(test-prog '(+ 1 2) 3)
(test-prog '((lambda (x) ((lambda (y) (+ x y)) 42)) 100) 142)
; input: a list of binds ((x . y) (y . 3))
; returns: pair of verts, edges ((x y) . (x . y))
(define (graph bs)
+ (define (go bs orig-bs)
(define (find-refs prog)
(ast-collect
(lambda (x)
(case (ast-type x)
; only count a reference if its a binding
- ['var (if (assoc x bs) (list x) '())]
+ ['var (if (assoc x orig-bs) (list x) '())]
[else '()]))
prog))
(if (null? bs)
(rest (if (null? (cdr bs))
(cons '() '())
- (graph (cdr bs))))
+ (go (cdr bs) orig-bs)))
(total-verts (cons vert (car rest)))
(total-edges (append edges (cdr rest)))]
(cons total-verts total-edges))))
+ (go bs bs))
(define (successors graph v)
(define (go v E)