diff --git a/scheme/cyclone/cps-optimizations.sld b/scheme/cyclone/cps-optimizations.sld index fafb6323..67bf88ce 100644 --- a/scheme/cyclone/cps-optimizations.sld +++ b/scheme/cyclone/cps-optimizations.sld @@ -233,11 +233,20 @@ (call/cc (lambda (k) (let* ((define-body (car (define->exp expr))) - (lambda-body (lambda->exp define-body))) + (lambda-body (lambda->exp define-body)) + (fv (filter + (lambda (v) + (not (prim? v))) + (free-vars expr))) + ) +;(trace:error `(JAE DEBUG ,(define->var expr) ,fv)) (cond ((> (length lambda-body) 1) (k #f)) ;; Fail with more than one expression in lambda body, ;; because CPS is required to compile that. + ((> (length fv) 1) ;; Reject any free variables to attempt to prevent + (k #f)) ;; cases where there is a variable that may be + ;; mutated outside the scope of this function. (else (scan (car lambda-body) @@ -245,7 +254,6 @@ (k #t))))))) ;; Scanned fine, return #t (else #f))) - ;; TODO: check app for const/const-value, also (for now) reset them ;; if the variable is modified via set/define (define (analyze exp lid)