From b189e47c56bab8158cc82f2f5dae96319e0d65dd Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 15 Sep 2022 00:54:14 -0700 Subject: compiler: eliminate rename-var hack. * stdlib/compiler.tl (env rename-var): Method removed. (compiler comp-let): Instead of initially creating a let* variable as a gensym, and then renaming it after compiling the init expression, we now just obtain the location not bound to a variable, use the location when compiling the init form, and bind the location to a variable right after. This is cleaner since the only thing we are mutating now is the environment, and we are not wastefully allocating a gensym. The real motivation is that this is building up to a bugfix in compiling optional variables in lambda: stay tuned! --- stdlib/compiler.tl | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'stdlib') diff --git a/stdlib/compiler.tl b/stdlib/compiler.tl index 527228e9..e31fa6a2 100644 --- a/stdlib/compiler.tl +++ b/stdlib/compiler.tl @@ -131,12 +131,6 @@ (bn (new fbinding sym sym loc loc env me))) (set me.fb (acons sym bn me.fb)))) - (:method rename-var (me from-sym to-sym) - (iflet ((cell (assoc from-sym me.vb))) - (rplaca cell to-sym) - (let ((bn (cdr cell))) - (set bn.sym to-sym)))) - (:method out-of-scope (me reg) (if (eq (car reg) 'v) (let ((lev (ssucc (cadr reg)))) @@ -977,16 +971,15 @@ (cdr allsyms)) frag.fvars))))) (form - (let* ((tmp (if seq (gensym))) - (bind (if seq - nenv.(extend-var tmp) - nenv.(lookup-var sym))) - (frag me.(compile bind.loc fenv form))) + (let* ((loc (if seq + nenv.(get-loc) + nenv.(lookup-var sym).loc)) + (frag me.(compile loc fenv form))) (when seq - fenv.(rename-var tmp sym)) + nenv.(extend-var* sym loc)) (pend frag.code) (unless (null-reg frag.oreg) - (pend me.(maybe-mov bind.loc frag.oreg))) + (pend me.(maybe-mov loc frag.oreg))) (set ffuns (uni ffuns frag.ffuns) fvars (uni fvars (if seq -- cgit v1.2.3