Optimize (if #f x y) to just y

This commit is contained in:
Justin Ethier 2016-07-29 18:52:00 -04:00
parent c1451e26ae
commit 0fb83a8100

View file

@ -368,9 +368,14 @@
((set!? exp) ((set!? exp)
`(set! ,(opt:contract (set!->var exp)) `(set! ,(opt:contract (set!->var exp))
,(opt:contract (set!->exp exp)))) ,(opt:contract (set!->exp exp))))
((if? exp) `(if ,(opt:contract (if->condition exp)) ((if? exp)
(cond
((not (if->condition exp))
(opt:contract (if->else exp)))
(else
`(if ,(opt:contract (if->condition exp))
,(opt:contract (if->then exp)) ,(opt:contract (if->then exp))
,(opt:contract (if->else exp)))) ,(opt:contract (if->else exp))))))
; Application: ; Application:
((app? exp) ((app? exp)
(let* ((fnc (opt:contract (car exp)))) (let* ((fnc (opt:contract (car exp))))
@ -442,9 +447,14 @@
((set!? exp) ((set!? exp)
`(set! ,(set!->var exp) `(set! ,(set!->var exp)
,(opt:inline-prims (set!->exp exp) refs))) ,(opt:inline-prims (set!->exp exp) refs)))
((if? exp) `(if ,(opt:inline-prims (if->condition exp) refs) ((if? exp)
(cond
((not (if->condition exp))
(opt:contract (if->else exp)))
(else
`(if ,(opt:inline-prims (if->condition exp) refs)
,(opt:inline-prims (if->then exp) refs) ,(opt:inline-prims (if->then exp) refs)
,(opt:inline-prims (if->else exp) refs))) ,(opt:inline-prims (if->else exp) refs)))))
; Application: ; Application:
((app? exp) ((app? exp)
;(trace:error `(app? ,exp ,(ast:lambda? (car exp)) ;(trace:error `(app? ,exp ,(ast:lambda? (car exp))