Fix bug in rco-arg and update tests

This commit is contained in:
Enrico Lumetti 2021-04-30 23:05:14 +02:00
parent d52c9eb875
commit febb63c240
2 changed files with 18 additions and 14 deletions

View File

@ -84,10 +84,12 @@
(values tmpname
assoc-list
new-tmpcount))]
; this must return a simple term
; i.e.: either a symbol, a read or a number literal
[`(let ([,var ,rexp]) ,body)
(begin
(define-values (new-exp exp-tmpcount) (rco-exp rexp tmpcount))
(define-values (new-body new-tmpcount) (rco-exp body exp-tmpcount))
(values `(let ([,var ,new-exp]) ,new-body)
`()
(define-values (new-body assoc-list new-tmpcount) (rco-arg body exp-tmpcount))
(values new-body
(cons `(,var ,new-exp) assoc-list)
new-tmpcount))]))

View File

@ -60,19 +60,21 @@
(test-eq
(remove-complex-opera* (list-ref programs 6))
`(program ()
(let ((x.1
(let ((tmp.1 (- 2)))
(let ((x.1 (+ tmp.1 3)))
(let ((tmp.3 (+ 2 3)))
(+ x.1 tmp.3))))))
(+ tmp.1 3))))
(let ((tmp.2 (+ 2 3)))
(+ x.1 tmp.2)))))
(test-eq
(remove-complex-opera* (list-ref programs 7))
`(program ()
(let ((x.1
(let ((tmp.1 (- 1)))
(let ((x.1 (+ tmp.1 2)))
(let ((tmp.3 (+ x.1 2)))
(let ((tmp.4 (+ 4 5)))
(+ tmp.3 tmp.4)))))))
(+ tmp.1 2))))
(let ((tmp.2 (+ x.1 2)))
(let ((tmp.3 (+ 4 5)))
(+ tmp.2 tmp.3))))))
(test-eq
(remove-complex-opera* (list-ref programs 8))
@ -88,10 +90,10 @@
(test-eq
(remove-complex-opera* (list-ref programs 11))
`(program () (let ((x.2 1)) (let ((x.1 x.2)) (+ 2 x.1)))))
`(program () (let ((x.1 (let ((x.2 1)) x.2))) (+ 2 x.1))))
(test-eq
(remove-complex-opera* (list-ref programs 12))
`(program () (let ((x.1 20)) (let ((x.2 22)) (let ((y.1 (+ x.1 x.2))) y.1)))))
`(program () (let ((y.1 (let ((x.1 20)) (let ((x.2 22)) (+ x.1 x.2))))) y.1)))