Don't create extra lambdas when both results of (if ...) are trivial.
Also map () directly to %nil, and allow (%if ...) to provide a value to a set! form.
This commit is contained in:
parent
46b18c07d6
commit
8e147f7989
17
compiler.ss
17
compiler.ss
|
|
@ -23,7 +23,7 @@
|
|||
(cdr form))]
|
||||
[(%bind %if %tail-call %apply %lambda %set! %cons %car %cdr) form]
|
||||
[else (simplify-funcall form)])
|
||||
form))
|
||||
(if (eq? form '()) '%nil form)))
|
||||
|
||||
(define (simplify-set! form)
|
||||
(let ([value-form (simplify-form (third form))])
|
||||
|
|
@ -33,7 +33,7 @@
|
|||
(if (pair? after)
|
||||
(cons subform after)
|
||||
(if (or (not (pair? subform))
|
||||
(memq (first subform) '(%apply %car %cdr %cons %bind)))
|
||||
(memq (first subform) '(%apply %car %cdr %cons %bind %if)))
|
||||
(list (simplify-set! `(set! ,(second form) ,subform)))
|
||||
(list subform))))
|
||||
'()
|
||||
|
|
@ -125,11 +125,14 @@
|
|||
(define-values (cond-expr true-expr false-expr)
|
||||
(apply values (cdr form)))
|
||||
(simplify-form
|
||||
`(let ([,cond-val ,cond-expr]
|
||||
[,true-fn (lambda () ,true-expr)]
|
||||
[,false-fn (lambda () ,false-expr)])
|
||||
(let ([,next-fn (%if ,cond-val ,true-fn ,false-fn)])
|
||||
(%apply ,next-fn %nil)))))
|
||||
(if (or (pair? true-expr) (pair? false-expr))
|
||||
`(let ([,cond-val ,cond-expr]
|
||||
[,true-fn (lambda () ,true-expr)]
|
||||
[,false-fn (lambda () ,false-expr)])
|
||||
(let ([,next-fn (%if ,cond-val ,true-fn ,false-fn)])
|
||||
(%apply ,next-fn %nil)))
|
||||
`(let ([,cond-val ,cond-expr])
|
||||
(%if ,cond-val ,(simplify-form true-expr) ,(simplify-form false-expr))))))
|
||||
|
||||
; (lambda (required... [optional default-expr]... . rest) bodyexpr...)
|
||||
; => (lambda argv
|
||||
|
|
|
|||
Loading…
Reference in New Issue