Do not inline functions with free vars

This commit is contained in:
Justin Ethier 2017-04-28 18:27:51 -04:00
parent fef4663f78
commit f80da86712

View file

@ -233,11 +233,20 @@
(call/cc (call/cc
(lambda (k) (lambda (k)
(let* ((define-body (car (define->exp expr))) (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 (cond
((> (length lambda-body) 1) ((> (length lambda-body) 1)
(k #f)) ;; Fail with more than one expression in lambda body, (k #f)) ;; Fail with more than one expression in lambda body,
;; because CPS is required to compile that. ;; 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 (else
(scan (scan
(car lambda-body) (car lambda-body)
@ -245,7 +254,6 @@
(k #t))))))) ;; Scanned fine, return #t (k #t))))))) ;; Scanned fine, return #t
(else #f))) (else #f)))
;; TODO: check app for const/const-value, also (for now) reset them ;; TODO: check app for const/const-value, also (for now) reset them
;; if the variable is modified via set/define ;; if the variable is modified via set/define
(define (analyze exp lid) (define (analyze exp lid)