From 0e26b5a4629c20a6339f754fb53c5baa74848f4c Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 24 May 2023 07:57:21 -0700 Subject: compiler: fbind/lbind: elide unnecessary frames. * stdlib/compiler.tl (comp-fbind): When after removing unused functions we are left with an empty list (or the list of functions was empty to begin with), let's only emit the body fragment without any frame wrapping. We can't just return bfrag because that was compiled in the environment which matches the frame. Instead of the expense of compiling the code again, we rely on eliminate-frame to move all v registers up one level. --- stdlib/compiler.tl | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/stdlib/compiler.tl b/stdlib/compiler.tl index c5d00612..fd7b2017 100644 --- a/stdlib/compiler.tl +++ b/stdlib/compiler.tl @@ -1111,15 +1111,21 @@ (set ffuns (uni ffuns ff.ffuns) fvars (uni fvars ff.fvars)) (list ff))))) - (new (frag boreg - (append ^((frame ,nenv.lev ,frsize)) - (mappend .code ffrags) - bfrag.code - (maybe-mov boreg bfrag.oreg) - ^((end ,boreg))) - (uni fvars bfrag.fvars) - (uni (diff bfrag.ffuns lexfuns) - (if rec (diff ffuns lexfuns) ffuns)))))))) + (if ffrags + (new (frag boreg + (append ^((frame ,nenv.lev ,frsize)) + (mappend .code ffrags) + bfrag.code + (maybe-mov boreg bfrag.oreg) + ^((end ,boreg))) + (uni fvars bfrag.fvars) + (uni (diff bfrag.ffuns lexfuns) + (if rec (diff ffuns lexfuns) ffuns)))) + (new (frag boreg + (append me.(eliminate-frame bfrag.code nenv) + (maybe-mov boreg bfrag.oreg)) + bfrag.fvars + bfrag.ffuns))))))) (defmeth compiler comp-lambda-impl (me oreg env form) (mac-param-bind form (t par-syntax . body) form -- cgit v1.2.3