~technomancy/fennel

Don't double-uniquify gensyms. v1 APPLIED

Phil Hagelberg: 1
 Don't double-uniquify gensyms.

 1 files changed, 5 insertions(+), 3 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~technomancy/fennel/patches/22416/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] Don't double-uniquify gensyms. Export this patch

Gensyms already have uniqueness checks, so they can skip the extra
uniqueness checks from declare-local.

This should fix https://todo.sr.ht/~technomancy/fennel/54
---
 src/fennel/compiler.fnl | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/fennel/compiler.fnl b/src/fennel/compiler.fnl
index 023d63b..349f270 100644
--- a/src/fennel/compiler.fnl
+++ b/src/fennel/compiler.fnl
@@ -24,7 +24,8 @@ implement nesting. "
     :specials (setmetatable [] {:__index (and parent parent.specials)})
     :symmeta (setmetatable [] {:__index (and parent parent.symmeta)})
     :unmanglings (setmetatable [] {:__index (and parent parent.unmanglings)})
     :autogensyms []
     :gensyms (setmetatable [] {:__index (and parent parent.gensyms)})
     :autogensyms (setmetatable [] {:__index (and parent parent.autogensyms)})
     :vararg (and parent parent.vararg)
     :depth (if parent (+ (or parent.depth 0) 1) 0)
     :hashfn (and parent parent.hashfn)
@@ -97,7 +98,7 @@ and compile-stream."
  (or (not allowed-globals) (utils.member? name allowed-globals)))

(fn unique-mangling [original mangling scope append]
  (if (. scope.unmanglings mangling)
  (if (and (. scope.unmanglings mangling) (not (. scope.gensyms mangling)))
      (unique-mangling original (.. original append) scope (+ append 1))
      mangling))

@@ -145,6 +146,7 @@ these new manglings instead of the current manglings."
    (set mangling (.. (or base "") "_" append "_"))
    (set append (+ append 1)))
  (tset scope.unmanglings mangling (or base true))
  (tset scope.gensyms mangling true)
  mangling)

(fn autogensym [base scope]
@@ -826,7 +828,7 @@ which we have to do if we don't know."
  "A custom traceback function for Fennel that looks similar to debug.traceback.
Use with xpcall to produce fennel specific stacktraces. Skips frames from the
compiler by default; these can be re-enabled with export FENNEL_DEBUG=trace."
  (let [msg (or msg "")]
  (let [msg (tostring (or msg ""))]
    (if (and (or (msg:find "^Compile error") (msg:find "^Parse error"))
             (not (utils.debug-on? :trace)))
        msg ; skip the trace because it's compiler internals.
-- 
2.20.1