From 44b3df23f628b459f41d58f330277c1d031c35d4 Mon Sep 17 00:00:00 2001 From: Oliver Caldwell Date: Sun, 4 Jul 2021 14:40:48 +0100 Subject: [PATCH 01/11] Initial work on the new module system --- example.fnl | 5 +++ modules-plugin.fnl | 84 ++++++++++++++++++++++++++++++++++++ scripts/internal/compile.fnl | 9 ++-- 3 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 example.fnl create mode 100644 modules-plugin.fnl diff --git a/example.fnl b/example.fnl new file mode 100644 index 0000000..9c3c8d2 --- /dev/null +++ b/example.fnl @@ -0,0 +1,5 @@ +(module foo + {require {a aniseed.core}}) + +(+ 10 20) +(a.println "Hello, World!") diff --git a/modules-plugin.fnl b/modules-plugin.fnl new file mode 100644 index 0000000..bdea2dd --- /dev/null +++ b/modules-plugin.fnl @@ -0,0 +1,84 @@ +;; TODO +;; *file* +;; (module...) +;; autoload +;; def, def-, defn, defn-, defonce, defonce-, time, deftest + +(local root-module-sym (sym :module)) +(local module-sym (sym :*module*)) +(local module-name-sym (sym :*module-name*)) +(local black-hole-sym (sym :_)) + +(fn empty-table [t] + (while (> (# t) 0) + (table.remove t)) ) + +(fn call [ast scope] + ;; (module ...) + (when (= root-module-sym (. ast 1)) + (let [[_module name new-local-fns initial-mod] ast + name-str (tostring name) + existing-mod (. package.loaded name-str) + mod (or existing-mod + initial-mod + {:aniseed/module name-str + :aniseed/locals {} + :aniseed/local-fns new-local-fns}) + locals []] + + ;; Stringify the keys and values of new-local-fns. + (each [f aliases (pairs new-local-fns)] + (each [alias arg (pairs aliases)] + (tset aliases alias nil) + (tset aliases (tostring alias) (tostring arg)))) + + ;; Sync new-local-fns into local-fns if the module is loaded. + ;; This is only used when reloading a module at runtime. + (when (and existing-mod new-local-fns) + (each [k v (pairs new-local-fns)] + (tset (. existing-mod :aniseed/local-fns) k v))) + + ;; Reset the AST. + (empty-table ast) + + ;; *module-name* + (table.insert locals [module-name-sym name-str]) + + ;; *module* + (table.insert locals [module-sym mod]) + + ;; package.loaded[module-name] = module + (table.insert + locals + [black-hole-sym + `(tset package.loaded ,name-str ,mod)]) + + ;; local-fns -> local definitions + (each [f aliases (pairs new-local-fns)] + (each [alias arg (pairs aliases)] + (table.insert + locals + [(sym alias) + `(,f ,arg)]))) + + ;; Now we build the AST from the locals table. + (let [names [] + vals []] + + ;; ( ...) + (table.insert ast `local) + + ;; Split all the locals pairs into the names and vals tables. + (each [_ [k v] (ipairs locals)] + (table.insert names k) + (table.insert vals v)) + + ;; Then we unpack those tables into our AST. + + ;; (local <(xk yk zk)> ...) + (table.insert ast (list (unpack names))) + + ;; (local ... <(xv yv zv)>) + (table.insert ast (list `values (unpack vals))))))) + +{:call call} diff --git a/scripts/internal/compile.fnl b/scripts/internal/compile.fnl index bcde8c4..c0f1452 100755 --- a/scripts/internal/compile.fnl +++ b/scripts/internal/compile.fnl @@ -1,3 +1,5 @@ +;; TODO Maybe this all goes away, just use the CLI for this part? + (local fennel (require :fennel)) (set fennel.path (.. fennel.path ";fnl/?.fnl")) @@ -11,17 +13,14 @@ (fn compile [content opts] (xpcall (fn [] - (fennel.compileString - (.. "(local *file* \"" opts.filename "\")" - "(require-macros :aniseed.macros)\n" content) - opts)) + (fennel.compileString content opts)) fennel.traceback)) (let [filename (. arg 1) (ok? result) (-> filename (read-file) (compile {:filename filename - :compilerEnv false}))] + :plugins ["modules-plugin.fnl"]}))] (if ok? (print result) (error result))) From 9bdc59f514238200531dcfbabebcfa03aa2dc102 Mon Sep 17 00:00:00 2001 From: Oliver Caldwell Date: Fri, 23 Jul 2021 11:48:48 +0100 Subject: [PATCH 02/11] Move the module form to it's own fn --- modules-plugin.fnl | 135 +++++++++++++++++++++++---------------------- 1 file changed, 69 insertions(+), 66 deletions(-) diff --git a/modules-plugin.fnl b/modules-plugin.fnl index bdea2dd..4500f05 100644 --- a/modules-plugin.fnl +++ b/modules-plugin.fnl @@ -13,72 +13,75 @@ (while (> (# t) 0) (table.remove t)) ) +(fn module-form [ast scope] + (let [[_module name new-local-fns initial-mod] ast + name-str (tostring name) + existing-mod (. package.loaded name-str) + mod (or existing-mod + initial-mod + {:aniseed/module name-str + :aniseed/locals {} + :aniseed/local-fns new-local-fns}) + locals []] + + ;; Stringify the keys and values of new-local-fns. + (each [f aliases (pairs new-local-fns)] + (each [alias arg (pairs aliases)] + (tset aliases alias nil) + (tset aliases (tostring alias) (tostring arg)))) + + ;; Sync new-local-fns into local-fns if the module is loaded. + ;; This is only used when reloading a module at runtime. + (when (and existing-mod new-local-fns) + (each [k v (pairs new-local-fns)] + (tset (. existing-mod :aniseed/local-fns) k v))) + + ;; Reset the AST. + (empty-table ast) + + ;; *module-name* + (table.insert locals [module-name-sym name-str]) + + ;; *module* + (table.insert locals [module-sym mod]) + + ;; package.loaded[module-name] = module + (table.insert + locals + [black-hole-sym + `(tset package.loaded ,name-str ,mod)]) + + ;; local-fns -> local definitions + (each [f aliases (pairs new-local-fns)] + (each [alias arg (pairs aliases)] + (table.insert + locals + [(sym alias) + `(,f ,arg)]))) + + ;; Now we build the AST from the locals table. + (let [names [] + vals []] + + ;; ( ...) + (table.insert ast `local) + + ;; Split all the locals pairs into the names and vals tables. + (each [_ [k v] (ipairs locals)] + (table.insert names k) + (table.insert vals v)) + + ;; Then we unpack those tables into our AST. + + ;; (local <(xk yk zk)> ...) + (table.insert ast (list (unpack names))) + + ;; (local ... <(xv yv zv)>) + (table.insert ast (list `values (unpack vals)))))) + (fn call [ast scope] - ;; (module ...) - (when (= root-module-sym (. ast 1)) - (let [[_module name new-local-fns initial-mod] ast - name-str (tostring name) - existing-mod (. package.loaded name-str) - mod (or existing-mod - initial-mod - {:aniseed/module name-str - :aniseed/locals {} - :aniseed/local-fns new-local-fns}) - locals []] - - ;; Stringify the keys and values of new-local-fns. - (each [f aliases (pairs new-local-fns)] - (each [alias arg (pairs aliases)] - (tset aliases alias nil) - (tset aliases (tostring alias) (tostring arg)))) - - ;; Sync new-local-fns into local-fns if the module is loaded. - ;; This is only used when reloading a module at runtime. - (when (and existing-mod new-local-fns) - (each [k v (pairs new-local-fns)] - (tset (. existing-mod :aniseed/local-fns) k v))) - - ;; Reset the AST. - (empty-table ast) - - ;; *module-name* - (table.insert locals [module-name-sym name-str]) - - ;; *module* - (table.insert locals [module-sym mod]) - - ;; package.loaded[module-name] = module - (table.insert - locals - [black-hole-sym - `(tset package.loaded ,name-str ,mod)]) - - ;; local-fns -> local definitions - (each [f aliases (pairs new-local-fns)] - (each [alias arg (pairs aliases)] - (table.insert - locals - [(sym alias) - `(,f ,arg)]))) - - ;; Now we build the AST from the locals table. - (let [names [] - vals []] - - ;; ( ...) - (table.insert ast `local) - - ;; Split all the locals pairs into the names and vals tables. - (each [_ [k v] (ipairs locals)] - (table.insert names k) - (table.insert vals v)) - - ;; Then we unpack those tables into our AST. - - ;; (local <(xk yk zk)> ...) - (table.insert ast (list (unpack names))) - - ;; (local ... <(xv yv zv)>) - (table.insert ast (list `values (unpack vals))))))) + (if + ;; (module ...) + (= root-module-sym (. ast 1)) (module-form ast scope))) {:call call} From 71d4bb04d779fc025c740c5f49c879fb0e0bb099 Mon Sep 17 00:00:00 2001 From: Oliver Caldwell Date: Fri, 23 Jul 2021 16:18:53 +0100 Subject: [PATCH 03/11] Begin adding def-, not sure if plugins are a good idea now --- example.fnl | 4 ++- modules-plugin.fnl | 65 +++++++++++++++++++++++++++++++--------------- 2 files changed, 47 insertions(+), 22 deletions(-) diff --git a/example.fnl b/example.fnl index 9c3c8d2..992d497 100644 --- a/example.fnl +++ b/example.fnl @@ -1,5 +1,7 @@ -(module foo +(module mymod {require {a aniseed.core}}) +(def- private-val :this-is-private) + (+ 10 20) (a.println "Hello, World!") diff --git a/modules-plugin.fnl b/modules-plugin.fnl index 4500f05..22e8397 100644 --- a/modules-plugin.fnl +++ b/modules-plugin.fnl @@ -2,13 +2,17 @@ ;; *file* ;; (module...) ;; autoload -;; def, def-, defn, defn-, defonce, defonce-, time, deftest +;; def, defn, defn-, defonce, defonce-, time, deftest (local root-module-sym (sym :module)) +(local def-private-sym (sym :def-)) (local module-sym (sym :*module*)) (local module-name-sym (sym :*module-name*)) (local black-hole-sym (sym :_)) +(fn table? [x] + (= :table (type x))) + (fn empty-table [t] (while (> (# t) 0) (table.remove t)) ) @@ -25,10 +29,11 @@ locals []] ;; Stringify the keys and values of new-local-fns. - (each [f aliases (pairs new-local-fns)] - (each [alias arg (pairs aliases)] - (tset aliases alias nil) - (tset aliases (tostring alias) (tostring arg)))) + (when (table? new-local-fns) + (each [f aliases (pairs new-local-fns)] + (each [alias arg (pairs aliases)] + (tset aliases alias nil) + (tset aliases (tostring alias) (tostring arg))))) ;; Sync new-local-fns into local-fns if the module is loaded. ;; This is only used when reloading a module at runtime. @@ -36,28 +41,28 @@ (each [k v (pairs new-local-fns)] (tset (. existing-mod :aniseed/local-fns) k v))) - ;; Reset the AST. (empty-table ast) - ;; *module-name* - (table.insert locals [module-name-sym name-str]) - - ;; *module* - (table.insert locals [module-sym mod]) - ;; package.loaded[module-name] = module (table.insert locals [black-hole-sym `(tset package.loaded ,name-str ,mod)]) + ;; *module-name* + (table.insert locals [module-name-sym name-str]) + + ;; *module* + (table.insert locals [module-sym `(. package.loaded ,name-str)]) + ;; local-fns -> local definitions - (each [f aliases (pairs new-local-fns)] - (each [alias arg (pairs aliases)] - (table.insert - locals - [(sym alias) - `(,f ,arg)]))) + (when (table? new-local-fns) + (each [f aliases (pairs new-local-fns)] + (each [alias arg (pairs aliases)] + (table.insert + locals + [(sym alias) + `(,f ,arg)])))) ;; Now we build the AST from the locals table. (let [names [] @@ -79,9 +84,27 @@ ;; (local ... <(xv yv zv)>) (table.insert ast (list `values (unpack vals)))))) +(fn def-private-form [ast scope] + (let [[_def- name value] ast] + (empty-table ast) + (table.insert ast `local) + (table.insert ast name) + (table.insert + ast + `(let [v# ,value] + (tset + (. ,module-sym :aniseed/locals) + ,(tostring name) + v#) + #v)))) + (fn call [ast scope] - (if - ;; (module ...) - (= root-module-sym (. ast 1)) (module-form ast scope))) + (let [head (. ast 1)] + (if + ;; (module ...) + (= root-module-sym head) (module-form ast scope) + + ;; (def- ...) + (= def-private-sym head) (def-private-form ast scope)))) {:call call} From 41832e4da2e2b9f5c0b7d06f3d57a59860da4ca2 Mon Sep 17 00:00:00 2001 From: Andrew DeFilippo Date: Mon, 26 Jul 2021 18:10:49 -0500 Subject: [PATCH 04/11] *Mostly* comptime module system rewrite, gets rid of macros.fnl, and the internal compile.fnl script following the suggestions in the comments. Uses my fork of Fennel that patches the `lua` special, and adds a few small changes to support this rewrite. Rewrote autoload to generate slightly less code. Slightly modified the tests to properly reflect the changes. --- Makefile | 5 +- fnl/aniseed/autoload.fnl | 36 +- fnl/aniseed/compile.fnl | 26 +- fnl/aniseed/macros.fnl | 144 -- lua/aniseed/autoload.lua | 90 +- lua/aniseed/compile.lua | 182 +-- lua/aniseed/core.lua | 1246 ++++++----------- lua/aniseed/deps/fennel.lua | 36 +- lua/aniseed/env.lua | 139 +- lua/aniseed/eval.lua | 76 +- lua/aniseed/fennel.lua | 138 +- lua/aniseed/fs.lua | 180 +-- lua/aniseed/macros.fnl | 144 -- lua/aniseed/nvim.lua | 44 +- lua/aniseed/nvim/util.lua | 158 +-- lua/aniseed/string.lua | 235 +--- lua/aniseed/test.lua | 333 ++--- lua/aniseed/view.lua | 62 +- module-system-plugin.fnl | 184 +++ modules-plugin.fnl | 110 -- scripts/internal/compile.fnl | 26 - test/fnl/aniseed/compile-test.fnl | 2 +- ...macros-test.fnl => module-system-test.fnl} | 2 +- 23 files changed, 1156 insertions(+), 2442 deletions(-) delete mode 100644 fnl/aniseed/macros.fnl delete mode 100644 lua/aniseed/macros.fnl create mode 100644 module-system-plugin.fnl delete mode 100644 modules-plugin.fnl delete mode 100755 scripts/internal/compile.fnl rename test/fnl/aniseed/{macros-test.fnl => module-system-test.fnl} (83%) diff --git a/Makefile b/Makefile index f6a2198..0ac9ad5 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ SRC_FILES := $(basename $(shell find fnl -type f -name "*.fnl" ! -name "macros.f default: deps compile test deps: - scripts/dep.sh bakpakin Fennel afebcb22999fe2a2f2174299f9c63b7e0f25022f + scripts/dep.sh sioonhho Fennel aniseed-comptime-module-system-support scripts/dep.sh norcalli nvim.lua 5d57be0b6eea6c06977b1c5fe0752da909cf4154 cd deps/Fennel && make build @@ -13,10 +13,9 @@ compile: rm -rf lua for f in $(SRC_FILES); do \ mkdir -p lua/$$(dirname $$f); \ - deps/Fennel/fennel scripts/internal/compile.fnl fnl/$$f.fnl > lua/$$f.lua; \ + deps/Fennel/fennel --compile --plugin module-system-plugin.fnl fnl/$$f.fnl > lua/$$f.lua; \ done mkdir -p lua/aniseed/deps - cp fnl/aniseed/macros.fnl lua/aniseed cp deps/Fennel/fennel.lua lua/aniseed/deps/fennel.lua cp deps/Fennel/fennelview.lua lua/aniseed/deps/fennelview.lua cp deps/nvim.lua/lua/nvim.lua lua/aniseed/deps/nvim.lua diff --git a/fnl/aniseed/autoload.fnl b/fnl/aniseed/autoload.fnl index ded7e0c..17c5b81 100644 --- a/fnl/aniseed/autoload.fnl +++ b/fnl/aniseed/autoload.fnl @@ -1,6 +1,6 @@ (module aniseed.autoload) -(defn autoload [name] +(defn autoload [alias name] "Like autoload from Vim Script! A replacement for require that will load the module when you first use it. Use it in Aniseed module macros with: @@ -10,27 +10,21 @@ startup dramatically. Only works with table modules, if the module you're requiring is a function etc you need to use the normal require." - (let [res {:aniseed/autoload-enabled? true - :aniseed/autoload-module false}] + (fn ensure [] + (set-forcibly! alias (require name)) + alias) - (fn ensure [] - (if (. res :aniseed/autoload-module) - (. res :aniseed/autoload-module) - (let [m (require name)] - (tset res :aniseed/autoload-module m) - m))) + (setmetatable + {} - (setmetatable - res + {:__call + (fn [t ...] + ((ensure) ...)) - {:__call - (fn [t ...] - ((ensure) ...)) + :__index + (fn [t k] + (. (ensure) k)) - :__index - (fn [t k] - (. (ensure) k)) - - :__newindex - (fn [t k v] - (tset (ensure) k v))}))) + :__newindex + (fn [t k v] + (tset (ensure) k v))})) diff --git a/fnl/aniseed/compile.fnl b/fnl/aniseed/compile.fnl index 45d1061..727e126 100644 --- a/fnl/aniseed/compile.fnl +++ b/fnl/aniseed/compile.fnl @@ -4,29 +4,25 @@ nvim aniseed.nvim fennel aniseed.fennel}}) -(defn macros-prefix [code opts] - (let [macros-module :aniseed.macros - filename (-?> (a.get opts :filename) - (string.gsub - (.. (nvim.fn.getcwd) fs.path-sep) - ""))] - (.. "(local *file* " - (if filename - (.. "\"" (string.gsub filename "\\" "\\\\") "\"") - "nil") - ")" - "(require-macros \"" macros-module "\")\n" code))) +(local base-path (-?> (. (debug.getinfo 1 :S) :source) + (: :gsub :^. "") + (: :gsub (string.gsub *file* :fnl :lua) ""))) (defn str [code opts] "Compile some Fennel code as a string into Lua. Maps to fennel.compileString with some wrapping, returns an (ok? result) tuple. Automatically requires the Aniseed macros." - (let [fnl (fennel.impl)] + (let [fnl (fennel.impl) + plugins ["module-system-plugin.fnl"] + plugins (icollect [_ plugin (ipairs plugins)] + (fnl.dofile (.. base-path plugin) + {:env :_COMPILER + :useMetadata true}))] (xpcall #(fnl.compileString - (macros-prefix code opts) - (a.merge {:allowedGlobals false} opts)) + code + (a.merge {:allowedGlobals false : plugins} opts)) fnl.traceback))) (defn file [src dest] diff --git a/fnl/aniseed/macros.fnl b/fnl/aniseed/macros.fnl deleted file mode 100644 index 1e5032e..0000000 --- a/fnl/aniseed/macros.fnl +++ /dev/null @@ -1,144 +0,0 @@ -;; All of Aniseed's macros in one place. -;; Can't be compiled to Lua directly. - -;; Automatically loaded through require-macros for all Aniseed based evaluations. - -(local module-sym (gensym)) - -(fn sorted-each [f x] - (let [acc []] - (each [k v (pairs x)] - (table.insert acc [k v])) - (table.sort - acc - (fn [a b] - (< (. a 1) (. b 1)))) - (each [_ [k v] (ipairs acc)] - (f k v)))) - -(fn module [name new-local-fns initial-mod] - `(-> [(local ,module-sym - (let [name# ,(tostring name) - module# (let [x# (. package.loaded name#)] - (if (= :table (type x#)) - x# - ,(or initial-mod {})))] - (tset module# :aniseed/module name#) - (tset module# :aniseed/locals (or (. module# :aniseed/locals) {})) - (tset module# :aniseed/local-fns (or (. module# :aniseed/local-fns) {})) - (tset package.loaded name# module#) - module#)) - - ,module-sym - - ;; Meta! Autoload the autoload function, so it's only loaded when used. - (local ,(sym :autoload) - (fn [...] ((. (require :aniseed.autoload) :autoload) ...))) - - ,(let [aliases [] - vals [] - effects [] - pkg (let [x (. package.loaded (tostring name))] - (when (= :table (type x)) - x)) - locals (-?> pkg (. :aniseed/locals)) - local-fns (or (and (not new-local-fns) - (?. pkg :aniseed/local-fns)) - {})] - - (when new-local-fns - (each [action binds (pairs new-local-fns)] - (let [action-str (tostring action) - current (or (. local-fns action-str) {})] - (tset local-fns action-str current) - (each [alias module (pairs binds)] - (if (= :number (type alias)) - (tset current (tostring module) true) - (tset current (tostring alias) (tostring module))))))) - - (sorted-each - (fn [action binds] - (sorted-each - (fn [alias-or-val val] - (if (= true val) - - ;; {require-macros [bar]} - (table.insert effects `(,(sym action) ,alias-or-val)) - - ;; {require {foo bar}} - (do - (table.insert aliases (sym alias-or-val)) - (table.insert vals `(,(sym action) ,val))))) - - binds)) - local-fns) - - (when locals - (sorted-each - (fn [alias val] - (table.insert aliases (sym alias)) - (table.insert vals `(. ,module-sym :aniseed/locals ,alias))) - locals)) - - `[,effects - (local ,aliases - (let [(ok?# val#) - (pcall - (fn [] ,vals))] - (if ok?# - (do - (tset ,module-sym :aniseed/local-fns ,local-fns) - val#) - (print val#)))) - (local ,(sym "*module*") ,module-sym) - (local ,(sym "*module-name*") ,(tostring name))])] - (. 2))) - -(fn def- [name value] - `(local ,name - (let [v# ,value - t# (. ,module-sym :aniseed/locals)] - (tset t# ,(tostring name) v#) - v#))) - -(fn def [name value] - `(def- ,name - (do - (let [v# ,value] - (tset ,module-sym ,(tostring name) v#) - v#)))) - -(fn defn- [name ...] - `(def- ,name (fn ,name ,...))) - -(fn defn [name ...] - `(def ,name (fn ,name ,...))) - -(fn defonce- [name value] - `(def- ,name - (or (. ,module-sym :aniseed/locals ,(tostring name)) - ,value))) - -(fn defonce [name value] - `(def ,name - (or (. ,module-sym ,(tostring name)) - ,value))) - -(fn deftest [name ...] - `(let [tests# (or (. ,module-sym :aniseed/tests) {})] - (tset tests# ,(tostring name) (fn [,(sym :t)] ,...)) - (tset ,module-sym :aniseed/tests tests#))) - -(fn time [...] - `(let [start# (vim.loop.hrtime) - result# (do ,...) - end# (vim.loop.hrtime)] - (print (.. "Elapsed time: " (/ (- end# start#) 1000000) " msecs")) - result#)) - -{:module module - :def- def- :def def - :defn- defn- :defn defn - :defonce- defonce- :defonce defonce - :deftest deftest - :time time} diff --git a/lua/aniseed/autoload.lua b/lua/aniseed/autoload.lua index 458631a..9d82085 100644 --- a/lua/aniseed/autoload.lua +++ b/lua/aniseed/autoload.lua @@ -1,78 +1,30 @@ -local _2afile_2a = "fnl/aniseed/autoload.fnl" +local _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil local _0_ do - local name_0_ = "aniseed.autoload" - local module_0_ - do - local x_0_ = package.loaded[name_0_] - if ("table" == type(x_0_)) then - module_0_ = x_0_ - else - module_0_ = {} - end - end - module_0_["aniseed/module"] = name_0_ - module_0_["aniseed/locals"] = ((module_0_)["aniseed/locals"] or {}) - do end (module_0_)["aniseed/local-fns"] = ((module_0_)["aniseed/local-fns"] or {}) - do end (package.loaded)[name_0_] = module_0_ - _0_ = module_0_ + local mod_0_ = {["aniseed/local-fns"] = {}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.autoload"} + package.loaded["aniseed.autoload"] = mod_0_ + _0_ = mod_0_ end +_2amodule_2a, _2amodule_name_2a, _2afile_2a = _0_, "aniseed.autoload", "fnl/aniseed/autoload.fnl" local autoload -local function _1_(...) - return (require("aniseed.autoload")).autoload(...) -end -autoload = _1_ -local function _2_(...) - local ok_3f_0_, val_0_ = nil, nil - local function _2_() - return {} +local function _1_(alias, name) + local function ensure() + alias = require(name) + return alias end - ok_3f_0_, val_0_ = pcall(_2_) - if ok_3f_0_ then - _0_["aniseed/local-fns"] = {} - return val_0_ - else - return print(val_0_) + local function _2_(t, ...) + return ensure()(...) end -end -local _local_0_ = _2_(...) -local _2amodule_2a = _0_ -local _2amodule_name_2a = "aniseed.autoload" -do local _ = ({nil, _0_, nil, {{}, nil, nil, nil}})[2] end -local autoload0 -do - local v_0_ - do - local v_0_0 - local function autoload1(name) - local res = {["aniseed/autoload-enabled?"] = true, ["aniseed/autoload-module"] = false} - local function ensure() - if res["aniseed/autoload-module"] then - return res["aniseed/autoload-module"] - else - local m = require(name) - do end (res)["aniseed/autoload-module"] = m - return m - end - end - local function _3_(t, ...) - return ensure()(...) - end - local function _4_(t, k) - return ensure()[k] - end - local function _5_(t, k, v) - ensure()[k] = v - return nil - end - return setmetatable(res, {__call = _3_, __index = _4_, __newindex = _5_}) - end - v_0_0 = autoload1 - _0_["autoload"] = v_0_0 - v_0_ = v_0_0 + local function _3_(t, k) + return ensure()[k] + end + local function _4_(t, k, v) + ensure()[k] = v + return nil end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["autoload"] = v_0_ - autoload0 = v_0_ + return setmetatable({}, {__call = _2_, __index = _3_, __newindex = _4_}) end +autoload = _1_ +_2amodule_2a["autoload"] = autoload +_2amodule_2a["aniseed/locals"]["autoload"] = autoload return nil diff --git a/lua/aniseed/compile.lua b/lua/aniseed/compile.lua index 870bbfe..dcf8aa5 100644 --- a/lua/aniseed/compile.lua +++ b/lua/aniseed/compile.lua @@ -1,146 +1,78 @@ -local _2afile_2a = "fnl/aniseed/compile.fnl" -local _0_ -do - local name_0_ = "aniseed.compile" - local module_0_ - do - local x_0_ = package.loaded[name_0_] - if ("table" == type(x_0_)) then - module_0_ = x_0_ - else - module_0_ = {} - end - end - module_0_["aniseed/module"] = name_0_ - module_0_["aniseed/locals"] = ((module_0_)["aniseed/locals"] or {}) - do end (module_0_)["aniseed/local-fns"] = ((module_0_)["aniseed/local-fns"] or {}) - do end (package.loaded)[name_0_] = module_0_ - _0_ = module_0_ -end local autoload -local function _1_(...) +local function _0_(...) return (require("aniseed.autoload")).autoload(...) end -autoload = _1_ -local function _2_(...) - local ok_3f_0_, val_0_ = nil, nil - local function _2_() - return {autoload("aniseed.core"), autoload("aniseed.fennel"), autoload("aniseed.fs"), autoload("aniseed.nvim")} - end - ok_3f_0_, val_0_ = pcall(_2_) - if ok_3f_0_ then - _0_["aniseed/local-fns"] = {autoload = {a = "aniseed.core", fennel = "aniseed.fennel", fs = "aniseed.fs", nvim = "aniseed.nvim"}} - return val_0_ - else - return print(val_0_) - end +autoload = _0_ +local nvim, fennel, fs, a, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil +local _1_ +do + local mod_0_ = {["aniseed/local-fns"] = {autoload = {a = "aniseed.core", fennel = "aniseed.fennel", fs = "aniseed.fs", nvim = "aniseed.nvim"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.compile"} + package.loaded["aniseed.compile"] = mod_0_ + _1_ = mod_0_ end -local _local_0_ = _2_(...) -local a = _local_0_[1] -local fennel = _local_0_[2] -local fs = _local_0_[3] -local nvim = _local_0_[4] -local _2amodule_2a = _0_ -local _2amodule_name_2a = "aniseed.compile" -do local _ = ({nil, _0_, nil, {{}, nil, nil, nil}})[2] end -local macros_prefix +nvim, fennel, fs, a, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(nvim, "aniseed.nvim"), autoload(fennel, "aniseed.fennel"), autoload(fs, "aniseed.fs"), autoload(a, "aniseed.core"), _1_, "aniseed.compile", "fnl/aniseed/compile.fnl" +local base_path do - local v_0_ - do - local v_0_0 - local function macros_prefix0(code, opts) - local macros_module = "aniseed.macros" - local filename - do - local _3_ = a.get(opts, "filename") - if _3_ then - filename = string.gsub(_3_, (nvim.fn.getcwd() .. fs["path-sep"]), "") - else - filename = _3_ - end - end - local _4_ - if filename then - _4_ = ("\"" .. string.gsub(filename, "\\", "\\\\") .. "\"") - else - _4_ = "nil" - end - return ("(local *file* " .. _4_ .. ")" .. "(require-macros \"" .. macros_module .. "\")\n" .. code) + local _2_ = (debug.getinfo(1, "S")).source + if _2_ then + local _3_ = _2_:gsub("^.", "") + if _3_ then + base_path = _3_:gsub(string.gsub(_2afile_2a, "fnl", "lua"), "") + else + base_path = _3_ end - v_0_0 = macros_prefix0 - _0_["macros-prefix"] = v_0_0 - v_0_ = v_0_0 + else + base_path = _2_ end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["macros-prefix"] = v_0_ - macros_prefix = v_0_ end local str -do - local v_0_ +local function _3_(code, opts) + local fnl = fennel.impl() + local plugins = {"module-system-plugin.fnl"} + local plugins0 do - local v_0_0 - local function str0(code, opts) - local fnl = fennel.impl() - local function _3_() - return fnl.compileString(macros_prefix(code, opts), a.merge({allowedGlobals = false}, opts)) - end - return xpcall(_3_, fnl.traceback) + local tbl_0_ = {} + for _, plugin in ipairs(plugins) do + tbl_0_[(#tbl_0_ + 1)] = fnl.dofile((base_path .. plugin), {env = "_COMPILER", useMetadata = true}) end - v_0_0 = str0 - _0_["str"] = v_0_0 - v_0_ = v_0_0 + plugins0 = tbl_0_ end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["str"] = v_0_ - str = v_0_ + local function _4_() + return fnl.compileString(code, a.merge({allowedGlobals = false, plugins = plugins0}, opts)) + end + return xpcall(_4_, fnl.traceback) end +str = _3_ +_2amodule_2a["str"] = str +_2amodule_2a["aniseed/locals"]["str"] = str local file -do - local v_0_ - do - local v_0_0 - local function file0(src, dest) - local code = a.slurp(src) - local _3_, _4_ = str(code, {filename = src}) - if ((_3_ == false) and (nil ~= _4_)) then - local err = _4_ - return nvim.err_writeln(err) - elseif ((_3_ == true) and (nil ~= _4_)) then - local result = _4_ - fs.mkdirp(fs.basename(dest)) - return a.spit(dest, result) - end - end - v_0_0 = file0 - _0_["file"] = v_0_0 - v_0_ = v_0_0 +local function _4_(src, dest) + local code = a.slurp(src) + local _5_, _6_ = str(code, {filename = src}) + if ((_5_ == false) and (nil ~= _6_)) then + local err = _6_ + return nvim.err_writeln(err) + elseif ((_5_ == true) and (nil ~= _6_)) then + local result = _6_ + fs.mkdirp(fs.basename(dest)) + return a.spit(dest, result) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["file"] = v_0_ - file = v_0_ end +file = _4_ +_2amodule_2a["file"] = file +_2amodule_2a["aniseed/locals"]["file"] = file local glob -do - local v_0_ - do - local v_0_0 - local function glob0(src_expr, src_dir, dest_dir) - for _, path in ipairs(fs.relglob(src_dir, src_expr)) do - if fs["macro-file-path?"](path) then - a.spit((dest_dir .. path), a.slurp((src_dir .. path))) - else - file((src_dir .. path), string.gsub((dest_dir .. path), ".fnl$", ".lua")) - end - end - return nil +local function _5_(src_expr, src_dir, dest_dir) + for _, path in ipairs(fs.relglob(src_dir, src_expr)) do + if fs["macro-file-path?"](path) then + a.spit((dest_dir .. path), a.slurp((src_dir .. path))) + else + file((src_dir .. path), string.gsub((dest_dir .. path), ".fnl$", ".lua")) end - v_0_0 = glob0 - _0_["glob"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["glob"] = v_0_ - glob = v_0_ + return nil end +glob = _5_ +_2amodule_2a["glob"] = glob +_2amodule_2a["aniseed/locals"]["glob"] = glob return nil diff --git a/lua/aniseed/core.lua b/lua/aniseed/core.lua index 47693bb..2b86153 100644 --- a/lua/aniseed/core.lua +++ b/lua/aniseed/core.lua @@ -1,957 +1,541 @@ -local _2afile_2a = "fnl/aniseed/core.fnl" -local _0_ -do - local name_0_ = "aniseed.core" - local module_0_ - do - local x_0_ = package.loaded[name_0_] - if ("table" == type(x_0_)) then - module_0_ = x_0_ - else - module_0_ = {} - end - end - module_0_["aniseed/module"] = name_0_ - module_0_["aniseed/locals"] = ((module_0_)["aniseed/locals"] or {}) - do end (module_0_)["aniseed/local-fns"] = ((module_0_)["aniseed/local-fns"] or {}) - do end (package.loaded)[name_0_] = module_0_ - _0_ = module_0_ -end local autoload -local function _1_(...) +local function _0_(...) return (require("aniseed.autoload")).autoload(...) end -autoload = _1_ -local function _2_(...) - local ok_3f_0_, val_0_ = nil, nil - local function _2_() - return {autoload("aniseed.view")} - end - ok_3f_0_, val_0_ = pcall(_2_) - if ok_3f_0_ then - _0_["aniseed/local-fns"] = {autoload = {view = "aniseed.view"}} - return val_0_ - else - return print(val_0_) - end +autoload = _0_ +local view, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil +local _1_ +do + local mod_0_ = {["aniseed/local-fns"] = {autoload = {view = "aniseed.view"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.core"} + package.loaded["aniseed.core"] = mod_0_ + _1_ = mod_0_ end -local _local_0_ = _2_(...) -local view = _local_0_[1] -local _2amodule_2a = _0_ -local _2amodule_name_2a = "aniseed.core" -do local _ = ({nil, _0_, nil, {{}, nil, nil, nil}})[2] end +view, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(view, "aniseed.view"), _1_, "aniseed.core", "fnl/aniseed/core.fnl" math.randomseed(os.time()) local rand -do - local v_0_ - do - local v_0_0 - local function rand0(n) - return (math.random() * (n or 1)) - end - v_0_0 = rand0 - _0_["rand"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["rand"] = v_0_ - rand = v_0_ +local function _2_(n) + return (math.random() * (n or 1)) end +rand = _2_ +_2amodule_2a["rand"] = rand +_2amodule_2a["aniseed/locals"]["rand"] = rand local string_3f -do - local v_0_ - do - local v_0_0 - local function string_3f0(x) - return ("string" == type(x)) - end - v_0_0 = string_3f0 - _0_["string?"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["string?"] = v_0_ - string_3f = v_0_ +local function _3_(x) + return ("string" == type(x)) end +string_3f = _3_ +_2amodule_2a["string?"] = string_3f +_2amodule_2a["aniseed/locals"]["string?"] = string_3f local nil_3f -do - local v_0_ - do - local v_0_0 - local function nil_3f0(x) - return (nil == x) - end - v_0_0 = nil_3f0 - _0_["nil?"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["nil?"] = v_0_ - nil_3f = v_0_ +local function _4_(x) + return (nil == x) end +nil_3f = _4_ +_2amodule_2a["nil?"] = nil_3f +_2amodule_2a["aniseed/locals"]["nil?"] = nil_3f local table_3f -do - local v_0_ - do - local v_0_0 - local function table_3f0(x) - return ("table" == type(x)) - end - v_0_0 = table_3f0 - _0_["table?"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["table?"] = v_0_ - table_3f = v_0_ +local function _5_(x) + return ("table" == type(x)) end +table_3f = _5_ +_2amodule_2a["table?"] = table_3f +_2amodule_2a["aniseed/locals"]["table?"] = table_3f local count -do - local v_0_ - do - local v_0_0 - local function count0(xs) - if table_3f(xs) then - return table.maxn(xs) - elseif not xs then - return 0 - else - return #xs - end - end - v_0_0 = count0 - _0_["count"] = v_0_0 - v_0_ = v_0_0 +local function _6_(xs) + if table_3f(xs) then + return table.maxn(xs) + elseif not xs then + return 0 + else + return #xs end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["count"] = v_0_ - count = v_0_ end +count = _6_ +_2amodule_2a["count"] = count +_2amodule_2a["aniseed/locals"]["count"] = count local empty_3f -do - local v_0_ - do - local v_0_0 - local function empty_3f0(xs) - return (0 == count(xs)) - end - v_0_0 = empty_3f0 - _0_["empty?"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["empty?"] = v_0_ - empty_3f = v_0_ +local function _7_(xs) + return (0 == count(xs)) end +empty_3f = _7_ +_2amodule_2a["empty?"] = empty_3f +_2amodule_2a["aniseed/locals"]["empty?"] = empty_3f local first -do - local v_0_ - do - local v_0_0 - local function first0(xs) - if xs then - return xs[1] - end - end - v_0_0 = first0 - _0_["first"] = v_0_0 - v_0_ = v_0_0 +local function _8_(xs) + if xs then + return xs[1] end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["first"] = v_0_ - first = v_0_ end +first = _8_ +_2amodule_2a["first"] = first +_2amodule_2a["aniseed/locals"]["first"] = first local second -do - local v_0_ - do - local v_0_0 - local function second0(xs) - if xs then - return xs[2] - end - end - v_0_0 = second0 - _0_["second"] = v_0_0 - v_0_ = v_0_0 +local function _9_(xs) + if xs then + return xs[2] end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["second"] = v_0_ - second = v_0_ end +second = _9_ +_2amodule_2a["second"] = second +_2amodule_2a["aniseed/locals"]["second"] = second local last -do - local v_0_ - do - local v_0_0 - local function last0(xs) - if xs then - return xs[count(xs)] - end - end - v_0_0 = last0 - _0_["last"] = v_0_0 - v_0_ = v_0_0 +local function _10_(xs) + if xs then + return xs[count(xs)] end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["last"] = v_0_ - last = v_0_ end +last = _10_ +_2amodule_2a["last"] = last +_2amodule_2a["aniseed/locals"]["last"] = last local inc -do - local v_0_ - do - local v_0_0 - local function inc0(n) - return (n + 1) - end - v_0_0 = inc0 - _0_["inc"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["inc"] = v_0_ - inc = v_0_ +local function _11_(n) + return (n + 1) end +inc = _11_ +_2amodule_2a["inc"] = inc +_2amodule_2a["aniseed/locals"]["inc"] = inc local dec -do - local v_0_ - do - local v_0_0 - local function dec0(n) - return (n - 1) - end - v_0_0 = dec0 - _0_["dec"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["dec"] = v_0_ - dec = v_0_ +local function _12_(n) + return (n - 1) end +dec = _12_ +_2amodule_2a["dec"] = dec +_2amodule_2a["aniseed/locals"]["dec"] = dec local even_3f -do - local v_0_ - do - local v_0_0 - local function even_3f0(n) - return ((n % 2) == 0) - end - v_0_0 = even_3f0 - _0_["even?"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["even?"] = v_0_ - even_3f = v_0_ +local function _13_(n) + return ((n % 2) == 0) end +even_3f = _13_ +_2amodule_2a["even?"] = even_3f +_2amodule_2a["aniseed/locals"]["even?"] = even_3f local odd_3f -do - local v_0_ - do - local v_0_0 - local function odd_3f0(n) - return not even_3f(n) - end - v_0_0 = odd_3f0 - _0_["odd?"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["odd?"] = v_0_ - odd_3f = v_0_ +local function _14_(n) + return not even_3f(n) end +odd_3f = _14_ +_2amodule_2a["odd?"] = odd_3f +_2amodule_2a["aniseed/locals"]["odd?"] = odd_3f local keys -do - local v_0_ - do - local v_0_0 - local function keys0(t) - local result = {} - if t then - for k, _ in pairs(t) do - table.insert(result, k) - end - end - return result +local function _15_(t) + local result = {} + if t then + for k, _ in pairs(t) do + table.insert(result, k) end - v_0_0 = keys0 - _0_["keys"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["keys"] = v_0_ - keys = v_0_ + return result end +keys = _15_ +_2amodule_2a["keys"] = keys +_2amodule_2a["aniseed/locals"]["keys"] = keys local vals -do - local v_0_ - do - local v_0_0 - local function vals0(t) - local result = {} - if t then - for _, v in pairs(t) do - table.insert(result, v) - end - end - return result +local function _16_(t) + local result = {} + if t then + for _, v in pairs(t) do + table.insert(result, v) end - v_0_0 = vals0 - _0_["vals"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["vals"] = v_0_ - vals = v_0_ + return result end +vals = _16_ +_2amodule_2a["vals"] = vals +_2amodule_2a["aniseed/locals"]["vals"] = vals local kv_pairs -do - local v_0_ - do - local v_0_0 - local function kv_pairs0(t) - local result = {} - if t then - for k, v in pairs(t) do - table.insert(result, {k, v}) - end - end - return result +local function _17_(t) + local result = {} + if t then + for k, v in pairs(t) do + table.insert(result, {k, v}) end - v_0_0 = kv_pairs0 - _0_["kv-pairs"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["kv-pairs"] = v_0_ - kv_pairs = v_0_ + return result end +kv_pairs = _17_ +_2amodule_2a["kv-pairs"] = kv_pairs +_2amodule_2a["aniseed/locals"]["kv-pairs"] = kv_pairs local run_21 -do - local v_0_ - do - local v_0_0 - local function run_210(f, xs) - if xs then - local nxs = count(xs) - if (nxs > 0) then - for i = 1, nxs do - f(xs[i]) - end - return nil - end +local function _18_(f, xs) + if xs then + local nxs = count(xs) + if (nxs > 0) then + for i = 1, nxs do + f(xs[i]) end + return nil end - v_0_0 = run_210 - _0_["run!"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["run!"] = v_0_ - run_21 = v_0_ end +run_21 = _18_ +_2amodule_2a["run!"] = run_21 +_2amodule_2a["aniseed/locals"]["run!"] = run_21 local filter -do - local v_0_ - do - local v_0_0 - local function filter0(f, xs) - local result = {} - local function _3_(x) - if f(x) then - return table.insert(result, x) - end - end - run_21(_3_, xs) - return result +local function _19_(f, xs) + local result = {} + local function _20_(x) + if f(x) then + return table.insert(result, x) end - v_0_0 = filter0 - _0_["filter"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["filter"] = v_0_ - filter = v_0_ + run_21(_20_, xs) + return result end +filter = _19_ +_2amodule_2a["filter"] = filter +_2amodule_2a["aniseed/locals"]["filter"] = filter local map -do - local v_0_ - do - local v_0_0 - local function map0(f, xs) - local result = {} - local function _3_(x) - local mapped = f(x) - local function _4_() - if (0 == select("#", mapped)) then - return nil - else - return mapped - end - end - return table.insert(result, _4_()) +local function _20_(f, xs) + local result = {} + local function _21_(x) + local mapped = f(x) + local function _22_() + if (0 == select("#", mapped)) then + return nil + else + return mapped end - run_21(_3_, xs) - return result end - v_0_0 = map0 - _0_["map"] = v_0_0 - v_0_ = v_0_0 + return table.insert(result, _22_()) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["map"] = v_0_ - map = v_0_ + run_21(_21_, xs) + return result end +map = _20_ +_2amodule_2a["map"] = map +_2amodule_2a["aniseed/locals"]["map"] = map local map_indexed -do - local v_0_ - do - local v_0_0 - local function map_indexed0(f, xs) - return map(f, kv_pairs(xs)) - end - v_0_0 = map_indexed0 - _0_["map-indexed"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["map-indexed"] = v_0_ - map_indexed = v_0_ +local function _21_(f, xs) + return map(f, kv_pairs(xs)) end +map_indexed = _21_ +_2amodule_2a["map-indexed"] = map_indexed +_2amodule_2a["aniseed/locals"]["map-indexed"] = map_indexed local identity -do - local v_0_ - do - local v_0_0 - local function identity0(x) - return x - end - v_0_0 = identity0 - _0_["identity"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["identity"] = v_0_ - identity = v_0_ +local function _22_(x) + return x end +identity = _22_ +_2amodule_2a["identity"] = identity +_2amodule_2a["aniseed/locals"]["identity"] = identity local reduce -do - local v_0_ - do - local v_0_0 - local function reduce0(f, init, xs) - local result = init - local function _3_(x) - result = f(result, x) - return nil - end - run_21(_3_, xs) - return result - end - v_0_0 = reduce0 - _0_["reduce"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["reduce"] = v_0_ - reduce = v_0_ -end +local function _23_(f, init, xs) + local result = init + local function _24_(x) + result = f(result, x) + return nil + end + run_21(_24_, xs) + return result +end +reduce = _23_ +_2amodule_2a["reduce"] = reduce +_2amodule_2a["aniseed/locals"]["reduce"] = reduce local some -do - local v_0_ - do - local v_0_0 - local function some0(f, xs) - local result = nil - local n = 1 - while (nil_3f(result) and (n <= count(xs))) do - local candidate = f(xs[n]) - if candidate then - result = candidate - end - n = inc(n) - end - return result +local function _24_(f, xs) + local result = nil + local n = 1 + while (nil_3f(result) and (n <= count(xs))) do + local candidate = f(xs[n]) + if candidate then + result = candidate end - v_0_0 = some0 - _0_["some"] = v_0_0 - v_0_ = v_0_0 + n = inc(n) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["some"] = v_0_ - some = v_0_ + return result end +some = _24_ +_2amodule_2a["some"] = some +_2amodule_2a["aniseed/locals"]["some"] = some local butlast -do - local v_0_ - do - local v_0_0 - local function butlast0(xs) - local total = count(xs) - local function _4_(_3_) - local _arg_0_ = _3_ - local n = _arg_0_[1] - local v = _arg_0_[2] - return (n ~= total) - end - return map(second, filter(_4_, kv_pairs(xs))) - end - v_0_0 = butlast0 - _0_["butlast"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["butlast"] = v_0_ - butlast = v_0_ -end +local function _25_(xs) + local total = count(xs) + local function _27_(_26_) + local _arg_0_ = _26_ + local n = _arg_0_[1] + local v = _arg_0_[2] + return (n ~= total) + end + return map(second, filter(_27_, kv_pairs(xs))) +end +butlast = _25_ +_2amodule_2a["butlast"] = butlast +_2amodule_2a["aniseed/locals"]["butlast"] = butlast local rest -do - local v_0_ - do - local v_0_0 - local function rest0(xs) - local function _4_(_3_) - local _arg_0_ = _3_ - local n = _arg_0_[1] - local v = _arg_0_[2] - return (n ~= 1) - end - return map(second, filter(_4_, kv_pairs(xs))) - end - v_0_0 = rest0 - _0_["rest"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["rest"] = v_0_ - rest = v_0_ -end +local function _26_(xs) + local function _28_(_27_) + local _arg_0_ = _27_ + local n = _arg_0_[1] + local v = _arg_0_[2] + return (n ~= 1) + end + return map(second, filter(_28_, kv_pairs(xs))) +end +rest = _26_ +_2amodule_2a["rest"] = rest +_2amodule_2a["aniseed/locals"]["rest"] = rest local concat -do - local v_0_ - do - local v_0_0 - local function concat0(...) - local result = {} - local function _3_(xs) - local function _4_(x) - return table.insert(result, x) - end - return run_21(_4_, xs) - end - run_21(_3_, {...}) - return result +local function _27_(...) + local result = {} + local function _28_(xs) + local function _29_(x) + return table.insert(result, x) end - v_0_0 = concat0 - _0_["concat"] = v_0_0 - v_0_ = v_0_0 + return run_21(_29_, xs) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["concat"] = v_0_ - concat = v_0_ + run_21(_28_, {...}) + return result end +concat = _27_ +_2amodule_2a["concat"] = concat +_2amodule_2a["aniseed/locals"]["concat"] = concat local mapcat -do - local v_0_ - do - local v_0_0 - local function mapcat0(f, xs) - return concat(unpack(map(f, xs))) - end - v_0_0 = mapcat0 - _0_["mapcat"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["mapcat"] = v_0_ - mapcat = v_0_ +local function _28_(f, xs) + return concat(unpack(map(f, xs))) end +mapcat = _28_ +_2amodule_2a["mapcat"] = mapcat +_2amodule_2a["aniseed/locals"]["mapcat"] = mapcat local pr_str -do - local v_0_ - do - local v_0_0 - local function pr_str0(...) - local s - local function _3_(x) - return view.serialise(x, {["one-line"] = true}) - end - s = table.concat(map(_3_, {...}), " ") - if (nil_3f(s) or ("" == s)) then - return "nil" - else - return s - end - end - v_0_0 = pr_str0 - _0_["pr-str"] = v_0_0 - v_0_ = v_0_0 +local function _29_(...) + local s + local function _30_(x) + return view.serialise(x, {["one-line"] = true}) + end + s = table.concat(map(_30_, {...}), " ") + if (nil_3f(s) or ("" == s)) then + return "nil" + else + return s end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["pr-str"] = v_0_ - pr_str = v_0_ end +pr_str = _29_ +_2amodule_2a["pr-str"] = pr_str +_2amodule_2a["aniseed/locals"]["pr-str"] = pr_str local str -do - local v_0_ - do - local v_0_0 - local function str0(...) - local function _3_(acc, s) - return (acc .. s) - end - local function _4_(s) - if string_3f(s) then - return s - else - return pr_str(s) - end - end - return reduce(_3_, "", map(_4_, {...})) +local function _30_(...) + local function _31_(acc, s) + return (acc .. s) + end + local function _32_(s) + if string_3f(s) then + return s + else + return pr_str(s) end - v_0_0 = str0 - _0_["str"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["str"] = v_0_ - str = v_0_ + return reduce(_31_, "", map(_32_, {...})) end +str = _30_ +_2amodule_2a["str"] = str +_2amodule_2a["aniseed/locals"]["str"] = str local println -do - local v_0_ - do - local v_0_0 - local function println0(...) - local function _3_(acc, s) - return (acc .. s) - end - local function _5_(_4_) - local _arg_0_ = _4_ - local i = _arg_0_[1] - local s = _arg_0_[2] - if (1 == i) then - return s - else - return (" " .. s) - end - end - local function _6_(s) - if string_3f(s) then - return s - else - return pr_str(s) - end - end - return print(reduce(_3_, "", map_indexed(_5_, map(_6_, {...})))) +local function _31_(...) + local function _32_(acc, s) + return (acc .. s) + end + local function _34_(_33_) + local _arg_0_ = _33_ + local i = _arg_0_[1] + local s = _arg_0_[2] + if (1 == i) then + return s + else + return (" " .. s) end - v_0_0 = println0 - _0_["println"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["println"] = v_0_ - println = v_0_ -end -local pr -do - local v_0_ - do - local v_0_0 - local function pr0(...) - return println(pr_str(...)) + local function _35_(s) + if string_3f(s) then + return s + else + return pr_str(s) end - v_0_0 = pr0 - _0_["pr"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["pr"] = v_0_ - pr = v_0_ + return print(reduce(_32_, "", map_indexed(_34_, map(_35_, {...})))) end -local slurp -do - local v_0_ - do - local v_0_0 - local function slurp0(path, silent_3f) - local _3_, _4_ = io.open(path, "r") - if ((_3_ == nil) and (nil ~= _4_)) then - local msg = _4_ - return nil - elseif (nil ~= _3_) then - local f = _3_ - local content = f:read("*all") - f:close() - return content - end - end - v_0_0 = slurp0 - _0_["slurp"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["slurp"] = v_0_ - slurp = v_0_ +println = _31_ +_2amodule_2a["println"] = println +_2amodule_2a["aniseed/locals"]["println"] = println +local pr +local function _32_(...) + return println(pr_str(...)) end +pr = _32_ +_2amodule_2a["pr"] = pr +_2amodule_2a["aniseed/locals"]["pr"] = pr +local slurp +local function _33_(path, silent_3f) + local _34_, _35_ = io.open(path, "r") + if ((_34_ == nil) and (nil ~= _35_)) then + local msg = _35_ + return nil + elseif (nil ~= _34_) then + local f = _34_ + local content = f:read("*all") + f:close() + return content + end +end +slurp = _33_ +_2amodule_2a["slurp"] = slurp +_2amodule_2a["aniseed/locals"]["slurp"] = slurp local spit -do - local v_0_ - do - local v_0_0 - local function spit0(path, content) - local _3_, _4_ = io.open(path, "w") - if ((_3_ == nil) and (nil ~= _4_)) then - local msg = _4_ - return error(("Could not open file: " .. msg)) - elseif (nil ~= _3_) then - local f = _3_ - f:write(content) - f:close() - return nil - end - end - v_0_0 = spit0 - _0_["spit"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["spit"] = v_0_ - spit = v_0_ -end +local function _34_(path, content) + local _35_, _36_ = io.open(path, "w") + if ((_35_ == nil) and (nil ~= _36_)) then + local msg = _36_ + return error(("Could not open file: " .. msg)) + elseif (nil ~= _35_) then + local f = _35_ + f:write(content) + f:close() + return nil + end +end +spit = _34_ +_2amodule_2a["spit"] = spit +_2amodule_2a["aniseed/locals"]["spit"] = spit local merge_21 -do - local v_0_ - do - local v_0_0 - local function merge_210(base, ...) - local function _3_(acc, m) - if m then - for k, v in pairs(m) do - acc[k] = v - end - end - return acc +local function _35_(base, ...) + local function _36_(acc, m) + if m then + for k, v in pairs(m) do + acc[k] = v end - return reduce(_3_, (base or {}), {...}) end - v_0_0 = merge_210 - _0_["merge!"] = v_0_0 - v_0_ = v_0_0 + return acc end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["merge!"] = v_0_ - merge_21 = v_0_ + return reduce(_36_, (base or {}), {...}) end +merge_21 = _35_ +_2amodule_2a["merge!"] = merge_21 +_2amodule_2a["aniseed/locals"]["merge!"] = merge_21 local merge -do - local v_0_ - do - local v_0_0 - local function merge0(...) - return merge_21({}, ...) - end - v_0_0 = merge0 - _0_["merge"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["merge"] = v_0_ - merge = v_0_ +local function _36_(...) + return merge_21({}, ...) end +merge = _36_ +_2amodule_2a["merge"] = merge +_2amodule_2a["aniseed/locals"]["merge"] = merge local select_keys -do - local v_0_ - do - local v_0_0 - local function select_keys0(t, ks) - if (t and ks) then - local function _3_(acc, k) - if k then - acc[k] = t[k] - end - return acc - end - return reduce(_3_, {}, ks) - else - return {} +local function _37_(t, ks) + if (t and ks) then + local function _38_(acc, k) + if k then + acc[k] = t[k] end + return acc end - v_0_0 = select_keys0 - _0_["select-keys"] = v_0_0 - v_0_ = v_0_0 + return reduce(_38_, {}, ks) + else + return {} end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["select-keys"] = v_0_ - select_keys = v_0_ end +select_keys = _37_ +_2amodule_2a["select-keys"] = select_keys +_2amodule_2a["aniseed/locals"]["select-keys"] = select_keys local get -do - local v_0_ - do - local v_0_0 - local function get0(t, k, d) - local res - if table_3f(t) then - local val = t[k] - if not nil_3f(val) then - res = val - else - res = nil - end - else - res = nil - end - if nil_3f(res) then - return d - else - return res - end +local function _38_(t, k, d) + local res + if table_3f(t) then + local val = t[k] + if not nil_3f(val) then + res = val + else + res = nil end - v_0_0 = get0 - _0_["get"] = v_0_0 - v_0_ = v_0_0 + else + res = nil + end + if nil_3f(res) then + return d + else + return res end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["get"] = v_0_ - get = v_0_ end +get = _38_ +_2amodule_2a["get"] = get +_2amodule_2a["aniseed/locals"]["get"] = get local get_in -do - local v_0_ - do - local v_0_0 - local function get_in0(t, ks, d) - local res - local function _3_(acc, k) - if table_3f(acc) then - return get(acc, k) - end - end - res = reduce(_3_, t, ks) - if nil_3f(res) then - return d - else - return res - end +local function _39_(t, ks, d) + local res + local function _40_(acc, k) + if table_3f(acc) then + return get(acc, k) end - v_0_0 = get_in0 - _0_["get-in"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["get-in"] = v_0_ - get_in = v_0_ -end -local assoc -do - local v_0_ - do - local v_0_0 - local function assoc0(t, ...) - local _let_0_ = {...} - local k = _let_0_[1] - local v = _let_0_[2] - local xs = {(table.unpack or unpack)(_let_0_, 3)} - local rem = count(xs) - local t0 = (t or {}) - if odd_3f(rem) then - error("assoc expects even number of arguments after table, found odd number") - end - if not nil_3f(k) then - t0[k] = v - end - if (rem > 0) then - assoc0(t0, unpack(xs)) - end - return t0 - end - v_0_0 = assoc0 - _0_["assoc"] = v_0_0 - v_0_ = v_0_0 + res = reduce(_40_, t, ks) + if nil_3f(res) then + return d + else + return res end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["assoc"] = v_0_ - assoc = v_0_ end +get_in = _39_ +_2amodule_2a["get-in"] = get_in +_2amodule_2a["aniseed/locals"]["get-in"] = get_in +local assoc +local function _40_(t, ...) + local _let_0_ = {...} + local k = _let_0_[1] + local v = _let_0_[2] + local xs = {(table.unpack or unpack)(_let_0_, 3)} + local rem = count(xs) + local t0 = (t or {}) + if odd_3f(rem) then + error("assoc expects even number of arguments after table, found odd number") + end + if not nil_3f(k) then + t0[k] = v + end + if (rem > 0) then + assoc(t0, unpack(xs)) + end + return t0 +end +assoc = _40_ +_2amodule_2a["assoc"] = assoc +_2amodule_2a["aniseed/locals"]["assoc"] = assoc local assoc_in -do - local v_0_ - do - local v_0_0 - local function assoc_in0(t, ks, v) - local path = butlast(ks) - local final = last(ks) - local t0 = (t or {}) - local function _3_(acc, k) - local step = get(acc, k) - if nil_3f(step) then - return get(assoc(acc, k, {}), k) - else - return step - end - end - assoc(reduce(_3_, t0, path), final, v) - return t0 +local function _41_(t, ks, v) + local path = butlast(ks) + local final = last(ks) + local t0 = (t or {}) + local function _42_(acc, k) + local step = get(acc, k) + if nil_3f(step) then + return get(assoc(acc, k, {}), k) + else + return step end - v_0_0 = assoc_in0 - _0_["assoc-in"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["assoc-in"] = v_0_ - assoc_in = v_0_ + assoc(reduce(_42_, t0, path), final, v) + return t0 end +assoc_in = _41_ +_2amodule_2a["assoc-in"] = assoc_in +_2amodule_2a["aniseed/locals"]["assoc-in"] = assoc_in local update -do - local v_0_ - do - local v_0_0 - local function update0(t, k, f) - return assoc(t, k, f(get(t, k))) - end - v_0_0 = update0 - _0_["update"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["update"] = v_0_ - update = v_0_ +local function _42_(t, k, f) + return assoc(t, k, f(get(t, k))) end +update = _42_ +_2amodule_2a["update"] = update +_2amodule_2a["aniseed/locals"]["update"] = update local update_in -do - local v_0_ - do - local v_0_0 - local function update_in0(t, ks, f) - return assoc_in(t, ks, f(get_in(t, ks))) - end - v_0_0 = update_in0 - _0_["update-in"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["update-in"] = v_0_ - update_in = v_0_ +local function _43_(t, ks, f) + return assoc_in(t, ks, f(get_in(t, ks))) end +update_in = _43_ +_2amodule_2a["update-in"] = update_in +_2amodule_2a["aniseed/locals"]["update-in"] = update_in local constantly -do - local v_0_ - do - local v_0_0 - local function constantly0(v) - local function _3_() - return v - end - return _3_ - end - v_0_0 = constantly0 - _0_["constantly"] = v_0_0 - v_0_ = v_0_0 +local function _44_(v) + local function _45_() + return v end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["constantly"] = v_0_ - constantly = v_0_ + return _45_ end +constantly = _44_ +_2amodule_2a["constantly"] = constantly +_2amodule_2a["aniseed/locals"]["constantly"] = constantly return nil diff --git a/lua/aniseed/deps/fennel.lua b/lua/aniseed/deps/fennel.lua index 520dc01..c346cea 100644 --- a/lua/aniseed/deps/fennel.lua +++ b/lua/aniseed/deps/fennel.lua @@ -965,10 +965,28 @@ package.preload["aniseed.fennel.specials"] = package.preload["aniseed.fennel.spe doc_special("fn", {"name?", "args", "docstring?", "..."}, "Function syntax. May optionally include a name and docstring.\nIf a name is provided, the function will be bound in the current scope.\nWhen called with the wrong number of args, excess args will be discarded\nand lacking args will be nil, use lambda for arity-checked functions.", true) SPECIALS.lua = function(ast, _, parent) compiler.assert(((#ast == 2) or (#ast == 3)), "expected 1 or 2 arguments", ast) - if (ast[2] ~= nil) then + local _1_ + do + local _0_0 = utils["sym?"](ast[2]) + if _0_0 then + _1_ = utils.deref(_0_0) + else + _1_ = _0_0 + end + end + if ("nil" ~= _1_) then table.insert(parent, {ast = ast, leaf = tostring(ast[2])}) end - if (ast[3] ~= nil) then + local _2_ + do + local _1_0 = utils["sym?"](ast[3]) + if _1_0 then + _2_ = utils.deref(_1_0) + else + _2_ = _1_0 + end + end + if ("nil" ~= _2_) then return tostring(ast[3]) end end @@ -1894,7 +1912,7 @@ package.preload["aniseed.fennel.compiler"] = package.preload["aniseed.fennel.com else _0_ = 0 end - return {autogensyms = setmetatable({}, {__index = (parent0 and parent0.autogensyms)}), depth = _0_, gensyms = setmetatable({}, {__index = (parent0 and parent0.gensyms)}), hashfn = (parent0 and parent0.hashfn), includes = setmetatable({}, {__index = (parent0 and parent0.includes)}), macros = setmetatable({}, {__index = (parent0 and parent0.macros)}), manglings = setmetatable({}, {__index = (parent0 and parent0.manglings)}), parent = parent0, refedglobals = setmetatable({}, {__index = (parent0 and parent0.refedglobals)}), specials = setmetatable({}, {__index = (parent0 and parent0.specials)}), symmeta = setmetatable({}, {__index = (parent0 and parent0.symmeta)}), unmanglings = setmetatable({}, {__index = (parent0 and parent0.unmanglings)}), vararg = (parent0 and parent0.vararg)} + return {autogensyms = setmetatable({}, {__index = (parent0 and parent0.autogensyms)}), depth = _0_, gensyms = setmetatable({}, {__index = (parent0 and parent0.gensyms)}), hashfn = (parent0 and parent0.hashfn), includes = setmetatable({}, {__index = (parent0 and parent0.includes)}), macros = setmetatable({}, {__index = (parent0 and parent0.macros)}), manglings = setmetatable({}, {__index = (parent0 and parent0.manglings)}), module = (parent0 and parent0.module), parent = parent0, refedglobals = setmetatable({}, {__index = (parent0 and parent0.refedglobals)}), specials = setmetatable({}, {__index = (parent0 and parent0.specials)}), symmeta = setmetatable({}, {__index = (parent0 and parent0.symmeta)}), unmanglings = setmetatable({}, {__index = (parent0 and parent0.unmanglings)}), vararg = (parent0 and parent0.vararg)} end local function assert_msg(ast, msg) local ast_tbl = nil @@ -2402,7 +2420,15 @@ package.preload["aniseed.fennel.compiler"] = package.preload["aniseed.fennel.com return handle_compile_opts({utils.expr(call, "statement")}, parent, opts, ast) end local function compile_call(ast, scope, parent, opts, compile1) - utils.hook("call", ast, scope) + do + local opts0 = nil + do + local _0_0 = utils.copy(opts) + _0_0["filename"] = utils.root.options.filename + opts0 = _0_0 + end + utils.hook("call", ast, scope, parent, opts0, compile1) + end local len = #ast local first = ast[1] local multi_sym_parts = utils["multi-sym?"](first) @@ -3279,7 +3305,7 @@ package.preload["aniseed.fennel.parser"] = package.preload["aniseed.fennel.parse end end local function escape_char(c) - return ({nil, nil, nil, nil, nil, nil, "\\a", "\\b", "\\t", "\\n", "\\v", "\\f", "\\r"})[c:byte()] + return ({[10] = "\\n", [11] = "\\v", [12] = "\\f", [13] = "\\r", [7] = "\\a", [8] = "\\b", [9] = "\\t"})[c:byte()] end local function parse_string() table.insert(stack, {closer = 34}) diff --git a/lua/aniseed/env.lua b/lua/aniseed/env.lua index 56767bb..9163f02 100644 --- a/lua/aniseed/env.lua +++ b/lua/aniseed/env.lua @@ -1,108 +1,57 @@ -local _2afile_2a = "fnl/aniseed/env.fnl" -local _0_ -do - local name_0_ = "aniseed.env" - local module_0_ - do - local x_0_ = package.loaded[name_0_] - if ("table" == type(x_0_)) then - module_0_ = x_0_ - else - module_0_ = {} - end - end - module_0_["aniseed/module"] = name_0_ - module_0_["aniseed/locals"] = ((module_0_)["aniseed/locals"] or {}) - do end (module_0_)["aniseed/local-fns"] = ((module_0_)["aniseed/local-fns"] or {}) - do end (package.loaded)[name_0_] = module_0_ - _0_ = module_0_ -end local autoload -local function _1_(...) +local function _0_(...) return (require("aniseed.autoload")).autoload(...) end -autoload = _1_ -local function _2_(...) - local ok_3f_0_, val_0_ = nil, nil - local function _2_() - return {autoload("aniseed.compile"), autoload("aniseed.fennel"), autoload("aniseed.fs"), autoload("aniseed.nvim")} - end - ok_3f_0_, val_0_ = pcall(_2_) - if ok_3f_0_ then - _0_["aniseed/local-fns"] = {autoload = {compile = "aniseed.compile", fennel = "aniseed.fennel", fs = "aniseed.fs", nvim = "aniseed.nvim"}} - return val_0_ - else - return print(val_0_) - end -end -local _local_0_ = _2_(...) -local compile = _local_0_[1] -local fennel = _local_0_[2] -local fs = _local_0_[3] -local nvim = _local_0_[4] -local _2amodule_2a = _0_ -local _2amodule_name_2a = "aniseed.env" -do local _ = ({nil, _0_, nil, {{}, nil, nil, nil}})[2] end -local config_dir +autoload = _0_ +local compile, fennel, fs, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil +local _1_ do - local v_0_ = nvim.fn.stdpath("config") - local t_0_ = (_0_)["aniseed/locals"] - t_0_["config-dir"] = v_0_ - config_dir = v_0_ + local mod_0_ = {["aniseed/local-fns"] = {autoload = {compile = "aniseed.compile", fennel = "aniseed.fennel", fs = "aniseed.fs", nvim = "aniseed.nvim"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.env"} + package.loaded["aniseed.env"] = mod_0_ + _1_ = mod_0_ end +compile, fennel, fs, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(compile, "aniseed.compile"), autoload(fennel, "aniseed.fennel"), autoload(fs, "aniseed.fs"), autoload(nvim, "aniseed.nvim"), _1_, "aniseed.env", "fnl/aniseed/env.fnl" +local config_dir = nvim.fn.stdpath("config") +do end (_2amodule_2a)["aniseed/locals"]["config-dir"] = config_dir local quiet_require -do - local v_0_ - local function quiet_require0(m) - local ok_3f, err = nil, nil - local function _3_() - return require(m) - end - ok_3f, err = pcall(_3_) - if (not ok_3f and not err:find(("module '" .. m .. "' not found"))) then - return nvim.ex.echoerr(err) - end +local function _2_(m) + local ok_3f, err = nil, nil + local function _3_() + return require(m) + end + ok_3f, err = pcall(_3_) + if (not ok_3f and not err:find(("module '" .. m .. "' not found"))) then + return nvim.ex.echoerr(err) end - v_0_ = quiet_require0 - local t_0_ = (_0_)["aniseed/locals"] - t_0_["quiet-require"] = v_0_ - quiet_require = v_0_ end +quiet_require = _2_ +_2amodule_2a["aniseed/locals"]["quiet-require"] = quiet_require local init -do - local v_0_ - do - local v_0_0 - local function init0(opts) - local opts0 - if ("table" == type(opts)) then - opts0 = opts - else - opts0 = {} - end - local glob_expr = "**/*.fnl" - local fnl_dir = (opts0.input or (config_dir .. fs["path-sep"] .. "fnl")) - local lua_dir = (opts0.output or (config_dir .. fs["path-sep"] .. "lua")) - package.path = (package.path .. ";" .. lua_dir .. fs["path-sep"] .. "?.lua") - local function _4_(path) - if fs["macro-file-path?"](path) then - return path - else - return string.gsub(path, ".fnl$", ".lua") - end - end - if (((false ~= opts0.compile) or os.getenv("ANISEED_ENV_COMPILE")) and fs["glob-dir-newer?"](fnl_dir, lua_dir, glob_expr, _4_)) then - fennel["add-path"]((fnl_dir .. fs["path-sep"] .. "?.fnl")) - compile.glob(glob_expr, fnl_dir, lua_dir, opts0) - end - return quiet_require((opts0.module or "init")) +local function _3_(opts) + local opts0 + if ("table" == type(opts)) then + opts0 = opts + else + opts0 = {} + end + local glob_expr = "**/*.fnl" + local fnl_dir = (opts0.input or (config_dir .. fs["path-sep"] .. "fnl")) + local lua_dir = (opts0.output or (config_dir .. fs["path-sep"] .. "lua")) + package.path = (package.path .. ";" .. lua_dir .. fs["path-sep"] .. "?.lua") + local function _5_(path) + if fs["macro-file-path?"](path) then + return path + else + return string.gsub(path, ".fnl$", ".lua") end - v_0_0 = init0 - _0_["init"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["init"] = v_0_ - init = v_0_ + if (((false ~= opts0.compile) or os.getenv("ANISEED_ENV_COMPILE")) and fs["glob-dir-newer?"](fnl_dir, lua_dir, glob_expr, _5_)) then + fennel["add-path"]((fnl_dir .. fs["path-sep"] .. "?.fnl")) + compile.glob(glob_expr, fnl_dir, lua_dir, opts0) + end + return quiet_require((opts0.module or "init")) end +init = _3_ +_2amodule_2a["init"] = init +_2amodule_2a["aniseed/locals"]["init"] = init return nil diff --git a/lua/aniseed/eval.lua b/lua/aniseed/eval.lua index 2e40a5b..6bb1ba9 100644 --- a/lua/aniseed/eval.lua +++ b/lua/aniseed/eval.lua @@ -1,67 +1,25 @@ -local _2afile_2a = "fnl/aniseed/eval.fnl" -local _0_ -do - local name_0_ = "aniseed.eval" - local module_0_ - do - local x_0_ = package.loaded[name_0_] - if ("table" == type(x_0_)) then - module_0_ = x_0_ - else - module_0_ = {} - end - end - module_0_["aniseed/module"] = name_0_ - module_0_["aniseed/locals"] = ((module_0_)["aniseed/locals"] or {}) - do end (module_0_)["aniseed/local-fns"] = ((module_0_)["aniseed/local-fns"] or {}) - do end (package.loaded)[name_0_] = module_0_ - _0_ = module_0_ -end local autoload -local function _1_(...) +local function _0_(...) return (require("aniseed.autoload")).autoload(...) end -autoload = _1_ -local function _2_(...) - local ok_3f_0_, val_0_ = nil, nil - local function _2_() - return {autoload("aniseed.core"), autoload("aniseed.compile"), autoload("aniseed.fennel"), autoload("aniseed.fs"), autoload("aniseed.nvim")} - end - ok_3f_0_, val_0_ = pcall(_2_) - if ok_3f_0_ then - _0_["aniseed/local-fns"] = {autoload = {a = "aniseed.core", compile = "aniseed.compile", fennel = "aniseed.fennel", fs = "aniseed.fs", nvim = "aniseed.nvim"}} - return val_0_ - else - return print(val_0_) - end +autoload = _0_ +local compile, fennel, fs, nvim, a, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil, nil +local _1_ +do + local mod_0_ = {["aniseed/local-fns"] = {autoload = {a = "aniseed.core", compile = "aniseed.compile", fennel = "aniseed.fennel", fs = "aniseed.fs", nvim = "aniseed.nvim"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.eval"} + package.loaded["aniseed.eval"] = mod_0_ + _1_ = mod_0_ end -local _local_0_ = _2_(...) -local a = _local_0_[1] -local compile = _local_0_[2] -local fennel = _local_0_[3] -local fs = _local_0_[4] -local nvim = _local_0_[5] -local _2amodule_2a = _0_ -local _2amodule_name_2a = "aniseed.eval" -do local _ = ({nil, _0_, nil, {{}, nil, nil, nil}})[2] end +compile, fennel, fs, nvim, a, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(compile, "aniseed.compile"), autoload(fennel, "aniseed.fennel"), autoload(fs, "aniseed.fs"), autoload(nvim, "aniseed.nvim"), autoload(a, "aniseed.core"), _1_, "aniseed.eval", "fnl/aniseed/eval.fnl" local str -do - local v_0_ - do - local v_0_0 - local function str0(code, opts) - local fnl = fennel.impl() - local function _3_() - return fnl.eval(compile["macros-prefix"](code, opts), a.merge({["compiler-env"] = _G}, opts)) - end - return xpcall(_3_, fnl.traceback) - end - v_0_0 = str0 - _0_["str"] = v_0_0 - v_0_ = v_0_0 +local function _2_(code, opts) + local fnl = fennel.impl() + local function _3_() + return fnl.eval(compile["macros-prefix"](code, opts), a.merge({["compiler-env"] = _G}, opts)) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["str"] = v_0_ - str = v_0_ + return xpcall(_3_, fnl.traceback) end +str = _2_ +_2amodule_2a["str"] = str +_2amodule_2a["aniseed/locals"]["str"] = str return nil diff --git a/lua/aniseed/fennel.lua b/lua/aniseed/fennel.lua index 5ec7c2f..dd39e35 100644 --- a/lua/aniseed/fennel.lua +++ b/lua/aniseed/fennel.lua @@ -1,112 +1,50 @@ -local _2afile_2a = "fnl/aniseed/fennel.fnl" -local _0_ -do - local name_0_ = "aniseed.fennel" - local module_0_ - do - local x_0_ = package.loaded[name_0_] - if ("table" == type(x_0_)) then - module_0_ = x_0_ - else - module_0_ = {} - end - end - module_0_["aniseed/module"] = name_0_ - module_0_["aniseed/locals"] = ((module_0_)["aniseed/locals"] or {}) - do end (module_0_)["aniseed/local-fns"] = ((module_0_)["aniseed/local-fns"] or {}) - do end (package.loaded)[name_0_] = module_0_ - _0_ = module_0_ -end local autoload -local function _1_(...) +local function _0_(...) return (require("aniseed.autoload")).autoload(...) end -autoload = _1_ -local function _2_(...) - local ok_3f_0_, val_0_ = nil, nil - local function _2_() - return {autoload("aniseed.fs"), autoload("aniseed.nvim")} - end - ok_3f_0_, val_0_ = pcall(_2_) - if ok_3f_0_ then - _0_["aniseed/local-fns"] = {autoload = {fs = "aniseed.fs", nvim = "aniseed.nvim"}} - return val_0_ - else - return print(val_0_) - end -end -local _local_0_ = _2_(...) -local fs = _local_0_[1] -local nvim = _local_0_[2] -local _2amodule_2a = _0_ -local _2amodule_name_2a = "aniseed.fennel" -do local _ = ({nil, _0_, nil, {{}, nil, nil, nil}})[2] end -local sync_rtp +autoload = _0_ +local fs, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil +local _1_ do - local v_0_ - do - local v_0_0 - local function sync_rtp0(compiler) - local sep = fs["path-sep"] - local fnl_suffix = (sep .. "fnl" .. sep .. "?.fnl") - local rtp = nvim.o.runtimepath - local fnl_path = (rtp:gsub(",", (fnl_suffix .. ";")) .. fnl_suffix) - local lua_path = fnl_path:gsub((sep .. "fnl" .. sep), (sep .. "lua" .. sep)) - do end (compiler)["path"] = (fnl_path .. ";" .. lua_path) - return nil - end - v_0_0 = sync_rtp0 - _0_["sync-rtp"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["sync-rtp"] = v_0_ - sync_rtp = v_0_ + local mod_0_ = {["aniseed/local-fns"] = {autoload = {fs = "aniseed.fs", nvim = "aniseed.nvim"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.fennel"} + package.loaded["aniseed.fennel"] = mod_0_ + _1_ = mod_0_ end -local state -do - local v_0_ = {["compiler-loaded?"] = false} - local t_0_ = (_0_)["aniseed/locals"] - t_0_["state"] = v_0_ - state = v_0_ +fs, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(fs, "aniseed.fs"), autoload(nvim, "aniseed.nvim"), _1_, "aniseed.fennel", "fnl/aniseed/fennel.fnl" +local sync_rtp +local function _2_(compiler) + local sep = fs["path-sep"] + local fnl_suffix = (sep .. "fnl" .. sep .. "?.fnl") + local rtp = nvim.o.runtimepath + local fnl_path = (rtp:gsub(",", (fnl_suffix .. ";")) .. fnl_suffix) + local lua_path = fnl_path:gsub((sep .. "fnl" .. sep), (sep .. "lua" .. sep)) + do end (compiler)["path"] = (fnl_path .. ";" .. lua_path) + return nil end +sync_rtp = _2_ +_2amodule_2a["sync-rtp"] = sync_rtp +_2amodule_2a["aniseed/locals"]["sync-rtp"] = sync_rtp +local state = {["compiler-loaded?"] = false} +_2amodule_2a["aniseed/locals"]["state"] = state local impl -do - local v_0_ - do - local v_0_0 - local function impl0() - local compiler = require("aniseed.deps.fennel") - if not state["compiler-loaded?"] then - state["compiler-loaded?"] = true - sync_rtp(compiler) - end - return compiler - end - v_0_0 = impl0 - _0_["impl"] = v_0_0 - v_0_ = v_0_0 +local function _3_() + local compiler = require("aniseed.deps.fennel") + if not state["compiler-loaded?"] then + state["compiler-loaded?"] = true + sync_rtp(compiler) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["impl"] = v_0_ - impl = v_0_ + return compiler end +impl = _3_ +_2amodule_2a["impl"] = impl +_2amodule_2a["aniseed/locals"]["impl"] = impl local add_path -do - local v_0_ - do - local v_0_0 - local function add_path0(path) - local fnl = impl() - do end (fnl)["path"] = (fnl.path .. ";" .. path) - return nil - end - v_0_0 = add_path0 - _0_["add-path"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["add-path"] = v_0_ - add_path = v_0_ +local function _4_(path) + local fnl = impl() + do end (fnl)["path"] = (fnl.path .. ";" .. path) + return nil end +add_path = _4_ +_2amodule_2a["add-path"] = add_path +_2amodule_2a["aniseed/locals"]["add-path"] = add_path return nil diff --git a/lua/aniseed/fs.lua b/lua/aniseed/fs.lua index d3b667e..616c56b 100644 --- a/lua/aniseed/fs.lua +++ b/lua/aniseed/fs.lua @@ -1,154 +1,70 @@ -local _2afile_2a = "fnl/aniseed/fs.fnl" -local _0_ -do - local name_0_ = "aniseed.fs" - local module_0_ - do - local x_0_ = package.loaded[name_0_] - if ("table" == type(x_0_)) then - module_0_ = x_0_ - else - module_0_ = {} - end - end - module_0_["aniseed/module"] = name_0_ - module_0_["aniseed/locals"] = ((module_0_)["aniseed/locals"] or {}) - do end (module_0_)["aniseed/local-fns"] = ((module_0_)["aniseed/local-fns"] or {}) - do end (package.loaded)[name_0_] = module_0_ - _0_ = module_0_ -end local autoload -local function _1_(...) +local function _0_(...) return (require("aniseed.autoload")).autoload(...) end -autoload = _1_ -local function _2_(...) - local ok_3f_0_, val_0_ = nil, nil - local function _2_() - return {autoload("aniseed.core"), autoload("aniseed.nvim")} - end - ok_3f_0_, val_0_ = pcall(_2_) - if ok_3f_0_ then - _0_["aniseed/local-fns"] = {autoload = {a = "aniseed.core", nvim = "aniseed.nvim"}} - return val_0_ - else - return print(val_0_) - end +autoload = _0_ +local a, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil +local _1_ +do + local mod_0_ = {["aniseed/local-fns"] = {autoload = {a = "aniseed.core", nvim = "aniseed.nvim"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.fs"} + package.loaded["aniseed.fs"] = mod_0_ + _1_ = mod_0_ end -local _local_0_ = _2_(...) -local a = _local_0_[1] -local nvim = _local_0_[2] -local _2amodule_2a = _0_ -local _2amodule_name_2a = "aniseed.fs" -do local _ = ({nil, _0_, nil, {{}, nil, nil, nil}})[2] end +a, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(a, "aniseed.core"), autoload(nvim, "aniseed.nvim"), _1_, "aniseed.fs", "fnl/aniseed/fs.fnl" local path_sep do - local v_0_ - do - local v_0_0 - do - local os = string.lower(jit.os) - if (("linux" == os) or ("osx" == os) or ("bsd" == os)) then - v_0_0 = "/" - else - v_0_0 = "\\" - end - end - _0_["path-sep"] = v_0_0 - v_0_ = v_0_0 + local os = string.lower(jit.os) + if (("linux" == os) or ("osx" == os) or ("bsd" == os)) then + path_sep = "/" + else + path_sep = "\\" end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["path-sep"] = v_0_ - path_sep = v_0_ end +_2amodule_2a["path-sep"] = path_sep +_2amodule_2a["aniseed/locals"]["path-sep"] = path_sep local basename -do - local v_0_ - do - local v_0_0 - local function basename0(path) - return nvim.fn.fnamemodify(path, ":h") - end - v_0_0 = basename0 - _0_["basename"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["basename"] = v_0_ - basename = v_0_ +local function _2_(path) + return nvim.fn.fnamemodify(path, ":h") end +basename = _2_ +_2amodule_2a["basename"] = basename +_2amodule_2a["aniseed/locals"]["basename"] = basename local mkdirp -do - local v_0_ - do - local v_0_0 - local function mkdirp0(dir) - return nvim.fn.mkdir(dir, "p") - end - v_0_0 = mkdirp0 - _0_["mkdirp"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["mkdirp"] = v_0_ - mkdirp = v_0_ +local function _3_(dir) + return nvim.fn.mkdir(dir, "p") end +mkdirp = _3_ +_2amodule_2a["mkdirp"] = mkdirp +_2amodule_2a["aniseed/locals"]["mkdirp"] = mkdirp local relglob -do - local v_0_ - do - local v_0_0 - local function relglob0(dir, expr) - local dir_len = a.inc(string.len(dir)) - local function _3_(_241) - return string.sub(_241, dir_len) - end - return a.map(_3_, nvim.fn.globpath(dir, expr, true, true)) - end - v_0_0 = relglob0 - _0_["relglob"] = v_0_0 - v_0_ = v_0_0 +local function _4_(dir, expr) + local dir_len = a.inc(string.len(dir)) + local function _5_(_241) + return string.sub(_241, dir_len) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["relglob"] = v_0_ - relglob = v_0_ + return a.map(_5_, nvim.fn.globpath(dir, expr, true, true)) end +relglob = _4_ +_2amodule_2a["relglob"] = relglob +_2amodule_2a["aniseed/locals"]["relglob"] = relglob local glob_dir_newer_3f -do - local v_0_ - do - local v_0_0 - local function glob_dir_newer_3f0(a_dir, b_dir, expr, b_dir_path_fn) - local newer_3f = false - for _, path in ipairs(relglob(a_dir, expr)) do - if (nvim.fn.getftime((a_dir .. path)) > nvim.fn.getftime((b_dir .. b_dir_path_fn(path)))) then - newer_3f = true - end - end - return newer_3f +local function _5_(a_dir, b_dir, expr, b_dir_path_fn) + local newer_3f = false + for _, path in ipairs(relglob(a_dir, expr)) do + if (nvim.fn.getftime((a_dir .. path)) > nvim.fn.getftime((b_dir .. b_dir_path_fn(path)))) then + newer_3f = true end - v_0_0 = glob_dir_newer_3f0 - _0_["glob-dir-newer?"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["glob-dir-newer?"] = v_0_ - glob_dir_newer_3f = v_0_ + return newer_3f end +glob_dir_newer_3f = _5_ +_2amodule_2a["glob-dir-newer?"] = glob_dir_newer_3f +_2amodule_2a["aniseed/locals"]["glob-dir-newer?"] = glob_dir_newer_3f local macro_file_path_3f -do - local v_0_ - do - local v_0_0 - local function macro_file_path_3f0(path) - return string.match(path, "macros.fnl$") - end - v_0_0 = macro_file_path_3f0 - _0_["macro-file-path?"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["macro-file-path?"] = v_0_ - macro_file_path_3f = v_0_ +local function _6_(path) + return string.match(path, "macros.fnl$") end +macro_file_path_3f = _6_ +_2amodule_2a["macro-file-path?"] = macro_file_path_3f +_2amodule_2a["aniseed/locals"]["macro-file-path?"] = macro_file_path_3f return nil diff --git a/lua/aniseed/macros.fnl b/lua/aniseed/macros.fnl deleted file mode 100644 index 1e5032e..0000000 --- a/lua/aniseed/macros.fnl +++ /dev/null @@ -1,144 +0,0 @@ -;; All of Aniseed's macros in one place. -;; Can't be compiled to Lua directly. - -;; Automatically loaded through require-macros for all Aniseed based evaluations. - -(local module-sym (gensym)) - -(fn sorted-each [f x] - (let [acc []] - (each [k v (pairs x)] - (table.insert acc [k v])) - (table.sort - acc - (fn [a b] - (< (. a 1) (. b 1)))) - (each [_ [k v] (ipairs acc)] - (f k v)))) - -(fn module [name new-local-fns initial-mod] - `(-> [(local ,module-sym - (let [name# ,(tostring name) - module# (let [x# (. package.loaded name#)] - (if (= :table (type x#)) - x# - ,(or initial-mod {})))] - (tset module# :aniseed/module name#) - (tset module# :aniseed/locals (or (. module# :aniseed/locals) {})) - (tset module# :aniseed/local-fns (or (. module# :aniseed/local-fns) {})) - (tset package.loaded name# module#) - module#)) - - ,module-sym - - ;; Meta! Autoload the autoload function, so it's only loaded when used. - (local ,(sym :autoload) - (fn [...] ((. (require :aniseed.autoload) :autoload) ...))) - - ,(let [aliases [] - vals [] - effects [] - pkg (let [x (. package.loaded (tostring name))] - (when (= :table (type x)) - x)) - locals (-?> pkg (. :aniseed/locals)) - local-fns (or (and (not new-local-fns) - (?. pkg :aniseed/local-fns)) - {})] - - (when new-local-fns - (each [action binds (pairs new-local-fns)] - (let [action-str (tostring action) - current (or (. local-fns action-str) {})] - (tset local-fns action-str current) - (each [alias module (pairs binds)] - (if (= :number (type alias)) - (tset current (tostring module) true) - (tset current (tostring alias) (tostring module))))))) - - (sorted-each - (fn [action binds] - (sorted-each - (fn [alias-or-val val] - (if (= true val) - - ;; {require-macros [bar]} - (table.insert effects `(,(sym action) ,alias-or-val)) - - ;; {require {foo bar}} - (do - (table.insert aliases (sym alias-or-val)) - (table.insert vals `(,(sym action) ,val))))) - - binds)) - local-fns) - - (when locals - (sorted-each - (fn [alias val] - (table.insert aliases (sym alias)) - (table.insert vals `(. ,module-sym :aniseed/locals ,alias))) - locals)) - - `[,effects - (local ,aliases - (let [(ok?# val#) - (pcall - (fn [] ,vals))] - (if ok?# - (do - (tset ,module-sym :aniseed/local-fns ,local-fns) - val#) - (print val#)))) - (local ,(sym "*module*") ,module-sym) - (local ,(sym "*module-name*") ,(tostring name))])] - (. 2))) - -(fn def- [name value] - `(local ,name - (let [v# ,value - t# (. ,module-sym :aniseed/locals)] - (tset t# ,(tostring name) v#) - v#))) - -(fn def [name value] - `(def- ,name - (do - (let [v# ,value] - (tset ,module-sym ,(tostring name) v#) - v#)))) - -(fn defn- [name ...] - `(def- ,name (fn ,name ,...))) - -(fn defn [name ...] - `(def ,name (fn ,name ,...))) - -(fn defonce- [name value] - `(def- ,name - (or (. ,module-sym :aniseed/locals ,(tostring name)) - ,value))) - -(fn defonce [name value] - `(def ,name - (or (. ,module-sym ,(tostring name)) - ,value))) - -(fn deftest [name ...] - `(let [tests# (or (. ,module-sym :aniseed/tests) {})] - (tset tests# ,(tostring name) (fn [,(sym :t)] ,...)) - (tset ,module-sym :aniseed/tests tests#))) - -(fn time [...] - `(let [start# (vim.loop.hrtime) - result# (do ,...) - end# (vim.loop.hrtime)] - (print (.. "Elapsed time: " (/ (- end# start#) 1000000) " msecs")) - result#)) - -{:module module - :def- def- :def def - :defn- defn- :defn defn - :defonce- defonce- :defonce defonce - :deftest deftest - :time time} diff --git a/lua/aniseed/nvim.lua b/lua/aniseed/nvim.lua index 050d67c..1389ee4 100644 --- a/lua/aniseed/nvim.lua +++ b/lua/aniseed/nvim.lua @@ -1,41 +1,9 @@ -local _2afile_2a = "fnl/aniseed/nvim.fnl" +local _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil local _0_ do - local name_0_ = "aniseed.nvim" - local module_0_ - do - local x_0_ = package.loaded[name_0_] - if ("table" == type(x_0_)) then - module_0_ = x_0_ - else - module_0_ = require("aniseed.deps.nvim") - end - end - module_0_["aniseed/module"] = name_0_ - module_0_["aniseed/locals"] = ((module_0_)["aniseed/locals"] or {}) - do end (module_0_)["aniseed/local-fns"] = ((module_0_)["aniseed/local-fns"] or {}) - do end (package.loaded)[name_0_] = module_0_ - _0_ = module_0_ + local mod_0_ = require("aniseed.deps.nvim") + do end (package.loaded)["aniseed.nvim"] = mod_0_ + _0_ = mod_0_ end -local autoload -local function _1_(...) - return (require("aniseed.autoload")).autoload(...) -end -autoload = _1_ -local function _2_(...) - local ok_3f_0_, val_0_ = nil, nil - local function _2_() - return {} - end - ok_3f_0_, val_0_ = pcall(_2_) - if ok_3f_0_ then - _0_["aniseed/local-fns"] = {} - return val_0_ - else - return print(val_0_) - end -end -local _local_0_ = _2_(...) -local _2amodule_2a = _0_ -local _2amodule_name_2a = "aniseed.nvim" -return ({nil, _0_, nil, {{}, nil, nil, nil}})[2] +_2amodule_2a, _2amodule_name_2a, _2afile_2a = _0_, "aniseed.nvim", "fnl/aniseed/nvim.fnl" +return nil diff --git a/lua/aniseed/nvim/util.lua b/lua/aniseed/nvim/util.lua index ef2e0e1..859d172 100644 --- a/lua/aniseed/nvim/util.lua +++ b/lua/aniseed/nvim/util.lua @@ -1,122 +1,66 @@ -local _2afile_2a = "fnl/aniseed/nvim/util.fnl" -local _0_ -do - local name_0_ = "aniseed.nvim.util" - local module_0_ - do - local x_0_ = package.loaded[name_0_] - if ("table" == type(x_0_)) then - module_0_ = x_0_ - else - module_0_ = {} - end - end - module_0_["aniseed/module"] = name_0_ - module_0_["aniseed/locals"] = ((module_0_)["aniseed/locals"] or {}) - do end (module_0_)["aniseed/local-fns"] = ((module_0_)["aniseed/local-fns"] or {}) - do end (package.loaded)[name_0_] = module_0_ - _0_ = module_0_ -end local autoload -local function _1_(...) +local function _0_(...) return (require("aniseed.autoload")).autoload(...) end -autoload = _1_ -local function _2_(...) - local ok_3f_0_, val_0_ = nil, nil - local function _2_() - return {autoload("aniseed.nvim")} - end - ok_3f_0_, val_0_ = pcall(_2_) - if ok_3f_0_ then - _0_["aniseed/local-fns"] = {autoload = {nvim = "aniseed.nvim"}} - return val_0_ - else - return print(val_0_) - end +autoload = _0_ +local nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil +local _1_ +do + local mod_0_ = {["aniseed/local-fns"] = {autoload = {nvim = "aniseed.nvim"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.nvim.util"} + package.loaded["aniseed.nvim.util"] = mod_0_ + _1_ = mod_0_ end -local _local_0_ = _2_(...) -local nvim = _local_0_[1] -local _2amodule_2a = _0_ -local _2amodule_name_2a = "aniseed.nvim.util" -do local _ = ({nil, _0_, nil, {{}, nil, nil, nil}})[2] end +nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(nvim, "aniseed.nvim"), _1_, "aniseed.nvim.util", "fnl/aniseed/nvim/util.fnl" local normal -do - local v_0_ - do - local v_0_0 - local function normal0(keys) - return nvim.ex.silent(("exe \"normal! " .. keys .. "\"")) - end - v_0_0 = normal0 - _0_["normal"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["normal"] = v_0_ - normal = v_0_ +local function _2_(keys) + return nvim.ex.silent(("exe \"normal! " .. keys .. "\"")) end +normal = _2_ +_2amodule_2a["normal"] = normal +_2amodule_2a["aniseed/locals"]["normal"] = normal local fn_bridge -do - local v_0_ - do - local v_0_0 - local function fn_bridge0(viml_name, mod, lua_name, opts) - local _let_0_ = (opts or {}) - local range = _let_0_["range"] - local _return = _let_0_["return"] - local _3_ - if range then - _3_ = " range" - else - _3_ = "" - end - local _5_ - if (_return ~= false) then - _5_ = "return" - else - _5_ = "call" - end - local _7_ - if range then - _7_ = "\" . a:firstline . \", \" . a:lastline . \", " - else - _7_ = "" - end - return nvim.ex.function_((viml_name .. "(...)" .. _3_ .. "\n " .. _5_ .. " luaeval(\"require('" .. mod .. "')['" .. lua_name .. "'](" .. _7_ .. "unpack(_A))\", a:000)\n endfunction")) - end - v_0_0 = fn_bridge0 - _0_["fn-bridge"] = v_0_0 - v_0_ = v_0_0 +local function _3_(viml_name, mod, lua_name, opts) + local _let_0_ = (opts or {}) + local range = _let_0_["range"] + local _return = _let_0_["return"] + local _4_ + if range then + _4_ = " range" + else + _4_ = "" end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["fn-bridge"] = v_0_ - fn_bridge = v_0_ + local _6_ + if (_return ~= false) then + _6_ = "return" + else + _6_ = "call" + end + local _8_ + if range then + _8_ = "\" . a:firstline . \", \" . a:lastline . \", " + else + _8_ = "" + end + return nvim.ex.function_((viml_name .. "(...)" .. _4_ .. "\n " .. _6_ .. " luaeval(\"require('" .. mod .. "')['" .. lua_name .. "'](" .. _8_ .. "unpack(_A))\", a:000)\n endfunction")) end +fn_bridge = _3_ +_2amodule_2a["fn-bridge"] = fn_bridge +_2amodule_2a["aniseed/locals"]["fn-bridge"] = fn_bridge local with_out_str -do - local v_0_ +local function _4_(f) + nvim.ex.redir("=> g:aniseed_nvim_util_out_str") do - local v_0_0 - local function with_out_str0(f) - nvim.ex.redir("=> g:aniseed_nvim_util_out_str") - do - local ok_3f, err = pcall(f) - nvim.ex.redir("END") - nvim.ex.echon("") - nvim.ex.redraw() - if not ok_3f then - error(err) - end - end - return string.gsub(nvim.g.aniseed_nvim_util_out_str, "^(\n?)(.*)$", "%2%1") + local ok_3f, err = pcall(f) + nvim.ex.redir("END") + nvim.ex.echon("") + nvim.ex.redraw() + if not ok_3f then + error(err) end - v_0_0 = with_out_str0 - _0_["with-out-str"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["with-out-str"] = v_0_ - with_out_str = v_0_ + return string.gsub(nvim.g.aniseed_nvim_util_out_str, "^(\n?)(.*)$", "%2%1") end +with_out_str = _4_ +_2amodule_2a["with-out-str"] = with_out_str +_2amodule_2a["aniseed/locals"]["with-out-str"] = with_out_str return nil diff --git a/lua/aniseed/string.lua b/lua/aniseed/string.lua index d1ddb2f..83d80b1 100644 --- a/lua/aniseed/string.lua +++ b/lua/aniseed/string.lua @@ -1,182 +1,99 @@ -local _2afile_2a = "fnl/aniseed/string.fnl" -local _0_ -do - local name_0_ = "aniseed.string" - local module_0_ - do - local x_0_ = package.loaded[name_0_] - if ("table" == type(x_0_)) then - module_0_ = x_0_ - else - module_0_ = {} - end - end - module_0_["aniseed/module"] = name_0_ - module_0_["aniseed/locals"] = ((module_0_)["aniseed/locals"] or {}) - do end (module_0_)["aniseed/local-fns"] = ((module_0_)["aniseed/local-fns"] or {}) - do end (package.loaded)[name_0_] = module_0_ - _0_ = module_0_ -end local autoload -local function _1_(...) +local function _0_(...) return (require("aniseed.autoload")).autoload(...) end -autoload = _1_ -local function _2_(...) - local ok_3f_0_, val_0_ = nil, nil - local function _2_() - return {autoload("aniseed.core")} - end - ok_3f_0_, val_0_ = pcall(_2_) - if ok_3f_0_ then - _0_["aniseed/local-fns"] = {autoload = {a = "aniseed.core"}} - return val_0_ - else - return print(val_0_) - end +autoload = _0_ +local a, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil +local _1_ +do + local mod_0_ = {["aniseed/local-fns"] = {autoload = {a = "aniseed.core"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.string"} + package.loaded["aniseed.string"] = mod_0_ + _1_ = mod_0_ end -local _local_0_ = _2_(...) -local a = _local_0_[1] -local _2amodule_2a = _0_ -local _2amodule_name_2a = "aniseed.string" -do local _ = ({nil, _0_, nil, {{}, nil, nil, nil}})[2] end +a, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(a, "aniseed.core"), _1_, "aniseed.string", "fnl/aniseed/string.fnl" local join -do - local v_0_ - do - local v_0_0 - local function join0(...) - local args = {...} - local function _3_(...) - if (2 == a.count(args)) then - return args - else - return {"", a.first(args)} - end +local function _2_(...) + local args = {...} + local function _3_(...) + if (2 == a.count(args)) then + return args + else + return {"", a.first(args)} + end + end + local _let_0_ = _3_(...) + local sep = _let_0_[1] + local xs = _let_0_[2] + local len = a.count(xs) + local result = {} + if (len > 0) then + for i = 1, len do + local x = xs[i] + local _4_ + if ("string" == type(x)) then + _4_ = x + elseif (nil == x) then + _4_ = x + else + _4_ = a["pr-str"](x) end - local _let_0_ = _3_(...) - local sep = _let_0_[1] - local xs = _let_0_[2] - local len = a.count(xs) - local result = {} - if (len > 0) then - for i = 1, len do - local x = xs[i] - local _4_ - if ("string" == type(x)) then - _4_ = x - elseif (nil == x) then - _4_ = x - else - _4_ = a["pr-str"](x) - end - if _4_ then - table.insert(result, _4_) - else - end - end + if _4_ then + table.insert(result, _4_) + else end - return table.concat(result, sep) end - v_0_0 = join0 - _0_["join"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["join"] = v_0_ - join = v_0_ + return table.concat(result, sep) end +join = _2_ +_2amodule_2a["join"] = join +_2amodule_2a["aniseed/locals"]["join"] = join local split -do - local v_0_ - do - local v_0_0 - local function split0(s, pat) - local done_3f = false - local acc = {} - local index = 1 - while not done_3f do - local start, _end = string.find(s, pat, index) - if ("nil" == type(start)) then - table.insert(acc, string.sub(s, index)) - done_3f = true - else - table.insert(acc, string.sub(s, index, (start - 1))) - index = (_end + 1) - end - end - return acc +local function _3_(s, pat) + local done_3f = false + local acc = {} + local index = 1 + while not done_3f do + local start, _end = string.find(s, pat, index) + if ("nil" == type(start)) then + table.insert(acc, string.sub(s, index)) + done_3f = true + else + table.insert(acc, string.sub(s, index, (start - 1))) + index = (_end + 1) end - v_0_0 = split0 - _0_["split"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["split"] = v_0_ - split = v_0_ + return acc end +split = _3_ +_2amodule_2a["split"] = split +_2amodule_2a["aniseed/locals"]["split"] = split local blank_3f -do - local v_0_ - do - local v_0_0 - local function blank_3f0(s) - return (a["empty?"](s) or not string.find(s, "[^%s]")) - end - v_0_0 = blank_3f0 - _0_["blank?"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["blank?"] = v_0_ - blank_3f = v_0_ +local function _4_(s) + return (a["empty?"](s) or not string.find(s, "[^%s]")) end +blank_3f = _4_ +_2amodule_2a["blank?"] = blank_3f +_2amodule_2a["aniseed/locals"]["blank?"] = blank_3f local triml -do - local v_0_ - do - local v_0_0 - local function triml0(s) - return string.gsub(s, "^%s*(.-)", "%1") - end - v_0_0 = triml0 - _0_["triml"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["triml"] = v_0_ - triml = v_0_ +local function _5_(s) + return string.gsub(s, "^%s*(.-)", "%1") end +triml = _5_ +_2amodule_2a["triml"] = triml +_2amodule_2a["aniseed/locals"]["triml"] = triml local trimr -do - local v_0_ - do - local v_0_0 - local function trimr0(s) - return string.gsub(s, "(.-)%s*$", "%1") - end - v_0_0 = trimr0 - _0_["trimr"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["trimr"] = v_0_ - trimr = v_0_ +local function _6_(s) + return string.gsub(s, "(.-)%s*$", "%1") end +trimr = _6_ +_2amodule_2a["trimr"] = trimr +_2amodule_2a["aniseed/locals"]["trimr"] = trimr local trim -do - local v_0_ - do - local v_0_0 - local function trim0(s) - return string.gsub(s, "^%s*(.-)%s*$", "%1") - end - v_0_0 = trim0 - _0_["trim"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["trim"] = v_0_ - trim = v_0_ +local function _7_(s) + return string.gsub(s, "^%s*(.-)%s*$", "%1") end +trim = _7_ +_2amodule_2a["trim"] = trim +_2amodule_2a["aniseed/locals"]["trim"] = trim return nil diff --git a/lua/aniseed/test.lua b/lua/aniseed/test.lua index 34bb445..dbb782e 100644 --- a/lua/aniseed/test.lua +++ b/lua/aniseed/test.lua @@ -1,235 +1,158 @@ -local _2afile_2a = "fnl/aniseed/test.fnl" -local _0_ -do - local name_0_ = "aniseed.test" - local module_0_ - do - local x_0_ = package.loaded[name_0_] - if ("table" == type(x_0_)) then - module_0_ = x_0_ - else - module_0_ = {} - end - end - module_0_["aniseed/module"] = name_0_ - module_0_["aniseed/locals"] = ((module_0_)["aniseed/locals"] or {}) - do end (module_0_)["aniseed/local-fns"] = ((module_0_)["aniseed/local-fns"] or {}) - do end (package.loaded)[name_0_] = module_0_ - _0_ = module_0_ -end local autoload -local function _1_(...) +local function _0_(...) return (require("aniseed.autoload")).autoload(...) end -autoload = _1_ -local function _2_(...) - local ok_3f_0_, val_0_ = nil, nil - local function _2_() - return {autoload("aniseed.core"), autoload("aniseed.fs"), autoload("aniseed.nvim"), autoload("aniseed.string")} - end - ok_3f_0_, val_0_ = pcall(_2_) - if ok_3f_0_ then - _0_["aniseed/local-fns"] = {autoload = {a = "aniseed.core", fs = "aniseed.fs", nvim = "aniseed.nvim", str = "aniseed.string"}} - return val_0_ - else - return print(val_0_) - end +autoload = _0_ +local a, fs, str, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil +local _1_ +do + local mod_0_ = {["aniseed/local-fns"] = {autoload = {a = "aniseed.core", fs = "aniseed.fs", nvim = "aniseed.nvim", str = "aniseed.string"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.test"} + package.loaded["aniseed.test"] = mod_0_ + _1_ = mod_0_ end -local _local_0_ = _2_(...) -local a = _local_0_[1] -local fs = _local_0_[2] -local nvim = _local_0_[3] -local str = _local_0_[4] -local _2amodule_2a = _0_ -local _2amodule_name_2a = "aniseed.test" -do local _ = ({nil, _0_, nil, {{}, nil, nil, nil}})[2] end +a, fs, str, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(a, "aniseed.core"), autoload(fs, "aniseed.fs"), autoload(str, "aniseed.string"), autoload(nvim, "aniseed.nvim"), _1_, "aniseed.test", "fnl/aniseed/test.fnl" local ok_3f -do - local v_0_ - do - local v_0_0 - local function ok_3f0(_3_) - local _arg_0_ = _3_ - local tests = _arg_0_["tests"] - local tests_passed = _arg_0_["tests-passed"] - return (tests == tests_passed) - end - v_0_0 = ok_3f0 - _0_["ok?"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["ok?"] = v_0_ - ok_3f = v_0_ +local function _3_(_2_) + local _arg_0_ = _2_ + local tests = _arg_0_["tests"] + local tests_passed = _arg_0_["tests-passed"] + return (tests == tests_passed) end +ok_3f = _3_ +_2amodule_2a["ok?"] = ok_3f +_2amodule_2a["aniseed/locals"]["ok?"] = ok_3f local display_results -do - local v_0_ +local function _4_(results, prefix) do - local v_0_0 - local function display_results0(results, prefix) - do - local _let_0_ = results - local assertions = _let_0_["assertions"] - local assertions_passed = _let_0_["assertions-passed"] - local tests = _let_0_["tests"] - local tests_passed = _let_0_["tests-passed"] - local _3_ - if ok_3f(results) then - _3_ = "OK" - else - _3_ = "FAILED" - end - a.println((prefix .. " " .. _3_ .. " " .. tests_passed .. "/" .. tests .. " tests and " .. assertions_passed .. "/" .. assertions .. " assertions passed")) - end - return results + local _let_0_ = results + local assertions = _let_0_["assertions"] + local assertions_passed = _let_0_["assertions-passed"] + local tests = _let_0_["tests"] + local tests_passed = _let_0_["tests-passed"] + local _5_ + if ok_3f(results) then + _5_ = "OK" + else + _5_ = "FAILED" end - v_0_0 = display_results0 - _0_["display-results"] = v_0_0 - v_0_ = v_0_0 + a.println((prefix .. " " .. _5_ .. " " .. tests_passed .. "/" .. tests .. " tests and " .. assertions_passed .. "/" .. assertions .. " assertions passed")) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["display-results"] = v_0_ - display_results = v_0_ + return results end +display_results = _4_ +_2amodule_2a["display-results"] = display_results +_2amodule_2a["aniseed/locals"]["display-results"] = display_results local run -do - local v_0_ - do - local v_0_0 - local function run0(mod_name) - local mod = package.loaded[mod_name] - local tests = (a["table?"](mod) and mod["aniseed/tests"]) - if a["table?"](tests) then - local results = {["assertions-passed"] = 0, ["tests-passed"] = 0, assertions = 0, tests = #tests} - for label, f in pairs(tests) do - local test_failed = false - a.update(results, "tests", a.inc) - do - local prefix = ("[" .. mod_name .. "/" .. label .. "]") - local fail - local function _3_(desc, ...) - test_failed = true - local function _4_(...) - if desc then - return (" (" .. desc .. ")") - else - return "" - end - end - return a.println((str.join({prefix, " ", ...}) .. _4_(...))) - end - fail = _3_ - local begin - local function _4_() - return a.update(results, "assertions", a.inc) - end - begin = _4_ - local pass - local function _5_() - return a.update(results, "assertions-passed", a.inc) - end - pass = _5_ - local t - local function _6_(e, r, desc) - begin() - if (e == r) then - return pass() - else - return fail(desc, "Expected '", a["pr-str"](e), "' but received '", a["pr-str"](r), "'") - end - end - local function _7_(r, desc) - begin() - if r then - return pass() - else - return fail(desc, "Expected truthy result but received '", a["pr-str"](r), "'") - end - end - local function _8_(e, r, desc) - begin() - local se = a["pr-str"](e) - local sr = a["pr-str"](r) - if (se == sr) then - return pass() - else - return fail(desc, "Expected (with pr) '", se, "' but received '", sr, "'") - end - end - t = {["="] = _6_, ["ok?"] = _7_, ["pr="] = _8_} - local _9_, _10_ = nil, nil - local function _11_() - return f(t) - end - _9_, _10_ = pcall(_11_) - if ((_9_ == false) and (nil ~= _10_)) then - local err = _10_ - fail("Exception: ", err) +local function _5_(mod_name) + local mod = package.loaded[mod_name] + local tests = (a["table?"](mod) and mod["aniseed/tests"]) + if a["table?"](tests) then + local results = {["assertions-passed"] = 0, ["tests-passed"] = 0, assertions = 0, tests = #tests} + for label, f in pairs(tests) do + local test_failed = false + a.update(results, "tests", a.inc) + do + local prefix = ("[" .. mod_name .. "/" .. label .. "]") + local fail + local function _6_(desc, ...) + test_failed = true + local function _7_(...) + if desc then + return (" (" .. desc .. ")") + else + return "" end end - if not test_failed then - a.update(results, "tests-passed", a.inc) + return a.println((str.join({prefix, " ", ...}) .. _7_(...))) + end + fail = _6_ + local begin + local function _7_() + return a.update(results, "assertions", a.inc) + end + begin = _7_ + local pass + local function _8_() + return a.update(results, "assertions-passed", a.inc) + end + pass = _8_ + local t + local function _9_(e, r, desc) + begin() + if (e == r) then + return pass() + else + return fail(desc, "Expected '", a["pr-str"](e), "' but received '", a["pr-str"](r), "'") end end - return display_results(results, ("[" .. mod_name .. "]")) + local function _10_(r, desc) + begin() + if r then + return pass() + else + return fail(desc, "Expected truthy result but received '", a["pr-str"](r), "'") + end + end + local function _11_(e, r, desc) + begin() + local se = a["pr-str"](e) + local sr = a["pr-str"](r) + if (se == sr) then + return pass() + else + return fail(desc, "Expected (with pr) '", se, "' but received '", sr, "'") + end + end + t = {["="] = _9_, ["ok?"] = _10_, ["pr="] = _11_} + local _12_, _13_ = nil, nil + local function _14_() + return f(t) + end + _12_, _13_ = pcall(_14_) + if ((_12_ == false) and (nil ~= _13_)) then + local err = _13_ + fail("Exception: ", err) + end + end + if not test_failed then + a.update(results, "tests-passed", a.inc) end end - v_0_0 = run0 - _0_["run"] = v_0_0 - v_0_ = v_0_0 + return display_results(results, ("[" .. mod_name .. "]")) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["run"] = v_0_ - run = v_0_ end +run = _5_ +_2amodule_2a["run"] = run +_2amodule_2a["aniseed/locals"]["run"] = run local run_all -do - local v_0_ - do - local v_0_0 - local function run_all0() - local function _3_(totals, results) - for k, v in pairs(results) do - totals[k] = (v + totals[k]) - end - return totals - end - return display_results(a.reduce(_3_, {["assertions-passed"] = 0, ["tests-passed"] = 0, assertions = 0, tests = 0}, a.filter(a["table?"], a.map(run, a.keys(package.loaded)))), "[total]") +local function _6_() + local function _7_(totals, results) + for k, v in pairs(results) do + totals[k] = (v + totals[k]) end - v_0_0 = run_all0 - _0_["run-all"] = v_0_0 - v_0_ = v_0_0 + return totals end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["run-all"] = v_0_ - run_all = v_0_ + return display_results(a.reduce(_7_, {["assertions-passed"] = 0, ["tests-passed"] = 0, assertions = 0, tests = 0}, a.filter(a["table?"], a.map(run, a.keys(package.loaded)))), "[total]") end +run_all = _6_ +_2amodule_2a["run-all"] = run_all +_2amodule_2a["aniseed/locals"]["run-all"] = run_all local suite -do - local v_0_ +local function _7_() do - local v_0_0 - local function suite0() - do - local sep = fs["path-sep"] - local function _3_(path) - return require(string.gsub(string.match(path, ("^test" .. sep .. "fnl" .. sep .. "(.-).fnl$")), sep, ".")) - end - a["run!"](_3_, nvim.fn.globpath(("test" .. sep .. "fnl"), "**/*-test.fnl", false, true)) - end - if ok_3f(run_all()) then - return nvim.ex.q() - else - return nvim.ex.cq() - end + local sep = fs["path-sep"] + local function _8_(path) + return require(string.gsub(string.match(path, ("^test" .. sep .. "fnl" .. sep .. "(.-).fnl$")), sep, ".")) end - v_0_0 = suite0 - _0_["suite"] = v_0_0 - v_0_ = v_0_0 + a["run!"](_8_, nvim.fn.globpath(("test" .. sep .. "fnl"), "**/*-test.fnl", false, true)) + end + if ok_3f(run_all()) then + return nvim.ex.q() + else + return nvim.ex.cq() end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["suite"] = v_0_ - suite = v_0_ end +suite = _7_ +_2amodule_2a["suite"] = suite +_2amodule_2a["aniseed/locals"]["suite"] = suite return nil diff --git a/lua/aniseed/view.lua b/lua/aniseed/view.lua index 1fe1aa8..21a208a 100644 --- a/lua/aniseed/view.lua +++ b/lua/aniseed/view.lua @@ -1,58 +1,16 @@ -local _2afile_2a = "fnl/aniseed/view.fnl" +local _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil local _0_ do - local name_0_ = "aniseed.view" - local module_0_ - do - local x_0_ = package.loaded[name_0_] - if ("table" == type(x_0_)) then - module_0_ = x_0_ - else - module_0_ = {} - end - end - module_0_["aniseed/module"] = name_0_ - module_0_["aniseed/locals"] = ((module_0_)["aniseed/locals"] or {}) - do end (module_0_)["aniseed/local-fns"] = ((module_0_)["aniseed/local-fns"] or {}) - do end (package.loaded)[name_0_] = module_0_ - _0_ = module_0_ + local mod_0_ = {["aniseed/local-fns"] = {}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.view"} + package.loaded["aniseed.view"] = mod_0_ + _0_ = mod_0_ end -local autoload -local function _1_(...) - return (require("aniseed.autoload")).autoload(...) -end -autoload = _1_ -local function _2_(...) - local ok_3f_0_, val_0_ = nil, nil - local function _2_() - return {} - end - ok_3f_0_, val_0_ = pcall(_2_) - if ok_3f_0_ then - _0_["aniseed/local-fns"] = {} - return val_0_ - else - return print(val_0_) - end -end -local _local_0_ = _2_(...) -local _2amodule_2a = _0_ -local _2amodule_name_2a = "aniseed.view" -do local _ = ({nil, _0_, nil, {{}, nil, nil, nil}})[2] end +_2amodule_2a, _2amodule_name_2a, _2afile_2a = _0_, "aniseed.view", "fnl/aniseed/view.fnl" local serialise -do - local v_0_ - do - local v_0_0 - local function _3_(...) - return require("aniseed.deps.fennelview")(...) - end - v_0_0 = _3_ - _0_["serialise"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["serialise"] = v_0_ - serialise = v_0_ +local function _1_(...) + return require("aniseed.deps.fennelview")(...) end +serialise = _1_ +_2amodule_2a["serialise"] = serialise +_2amodule_2a["aniseed/locals"]["serialise"] = serialise return nil diff --git a/module-system-plugin.fnl b/module-system-plugin.fnl new file mode 100644 index 0000000..ce07e7e --- /dev/null +++ b/module-system-plugin.fnl @@ -0,0 +1,184 @@ +(local syms (setmetatable {} {:__index #(sym $2)})) + +(fn table? [x] + (= :table (type x))) + +(fn empty-table [t] + (while (> (# t) 0) + (table.remove t))) + +;; copied from fennel.utils.copy +;; simple table copy +(fn copy [from to] + (let [to (or to [])] + (each [k v (pairs (or from []))] + (tset to k v)) + to)) + +;; splits a table into two by running p on each key +(fn partition-by-key [p x] + (let [t {} f {}] + (each [k v (pairs (or x []))] + (if (p k) + (tset t k v) + (tset f k v))) + (values t f))) + +;; recursively `tostring`s a table, only recursing on a value if it is +;; a table and *not* a symbol, as symbols should be `tostring`ed +(fn stringify-table [t] + (collect [k v (pairs t)] + (values + (tostring k) + (if (and (not (sym? v)) (table? v)) + (stringify-table v) + (tostring v))))) + +(fn module-form [ast {: scope : parent : opts : compile1}] + (let [name-str (-?> (assert-compile + (sym? (. ast 2)) "expected symbol for module name" ast) + tostring) + all-new-local-fns (stringify-table (or (. ast 3) [])) + (autoloads new-local-fns) (partition-by-key + #(= :autoload $) + all-new-local-fns) + mod (doto (or (. ast 4) {}) + (tset :aniseed/module name-str) + (tset :aniseed/locals {}) + (tset :aniseed/local-fns all-new-local-fns)) + locals []] + + (tset scope :module {:locals {} :public {}}) + + (when (next new-local-fns) + (each [f aliases (pairs new-local-fns)] + (each [alias arg (pairs aliases)] + (table.insert locals + [(sym alias) + `(,(sym f) ,arg)])))) + + (when (next autoloads) + (compile1 `(local ,syms.autoload + #((. (require :aniseed.autoload) :autoload) $...)) + scope parent opts) + + (each [_ aliases (pairs autoloads)] + (each [alias arg (pairs aliases)] + (let [sym-alias (sym alias)] + (table.insert locals + [sym-alias + `(autoload ,sym-alias ,arg)]))))) + + (table.insert locals + [syms.*module* + `(let [mod# ,mod] + (tset package.loaded ,name-str mod#) + mod#)]) + + (table.insert locals [syms.*module-name* name-str]) + + (when opts.filename + (table.insert locals [syms.*file* opts.filename])) + + (let [names [] + vals []] + + (each [_ [k v] (ipairs locals)] + (table.insert names k) + (table.insert vals v)) + + (empty-table ast) + (copy [`local `(,(unpack names)) `(values ,(unpack vals))] ast)))) + +(fn def-form [ast {: scope : parent : opts : compile1 &as state} private? value?] + (let [name (. ast 2) + name-str (tostring name) + value (or value? (. ast 3)) + mod-scope (if private? :locals :public)] + (tset scope.module mod-scope name-str value) + + (compile1 `(local ,name ,value) scope parent opts) + + (when (not private?) + (compile1 `(tset ,syms.*module* ,name-str ,name) scope parent opts)) + + (empty-table ast) + (copy [`tset syms.*module* :aniseed/locals name-str name] ast))) + +(fn defn-form [ast {: scope : parent : opts : compile1 &as state} private?] + (let [[_ _ args & body] ast + fn-ast `(fn ,args)] + (each [_ stmt (pairs body)] + (table.insert fn-ast stmt)) + + (def-form ast state private? fn-ast))) + +(fn defonce-form [ast {: scope : parent : opts : compile1 &as state} private?] + (let [[_ name value] ast + name-str (tostring name) + mod-scope (if private? :locals :public)] + (if (. scope.module mod-scope name-str) + (do + (empty-table ast) + (copy [`lua syms.nil] ast)) + (def-form ast state private?)))) + +(fn deftest-form [ast {: scope : parent : opts : compile1 &as state}] + (let [[_ name & body] ast + name-str (tostring name) + fn-sym (gensym) + fn-ast `(fn ,fn-sym [,syms.t])] + (each [_ stmt (pairs body)] + (table.insert fn-ast stmt)) + + (compile1 fn-ast scope parent opts) + + (empty-table ast) + + (if (. scope.module :has-tests) + (copy [`tset syms.*module* :aniseed/tests name-str fn-sym] ast) + (do + (tset scope.module :has-tests true) + (copy [`tset syms.*module* :aniseed/tests {name-str fn-sym}] ast))))) + +(fn time-form [ast {: scope : parent : opts : compile1 &as state}] + (let [[_ & body] ast + time-fn-sym (. scope.module :time-fn-sym) + body-ast `(do)] + (when (not time-fn-sym) + (set-forcibly! time-fn-sym (gensym)) + (tset scope.module :time-fn-sym time-fn-sym) + (compile1 `(fn ,time-fn-sym [...] + (let [start# (vim.loop.hrtime) + result# ... + end# (vim.loop.hrtime)] + (print (.. "Elapsed time: " + (/ (- end# start#) 1000000) + " msecs")) + result#)) + scope parent opts)) + + (each [_ stmt (pairs body)] + (table.insert body-ast stmt)) + + (empty-table ast) + (copy `(,time-fn-sym ,body-ast) ast))) + +(fn call [ast scope parent opts compile1] + (let [symbol (. ast 1) + state {: scope : parent : compile1 + :opts (doto (copy opts) + (tset :tail false))}] + + (match (. ast 1) + syms.module (module-form ast state) + syms.def- (def-form ast state true) + syms.def (def-form ast state false) + syms.defn- (defn-form ast state true) + syms.defn (defn-form ast state false) + syms.defonce- (defonce-form ast state true) + syms.defonce (defonce-form ast state false) + syms.deftest (deftest-form ast state) + syms.time (time-form ast state)))) + +{: call} diff --git a/modules-plugin.fnl b/modules-plugin.fnl deleted file mode 100644 index 22e8397..0000000 --- a/modules-plugin.fnl +++ /dev/null @@ -1,110 +0,0 @@ -;; TODO -;; *file* -;; (module...) -;; autoload -;; def, defn, defn-, defonce, defonce-, time, deftest - -(local root-module-sym (sym :module)) -(local def-private-sym (sym :def-)) -(local module-sym (sym :*module*)) -(local module-name-sym (sym :*module-name*)) -(local black-hole-sym (sym :_)) - -(fn table? [x] - (= :table (type x))) - -(fn empty-table [t] - (while (> (# t) 0) - (table.remove t)) ) - -(fn module-form [ast scope] - (let [[_module name new-local-fns initial-mod] ast - name-str (tostring name) - existing-mod (. package.loaded name-str) - mod (or existing-mod - initial-mod - {:aniseed/module name-str - :aniseed/locals {} - :aniseed/local-fns new-local-fns}) - locals []] - - ;; Stringify the keys and values of new-local-fns. - (when (table? new-local-fns) - (each [f aliases (pairs new-local-fns)] - (each [alias arg (pairs aliases)] - (tset aliases alias nil) - (tset aliases (tostring alias) (tostring arg))))) - - ;; Sync new-local-fns into local-fns if the module is loaded. - ;; This is only used when reloading a module at runtime. - (when (and existing-mod new-local-fns) - (each [k v (pairs new-local-fns)] - (tset (. existing-mod :aniseed/local-fns) k v))) - - (empty-table ast) - - ;; package.loaded[module-name] = module - (table.insert - locals - [black-hole-sym - `(tset package.loaded ,name-str ,mod)]) - - ;; *module-name* - (table.insert locals [module-name-sym name-str]) - - ;; *module* - (table.insert locals [module-sym `(. package.loaded ,name-str)]) - - ;; local-fns -> local definitions - (when (table? new-local-fns) - (each [f aliases (pairs new-local-fns)] - (each [alias arg (pairs aliases)] - (table.insert - locals - [(sym alias) - `(,f ,arg)])))) - - ;; Now we build the AST from the locals table. - (let [names [] - vals []] - - ;; ( ...) - (table.insert ast `local) - - ;; Split all the locals pairs into the names and vals tables. - (each [_ [k v] (ipairs locals)] - (table.insert names k) - (table.insert vals v)) - - ;; Then we unpack those tables into our AST. - - ;; (local <(xk yk zk)> ...) - (table.insert ast (list (unpack names))) - - ;; (local ... <(xv yv zv)>) - (table.insert ast (list `values (unpack vals)))))) - -(fn def-private-form [ast scope] - (let [[_def- name value] ast] - (empty-table ast) - (table.insert ast `local) - (table.insert ast name) - (table.insert - ast - `(let [v# ,value] - (tset - (. ,module-sym :aniseed/locals) - ,(tostring name) - v#) - #v)))) - -(fn call [ast scope] - (let [head (. ast 1)] - (if - ;; (module ...) - (= root-module-sym head) (module-form ast scope) - - ;; (def- ...) - (= def-private-sym head) (def-private-form ast scope)))) - -{:call call} diff --git a/scripts/internal/compile.fnl b/scripts/internal/compile.fnl deleted file mode 100755 index c0f1452..0000000 --- a/scripts/internal/compile.fnl +++ /dev/null @@ -1,26 +0,0 @@ -;; TODO Maybe this all goes away, just use the CLI for this part? - -(local fennel (require :fennel)) - -(set fennel.path (.. fennel.path ";fnl/?.fnl")) - -(fn read-file [path] - (let [file (io.open path "rb") - content (file:read "*a")] - (file:close) - content)) - -(fn compile [content opts] - (xpcall - (fn [] - (fennel.compileString content opts)) - fennel.traceback)) - -(let [filename (. arg 1) - (ok? result) (-> filename - (read-file) - (compile {:filename filename - :plugins ["modules-plugin.fnl"]}))] - (if ok? - (print result) - (error result))) diff --git a/test/fnl/aniseed/compile-test.fnl b/test/fnl/aniseed/compile-test.fnl index 66ed29c..e7bb614 100644 --- a/test/fnl/aniseed/compile-test.fnl +++ b/test/fnl/aniseed/compile-test.fnl @@ -5,7 +5,7 @@ (deftest str (let [(success result) (compile.str "(+ 10 20)")] (t.ok? success "compilation should return true") - (t.= "local _2afile_2a = nil\nreturn (10 + 20)" result "results include a return and parens")) + (t.= "return (10 + 20)" result "results include a return and parens")) (let [(success result) (compile.str "(+ 10 20")] (t.ok? (not success)) diff --git a/test/fnl/aniseed/macros-test.fnl b/test/fnl/aniseed/module-system-test.fnl similarity index 83% rename from test/fnl/aniseed/macros-test.fnl rename to test/fnl/aniseed/module-system-test.fnl index 47c8d9f..690979e 100644 --- a/test/fnl/aniseed/macros-test.fnl +++ b/test/fnl/aniseed/module-system-test.fnl @@ -1,4 +1,4 @@ -(module aniseed.macros-test) +(module aniseed.module-system-test) (deftest defonce (var calls 0) From 39841b0aceac675070bb4ec5227231b8d2a74358 Mon Sep 17 00:00:00 2001 From: Andrew DeFilippo Date: Mon, 26 Jul 2021 19:29:49 -0500 Subject: [PATCH 05/11] Added `assert-compile`s that I forgot to before, and expanded on module-system-tests to include compilation tests and then some. --- lua/aniseed/compile.lua | 4 +- lua/aniseed/env.lua | 4 +- lua/aniseed/eval.lua | 4 +- lua/aniseed/fennel.lua | 4 +- lua/aniseed/fs.lua | 4 +- lua/aniseed/test.lua | 4 +- module-system-plugin.fnl | 25 +++++-- test/fnl/aniseed/compile-test.fnl | 3 +- test/fnl/aniseed/module-system-test.fnl | 93 ++++++++++++++++++++++++- 9 files changed, 122 insertions(+), 23 deletions(-) diff --git a/lua/aniseed/compile.lua b/lua/aniseed/compile.lua index dcf8aa5..481d613 100644 --- a/lua/aniseed/compile.lua +++ b/lua/aniseed/compile.lua @@ -3,14 +3,14 @@ local function _0_(...) return (require("aniseed.autoload")).autoload(...) end autoload = _0_ -local nvim, fennel, fs, a, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil +local nvim, a, fs, fennel, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil local _1_ do local mod_0_ = {["aniseed/local-fns"] = {autoload = {a = "aniseed.core", fennel = "aniseed.fennel", fs = "aniseed.fs", nvim = "aniseed.nvim"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.compile"} package.loaded["aniseed.compile"] = mod_0_ _1_ = mod_0_ end -nvim, fennel, fs, a, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(nvim, "aniseed.nvim"), autoload(fennel, "aniseed.fennel"), autoload(fs, "aniseed.fs"), autoload(a, "aniseed.core"), _1_, "aniseed.compile", "fnl/aniseed/compile.fnl" +nvim, a, fs, fennel, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(nvim, "aniseed.nvim"), autoload(a, "aniseed.core"), autoload(fs, "aniseed.fs"), autoload(fennel, "aniseed.fennel"), _1_, "aniseed.compile", "fnl/aniseed/compile.fnl" local base_path do local _2_ = (debug.getinfo(1, "S")).source diff --git a/lua/aniseed/env.lua b/lua/aniseed/env.lua index 9163f02..ab3a2d8 100644 --- a/lua/aniseed/env.lua +++ b/lua/aniseed/env.lua @@ -3,14 +3,14 @@ local function _0_(...) return (require("aniseed.autoload")).autoload(...) end autoload = _0_ -local compile, fennel, fs, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil +local fennel, compile, nvim, fs, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil local _1_ do local mod_0_ = {["aniseed/local-fns"] = {autoload = {compile = "aniseed.compile", fennel = "aniseed.fennel", fs = "aniseed.fs", nvim = "aniseed.nvim"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.env"} package.loaded["aniseed.env"] = mod_0_ _1_ = mod_0_ end -compile, fennel, fs, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(compile, "aniseed.compile"), autoload(fennel, "aniseed.fennel"), autoload(fs, "aniseed.fs"), autoload(nvim, "aniseed.nvim"), _1_, "aniseed.env", "fnl/aniseed/env.fnl" +fennel, compile, nvim, fs, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(fennel, "aniseed.fennel"), autoload(compile, "aniseed.compile"), autoload(nvim, "aniseed.nvim"), autoload(fs, "aniseed.fs"), _1_, "aniseed.env", "fnl/aniseed/env.fnl" local config_dir = nvim.fn.stdpath("config") do end (_2amodule_2a)["aniseed/locals"]["config-dir"] = config_dir local quiet_require diff --git a/lua/aniseed/eval.lua b/lua/aniseed/eval.lua index 6bb1ba9..e1511ae 100644 --- a/lua/aniseed/eval.lua +++ b/lua/aniseed/eval.lua @@ -3,14 +3,14 @@ local function _0_(...) return (require("aniseed.autoload")).autoload(...) end autoload = _0_ -local compile, fennel, fs, nvim, a, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil, nil +local fennel, fs, a, compile, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil, nil local _1_ do local mod_0_ = {["aniseed/local-fns"] = {autoload = {a = "aniseed.core", compile = "aniseed.compile", fennel = "aniseed.fennel", fs = "aniseed.fs", nvim = "aniseed.nvim"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.eval"} package.loaded["aniseed.eval"] = mod_0_ _1_ = mod_0_ end -compile, fennel, fs, nvim, a, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(compile, "aniseed.compile"), autoload(fennel, "aniseed.fennel"), autoload(fs, "aniseed.fs"), autoload(nvim, "aniseed.nvim"), autoload(a, "aniseed.core"), _1_, "aniseed.eval", "fnl/aniseed/eval.fnl" +fennel, fs, a, compile, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(fennel, "aniseed.fennel"), autoload(fs, "aniseed.fs"), autoload(a, "aniseed.core"), autoload(compile, "aniseed.compile"), autoload(nvim, "aniseed.nvim"), _1_, "aniseed.eval", "fnl/aniseed/eval.fnl" local str local function _2_(code, opts) local fnl = fennel.impl() diff --git a/lua/aniseed/fennel.lua b/lua/aniseed/fennel.lua index dd39e35..07646ca 100644 --- a/lua/aniseed/fennel.lua +++ b/lua/aniseed/fennel.lua @@ -3,14 +3,14 @@ local function _0_(...) return (require("aniseed.autoload")).autoload(...) end autoload = _0_ -local fs, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil +local nvim, fs, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil local _1_ do local mod_0_ = {["aniseed/local-fns"] = {autoload = {fs = "aniseed.fs", nvim = "aniseed.nvim"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.fennel"} package.loaded["aniseed.fennel"] = mod_0_ _1_ = mod_0_ end -fs, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(fs, "aniseed.fs"), autoload(nvim, "aniseed.nvim"), _1_, "aniseed.fennel", "fnl/aniseed/fennel.fnl" +nvim, fs, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(nvim, "aniseed.nvim"), autoload(fs, "aniseed.fs"), _1_, "aniseed.fennel", "fnl/aniseed/fennel.fnl" local sync_rtp local function _2_(compiler) local sep = fs["path-sep"] diff --git a/lua/aniseed/fs.lua b/lua/aniseed/fs.lua index 616c56b..7edb0ed 100644 --- a/lua/aniseed/fs.lua +++ b/lua/aniseed/fs.lua @@ -3,14 +3,14 @@ local function _0_(...) return (require("aniseed.autoload")).autoload(...) end autoload = _0_ -local a, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil +local nvim, a, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil local _1_ do local mod_0_ = {["aniseed/local-fns"] = {autoload = {a = "aniseed.core", nvim = "aniseed.nvim"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.fs"} package.loaded["aniseed.fs"] = mod_0_ _1_ = mod_0_ end -a, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(a, "aniseed.core"), autoload(nvim, "aniseed.nvim"), _1_, "aniseed.fs", "fnl/aniseed/fs.fnl" +nvim, a, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(nvim, "aniseed.nvim"), autoload(a, "aniseed.core"), _1_, "aniseed.fs", "fnl/aniseed/fs.fnl" local path_sep do local os = string.lower(jit.os) diff --git a/lua/aniseed/test.lua b/lua/aniseed/test.lua index dbb782e..97b982b 100644 --- a/lua/aniseed/test.lua +++ b/lua/aniseed/test.lua @@ -3,14 +3,14 @@ local function _0_(...) return (require("aniseed.autoload")).autoload(...) end autoload = _0_ -local a, fs, str, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil +local str, a, fs, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil local _1_ do local mod_0_ = {["aniseed/local-fns"] = {autoload = {a = "aniseed.core", fs = "aniseed.fs", nvim = "aniseed.nvim", str = "aniseed.string"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.test"} package.loaded["aniseed.test"] = mod_0_ _1_ = mod_0_ end -a, fs, str, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(a, "aniseed.core"), autoload(fs, "aniseed.fs"), autoload(str, "aniseed.string"), autoload(nvim, "aniseed.nvim"), _1_, "aniseed.test", "fnl/aniseed/test.fnl" +str, a, fs, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(str, "aniseed.string"), autoload(a, "aniseed.core"), autoload(fs, "aniseed.fs"), autoload(nvim, "aniseed.nvim"), _1_, "aniseed.test", "fnl/aniseed/test.fnl" local ok_3f local function _3_(_2_) local _arg_0_ = _2_ diff --git a/module-system-plugin.fnl b/module-system-plugin.fnl index ce07e7e..0f0bfc0 100644 --- a/module-system-plugin.fnl +++ b/module-system-plugin.fnl @@ -1,7 +1,7 @@ (local syms (setmetatable {} {:__index #(sym $2)})) (fn table? [x] - (= :table (type x))) + (and (= :table (type x)) x)) (fn empty-table [t] (while (> (# t) 0) @@ -36,7 +36,7 @@ (fn module-form [ast {: scope : parent : opts : compile1}] (let [name-str (-?> (assert-compile - (sym? (. ast 2)) "expected symbol for module name" ast) + (sym? (. ast 2)) "expected module name" ast) tostring) all-new-local-fns (stringify-table (or (. ast 3) [])) (autoloads new-local-fns) (partition-by-key @@ -91,9 +91,9 @@ (copy [`local `(,(unpack names)) `(values ,(unpack vals))] ast)))) (fn def-form [ast {: scope : parent : opts : compile1 &as state} private? value?] - (let [name (. ast 2) + (let [name (assert-compile (sym? (. ast 2)) "expected name" ast) name-str (tostring name) - value (or value? (. ast 3)) + value (assert-compile (or value? (. ast 3)) "expected value" ast) mod-scope (if private? :locals :public)] (tset scope.module mod-scope name-str value) @@ -107,6 +107,10 @@ (fn defn-form [ast {: scope : parent : opts : compile1 &as state} private?] (let [[_ _ args & body] ast + args (assert-compile (table? (. ast 3)) "expected parameters table" ast) + body (assert-compile (-?>> (table? body) + (and (< 0 (length body)))) + "expected body expression" ast) fn-ast `(fn ,args)] (each [_ stmt (pairs body)] (table.insert fn-ast stmt)) @@ -114,8 +118,8 @@ (def-form ast state private? fn-ast))) (fn defonce-form [ast {: scope : parent : opts : compile1 &as state} private?] - (let [[_ name value] ast - name-str (tostring name) + (let [name-str (-?> (assert-compile (. ast 2) "expected name") + tostring) mod-scope (if private? :locals :public)] (if (. scope.module mod-scope name-str) (do @@ -125,7 +129,11 @@ (fn deftest-form [ast {: scope : parent : opts : compile1 &as state}] (let [[_ name & body] ast - name-str (tostring name) + name-str (-?> (assert-compile (. ast 2) "expected name") + tostring) + body (assert-compile (-?>> (table? body) + (and (< 0 (length body)))) + "expected body expression" ast) fn-sym (gensym) fn-ast `(fn ,fn-sym [,syms.t])] (each [_ stmt (pairs body)] @@ -143,6 +151,9 @@ (fn time-form [ast {: scope : parent : opts : compile1 &as state}] (let [[_ & body] ast + body (assert-compile (-?>> (table? body) + (and (< 0 (length body)))) + "expected body expression" ast) time-fn-sym (. scope.module :time-fn-sym) body-ast `(do)] (when (not time-fn-sym) diff --git a/test/fnl/aniseed/compile-test.fnl b/test/fnl/aniseed/compile-test.fnl index e7bb614..a8a918f 100644 --- a/test/fnl/aniseed/compile-test.fnl +++ b/test/fnl/aniseed/compile-test.fnl @@ -1,6 +1,5 @@ (module aniseed.compile-test - {autoload {a aniseed.core - compile aniseed.compile}}) + {autoload {compile aniseed.compile}}) (deftest str (let [(success result) (compile.str "(+ 10 20)")] diff --git a/test/fnl/aniseed/module-system-test.fnl b/test/fnl/aniseed/module-system-test.fnl index 690979e..aded150 100644 --- a/test/fnl/aniseed/module-system-test.fnl +++ b/test/fnl/aniseed/module-system-test.fnl @@ -1,4 +1,67 @@ -(module aniseed.module-system-test) +(module aniseed.module-system-test + {autoload {compile aniseed.compile}}) + +(deftest module + (local initial {:foo :bar}) + + (module module-test + {require {a_ aniseed.core} + autoload {compile_ aniseed.compile}} + initial) + + (t.= *module-name* :module-test + "*module-name* not defined") + + (t.= *file* :test/fnl/aniseed/module-system-test.fnl + "*file* not defined") + + (t.ok? (not= nil a_) "require aniseed.core failed") + (t.ok? (not= nil compile_) "autoload aniseed.compile failed") + + (t.= (. *module* :foo) (. initial :foo) + "failed to carry over initial-mod into *module*") + + (let [(ok? result) (compile.str "(module)")] + (t.ok? (not ok?) "compilation should return false") + (t.= 30 (result:find "expected module name")))) + +(deftest def + (module def-test) + + (def a 3) + (def- b 4) + + (t.= (* (. *module* :aniseed/locals :b) + (. package.loaded :def-test :a) + (. *module* :aniseed/locals :a)) + 36 "failed to set all *module* sub tables properly") + + (t.ok? (= nil (. package.loaded :def-test :b)) + "def- declared variable is public") + + (let [(ok? result) (compile.str "(def)")] + (t.ok? (not ok?) "compilation should return false") + (t.= 30 (result:find "expected name"))) + + (let [(ok? result) (compile.str "(def- name)")] + (t.ok? (not ok?) "compilation should return false") + (t.= 30 (result:find "expected value")))) + +(deftest defn + (module defn-test) + + (defn- f [x] (+ 2 x)) + (defn g [y z] (* 5 (- z (f y)))) + + (t.= ((. *module* :g) 2 7) 15 "failed to properly define defns") + + (let [(ok? result) (compile.str "(defn name)")] + (t.ok? (not ok?) "compilation should return false") + (t.= 30 (result:find "expected parameters table"))) + + (let [(ok? result) (compile.str "(defn- name [])")] + (t.ok? (not ok?) "compilation should return false") + (t.= 30 (result:find "expected body expression")))) (deftest defonce (var calls 0) @@ -9,4 +72,30 @@ (defonce foo (inc)) (t.= 1 calls) (defonce foo (inc)) - (t.= 1 calls)) + (t.= 1 calls) + + (let [(ok? result) (compile.str "(defonce)")] + (t.ok? (not ok?) "compilation should return false") + (t.= 30 (result:find "expected name")))) + +(deftest deftest- + (let [(ok? result) (compile.str "(deftest)")] + (t.ok? (not ok?) "compilation should return false") + (t.= 30 (result:find "expected name"))) + + (let [(ok? result) (compile.str "(deftest name)")] + (t.ok? (not ok?) "compilation should return false") + (t.= 30 (result:find "expected body expression")))) + +(deftest time + (local x 4) + (t.= (time + (local y 5) + (* x y)) + 20 "time function failed") + + (t.= (time 42) 42 "second time function failed") + + (let [(ok? result) (compile.str "(time)")] + (t.ok? (not ok?) "compilation should return false") + (t.= 30 (result:find "expected body expression")))) From fb866b085035a315e28190b0ee2d0f7d40324304 Mon Sep 17 00:00:00 2001 From: Andrew DeFilippo Date: Tue, 27 Jul 2021 09:24:21 -0500 Subject: [PATCH 06/11] Separated compile and runtime tests into their respective files. --- test/fnl/aniseed/compile-test.fnl | 37 ++++++++++++++++-- test/fnl/aniseed/module-system-test.fnl | 50 +++---------------------- 2 files changed, 40 insertions(+), 47 deletions(-) diff --git a/test/fnl/aniseed/compile-test.fnl b/test/fnl/aniseed/compile-test.fnl index a8a918f..e047b64 100644 --- a/test/fnl/aniseed/compile-test.fnl +++ b/test/fnl/aniseed/compile-test.fnl @@ -1,11 +1,42 @@ (module aniseed.compile-test {autoload {compile aniseed.compile}}) +(defn- compile-fail [t code loc msg] + (let [(success result) (compile.str code)] + (t.ok? (not success) "compilation should fail") + (t.= loc (result:find msg)))) + (deftest str (let [(success result) (compile.str "(+ 10 20)")] (t.ok? success "compilation should return true") (t.= "return (10 + 20)" result "results include a return and parens")) - (let [(success result) (compile.str "(+ 10 20")] - (t.ok? (not success)) - (t.= 28 (result:find "expected closing delimiter")))) + (compile-fail t "(+ 10 20" 28 "expected closing delimiter")) + +(deftest module + (compile-fail t "(module)" 30 "expected module name")) + +(deftest def + (compile-fail t "(def)" 30 "expected name") + (compile-fail t "(def-)" 30 "expected name") + + (compile-fail t "(def name)" 30 "expected value") + (compile-fail t "(def- name)" 30 "expected value")) + +(deftest defn + (compile-fail t "(defn name)" 30 "expected parameters table") + (compile-fail t "(defn- name)" 30 "expected parameters table") + + (compile-fail t "(defn name [])" 30 "expected body expression") + (compile-fail t "(defn- name [])" 30 "expected body expression")) + +(deftest defonce + (compile-fail t "(defonce)" 30 "expected name") + (compile-fail t "(defonce-)" 30 "expected name")) + +(deftest deftest + (compile-fail t "(deftest)" 30 "expected name") + (compile-fail t "(deftest name)" 30 "expected body expression")) + +(deftest time + (compile-fail t "(time)" 30 "expected body expression")) diff --git a/test/fnl/aniseed/module-system-test.fnl b/test/fnl/aniseed/module-system-test.fnl index aded150..0e19828 100644 --- a/test/fnl/aniseed/module-system-test.fnl +++ b/test/fnl/aniseed/module-system-test.fnl @@ -1,5 +1,4 @@ -(module aniseed.module-system-test - {autoload {compile aniseed.compile}}) +(module aniseed.module-system-test) (deftest module (local initial {:foo :bar}) @@ -19,11 +18,7 @@ (t.ok? (not= nil compile_) "autoload aniseed.compile failed") (t.= (. *module* :foo) (. initial :foo) - "failed to carry over initial-mod into *module*") - - (let [(ok? result) (compile.str "(module)")] - (t.ok? (not ok?) "compilation should return false") - (t.= 30 (result:find "expected module name")))) + "failed to carry over initial-mod into *module*")) (deftest def (module def-test) @@ -37,15 +32,7 @@ 36 "failed to set all *module* sub tables properly") (t.ok? (= nil (. package.loaded :def-test :b)) - "def- declared variable is public") - - (let [(ok? result) (compile.str "(def)")] - (t.ok? (not ok?) "compilation should return false") - (t.= 30 (result:find "expected name"))) - - (let [(ok? result) (compile.str "(def- name)")] - (t.ok? (not ok?) "compilation should return false") - (t.= 30 (result:find "expected value")))) + "def- declared variable is public")) (deftest defn (module defn-test) @@ -53,15 +40,7 @@ (defn- f [x] (+ 2 x)) (defn g [y z] (* 5 (- z (f y)))) - (t.= ((. *module* :g) 2 7) 15 "failed to properly define defns") - - (let [(ok? result) (compile.str "(defn name)")] - (t.ok? (not ok?) "compilation should return false") - (t.= 30 (result:find "expected parameters table"))) - - (let [(ok? result) (compile.str "(defn- name [])")] - (t.ok? (not ok?) "compilation should return false") - (t.= 30 (result:find "expected body expression")))) + (t.= ((. *module* :g) 2 7) 15 "failed to properly define defns")) (deftest defonce (var calls 0) @@ -72,20 +51,7 @@ (defonce foo (inc)) (t.= 1 calls) (defonce foo (inc)) - (t.= 1 calls) - - (let [(ok? result) (compile.str "(defonce)")] - (t.ok? (not ok?) "compilation should return false") - (t.= 30 (result:find "expected name")))) - -(deftest deftest- - (let [(ok? result) (compile.str "(deftest)")] - (t.ok? (not ok?) "compilation should return false") - (t.= 30 (result:find "expected name"))) - - (let [(ok? result) (compile.str "(deftest name)")] - (t.ok? (not ok?) "compilation should return false") - (t.= 30 (result:find "expected body expression")))) + (t.= 1 calls)) (deftest time (local x 4) @@ -94,8 +60,4 @@ (* x y)) 20 "time function failed") - (t.= (time 42) 42 "second time function failed") - - (let [(ok? result) (compile.str "(time)")] - (t.ok? (not ok?) "compilation should return false") - (t.= 30 (result:find "expected body expression")))) + (t.= (time 42) 42 "second time function failed")) From a8c37523f5989e5191931682d36eda296a20abaf Mon Sep 17 00:00:00 2001 From: Andrew DeFilippo Date: Tue, 27 Jul 2021 10:36:52 -0500 Subject: [PATCH 07/11] Update generated autoload autoload function, slightly cleaner Lua emitted now. --- lua/aniseed/compile.lua | 54 ++++---- lua/aniseed/core.lua | 280 +++++++++++++++++++------------------- lua/aniseed/env.lua | 30 ++-- lua/aniseed/eval.lua | 22 ++- lua/aniseed/fennel.lua | 24 ++-- lua/aniseed/fs.lua | 38 +++--- lua/aniseed/nvim/util.lua | 44 +++--- lua/aniseed/string.lua | 52 ++++--- lua/aniseed/test.lua | 86 ++++++------ module-system-plugin.fnl | 3 +- 10 files changed, 298 insertions(+), 335 deletions(-) diff --git a/lua/aniseed/compile.lua b/lua/aniseed/compile.lua index 481d613..35f6790 100644 --- a/lua/aniseed/compile.lua +++ b/lua/aniseed/compile.lua @@ -1,32 +1,28 @@ -local autoload -local function _0_(...) - return (require("aniseed.autoload")).autoload(...) -end -autoload = _0_ -local nvim, a, fs, fennel, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil -local _1_ +local autoload = (require("aniseed.autoload")).autoload +local a, fs, fennel, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil +local _0_ do local mod_0_ = {["aniseed/local-fns"] = {autoload = {a = "aniseed.core", fennel = "aniseed.fennel", fs = "aniseed.fs", nvim = "aniseed.nvim"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.compile"} package.loaded["aniseed.compile"] = mod_0_ - _1_ = mod_0_ + _0_ = mod_0_ end -nvim, a, fs, fennel, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(nvim, "aniseed.nvim"), autoload(a, "aniseed.core"), autoload(fs, "aniseed.fs"), autoload(fennel, "aniseed.fennel"), _1_, "aniseed.compile", "fnl/aniseed/compile.fnl" +a, fs, fennel, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(a, "aniseed.core"), autoload(fs, "aniseed.fs"), autoload(fennel, "aniseed.fennel"), autoload(nvim, "aniseed.nvim"), _0_, "aniseed.compile", "fnl/aniseed/compile.fnl" local base_path do - local _2_ = (debug.getinfo(1, "S")).source - if _2_ then - local _3_ = _2_:gsub("^.", "") - if _3_ then - base_path = _3_:gsub(string.gsub(_2afile_2a, "fnl", "lua"), "") + local _1_ = (debug.getinfo(1, "S")).source + if _1_ then + local _2_ = _1_:gsub("^.", "") + if _2_ then + base_path = _2_:gsub(string.gsub(_2afile_2a, "fnl", "lua"), "") else - base_path = _3_ + base_path = _2_ end else - base_path = _2_ + base_path = _1_ end end local str -local function _3_(code, opts) +local function _2_(code, opts) local fnl = fennel.impl() local plugins = {"module-system-plugin.fnl"} local plugins0 @@ -37,32 +33,32 @@ local function _3_(code, opts) end plugins0 = tbl_0_ end - local function _4_() + local function _3_() return fnl.compileString(code, a.merge({allowedGlobals = false, plugins = plugins0}, opts)) end - return xpcall(_4_, fnl.traceback) + return xpcall(_3_, fnl.traceback) end -str = _3_ +str = _2_ _2amodule_2a["str"] = str _2amodule_2a["aniseed/locals"]["str"] = str local file -local function _4_(src, dest) +local function _3_(src, dest) local code = a.slurp(src) - local _5_, _6_ = str(code, {filename = src}) - if ((_5_ == false) and (nil ~= _6_)) then - local err = _6_ + local _4_, _5_ = str(code, {filename = src}) + if ((_4_ == false) and (nil ~= _5_)) then + local err = _5_ return nvim.err_writeln(err) - elseif ((_5_ == true) and (nil ~= _6_)) then - local result = _6_ + elseif ((_4_ == true) and (nil ~= _5_)) then + local result = _5_ fs.mkdirp(fs.basename(dest)) return a.spit(dest, result) end end -file = _4_ +file = _3_ _2amodule_2a["file"] = file _2amodule_2a["aniseed/locals"]["file"] = file local glob -local function _5_(src_expr, src_dir, dest_dir) +local function _4_(src_expr, src_dir, dest_dir) for _, path in ipairs(fs.relglob(src_dir, src_expr)) do if fs["macro-file-path?"](path) then a.spit((dest_dir .. path), a.slurp((src_dir .. path))) @@ -72,7 +68,7 @@ local function _5_(src_expr, src_dir, dest_dir) end return nil end -glob = _5_ +glob = _4_ _2amodule_2a["glob"] = glob _2amodule_2a["aniseed/locals"]["glob"] = glob return nil diff --git a/lua/aniseed/core.lua b/lua/aniseed/core.lua index 2b86153..f9e2de7 100644 --- a/lua/aniseed/core.lua +++ b/lua/aniseed/core.lua @@ -1,47 +1,43 @@ -local autoload -local function _0_(...) - return (require("aniseed.autoload")).autoload(...) -end -autoload = _0_ +local autoload = (require("aniseed.autoload")).autoload local view, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil -local _1_ +local _0_ do local mod_0_ = {["aniseed/local-fns"] = {autoload = {view = "aniseed.view"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.core"} package.loaded["aniseed.core"] = mod_0_ - _1_ = mod_0_ + _0_ = mod_0_ end -view, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(view, "aniseed.view"), _1_, "aniseed.core", "fnl/aniseed/core.fnl" +view, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(view, "aniseed.view"), _0_, "aniseed.core", "fnl/aniseed/core.fnl" math.randomseed(os.time()) local rand -local function _2_(n) +local function _1_(n) return (math.random() * (n or 1)) end -rand = _2_ +rand = _1_ _2amodule_2a["rand"] = rand _2amodule_2a["aniseed/locals"]["rand"] = rand local string_3f -local function _3_(x) +local function _2_(x) return ("string" == type(x)) end -string_3f = _3_ +string_3f = _2_ _2amodule_2a["string?"] = string_3f _2amodule_2a["aniseed/locals"]["string?"] = string_3f local nil_3f -local function _4_(x) +local function _3_(x) return (nil == x) end -nil_3f = _4_ +nil_3f = _3_ _2amodule_2a["nil?"] = nil_3f _2amodule_2a["aniseed/locals"]["nil?"] = nil_3f local table_3f -local function _5_(x) +local function _4_(x) return ("table" == type(x)) end -table_3f = _5_ +table_3f = _4_ _2amodule_2a["table?"] = table_3f _2amodule_2a["aniseed/locals"]["table?"] = table_3f local count -local function _6_(xs) +local function _5_(xs) if table_3f(xs) then return table.maxn(xs) elseif not xs then @@ -50,73 +46,73 @@ local function _6_(xs) return #xs end end -count = _6_ +count = _5_ _2amodule_2a["count"] = count _2amodule_2a["aniseed/locals"]["count"] = count local empty_3f -local function _7_(xs) +local function _6_(xs) return (0 == count(xs)) end -empty_3f = _7_ +empty_3f = _6_ _2amodule_2a["empty?"] = empty_3f _2amodule_2a["aniseed/locals"]["empty?"] = empty_3f local first -local function _8_(xs) +local function _7_(xs) if xs then return xs[1] end end -first = _8_ +first = _7_ _2amodule_2a["first"] = first _2amodule_2a["aniseed/locals"]["first"] = first local second -local function _9_(xs) +local function _8_(xs) if xs then return xs[2] end end -second = _9_ +second = _8_ _2amodule_2a["second"] = second _2amodule_2a["aniseed/locals"]["second"] = second local last -local function _10_(xs) +local function _9_(xs) if xs then return xs[count(xs)] end end -last = _10_ +last = _9_ _2amodule_2a["last"] = last _2amodule_2a["aniseed/locals"]["last"] = last local inc -local function _11_(n) +local function _10_(n) return (n + 1) end -inc = _11_ +inc = _10_ _2amodule_2a["inc"] = inc _2amodule_2a["aniseed/locals"]["inc"] = inc local dec -local function _12_(n) +local function _11_(n) return (n - 1) end -dec = _12_ +dec = _11_ _2amodule_2a["dec"] = dec _2amodule_2a["aniseed/locals"]["dec"] = dec local even_3f -local function _13_(n) +local function _12_(n) return ((n % 2) == 0) end -even_3f = _13_ +even_3f = _12_ _2amodule_2a["even?"] = even_3f _2amodule_2a["aniseed/locals"]["even?"] = even_3f local odd_3f -local function _14_(n) +local function _13_(n) return not even_3f(n) end -odd_3f = _14_ +odd_3f = _13_ _2amodule_2a["odd?"] = odd_3f _2amodule_2a["aniseed/locals"]["odd?"] = odd_3f local keys -local function _15_(t) +local function _14_(t) local result = {} if t then for k, _ in pairs(t) do @@ -125,11 +121,11 @@ local function _15_(t) end return result end -keys = _15_ +keys = _14_ _2amodule_2a["keys"] = keys _2amodule_2a["aniseed/locals"]["keys"] = keys local vals -local function _16_(t) +local function _15_(t) local result = {} if t then for _, v in pairs(t) do @@ -138,11 +134,11 @@ local function _16_(t) end return result end -vals = _16_ +vals = _15_ _2amodule_2a["vals"] = vals _2amodule_2a["aniseed/locals"]["vals"] = vals local kv_pairs -local function _17_(t) +local function _16_(t) local result = {} if t then for k, v in pairs(t) do @@ -151,11 +147,11 @@ local function _17_(t) end return result end -kv_pairs = _17_ +kv_pairs = _16_ _2amodule_2a["kv-pairs"] = kv_pairs _2amodule_2a["aniseed/locals"]["kv-pairs"] = kv_pairs local run_21 -local function _18_(f, xs) +local function _17_(f, xs) if xs then local nxs = count(xs) if (nxs > 0) then @@ -166,72 +162,72 @@ local function _18_(f, xs) end end end -run_21 = _18_ +run_21 = _17_ _2amodule_2a["run!"] = run_21 _2amodule_2a["aniseed/locals"]["run!"] = run_21 local filter -local function _19_(f, xs) +local function _18_(f, xs) local result = {} - local function _20_(x) + local function _19_(x) if f(x) then return table.insert(result, x) end end - run_21(_20_, xs) + run_21(_19_, xs) return result end -filter = _19_ +filter = _18_ _2amodule_2a["filter"] = filter _2amodule_2a["aniseed/locals"]["filter"] = filter local map -local function _20_(f, xs) +local function _19_(f, xs) local result = {} - local function _21_(x) + local function _20_(x) local mapped = f(x) - local function _22_() + local function _21_() if (0 == select("#", mapped)) then return nil else return mapped end end - return table.insert(result, _22_()) + return table.insert(result, _21_()) end - run_21(_21_, xs) + run_21(_20_, xs) return result end -map = _20_ +map = _19_ _2amodule_2a["map"] = map _2amodule_2a["aniseed/locals"]["map"] = map local map_indexed -local function _21_(f, xs) +local function _20_(f, xs) return map(f, kv_pairs(xs)) end -map_indexed = _21_ +map_indexed = _20_ _2amodule_2a["map-indexed"] = map_indexed _2amodule_2a["aniseed/locals"]["map-indexed"] = map_indexed local identity -local function _22_(x) +local function _21_(x) return x end -identity = _22_ +identity = _21_ _2amodule_2a["identity"] = identity _2amodule_2a["aniseed/locals"]["identity"] = identity local reduce -local function _23_(f, init, xs) +local function _22_(f, init, xs) local result = init - local function _24_(x) + local function _23_(x) result = f(result, x) return nil end - run_21(_24_, xs) + run_21(_23_, xs) return result end -reduce = _23_ +reduce = _22_ _2amodule_2a["reduce"] = reduce _2amodule_2a["aniseed/locals"]["reduce"] = reduce local some -local function _24_(f, xs) +local function _23_(f, xs) local result = nil local n = 1 while (nil_3f(result) and (n <= count(xs))) do @@ -243,98 +239,98 @@ local function _24_(f, xs) end return result end -some = _24_ +some = _23_ _2amodule_2a["some"] = some _2amodule_2a["aniseed/locals"]["some"] = some local butlast -local function _25_(xs) +local function _24_(xs) local total = count(xs) - local function _27_(_26_) - local _arg_0_ = _26_ + local function _26_(_25_) + local _arg_0_ = _25_ local n = _arg_0_[1] local v = _arg_0_[2] return (n ~= total) end - return map(second, filter(_27_, kv_pairs(xs))) + return map(second, filter(_26_, kv_pairs(xs))) end -butlast = _25_ +butlast = _24_ _2amodule_2a["butlast"] = butlast _2amodule_2a["aniseed/locals"]["butlast"] = butlast local rest -local function _26_(xs) - local function _28_(_27_) - local _arg_0_ = _27_ +local function _25_(xs) + local function _27_(_26_) + local _arg_0_ = _26_ local n = _arg_0_[1] local v = _arg_0_[2] return (n ~= 1) end - return map(second, filter(_28_, kv_pairs(xs))) + return map(second, filter(_27_, kv_pairs(xs))) end -rest = _26_ +rest = _25_ _2amodule_2a["rest"] = rest _2amodule_2a["aniseed/locals"]["rest"] = rest local concat -local function _27_(...) +local function _26_(...) local result = {} - local function _28_(xs) - local function _29_(x) + local function _27_(xs) + local function _28_(x) return table.insert(result, x) end - return run_21(_29_, xs) + return run_21(_28_, xs) end - run_21(_28_, {...}) + run_21(_27_, {...}) return result end -concat = _27_ +concat = _26_ _2amodule_2a["concat"] = concat _2amodule_2a["aniseed/locals"]["concat"] = concat local mapcat -local function _28_(f, xs) +local function _27_(f, xs) return concat(unpack(map(f, xs))) end -mapcat = _28_ +mapcat = _27_ _2amodule_2a["mapcat"] = mapcat _2amodule_2a["aniseed/locals"]["mapcat"] = mapcat local pr_str -local function _29_(...) +local function _28_(...) local s - local function _30_(x) + local function _29_(x) return view.serialise(x, {["one-line"] = true}) end - s = table.concat(map(_30_, {...}), " ") + s = table.concat(map(_29_, {...}), " ") if (nil_3f(s) or ("" == s)) then return "nil" else return s end end -pr_str = _29_ +pr_str = _28_ _2amodule_2a["pr-str"] = pr_str _2amodule_2a["aniseed/locals"]["pr-str"] = pr_str local str -local function _30_(...) - local function _31_(acc, s) +local function _29_(...) + local function _30_(acc, s) return (acc .. s) end - local function _32_(s) + local function _31_(s) if string_3f(s) then return s else return pr_str(s) end end - return reduce(_31_, "", map(_32_, {...})) + return reduce(_30_, "", map(_31_, {...})) end -str = _30_ +str = _29_ _2amodule_2a["str"] = str _2amodule_2a["aniseed/locals"]["str"] = str local println -local function _31_(...) - local function _32_(acc, s) +local function _30_(...) + local function _31_(acc, s) return (acc .. s) end - local function _34_(_33_) - local _arg_0_ = _33_ + local function _33_(_32_) + local _arg_0_ = _32_ local i = _arg_0_[1] local s = _arg_0_[2] if (1 == i) then @@ -343,60 +339,60 @@ local function _31_(...) return (" " .. s) end end - local function _35_(s) + local function _34_(s) if string_3f(s) then return s else return pr_str(s) end end - return print(reduce(_32_, "", map_indexed(_34_, map(_35_, {...})))) + return print(reduce(_31_, "", map_indexed(_33_, map(_34_, {...})))) end -println = _31_ +println = _30_ _2amodule_2a["println"] = println _2amodule_2a["aniseed/locals"]["println"] = println local pr -local function _32_(...) +local function _31_(...) return println(pr_str(...)) end -pr = _32_ +pr = _31_ _2amodule_2a["pr"] = pr _2amodule_2a["aniseed/locals"]["pr"] = pr local slurp -local function _33_(path, silent_3f) - local _34_, _35_ = io.open(path, "r") - if ((_34_ == nil) and (nil ~= _35_)) then - local msg = _35_ +local function _32_(path, silent_3f) + local _33_, _34_ = io.open(path, "r") + if ((_33_ == nil) and (nil ~= _34_)) then + local msg = _34_ return nil - elseif (nil ~= _34_) then - local f = _34_ + elseif (nil ~= _33_) then + local f = _33_ local content = f:read("*all") f:close() return content end end -slurp = _33_ +slurp = _32_ _2amodule_2a["slurp"] = slurp _2amodule_2a["aniseed/locals"]["slurp"] = slurp local spit -local function _34_(path, content) - local _35_, _36_ = io.open(path, "w") - if ((_35_ == nil) and (nil ~= _36_)) then - local msg = _36_ +local function _33_(path, content) + local _34_, _35_ = io.open(path, "w") + if ((_34_ == nil) and (nil ~= _35_)) then + local msg = _35_ return error(("Could not open file: " .. msg)) - elseif (nil ~= _35_) then - local f = _35_ + elseif (nil ~= _34_) then + local f = _34_ f:write(content) f:close() return nil end end -spit = _34_ +spit = _33_ _2amodule_2a["spit"] = spit _2amodule_2a["aniseed/locals"]["spit"] = spit local merge_21 -local function _35_(base, ...) - local function _36_(acc, m) +local function _34_(base, ...) + local function _35_(acc, m) if m then for k, v in pairs(m) do acc[k] = v @@ -404,37 +400,37 @@ local function _35_(base, ...) end return acc end - return reduce(_36_, (base or {}), {...}) + return reduce(_35_, (base or {}), {...}) end -merge_21 = _35_ +merge_21 = _34_ _2amodule_2a["merge!"] = merge_21 _2amodule_2a["aniseed/locals"]["merge!"] = merge_21 local merge -local function _36_(...) +local function _35_(...) return merge_21({}, ...) end -merge = _36_ +merge = _35_ _2amodule_2a["merge"] = merge _2amodule_2a["aniseed/locals"]["merge"] = merge local select_keys -local function _37_(t, ks) +local function _36_(t, ks) if (t and ks) then - local function _38_(acc, k) + local function _37_(acc, k) if k then acc[k] = t[k] end return acc end - return reduce(_38_, {}, ks) + return reduce(_37_, {}, ks) else return {} end end -select_keys = _37_ +select_keys = _36_ _2amodule_2a["select-keys"] = select_keys _2amodule_2a["aniseed/locals"]["select-keys"] = select_keys local get -local function _38_(t, k, d) +local function _37_(t, k, d) local res if table_3f(t) then local val = t[k] @@ -452,29 +448,29 @@ local function _38_(t, k, d) return res end end -get = _38_ +get = _37_ _2amodule_2a["get"] = get _2amodule_2a["aniseed/locals"]["get"] = get local get_in -local function _39_(t, ks, d) +local function _38_(t, ks, d) local res - local function _40_(acc, k) + local function _39_(acc, k) if table_3f(acc) then return get(acc, k) end end - res = reduce(_40_, t, ks) + res = reduce(_39_, t, ks) if nil_3f(res) then return d else return res end end -get_in = _39_ +get_in = _38_ _2amodule_2a["get-in"] = get_in _2amodule_2a["aniseed/locals"]["get-in"] = get_in local assoc -local function _40_(t, ...) +local function _39_(t, ...) local _let_0_ = {...} local k = _let_0_[1] local v = _let_0_[2] @@ -492,15 +488,15 @@ local function _40_(t, ...) end return t0 end -assoc = _40_ +assoc = _39_ _2amodule_2a["assoc"] = assoc _2amodule_2a["aniseed/locals"]["assoc"] = assoc local assoc_in -local function _41_(t, ks, v) +local function _40_(t, ks, v) local path = butlast(ks) local final = last(ks) local t0 = (t or {}) - local function _42_(acc, k) + local function _41_(acc, k) local step = get(acc, k) if nil_3f(step) then return get(assoc(acc, k, {}), k) @@ -508,34 +504,34 @@ local function _41_(t, ks, v) return step end end - assoc(reduce(_42_, t0, path), final, v) + assoc(reduce(_41_, t0, path), final, v) return t0 end -assoc_in = _41_ +assoc_in = _40_ _2amodule_2a["assoc-in"] = assoc_in _2amodule_2a["aniseed/locals"]["assoc-in"] = assoc_in local update -local function _42_(t, k, f) +local function _41_(t, k, f) return assoc(t, k, f(get(t, k))) end -update = _42_ +update = _41_ _2amodule_2a["update"] = update _2amodule_2a["aniseed/locals"]["update"] = update local update_in -local function _43_(t, ks, f) +local function _42_(t, ks, f) return assoc_in(t, ks, f(get_in(t, ks))) end -update_in = _43_ +update_in = _42_ _2amodule_2a["update-in"] = update_in _2amodule_2a["aniseed/locals"]["update-in"] = update_in local constantly -local function _44_(v) - local function _45_() +local function _43_(v) + local function _44_() return v end - return _45_ + return _44_ end -constantly = _44_ +constantly = _43_ _2amodule_2a["constantly"] = constantly _2amodule_2a["aniseed/locals"]["constantly"] = constantly return nil diff --git a/lua/aniseed/env.lua b/lua/aniseed/env.lua index ab3a2d8..bf04be3 100644 --- a/lua/aniseed/env.lua +++ b/lua/aniseed/env.lua @@ -1,33 +1,29 @@ -local autoload -local function _0_(...) - return (require("aniseed.autoload")).autoload(...) -end -autoload = _0_ -local fennel, compile, nvim, fs, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil -local _1_ +local autoload = (require("aniseed.autoload")).autoload +local nvim, compile, fs, fennel, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil +local _0_ do local mod_0_ = {["aniseed/local-fns"] = {autoload = {compile = "aniseed.compile", fennel = "aniseed.fennel", fs = "aniseed.fs", nvim = "aniseed.nvim"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.env"} package.loaded["aniseed.env"] = mod_0_ - _1_ = mod_0_ + _0_ = mod_0_ end -fennel, compile, nvim, fs, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(fennel, "aniseed.fennel"), autoload(compile, "aniseed.compile"), autoload(nvim, "aniseed.nvim"), autoload(fs, "aniseed.fs"), _1_, "aniseed.env", "fnl/aniseed/env.fnl" +nvim, compile, fs, fennel, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(nvim, "aniseed.nvim"), autoload(compile, "aniseed.compile"), autoload(fs, "aniseed.fs"), autoload(fennel, "aniseed.fennel"), _0_, "aniseed.env", "fnl/aniseed/env.fnl" local config_dir = nvim.fn.stdpath("config") do end (_2amodule_2a)["aniseed/locals"]["config-dir"] = config_dir local quiet_require -local function _2_(m) +local function _1_(m) local ok_3f, err = nil, nil - local function _3_() + local function _2_() return require(m) end - ok_3f, err = pcall(_3_) + ok_3f, err = pcall(_2_) if (not ok_3f and not err:find(("module '" .. m .. "' not found"))) then return nvim.ex.echoerr(err) end end -quiet_require = _2_ +quiet_require = _1_ _2amodule_2a["aniseed/locals"]["quiet-require"] = quiet_require local init -local function _3_(opts) +local function _2_(opts) local opts0 if ("table" == type(opts)) then opts0 = opts @@ -38,20 +34,20 @@ local function _3_(opts) local fnl_dir = (opts0.input or (config_dir .. fs["path-sep"] .. "fnl")) local lua_dir = (opts0.output or (config_dir .. fs["path-sep"] .. "lua")) package.path = (package.path .. ";" .. lua_dir .. fs["path-sep"] .. "?.lua") - local function _5_(path) + local function _4_(path) if fs["macro-file-path?"](path) then return path else return string.gsub(path, ".fnl$", ".lua") end end - if (((false ~= opts0.compile) or os.getenv("ANISEED_ENV_COMPILE")) and fs["glob-dir-newer?"](fnl_dir, lua_dir, glob_expr, _5_)) then + if (((false ~= opts0.compile) or os.getenv("ANISEED_ENV_COMPILE")) and fs["glob-dir-newer?"](fnl_dir, lua_dir, glob_expr, _4_)) then fennel["add-path"]((fnl_dir .. fs["path-sep"] .. "?.fnl")) compile.glob(glob_expr, fnl_dir, lua_dir, opts0) end return quiet_require((opts0.module or "init")) end -init = _3_ +init = _2_ _2amodule_2a["init"] = init _2amodule_2a["aniseed/locals"]["init"] = init return nil diff --git a/lua/aniseed/eval.lua b/lua/aniseed/eval.lua index e1511ae..6871eff 100644 --- a/lua/aniseed/eval.lua +++ b/lua/aniseed/eval.lua @@ -1,25 +1,21 @@ -local autoload -local function _0_(...) - return (require("aniseed.autoload")).autoload(...) -end -autoload = _0_ -local fennel, fs, a, compile, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil, nil -local _1_ +local autoload = (require("aniseed.autoload")).autoload +local fennel, a, fs, nvim, compile, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil, nil +local _0_ do local mod_0_ = {["aniseed/local-fns"] = {autoload = {a = "aniseed.core", compile = "aniseed.compile", fennel = "aniseed.fennel", fs = "aniseed.fs", nvim = "aniseed.nvim"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.eval"} package.loaded["aniseed.eval"] = mod_0_ - _1_ = mod_0_ + _0_ = mod_0_ end -fennel, fs, a, compile, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(fennel, "aniseed.fennel"), autoload(fs, "aniseed.fs"), autoload(a, "aniseed.core"), autoload(compile, "aniseed.compile"), autoload(nvim, "aniseed.nvim"), _1_, "aniseed.eval", "fnl/aniseed/eval.fnl" +fennel, a, fs, nvim, compile, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(fennel, "aniseed.fennel"), autoload(a, "aniseed.core"), autoload(fs, "aniseed.fs"), autoload(nvim, "aniseed.nvim"), autoload(compile, "aniseed.compile"), _0_, "aniseed.eval", "fnl/aniseed/eval.fnl" local str -local function _2_(code, opts) +local function _1_(code, opts) local fnl = fennel.impl() - local function _3_() + local function _2_() return fnl.eval(compile["macros-prefix"](code, opts), a.merge({["compiler-env"] = _G}, opts)) end - return xpcall(_3_, fnl.traceback) + return xpcall(_2_, fnl.traceback) end -str = _2_ +str = _1_ _2amodule_2a["str"] = str _2amodule_2a["aniseed/locals"]["str"] = str return nil diff --git a/lua/aniseed/fennel.lua b/lua/aniseed/fennel.lua index 07646ca..8dcd6d1 100644 --- a/lua/aniseed/fennel.lua +++ b/lua/aniseed/fennel.lua @@ -1,18 +1,14 @@ -local autoload -local function _0_(...) - return (require("aniseed.autoload")).autoload(...) -end -autoload = _0_ +local autoload = (require("aniseed.autoload")).autoload local nvim, fs, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil -local _1_ +local _0_ do local mod_0_ = {["aniseed/local-fns"] = {autoload = {fs = "aniseed.fs", nvim = "aniseed.nvim"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.fennel"} package.loaded["aniseed.fennel"] = mod_0_ - _1_ = mod_0_ + _0_ = mod_0_ end -nvim, fs, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(nvim, "aniseed.nvim"), autoload(fs, "aniseed.fs"), _1_, "aniseed.fennel", "fnl/aniseed/fennel.fnl" +nvim, fs, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(nvim, "aniseed.nvim"), autoload(fs, "aniseed.fs"), _0_, "aniseed.fennel", "fnl/aniseed/fennel.fnl" local sync_rtp -local function _2_(compiler) +local function _1_(compiler) local sep = fs["path-sep"] local fnl_suffix = (sep .. "fnl" .. sep .. "?.fnl") local rtp = nvim.o.runtimepath @@ -21,13 +17,13 @@ local function _2_(compiler) do end (compiler)["path"] = (fnl_path .. ";" .. lua_path) return nil end -sync_rtp = _2_ +sync_rtp = _1_ _2amodule_2a["sync-rtp"] = sync_rtp _2amodule_2a["aniseed/locals"]["sync-rtp"] = sync_rtp local state = {["compiler-loaded?"] = false} _2amodule_2a["aniseed/locals"]["state"] = state local impl -local function _3_() +local function _2_() local compiler = require("aniseed.deps.fennel") if not state["compiler-loaded?"] then state["compiler-loaded?"] = true @@ -35,16 +31,16 @@ local function _3_() end return compiler end -impl = _3_ +impl = _2_ _2amodule_2a["impl"] = impl _2amodule_2a["aniseed/locals"]["impl"] = impl local add_path -local function _4_(path) +local function _3_(path) local fnl = impl() do end (fnl)["path"] = (fnl.path .. ";" .. path) return nil end -add_path = _4_ +add_path = _3_ _2amodule_2a["add-path"] = add_path _2amodule_2a["aniseed/locals"]["add-path"] = add_path return nil diff --git a/lua/aniseed/fs.lua b/lua/aniseed/fs.lua index 7edb0ed..cacbc44 100644 --- a/lua/aniseed/fs.lua +++ b/lua/aniseed/fs.lua @@ -1,16 +1,12 @@ -local autoload -local function _0_(...) - return (require("aniseed.autoload")).autoload(...) -end -autoload = _0_ -local nvim, a, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil -local _1_ +local autoload = (require("aniseed.autoload")).autoload +local a, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil +local _0_ do local mod_0_ = {["aniseed/local-fns"] = {autoload = {a = "aniseed.core", nvim = "aniseed.nvim"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.fs"} package.loaded["aniseed.fs"] = mod_0_ - _1_ = mod_0_ + _0_ = mod_0_ end -nvim, a, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(nvim, "aniseed.nvim"), autoload(a, "aniseed.core"), _1_, "aniseed.fs", "fnl/aniseed/fs.fnl" +a, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(a, "aniseed.core"), autoload(nvim, "aniseed.nvim"), _0_, "aniseed.fs", "fnl/aniseed/fs.fnl" local path_sep do local os = string.lower(jit.os) @@ -23,32 +19,32 @@ end _2amodule_2a["path-sep"] = path_sep _2amodule_2a["aniseed/locals"]["path-sep"] = path_sep local basename -local function _2_(path) +local function _1_(path) return nvim.fn.fnamemodify(path, ":h") end -basename = _2_ +basename = _1_ _2amodule_2a["basename"] = basename _2amodule_2a["aniseed/locals"]["basename"] = basename local mkdirp -local function _3_(dir) +local function _2_(dir) return nvim.fn.mkdir(dir, "p") end -mkdirp = _3_ +mkdirp = _2_ _2amodule_2a["mkdirp"] = mkdirp _2amodule_2a["aniseed/locals"]["mkdirp"] = mkdirp local relglob -local function _4_(dir, expr) +local function _3_(dir, expr) local dir_len = a.inc(string.len(dir)) - local function _5_(_241) + local function _4_(_241) return string.sub(_241, dir_len) end - return a.map(_5_, nvim.fn.globpath(dir, expr, true, true)) + return a.map(_4_, nvim.fn.globpath(dir, expr, true, true)) end -relglob = _4_ +relglob = _3_ _2amodule_2a["relglob"] = relglob _2amodule_2a["aniseed/locals"]["relglob"] = relglob local glob_dir_newer_3f -local function _5_(a_dir, b_dir, expr, b_dir_path_fn) +local function _4_(a_dir, b_dir, expr, b_dir_path_fn) local newer_3f = false for _, path in ipairs(relglob(a_dir, expr)) do if (nvim.fn.getftime((a_dir .. path)) > nvim.fn.getftime((b_dir .. b_dir_path_fn(path)))) then @@ -57,14 +53,14 @@ local function _5_(a_dir, b_dir, expr, b_dir_path_fn) end return newer_3f end -glob_dir_newer_3f = _5_ +glob_dir_newer_3f = _4_ _2amodule_2a["glob-dir-newer?"] = glob_dir_newer_3f _2amodule_2a["aniseed/locals"]["glob-dir-newer?"] = glob_dir_newer_3f local macro_file_path_3f -local function _6_(path) +local function _5_(path) return string.match(path, "macros.fnl$") end -macro_file_path_3f = _6_ +macro_file_path_3f = _5_ _2amodule_2a["macro-file-path?"] = macro_file_path_3f _2amodule_2a["aniseed/locals"]["macro-file-path?"] = macro_file_path_3f return nil diff --git a/lua/aniseed/nvim/util.lua b/lua/aniseed/nvim/util.lua index 859d172..3c267fe 100644 --- a/lua/aniseed/nvim/util.lua +++ b/lua/aniseed/nvim/util.lua @@ -1,53 +1,49 @@ -local autoload -local function _0_(...) - return (require("aniseed.autoload")).autoload(...) -end -autoload = _0_ +local autoload = (require("aniseed.autoload")).autoload local nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil -local _1_ +local _0_ do local mod_0_ = {["aniseed/local-fns"] = {autoload = {nvim = "aniseed.nvim"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.nvim.util"} package.loaded["aniseed.nvim.util"] = mod_0_ - _1_ = mod_0_ + _0_ = mod_0_ end -nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(nvim, "aniseed.nvim"), _1_, "aniseed.nvim.util", "fnl/aniseed/nvim/util.fnl" +nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(nvim, "aniseed.nvim"), _0_, "aniseed.nvim.util", "fnl/aniseed/nvim/util.fnl" local normal -local function _2_(keys) +local function _1_(keys) return nvim.ex.silent(("exe \"normal! " .. keys .. "\"")) end -normal = _2_ +normal = _1_ _2amodule_2a["normal"] = normal _2amodule_2a["aniseed/locals"]["normal"] = normal local fn_bridge -local function _3_(viml_name, mod, lua_name, opts) +local function _2_(viml_name, mod, lua_name, opts) local _let_0_ = (opts or {}) local range = _let_0_["range"] local _return = _let_0_["return"] - local _4_ + local _3_ if range then - _4_ = " range" + _3_ = " range" else - _4_ = "" + _3_ = "" end - local _6_ + local _5_ if (_return ~= false) then - _6_ = "return" + _5_ = "return" else - _6_ = "call" + _5_ = "call" end - local _8_ + local _7_ if range then - _8_ = "\" . a:firstline . \", \" . a:lastline . \", " + _7_ = "\" . a:firstline . \", \" . a:lastline . \", " else - _8_ = "" + _7_ = "" end - return nvim.ex.function_((viml_name .. "(...)" .. _4_ .. "\n " .. _6_ .. " luaeval(\"require('" .. mod .. "')['" .. lua_name .. "'](" .. _8_ .. "unpack(_A))\", a:000)\n endfunction")) + return nvim.ex.function_((viml_name .. "(...)" .. _3_ .. "\n " .. _5_ .. " luaeval(\"require('" .. mod .. "')['" .. lua_name .. "'](" .. _7_ .. "unpack(_A))\", a:000)\n endfunction")) end -fn_bridge = _3_ +fn_bridge = _2_ _2amodule_2a["fn-bridge"] = fn_bridge _2amodule_2a["aniseed/locals"]["fn-bridge"] = fn_bridge local with_out_str -local function _4_(f) +local function _3_(f) nvim.ex.redir("=> g:aniseed_nvim_util_out_str") do local ok_3f, err = pcall(f) @@ -60,7 +56,7 @@ local function _4_(f) end return string.gsub(nvim.g.aniseed_nvim_util_out_str, "^(\n?)(.*)$", "%2%1") end -with_out_str = _4_ +with_out_str = _3_ _2amodule_2a["with-out-str"] = with_out_str _2amodule_2a["aniseed/locals"]["with-out-str"] = with_out_str return nil diff --git a/lua/aniseed/string.lua b/lua/aniseed/string.lua index 83d80b1..7293e3b 100644 --- a/lua/aniseed/string.lua +++ b/lua/aniseed/string.lua @@ -1,27 +1,23 @@ -local autoload -local function _0_(...) - return (require("aniseed.autoload")).autoload(...) -end -autoload = _0_ +local autoload = (require("aniseed.autoload")).autoload local a, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil -local _1_ +local _0_ do local mod_0_ = {["aniseed/local-fns"] = {autoload = {a = "aniseed.core"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.string"} package.loaded["aniseed.string"] = mod_0_ - _1_ = mod_0_ + _0_ = mod_0_ end -a, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(a, "aniseed.core"), _1_, "aniseed.string", "fnl/aniseed/string.fnl" +a, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(a, "aniseed.core"), _0_, "aniseed.string", "fnl/aniseed/string.fnl" local join -local function _2_(...) +local function _1_(...) local args = {...} - local function _3_(...) + local function _2_(...) if (2 == a.count(args)) then return args else return {"", a.first(args)} end end - local _let_0_ = _3_(...) + local _let_0_ = _2_(...) local sep = _let_0_[1] local xs = _let_0_[2] local len = a.count(xs) @@ -29,27 +25,27 @@ local function _2_(...) if (len > 0) then for i = 1, len do local x = xs[i] - local _4_ + local _3_ if ("string" == type(x)) then - _4_ = x + _3_ = x elseif (nil == x) then - _4_ = x + _3_ = x else - _4_ = a["pr-str"](x) + _3_ = a["pr-str"](x) end - if _4_ then - table.insert(result, _4_) + if _3_ then + table.insert(result, _3_) else end end end return table.concat(result, sep) end -join = _2_ +join = _1_ _2amodule_2a["join"] = join _2amodule_2a["aniseed/locals"]["join"] = join local split -local function _3_(s, pat) +local function _2_(s, pat) local done_3f = false local acc = {} local index = 1 @@ -65,35 +61,35 @@ local function _3_(s, pat) end return acc end -split = _3_ +split = _2_ _2amodule_2a["split"] = split _2amodule_2a["aniseed/locals"]["split"] = split local blank_3f -local function _4_(s) +local function _3_(s) return (a["empty?"](s) or not string.find(s, "[^%s]")) end -blank_3f = _4_ +blank_3f = _3_ _2amodule_2a["blank?"] = blank_3f _2amodule_2a["aniseed/locals"]["blank?"] = blank_3f local triml -local function _5_(s) +local function _4_(s) return string.gsub(s, "^%s*(.-)", "%1") end -triml = _5_ +triml = _4_ _2amodule_2a["triml"] = triml _2amodule_2a["aniseed/locals"]["triml"] = triml local trimr -local function _6_(s) +local function _5_(s) return string.gsub(s, "(.-)%s*$", "%1") end -trimr = _6_ +trimr = _5_ _2amodule_2a["trimr"] = trimr _2amodule_2a["aniseed/locals"]["trimr"] = trimr local trim -local function _7_(s) +local function _6_(s) return string.gsub(s, "^%s*(.-)%s*$", "%1") end -trim = _7_ +trim = _6_ _2amodule_2a["trim"] = trim _2amodule_2a["aniseed/locals"]["trim"] = trim return nil diff --git a/lua/aniseed/test.lua b/lua/aniseed/test.lua index 97b982b..2d190a2 100644 --- a/lua/aniseed/test.lua +++ b/lua/aniseed/test.lua @@ -1,49 +1,45 @@ -local autoload -local function _0_(...) - return (require("aniseed.autoload")).autoload(...) -end -autoload = _0_ -local str, a, fs, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil -local _1_ +local autoload = (require("aniseed.autoload")).autoload +local a, str, fs, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil +local _0_ do local mod_0_ = {["aniseed/local-fns"] = {autoload = {a = "aniseed.core", fs = "aniseed.fs", nvim = "aniseed.nvim", str = "aniseed.string"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.test"} package.loaded["aniseed.test"] = mod_0_ - _1_ = mod_0_ + _0_ = mod_0_ end -str, a, fs, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(str, "aniseed.string"), autoload(a, "aniseed.core"), autoload(fs, "aniseed.fs"), autoload(nvim, "aniseed.nvim"), _1_, "aniseed.test", "fnl/aniseed/test.fnl" +a, str, fs, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(a, "aniseed.core"), autoload(str, "aniseed.string"), autoload(fs, "aniseed.fs"), autoload(nvim, "aniseed.nvim"), _0_, "aniseed.test", "fnl/aniseed/test.fnl" local ok_3f -local function _3_(_2_) - local _arg_0_ = _2_ +local function _2_(_1_) + local _arg_0_ = _1_ local tests = _arg_0_["tests"] local tests_passed = _arg_0_["tests-passed"] return (tests == tests_passed) end -ok_3f = _3_ +ok_3f = _2_ _2amodule_2a["ok?"] = ok_3f _2amodule_2a["aniseed/locals"]["ok?"] = ok_3f local display_results -local function _4_(results, prefix) +local function _3_(results, prefix) do local _let_0_ = results local assertions = _let_0_["assertions"] local assertions_passed = _let_0_["assertions-passed"] local tests = _let_0_["tests"] local tests_passed = _let_0_["tests-passed"] - local _5_ + local _4_ if ok_3f(results) then - _5_ = "OK" + _4_ = "OK" else - _5_ = "FAILED" + _4_ = "FAILED" end - a.println((prefix .. " " .. _5_ .. " " .. tests_passed .. "/" .. tests .. " tests and " .. assertions_passed .. "/" .. assertions .. " assertions passed")) + a.println((prefix .. " " .. _4_ .. " " .. tests_passed .. "/" .. tests .. " tests and " .. assertions_passed .. "/" .. assertions .. " assertions passed")) end return results end -display_results = _4_ +display_results = _3_ _2amodule_2a["display-results"] = display_results _2amodule_2a["aniseed/locals"]["display-results"] = display_results local run -local function _5_(mod_name) +local function _4_(mod_name) local mod = package.loaded[mod_name] local tests = (a["table?"](mod) and mod["aniseed/tests"]) if a["table?"](tests) then @@ -54,30 +50,30 @@ local function _5_(mod_name) do local prefix = ("[" .. mod_name .. "/" .. label .. "]") local fail - local function _6_(desc, ...) + local function _5_(desc, ...) test_failed = true - local function _7_(...) + local function _6_(...) if desc then return (" (" .. desc .. ")") else return "" end end - return a.println((str.join({prefix, " ", ...}) .. _7_(...))) + return a.println((str.join({prefix, " ", ...}) .. _6_(...))) end - fail = _6_ + fail = _5_ local begin - local function _7_() + local function _6_() return a.update(results, "assertions", a.inc) end - begin = _7_ + begin = _6_ local pass - local function _8_() + local function _7_() return a.update(results, "assertions-passed", a.inc) end - pass = _8_ + pass = _7_ local t - local function _9_(e, r, desc) + local function _8_(e, r, desc) begin() if (e == r) then return pass() @@ -85,7 +81,7 @@ local function _5_(mod_name) return fail(desc, "Expected '", a["pr-str"](e), "' but received '", a["pr-str"](r), "'") end end - local function _10_(r, desc) + local function _9_(r, desc) begin() if r then return pass() @@ -93,7 +89,7 @@ local function _5_(mod_name) return fail(desc, "Expected truthy result but received '", a["pr-str"](r), "'") end end - local function _11_(e, r, desc) + local function _10_(e, r, desc) begin() local se = a["pr-str"](e) local sr = a["pr-str"](r) @@ -103,14 +99,14 @@ local function _5_(mod_name) return fail(desc, "Expected (with pr) '", se, "' but received '", sr, "'") end end - t = {["="] = _9_, ["ok?"] = _10_, ["pr="] = _11_} - local _12_, _13_ = nil, nil - local function _14_() + t = {["="] = _8_, ["ok?"] = _9_, ["pr="] = _10_} + local _11_, _12_ = nil, nil + local function _13_() return f(t) end - _12_, _13_ = pcall(_14_) - if ((_12_ == false) and (nil ~= _13_)) then - local err = _13_ + _11_, _12_ = pcall(_13_) + if ((_11_ == false) and (nil ~= _12_)) then + local err = _12_ fail("Exception: ", err) end end @@ -121,30 +117,30 @@ local function _5_(mod_name) return display_results(results, ("[" .. mod_name .. "]")) end end -run = _5_ +run = _4_ _2amodule_2a["run"] = run _2amodule_2a["aniseed/locals"]["run"] = run local run_all -local function _6_() - local function _7_(totals, results) +local function _5_() + local function _6_(totals, results) for k, v in pairs(results) do totals[k] = (v + totals[k]) end return totals end - return display_results(a.reduce(_7_, {["assertions-passed"] = 0, ["tests-passed"] = 0, assertions = 0, tests = 0}, a.filter(a["table?"], a.map(run, a.keys(package.loaded)))), "[total]") + return display_results(a.reduce(_6_, {["assertions-passed"] = 0, ["tests-passed"] = 0, assertions = 0, tests = 0}, a.filter(a["table?"], a.map(run, a.keys(package.loaded)))), "[total]") end -run_all = _6_ +run_all = _5_ _2amodule_2a["run-all"] = run_all _2amodule_2a["aniseed/locals"]["run-all"] = run_all local suite -local function _7_() +local function _6_() do local sep = fs["path-sep"] - local function _8_(path) + local function _7_(path) return require(string.gsub(string.match(path, ("^test" .. sep .. "fnl" .. sep .. "(.-).fnl$")), sep, ".")) end - a["run!"](_8_, nvim.fn.globpath(("test" .. sep .. "fnl"), "**/*-test.fnl", false, true)) + a["run!"](_7_, nvim.fn.globpath(("test" .. sep .. "fnl"), "**/*-test.fnl", false, true)) end if ok_3f(run_all()) then return nvim.ex.q() @@ -152,7 +148,7 @@ local function _7_() return nvim.ex.cq() end end -suite = _7_ +suite = _6_ _2amodule_2a["suite"] = suite _2amodule_2a["aniseed/locals"]["suite"] = suite return nil diff --git a/module-system-plugin.fnl b/module-system-plugin.fnl index 0f0bfc0..e21ce1d 100644 --- a/module-system-plugin.fnl +++ b/module-system-plugin.fnl @@ -58,8 +58,7 @@ `(,(sym f) ,arg)])))) (when (next autoloads) - (compile1 `(local ,syms.autoload - #((. (require :aniseed.autoload) :autoload) $...)) + (compile1 `(local ,syms.autoload (. (require :aniseed.autoload) :autoload)) scope parent opts) (each [_ aliases (pairs autoloads)] From 004e968fac8890e714c18042add42879098226c9 Mon Sep 17 00:00:00 2001 From: Andrew DeFilippo Date: Sun, 1 Aug 2021 18:19:20 -0500 Subject: [PATCH 08/11] Refactored `module-form` to handle local fns by name instead of by whether the collection type was a sequence or table. Cleaned up the process by which `compile1` is called. Some slight changes to tests, and general code cleanup. --- lua/aniseed/compile.lua | 4 +- lua/aniseed/env.lua | 4 +- lua/aniseed/eval.lua | 4 +- lua/aniseed/fs.lua | 4 +- lua/aniseed/test.lua | 4 +- module-system-plugin.fnl | 174 +++++++++++++----------- test/fnl/aniseed/compile-test.fnl | 5 +- test/fnl/aniseed/module-system-test.fnl | 10 +- 8 files changed, 116 insertions(+), 93 deletions(-) diff --git a/lua/aniseed/compile.lua b/lua/aniseed/compile.lua index 35f6790..a4a07ba 100644 --- a/lua/aniseed/compile.lua +++ b/lua/aniseed/compile.lua @@ -1,12 +1,12 @@ local autoload = (require("aniseed.autoload")).autoload -local a, fs, fennel, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil +local a, nvim, fs, fennel, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil local _0_ do local mod_0_ = {["aniseed/local-fns"] = {autoload = {a = "aniseed.core", fennel = "aniseed.fennel", fs = "aniseed.fs", nvim = "aniseed.nvim"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.compile"} package.loaded["aniseed.compile"] = mod_0_ _0_ = mod_0_ end -a, fs, fennel, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(a, "aniseed.core"), autoload(fs, "aniseed.fs"), autoload(fennel, "aniseed.fennel"), autoload(nvim, "aniseed.nvim"), _0_, "aniseed.compile", "fnl/aniseed/compile.fnl" +a, nvim, fs, fennel, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(a, "aniseed.core"), autoload(nvim, "aniseed.nvim"), autoload(fs, "aniseed.fs"), autoload(fennel, "aniseed.fennel"), _0_, "aniseed.compile", "fnl/aniseed/compile.fnl" local base_path do local _1_ = (debug.getinfo(1, "S")).source diff --git a/lua/aniseed/env.lua b/lua/aniseed/env.lua index bf04be3..6c1b115 100644 --- a/lua/aniseed/env.lua +++ b/lua/aniseed/env.lua @@ -1,12 +1,12 @@ local autoload = (require("aniseed.autoload")).autoload -local nvim, compile, fs, fennel, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil +local fs, nvim, fennel, compile, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil local _0_ do local mod_0_ = {["aniseed/local-fns"] = {autoload = {compile = "aniseed.compile", fennel = "aniseed.fennel", fs = "aniseed.fs", nvim = "aniseed.nvim"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.env"} package.loaded["aniseed.env"] = mod_0_ _0_ = mod_0_ end -nvim, compile, fs, fennel, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(nvim, "aniseed.nvim"), autoload(compile, "aniseed.compile"), autoload(fs, "aniseed.fs"), autoload(fennel, "aniseed.fennel"), _0_, "aniseed.env", "fnl/aniseed/env.fnl" +fs, nvim, fennel, compile, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(fs, "aniseed.fs"), autoload(nvim, "aniseed.nvim"), autoload(fennel, "aniseed.fennel"), autoload(compile, "aniseed.compile"), _0_, "aniseed.env", "fnl/aniseed/env.fnl" local config_dir = nvim.fn.stdpath("config") do end (_2amodule_2a)["aniseed/locals"]["config-dir"] = config_dir local quiet_require diff --git a/lua/aniseed/eval.lua b/lua/aniseed/eval.lua index 6871eff..847d210 100644 --- a/lua/aniseed/eval.lua +++ b/lua/aniseed/eval.lua @@ -1,12 +1,12 @@ local autoload = (require("aniseed.autoload")).autoload -local fennel, a, fs, nvim, compile, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil, nil +local fennel, a, fs, compile, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil, nil local _0_ do local mod_0_ = {["aniseed/local-fns"] = {autoload = {a = "aniseed.core", compile = "aniseed.compile", fennel = "aniseed.fennel", fs = "aniseed.fs", nvim = "aniseed.nvim"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.eval"} package.loaded["aniseed.eval"] = mod_0_ _0_ = mod_0_ end -fennel, a, fs, nvim, compile, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(fennel, "aniseed.fennel"), autoload(a, "aniseed.core"), autoload(fs, "aniseed.fs"), autoload(nvim, "aniseed.nvim"), autoload(compile, "aniseed.compile"), _0_, "aniseed.eval", "fnl/aniseed/eval.fnl" +fennel, a, fs, compile, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(fennel, "aniseed.fennel"), autoload(a, "aniseed.core"), autoload(fs, "aniseed.fs"), autoload(compile, "aniseed.compile"), autoload(nvim, "aniseed.nvim"), _0_, "aniseed.eval", "fnl/aniseed/eval.fnl" local str local function _1_(code, opts) local fnl = fennel.impl() diff --git a/lua/aniseed/fs.lua b/lua/aniseed/fs.lua index cacbc44..f28f907 100644 --- a/lua/aniseed/fs.lua +++ b/lua/aniseed/fs.lua @@ -1,12 +1,12 @@ local autoload = (require("aniseed.autoload")).autoload -local a, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil +local nvim, a, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil local _0_ do local mod_0_ = {["aniseed/local-fns"] = {autoload = {a = "aniseed.core", nvim = "aniseed.nvim"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.fs"} package.loaded["aniseed.fs"] = mod_0_ _0_ = mod_0_ end -a, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(a, "aniseed.core"), autoload(nvim, "aniseed.nvim"), _0_, "aniseed.fs", "fnl/aniseed/fs.fnl" +nvim, a, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(nvim, "aniseed.nvim"), autoload(a, "aniseed.core"), _0_, "aniseed.fs", "fnl/aniseed/fs.fnl" local path_sep do local os = string.lower(jit.os) diff --git a/lua/aniseed/test.lua b/lua/aniseed/test.lua index 2d190a2..8636a4f 100644 --- a/lua/aniseed/test.lua +++ b/lua/aniseed/test.lua @@ -1,12 +1,12 @@ local autoload = (require("aniseed.autoload")).autoload -local a, str, fs, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil +local a, nvim, fs, str, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil local _0_ do local mod_0_ = {["aniseed/local-fns"] = {autoload = {a = "aniseed.core", fs = "aniseed.fs", nvim = "aniseed.nvim", str = "aniseed.string"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.test"} package.loaded["aniseed.test"] = mod_0_ _0_ = mod_0_ end -a, str, fs, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(a, "aniseed.core"), autoload(str, "aniseed.string"), autoload(fs, "aniseed.fs"), autoload(nvim, "aniseed.nvim"), _0_, "aniseed.test", "fnl/aniseed/test.fnl" +a, nvim, fs, str, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(a, "aniseed.core"), autoload(nvim, "aniseed.nvim"), autoload(fs, "aniseed.fs"), autoload(str, "aniseed.string"), _0_, "aniseed.test", "fnl/aniseed/test.fnl" local ok_3f local function _2_(_1_) local _arg_0_ = _1_ diff --git a/module-system-plugin.fnl b/module-system-plugin.fnl index e21ce1d..79c2582 100644 --- a/module-system-plugin.fnl +++ b/module-system-plugin.fnl @@ -15,58 +15,72 @@ (tset to k v)) to)) -;; splits a table into two by running p on each key -(fn partition-by-key [p x] - (let [t {} f {}] - (each [k v (pairs (or x []))] - (if (p k) - (tset t k v) - (tset f k v))) - (values t f))) - -;; recursively `tostring`s a table, only recursing on a value if it is -;; a table and *not* a symbol, as symbols should be `tostring`ed -(fn stringify-table [t] - (collect [k v (pairs t)] - (values - (tostring k) - (if (and (not (sym? v)) (table? v)) - (stringify-table v) - (tostring v))))) - -(fn module-form [ast {: scope : parent : opts : compile1}] - (let [name-str (-?> (assert-compile - (sym? (. ast 2)) "expected module name" ast) - tostring) - all-new-local-fns (stringify-table (or (. ast 3) [])) - (autoloads new-local-fns) (partition-by-key - #(= :autoload $) - all-new-local-fns) +;; serializes the local-fns table for runtime +(fn view-local-fns [t] + (let [serialized (copy t)] + (fn process [f args] + (if (or (= f :require) + (= f :autoload) + (= f :import-macros)) + (collect [bindings module (pairs args)] + (values (view bindings) (tostring module))) + (or (= f :include) + (= f :require-macros)) + (icollect [_ module (pairs args)] + (tostring module)) + (view args))) + + (each [f args (pairs serialized)] + (tset serialized f (process f args))) + serialized)) + +(fn module-form [ast scope filename compile] + (let [name-str (-?> (assert-compile (sym? (. ast 2)) + "expected name" + ast) + (tostring)) + {:include included + :require required + :autoload autoloaded + :import-macros imported-macros + :require-macros required-macros + &as new-local-fns} (collect [f args (pairs (or (. ast 3) []))] + (values (tostring f) args)) mod (doto (or (. ast 4) {}) (tset :aniseed/module name-str) (tset :aniseed/locals {}) - (tset :aniseed/local-fns all-new-local-fns)) + (tset :aniseed/local-fns (view-local-fns new-local-fns))) locals []] (tset scope :module {:locals {} :public {}}) - (when (next new-local-fns) - (each [f aliases (pairs new-local-fns)] - (each [alias arg (pairs aliases)] - (table.insert locals - [(sym alias) - `(,(sym f) ,arg)])))) + (when included + (each [_ module (ipairs included)] + (compile `(include ,(tostring module))))) - (when (next autoloads) - (compile1 `(local ,syms.autoload (. (require :aniseed.autoload) :autoload)) - scope parent opts) + (when imported-macros + (each [bindings module (pairs imported-macros)] + (compile `(import-macros ,bindings ,(tostring module))))) - (each [_ aliases (pairs autoloads)] - (each [alias arg (pairs aliases)] - (let [sym-alias (sym alias)] - (table.insert locals - [sym-alias - `(autoload ,sym-alias ,arg)]))))) + (when required-macros + (each [_ module (ipairs required-macros)] + (compile `(require-macros ,(tostring module))))) + + (when required + (each [bindings module (pairs required)] + (table.insert locals [bindings + `(require ,(tostring module))]))) + + (when autoloaded + (compile `(local ,syms.autoload + (. (require :aniseed.autoload) :autoload))) + + (each [alias module (pairs autoloaded)] + (assert-compile (sym? alias) + "expected symbol, destructuring not yet supported for `autoload`" + alias) + (table.insert locals [alias + `(autoload ,alias ,(tostring module))]))) (table.insert locals [syms.*module* @@ -76,8 +90,8 @@ (table.insert locals [syms.*module-name* name-str]) - (when opts.filename - (table.insert locals [syms.*file* opts.filename])) + (when filename + (table.insert locals [syms.*file* filename])) (let [names [] vals []] @@ -89,56 +103,60 @@ (empty-table ast) (copy [`local `(,(unpack names)) `(values ,(unpack vals))] ast)))) -(fn def-form [ast {: scope : parent : opts : compile1 &as state} private? value?] +(fn def-form [ast scope compile private? value?] (let [name (assert-compile (sym? (. ast 2)) "expected name" ast) name-str (tostring name) value (assert-compile (or value? (. ast 3)) "expected value" ast) mod-scope (if private? :locals :public)] (tset scope.module mod-scope name-str value) - (compile1 `(local ,name ,value) scope parent opts) + (compile `(local ,name ,value)) (when (not private?) - (compile1 `(tset ,syms.*module* ,name-str ,name) scope parent opts)) + (compile `(tset ,syms.*module* ,name-str ,name))) (empty-table ast) (copy [`tset syms.*module* :aniseed/locals name-str name] ast))) -(fn defn-form [ast {: scope : parent : opts : compile1 &as state} private?] +(fn defn-form [ast scope compile private?] (let [[_ _ args & body] ast - args (assert-compile (table? (. ast 3)) "expected parameters table" ast) + args (assert-compile (table? (. ast 3)) + "expected parameters table" + ast) body (assert-compile (-?>> (table? body) (and (< 0 (length body)))) - "expected body expression" ast) + "expected body expression" + ast) fn-ast `(fn ,args)] (each [_ stmt (pairs body)] (table.insert fn-ast stmt)) - (def-form ast state private? fn-ast))) + (def-form ast scope compile private? fn-ast))) -(fn defonce-form [ast {: scope : parent : opts : compile1 &as state} private?] - (let [name-str (-?> (assert-compile (. ast 2) "expected name") - tostring) +(fn defonce-form [ast scope compile private?] + (let [name-str (-?> (assert-compile (. ast 2) "expected name" ast) + (tostring)) mod-scope (if private? :locals :public)] (if (. scope.module mod-scope name-str) (do (empty-table ast) (copy [`lua syms.nil] ast)) - (def-form ast state private?)))) + (def-form ast scope compile private?)))) -(fn deftest-form [ast {: scope : parent : opts : compile1 &as state}] +(fn deftest-form [ast scope compile] (let [[_ name & body] ast - name-str (-?> (assert-compile (. ast 2) "expected name") - tostring) + name-str (-?> (assert-compile (. ast 2) "expected name" ast) + (tostring)) body (assert-compile (-?>> (table? body) (and (< 0 (length body)))) - "expected body expression" ast) + "expected body expression" + ast) fn-sym (gensym) fn-ast `(fn ,fn-sym [,syms.t])] (each [_ stmt (pairs body)] (table.insert fn-ast stmt)) - (compile1 fn-ast scope parent opts) + (compile fn-ast) (empty-table ast) @@ -148,25 +166,25 @@ (tset scope.module :has-tests true) (copy [`tset syms.*module* :aniseed/tests {name-str fn-sym}] ast))))) -(fn time-form [ast {: scope : parent : opts : compile1 &as state}] +(fn time-form [ast scope compile] (let [[_ & body] ast body (assert-compile (-?>> (table? body) (and (< 0 (length body)))) - "expected body expression" ast) + "expected body expression" + ast) time-fn-sym (. scope.module :time-fn-sym) body-ast `(do)] (when (not time-fn-sym) (set-forcibly! time-fn-sym (gensym)) (tset scope.module :time-fn-sym time-fn-sym) - (compile1 `(fn ,time-fn-sym [...] + (compile `(fn ,time-fn-sym [...] (let [start# (vim.loop.hrtime) result# ... end# (vim.loop.hrtime)] (print (.. "Elapsed time: " (/ (- end# start#) 1000000) " msecs")) - result#)) - scope parent opts)) + result#)))) (each [_ stmt (pairs body)] (table.insert body-ast stmt)) @@ -176,19 +194,19 @@ (fn call [ast scope parent opts compile1] (let [symbol (. ast 1) - state {: scope : parent : compile1 - :opts (doto (copy opts) - (tset :tail false))}] + opts (doto (copy opts) + (tset :tail false)) + compile (fn [ast] (compile1 ast scope parent opts))] (match (. ast 1) - syms.module (module-form ast state) - syms.def- (def-form ast state true) - syms.def (def-form ast state false) - syms.defn- (defn-form ast state true) - syms.defn (defn-form ast state false) - syms.defonce- (defonce-form ast state true) - syms.defonce (defonce-form ast state false) - syms.deftest (deftest-form ast state) - syms.time (time-form ast state)))) + syms.module (module-form ast scope opts.filename compile) + syms.def- (def-form ast scope compile true) + syms.def (def-form ast scope compile false) + syms.defn- (defn-form ast scope compile true) + syms.defn (defn-form ast scope compile false) + syms.defonce- (defonce-form ast scope compile true) + syms.defonce (defonce-form ast scope compile false) + syms.deftest (deftest-form ast scope compile) + syms.time (time-form ast scope compile)))) {: call} diff --git a/test/fnl/aniseed/compile-test.fnl b/test/fnl/aniseed/compile-test.fnl index e047b64..c053b82 100644 --- a/test/fnl/aniseed/compile-test.fnl +++ b/test/fnl/aniseed/compile-test.fnl @@ -14,7 +14,10 @@ (compile-fail t "(+ 10 20" 28 "expected closing delimiter")) (deftest module - (compile-fail t "(module)" 30 "expected module name")) + (compile-fail t "(module)" 30 "expected name") + + (compile-fail t "(module _ {autoload {{&as root} base}})" + 30 "expected symbol, destructuring not yet supported for `autoload`")) (deftest def (compile-fail t "(def)" 30 "expected name") diff --git a/test/fnl/aniseed/module-system-test.fnl b/test/fnl/aniseed/module-system-test.fnl index 0e19828..90420b6 100644 --- a/test/fnl/aniseed/module-system-test.fnl +++ b/test/fnl/aniseed/module-system-test.fnl @@ -4,8 +4,8 @@ (local initial {:foo :bar}) (module module-test - {require {a_ aniseed.core} - autoload {compile_ aniseed.compile}} + {require {{: println &as a} aniseed.core} + autoload {compile aniseed.compile}} initial) (t.= *module-name* :module-test @@ -14,8 +14,10 @@ (t.= *file* :test/fnl/aniseed/module-system-test.fnl "*file* not defined") - (t.ok? (not= nil a_) "require aniseed.core failed") - (t.ok? (not= nil compile_) "autoload aniseed.compile failed") + (t.ok? (and (not= nil println) + (not= nil a.println) + (= println a.println)) "module-level `require` destructuring failed") + (t.ok? (not= nil compile) "autoload aniseed.compile failed") (t.= (. *module* :foo) (. initial :foo) "failed to carry over initial-mod into *module*")) From 2109ff32b8536b89f55c6d71fddd9d43b3cf6809 Mon Sep 17 00:00:00 2001 From: Andrew DeFilippo Date: Mon, 2 Aug 2021 15:26:29 -0500 Subject: [PATCH 09/11] Fixed def-form to allow for recursion in functions defined with this module system, added test coverage. --- lua/aniseed/autoload.lua | 2 +- lua/aniseed/compile.lua | 10 +-- lua/aniseed/core.lua | 86 ++++++++++++------------- lua/aniseed/env.lua | 11 ++-- lua/aniseed/eval.lua | 6 +- lua/aniseed/fennel.lua | 9 +-- lua/aniseed/fs.lua | 12 ++-- lua/aniseed/nvim/util.lua | 6 +- lua/aniseed/string.lua | 12 ++-- lua/aniseed/test.lua | 14 ++-- lua/aniseed/view.lua | 2 +- module-system-plugin.fnl | 5 +- test/fnl/aniseed/module-system-test.fnl | 9 ++- 13 files changed, 98 insertions(+), 86 deletions(-) diff --git a/lua/aniseed/autoload.lua b/lua/aniseed/autoload.lua index 9d82085..d1d5812 100644 --- a/lua/aniseed/autoload.lua +++ b/lua/aniseed/autoload.lua @@ -6,7 +6,7 @@ do _0_ = mod_0_ end _2amodule_2a, _2amodule_name_2a, _2afile_2a = _0_, "aniseed.autoload", "fnl/aniseed/autoload.fnl" -local autoload +local autoload = nil local function _1_(alias, name) local function ensure() alias = require(name) diff --git a/lua/aniseed/compile.lua b/lua/aniseed/compile.lua index a4a07ba..812968f 100644 --- a/lua/aniseed/compile.lua +++ b/lua/aniseed/compile.lua @@ -1,12 +1,12 @@ local autoload = (require("aniseed.autoload")).autoload -local a, nvim, fs, fennel, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil +local a, fs, fennel, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil local _0_ do local mod_0_ = {["aniseed/local-fns"] = {autoload = {a = "aniseed.core", fennel = "aniseed.fennel", fs = "aniseed.fs", nvim = "aniseed.nvim"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.compile"} package.loaded["aniseed.compile"] = mod_0_ _0_ = mod_0_ end -a, nvim, fs, fennel, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(a, "aniseed.core"), autoload(nvim, "aniseed.nvim"), autoload(fs, "aniseed.fs"), autoload(fennel, "aniseed.fennel"), _0_, "aniseed.compile", "fnl/aniseed/compile.fnl" +a, fs, fennel, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(a, "aniseed.core"), autoload(fs, "aniseed.fs"), autoload(fennel, "aniseed.fennel"), autoload(nvim, "aniseed.nvim"), _0_, "aniseed.compile", "fnl/aniseed/compile.fnl" local base_path do local _1_ = (debug.getinfo(1, "S")).source @@ -21,7 +21,7 @@ do base_path = _1_ end end -local str +local str = nil local function _2_(code, opts) local fnl = fennel.impl() local plugins = {"module-system-plugin.fnl"} @@ -41,7 +41,7 @@ end str = _2_ _2amodule_2a["str"] = str _2amodule_2a["aniseed/locals"]["str"] = str -local file +local file = nil local function _3_(src, dest) local code = a.slurp(src) local _4_, _5_ = str(code, {filename = src}) @@ -57,7 +57,7 @@ end file = _3_ _2amodule_2a["file"] = file _2amodule_2a["aniseed/locals"]["file"] = file -local glob +local glob = nil local function _4_(src_expr, src_dir, dest_dir) for _, path in ipairs(fs.relglob(src_dir, src_expr)) do if fs["macro-file-path?"](path) then diff --git a/lua/aniseed/core.lua b/lua/aniseed/core.lua index f9e2de7..5100602 100644 --- a/lua/aniseed/core.lua +++ b/lua/aniseed/core.lua @@ -8,35 +8,35 @@ do end view, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(view, "aniseed.view"), _0_, "aniseed.core", "fnl/aniseed/core.fnl" math.randomseed(os.time()) -local rand +local rand = nil local function _1_(n) return (math.random() * (n or 1)) end rand = _1_ _2amodule_2a["rand"] = rand _2amodule_2a["aniseed/locals"]["rand"] = rand -local string_3f +local string_3f = nil local function _2_(x) return ("string" == type(x)) end string_3f = _2_ _2amodule_2a["string?"] = string_3f _2amodule_2a["aniseed/locals"]["string?"] = string_3f -local nil_3f +local nil_3f = nil local function _3_(x) return (nil == x) end nil_3f = _3_ _2amodule_2a["nil?"] = nil_3f _2amodule_2a["aniseed/locals"]["nil?"] = nil_3f -local table_3f +local table_3f = nil local function _4_(x) return ("table" == type(x)) end table_3f = _4_ _2amodule_2a["table?"] = table_3f _2amodule_2a["aniseed/locals"]["table?"] = table_3f -local count +local count = nil local function _5_(xs) if table_3f(xs) then return table.maxn(xs) @@ -49,14 +49,14 @@ end count = _5_ _2amodule_2a["count"] = count _2amodule_2a["aniseed/locals"]["count"] = count -local empty_3f +local empty_3f = nil local function _6_(xs) return (0 == count(xs)) end empty_3f = _6_ _2amodule_2a["empty?"] = empty_3f _2amodule_2a["aniseed/locals"]["empty?"] = empty_3f -local first +local first = nil local function _7_(xs) if xs then return xs[1] @@ -65,7 +65,7 @@ end first = _7_ _2amodule_2a["first"] = first _2amodule_2a["aniseed/locals"]["first"] = first -local second +local second = nil local function _8_(xs) if xs then return xs[2] @@ -74,7 +74,7 @@ end second = _8_ _2amodule_2a["second"] = second _2amodule_2a["aniseed/locals"]["second"] = second -local last +local last = nil local function _9_(xs) if xs then return xs[count(xs)] @@ -83,35 +83,35 @@ end last = _9_ _2amodule_2a["last"] = last _2amodule_2a["aniseed/locals"]["last"] = last -local inc +local inc = nil local function _10_(n) return (n + 1) end inc = _10_ _2amodule_2a["inc"] = inc _2amodule_2a["aniseed/locals"]["inc"] = inc -local dec +local dec = nil local function _11_(n) return (n - 1) end dec = _11_ _2amodule_2a["dec"] = dec _2amodule_2a["aniseed/locals"]["dec"] = dec -local even_3f +local even_3f = nil local function _12_(n) return ((n % 2) == 0) end even_3f = _12_ _2amodule_2a["even?"] = even_3f _2amodule_2a["aniseed/locals"]["even?"] = even_3f -local odd_3f +local odd_3f = nil local function _13_(n) return not even_3f(n) end odd_3f = _13_ _2amodule_2a["odd?"] = odd_3f _2amodule_2a["aniseed/locals"]["odd?"] = odd_3f -local keys +local keys = nil local function _14_(t) local result = {} if t then @@ -124,7 +124,7 @@ end keys = _14_ _2amodule_2a["keys"] = keys _2amodule_2a["aniseed/locals"]["keys"] = keys -local vals +local vals = nil local function _15_(t) local result = {} if t then @@ -137,7 +137,7 @@ end vals = _15_ _2amodule_2a["vals"] = vals _2amodule_2a["aniseed/locals"]["vals"] = vals -local kv_pairs +local kv_pairs = nil local function _16_(t) local result = {} if t then @@ -150,7 +150,7 @@ end kv_pairs = _16_ _2amodule_2a["kv-pairs"] = kv_pairs _2amodule_2a["aniseed/locals"]["kv-pairs"] = kv_pairs -local run_21 +local run_21 = nil local function _17_(f, xs) if xs then local nxs = count(xs) @@ -165,7 +165,7 @@ end run_21 = _17_ _2amodule_2a["run!"] = run_21 _2amodule_2a["aniseed/locals"]["run!"] = run_21 -local filter +local filter = nil local function _18_(f, xs) local result = {} local function _19_(x) @@ -179,7 +179,7 @@ end filter = _18_ _2amodule_2a["filter"] = filter _2amodule_2a["aniseed/locals"]["filter"] = filter -local map +local map = nil local function _19_(f, xs) local result = {} local function _20_(x) @@ -199,21 +199,21 @@ end map = _19_ _2amodule_2a["map"] = map _2amodule_2a["aniseed/locals"]["map"] = map -local map_indexed +local map_indexed = nil local function _20_(f, xs) return map(f, kv_pairs(xs)) end map_indexed = _20_ _2amodule_2a["map-indexed"] = map_indexed _2amodule_2a["aniseed/locals"]["map-indexed"] = map_indexed -local identity +local identity = nil local function _21_(x) return x end identity = _21_ _2amodule_2a["identity"] = identity _2amodule_2a["aniseed/locals"]["identity"] = identity -local reduce +local reduce = nil local function _22_(f, init, xs) local result = init local function _23_(x) @@ -226,7 +226,7 @@ end reduce = _22_ _2amodule_2a["reduce"] = reduce _2amodule_2a["aniseed/locals"]["reduce"] = reduce -local some +local some = nil local function _23_(f, xs) local result = nil local n = 1 @@ -242,7 +242,7 @@ end some = _23_ _2amodule_2a["some"] = some _2amodule_2a["aniseed/locals"]["some"] = some -local butlast +local butlast = nil local function _24_(xs) local total = count(xs) local function _26_(_25_) @@ -256,7 +256,7 @@ end butlast = _24_ _2amodule_2a["butlast"] = butlast _2amodule_2a["aniseed/locals"]["butlast"] = butlast -local rest +local rest = nil local function _25_(xs) local function _27_(_26_) local _arg_0_ = _26_ @@ -269,7 +269,7 @@ end rest = _25_ _2amodule_2a["rest"] = rest _2amodule_2a["aniseed/locals"]["rest"] = rest -local concat +local concat = nil local function _26_(...) local result = {} local function _27_(xs) @@ -284,14 +284,14 @@ end concat = _26_ _2amodule_2a["concat"] = concat _2amodule_2a["aniseed/locals"]["concat"] = concat -local mapcat +local mapcat = nil local function _27_(f, xs) return concat(unpack(map(f, xs))) end mapcat = _27_ _2amodule_2a["mapcat"] = mapcat _2amodule_2a["aniseed/locals"]["mapcat"] = mapcat -local pr_str +local pr_str = nil local function _28_(...) local s local function _29_(x) @@ -307,7 +307,7 @@ end pr_str = _28_ _2amodule_2a["pr-str"] = pr_str _2amodule_2a["aniseed/locals"]["pr-str"] = pr_str -local str +local str = nil local function _29_(...) local function _30_(acc, s) return (acc .. s) @@ -324,7 +324,7 @@ end str = _29_ _2amodule_2a["str"] = str _2amodule_2a["aniseed/locals"]["str"] = str -local println +local println = nil local function _30_(...) local function _31_(acc, s) return (acc .. s) @@ -351,14 +351,14 @@ end println = _30_ _2amodule_2a["println"] = println _2amodule_2a["aniseed/locals"]["println"] = println -local pr +local pr = nil local function _31_(...) return println(pr_str(...)) end pr = _31_ _2amodule_2a["pr"] = pr _2amodule_2a["aniseed/locals"]["pr"] = pr -local slurp +local slurp = nil local function _32_(path, silent_3f) local _33_, _34_ = io.open(path, "r") if ((_33_ == nil) and (nil ~= _34_)) then @@ -374,7 +374,7 @@ end slurp = _32_ _2amodule_2a["slurp"] = slurp _2amodule_2a["aniseed/locals"]["slurp"] = slurp -local spit +local spit = nil local function _33_(path, content) local _34_, _35_ = io.open(path, "w") if ((_34_ == nil) and (nil ~= _35_)) then @@ -390,7 +390,7 @@ end spit = _33_ _2amodule_2a["spit"] = spit _2amodule_2a["aniseed/locals"]["spit"] = spit -local merge_21 +local merge_21 = nil local function _34_(base, ...) local function _35_(acc, m) if m then @@ -405,14 +405,14 @@ end merge_21 = _34_ _2amodule_2a["merge!"] = merge_21 _2amodule_2a["aniseed/locals"]["merge!"] = merge_21 -local merge +local merge = nil local function _35_(...) return merge_21({}, ...) end merge = _35_ _2amodule_2a["merge"] = merge _2amodule_2a["aniseed/locals"]["merge"] = merge -local select_keys +local select_keys = nil local function _36_(t, ks) if (t and ks) then local function _37_(acc, k) @@ -429,7 +429,7 @@ end select_keys = _36_ _2amodule_2a["select-keys"] = select_keys _2amodule_2a["aniseed/locals"]["select-keys"] = select_keys -local get +local get = nil local function _37_(t, k, d) local res if table_3f(t) then @@ -451,7 +451,7 @@ end get = _37_ _2amodule_2a["get"] = get _2amodule_2a["aniseed/locals"]["get"] = get -local get_in +local get_in = nil local function _38_(t, ks, d) local res local function _39_(acc, k) @@ -469,7 +469,7 @@ end get_in = _38_ _2amodule_2a["get-in"] = get_in _2amodule_2a["aniseed/locals"]["get-in"] = get_in -local assoc +local assoc = nil local function _39_(t, ...) local _let_0_ = {...} local k = _let_0_[1] @@ -491,7 +491,7 @@ end assoc = _39_ _2amodule_2a["assoc"] = assoc _2amodule_2a["aniseed/locals"]["assoc"] = assoc -local assoc_in +local assoc_in = nil local function _40_(t, ks, v) local path = butlast(ks) local final = last(ks) @@ -510,21 +510,21 @@ end assoc_in = _40_ _2amodule_2a["assoc-in"] = assoc_in _2amodule_2a["aniseed/locals"]["assoc-in"] = assoc_in -local update +local update = nil local function _41_(t, k, f) return assoc(t, k, f(get(t, k))) end update = _41_ _2amodule_2a["update"] = update _2amodule_2a["aniseed/locals"]["update"] = update -local update_in +local update_in = nil local function _42_(t, ks, f) return assoc_in(t, ks, f(get_in(t, ks))) end update_in = _42_ _2amodule_2a["update-in"] = update_in _2amodule_2a["aniseed/locals"]["update-in"] = update_in -local constantly +local constantly = nil local function _43_(v) local function _44_() return v diff --git a/lua/aniseed/env.lua b/lua/aniseed/env.lua index 6c1b115..54e5cfe 100644 --- a/lua/aniseed/env.lua +++ b/lua/aniseed/env.lua @@ -1,15 +1,16 @@ local autoload = (require("aniseed.autoload")).autoload -local fs, nvim, fennel, compile, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil +local nvim, fennel, fs, compile, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil local _0_ do local mod_0_ = {["aniseed/local-fns"] = {autoload = {compile = "aniseed.compile", fennel = "aniseed.fennel", fs = "aniseed.fs", nvim = "aniseed.nvim"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.env"} package.loaded["aniseed.env"] = mod_0_ _0_ = mod_0_ end -fs, nvim, fennel, compile, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(fs, "aniseed.fs"), autoload(nvim, "aniseed.nvim"), autoload(fennel, "aniseed.fennel"), autoload(compile, "aniseed.compile"), _0_, "aniseed.env", "fnl/aniseed/env.fnl" -local config_dir = nvim.fn.stdpath("config") +nvim, fennel, fs, compile, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(nvim, "aniseed.nvim"), autoload(fennel, "aniseed.fennel"), autoload(fs, "aniseed.fs"), autoload(compile, "aniseed.compile"), _0_, "aniseed.env", "fnl/aniseed/env.fnl" +local config_dir = nil +config_dir = nvim.fn.stdpath("config") do end (_2amodule_2a)["aniseed/locals"]["config-dir"] = config_dir -local quiet_require +local quiet_require = nil local function _1_(m) local ok_3f, err = nil, nil local function _2_() @@ -22,7 +23,7 @@ local function _1_(m) end quiet_require = _1_ _2amodule_2a["aniseed/locals"]["quiet-require"] = quiet_require -local init +local init = nil local function _2_(opts) local opts0 if ("table" == type(opts)) then diff --git a/lua/aniseed/eval.lua b/lua/aniseed/eval.lua index 847d210..3b41a6d 100644 --- a/lua/aniseed/eval.lua +++ b/lua/aniseed/eval.lua @@ -1,13 +1,13 @@ local autoload = (require("aniseed.autoload")).autoload -local fennel, a, fs, compile, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil, nil +local fennel, a, compile, fs, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil, nil local _0_ do local mod_0_ = {["aniseed/local-fns"] = {autoload = {a = "aniseed.core", compile = "aniseed.compile", fennel = "aniseed.fennel", fs = "aniseed.fs", nvim = "aniseed.nvim"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.eval"} package.loaded["aniseed.eval"] = mod_0_ _0_ = mod_0_ end -fennel, a, fs, compile, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(fennel, "aniseed.fennel"), autoload(a, "aniseed.core"), autoload(fs, "aniseed.fs"), autoload(compile, "aniseed.compile"), autoload(nvim, "aniseed.nvim"), _0_, "aniseed.eval", "fnl/aniseed/eval.fnl" -local str +fennel, a, compile, fs, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(fennel, "aniseed.fennel"), autoload(a, "aniseed.core"), autoload(compile, "aniseed.compile"), autoload(fs, "aniseed.fs"), autoload(nvim, "aniseed.nvim"), _0_, "aniseed.eval", "fnl/aniseed/eval.fnl" +local str = nil local function _1_(code, opts) local fnl = fennel.impl() local function _2_() diff --git a/lua/aniseed/fennel.lua b/lua/aniseed/fennel.lua index 8dcd6d1..fd60f43 100644 --- a/lua/aniseed/fennel.lua +++ b/lua/aniseed/fennel.lua @@ -7,7 +7,7 @@ do _0_ = mod_0_ end nvim, fs, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(nvim, "aniseed.nvim"), autoload(fs, "aniseed.fs"), _0_, "aniseed.fennel", "fnl/aniseed/fennel.fnl" -local sync_rtp +local sync_rtp = nil local function _1_(compiler) local sep = fs["path-sep"] local fnl_suffix = (sep .. "fnl" .. sep .. "?.fnl") @@ -20,9 +20,10 @@ end sync_rtp = _1_ _2amodule_2a["sync-rtp"] = sync_rtp _2amodule_2a["aniseed/locals"]["sync-rtp"] = sync_rtp -local state = {["compiler-loaded?"] = false} +local state = nil +state = {["compiler-loaded?"] = false} _2amodule_2a["aniseed/locals"]["state"] = state -local impl +local impl = nil local function _2_() local compiler = require("aniseed.deps.fennel") if not state["compiler-loaded?"] then @@ -34,7 +35,7 @@ end impl = _2_ _2amodule_2a["impl"] = impl _2amodule_2a["aniseed/locals"]["impl"] = impl -local add_path +local add_path = nil local function _3_(path) local fnl = impl() do end (fnl)["path"] = (fnl.path .. ";" .. path) diff --git a/lua/aniseed/fs.lua b/lua/aniseed/fs.lua index f28f907..6fb56eb 100644 --- a/lua/aniseed/fs.lua +++ b/lua/aniseed/fs.lua @@ -7,7 +7,7 @@ do _0_ = mod_0_ end nvim, a, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(nvim, "aniseed.nvim"), autoload(a, "aniseed.core"), _0_, "aniseed.fs", "fnl/aniseed/fs.fnl" -local path_sep +local path_sep = nil do local os = string.lower(jit.os) if (("linux" == os) or ("osx" == os) or ("bsd" == os)) then @@ -18,21 +18,21 @@ do end _2amodule_2a["path-sep"] = path_sep _2amodule_2a["aniseed/locals"]["path-sep"] = path_sep -local basename +local basename = nil local function _1_(path) return nvim.fn.fnamemodify(path, ":h") end basename = _1_ _2amodule_2a["basename"] = basename _2amodule_2a["aniseed/locals"]["basename"] = basename -local mkdirp +local mkdirp = nil local function _2_(dir) return nvim.fn.mkdir(dir, "p") end mkdirp = _2_ _2amodule_2a["mkdirp"] = mkdirp _2amodule_2a["aniseed/locals"]["mkdirp"] = mkdirp -local relglob +local relglob = nil local function _3_(dir, expr) local dir_len = a.inc(string.len(dir)) local function _4_(_241) @@ -43,7 +43,7 @@ end relglob = _3_ _2amodule_2a["relglob"] = relglob _2amodule_2a["aniseed/locals"]["relglob"] = relglob -local glob_dir_newer_3f +local glob_dir_newer_3f = nil local function _4_(a_dir, b_dir, expr, b_dir_path_fn) local newer_3f = false for _, path in ipairs(relglob(a_dir, expr)) do @@ -56,7 +56,7 @@ end glob_dir_newer_3f = _4_ _2amodule_2a["glob-dir-newer?"] = glob_dir_newer_3f _2amodule_2a["aniseed/locals"]["glob-dir-newer?"] = glob_dir_newer_3f -local macro_file_path_3f +local macro_file_path_3f = nil local function _5_(path) return string.match(path, "macros.fnl$") end diff --git a/lua/aniseed/nvim/util.lua b/lua/aniseed/nvim/util.lua index 3c267fe..7919dc8 100644 --- a/lua/aniseed/nvim/util.lua +++ b/lua/aniseed/nvim/util.lua @@ -7,14 +7,14 @@ do _0_ = mod_0_ end nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(nvim, "aniseed.nvim"), _0_, "aniseed.nvim.util", "fnl/aniseed/nvim/util.fnl" -local normal +local normal = nil local function _1_(keys) return nvim.ex.silent(("exe \"normal! " .. keys .. "\"")) end normal = _1_ _2amodule_2a["normal"] = normal _2amodule_2a["aniseed/locals"]["normal"] = normal -local fn_bridge +local fn_bridge = nil local function _2_(viml_name, mod, lua_name, opts) local _let_0_ = (opts or {}) local range = _let_0_["range"] @@ -42,7 +42,7 @@ end fn_bridge = _2_ _2amodule_2a["fn-bridge"] = fn_bridge _2amodule_2a["aniseed/locals"]["fn-bridge"] = fn_bridge -local with_out_str +local with_out_str = nil local function _3_(f) nvim.ex.redir("=> g:aniseed_nvim_util_out_str") do diff --git a/lua/aniseed/string.lua b/lua/aniseed/string.lua index 7293e3b..b35a8b8 100644 --- a/lua/aniseed/string.lua +++ b/lua/aniseed/string.lua @@ -7,7 +7,7 @@ do _0_ = mod_0_ end a, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(a, "aniseed.core"), _0_, "aniseed.string", "fnl/aniseed/string.fnl" -local join +local join = nil local function _1_(...) local args = {...} local function _2_(...) @@ -44,7 +44,7 @@ end join = _1_ _2amodule_2a["join"] = join _2amodule_2a["aniseed/locals"]["join"] = join -local split +local split = nil local function _2_(s, pat) local done_3f = false local acc = {} @@ -64,28 +64,28 @@ end split = _2_ _2amodule_2a["split"] = split _2amodule_2a["aniseed/locals"]["split"] = split -local blank_3f +local blank_3f = nil local function _3_(s) return (a["empty?"](s) or not string.find(s, "[^%s]")) end blank_3f = _3_ _2amodule_2a["blank?"] = blank_3f _2amodule_2a["aniseed/locals"]["blank?"] = blank_3f -local triml +local triml = nil local function _4_(s) return string.gsub(s, "^%s*(.-)", "%1") end triml = _4_ _2amodule_2a["triml"] = triml _2amodule_2a["aniseed/locals"]["triml"] = triml -local trimr +local trimr = nil local function _5_(s) return string.gsub(s, "(.-)%s*$", "%1") end trimr = _5_ _2amodule_2a["trimr"] = trimr _2amodule_2a["aniseed/locals"]["trimr"] = trimr -local trim +local trim = nil local function _6_(s) return string.gsub(s, "^%s*(.-)%s*$", "%1") end diff --git a/lua/aniseed/test.lua b/lua/aniseed/test.lua index 8636a4f..7a1af36 100644 --- a/lua/aniseed/test.lua +++ b/lua/aniseed/test.lua @@ -1,13 +1,13 @@ local autoload = (require("aniseed.autoload")).autoload -local a, nvim, fs, str, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil +local a, fs, nvim, str, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil local _0_ do local mod_0_ = {["aniseed/local-fns"] = {autoload = {a = "aniseed.core", fs = "aniseed.fs", nvim = "aniseed.nvim", str = "aniseed.string"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.test"} package.loaded["aniseed.test"] = mod_0_ _0_ = mod_0_ end -a, nvim, fs, str, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(a, "aniseed.core"), autoload(nvim, "aniseed.nvim"), autoload(fs, "aniseed.fs"), autoload(str, "aniseed.string"), _0_, "aniseed.test", "fnl/aniseed/test.fnl" -local ok_3f +a, fs, nvim, str, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(a, "aniseed.core"), autoload(fs, "aniseed.fs"), autoload(nvim, "aniseed.nvim"), autoload(str, "aniseed.string"), _0_, "aniseed.test", "fnl/aniseed/test.fnl" +local ok_3f = nil local function _2_(_1_) local _arg_0_ = _1_ local tests = _arg_0_["tests"] @@ -17,7 +17,7 @@ end ok_3f = _2_ _2amodule_2a["ok?"] = ok_3f _2amodule_2a["aniseed/locals"]["ok?"] = ok_3f -local display_results +local display_results = nil local function _3_(results, prefix) do local _let_0_ = results @@ -38,7 +38,7 @@ end display_results = _3_ _2amodule_2a["display-results"] = display_results _2amodule_2a["aniseed/locals"]["display-results"] = display_results -local run +local run = nil local function _4_(mod_name) local mod = package.loaded[mod_name] local tests = (a["table?"](mod) and mod["aniseed/tests"]) @@ -120,7 +120,7 @@ end run = _4_ _2amodule_2a["run"] = run _2amodule_2a["aniseed/locals"]["run"] = run -local run_all +local run_all = nil local function _5_() local function _6_(totals, results) for k, v in pairs(results) do @@ -133,7 +133,7 @@ end run_all = _5_ _2amodule_2a["run-all"] = run_all _2amodule_2a["aniseed/locals"]["run-all"] = run_all -local suite +local suite = nil local function _6_() do local sep = fs["path-sep"] diff --git a/lua/aniseed/view.lua b/lua/aniseed/view.lua index 21a208a..a862d1d 100644 --- a/lua/aniseed/view.lua +++ b/lua/aniseed/view.lua @@ -6,7 +6,7 @@ do _0_ = mod_0_ end _2amodule_2a, _2amodule_name_2a, _2afile_2a = _0_, "aniseed.view", "fnl/aniseed/view.fnl" -local serialise +local serialise = nil local function _1_(...) return require("aniseed.deps.fennelview")(...) end diff --git a/module-system-plugin.fnl b/module-system-plugin.fnl index 79c2582..d147404 100644 --- a/module-system-plugin.fnl +++ b/module-system-plugin.fnl @@ -110,7 +110,10 @@ mod-scope (if private? :locals :public)] (tset scope.module mod-scope name-str value) - (compile `(local ,name ,value)) + ;; this has been separated into two statements now + ;; to support self reference within the value + (compile `(local ,name nil)) + (compile `(set-forcibly! ,name ,value)) (when (not private?) (compile `(tset ,syms.*module* ,name-str ,name))) diff --git a/test/fnl/aniseed/module-system-test.fnl b/test/fnl/aniseed/module-system-test.fnl index 90420b6..b694e5b 100644 --- a/test/fnl/aniseed/module-system-test.fnl +++ b/test/fnl/aniseed/module-system-test.fnl @@ -42,7 +42,14 @@ (defn- f [x] (+ 2 x)) (defn g [y z] (* 5 (- z (f y)))) - (t.= ((. *module* :g) 2 7) 15 "failed to properly define defns")) + (t.= ((. *module* :g) 2 7) 15 "failed to properly define defns") + + (defn h [x] (if (< x 21) (h (+ 1 x)) x)) + + (t.ok? (= (h 2) + (h 20) + (h -4) + 21) "self reference/recursion failure")) (deftest defonce (var calls 0) From 5517f0eb3abb041f5e39925fd83ec179a26debac Mon Sep 17 00:00:00 2001 From: Andrew DeFilippo Date: Mon, 2 Aug 2021 15:47:27 -0500 Subject: [PATCH 10/11] Removed macros-prefix reference from eval.fnl. --- fnl/aniseed/eval.fnl | 1 - lua/aniseed/env.lua | 4 ++-- lua/aniseed/eval.lua | 6 +++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/fnl/aniseed/eval.fnl b/fnl/aniseed/eval.fnl index d19c28c..c794628 100644 --- a/fnl/aniseed/eval.fnl +++ b/fnl/aniseed/eval.fnl @@ -13,6 +13,5 @@ (xpcall (fn [] (-> code - (compile.macros-prefix opts) (fnl.eval (a.merge {:compiler-env _G} opts)))) fnl.traceback))) diff --git a/lua/aniseed/env.lua b/lua/aniseed/env.lua index 54e5cfe..e677099 100644 --- a/lua/aniseed/env.lua +++ b/lua/aniseed/env.lua @@ -1,12 +1,12 @@ local autoload = (require("aniseed.autoload")).autoload -local nvim, fennel, fs, compile, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil +local fennel, fs, nvim, compile, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil local _0_ do local mod_0_ = {["aniseed/local-fns"] = {autoload = {compile = "aniseed.compile", fennel = "aniseed.fennel", fs = "aniseed.fs", nvim = "aniseed.nvim"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.env"} package.loaded["aniseed.env"] = mod_0_ _0_ = mod_0_ end -nvim, fennel, fs, compile, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(nvim, "aniseed.nvim"), autoload(fennel, "aniseed.fennel"), autoload(fs, "aniseed.fs"), autoload(compile, "aniseed.compile"), _0_, "aniseed.env", "fnl/aniseed/env.fnl" +fennel, fs, nvim, compile, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(fennel, "aniseed.fennel"), autoload(fs, "aniseed.fs"), autoload(nvim, "aniseed.nvim"), autoload(compile, "aniseed.compile"), _0_, "aniseed.env", "fnl/aniseed/env.fnl" local config_dir = nil config_dir = nvim.fn.stdpath("config") do end (_2amodule_2a)["aniseed/locals"]["config-dir"] = config_dir diff --git a/lua/aniseed/eval.lua b/lua/aniseed/eval.lua index 3b41a6d..71d39a9 100644 --- a/lua/aniseed/eval.lua +++ b/lua/aniseed/eval.lua @@ -1,17 +1,17 @@ local autoload = (require("aniseed.autoload")).autoload -local fennel, a, compile, fs, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil, nil +local fs, nvim, a, compile, fennel, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil, nil local _0_ do local mod_0_ = {["aniseed/local-fns"] = {autoload = {a = "aniseed.core", compile = "aniseed.compile", fennel = "aniseed.fennel", fs = "aniseed.fs", nvim = "aniseed.nvim"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.eval"} package.loaded["aniseed.eval"] = mod_0_ _0_ = mod_0_ end -fennel, a, compile, fs, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(fennel, "aniseed.fennel"), autoload(a, "aniseed.core"), autoload(compile, "aniseed.compile"), autoload(fs, "aniseed.fs"), autoload(nvim, "aniseed.nvim"), _0_, "aniseed.eval", "fnl/aniseed/eval.fnl" +fs, nvim, a, compile, fennel, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(fs, "aniseed.fs"), autoload(nvim, "aniseed.nvim"), autoload(a, "aniseed.core"), autoload(compile, "aniseed.compile"), autoload(fennel, "aniseed.fennel"), _0_, "aniseed.eval", "fnl/aniseed/eval.fnl" local str = nil local function _1_(code, opts) local fnl = fennel.impl() local function _2_() - return fnl.eval(compile["macros-prefix"](code, opts), a.merge({["compiler-env"] = _G}, opts)) + return fnl.eval(code, a.merge({["compiler-env"] = _G}, opts)) end return xpcall(_2_, fnl.traceback) end From 173bbf84503f8fc29e37cc5844ee13af8820c80a Mon Sep 17 00:00:00 2001 From: Andrew DeFilippo Date: Mon, 2 Aug 2021 15:57:25 -0500 Subject: [PATCH 11/11] Forgot to add the compiler plugin in opts in eval ... --- fnl/aniseed/eval.fnl | 13 +++++++++++-- lua/aniseed/env.lua | 4 ++-- lua/aniseed/eval.lua | 37 ++++++++++++++++++++++++++++++------- lua/aniseed/test.lua | 4 ++-- 4 files changed, 45 insertions(+), 13 deletions(-) diff --git a/fnl/aniseed/eval.fnl b/fnl/aniseed/eval.fnl index c794628..6e5cd02 100644 --- a/fnl/aniseed/eval.fnl +++ b/fnl/aniseed/eval.fnl @@ -5,13 +5,22 @@ fennel aniseed.fennel compile aniseed.compile}}) +(local base-path (-?> (. (debug.getinfo 1 :S) :source) + (: :gsub :^. "") + (: :gsub (string.gsub *file* :fnl :lua) ""))) + (defn str [code opts] "Like aniseed.compile/str but uses fennel.eval. Returns the result of evaluating the given Fennel code with the Aniseed macros automatically equired." - (let [fnl (fennel.impl)] + (let [fnl (fennel.impl) + plugins ["module-system-plugin.fnl"] + plugins (icollect [_ plugin (ipairs plugins)] + (fnl.dofile (.. base-path plugin) + {:env :_COMPILER + :useMetadata true}))] (xpcall (fn [] (-> code - (fnl.eval (a.merge {:compiler-env _G} opts)))) + (fnl.eval (a.merge {:compiler-env _G : plugins} opts)))) fnl.traceback))) diff --git a/lua/aniseed/env.lua b/lua/aniseed/env.lua index e677099..54e5cfe 100644 --- a/lua/aniseed/env.lua +++ b/lua/aniseed/env.lua @@ -1,12 +1,12 @@ local autoload = (require("aniseed.autoload")).autoload -local fennel, fs, nvim, compile, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil +local nvim, fennel, fs, compile, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil local _0_ do local mod_0_ = {["aniseed/local-fns"] = {autoload = {compile = "aniseed.compile", fennel = "aniseed.fennel", fs = "aniseed.fs", nvim = "aniseed.nvim"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.env"} package.loaded["aniseed.env"] = mod_0_ _0_ = mod_0_ end -fennel, fs, nvim, compile, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(fennel, "aniseed.fennel"), autoload(fs, "aniseed.fs"), autoload(nvim, "aniseed.nvim"), autoload(compile, "aniseed.compile"), _0_, "aniseed.env", "fnl/aniseed/env.fnl" +nvim, fennel, fs, compile, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(nvim, "aniseed.nvim"), autoload(fennel, "aniseed.fennel"), autoload(fs, "aniseed.fs"), autoload(compile, "aniseed.compile"), _0_, "aniseed.env", "fnl/aniseed/env.fnl" local config_dir = nil config_dir = nvim.fn.stdpath("config") do end (_2amodule_2a)["aniseed/locals"]["config-dir"] = config_dir diff --git a/lua/aniseed/eval.lua b/lua/aniseed/eval.lua index 71d39a9..8640330 100644 --- a/lua/aniseed/eval.lua +++ b/lua/aniseed/eval.lua @@ -1,21 +1,44 @@ local autoload = (require("aniseed.autoload")).autoload -local fs, nvim, a, compile, fennel, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil, nil +local a, compile, fs, fennel, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil, nil local _0_ do local mod_0_ = {["aniseed/local-fns"] = {autoload = {a = "aniseed.core", compile = "aniseed.compile", fennel = "aniseed.fennel", fs = "aniseed.fs", nvim = "aniseed.nvim"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.eval"} package.loaded["aniseed.eval"] = mod_0_ _0_ = mod_0_ end -fs, nvim, a, compile, fennel, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(fs, "aniseed.fs"), autoload(nvim, "aniseed.nvim"), autoload(a, "aniseed.core"), autoload(compile, "aniseed.compile"), autoload(fennel, "aniseed.fennel"), _0_, "aniseed.eval", "fnl/aniseed/eval.fnl" +a, compile, fs, fennel, nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(a, "aniseed.core"), autoload(compile, "aniseed.compile"), autoload(fs, "aniseed.fs"), autoload(fennel, "aniseed.fennel"), autoload(nvim, "aniseed.nvim"), _0_, "aniseed.eval", "fnl/aniseed/eval.fnl" +local base_path +do + local _1_ = (debug.getinfo(1, "S")).source + if _1_ then + local _2_ = _1_:gsub("^.", "") + if _2_ then + base_path = _2_:gsub(string.gsub(_2afile_2a, "fnl", "lua"), "") + else + base_path = _2_ + end + else + base_path = _1_ + end +end local str = nil -local function _1_(code, opts) +local function _2_(code, opts) local fnl = fennel.impl() - local function _2_() - return fnl.eval(code, a.merge({["compiler-env"] = _G}, opts)) + local plugins = {"module-system-plugin.fnl"} + local plugins0 + do + local tbl_0_ = {} + for _, plugin in ipairs(plugins) do + tbl_0_[(#tbl_0_ + 1)] = fnl.dofile((base_path .. plugin), {env = "_COMPILER", useMetadata = true}) + end + plugins0 = tbl_0_ + end + local function _3_() + return fnl.eval(code, a.merge({["compiler-env"] = _G, plugins = plugins0}, opts)) end - return xpcall(_2_, fnl.traceback) + return xpcall(_3_, fnl.traceback) end -str = _1_ +str = _2_ _2amodule_2a["str"] = str _2amodule_2a["aniseed/locals"]["str"] = str return nil diff --git a/lua/aniseed/test.lua b/lua/aniseed/test.lua index 7a1af36..c966ac2 100644 --- a/lua/aniseed/test.lua +++ b/lua/aniseed/test.lua @@ -1,12 +1,12 @@ local autoload = (require("aniseed.autoload")).autoload -local a, fs, nvim, str, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil +local nvim, a, fs, str, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil local _0_ do local mod_0_ = {["aniseed/local-fns"] = {autoload = {a = "aniseed.core", fs = "aniseed.fs", nvim = "aniseed.nvim", str = "aniseed.string"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.test"} package.loaded["aniseed.test"] = mod_0_ _0_ = mod_0_ end -a, fs, nvim, str, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(a, "aniseed.core"), autoload(fs, "aniseed.fs"), autoload(nvim, "aniseed.nvim"), autoload(str, "aniseed.string"), _0_, "aniseed.test", "fnl/aniseed/test.fnl" +nvim, a, fs, str, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(nvim, "aniseed.nvim"), autoload(a, "aniseed.core"), autoload(fs, "aniseed.fs"), autoload(str, "aniseed.string"), _0_, "aniseed.test", "fnl/aniseed/test.fnl" local ok_3f = nil local function _2_(_1_) local _arg_0_ = _1_