~technomancy/antifennel

00a9735886d23191e4e7023415f0805499deb87f — Phil Hagelberg 6 months ago 43eadf6
Compile global functions to _G.foo.
2 files changed, 6 insertions(+), 6 deletions(-)

M anticompiler.fnl
M changelog.md
M anticompiler.fnl => anticompiler.fnl +5 -6
@@ 44,12 44,11 @@
          (unpack (map body (partial compile subscope) true)))))

(fn declare-function [compile scope ast]
  (if (or ast.locald (= :MemberExpression ast.id.kind))
      (doto (function compile scope ast)
        (table.insert 2 (compile scope ast.id)))
      (list (sym :set-forcibly!)
            (compile scope ast.id)
            (function compile scope ast))))
  (let [target (if (or ast.locald (= :MemberExpression ast.id.kind))
                   (compile scope ast.id)
                   (sym (.. "_G." ast.id.name)))]
    (doto (function compile scope ast)
      (table.insert 2 target))))

(fn identifier [ast]
  (if (and (ast.name:find "^[-_0-9]+$") (ast.name:find "[0-9]"))

M changelog.md => changelog.md +1 -0
@@ 2,6 2,7 @@

## 0.3.0 / ???

* Compile global functions to `(fn _G.f [] ...)` instead of `set-forcibly!`
* Compile `t.f = function` to `(fn t.f [] ...)` without `set`.
* Refuse to compile multivals at the end of mixed tables.
* Fix a bug with raw iterator values in a for loop.