mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-25 04:55:04 +02:00
Optimize (if #f x y) to just y
This commit is contained in:
parent
c1451e26ae
commit
0fb83a8100
1 changed files with 16 additions and 6 deletions
|
@ -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)
|
||||||
,(opt:contract (if->then exp))
|
(cond
|
||||||
,(opt:contract (if->else exp))))
|
((not (if->condition exp))
|
||||||
|
(opt:contract (if->else exp)))
|
||||||
|
(else
|
||||||
|
`(if ,(opt:contract (if->condition exp))
|
||||||
|
,(opt:contract (if->then 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)
|
||||||
,(opt:inline-prims (if->then exp) refs)
|
(cond
|
||||||
,(opt:inline-prims (if->else exp) refs)))
|
((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->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))
|
||||||
|
|
Loading…
Add table
Reference in a new issue