Omit C meaningless expressions

When compiling Cyc-seq expressions there are cases where the generated C code would have no effect. Just omit it in this case to prevent a warning from the C compiler.
This commit is contained in:
Justin Ethier 2017-07-13 10:35:10 +00:00
parent 856f201eb0
commit 89c58f8b44

View file

@ -828,11 +828,17 @@
((equal? 'Cyc-seq fun) ((equal? 'Cyc-seq fun)
(let ((exps (foldr (let ((exps (foldr
(lambda (expr acc) (lambda (expr acc)
;(c:append ;; Join expressions; based on c:append
(let ((cp1 (c-compile-exp expr append-preamble cont trace cps?)) (let ((cp1 (if (ref? expr)
; Ignore lone ref to avoid C warning
(c-code/vars "" '())
(c-compile-exp expr append-preamble cont trace cps?)))
(cp2 acc)) (cp2 acc))
(c-code/vars (c-code/vars
(string-append (c:body cp1) ";" (c:body cp2)) (let ((cp1-body (c:body cp1)))
(if (zero? (string-length cp1-body))
(c:body cp2) ;; Ignore cp1 if necessary
(string-append cp1-body ";" (c:body cp2))))
(append (c:allocs cp1) (c:allocs cp2))))) (append (c:allocs cp1) (c:allocs cp2)))))
(c-code "") (c-code "")
args))) args)))