2 ms·
Nope; it makes the let bindings. The job of reducing to a constant is better left to the processing of the let rather than duplicated in the macro. If you have
by kazinator 9y ago
Nope; it makes the let bindings. The job of reducing to a constant is better left to the processing of the let rather than duplicated in the macro.
If you have a compiler which can reduce (let ((x 3)) ((y 4)) (+ x y)) to 5, why replicate that in a macro.
If you do not have one (as is the case here), then it's better to work on getting one than compensating for it in macros.
Yet, with the following small change to compile-expr, whereby we avoid generating temps for constant expressions, we can at least get some nicer-looking output:
(defun compile-expr (rct expr)
(cond
((member expr rct.temps) expr)
((constantp expr) expr)
(t (let ((temp (allocate-temp rct)))
(push ^(,temp ,expr) rct.lets)
temp))))
1> (rpn-compile '(3 4 + 5 6 + *))
(let* ((#:g0266 (+ 4 3))
(#:g0267 (+ 6 5))
(#:g0268 (* #:g0267 #:g0266)))
#:g0268)