2556
2556
(and (memq var (scope:locals scope)) 'local )
2557
2557
(and (memq var (scope:globals scope))
2558
2558
(if (and exclude-top-level-globals
2559
- (null? (lam:vars (scope:lam scope)))
2559
+ (null? (lam:args (scope:lam scope)))
2560
2560
; ; don't inherit global decls from the outermost scope block
2561
2561
; ; in a top-level expression.
2562
2562
(or (not (scope:prev scope))
2636
2636
' (false)
2637
2637
' (true)))
2638
2638
((eq? (car e) 'lambda )
2639
- (let* ((args (lam:vars e))
2639
+ (let* ((args (lam:argnames e))
2640
2640
(body (resolve-scopes- (lam:body e) (make-scope e args '() '() sp '() scope))))
2641
2641
`(lambda ,(cadr e) ,(caddr e) ,body)))
2642
2642
((eq? (car e) 'scope-block )
2643
2643
(let* ((blok (cadr e)) ; ; body of scope-block expression
2644
2644
(lam (scope:lam scope))
2645
- (argnames (lam:vars lam))
2645
+ (argnames (lam:argnames lam))
2646
2646
(toplevel? (and (null? argnames) (eq? e (lam:body lam))))
2647
2647
(current-locals (caddr lam)) ; ; locals created so far in our lambda
2648
2648
(globals (find-global-decls blok))
2755
2755
,(resolve-scopes- (cadddr e) scope (method-expr-static-parameters e))))
2756
2756
(else
2757
2757
(if (and (eq? (car e) '= ) (symbol? (cadr e))
2758
- scope (null? (lam:vars (scope:lam scope)))
2758
+ scope (null? (lam:args (scope:lam scope)))
2759
2759
(warn-var?! (cadr e) scope)
2760
2760
(= *scopewarn-opt* 1 ))
2761
2761
(let* ((v (cadr e))
2782
2782
2783
2783
; ; names of arguments and local vars
2784
2784
(define (lambda-all-vars e )
2785
- (append (lam:vars e) (caddr e)))
2785
+ (append (lam:argnames e) (caddr e)))
2786
2786
2787
2787
; ; compute set of variables referenced in a lambda but not bound by it
2788
2788
(define (free-vars- e tab )
@@ -3201,6 +3201,7 @@ f(x) = yt(x)
3201
3201
; ; This does a basic-block-local dominance analysis to find variables that
3202
3202
; ; are never used undef.
3203
3203
(let ((vi (car (lam:vinfo lam)))
3204
+ (args (lam:argnames lam))
3204
3205
(unused (table)) ; ; variables not (yet) used (read from) in the current block
3205
3206
(live (table)) ; ; variables that have been set in the current block
3206
3207
(seen (table))) ; ; all variables we've seen assignments to
@@ -3221,6 +3222,11 @@ f(x) = yt(x)
3221
3222
(restore (table)))
3222
3223
(define (mark-used var )
3223
3224
; ; remove variable from the unused table
3225
+ ; ; Note arguments are only "used" for purposes of this analysis when
3226
+ ; ; they are captured, since they are never undefined.
3227
+ (if (and (has? unused var) (not (memq var args)))
3228
+ (del! unused var)))
3229
+ (define (mark-captured var )
3224
3230
(if (has? unused var)
3225
3231
(del! unused var)))
3226
3232
(define (assign! var )
@@ -3272,7 +3278,7 @@ f(x) = yt(x)
3272
3278
(get-methods e (lam:body lam))
3273
3279
(list e))))
3274
3280
(for-each (lambda (ex )
3275
- (for-each mark-used
3281
+ (for-each mark-captured
3276
3282
(map car (cadr (lam:vinfo (cadddr ex))))))
3277
3283
all-methods)
3278
3284
(assign! (cadr e))))
0 commit comments