mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-24 20:45:06 +02:00
Optimize (if (not a) b c)
This commit is contained in:
parent
160e4a560a
commit
0dea5d82c6
1 changed files with 12 additions and 3 deletions
|
@ -1219,9 +1219,18 @@
|
||||||
;; Add a failsafe here in case macro expansion added more
|
;; Add a failsafe here in case macro expansion added more
|
||||||
;; incomplete if expressions.
|
;; incomplete if expressions.
|
||||||
;; FUTURE: append the empty (unprinted) value instead of #f
|
;; FUTURE: append the empty (unprinted) value instead of #f
|
||||||
(if (if-else? ast)
|
(let ((new-ast (if (if-else? ast)
|
||||||
`(if ,@(map (lambda (a) (convert a renamed)) (cdr ast)))
|
`(if ,@(map (lambda (a) (convert a renamed)) (cdr ast)))
|
||||||
(convert (append ast '(#f)) renamed)))
|
(convert (append ast '(#f)) renamed))))
|
||||||
|
;; Optimization - convert (if (not a) b c) into (if a c b)
|
||||||
|
(cond
|
||||||
|
((and (app? (if->condition new-ast))
|
||||||
|
(equal? 'not (app->fun (if->condition new-ast))))
|
||||||
|
`(if ,@(app->args (if->condition new-ast))
|
||||||
|
,(if->else new-ast)
|
||||||
|
,(if->then new-ast)))
|
||||||
|
(else
|
||||||
|
new-ast))))
|
||||||
((prim-call? ast)
|
((prim-call? ast)
|
||||||
(let ((converted
|
(let ((converted
|
||||||
(cons (car ast)
|
(cons (car ast)
|
||||||
|
|
Loading…
Add table
Reference in a new issue