mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-11 23:07:36 +02:00
Do not accumulate free vars from our local (let)'s
This commit is contained in:
parent
ef647082e6
commit
a06d2793c8
1 changed files with 8 additions and 1 deletions
|
@ -623,6 +623,7 @@
|
||||||
|
|
||||||
; free-vars : exp -> sorted-set[var]
|
; free-vars : exp -> sorted-set[var]
|
||||||
(define (free-vars ast . opts)
|
(define (free-vars ast . opts)
|
||||||
|
(define let-vars '())
|
||||||
(define bound-only?
|
(define bound-only?
|
||||||
(and (not (null? opts))
|
(and (not (null? opts))
|
||||||
(car opts)))
|
(car opts)))
|
||||||
|
@ -636,7 +637,10 @@
|
||||||
((const? exp) '())
|
((const? exp) '())
|
||||||
((prim? exp) '())
|
((prim? exp) '())
|
||||||
((quote? exp) '())
|
((quote? exp) '())
|
||||||
((ref? exp) (if bound-only? '() (list exp)))
|
((ref? exp)
|
||||||
|
(if (member exp let-vars)
|
||||||
|
'()
|
||||||
|
(if bound-only? '() (list exp))))
|
||||||
((lambda? exp)
|
((lambda? exp)
|
||||||
(difference (reduce union (map search (lambda->exp exp)) '())
|
(difference (reduce union (map search (lambda->exp exp)) '())
|
||||||
(lambda-formals->list exp)))
|
(lambda-formals->list exp)))
|
||||||
|
@ -648,6 +652,9 @@
|
||||||
((define-c? exp) (list (define->var exp)))
|
((define-c? exp) (list (define->var exp)))
|
||||||
((set!? exp) (union (list (set!->var exp))
|
((set!? exp) (union (list (set!->var exp))
|
||||||
(search (set!->exp exp))))
|
(search (set!->exp exp))))
|
||||||
|
((tagged-list? 'let exp)
|
||||||
|
(set! let-vars (append (map car (cadr exp)) let-vars))
|
||||||
|
(search (cdr exp)))
|
||||||
; Application:
|
; Application:
|
||||||
((app? exp) (reduce union (map search exp) '()))
|
((app? exp) (reduce union (map search exp) '()))
|
||||||
(else (error "unknown expression: " exp))))
|
(else (error "unknown expression: " exp))))
|
||||||
|
|
Loading…
Add table
Reference in a new issue