mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-23 20:15:05 +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
|
||||
;; incomplete if expressions.
|
||||
;; FUTURE: append the empty (unprinted) value instead of #f
|
||||
(if (if-else? ast)
|
||||
`(if ,@(map (lambda (a) (convert a renamed)) (cdr ast)))
|
||||
(convert (append ast '(#f)) renamed)))
|
||||
(let ((new-ast (if (if-else? ast)
|
||||
`(if ,@(map (lambda (a) (convert a renamed)) (cdr ast)))
|
||||
(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)
|
||||
(let ((converted
|
||||
(cons (car ast)
|
||||
|
|
Loading…
Add table
Reference in a new issue