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/example.fnl b/example.fnl new file mode 100644 index 0000000..992d497 --- /dev/null +++ b/example.fnl @@ -0,0 +1,7 @@ +(module mymod + {require {a aniseed.core}}) + +(def- private-val :this-is-private) + +(+ 10 20) +(a.println "Hello, World!") 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/eval.fnl b/fnl/aniseed/eval.fnl index d19c28c..6e5cd02 100644 --- a/fnl/aniseed/eval.fnl +++ b/fnl/aniseed/eval.fnl @@ -5,14 +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 - (compile.macros-prefix opts) - (fnl.eval (a.merge {:compiler-env _G} opts)))) + (fnl.eval (a.merge {:compiler-env _G : plugins} opts)))) fnl.traceback))) 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..d1d5812 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_ -end -local autoload -local function _1_(...) - return (require("aniseed.autoload")).autoload(...) + local mod_0_ = {["aniseed/local-fns"] = {}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.autoload"} + package.loaded["aniseed.autoload"] = mod_0_ + _0_ = mod_0_ end -autoload = _1_ -local function _2_(...) - local ok_3f_0_, val_0_ = nil, nil - local function _2_() - return {} +_2amodule_2a, _2amodule_name_2a, _2afile_2a = _0_, "aniseed.autoload", "fnl/aniseed/autoload.fnl" +local autoload = nil +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..812968f 100644 --- a/lua/aniseed/compile.lua +++ b/lua/aniseed/compile.lua @@ -1,146 +1,74 @@ -local _2afile_2a = "fnl/aniseed/compile.fnl" +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 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_ + 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" +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 - module_0_ = {} + base_path = _2_ 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_(...) - 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_) + base_path = _1_ end 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 -do - local v_0_ +local str = nil +local function _2_(code, opts) + local fnl = fennel.impl() + local plugins = {"module-system-plugin.fnl"} + local plugins0 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 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 = macros_prefix0 - _0_["macros-prefix"] = v_0_0 - v_0_ = v_0_0 + plugins0 = tbl_0_ end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["macros-prefix"] = v_0_ - macros_prefix = v_0_ -end -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.compileString(macros_prefix(code, opts), a.merge({allowedGlobals = false}, opts)) - end - return xpcall(_3_, fnl.traceback) - end - v_0_0 = str0 - _0_["str"] = v_0_0 - v_0_ = v_0_0 + local function _3_() + return fnl.compileString(code, a.merge({allowedGlobals = false, plugins = plugins0}, opts)) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["str"] = v_0_ - str = v_0_ + return xpcall(_3_, fnl.traceback) end -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 +str = _2_ +_2amodule_2a["str"] = str +_2amodule_2a["aniseed/locals"]["str"] = str +local file = nil +local function _3_(src, dest) + local code = a.slurp(src) + local _4_, _5_ = str(code, {filename = src}) + if ((_4_ == false) and (nil ~= _5_)) then + local err = _5_ + return nvim.err_writeln(err) + elseif ((_4_ == true) and (nil ~= _5_)) then + local result = _5_ + 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 -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 +file = _3_ +_2amodule_2a["file"] = file +_2amodule_2a["aniseed/locals"]["file"] = file +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 + 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 = _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 47693bb..5100602 100644 --- a/lua/aniseed/core.lua +++ b/lua/aniseed/core.lua @@ -1,957 +1,537 @@ -local _2afile_2a = "fnl/aniseed/core.fnl" +local autoload = (require("aniseed.autoload")).autoload +local view, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil 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_(...) - 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 + local mod_0_ = {["aniseed/local-fns"] = {autoload = {view = "aniseed.view"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.core"} + package.loaded["aniseed.core"] = mod_0_ + _0_ = 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"), _0_, "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_ -end -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_ -end -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_ -end -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_ -end -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 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["count"] = v_0_ - count = v_0_ -end -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_ -end -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 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["first"] = v_0_ - first = v_0_ -end -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 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["second"] = v_0_ - second = v_0_ -end -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 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["last"] = v_0_ - last = v_0_ -end -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_ -end -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_ -end -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_ -end -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_ -end -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 - 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_ -end -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 - 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_ -end -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 - 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_ -end -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 - end - 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 -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 - 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_ -end -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_()) - end - run_21(_3_, xs) - return result - end - v_0_0 = map0 - _0_["map"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["map"] = v_0_ - map = v_0_ -end -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_ -end -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_ -end -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 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 - end - v_0_0 = some0 - _0_["some"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["some"] = v_0_ - some = v_0_ -end -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 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 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 - end - v_0_0 = concat0 - _0_["concat"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["concat"] = v_0_ - concat = v_0_ -end -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_ -end -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 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["pr-str"] = v_0_ - pr_str = v_0_ -end -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_, {...})) - 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_ -end -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_, {...})))) - 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(...)) - 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_ -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_ -end -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() +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 = 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 = 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 = 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 = nil +local function _5_(xs) + if table_3f(xs) then + return table.maxn(xs) + elseif not xs then + return 0 + else + return #xs + end +end +count = _5_ +_2amodule_2a["count"] = count +_2amodule_2a["aniseed/locals"]["count"] = count +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 = nil +local function _7_(xs) + if xs then + return xs[1] + end +end +first = _7_ +_2amodule_2a["first"] = first +_2amodule_2a["aniseed/locals"]["first"] = first +local second = nil +local function _8_(xs) + if xs then + return xs[2] + end +end +second = _8_ +_2amodule_2a["second"] = second +_2amodule_2a["aniseed/locals"]["second"] = second +local last = nil +local function _9_(xs) + if xs then + return xs[count(xs)] + end +end +last = _9_ +_2amodule_2a["last"] = last +_2amodule_2a["aniseed/locals"]["last"] = last +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 = nil +local function _11_(n) + return (n - 1) +end +dec = _11_ +_2amodule_2a["dec"] = dec +_2amodule_2a["aniseed/locals"]["dec"] = dec +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 = 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 = nil +local function _14_(t) + local result = {} + if t then + for k, _ in pairs(t) do + table.insert(result, k) + end + end + return result +end +keys = _14_ +_2amodule_2a["keys"] = keys +_2amodule_2a["aniseed/locals"]["keys"] = keys +local vals = nil +local function _15_(t) + local result = {} + if t then + for _, v in pairs(t) do + table.insert(result, v) + end + end + return result +end +vals = _15_ +_2amodule_2a["vals"] = vals +_2amodule_2a["aniseed/locals"]["vals"] = vals +local kv_pairs = nil +local function _16_(t) + local result = {} + if t then + for k, v in pairs(t) do + table.insert(result, {k, v}) + end + end + return result +end +kv_pairs = _16_ +_2amodule_2a["kv-pairs"] = kv_pairs +_2amodule_2a["aniseed/locals"]["kv-pairs"] = kv_pairs +local run_21 = nil +local function _17_(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 + end +end +run_21 = _17_ +_2amodule_2a["run!"] = run_21 +_2amodule_2a["aniseed/locals"]["run!"] = run_21 +local filter = nil +local function _18_(f, xs) + local result = {} + local function _19_(x) + if f(x) then + return table.insert(result, x) + end + end + run_21(_19_, xs) + return result +end +filter = _18_ +_2amodule_2a["filter"] = filter +_2amodule_2a["aniseed/locals"]["filter"] = filter +local map = nil +local function _19_(f, xs) + local result = {} + local function _20_(x) + local mapped = f(x) + local function _21_() + if (0 == select("#", mapped)) then 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 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 - end - return reduce(_3_, (base or {}), {...}) - end - v_0_0 = merge_210 - _0_["merge!"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["merge!"] = v_0_ - merge_21 = v_0_ -end -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_ -end -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 {} - end - end - v_0_0 = select_keys0 - _0_["select-keys"] = v_0_0 - v_0_ = v_0_0 + return mapped + end + end + return table.insert(result, _21_()) + end + run_21(_20_, xs) + return result +end +map = _19_ +_2amodule_2a["map"] = map +_2amodule_2a["aniseed/locals"]["map"] = map +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 = nil +local function _21_(x) + return x +end +identity = _21_ +_2amodule_2a["identity"] = identity +_2amodule_2a["aniseed/locals"]["identity"] = identity +local reduce = nil +local function _22_(f, init, xs) + local result = init + local function _23_(x) + result = f(result, x) + return nil + end + run_21(_23_, xs) + return result +end +reduce = _22_ +_2amodule_2a["reduce"] = reduce +_2amodule_2a["aniseed/locals"]["reduce"] = reduce +local some = nil +local function _23_(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 +end +some = _23_ +_2amodule_2a["some"] = some +_2amodule_2a["aniseed/locals"]["some"] = some +local butlast = nil +local function _24_(xs) + local total = count(xs) + 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(_26_, kv_pairs(xs))) +end +butlast = _24_ +_2amodule_2a["butlast"] = butlast +_2amodule_2a["aniseed/locals"]["butlast"] = butlast +local rest = nil +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(_27_, kv_pairs(xs))) +end +rest = _25_ +_2amodule_2a["rest"] = rest +_2amodule_2a["aniseed/locals"]["rest"] = rest +local concat = nil +local function _26_(...) + local result = {} + local function _27_(xs) + local function _28_(x) + return table.insert(result, x) + end + return run_21(_28_, xs) + end + run_21(_27_, {...}) + return result +end +concat = _26_ +_2amodule_2a["concat"] = concat +_2amodule_2a["aniseed/locals"]["concat"] = concat +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 = nil +local function _28_(...) + local s + local function _29_(x) + return view.serialise(x, {["one-line"] = true}) + end + s = table.concat(map(_29_, {...}), " ") + if (nil_3f(s) or ("" == s)) then + return "nil" + else + return s end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["select-keys"] = v_0_ - select_keys = v_0_ end -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 - end - v_0_0 = get0 - _0_["get"] = v_0_0 - v_0_ = v_0_0 +pr_str = _28_ +_2amodule_2a["pr-str"] = pr_str +_2amodule_2a["aniseed/locals"]["pr-str"] = pr_str +local str = nil +local function _29_(...) + local function _30_(acc, s) + return (acc .. s) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["get"] = v_0_ - get = v_0_ -end -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 _31_(s) + if string_3f(s) then + return s + else + return pr_str(s) 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_ + return reduce(_30_, "", map(_31_, {...})) 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 +str = _29_ +_2amodule_2a["str"] = str +_2amodule_2a["aniseed/locals"]["str"] = str +local println = nil +local function _30_(...) + local function _31_(acc, s) + return (acc .. s) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["assoc"] = v_0_ - assoc = v_0_ -end -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 _33_(_32_) + local _arg_0_ = _32_ + local i = _arg_0_[1] + local s = _arg_0_[2] + if (1 == i) then + return s + else + return (" " .. s) 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_ -end -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))) + local function _34_(s) + if string_3f(s) then + return s + else + return pr_str(s) + end + end + return print(reduce(_31_, "", map_indexed(_33_, map(_34_, {...})))) +end +println = _30_ +_2amodule_2a["println"] = println +_2amodule_2a["aniseed/locals"]["println"] = println +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 = nil +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 ~= _33_) then + local f = _33_ + local content = f:read("*all") + f:close() + return content + end +end +slurp = _32_ +_2amodule_2a["slurp"] = slurp +_2amodule_2a["aniseed/locals"]["slurp"] = slurp +local spit = nil +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 ~= _34_) then + local f = _34_ + f:write(content) + f:close() + return nil + end +end +spit = _33_ +_2amodule_2a["spit"] = spit +_2amodule_2a["aniseed/locals"]["spit"] = spit +local merge_21 = nil +local function _34_(base, ...) + local function _35_(acc, m) + if m then + for k, v in pairs(m) do + acc[k] = v + end + end + return acc + end + return reduce(_35_, (base or {}), {...}) +end +merge_21 = _34_ +_2amodule_2a["merge!"] = merge_21 +_2amodule_2a["aniseed/locals"]["merge!"] = merge_21 +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 = nil +local function _36_(t, ks) + if (t and ks) then + local function _37_(acc, k) + if k then + acc[k] = t[k] + end + return acc + end + return reduce(_37_, {}, ks) + else + return {} + end +end +select_keys = _36_ +_2amodule_2a["select-keys"] = select_keys +_2amodule_2a["aniseed/locals"]["select-keys"] = select_keys +local get = nil +local function _37_(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 = update0 - _0_["update"] = v_0_0 - v_0_ = v_0_0 + else + res = nil end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["update"] = v_0_ - update = v_0_ -end -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 + if nil_3f(res) then + return d + else + return res end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["update-in"] = v_0_ - update_in = v_0_ end -local constantly -do - local v_0_ - do - local v_0_0 - local function constantly0(v) - local function _3_() - return v - end - return _3_ +get = _37_ +_2amodule_2a["get"] = get +_2amodule_2a["aniseed/locals"]["get"] = get +local get_in = nil +local function _38_(t, ks, d) + local res + local function _39_(acc, k) + if table_3f(acc) then + return get(acc, k) end - v_0_0 = constantly0 - _0_["constantly"] = v_0_0 - v_0_ = v_0_0 end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["constantly"] = v_0_ - constantly = v_0_ -end + res = reduce(_39_, t, ks) + if nil_3f(res) then + return d + else + return res + end +end +get_in = _38_ +_2amodule_2a["get-in"] = get_in +_2amodule_2a["aniseed/locals"]["get-in"] = get_in +local assoc = nil +local function _39_(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 = _39_ +_2amodule_2a["assoc"] = assoc +_2amodule_2a["aniseed/locals"]["assoc"] = assoc +local assoc_in = nil +local function _40_(t, ks, v) + local path = butlast(ks) + local final = last(ks) + local t0 = (t or {}) + local function _41_(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(_41_, t0, path), final, v) + return t0 +end +assoc_in = _40_ +_2amodule_2a["assoc-in"] = assoc_in +_2amodule_2a["aniseed/locals"]["assoc-in"] = assoc_in +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 = 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 = nil +local function _43_(v) + local function _44_() + return v + end + return _44_ +end +constantly = _43_ +_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..54e5cfe 100644 --- a/lua/aniseed/env.lua +++ b/lua/aniseed/env.lua @@ -1,108 +1,54 @@ -local _2afile_2a = "fnl/aniseed/env.fnl" +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 _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_(...) - return (require("aniseed.autoload")).autoload(...) + 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 -autoload = _1_ -local function _2_(...) - local ok_3f_0_, val_0_ = nil, nil +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 = nil +local function _1_(m) + local ok_3f, err = nil, nil local function _2_() - return {autoload("aniseed.compile"), autoload("aniseed.fennel"), autoload("aniseed.fs"), autoload("aniseed.nvim")} + return require(m) 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_) + 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 -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 -do - local v_0_ = nvim.fn.stdpath("config") - local t_0_ = (_0_)["aniseed/locals"] - t_0_["config-dir"] = v_0_ - config_dir = v_0_ -end -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 +quiet_require = _1_ +_2amodule_2a["aniseed/locals"]["quiet-require"] = quiet_require +local init = nil +local function _2_(opts) + local opts0 + if ("table" == type(opts)) then + opts0 = opts + else + opts0 = {} end - v_0_ = quiet_require0 - local t_0_ = (_0_)["aniseed/locals"] - t_0_["quiet-require"] = v_0_ - quiet_require = v_0_ -end -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 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 - 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, _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 = _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 2e40a5b..8640330 100644 --- a/lua/aniseed/eval.lua +++ b/lua/aniseed/eval.lua @@ -1,67 +1,44 @@ -local _2afile_2a = "fnl/aniseed/eval.fnl" +local autoload = (require("aniseed.autoload")).autoload +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 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_ + 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 +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 - module_0_ = {} + base_path = _2_ 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_(...) - 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_) + base_path = _1_ end 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 -local str -do - local v_0_ +local str = nil +local function _2_(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.eval(compile["macros-prefix"](code, opts), a.merge({["compiler-env"] = _G}, 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 function _3_() + return fnl.eval(code, a.merge({["compiler-env"] = _G, plugins = plugins0}, 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..fd60f43 100644 --- a/lua/aniseed/fennel.lua +++ b/lua/aniseed/fennel.lua @@ -1,112 +1,47 @@ -local _2afile_2a = "fnl/aniseed/fennel.fnl" +local autoload = (require("aniseed.autoload")).autoload +local nvim, fs, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil 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_(...) - 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 -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_ + _0_ = 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_ +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 = nil +local function _1_(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 -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 +sync_rtp = _1_ +_2amodule_2a["sync-rtp"] = sync_rtp +_2amodule_2a["aniseed/locals"]["sync-rtp"] = sync_rtp +local state = nil +state = {["compiler-loaded?"] = false} +_2amodule_2a["aniseed/locals"]["state"] = state +local impl = nil +local function _2_() + 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 -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_ +impl = _2_ +_2amodule_2a["impl"] = impl +_2amodule_2a["aniseed/locals"]["impl"] = impl +local add_path = nil +local function _3_(path) + local fnl = impl() + do end (fnl)["path"] = (fnl.path .. ";" .. path) + return nil end +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 d3b667e..6fb56eb 100644 --- a/lua/aniseed/fs.lua +++ b/lua/aniseed/fs.lua @@ -1,154 +1,66 @@ -local _2afile_2a = "fnl/aniseed/fs.fnl" +local autoload = (require("aniseed.autoload")).autoload +local nvim, a, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil 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_(...) - return (require("aniseed.autoload")).autoload(...) + 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 -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_ +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 = nil +do + local os = string.lower(jit.os) + if (("linux" == os) or ("osx" == os) or ("bsd" == os)) then + path_sep = "/" else - return print(val_0_) + path_sep = "\\" end 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 -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 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["path-sep"] = v_0_ - path_sep = v_0_ +_2amodule_2a["path-sep"] = path_sep +_2amodule_2a["aniseed/locals"]["path-sep"] = path_sep +local basename = nil +local function _1_(path) + return nvim.fn.fnamemodify(path, ":h") end -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_ +basename = _1_ +_2amodule_2a["basename"] = basename +_2amodule_2a["aniseed/locals"]["basename"] = basename +local mkdirp = nil +local function _2_(dir) + return nvim.fn.mkdir(dir, "p") end -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_ -end -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 +mkdirp = _2_ +_2amodule_2a["mkdirp"] = mkdirp +_2amodule_2a["aniseed/locals"]["mkdirp"] = mkdirp +local relglob = nil +local function _3_(dir, expr) + local dir_len = a.inc(string.len(dir)) + local function _4_(_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(_4_, nvim.fn.globpath(dir, expr, true, true)) end -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 +relglob = _3_ +_2amodule_2a["relglob"] = relglob +_2amodule_2a["aniseed/locals"]["relglob"] = relglob +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 + 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 -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_ +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 = nil +local function _5_(path) + return string.match(path, "macros.fnl$") end +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/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..7919dc8 100644 --- a/lua/aniseed/nvim/util.lua +++ b/lua/aniseed/nvim/util.lua @@ -1,122 +1,62 @@ -local _2afile_2a = "fnl/aniseed/nvim/util.fnl" +local autoload = (require("aniseed.autoload")).autoload +local nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil 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_ + local mod_0_ = {["aniseed/local-fns"] = {autoload = {nvim = "aniseed.nvim"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.nvim.util"} + package.loaded["aniseed.nvim.util"] = mod_0_ + _0_ = mod_0_ end -local autoload -local function _1_(...) - return (require("aniseed.autoload")).autoload(...) +nvim, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(nvim, "aniseed.nvim"), _0_, "aniseed.nvim.util", "fnl/aniseed/nvim/util.fnl" +local normal = nil +local function _1_(keys) + return nvim.ex.silent(("exe \"normal! " .. keys .. "\"")) 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_ +normal = _1_ +_2amodule_2a["normal"] = normal +_2amodule_2a["aniseed/locals"]["normal"] = normal +local fn_bridge = nil +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 _3_ + if range then + _3_ = " range" else - return print(val_0_) + _3_ = "" end -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 -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 + local _5_ + if (_return ~= false) then + _5_ = "return" + else + _5_ = "call" end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["normal"] = v_0_ - normal = v_0_ -end -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 _7_ + if range then + _7_ = "\" . a:firstline . \", \" . a:lastline . \", " + else + _7_ = "" end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["fn-bridge"] = v_0_ - fn_bridge = v_0_ + return nvim.ex.function_((viml_name .. "(...)" .. _3_ .. "\n " .. _5_ .. " luaeval(\"require('" .. mod .. "')['" .. lua_name .. "'](" .. _7_ .. "unpack(_A))\", a:000)\n endfunction")) end -local with_out_str -do - local v_0_ +fn_bridge = _2_ +_2amodule_2a["fn-bridge"] = fn_bridge +_2amodule_2a["aniseed/locals"]["fn-bridge"] = fn_bridge +local with_out_str = nil +local function _3_(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 = _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 d1ddb2f..b35a8b8 100644 --- a/lua/aniseed/string.lua +++ b/lua/aniseed/string.lua @@ -1,182 +1,95 @@ -local _2afile_2a = "fnl/aniseed/string.fnl" +local autoload = (require("aniseed.autoload")).autoload +local a, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil 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_ + local mod_0_ = {["aniseed/local-fns"] = {autoload = {a = "aniseed.core"}}, ["aniseed/locals"] = {}, ["aniseed/module"] = "aniseed.string"} + package.loaded["aniseed.string"] = mod_0_ + _0_ = mod_0_ end -local autoload +a, _2amodule_2a, _2amodule_name_2a, _2afile_2a = autoload(a, "aniseed.core"), _0_, "aniseed.string", "fnl/aniseed/string.fnl" +local join = nil 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 {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_) + local args = {...} + local function _2_(...) + if (2 == a.count(args)) then + return args + else + return {"", a.first(args)} + end end -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 -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 _let_0_ = _2_(...) + 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 _3_ + if ("string" == type(x)) then + _3_ = x + elseif (nil == x) then + _3_ = x + else + _3_ = 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 _3_ then + table.insert(result, _3_) + 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 -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 +join = _1_ +_2amodule_2a["join"] = join +_2amodule_2a["aniseed/locals"]["join"] = join +local split = nil +local function _2_(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 -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_ +split = _2_ +_2amodule_2a["split"] = split +_2amodule_2a["aniseed/locals"]["split"] = split +local blank_3f = nil +local function _3_(s) + return (a["empty?"](s) or not string.find(s, "[^%s]")) end -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_ +blank_3f = _3_ +_2amodule_2a["blank?"] = blank_3f +_2amodule_2a["aniseed/locals"]["blank?"] = blank_3f +local triml = nil +local function _4_(s) + return string.gsub(s, "^%s*(.-)", "%1") end -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_ +triml = _4_ +_2amodule_2a["triml"] = triml +_2amodule_2a["aniseed/locals"]["triml"] = triml +local trimr = nil +local function _5_(s) + return string.gsub(s, "(.-)%s*$", "%1") end -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_ +trimr = _5_ +_2amodule_2a["trimr"] = trimr +_2amodule_2a["aniseed/locals"]["trimr"] = trimr +local trim = nil +local function _6_(s) + return string.gsub(s, "^%s*(.-)%s*$", "%1") end +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 34bb445..c966ac2 100644 --- a/lua/aniseed/test.lua +++ b/lua/aniseed/test.lua @@ -1,235 +1,154 @@ -local _2afile_2a = "fnl/aniseed/test.fnl" +local autoload = (require("aniseed.autoload")).autoload +local nvim, a, fs, str, _2amodule_2a, _2amodule_name_2a, _2afile_2a = nil, nil, nil, nil, nil, nil, nil 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_(...) - return (require("aniseed.autoload")).autoload(...) + 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 -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 +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_ + local tests = _arg_0_["tests"] + local tests_passed = _arg_0_["tests-passed"] + return (tests == tests_passed) 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 -local ok_3f -do - local v_0_ +ok_3f = _2_ +_2amodule_2a["ok?"] = ok_3f +_2amodule_2a["aniseed/locals"]["ok?"] = ok_3f +local display_results = nil +local function _3_(results, prefix) 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) + 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 _4_ + if ok_3f(results) then + _4_ = "OK" + else + _4_ = "FAILED" end - v_0_0 = ok_3f0 - _0_["ok?"] = v_0_0 - v_0_ = v_0_0 + a.println((prefix .. " " .. _4_ .. " " .. tests_passed .. "/" .. tests .. " tests and " .. assertions_passed .. "/" .. assertions .. " assertions passed")) end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["ok?"] = v_0_ - ok_3f = v_0_ + return results end -local display_results -do - local v_0_ - do - local v_0_0 - local function display_results0(results, prefix) +display_results = _3_ +_2amodule_2a["display-results"] = display_results +_2amodule_2a["aniseed/locals"]["display-results"] = display_results +local run = nil +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 + 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 _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 - end - v_0_0 = display_results0 - _0_["display-results"] = v_0_0 - v_0_ = v_0_0 - end - local t_0_ = (_0_)["aniseed/locals"] - t_0_["display-results"] = v_0_ - display_results = v_0_ -end -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 prefix = ("[" .. mod_name .. "/" .. label .. "]") + local fail + local function _5_(desc, ...) + test_failed = true + local function _6_(...) + 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, " ", ...}) .. _6_(...))) + end + fail = _5_ + local begin + local function _6_() + return a.update(results, "assertions", a.inc) + end + begin = _6_ + local pass + local function _7_() + return a.update(results, "assertions-passed", a.inc) + end + pass = _7_ + local t + local function _8_(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 _9_(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 _10_(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 - return display_results(results, ("[" .. mod_name .. "]")) + t = {["="] = _8_, ["ok?"] = _9_, ["pr="] = _10_} + local _11_, _12_ = nil, nil + local function _13_() + return f(t) + end + _11_, _12_ = pcall(_13_) + if ((_11_ == false) and (nil ~= _12_)) then + local err = _12_ + 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 -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]") +run = _4_ +_2amodule_2a["run"] = run +_2amodule_2a["aniseed/locals"]["run"] = run +local run_all = nil +local function _5_() + local function _6_(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(_6_, {["assertions-passed"] = 0, ["tests-passed"] = 0, assertions = 0, tests = 0}, a.filter(a["table?"], a.map(run, a.keys(package.loaded)))), "[total]") end -local suite -do - local v_0_ +run_all = _5_ +_2amodule_2a["run-all"] = run_all +_2amodule_2a["aniseed/locals"]["run-all"] = run_all +local suite = nil +local function _6_() 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 _7_(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!"](_7_, 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 = _6_ +_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..a862d1d 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 +_2amodule_2a, _2amodule_name_2a, _2afile_2a = _0_, "aniseed.view", "fnl/aniseed/view.fnl" +local serialise = nil 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 -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_ + 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..d147404 --- /dev/null +++ b/module-system-plugin.fnl @@ -0,0 +1,215 @@ +(local syms (setmetatable {} {:__index #(sym $2)})) + +(fn table? [x] + (and (= :table (type x)) 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)) + +;; 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 (view-local-fns new-local-fns))) + locals []] + + (tset scope :module {:locals {} :public {}}) + + (when included + (each [_ module (ipairs included)] + (compile `(include ,(tostring module))))) + + (when imported-macros + (each [bindings module (pairs imported-macros)] + (compile `(import-macros ,bindings ,(tostring module))))) + + (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* + `(let [mod# ,mod] + (tset package.loaded ,name-str mod#) + mod#)]) + + (table.insert locals [syms.*module-name* name-str]) + + (when filename + (table.insert locals [syms.*file* 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 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) + + ;; 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))) + + (empty-table ast) + (copy [`tset syms.*module* :aniseed/locals name-str name] ast))) + +(fn defn-form [ast scope compile 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)) + + (def-form ast scope compile private? fn-ast))) + +(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 scope compile private?)))) + +(fn deftest-form [ast scope compile] + (let [[_ name & body] ast + name-str (-?> (assert-compile (. ast 2) "expected name" ast) + (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)] + (table.insert fn-ast stmt)) + + (compile fn-ast) + + (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 compile] + (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) + (set-forcibly! time-fn-sym (gensym)) + (tset scope.module :time-fn-sym 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#)))) + + (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) + opts (doto (copy opts) + (tset :tail false)) + compile (fn [ast] (compile1 ast scope parent opts))] + + (match (. ast 1) + 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/scripts/internal/compile.fnl b/scripts/internal/compile.fnl deleted file mode 100755 index bcde8c4..0000000 --- a/scripts/internal/compile.fnl +++ /dev/null @@ -1,27 +0,0 @@ -(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 - (.. "(local *file* \"" opts.filename "\")" - "(require-macros :aniseed.macros)\n" content) - opts)) - fennel.traceback)) - -(let [filename (. arg 1) - (ok? result) (-> filename - (read-file) - (compile {:filename filename - :compilerEnv false}))] - (if ok? - (print result) - (error result))) diff --git a/test/fnl/aniseed/compile-test.fnl b/test/fnl/aniseed/compile-test.fnl index 66ed29c..c053b82 100644 --- a/test/fnl/aniseed/compile-test.fnl +++ b/test/fnl/aniseed/compile-test.fnl @@ -1,12 +1,45 @@ (module aniseed.compile-test - {autoload {a aniseed.core - compile aniseed.compile}}) + {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.= "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")) + + (compile-fail t "(+ 10 20" 28 "expected closing delimiter")) + +(deftest module + (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") + (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")) - (let [(success result) (compile.str "(+ 10 20")] - (t.ok? (not success)) - (t.= 28 (result:find "expected closing delimiter")))) +(deftest time + (compile-fail t "(time)" 30 "expected body expression")) diff --git a/test/fnl/aniseed/macros-test.fnl b/test/fnl/aniseed/macros-test.fnl deleted file mode 100644 index 47c8d9f..0000000 --- a/test/fnl/aniseed/macros-test.fnl +++ /dev/null @@ -1,12 +0,0 @@ -(module aniseed.macros-test) - -(deftest defonce - (var calls 0) - (fn inc [] - (set calls (+ calls 1)) - :ok) - (t.= 0 calls) - (defonce foo (inc)) - (t.= 1 calls) - (defonce foo (inc)) - (t.= 1 calls)) diff --git a/test/fnl/aniseed/module-system-test.fnl b/test/fnl/aniseed/module-system-test.fnl new file mode 100644 index 0000000..b694e5b --- /dev/null +++ b/test/fnl/aniseed/module-system-test.fnl @@ -0,0 +1,72 @@ +(module aniseed.module-system-test) + +(deftest module + (local initial {:foo :bar}) + + (module module-test + {require {{: println &as 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? (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*")) + +(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")) + +(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") + + (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) + (fn inc [] + (set calls (+ calls 1)) + :ok) + (t.= 0 calls) + (defonce foo (inc)) + (t.= 1 calls) + (defonce foo (inc)) + (t.= 1 calls)) + +(deftest time + (local x 4) + (t.= (time + (local y 5) + (* x y)) + 20 "time function failed") + + (t.= (time 42) 42 "second time function failed"))