Only generate a let if local var is used

If the variable is not used we will get a warning from the C compiler. So let's not generate a let unless the var is actually used.

We may want to revisit this later for a related optimization, maybe via Cyc-seq.
This commit is contained in:
Justin Ethier 2018-11-23 21:46:51 -05:00
parent 09f2f0412d
commit 1145d1f8e2

View file

@ -64,14 +64,21 @@
;;(newline)
;TODO: need to revisit this, may need to replace values with assignments to the "let" variable.
;would need to be able to carry that through to cgen and assign properly over there...
(let ((value (lvr:tail-calls->values
(car (ast:lambda-body (car exp)))
(car (ast:lambda-args (car exp)))
(car (ast:lambda-args (cadr exp)))
))
(var (car (ast:lambda-args (cadr exp))))
(body (ast:lambda-body (cadr exp))))
(if value
(let* ((value (lvr:tail-calls->values
(car (ast:lambda-body (car exp)))
(car (ast:lambda-args (car exp)))
(car (ast:lambda-args (cadr exp)))
))
(var (car (ast:lambda-args (cadr exp))))
(body (ast:lambda-body (cadr exp)))
(av (adb:get/default var #f)) ;; Set to #f if unit testing
(ref-count
(if av
(adbv:ref-count av)
1)) ;; Dummy value
)
(if (and (> ref-count 0) ;; 0 ==> local var is never used
value)
`(let ((,var ,value))
,@body)
(map scan exp)) ;; failsafe