From 914c8686b73f8aa1b290247074396c808f2630e5 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 19 Mar 2018 06:38:50 -0700 Subject: compiler: bug: lambda body uses inappropriate output reg. * share/txr/stdlib/compiler.tl (compiler comp-lambda): The incoming oreg, which indicates where the surrounding context would like to put the closure, cannot be used for the output location of the lambda body. Because then when the closure is called, its return value will overwrite the location where the closure was placed. We must allocate a a new temporary register for this, and be sure to free it. --- share/txr/stdlib/compiler.tl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/share/txr/stdlib/compiler.tl b/share/txr/stdlib/compiler.tl index 47abbeab..47f32152 100644 --- a/share/txr/stdlib/compiler.tl +++ b/share/txr/stdlib/compiler.tl @@ -299,10 +299,12 @@ ^((mov ,vbind.loc ,ifrg.oreg))) ,lskip))))) (benv (if specials (new env up nenv co me) nenv)) - (bfrag me.(comp-progn oreg benv body)) - (boreg (if env.(out-of-scope bfrag.oreg) oreg bfrag.oreg)) + (btreg me.(alloc-treg)) + (bfrag me.(comp-progn btreg benv body)) + (boreg (if env.(out-of-scope bfrag.oreg) btreg bfrag.oreg)) (lskip (gensym "l-")) (frsize nenv.v-cntr)) + me.(free-treg btreg) (new (frag oreg ^((close ,oreg ,frsize ,lskip ,nfixed ,nreq ,(if rest-par t nil) @@ -323,7 +325,7 @@ ^(bindv ,sub-bind.loc ,dreg))))) ,*bfrag.code ,*(if specials - ^((end ,oreg))) + ^((end ,boreg))) ,*(if (nequal boreg bfrag.oreg) ^((mov ,boreg ,bfrag.oreg))) (end ,boreg) -- cgit v1.2.3