diff --git a/remove-complex-oper.scm b/remove-complex-oper.scm index b4ec6d3..e30e1c9 100644 --- a/remove-complex-oper.scm +++ b/remove-complex-oper.scm @@ -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))])) diff --git a/test-remove-complex-opera.scm b/test-remove-complex-opera.scm index 12f1e54..3b5a75e 100644 --- a/test-remove-complex-opera.scm +++ b/test-remove-complex-opera.scm @@ -60,19 +60,21 @@ (test-eq (remove-complex-opera* (list-ref programs 6)) `(program () - (let ((tmp.1 (- 2))) - (let ((x.1 (+ tmp.1 3))) - (let ((tmp.3 (+ 2 3))) - (+ x.1 tmp.3)))))) + (let ((x.1 + (let ((tmp.1 (- 2))) + (+ tmp.1 3)))) + (let ((tmp.2 (+ 2 3))) + (+ x.1 tmp.2))))) (test-eq (remove-complex-opera* (list-ref programs 7)) `(program () - (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))))))) + (let ((x.1 + (let ((tmp.1 (- 1))) + (+ 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)))