@@ 1,29 1,7 @@
#!/usr/bin/env luajit
---WARNING: include module not found, falling back to require: "fennel.utils"
---WARNING: include module not found, falling back to require: "fennel.parser"
---WARNING: include module not found, falling back to require: "fennel.compiler"
---WARNING: include module not found, falling back to require: "fennel.specials"
---WARNING: include module not found, falling back to require: "fennel.view"
---WARNING: include module not found, falling back to require: "fennel.utils"
---WARNING: include module not found, falling back to require: "fennel.view"
---WARNING: include module not found, falling back to require: "fennel.parser"
---WARNING: include module not found, falling back to require: "fennel.compiler"
---WARNING: include module not found, falling back to require: "fennel.utils"
---WARNING: include module not found, falling back to require: "fennel.parser"
---WARNING: include module not found, falling back to require: "fennel.friend"
---WARNING: include module not found, falling back to require: "fennel.utils"
---WARNING: include module not found, falling back to require: "fennel.utils"
---WARNING: include module not found, falling back to require: "fennel.friend"
---WARNING: include module not found, falling back to require: "fennel.view"
---WARNING: include module not found, falling back to require: "fennel.utils"
---WARNING: include module not found, falling back to require: "fennel.parser"
---WARNING: include module not found, falling back to require: "fennel.compiler"
---WARNING: include module not found, falling back to require: "fennel.specials"
---WARNING: include module not found, falling back to require: "fennel.repl"
---WARNING: include module not found, falling back to require: "fennel.view"
local fennel
package.preload["fennel"] = package.preload["fennel"] or function(...)
- local function _1_(...)
+ package.preload["fennel.repl"] = package.preload["fennel.repl"] or function(...)
local utils = require("fennel.utils")
local parser = require("fennel.parser")
local compiler = require("fennel.compiler")
@@ 31,14 9,14 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
local view = require("fennel.view")
local unpack = (table.unpack or _G.unpack)
local function default_read_chunk(parser_state)
- local function _608_()
+ local function _631_()
if (0 < parser_state["stack-size"]) then
return ".."
else
return ">> "
end
end
- io.write(_608_())
+ io.write(_631_())
io.flush()
local input = io.read()
return (input and (input .. "\n"))
@@ 48,36 26,82 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return io.write("\n")
end
local function default_on_error(errtype, err, lua_source)
- local function _610_()
- local _609_ = errtype
- if (_609_ == "Lua Compile") then
+ local function _633_()
+ local _632_ = errtype
+ if (_632_ == "Lua Compile") then
return ("Bad code generated - likely a bug with the compiler:\n" .. "--- Generated Lua Start ---\n" .. lua_source .. "--- Generated Lua End ---\n")
- elseif (_609_ == "Runtime") then
+ elseif (_632_ == "Runtime") then
return (compiler.traceback(tostring(err), 4) .. "\n")
elseif true then
- local _ = _609_
+ local _ = _632_
return ("%s error: %s\n"):format(errtype, tostring(err))
else
return nil
end
end
- return io.write(_610_())
+ return io.write(_633_())
end
- local save_source = table.concat({"local ___i___ = 1", "while true do", " local name, value = debug.getlocal(1, ___i___)", " if(name and name ~= \"___i___\") then", " ___replLocals___[name] = value", " ___i___ = ___i___ + 1", " else break end end"}, "\n")
- local function splice_save_locals(env, lua_source)
- local spliced_source = {}
- local bind = "local %s = ___replLocals___['%s']"
- for line in lua_source:gmatch("([^\n]+)\n?") do
- table.insert(spliced_source, line)
+ local function splice_save_locals(env, lua_source, scope)
+ local saves
+ do
+ local tbl_16_auto = {}
+ local i_17_auto = #tbl_16_auto
+ for name in pairs(env.___replLocals___) do
+ local val_18_auto = ("local %s = ___replLocals___['%s']"):format(name, name)
+ if (nil ~= val_18_auto) then
+ i_17_auto = (i_17_auto + 1)
+ do end (tbl_16_auto)[i_17_auto] = val_18_auto
+ else
+ end
+ end
+ saves = tbl_16_auto
end
- for name in pairs(env.___replLocals___) do
- table.insert(spliced_source, 1, bind:format(name, name))
+ local binds
+ do
+ local tbl_16_auto = {}
+ local i_17_auto = #tbl_16_auto
+ for _, name in pairs(scope.manglings) do
+ local val_18_auto
+ if not scope.gensyms[name] then
+ val_18_auto = ("___replLocals___['%s'] = %s"):format(name, name)
+ else
+ val_18_auto = nil
+ end
+ if (nil ~= val_18_auto) then
+ i_17_auto = (i_17_auto + 1)
+ do end (tbl_16_auto)[i_17_auto] = val_18_auto
+ else
+ end
+ end
+ binds = tbl_16_auto
end
- if ((1 < #spliced_source) and (spliced_source[#spliced_source]):match("^ *return .*$")) then
- table.insert(spliced_source, #spliced_source, save_source)
+ local gap
+ if lua_source:find("\n") then
+ gap = "\n"
else
+ gap = " "
+ end
+ local function _639_()
+ if next(saves) then
+ return (table.concat(saves, " ") .. gap)
+ else
+ return ""
+ end
end
- return table.concat(spliced_source, "\n")
+ local function _642_()
+ local _640_, _641_ = lua_source:match("^(.*)[\n ](return .*)$")
+ if ((nil ~= _640_) and (nil ~= _641_)) then
+ local body = _640_
+ local _return = _641_
+ return (body .. gap .. table.concat(binds, " ") .. gap .. _return)
+ elseif true then
+ local _ = _640_
+ return lua_source
+ else
+ return nil
+ end
+ end
+ return (_639_() .. _642_())
end
local function completer(env, scope, text)
local max_items = 2000
@@ 87,47 111,42 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
local stop_looking_3f = false
local function add_partials(input, tbl, prefix)
local scope_first_3f = ((tbl == env) or (tbl == env.___replLocals___))
- local tbl_14_auto = matches
- local i_15_auto = #tbl_14_auto
- local function _613_()
+ local tbl_16_auto = matches
+ local i_17_auto = #tbl_16_auto
+ local function _644_()
if scope_first_3f then
return scope.manglings
else
return tbl
end
end
- for k, is_mangled in utils.allpairs(_613_()) do
- if (max_items <= #matches) then
- break
- else
- end
- local val_16_auto = nil
+ for k, is_mangled in utils.allpairs(_644_()) do
+ if (max_items <= #matches) then break end
+ local val_18_auto
do
- local lookup_k = nil
+ local lookup_k
if scope_first_3f then
lookup_k = is_mangled
else
lookup_k = k
end
- if ((((type(k) == "string") and (input == k:sub(0, #input))) and not seen[k]) and ((":" ~= prefix:sub(( - 1))) or ("function" == type(tbl[lookup_k])))) then
+ if ((type(k) == "string") and (input == k:sub(0, #input)) and not seen[k] and ((":" ~= prefix:sub(-1)) or ("function" == type(tbl[lookup_k])))) then
seen[k] = true
- val_16_auto = (prefix .. k)
+ val_18_auto = (prefix .. k)
else
- val_16_auto = nil
+ val_18_auto = nil
end
end
- if (nil ~= val_16_auto) then
- i_15_auto = (i_15_auto + 1)
- do
- end
- tbl_14_auto[i_15_auto] = val_16_auto
+ if (nil ~= val_18_auto) then
+ i_17_auto = (i_17_auto + 1)
+ do end (tbl_16_auto)[i_17_auto] = val_18_auto
else
end
end
- return tbl_14_auto
+ return tbl_16_auto
end
local function descend(input, tbl, prefix, add_matches, method_3f)
- local splitter = nil
+ local splitter
if method_3f then
splitter = "^([^:]+):(.*)"
else
@@ 147,7 166,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
end
local function add_matches(input, tbl, prefix)
- local prefix0 = nil
+ local prefix0
if prefix then
prefix0 = (prefix .. ".")
else
@@ 162,10 181,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
end
for _, source in ipairs({scope.specials, scope.macros, (env.___replLocals___ or {}), env, env._G}) do
- if stop_looking_3f then
- break
- else
- end
+ if stop_looking_3f then break end
add_matches(input_fragment, source)
end
return matches
@@ 175,40 191,35 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return input:match("^%s*,")
end
local function command_docs()
- local _622_ = nil
+ local _653_
do
- local tbl_14_auto = {}
- local i_15_auto = #tbl_14_auto
+ local tbl_16_auto = {}
+ local i_17_auto = #tbl_16_auto
for name, f in pairs(commands) do
- local val_16_auto = (" ,%s - %s"):format(name, ((compiler.metadata):get(f, "fnl/docstring") or "undocumented"))
- if (nil ~= val_16_auto) then
- i_15_auto = (i_15_auto + 1)
- do
- end
- tbl_14_auto[i_15_auto] = val_16_auto
+ local val_18_auto = (" ,%s - %s"):format(name, ((compiler.metadata):get(f, "fnl/docstring") or "undocumented"))
+ if (nil ~= val_18_auto) then
+ i_17_auto = (i_17_auto + 1)
+ do end (tbl_16_auto)[i_17_auto] = val_18_auto
else
end
end
- _622_ = tbl_14_auto
+ _653_ = tbl_16_auto
end
- return table.concat(_622_, "\n")
+ return table.concat(_653_, "\n")
end
- local function _17_(_, _0, on_values)
+ commands.help = function(_, _0, on_values)
return on_values({("Welcome to Fennel.\nThis is the REPL where you can enter code to be evaluated.\nYou can also run these repl commands:\n\n" .. command_docs() .. "\n ,exit - Leave the repl.\n\nUse ,doc something to see descriptions for individual macros and special forms.\n\nFor more information about the language, see https://fennel-lang.org/reference")})
end
- commands.help = _17_
- do
- end
do end (compiler.metadata):set(commands.help, "fnl/docstring", "Show this message.")
local function reload(module_name, env, on_values, on_error)
- local _624_, _625_ = pcall(specials["load-code"]("return require(...)", env), module_name)
- if ((_624_ == true) and (nil ~= _625_)) then
- local old = _625_
- local _ = nil
+ local _655_, _656_ = pcall(specials["load-code"]("return require(...)", env), module_name)
+ if ((_655_ == true) and (nil ~= _656_)) then
+ local old = _656_
+ local _
package.loaded[module_name] = nil
_ = nil
local ok, new = pcall(require, module_name)
- local new0 = nil
+ local new0
if not ok then
on_values({new})
new0 = old
@@ 230,79 241,73 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
else
end
return on_values({"ok"})
- elseif ((_624_ == false) and (nil ~= _625_)) then
- local msg = _625_
- if (specials["macro-loaded"])[module_name] then
+ elseif ((_655_ == false) and (nil ~= _656_)) then
+ local msg = _656_
+ if msg:match("loop or previous error loading module") then
+ package.loaded[module_name] = nil
+ return reload(module_name, env, on_values, on_error)
+ elseif (specials["macro-loaded"])[module_name] then
specials["macro-loaded"][module_name] = nil
return nil
else
- local function _630_()
- local _629_ = msg:gsub("\n.*", "")
- return _629_
+ local function _661_()
+ local _660_ = msg:gsub("\n.*", "")
+ return _660_
end
- return on_error("Runtime", _630_())
+ return on_error("Runtime", _661_())
end
else
return nil
end
end
local function run_command(read, on_error, f)
- local _633_, _634_, _635_ = pcall(read)
- if (((_633_ == true) and (_634_ == true)) and (nil ~= _635_)) then
- local val = _635_
+ local _664_, _665_, _666_ = pcall(read)
+ if ((_664_ == true) and (_665_ == true) and (nil ~= _666_)) then
+ local val = _666_
return f(val)
- elseif (_633_ == false) then
+ elseif (_664_ == false) then
return on_error("Parse", "Couldn't parse input.")
else
return nil
end
end
- local function _24_(env, read, on_values, on_error)
- local function _637_(_241)
+ commands.reload = function(env, read, on_values, on_error)
+ local function _668_(_241)
return reload(tostring(_241), env, on_values, on_error)
end
- return run_command(read, on_error, _637_)
- end
- commands.reload = _24_
- do
+ return run_command(read, on_error, _668_)
end
do end (compiler.metadata):set(commands.reload, "fnl/docstring", "Reload the specified module.")
- local function _25_(env, _, on_values)
+ commands.reset = function(env, _, on_values)
env.___replLocals___ = {}
return on_values({"ok"})
end
- commands.reset = _25_
- do
- end
do end (compiler.metadata):set(commands.reset, "fnl/docstring", "Erase all repl-local scope.")
- local function _26_(env, read, on_values, on_error, scope, chars)
- local function _638_()
- return on_values(completer(env, scope, string.char(unpack(chars)):gsub(",complete +", ""):sub(1, ( - 2))))
+ commands.complete = function(env, read, on_values, on_error, scope, chars)
+ local function _669_()
+ return on_values(completer(env, scope, string.char(unpack(chars)):gsub(",complete +", ""):sub(1, -2)))
end
- return run_command(read, on_error, _638_)
- end
- commands.complete = _26_
- do
+ return run_command(read, on_error, _669_)
end
do end (compiler.metadata):set(commands.complete, "fnl/docstring", "Print all possible completions for a given input symbol.")
local function apropos_2a(pattern, tbl, prefix, seen, names)
for name, subtbl in pairs(tbl) do
if (("string" == type(name)) and (package ~= subtbl)) then
- local _639_ = type(subtbl)
- if (_639_ == "function") then
+ local _670_ = type(subtbl)
+ if (_670_ == "function") then
if ((prefix .. name)):match(pattern) then
table.insert(names, (prefix .. name))
else
end
- elseif (_639_ == "table") then
+ elseif (_670_ == "table") then
if not seen[subtbl] then
- local _642_ = nil
+ local _673_
do
- local _641_ = seen
- _641_[subtbl] = true
- _642_ = _641_
+ local _672_ = seen
+ _672_[subtbl] = true
+ _673_ = _672_
end
- apropos_2a(pattern, subtbl, (prefix .. name:gsub("%.", "/") .. "."), _642_, names)
+ apropos_2a(pattern, subtbl, (prefix .. name:gsub("%.", "/") .. "."), _673_, names)
else
end
else
@@ 314,99 319,84 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
local function apropos(pattern)
local names = apropos_2a(pattern, package.loaded, "", {}, {})
- local tbl_14_auto = {}
- local i_15_auto = #tbl_14_auto
+ local tbl_16_auto = {}
+ local i_17_auto = #tbl_16_auto
for _, name in ipairs(names) do
- local val_16_auto = name:gsub("^_G%.", "")
- if (nil ~= val_16_auto) then
- i_15_auto = (i_15_auto + 1)
- do
- end
- tbl_14_auto[i_15_auto] = val_16_auto
+ local val_18_auto = name:gsub("^_G%.", "")
+ if (nil ~= val_18_auto) then
+ i_17_auto = (i_17_auto + 1)
+ do end (tbl_16_auto)[i_17_auto] = val_18_auto
else
end
end
- return tbl_14_auto
+ return tbl_16_auto
end
- local function _32_(_env, read, on_values, on_error, _scope)
- local function _647_(_241)
+ commands.apropos = function(_env, read, on_values, on_error, _scope)
+ local function _678_(_241)
return on_values(apropos(tostring(_241)))
end
- return run_command(read, on_error, _647_)
- end
- commands.apropos = _32_
- do
+ return run_command(read, on_error, _678_)
end
do end (compiler.metadata):set(commands.apropos, "fnl/docstring", "Print all functions matching a pattern in all loaded modules.")
local function apropos_follow_path(path)
- local paths = nil
+ local paths
do
- local tbl_14_auto = {}
- local i_15_auto = #tbl_14_auto
+ local tbl_16_auto = {}
+ local i_17_auto = #tbl_16_auto
for p in path:gmatch("[^%.]+") do
- local val_16_auto = p
- if (nil ~= val_16_auto) then
- i_15_auto = (i_15_auto + 1)
- do
- end
- tbl_14_auto[i_15_auto] = val_16_auto
+ local val_18_auto = p
+ if (nil ~= val_18_auto) then
+ i_17_auto = (i_17_auto + 1)
+ do end (tbl_16_auto)[i_17_auto] = val_18_auto
else
end
end
- paths = tbl_14_auto
+ paths = tbl_16_auto
end
local tgt = package.loaded
for _, path0 in ipairs(paths) do
- if (nil == tgt) then
- break
- else
- end
- local _650_ = nil
+ if (nil == tgt) then break end
+ local _681_
do
- local _649_ = path0:gsub("%/", ".")
- _650_ = _649_
+ local _680_ = path0:gsub("%/", ".")
+ _681_ = _680_
end
- tgt = tgt[_650_]
+ tgt = tgt[_681_]
end
return tgt
end
local function apropos_doc(pattern)
- local tbl_14_auto = {}
- local i_15_auto = #tbl_14_auto
+ local tbl_16_auto = {}
+ local i_17_auto = #tbl_16_auto
for _, path in ipairs(apropos(".*")) do
- local val_16_auto = nil
+ local val_18_auto
do
local tgt = apropos_follow_path(path)
if ("function" == type(tgt)) then
- local _651_ = (compiler.metadata):get(tgt, "fnl/docstring")
- if (nil ~= _651_) then
- local docstr = _651_
- val_16_auto = (docstr:match(pattern) and path)
+ local _682_ = (compiler.metadata):get(tgt, "fnl/docstring")
+ if (nil ~= _682_) then
+ local docstr = _682_
+ val_18_auto = (docstr:match(pattern) and path)
else
- val_16_auto = nil
+ val_18_auto = nil
end
else
- val_16_auto = nil
+ val_18_auto = nil
end
end
- if (nil ~= val_16_auto) then
- i_15_auto = (i_15_auto + 1)
- do
- end
- tbl_14_auto[i_15_auto] = val_16_auto
+ if (nil ~= val_18_auto) then
+ i_17_auto = (i_17_auto + 1)
+ do end (tbl_16_auto)[i_17_auto] = val_18_auto
else
end
end
- return tbl_14_auto
+ return tbl_16_auto
end
- local function _38_(_env, read, on_values, on_error, _scope)
- local function _655_(_241)
+ commands["apropos-doc"] = function(_env, read, on_values, on_error, _scope)
+ local function _686_(_241)
return on_values(apropos_doc(tostring(_241)))
end
- return run_command(read, on_error, _655_)
- end
- commands["apropos-doc"] = _38_
- do
+ return run_command(read, on_error, _686_)
end
do end (compiler.metadata):set(commands["apropos-doc"], "fnl/docstring", "Print all functions that match the pattern in their docs")
local function apropos_show_docs(on_values, pattern)
@@ 420,122 410,117 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
return nil
end
- local function _40_(_env, read, on_values, on_error)
- local function _657_(_241)
+ commands["apropos-show-docs"] = function(_env, read, on_values, on_error)
+ local function _688_(_241)
return apropos_show_docs(on_values, tostring(_241))
end
- return run_command(read, on_error, _657_)
- end
- commands["apropos-show-docs"] = _40_
- do
+ return run_command(read, on_error, _688_)
end
do end (compiler.metadata):set(commands["apropos-show-docs"], "fnl/docstring", "Print all documentations matching a pattern in function name")
- local function resolve(identifier, _658_, scope)
- local _arg_659_ = _658_
- local ___repl_locals___ = (_arg_659_).___replLocals___
- local env = _arg_659_
- local e = nil
- local function _660_(_241, _242)
- return (___repl_locals___[_242] or env[_242])
- end
- e = setmetatable({}, {__index = _660_})
- local _661_, _662_ = pcall(compiler["compile-string"], tostring(identifier), {scope = scope})
- if ((_661_ == true) and (nil ~= _662_)) then
- local code = _662_
- local _663_ = specials["load-code"](code, e)()
- local function _664_()
- local x = _663_
- return (type(x) == "function")
- end
- if ((nil ~= _663_) and _664_()) then
- local x = _663_
- return x
- else
- return nil
- end
+ local function resolve(identifier, _689_, scope)
+ local _arg_690_ = _689_
+ local ___replLocals___ = _arg_690_["___replLocals___"]
+ local env = _arg_690_
+ local e
+ local function _691_(_241, _242)
+ return (___replLocals___[_242] or env[_242])
+ end
+ e = setmetatable({}, {__index = _691_})
+ local _692_, _693_ = pcall(compiler["compile-string"], tostring(identifier), {scope = scope})
+ if ((_692_ == true) and (nil ~= _693_)) then
+ local code = _693_
+ return specials["load-code"](code, e)()
else
return nil
end
end
- local function _43_(env, read, on_values, on_error, scope)
- local function _667_(_241)
- local _668_ = nil
+ commands.find = function(env, read, on_values, on_error, scope)
+ local function _695_(_241)
+ local _696_
do
- local _669_ = utils["sym?"](_241)
- if (nil ~= _669_) then
- local _670_ = resolve(_669_, env, scope)
- if (nil ~= _670_) then
- _668_ = debug.getinfo(_670_)
+ local _697_ = utils["sym?"](_241)
+ if (nil ~= _697_) then
+ local _698_ = resolve(_697_, env, scope)
+ if (nil ~= _698_) then
+ _696_ = debug.getinfo(_698_)
else
- _668_ = _670_
+ _696_ = _698_
end
else
- _668_ = _669_
+ _696_ = _697_
end
end
- if (((((_G.type(_668_) == "table") and (nil ~= _668_.short_src)) and (_668_.what == "Lua")) and (nil ~= _668_.source)) and (nil ~= _668_.linedefined)) then
- local src = _668_.short_src
- local source = _668_.source
- local line = _668_.linedefined
- local fnlsrc = nil
+ if ((_G.type(_696_) == "table") and ((_696_).what == "Lua") and (nil ~= (_696_).source) and (nil ~= (_696_).linedefined) and (nil ~= (_696_).short_src)) then
+ local source = (_696_).source
+ local line = (_696_).linedefined
+ local src = (_696_).short_src
+ local fnlsrc
do
- local t_673_ = compiler.sourcemap
- if (nil ~= t_673_) then
- t_673_ = (t_673_)[source]
+ local t_701_ = compiler.sourcemap
+ if (nil ~= t_701_) then
+ t_701_ = (t_701_)[source]
else
end
- if (nil ~= t_673_) then
- t_673_ = (t_673_)[line]
+ if (nil ~= t_701_) then
+ t_701_ = (t_701_)[line]
else
end
- if (nil ~= t_673_) then
- t_673_ = (t_673_)[2]
+ if (nil ~= t_701_) then
+ t_701_ = (t_701_)[2]
else
end
- fnlsrc = t_673_
+ fnlsrc = t_701_
end
return on_values({string.format("%s:%s", src, (fnlsrc or line))})
- elseif (_668_ == nil) then
+ elseif (_696_ == nil) then
return on_error("Repl", "Unknown value")
elseif true then
- local _ = _668_
+ local _ = _696_
return on_error("Repl", "No source info")
else
return nil
end
end
- return run_command(read, on_error, _667_)
- end
- commands.find = _43_
- do
+ return run_command(read, on_error, _695_)
end
do end (compiler.metadata):set(commands.find, "fnl/docstring", "Print the filename and line number for a given function")
- local function _50_(env, read, on_values, on_error, scope)
- local function _678_(_241)
+ commands.doc = function(env, read, on_values, on_error, scope)
+ local function _706_(_241)
local name = tostring(_241)
- local is_ok, target = nil, nil
- local function _679_()
- return ((scope.specials[name] or scope.macros[name]) or resolve(name, env, scope))
+ local path = (utils["multi-sym?"](name) or {name})
+ local ok_3f, target = nil, nil
+ local function _707_()
+ return (utils["get-in"](scope.specials, path) or utils["get-in"](scope.macros, path) or resolve(name, env, scope))
end
- is_ok, target = pcall(_679_)
- if is_ok then
+ ok_3f, target = pcall(_707_)
+ if ok_3f then
return on_values({specials.doc(target, name)})
else
return on_error("Repl", "Could not resolve value for docstring lookup")
end
end
- return run_command(read, on_error, _678_)
- end
- commands.doc = _50_
- do
+ return run_command(read, on_error, _706_)
end
do end (compiler.metadata):set(commands.doc, "fnl/docstring", "Print the docstring and arglist for a function, macro, or special form.")
+ commands.compile = function(env, read, on_values, on_error, scope)
+ local function _709_(_241)
+ local allowedGlobals = specials["current-global-names"](env)
+ local ok_3f, result = pcall(compiler.compile, _241, {env = env, scope = scope, allowedGlobals = allowedGlobals})
+ if ok_3f then
+ return on_values({result})
+ else
+ return on_error("Repl", ("Error compiling expression: " .. result))
+ end
+ end
+ return run_command(read, on_error, _709_)
+ end
+ do end (compiler.metadata):set(commands.compile, "fnl/docstring", "compiles the expression into lua and prints the result.")
local function load_plugin_commands(plugins)
for _, plugin in ipairs((plugins or {})) do
for name, f in pairs(plugin) do
- local _681_ = name:match("^repl%-command%-(.*)")
- if (nil ~= _681_) then
- local cmd_name = _681_
+ local _711_ = name:match("^repl%-command%-(.*)")
+ if (nil ~= _711_) then
+ local cmd_name = _711_
commands[cmd_name] = (commands[cmd_name] or f)
else
end
@@ 546,12 531,12 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
local function run_command_loop(input, read, loop, env, on_values, on_error, scope, chars)
local command_name = input:match(",([^%s/]+)")
do
- local _683_ = commands[command_name]
- if (nil ~= _683_) then
- local command = _683_
+ local _713_ = commands[command_name]
+ if (nil ~= _713_) then
+ local command = _713_
command(env, read, on_values, on_error, scope, chars)
elseif true then
- local _ = _683_
+ local _ = _713_
if ("exit" ~= command_name) then
on_values({"Unknown command", command_name})
else
@@ 571,25 556,9 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
readline.set_readline_name("fennel")
else
end
- do
- local rl_opts = nil
- do
- local tbl_11_auto = {histfile = "", keeplines = 1000}
- for k, v in pairs(readline.set_options({})) do
- local _688_, _689_ = k, v
- if ((nil ~= _688_) and (nil ~= _689_)) then
- local k_12_auto = _688_
- local v_13_auto = _689_
- tbl_11_auto[k_12_auto] = v_13_auto
- else
- end
- end
- rl_opts = tbl_11_auto
- end
- readline.set_options(rl_opts)
- end
- local function _58_(parser_state)
- local prompt = nil
+ readline.set_options({keeplines = 1000, histfile = ""})
+ opts.readChunk = function(parser_state)
+ local prompt
if (0 < parser_state["stack-size"]) then
prompt = ".. "
else
@@ 602,13 571,11 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return nil
end
end
- opts.readChunk = _58_
local completer0 = nil
- local function _61_(repl_completer)
+ opts.registerCompleter = function(repl_completer)
completer0 = repl_completer
return nil
end
- opts.registerCompleter = _61_
local function repl_completer(text, from, to)
if completer0 then
readline.set_completion_append_character("")
@@ 624,14 591,25 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
end
local function should_use_readline_3f(opts)
- return ((("dumb" ~= os.getenv("TERM")) and not opts.readChunk) and not opts.registerCompleter)
+ return (("dumb" ~= os.getenv("TERM")) and not opts.readChunk and not opts.registerCompleter)
end
local function repl(_3foptions)
local old_root_options = utils.root.options
- local opts = ((_3foptions and utils.copy(_3foptions)) or {})
+ local _let_722_ = utils.copy(_3foptions)
+ local _3ffennelrc = _let_722_["fennelrc"]
+ local opts = _let_722_
+ local _
+ opts.fennelrc = nil
+ _ = nil
local readline = (should_use_readline_3f(opts) and try_readline_21(opts, pcall(require, "readline")))
- local env = specials["wrap-env"](((opts.env or rawget(_G, "_ENV")) or _G))
- local save_locals_3f = (((opts.saveLocals ~= false) and env.debug) and env.debug.getlocal)
+ local _0
+ if _3ffennelrc then
+ _0 = _3ffennelrc()
+ else
+ _0 = nil
+ end
+ local env = specials["wrap-env"]((opts.env or rawget(_G, "_ENV") or _G))
+ local save_locals_3f = (opts.saveLocals ~= false)
local read_chunk = (opts.readChunk or default_read_chunk)
local on_values = (opts.onValues or default_on_values)
local on_error = (opts.onError or default_on_error)
@@ 639,12 617,12 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
local byte_stream, clear_stream = parser.granulate(read_chunk)
local chars = {}
local read, reset = nil, nil
- local function _695_(parser_state)
+ local function _724_(parser_state)
local c = byte_stream(parser_state)
table.insert(chars, c)
return c
end
- read, reset = parser.parser(_695_)
+ read, reset = parser.parser(_724_)
opts.env, opts.scope = env, compiler["make-scope"]()
opts.useMetadata = (opts.useMetadata ~= false)
if (opts.allowedGlobals == nil) then
@@ 652,15 630,15 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
else
end
if opts.registerCompleter then
- local function _699_()
- local _697_ = env
- local _698_ = opts.scope
- local function _700_(...)
- return completer(_697_, _698_, ...)
+ local function _728_()
+ local _726_ = env
+ local _727_ = opts.scope
+ local function _729_(...)
+ return completer(_726_, _727_, ...)
end
- return _700_
+ return _729_
end
- opts.registerCompleter(_699_())
+ opts.registerCompleter(_728_())
else
end
load_plugin_commands(opts.plugins)
@@ 689,8 667,10 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
chars[k] = nil
end
reset()
- local ok, not_eof_3f, x = pcall(read)
+ local ok, parser_not_eof_3f, x = pcall(read)
local src_string = string.char(unpack(chars))
+ local readline_not_eof_3f = (not readline or (src_string ~= "(null)"))
+ local not_eof_3f = (readline_not_eof_3f and parser_not_eof_3f)
if not ok then
on_error("Parse", not_eof_3f)
clear_stream()
@@ 700,43 680,43 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
else
if not_eof_3f then
do
- local _704_, _705_ = nil, nil
- local function _707_()
- local _706_ = opts
- _706_["source"] = src_string
- return _706_
+ local _733_, _734_ = nil, nil
+ local function _736_()
+ local _735_ = opts
+ _735_["source"] = src_string
+ return _735_
end
- _704_, _705_ = pcall(compiler.compile, x, _707_())
- if ((_704_ == false) and (nil ~= _705_)) then
- local msg = _705_
+ _733_, _734_ = pcall(compiler.compile, x, _736_())
+ if ((_733_ == false) and (nil ~= _734_)) then
+ local msg = _734_
clear_stream()
on_error("Compile", msg)
- elseif ((_704_ == true) and (nil ~= _705_)) then
- local src = _705_
- local src0 = nil
+ elseif ((_733_ == true) and (nil ~= _734_)) then
+ local src = _734_
+ local src0
if save_locals_3f then
src0 = splice_save_locals(env, src, opts.scope)
else
src0 = src
end
- local _709_, _710_ = pcall(specials["load-code"], src0, env)
- if ((_709_ == false) and (nil ~= _710_)) then
- local msg = _710_
+ local _738_, _739_ = pcall(specials["load-code"], src0, env)
+ if ((_738_ == false) and (nil ~= _739_)) then
+ local msg = _739_
clear_stream()
on_error("Lua Compile", msg, src0)
- elseif (true and (nil ~= _710_)) then
- local _ = _709_
- local chunk = _710_
- local function _711_()
+ elseif (true and (nil ~= _739_)) then
+ local _1 = _738_
+ local chunk = _739_
+ local function _740_()
return print_values(chunk())
end
- local function _712_()
- local function _713_(...)
+ local function _741_()
+ local function _742_(...)
return on_error("Runtime", ...)
end
- return _713_
+ return _742_
end
- xpcall(_711_, _712_())
+ xpcall(_740_, _741_())
else
end
else
@@ 758,8 738,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
return repl
end
- package.preload["fennel.repl"] = (package.preload["fennel.repl"] or _1_)
- local function _74_(...)
+ package.preload["fennel.specials"] = package.preload["fennel.specials"] or function(...)
local utils = require("fennel.utils")
local view = require("fennel.view")
local parser = require("fennel.parser")
@@ 767,14 746,14 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
local unpack = (table.unpack or _G.unpack)
local SPECIALS = compiler.scopes.global.specials
local function wrap_env(env)
- local function _403_(_, key)
+ local function _424_(_, key)
if utils["string?"](key) then
return env[compiler["global-unmangling"](key)]
else
return env[key]
end
end
- local function _405_(_, key, value)
+ local function _426_(_, key, value)
if utils["string?"](key) then
env[compiler["global-unmangling"](key)] = value
return nil
@@ 783,38 762,36 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return nil
end
end
- local function _407_()
+ local function _428_()
local function putenv(k, v)
- local _408_ = nil
+ local _429_
if utils["string?"](k) then
- _408_ = compiler["global-unmangling"](k)
+ _429_ = compiler["global-unmangling"](k)
else
- _408_ = k
+ _429_ = k
end
- return _408_, v
+ return _429_, v
end
return next, utils.kvmap(env, putenv), nil
end
- return setmetatable({}, {__newindex = _405_, __pairs = _407_, __index = _403_})
+ return setmetatable({}, {__index = _424_, __newindex = _426_, __pairs = _428_})
end
local function current_global_names(_3fenv)
- local mt = nil
+ local mt
do
- local _410_ = getmetatable(_3fenv)
- if ((_G.type(_410_) == "table") and (nil ~= _410_.__pairs)) then
- local mtpairs = _410_.__pairs
- local tbl_11_auto = {}
+ local _431_ = getmetatable(_3fenv)
+ if ((_G.type(_431_) == "table") and (nil ~= (_431_).__pairs)) then
+ local mtpairs = (_431_).__pairs
+ local tbl_13_auto = {}
for k, v in mtpairs(_3fenv) do
- local _411_, _412_ = k, v
- if ((nil ~= _411_) and (nil ~= _412_)) then
- local k_12_auto = _411_
- local v_13_auto = _412_
- tbl_11_auto[k_12_auto] = v_13_auto
+ local k_14_auto, v_15_auto = k, v
+ if ((k_14_auto ~= nil) and (v_15_auto ~= nil)) then
+ tbl_13_auto[k_14_auto] = v_15_auto
else
end
end
- mt = tbl_11_auto
- elseif (_410_ == nil) then
+ mt = tbl_13_auto
+ elseif (_431_ == nil) then
mt = (_3fenv or _G)
else
mt = nil
@@ 823,17 800,17 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return (mt and utils.kvmap(mt, compiler["global-unmangling"]))
end
local function load_code(code, _3fenv, _3ffilename)
- local env = ((_3fenv or rawget(_G, "_ENV")) or _G)
- local _415_, _416_ = rawget(_G, "setfenv"), rawget(_G, "loadstring")
- if ((nil ~= _415_) and (nil ~= _416_)) then
- local setfenv = _415_
- local loadstring = _416_
+ local env = (_3fenv or rawget(_G, "_ENV") or _G)
+ local _434_, _435_ = rawget(_G, "setfenv"), rawget(_G, "loadstring")
+ if ((nil ~= _434_) and (nil ~= _435_)) then
+ local setfenv = _434_
+ local loadstring = _435_
local f = assert(loadstring(code, _3ffilename))
- local _417_ = f
- setfenv(_417_, env)
- return _417_
+ local _436_ = f
+ setfenv(_436_, env)
+ return _436_
elseif true then
- local _ = _415_
+ local _ = _434_
return assert(load(code, _3ffilename, "t", env))
else
return nil
@@ 847,20 824,20 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
local mt = getmetatable(tgt)
if ((type(tgt) == "function") or ((type(mt) == "table") and (type(mt.__call) == "function"))) then
local arglist = table.concat(((compiler.metadata):get(tgt, "fnl/arglist") or {"#<unknown-arguments>"}), " ")
- local _419_ = nil
+ local _438_
if (0 < #arglist) then
- _419_ = " "
+ _438_ = " "
else
- _419_ = ""
+ _438_ = ""
end
- return string.format("(%s%s%s)\n %s", name, _419_, arglist, docstring)
+ return string.format("(%s%s%s)\n %s", name, _438_, arglist, docstring)
else
return string.format("%s\n %s", name, docstring)
end
end
end
local function doc_special(name, arglist, docstring, body_form_3f)
- compiler.metadata[SPECIALS[name]] = {["fnl/body-form?"] = body_form_3f, ["fnl/arglist"] = arglist, ["fnl/docstring"] = docstring}
+ compiler.metadata[SPECIALS[name]] = {["fnl/arglist"] = arglist, ["fnl/docstring"] = docstring, ["fnl/body-form?"] = body_form_3f}
return nil
end
local function compile_do(ast, scope, parent, _3fstart)
@@ 872,7 849,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
return nil
end
- local function _84_(ast, scope, parent, opts, _3fstart, _3fchunk, _3fsub_scope, _3fpre_syms)
+ SPECIALS["do"] = function(ast, scope, parent, opts, _3fstart, _3fchunk, _3fsub_scope, _3fpre_syms)
local start = (_3fstart or 2)
local sub_scope = (_3fsub_scope or compiler["make-scope"](scope))
local chunk = (_3fchunk or {})
@@ 883,7 860,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
compiler.compile1(nil, sub_scope, chunk, {tail = outer_tail, target = outer_target})
else
for i = start, len do
- local subopts = {nval = (((i ~= len) and 0) or opts.nval), target = (((i == len) and outer_target) or nil), tail = (((i == len) and outer_tail) or nil)}
+ local subopts = {nval = (((i ~= len) and 0) or opts.nval), tail = (((i == len) and outer_tail) or nil), target = (((i == len) and outer_target) or nil)}
local _ = utils["propagate-options"](opts, subopts)
local subexprs = compiler.compile1(ast[i], sub_scope, chunk, subopts)
if (i ~= len) then
@@ 897,16 874,14 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
utils.hook("do", ast, sub_scope)
return (outer_retexprs or retexprs)
end
- if ((opts.target or (opts.nval == 0)) or opts.tail) then
+ if (opts.target or (opts.nval == 0) or opts.tail) then
compiler.emit(parent, "do", ast)
return compile_body(opts.target, opts.tail)
elseif opts.nval then
local syms = {}
for i = 1, opts.nval do
local s = ((_3fpre_syms and (_3fpre_syms)[i]) or compiler.gensym(scope))
- do
- end
- syms[i] = s
+ do end (syms)[i] = s
retexprs[i] = utils.expr(s, "sym")
end
local outer_target = table.concat(syms, ", ")
@@ 915,7 890,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return compile_body(outer_target, opts.tail)
else
local fname = compiler.gensym(scope)
- local fargs = nil
+ local fargs
if scope.vararg then
fargs = "..."
else
@@ 925,9 900,8 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return compile_body(nil, true, utils.expr((fname .. "(" .. fargs .. ")"), "statement"))
end
end
- SPECIALS["do"] = _84_
doc_special("do", {"..."}, "Evaluate multiple forms; return last value.", true)
- local function _89_(ast, scope, parent)
+ SPECIALS.values = function(ast, scope, parent)
local len = #ast
local exprs = {}
for i = 2, len do
@@ 942,83 916,78 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
return exprs
end
- SPECIALS.values = _89_
doc_special("values", {"..."}, "Return multiple values from a function. Must be in tail position.")
- local function deep_tostring(x, key_3f)
- if utils["list?"](x) then
- local _428_ = nil
- do
- local tbl_14_auto = {}
- local i_15_auto = #tbl_14_auto
- for _, v in ipairs(x) do
- local val_16_auto = deep_tostring(v)
- if (nil ~= val_16_auto) then
- i_15_auto = (i_15_auto + 1)
- do
- end
- tbl_14_auto[i_15_auto] = val_16_auto
- else
- end
- end
- _428_ = tbl_14_auto
- end
- return ("(" .. table.concat(_428_, " ") .. ")")
- elseif utils["sequence?"](x) then
- local _430_ = nil
- do
- local tbl_14_auto = {}
- local i_15_auto = #tbl_14_auto
- for _, v in ipairs(x) do
- local val_16_auto = deep_tostring(v)
- if (nil ~= val_16_auto) then
- i_15_auto = (i_15_auto + 1)
- do
- end
- tbl_14_auto[i_15_auto] = val_16_auto
- else
- end
- end
- _430_ = tbl_14_auto
- end
- return ("[" .. table.concat(_430_, " ") .. "]")
- elseif utils["table?"](x) then
- local _432_ = nil
- do
- local tbl_14_auto = {}
- local i_15_auto = #tbl_14_auto
- for k, v in pairs(x) do
- local val_16_auto = (deep_tostring(k, true) .. " " .. deep_tostring(v))
- if (nil ~= val_16_auto) then
- i_15_auto = (i_15_auto + 1)
- do
- end
- tbl_14_auto[i_15_auto] = val_16_auto
- else
- end
+ local function __3estack(stack, tbl)
+ for k, v in pairs(tbl) do
+ local _447_ = stack
+ table.insert(_447_, k)
+ table.insert(_447_, v)
+ end
+ return stack
+ end
+ local function literal_3f(val)
+ local res = true
+ if utils["list?"](val) then
+ res = false
+ elseif utils["table?"](val) then
+ local stack = __3estack({}, val)
+ for _, elt in ipairs(stack) do
+ if not res then break end
+ if utils["list?"](elt) then
+ res = false
+ elseif utils["table?"](elt) then
+ __3estack(stack, elt)
+ else
end
- _432_ = tbl_14_auto
end
- return ("{" .. table.concat(_432_, " ") .. "}")
- elseif ((key_3f and utils["string?"](x)) and x:find("^[-%w?\\^_!$%&*+./@:|<=>]+$")) then
- return (":" .. x)
- elseif utils["string?"](x) then
- return string.format("%q", x):gsub("\\\"", "\\\\\""):gsub("\"", "\\\"")
else
- return tostring(x)
end
+ return res
end
- local function set_fn_metadata(arg_list, docstring, parent, fn_name)
+ local function compile_value(v)
+ local opts = {nval = 1, tail = false}
+ local scope = compiler["make-scope"]()
+ local chunk = {}
+ local _let_450_ = compiler.compile1(v, scope, chunk, opts)
+ local _let_451_ = _let_450_[1]
+ local v0 = _let_451_[1]
+ return v0
+ end
+ local function insert_meta(meta, k, v)
+ local view_opts = {["escape-newlines?"] = true, ["line-length"] = math.huge, ["one-line?"] = true}
+ compiler.assert((type(k) == "string"), ("expected string keys in metadata table, got: %s"):format(view(k, view_opts)))
+ compiler.assert(literal_3f(v), ("expected literal value in metadata table, got: %s %s"):format(view(k, view_opts), view(v, view_opts)))
+ local _452_ = meta
+ table.insert(_452_, view(k))
+ local function _453_()
+ if ("string" == type(v)) then
+ return view(v, view_opts)
+ else
+ return compile_value(v)
+ end
+ end
+ table.insert(_452_, _453_())
+ return _452_
+ end
+ local function insert_arglist(meta, arg_list)
+ local view_opts = {["one-line?"] = true, ["escape-newlines?"] = true, ["line-length"] = math.huge}
+ local _454_ = meta
+ table.insert(_454_, "\"fnl/arglist\"")
+ local function _455_(_241)
+ return view(view(_241, view_opts))
+ end
+ table.insert(_454_, ("{" .. table.concat(utils.map(arg_list, _455_), ", ") .. "}"))
+ return _454_
+ end
+ local function set_fn_metadata(f_metadata, parent, fn_name)
if utils.root.options.useMetadata then
- local args = nil
- local function _435_(_241)
- return ("\"%s\""):format(deep_tostring(_241))
- end
- args = utils.map(arg_list, _435_)
- local meta_fields = {"\"fnl/arglist\"", ("{" .. table.concat(args, ", ") .. "}")}
- if docstring then
- table.insert(meta_fields, "\"fnl/docstring\"")
- table.insert(meta_fields, ("\"" .. docstring:gsub("%s+$", ""):gsub("\\", "\\\\"):gsub("\n", "\\n"):gsub("\"", "\\\"") .. "\""))
- else
+ local meta_fields = {}
+ for k, v in utils.stablepairs(f_metadata) do
+ if (k == "fnl/arglist") then
+ insert_arglist(meta_fields, v)
+ else
+ insert_meta(meta_fields, k, v)
+ end
end
local meta_str = ("require(\"%s\").metadata"):format((utils.root.options.moduleName or "fennel"))
return compiler.emit(parent, ("pcall(function() %s:setall(%s, %s) end)"):format(meta_str, fn_name, table.concat(meta_fields, ", ")))
@@ 1028,13 997,13 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
local function get_fn_name(ast, scope, fn_name, multi)
if (fn_name and (fn_name[1] ~= "nil")) then
- local _438_ = nil
+ local _458_
if not multi then
- _438_ = compiler["declare-local"](fn_name, {}, scope, ast)
+ _458_ = compiler["declare-local"](fn_name, {}, scope, ast)
else
- _438_ = (compiler["symbol-to-expression"](fn_name, scope))[1]
+ _458_ = (compiler["symbol-to-expression"](fn_name, scope))[1]
end
- return _438_, not multi, 3
+ return _458_, not multi, 3
else
return nil, true, 2
end
@@ 1043,16 1012,16 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
for i = (index + 1), #ast do
compiler.compile1(ast[i], f_scope, f_chunk, {nval = (((i ~= #ast) and 0) or nil), tail = (i == #ast)})
end
- local _441_ = nil
+ local _461_
if local_3f then
- _441_ = "local function %s(%s)"
+ _461_ = "local function %s(%s)"
else
- _441_ = "%s = function(%s)"
+ _461_ = "%s = function(%s)"
end
- compiler.emit(parent, string.format(_441_, fn_name, table.concat(arg_name_list, ", ")), ast)
+ compiler.emit(parent, string.format(_461_, fn_name, table.concat(arg_name_list, ", ")), ast)
compiler.emit(parent, f_chunk, ast)
compiler.emit(parent, "end", ast)
- set_fn_metadata(f_metadata["fnl/arglist"], f_metadata["fnl/docstring"], parent, fn_name)
+ set_fn_metadata(f_metadata, parent, fn_name)
utils.hook("fn", ast, f_scope)
return utils.expr(fn_name, "sym")
end
@@ 1060,46 1029,54 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
local fn_name = compiler.gensym(scope)
return compile_named_fn(ast, f_scope, f_chunk, parent, index, fn_name, true, arg_name_list, f_metadata)
end
+ local function assoc_table_3f(t)
+ local len = #t
+ local nxt, t0, k = pairs(t)
+ local function _463_()
+ if (len == 0) then
+ return k
+ else
+ return len
+ end
+ end
+ return (nil ~= nxt(t0, _463_()))
+ end
local function get_function_metadata(ast, arg_list, index)
local f_metadata = {["fnl/arglist"] = arg_list}
local index_2a = (index + 1)
local expr = ast[index_2a]
if (utils["string?"](expr) and (index_2a < #ast)) then
- local _444_ = nil
+ local _465_
do
- local _443_ = f_metadata
- _443_["fnl/docstring"] = expr
- _444_ = _443_
+ local _464_ = f_metadata
+ _464_["fnl/docstring"] = expr
+ _465_ = _464_
end
- return _444_, index_2a
- elseif (utils["table?"](expr) and (index_2a < #ast)) then
- local _445_ = nil
+ return _465_, index_2a
+ elseif (utils["table?"](expr) and (index_2a < #ast) and assoc_table_3f(expr)) then
+ local _466_
do
- local tbl_11_auto = f_metadata
+ local tbl_13_auto = f_metadata
for k, v in pairs(expr) do
- local _446_, _447_ = k, v
- if ((nil ~= _446_) and (nil ~= _447_)) then
- local k_12_auto = _446_
- local v_13_auto = _447_
- tbl_11_auto[k_12_auto] = v_13_auto
+ local k_14_auto, v_15_auto = k, v
+ if ((k_14_auto ~= nil) and (v_15_auto ~= nil)) then
+ tbl_13_auto[k_14_auto] = v_15_auto
else
end
end
- _445_ = tbl_11_auto
+ _466_ = tbl_13_auto
end
- return _445_, index_2a
+ return _466_, index_2a
else
return f_metadata, index
end
end
- local function _102_(ast, scope, parent)
- local f_scope = nil
+ SPECIALS.fn = function(ast, scope, parent)
+ local f_scope
do
- local _450_ = compiler["make-scope"](scope)
- do
- end
- _450_["vararg"] = false
- f_scope = _450_
+ local _469_ = compiler["make-scope"](scope)
+ do end (_469_)["vararg"] = false
+ f_scope = _469_
end
local f_chunk = {}
local fn_sym = utils["sym?"](ast[2])
@@ 1107,23 1084,49 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
local fn_name, local_3f, index = get_fn_name(ast, scope, fn_sym, multi)
local arg_list = compiler.assert(utils["table?"](ast[index]), "expected parameters table", ast)
compiler.assert((not multi or not multi["multi-sym-method-call"]), ("unexpected multi symbol " .. tostring(fn_name)), fn_sym)
- local function get_arg_name(arg)
- if utils["varg?"](arg) then
+ local function destructure_arg(arg)
+ local raw = utils.sym(compiler.gensym(scope))
+ local declared = compiler["declare-local"](raw, {}, f_scope, ast)
+ compiler.destructure(arg, raw, ast, f_scope, f_chunk, {declaration = true, nomulti = true, symtype = "arg"})
+ return declared
+ end
+ local function destructure_amp(i)
+ compiler.assert((i == (#arg_list - 1)), "expected rest argument before last parameter", arg_list[(i + 1)], arg_list)
+ f_scope.vararg = true
+ compiler.destructure(arg_list[#arg_list], {utils.varg()}, ast, f_scope, f_chunk, {declaration = true, nomulti = true, symtype = "arg"})
+ return "..."
+ end
+ local function get_arg_name(arg, i)
+ if f_scope.vararg then
+ return nil
+ elseif utils["varg?"](arg) then
compiler.assert((arg == arg_list[#arg_list]), "expected vararg as last parameter", ast)
f_scope.vararg = true
return "..."
- elseif ((utils["sym?"](arg) and (tostring(arg) ~= "nil")) and not utils["multi-sym?"](tostring(arg))) then
+ elseif (utils.sym("&") == arg) then
+ return destructure_amp(i)
+ elseif (utils["sym?"](arg) and (tostring(arg) ~= "nil") and not utils["multi-sym?"](tostring(arg))) then
return compiler["declare-local"](arg, {}, f_scope, ast)
elseif utils["table?"](arg) then
- local raw = utils.sym(compiler.gensym(scope))
- local declared = compiler["declare-local"](raw, {}, f_scope, ast)
- compiler.destructure(arg, raw, ast, f_scope, f_chunk, {nomulti = true, declaration = true, symtype = "arg"})
- return declared
+ return destructure_arg(arg)
else
return compiler.assert(false, ("expected symbol for function parameter: %s"):format(tostring(arg)), ast[index])
end
end
- local arg_name_list = utils.map(arg_list, get_arg_name)
+ local arg_name_list
+ do
+ local tbl_16_auto = {}
+ local i_17_auto = #tbl_16_auto
+ for i, a in ipairs(arg_list) do
+ local val_18_auto = get_arg_name(a, i)
+ if (nil ~= val_18_auto) then
+ i_17_auto = (i_17_auto + 1)
+ do end (tbl_16_auto)[i_17_auto] = val_18_auto
+ else
+ end
+ end
+ arg_name_list = tbl_16_auto
+ end
local f_metadata, index0 = get_function_metadata(ast, arg_list, index)
if fn_name then
return compile_named_fn(ast, f_scope, f_chunk, parent, index0, fn_name, local_3f, arg_name_list, f_metadata)
@@ 1131,44 1134,42 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return compile_anonymous_fn(ast, f_scope, f_chunk, parent, index0, arg_name_list, f_metadata, scope)
end
end
- SPECIALS.fn = _102_
doc_special("fn", {"name?", "args", "docstring?", "..."}, "Function syntax. May optionally include a name and docstring or a metadata table.\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)
- local function _105_(ast, _, parent)
+ SPECIALS.lua = function(ast, _, parent)
compiler.assert(((#ast == 2) or (#ast == 3)), "expected 1 or 2 arguments", ast)
- local _454_ = nil
+ local _474_
do
- local _453_ = utils["sym?"](ast[2])
- if (nil ~= _453_) then
- _454_ = tostring(_453_)
+ local _473_ = utils["sym?"](ast[2])
+ if (nil ~= _473_) then
+ _474_ = tostring(_473_)
else
- _454_ = _453_
+ _474_ = _473_
end
end
- if ("nil" ~= _454_) then
+ if ("nil" ~= _474_) then
table.insert(parent, {ast = ast, leaf = tostring(ast[2])})
else
end
- local _458_ = nil
+ local _478_
do
- local _457_ = utils["sym?"](ast[3])
- if (nil ~= _457_) then
- _458_ = tostring(_457_)
+ local _477_ = utils["sym?"](ast[3])
+ if (nil ~= _477_) then
+ _478_ = tostring(_477_)
else
- _458_ = _457_
+ _478_ = _477_
end
end
- if ("nil" ~= _458_) then
+ if ("nil" ~= _478_) then
return tostring(ast[3])
else
return nil
end
end
- SPECIALS.lua = _105_
local function dot(ast, scope, parent)
compiler.assert((1 < #ast), "expected table argument", ast)
local len = #ast
- local _let_461_ = compiler.compile1(ast[2], scope, parent, {nval = 1})
- local lhs = (_let_461_)[1]
+ local _let_481_ = compiler.compile1(ast[2], scope, parent, {nval = 1})
+ local lhs = _let_481_[1]
if (len == 2) then
return tostring(lhs)
else
@@ 1178,8 1179,8 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
if (utils["string?"](index) and utils["valid-lua-identifier?"](index)) then
table.insert(indices, ("." .. index))
else
- local _let_462_ = compiler.compile1(index, scope, parent, {nval = 1})
- local index0 = (_let_462_)[1]
+ local _let_482_ = compiler.compile1(index, scope, parent, {nval = 1})
+ local index0 = _let_482_[1]
table.insert(indices, ("[" .. tostring(index0) .. "]"))
end
end
@@ 1192,65 1193,60 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
SPECIALS["."] = dot
doc_special(".", {"tbl", "key1", "..."}, "Look up key1 in tbl table. If more args are provided, do a nested lookup.")
- local function _113_(ast, scope, parent)
+ SPECIALS.global = function(ast, scope, parent)
compiler.assert((#ast == 3), "expected name and value", ast)
- compiler.destructure(ast[2], ast[3], ast, scope, parent, {nomulti = true, symtype = "global", forceglobal = true})
+ compiler.destructure(ast[2], ast[3], ast, scope, parent, {forceglobal = true, nomulti = true, symtype = "global"})
return nil
end
- SPECIALS.global = _113_
doc_special("global", {"name", "val"}, "Set name as a global with val.")
- local function _114_(ast, scope, parent)
+ SPECIALS.set = function(ast, scope, parent)
compiler.assert((#ast == 3), "expected name and value", ast)
compiler.destructure(ast[2], ast[3], ast, scope, parent, {noundef = true, symtype = "set"})
return nil
end
- SPECIALS.set = _114_
doc_special("set", {"name", "val"}, "Set a local variable to a new value. Only works on locals using var.")
local function set_forcibly_21_2a(ast, scope, parent)
compiler.assert((#ast == 3), "expected name and value", ast)
- compiler.destructure(ast[2], ast[3], ast, scope, parent, {symtype = "set", forceset = true})
+ compiler.destructure(ast[2], ast[3], ast, scope, parent, {forceset = true, symtype = "set"})
return nil
end
SPECIALS["set-forcibly!"] = set_forcibly_21_2a
local function local_2a(ast, scope, parent)
compiler.assert((#ast == 3), "expected name and value", ast)
- compiler.destructure(ast[2], ast[3], ast, scope, parent, {nomulti = true, declaration = true, symtype = "local"})
+ compiler.destructure(ast[2], ast[3], ast, scope, parent, {declaration = true, nomulti = true, symtype = "local"})
return nil
end
SPECIALS["local"] = local_2a
doc_special("local", {"name", "val"}, "Introduce new top-level immutable local.")
- local function _115_(ast, scope, parent)
+ SPECIALS.var = function(ast, scope, parent)
compiler.assert((#ast == 3), "expected name and value", ast)
- compiler.destructure(ast[2], ast[3], ast, scope, parent, {symtype = "var", nomulti = true, declaration = true, isvar = true})
+ compiler.destructure(ast[2], ast[3], ast, scope, parent, {declaration = true, isvar = true, nomulti = true, symtype = "var"})
return nil
end
- SPECIALS.var = _115_
doc_special("var", {"name", "val"}, "Introduce new mutable local.")
local function kv_3f(t)
- local _466_ = nil
+ local _486_
do
- local tbl_14_auto = {}
- local i_15_auto = #tbl_14_auto
+ local tbl_16_auto = {}
+ local i_17_auto = #tbl_16_auto
for k in pairs(t) do
- local val_16_auto = nil
+ local val_18_auto
if ("number" ~= type(k)) then
- val_16_auto = k
+ val_18_auto = k
else
- val_16_auto = nil
+ val_18_auto = nil
end
- if (nil ~= val_16_auto) then
- i_15_auto = (i_15_auto + 1)
- do
- end
- tbl_14_auto[i_15_auto] = val_16_auto
+ if (nil ~= val_18_auto) then
+ i_17_auto = (i_17_auto + 1)
+ do end (tbl_16_auto)[i_17_auto] = val_18_auto
else
end
end
- _466_ = tbl_14_auto
+ _486_ = tbl_16_auto
end
- return (_466_)[1]
+ return (_486_)[1]
end
- local function _118_(ast, scope, parent, opts)
+ SPECIALS.let = function(ast, scope, parent, opts)
local bindings = ast[2]
local pre_syms = {}
compiler.assert((utils["table?"](bindings) and not kv_3f(bindings)), "expected binding sequence", bindings)
@@ 1262,11 1258,10 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
local sub_scope = compiler["make-scope"](scope)
local sub_chunk = {}
for i = 1, #bindings, 2 do
- compiler.destructure(bindings[i], bindings[(i + 1)], ast, sub_scope, sub_chunk, {nomulti = true, declaration = true, symtype = "let"})
+ compiler.destructure(bindings[i], bindings[(i + 1)], ast, sub_scope, sub_chunk, {declaration = true, nomulti = true, symtype = "let"})
end
return SPECIALS["do"](ast, scope, parent, opts, 3, sub_chunk, sub_scope, pre_syms)
end
- SPECIALS.let = _118_
doc_special("let", {"[name1 val1 ... nameN valN]", "..."}, "Introduces a new scope in which a given set of local bindings are used.", true)
local function get_prev_line(parent)
if ("table" == type(parent)) then
@@ 1276,29 1271,29 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
end
local function disambiguate_3f(rootstr, parent)
- local function _471_()
- local _470_ = get_prev_line(parent)
- if (nil ~= _470_) then
- local prev_line = _470_
+ local function _491_()
+ local _490_ = get_prev_line(parent)
+ if (nil ~= _490_) then
+ local prev_line = _490_
return prev_line:match("%)$")
else
return nil
end
end
- return (rootstr:match("^{") or _471_())
+ return (rootstr:match("^{") or _491_())
end
- local function _121_(ast, scope, parent)
+ SPECIALS.tset = function(ast, scope, parent)
compiler.assert((3 < #ast), "expected table, key, and value arguments", ast)
local root = (compiler.compile1(ast[2], scope, parent, {nval = 1}))[1]
local keys = {}
for i = 3, (#ast - 1) do
- local _let_473_ = compiler.compile1(ast[i], scope, parent, {nval = 1})
- local key = (_let_473_)[1]
+ local _let_493_ = compiler.compile1(ast[i], scope, parent, {nval = 1})
+ local key = _let_493_[1]
table.insert(keys, tostring(key))
end
local value = (compiler.compile1(ast[#ast], scope, parent, {nval = 1}))[1]
local rootstr = tostring(root)
- local fmtstr = nil
+ local fmtstr
if disambiguate_3f(rootstr, parent) then
fmtstr = "do end (%s)[%s] = %s"
else
@@ 1306,19 1301,16 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
return compiler.emit(parent, fmtstr:format(rootstr, table.concat(keys, "]["), tostring(value)), ast)
end
- SPECIALS.tset = _121_
doc_special("tset", {"tbl", "key1", "...", "keyN", "val"}, "Set the value of a table field. Can take additional keys to set\nnested values, but all parents must contain an existing table.")
local function calculate_target(scope, opts)
- if not ((opts.tail or opts.target) or opts.nval) then
+ if not (opts.tail or opts.target or opts.nval) then
return "iife", true, nil
- elseif ((opts.nval and (opts.nval ~= 0)) and not opts.target) then
+ elseif (opts.nval and (opts.nval ~= 0) and not opts.target) then
local accum = {}
local target_exprs = {}
for i = 1, opts.nval do
local s = compiler.gensym(scope)
- do
- end
- accum[i] = s
+ do end (accum)[i] = s
target_exprs[i] = utils.expr(s, "sym")
end
return "target", opts.tail, table.concat(accum, ", "), target_exprs
@@ 1331,7 1323,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
local do_scope = compiler["make-scope"](scope)
local branches = {}
local wrapper, inner_tail, inner_target, target_exprs = calculate_target(scope, opts)
- local body_opts = {nval = opts.nval, target = inner_target, tail = inner_tail}
+ local body_opts = {nval = opts.nval, tail = inner_tail, target = inner_target}
local function compile_body(i)
local chunk = {}
local cscope = compiler["make-scope"](do_scope)
@@ 1358,7 1350,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
local last_buffer = buffer
for i = 1, #branches do
local branch = branches[i]
- local fstr = nil
+ local fstr
if not branch.nested then
fstr = "if %s then"
else
@@ 1420,14 1412,14 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
local function compile_until(condition, scope, chunk)
if condition then
- local _let_482_ = compiler.compile1(condition, scope, chunk, {nval = 1})
- local condition_lua = (_let_482_)[1]
+ local _let_502_ = compiler.compile1(condition, scope, chunk, {nval = 1})
+ local condition_lua = _let_502_[1]
return compiler.emit(chunk, ("if %s then break end"):format(tostring(condition_lua)), utils.expr(condition, "expression"))
else
return nil
end
end
- local function _131_(ast, scope, parent)
+ SPECIALS.each = function(ast, scope, parent)
compiler.assert((3 <= #ast), "expected body expression", ast[1])
local binding = compiler.assert(utils["table?"](ast[2]), "expected binding table", ast)
local _ = compiler.assert((2 <= #binding), "expected binding and iterator", binding)
@@ 1442,9 1434,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return compiler["declare-local"](v, {}, sub_scope, ast, new_manglings)
else
local raw = utils.sym(compiler.gensym(sub_scope))
- do
- end
- destructures[raw] = v
+ do end (destructures)[raw] = v
return compiler["declare-local"](raw, {}, sub_scope, ast)
end
end
@@ 1454,7 1444,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
local chunk = {}
compiler.emit(parent, ("for %s in %s do"):format(table.concat(bind_vars, ", "), table.concat(val_names, ", ")), ast)
for raw, args in utils.stablepairs(destructures) do
- compiler.destructure(args, raw, ast, sub_scope, chunk, {nomulti = true, declaration = true, symtype = "each"})
+ compiler.destructure(args, raw, ast, sub_scope, chunk, {declaration = true, nomulti = true, symtype = "each"})
end
compiler["apply-manglings"](sub_scope, new_manglings, ast)
compile_until(until_condition, sub_scope, chunk)
@@ 1462,7 1452,6 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
compiler.emit(parent, chunk, ast)
return compiler.emit(parent, "end", ast)
end
- SPECIALS.each = _131_
doc_special("each", {"[key value (iterator)]", "..."}, "Runs the body once for each set of values provided by the given iterator.\nMost commonly used with ipairs for sequential tables or pairs for undefined\norder, but can be used with any iterator.", true)
local function while_2a(ast, scope, parent)
local len1 = #parent
@@ 1472,9 1461,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
if (len1 ~= len2) then
for i = (len1 + 1), len2 do
table.insert(sub_chunk, parent[i])
- do
- end
- parent[i] = nil
+ do end (parent)[i] = nil
end
compiler.emit(parent, "while true do", ast)
compiler.emit(sub_chunk, ("if not %s then break end"):format(condition[1]), ast)
@@ 1509,12 1496,12 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
SPECIALS["for"] = for_2a
doc_special("for", {"[index start stop step?]", "..."}, "Numeric loop construct.\nEvaluates body once for each value between start and stop (inclusive).", true)
local function native_method_call(ast, _scope, _parent, target, args)
- local _let_486_ = ast
- local _ = (_let_486_)[1]
- local _0 = (_let_486_)[2]
- local method_string = (_let_486_)[3]
- local call_string = nil
- if (((target.type == "literal") or (target.type == "varg")) or (target.type == "expression")) then
+ local _let_506_ = ast
+ local _ = _let_506_[1]
+ local _0 = _let_506_[2]
+ local method_string = _let_506_[3]
+ local call_string
+ if ((target.type == "literal") or (target.type == "varg") or (target.type == "expression")) then
call_string = "(%s):%s(%s)"
else
call_string = "%s:%s(%s)"
@@ 1534,18 1521,18 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
local function method_call(ast, scope, parent)
compiler.assert((2 < #ast), "expected at least 2 arguments", ast)
- local _let_488_ = compiler.compile1(ast[2], scope, parent, {nval = 1})
- local target = (_let_488_)[1]
+ local _let_508_ = compiler.compile1(ast[2], scope, parent, {nval = 1})
+ local target = _let_508_[1]
local args = {}
for i = 4, #ast do
- local subexprs = nil
- local _489_ = nil
+ local subexprs
+ local _509_
if (i ~= #ast) then
- _489_ = 1
+ _509_ = 1
else
- _489_ = nil
+ _509_ = nil
end
- subexprs = compiler.compile1(ast[i], scope, parent, {nval = _489_})
+ subexprs = compiler.compile1(ast[i], scope, parent, {nval = _509_})
utils.map(subexprs, tostring, args)
end
if (utils["string?"](ast[3]) and utils["valid-lua-identifier?"](ast[3])) then
@@ 1558,18 1545,17 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
SPECIALS[":"] = method_call
doc_special(":", {"tbl", "method-name", "..."}, "Call the named method on tbl with the provided args.\nMethod name doesn't have to be known at compile-time; if it is, use\n(tbl:method-name ...) instead.")
- local function _137_(ast, _, parent)
+ SPECIALS.comment = function(ast, _, parent)
local els = {}
for i = 2, #ast do
table.insert(els, view(ast[i], {["one-line?"] = true}))
end
return compiler.emit(parent, ("--[[ " .. table.concat(els, " ") .. " ]]"), ast)
end
- SPECIALS.comment = _137_
doc_special("comment", {"..."}, "Comment which will be emitted in Lua output.", true)
local function hashfn_max_used(f_scope, i, max)
- local max0 = nil
- if (f_scope.symmeta[("$" .. i)]).used then
+ local max0
+ if f_scope.symmeta[("$" .. i)].used then
max0 = i
else
max0 = max
@@ 1580,16 1566,14 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return max0
end
end
- local function _140_(ast, scope, parent)
+ SPECIALS.hashfn = function(ast, scope, parent)
compiler.assert((#ast == 2), "expected one argument", ast)
- local f_scope = nil
+ local f_scope
do
- local _494_ = compiler["make-scope"](scope)
- do
- end
- _494_["vararg"] = false
- _494_["hashfn"] = true
- f_scope = _494_
+ local _514_ = compiler["make-scope"](scope)
+ do end (_514_)["vararg"] = false
+ _514_["hashfn"] = true
+ f_scope = _514_
end
local f_chunk = {}
local name = compiler.gensym(scope)
@@ 1605,7 1589,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
f_scope.vararg = true
return nil
else
- return (utils["list?"](node) or utils["table?"](node))
+ return (("table" == type(node)) and (utils.sym("hashfn") ~= node[1]) and (utils["list?"](node) or utils["table?"](node)))
end
end
utils["walk-tree"](ast[2], walker)
@@ 1615,7 1599,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
compiler.assert((max_used == 0), "$ and $... in hashfn are mutually exclusive", ast)
else
end
- local arg_str = nil
+ local arg_str
if f_scope.vararg then
arg_str = tostring(utils.varg())
else
@@ 1626,13 1610,12 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
compiler.emit(parent, "end", ast)
return utils.expr(name, "sym")
end
- SPECIALS.hashfn = _140_
doc_special("hashfn", {"..."}, "Function literal shorthand; args are either $... OR $1, $2, etc.")
- local function maybe_short_circuit_protect(ast, i, name, _498_)
- local _arg_499_ = _498_
- local mac = (_arg_499_).macros
+ local function maybe_short_circuit_protect(ast, i, name, _518_)
+ local _arg_519_ = _518_
+ local mac = _arg_519_["macros"]
local call = (utils["list?"](ast) and tostring(ast[1]))
- if (((("or" == name) or ("and" == name)) and (1 < i)) and (((mac[call] or ("set" == call)) or ("tset" == call)) or ("global" == call))) then
+ if ((("or" == name) or ("and" == name)) and (1 < i) and (mac[call] or ("set" == call) or ("tset" == call) or ("global" == call))) then
return utils.list(utils.sym("do"), ast)
else
return ast
@@ 1651,40 1634,40 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
table.insert(operands, tostring(subexprs[1]))
end
end
- local _502_ = #operands
- if (_502_ == 0) then
- local _504_ = nil
+ local _522_ = #operands
+ if (_522_ == 0) then
+ local _524_
do
- local _503_ = zero_arity
- compiler.assert(_503_, "Expected more than 0 arguments", ast)
- _504_ = _503_
+ local _523_ = zero_arity
+ compiler.assert(_523_, "Expected more than 0 arguments", ast)
+ _524_ = _523_
end
- return utils.expr(_504_, "literal")
- elseif (_502_ == 1) then
+ return utils.expr(_524_, "literal")
+ elseif (_522_ == 1) then
if unary_prefix then
return ("(" .. unary_prefix .. padded_op .. operands[1] .. ")")
else
return operands[1]
end
elseif true then
- local _ = _502_
+ local _ = _522_
return ("(" .. table.concat(operands, padded_op) .. ")")
else
return nil
end
end
local function define_arithmetic_special(name, zero_arity, unary_prefix, _3flua_name)
- local _510_ = nil
+ local _530_
do
- local _507_ = (_3flua_name or name)
- local _508_ = zero_arity
- local _509_ = unary_prefix
- local function _511_(...)
- return arithmetic_special(_507_, _508_, _509_, ...)
+ local _527_ = (_3flua_name or name)
+ local _528_ = zero_arity
+ local _529_ = unary_prefix
+ local function _531_(...)
+ return arithmetic_special(_527_, _528_, _529_, ...)
end
- _510_ = _511_
+ _530_ = _531_
end
- SPECIALS[name] = _510_
+ SPECIALS[name] = _530_
return doc_special(name, {"a", "b", "..."}, "Arithmetic operator; works the same as Lua but accepts more arguments.")
end
define_arithmetic_special("+", "0")
@@ 1695,14 1678,12 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
define_arithmetic_special("%")
define_arithmetic_special("/", nil, "1")
define_arithmetic_special("//", nil, "1")
- local function _148_(ast, scope, parent)
+ SPECIALS["or"] = function(ast, scope, parent)
return arithmetic_special("or", "false", nil, ast, scope, parent)
end
- SPECIALS["or"] = _148_
- local function _149_(ast, scope, parent)
+ SPECIALS["and"] = function(ast, scope, parent)
return arithmetic_special("and", "true", nil, ast, scope, parent)
end
- SPECIALS["and"] = _149_
doc_special("and", {"a", "b", "..."}, "Boolean operator; works the same as Lua but accepts more arguments.")
doc_special("or", {"a", "b", "..."}, "Boolean operator; works the same as Lua but accepts more arguments.")
local function bitop_special(native_name, lib_name, zero_arity, unary_prefix, ast, scope, parent)
@@ 1714,14 1695,14 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
local padded_native_name = (" " .. native_name .. " ")
local prefixed_lib_name = ("bit." .. lib_name)
for i = 2, len do
- local subexprs = nil
- local _512_ = nil
+ local subexprs
+ local _532_
if (i ~= len) then
- _512_ = 1
+ _532_ = 1
else
- _512_ = nil
+ _532_ = nil
end
- subexprs = compiler.compile1(ast[i], scope, parent, {nval = _512_})
+ subexprs = compiler.compile1(ast[i], scope, parent, {nval = _532_})
utils.map(subexprs, tostring, operands)
end
if (#operands == 1) then
@@ 1740,18 1721,18 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
end
local function define_bitop_special(name, zero_arity, unary_prefix, native)
- local _522_ = nil
+ local _542_
do
- local _518_ = native
- local _519_ = name
- local _520_ = zero_arity
- local _521_ = unary_prefix
- local function _523_(...)
- return bitop_special(_518_, _519_, _520_, _521_, ...)
+ local _538_ = native
+ local _539_ = name
+ local _540_ = zero_arity
+ local _541_ = unary_prefix
+ local function _543_(...)
+ return bitop_special(_538_, _539_, _540_, _541_, ...)
end
- _522_ = _523_
+ _542_ = _543_
end
- SPECIALS[name] = _522_
+ SPECIALS[name] = _542_
return nil
end
define_bitop_special("lshift", nil, "1", "<<")
@@ 1765,17 1746,49 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
doc_special("bor", {"x1", "x2", "..."}, "Bitwise OR of any number of arguments.\nOnly works in Lua 5.3+ or LuaJIT with the --use-bit-lib flag.")
doc_special("bxor", {"x1", "x2", "..."}, "Bitwise XOR of any number of arguments.\nOnly works in Lua 5.3+ or LuaJIT with the --use-bit-lib flag.")
doc_special("..", {"a", "b", "..."}, "String concatenation operator; works the same as Lua but accepts more arguments.")
- local function native_comparator(op, _524_, scope, parent)
- local _arg_525_ = _524_
- local _ = (_arg_525_)[1]
- local lhs_ast = (_arg_525_)[2]
- local rhs_ast = (_arg_525_)[3]
- local _let_526_ = compiler.compile1(lhs_ast, scope, parent, {nval = 1})
- local lhs = (_let_526_)[1]
- local _let_527_ = compiler.compile1(rhs_ast, scope, parent, {nval = 1})
- local rhs = (_let_527_)[1]
+ local function native_comparator(op, _544_, scope, parent)
+ local _arg_545_ = _544_
+ local _ = _arg_545_[1]
+ local lhs_ast = _arg_545_[2]
+ local rhs_ast = _arg_545_[3]
+ local _let_546_ = compiler.compile1(lhs_ast, scope, parent, {nval = 1})
+ local lhs = _let_546_[1]
+ local _let_547_ = compiler.compile1(rhs_ast, scope, parent, {nval = 1})
+ local rhs = _let_547_[1]
return string.format("(%s %s %s)", tostring(lhs), op, tostring(rhs))
end
+ local function idempotent_comparator(op, chain_op, ast, scope, parent)
+ local vals
+ do
+ local tbl_16_auto = {}
+ local i_17_auto = #tbl_16_auto
+ for i = 2, #ast do
+ local val_18_auto = tostring((compiler.compile1(ast[i], scope, parent, {nval = 1}))[1])
+ if (nil ~= val_18_auto) then
+ i_17_auto = (i_17_auto + 1)
+ do end (tbl_16_auto)[i_17_auto] = val_18_auto
+ else
+ end
+ end
+ vals = tbl_16_auto
+ end
+ local comparisons
+ do
+ local tbl_16_auto = {}
+ local i_17_auto = #tbl_16_auto
+ for i = 1, (#vals - 1) do
+ local val_18_auto = string.format("(%s %s %s)", vals[i], op, vals[(i + 1)])
+ if (nil ~= val_18_auto) then
+ i_17_auto = (i_17_auto + 1)
+ do end (tbl_16_auto)[i_17_auto] = val_18_auto
+ else
+ end
+ end
+ comparisons = tbl_16_auto
+ end
+ local chain = string.format(" %s ", (chain_op or "and"))
+ return table.concat(comparisons, chain)
+ end
local function double_eval_protected_comparator(op, chain_op, ast, scope, parent)
local arglist = {}
local comparisons = {}
@@ 1785,8 1798,17 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
table.insert(arglist, tostring(compiler.gensym(scope)))
table.insert(vals, tostring((compiler.compile1(ast[i], scope, parent, {nval = 1}))[1]))
end
- for i = 1, (#arglist - 1) do
- table.insert(comparisons, string.format("(%s %s %s)", arglist[i], op, arglist[(i + 1)]))
+ do
+ local tbl_16_auto = comparisons
+ local i_17_auto = #tbl_16_auto
+ for i = 1, (#arglist - 1) do
+ local val_18_auto = string.format("(%s %s %s)", arglist[i], op, arglist[(i + 1)])
+ if (nil ~= val_18_auto) then
+ i_17_auto = (i_17_auto + 1)
+ do end (tbl_16_auto)[i_17_auto] = val_18_auto
+ else
+ end
+ end
end
return string.format("(function(%s) return %s end)(%s)", table.concat(arglist, ","), table.concat(comparisons, chain), table.concat(vals, ","))
end
@@ 1797,6 1819,8 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
compiler.assert((2 < #ast), "expected at least two arguments", ast)
if (3 == #ast) then
return native_comparator(op, ast, scope, parent)
+ elseif utils["every?"](utils["idempotent-expr?"], {unpack(ast, 2)}) then
+ return idempotent_comparator(op, _3fchain_op, ast, scope, parent)
else
return double_eval_protected_comparator(op, _3fchain_op, ast, scope, parent)
end
@@ 1826,11 1850,9 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
doc_special("bnot", {"x"}, "Bitwise negation; only works in Lua 5.3+ or LuaJIT with the --use-bit-lib flag.")
define_unary_special("length", "#")
doc_special("length", {"x"}, "Returns the length of a table or string.")
- do
- end
- SPECIALS["~="] = SPECIALS["not="]
+ do end (SPECIALS)["~="] = SPECIALS["not="]
SPECIALS["#"] = SPECIALS.length
- local function _156_(ast, scope, parent)
+ SPECIALS.quote = function(ast, scope, parent)
compiler.assert((#ast == 2), "expected one argument", ast)
local runtime, this_scope = true, scope
while this_scope do
@@ 1842,7 1864,6 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
return compiler["do-quote"](ast[2], scope, parent, runtime)
end
- SPECIALS.quote = _156_
doc_special("quote", {"x"}, "Quasiquote the following form. Only works in macro/compiler scope.")
local macro_loaded = {}
local function safe_getmetatable(tbl)
@@ 1852,90 1873,88 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
local safe_require = nil
local function safe_compiler_env()
- local _531_ = nil
+ local _554_
do
- local _530_ = rawget(_G, "utf8")
- if (nil ~= _530_) then
- _531_ = utils.copy(_530_)
+ local _553_ = rawget(_G, "utf8")
+ if (nil ~= _553_) then
+ _554_ = utils.copy(_553_)
else
- _531_ = _530_
+ _554_ = _553_
end
end
- return {assert = assert, pairs = pairs, tostring = tostring, table = utils.copy(table), error = error, rawget = rawget, rawequal = rawequal, xpcall = xpcall, utf8 = _531_, rawlen = rawget(_G, "rawlen"), rawset = rawset, ipairs = ipairs, _VERSION = _VERSION, require = safe_require, next = next, math = utils.copy(math), select = select, pcall = pcall, setmetatable = setmetatable, bit = rawget(_G, "bit"), string = utils.copy(string), type = type, getmetatable = safe_getmetatable, print = print, tonumber = tonumber}
+ return {table = utils.copy(table), math = utils.copy(math), string = utils.copy(string), pairs = utils.stablepairs, ipairs = ipairs, select = select, tostring = tostring, tonumber = tonumber, bit = rawget(_G, "bit"), pcall = pcall, xpcall = xpcall, next = next, print = print, type = type, assert = assert, error = error, setmetatable = setmetatable, getmetatable = safe_getmetatable, require = safe_require, rawlen = rawget(_G, "rawlen"), rawget = rawget, rawset = rawset, rawequal = rawequal, _VERSION = _VERSION, utf8 = _554_}
end
local function combined_mt_pairs(env)
local combined = {}
- local _let_533_ = getmetatable(env)
- local __index = (_let_533_).__index
+ local _let_556_ = getmetatable(env)
+ local __index = _let_556_["__index"]
if ("table" == type(__index)) then
for k, v in pairs(__index) do
combined[k] = v
end
else
end
- for k, v, next, env0 in nil do
+ for k, v in next, env, nil do
combined[k] = v
end
return next, combined, nil
end
local function make_compiler_env(ast, scope, parent, _3fopts)
- local provided = nil
+ local provided
do
- local _535_ = (_3fopts or utils.root.options)
- if ((_G.type(_535_) == "table") and ((_535_)["compiler-env"] == "strict")) then
+ local _558_ = (_3fopts or utils.root.options)
+ if ((_G.type(_558_) == "table") and ((_558_)["compiler-env"] == "strict")) then
provided = safe_compiler_env()
- elseif ((_G.type(_535_) == "table") and (nil ~= _535_.compilerEnv)) then
- local compiler_env = _535_.compilerEnv
- provided = compiler_env
- elseif ((_G.type(_535_) == "table") and (nil ~= (_535_)["compiler-env"])) then
- local compiler_env = (_535_)["compiler-env"]
+ elseif ((_G.type(_558_) == "table") and (nil ~= (_558_).compilerEnv)) then
+ local compilerEnv = (_558_).compilerEnv
+ provided = compilerEnv
+ elseif ((_G.type(_558_) == "table") and (nil ~= (_558_)["compiler-env"])) then
+ local compiler_env = (_558_)["compiler-env"]
provided = compiler_env
elseif true then
- local _ = _535_
+ local _ = _558_
provided = safe_compiler_env(false)
else
provided = nil
end
end
- local env = nil
- local function _537_(base)
+ local env
+ local function _560_(base)
return utils.sym(compiler.gensym((compiler.scopes.macro or scope), base))
end
- local function _538_()
+ local function _561_()
return compiler.scopes.macro
end
- local function _539_(symbol)
+ local function _562_(symbol)
compiler.assert(compiler.scopes.macro, "must call from macro", ast)
return compiler.scopes.macro.manglings[tostring(symbol)]
end
- local function _540_(form)
+ local function _563_(form)
compiler.assert(compiler.scopes.macro, "must call from macro", ast)
return compiler.macroexpand(form, compiler.scopes.macro)
end
- env = {_VARARG = utils.varg(), ["ast-source"] = utils["ast-source"], list = utils.list, ["comment?"] = utils["comment?"], ["list?"] = utils["list?"], sequence = utils.sequence, macroexpand = _540_, view = view, metadata = compiler.metadata, comment = utils.comment, sym = utils.sym, ["sym?"] = utils["sym?"], ["in-scope?"] = _539_, ["get-scope"] = _538_, _SPECIALS = compiler.scopes.global.specials, gensym = _537_, ["varg?"] = utils["varg?"], ["multi-sym?"] = utils["multi-sym?"], ["sequence?"] = utils["sequence?"], _SCOPE = scope, _AST = ast, _CHUNK = parent, ["macro-loaded"] = macro_loaded, ["assert-compile"] = compiler.assert, unpack = unpack, version = utils.version, _IS_COMPILER = true, ["table?"] = utils["table?"]}
+ env = {_AST = ast, _CHUNK = parent, _IS_COMPILER = true, _SCOPE = scope, _SPECIALS = compiler.scopes.global.specials, _VARARG = utils.varg(), ["macro-loaded"] = macro_loaded, unpack = unpack, ["assert-compile"] = compiler.assert, view = view, version = utils.version, metadata = compiler.metadata, ["ast-source"] = utils["ast-source"], list = utils.list, ["list?"] = utils["list?"], ["table?"] = utils["table?"], sequence = utils.sequence, ["sequence?"] = utils["sequence?"], sym = utils.sym, ["sym?"] = utils["sym?"], ["multi-sym?"] = utils["multi-sym?"], comment = utils.comment, ["comment?"] = utils["comment?"], ["varg?"] = utils["varg?"], gensym = _560_, ["get-scope"] = _561_, ["in-scope?"] = _562_, macroexpand = _563_}
env._G = env
- return setmetatable(env, {__newindex = provided, __pairs = combined_mt_pairs, __index = provided})
+ return setmetatable(env, {__index = provided, __newindex = provided, __pairs = combined_mt_pairs})
end
- local function _542_(...)
- local tbl_14_auto = {}
- local i_15_auto = #tbl_14_auto
+ local function _565_(...)
+ local tbl_16_auto = {}
+ local i_17_auto = #tbl_16_auto
for c in string.gmatch((package.config or ""), "([^\n]+)") do
- local val_16_auto = c
- if (nil ~= val_16_auto) then
- i_15_auto = (i_15_auto + 1)
- do
- end
- tbl_14_auto[i_15_auto] = val_16_auto
+ local val_18_auto = c
+ if (nil ~= val_18_auto) then
+ i_17_auto = (i_17_auto + 1)
+ do end (tbl_16_auto)[i_17_auto] = val_18_auto
else
end
end
- return tbl_14_auto
+ return tbl_16_auto
end
- local _local_541_ = _542_(...)
- local dirsep = (_local_541_)[1]
- local pathsep = (_local_541_)[2]
- local pathmark = (_local_541_)[3]
- local pkg_config = {pathmark = (pathmark or ";"), pathsep = (pathsep or "?"), dirsep = (dirsep or "/")}
+ local _local_564_ = _565_(...)
+ local dirsep = _local_564_[1]
+ local pathsep = _local_564_[2]
+ local pathmark = _local_564_[3]
+ local pkg_config = {dirsep = (dirsep or "/"), pathmark = (pathmark or ";"), pathsep = (pathsep or "?")}
local function escapepat(str)
return string.gsub(str, "[^%w]", "%%%1")
end
@@ 1943,44 1962,44 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
local pathsepesc = escapepat(pkg_config.pathsep)
local pattern = ("([^%s]*)%s"):format(pathsepesc, pathsepesc)
local no_dot_module = modulename:gsub("%.", pkg_config.dirsep)
- local fullpath = ((_3fpathstring or (utils["fennel-module"]).path) .. pkg_config.pathsep)
+ local fullpath = ((_3fpathstring or utils["fennel-module"].path) .. pkg_config.pathsep)
local function try_path(path)
local filename = path:gsub(escapepat(pkg_config.pathmark), no_dot_module)
local filename2 = path:gsub(escapepat(pkg_config.pathmark), modulename)
- local _544_ = (io.open(filename) or io.open(filename2))
- if (nil ~= _544_) then
- local file = _544_
+ local _567_ = (io.open(filename) or io.open(filename2))
+ if (nil ~= _567_) then
+ local file = _567_
file:close()
return filename
elseif true then
- local _ = _544_
+ local _ = _567_
return nil, ("no file '" .. filename .. "'")
else
return nil
end
end
local function find_in_path(start, _3ftried_paths)
- local _546_ = fullpath:match(pattern, start)
- if (nil ~= _546_) then
- local path = _546_
- local _547_, _548_ = try_path(path)
- if (nil ~= _547_) then
- local filename = _547_
+ local _569_ = fullpath:match(pattern, start)
+ if (nil ~= _569_) then
+ local path = _569_
+ local _570_, _571_ = try_path(path)
+ if (nil ~= _570_) then
+ local filename = _570_
return filename
- elseif ((_547_ == nil) and (nil ~= _548_)) then
- local error = _548_
- local function _550_()
- local _549_ = (_3ftried_paths or {})
- table.insert(_549_, error)
- return _549_
+ elseif ((_570_ == nil) and (nil ~= _571_)) then
+ local error = _571_
+ local function _573_()
+ local _572_ = (_3ftried_paths or {})
+ table.insert(_572_, error)
+ return _572_
end
- return find_in_path(((start + #path) + 1), _550_())
+ return find_in_path((start + #path + 1), _573_())
else
return nil
end
elseif true then
- local _ = _546_
- local function _552_()
+ local _ = _569_
+ local function _575_()
local tried_paths = table.concat((_3ftried_paths or {}), "\n\9")
if (_VERSION < "Lua 5.4") then
return ("\n\9" .. tried_paths)
@@ 1988,7 2007,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return tried_paths
end
end
- return nil, _552_()
+ return nil, _575_()
else
return nil
end
@@ 1996,83 2015,81 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return find_in_path(1)
end
local function make_searcher(_3foptions)
- local function _555_(module_name)
+ local function _578_(module_name)
local opts = utils.copy(utils.root.options)
for k, v in pairs((_3foptions or {})) do
opts[k] = v
end
opts["module-name"] = module_name
- local _556_, _557_ = search_module(module_name)
- if (nil ~= _556_) then
- local filename = _556_
- local _560_ = nil
+ local _579_, _580_ = search_module(module_name)
+ if (nil ~= _579_) then
+ local filename = _579_
+ local _583_
do
- local _558_ = filename
- local _559_ = opts
- local function _561_(...)
- return (utils["fennel-module"]).dofile(_558_, _559_, ...)
+ local _581_ = filename
+ local _582_ = opts
+ local function _584_(...)
+ return utils["fennel-module"].dofile(_581_, _582_, ...)
end
- _560_ = _561_
+ _583_ = _584_
end
- return _560_, filename
- elseif ((_556_ == nil) and (nil ~= _557_)) then
- local error = _557_
+ return _583_, filename
+ elseif ((_579_ == nil) and (nil ~= _580_)) then
+ local error = _580_
return error
else
return nil
end
end
- return _555_
+ return _578_
end
local function dofile_with_searcher(fennel_macro_searcher, filename, opts, ...)
- local searchers = ((package.loaders or package.searchers) or {})
+ local searchers = (package.loaders or package.searchers or {})
local _ = table.insert(searchers, 1, fennel_macro_searcher)
- local m = (utils["fennel-module"]).dofile(filename, opts, ...)
+ local m = utils["fennel-module"].dofile(filename, opts, ...)
table.remove(searchers, 1)
return m
end
local function fennel_macro_searcher(module_name)
- local opts = nil
+ local opts
do
- local _563_ = utils.copy(utils.root.options)
- do
- end
- _563_["module-name"] = module_name
- _563_["env"] = "_COMPILER"
- _563_["requireAsInclude"] = false
- _563_["allowedGlobals"] = nil
- opts = _563_
- end
- local _564_ = search_module(module_name, (utils["fennel-module"])["macro-path"])
- if (nil ~= _564_) then
- local filename = _564_
- local _565_ = nil
+ local _586_ = utils.copy(utils.root.options)
+ do end (_586_)["module-name"] = module_name
+ _586_["env"] = "_COMPILER"
+ _586_["requireAsInclude"] = false
+ _586_["allowedGlobals"] = nil
+ opts = _586_
+ end
+ local _587_ = search_module(module_name, utils["fennel-module"]["macro-path"])
+ if (nil ~= _587_) then
+ local filename = _587_
+ local _588_
if (opts["compiler-env"] == _G) then
- local _566_ = fennel_macro_searcher
- local _567_ = filename
- local _568_ = opts
- local function _570_(...)
- return dofile_with_searcher(_566_, _567_, _568_, ...)
+ local _589_ = fennel_macro_searcher
+ local _590_ = filename
+ local _591_ = opts
+ local function _593_(...)
+ return dofile_with_searcher(_589_, _590_, _591_, ...)
end
- _565_ = _570_
+ _588_ = _593_
else
- local _571_ = filename
- local _572_ = opts
- local function _574_(...)
- return (utils["fennel-module"]).dofile(_571_, _572_, ...)
+ local _594_ = filename
+ local _595_ = opts
+ local function _597_(...)
+ return utils["fennel-module"].dofile(_594_, _595_, ...)
end
- _565_ = _574_
+ _588_ = _597_
end
- return _565_, filename
+ return _588_, filename
else
return nil
end
end
local function lua_macro_searcher(module_name)
- local _577_ = search_module(module_name, package.path)
- if (nil ~= _577_) then
- local filename = _577_
- local code = nil
+ local _600_ = search_module(module_name, package.path)
+ if (nil ~= _600_) then
+ local filename = _600_
+ local code
do
local f = io.open(filename)
local function close_handlers_8_auto(ok_9_auto, ...)
@@ 2083,10 2100,10 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return error(..., 0)
end
end
- local function _579_()
+ local function _602_()
return assert(f:read("*a"))
end
- code = close_handlers_8_auto(_G.xpcall(_579_, (package.loaded.fennel or debug).traceback))
+ code = close_handlers_8_auto(_G.xpcall(_602_, (package.loaded.fennel or debug).traceback))
end
local chunk = load_code(code, make_compiler_env(), filename)
return chunk, filename
@@ 2096,16 2113,16 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
local macro_searchers = {fennel_macro_searcher, lua_macro_searcher}
local function search_macro_module(modname, n)
- local _581_ = macro_searchers[n]
- if (nil ~= _581_) then
- local f = _581_
- local _582_, _583_ = f(modname)
- if ((nil ~= _582_) and true) then
- local loader = _582_
- local _3ffilename = _583_
+ local _604_ = macro_searchers[n]
+ if (nil ~= _604_) then
+ local f = _604_
+ local _605_, _606_ = f(modname)
+ if ((nil ~= _605_) and true) then
+ local loader = _605_
+ local _3ffilename = _606_
return loader, _3ffilename
elseif true then
- local _ = _582_
+ local _ = _605_
return search_macro_module(modname, (n + 1))
else
return nil
@@ 2115,55 2132,49 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
end
local function sandbox_fennel_module(modname)
- if ((modname == "fennel.macros") or (((package and package.loaded) and ("table" == type(package.loaded[modname]))) and (package.loaded[modname].metadata == compiler.metadata))) then
+ if ((modname == "fennel.macros") or (package and package.loaded and ("table" == type(package.loaded[modname])) and (package.loaded[modname].metadata == compiler.metadata))) then
return {metadata = compiler.metadata, view = view}
else
return nil
end
end
- local function _587_(modname)
- local function _588_()
+ local function _610_(modname)
+ local function _611_()
local loader, filename = search_macro_module(modname, 1)
compiler.assert(loader, (modname .. " module not found."))
- do
- end
- macro_loaded[modname] = loader(modname, filename)
+ do end (macro_loaded)[modname] = loader(modname, filename)
return macro_loaded[modname]
end
- return ((macro_loaded[modname] or sandbox_fennel_module(modname)) or _588_())
+ return (macro_loaded[modname] or sandbox_fennel_module(modname) or _611_())
end
- safe_require = _587_
+ safe_require = _610_
local function add_macros(macros_2a, ast, scope)
compiler.assert(utils["table?"](macros_2a), "expected macros to be table", ast)
for k, v in pairs(macros_2a) do
compiler.assert((type(v) == "function"), "expected each macro to be function", ast)
- compiler["check-binding-valid"](utils.sym(k), scope, ast)
- do
- end
- scope.macros[k] = v
+ compiler["check-binding-valid"](utils.sym(k), scope, ast, {["macro?"] = true})
+ do end (scope.macros)[k] = v
end
return nil
end
- local function resolve_module_name(_589_, _scope, _parent, opts)
- local _arg_590_ = _589_
- local filename = (_arg_590_).filename
- local second = (_arg_590_)[2]
+ local function resolve_module_name(_612_, _scope, _parent, opts)
+ local _arg_613_ = _612_
+ local filename = _arg_613_["filename"]
+ local second = _arg_613_[2]
local filename0 = (filename or (utils["table?"](second) and second.filename))
local module_name = utils.root.options["module-name"]
local modexpr = compiler.compile(second, opts)
local modname_chunk = load_code(modexpr)
return modname_chunk(module_name, filename0)
end
- local function _174_(ast, scope, parent, _3freal_ast)
+ SPECIALS["require-macros"] = function(ast, scope, parent, _3freal_ast)
compiler.assert((#ast == 2), "Expected one module name argument", (_3freal_ast or ast))
local modname = resolve_module_name(ast, scope, parent, {})
compiler.assert(utils["string?"](modname), "module name must compile to string", (_3freal_ast or ast))
if not macro_loaded[modname] then
local loader, filename = search_macro_module(modname, 1)
compiler.assert(loader, (modname .. " module not found."), ast)
- do
- end
- macro_loaded[modname] = loader(modname, filename)
+ do end (macro_loaded)[modname] = compiler.assert(utils["table?"](loader(modname, filename)), "expected macros to be table", (_3freal_ast or ast))
else
end
if ("import-macros" == tostring(ast[1])) then
@@ 2172,7 2183,6 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return add_macros(macro_loaded[modname], ast, scope, parent)
end
end
- SPECIALS["require-macros"] = _174_
doc_special("require-macros", {"macro-module-name"}, "Load given module and use its contents as macro definitions in current scope.\nMacro module should return a table of macro functions with string keys.\nConsider using import-macros instead as it is more flexible.")
local function emit_included_fennel(src, path, opts, sub_chunk)
local subscope = compiler["make-scope"](utils.root.scope.parent)
@@ 2185,7 2195,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
table.insert(forms, val)
end
for i = 1, #forms do
- local subopts = nil
+ local subopts
if (i == #forms) then
subopts = {tail = true}
else
@@ 2198,7 2208,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
local function include_path(ast, opts, path, mod, fennel_3f)
utils.root.scope.includes[mod] = "fnl/loading"
- local src = nil
+ local src
do
local f = assert(io.open(path))
local function close_handlers_8_auto(ok_9_auto, ...)
@@ 2209,10 2219,10 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return error(..., 0)
end
end
- local function _596_()
+ local function _619_()
return assert(f:read("*all")):gsub("[\13\n]*$", "")
end
- src = close_handlers_8_auto(_G.xpcall(_596_, (package.loaded.fennel or debug).traceback))
+ src = close_handlers_8_auto(_G.xpcall(_619_, (package.loaded.fennel or debug).traceback))
end
local ret = utils.expr(("require(\"" .. mod .. "\")"), "statement")
local target = ("package.preload[%q]"):format(mod)
@@ 2240,16 2250,16 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return nil
end
end
- local function _182_(ast, scope, parent, opts)
+ SPECIALS.include = function(ast, scope, parent, opts)
compiler.assert((#ast == 2), "expected one argument", ast)
- local modexpr = nil
+ local modexpr
do
- local _599_, _600_ = pcall(resolve_module_name, ast, scope, parent, opts)
- if ((_599_ == true) and (nil ~= _600_)) then
- local modname = _600_
+ local _622_, _623_ = pcall(resolve_module_name, ast, scope, parent, opts)
+ if ((_622_ == true) and (nil ~= _623_)) then
+ local modname = _623_
modexpr = utils.expr(string.format("%q", modname), "literal")
elseif true then
- local _ = _599_
+ local _ = _622_
modexpr = (compiler.compile1(ast[2], scope, parent, {nval = 1}))[1]
else
modexpr = nil
@@ 2264,17 2274,17 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
else
local mod = load_code(("return " .. modexpr[1]))()
local oldmod = utils.root.options["module-name"]
- local _ = nil
+ local _
utils.root.options["module-name"] = mod
_ = nil
- local res = nil
- local function _604_()
- local _603_ = search_module(mod)
- if (nil ~= _603_) then
- local fennel_path = _603_
+ local res
+ local function _627_()
+ local _626_ = search_module(mod)
+ if (nil ~= _626_) then
+ local fennel_path = _626_
return include_path(ast, opts, fennel_path, mod, true)
elseif true then
- local _0 = _603_
+ local _0 = _626_
local lua_path = search_module(mod, package.path)
if lua_path then
return include_path(ast, opts, lua_path, mod, false)
@@ 2287,41 2297,35 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return nil
end
end
- res = ((((utils["member?"](mod, (utils.root.options.skipInclude or {})) and opts.fallback(modexpr, true)) or include_circular_fallback(mod, modexpr, opts.fallback, ast)) or utils.root.scope.includes[mod]) or _604_())
- do end (utils.root.options)["module-name"] = oldmod
+ res = ((utils["member?"](mod, (utils.root.options.skipInclude or {})) and opts.fallback(modexpr, true)) or include_circular_fallback(mod, modexpr, opts.fallback, ast) or utils.root.scope.includes[mod] or _627_())
+ utils.root.options["module-name"] = oldmod
return res
end
end
- SPECIALS.include = _182_
doc_special("include", {"module-name-literal"}, "Like require but load the target module during compilation and embed it in the\nLua output. The module must be a string literal and resolvable at compile time.")
local function eval_compiler_2a(ast, scope, parent)
local env = make_compiler_env(ast, scope, parent)
local opts = utils.copy(utils.root.options)
opts.scope = compiler["make-scope"](compiler.scopes.compiler)
opts.allowedGlobals = current_global_names(env)
- return load_code(compiler.compile(ast, opts), wrap_env(env))(opts["module-name"], ast.filename)
+ return assert(load_code(compiler.compile(ast, opts), wrap_env(env)), opts["module-name"], ast.filename)()
end
- local function _188_(ast, scope, parent)
- compiler.assert((#ast == 2), "Expected one table argument", ast)
+ SPECIALS.macros = function(ast, scope, parent)
+ compiler.assert(((#ast == 2) and utils["table?"](ast[2])), "Expected one table argument", ast)
return add_macros(eval_compiler_2a(ast[2], scope, parent), ast, scope, parent)
end
- SPECIALS.macros = _188_
doc_special("macros", {"{:macro-name-1 (fn [...] ...) ... :macro-name-N macro-body-N}"}, "Define all functions in the given table as macros local to the current scope.")
- local function _189_(ast, scope, parent)
+ SPECIALS["eval-compiler"] = function(ast, scope, parent)
local old_first = ast[1]
ast[1] = utils.sym("do")
local val = eval_compiler_2a(ast, scope, parent)
- do
- end
- ast[1] = old_first
+ do end (ast)[1] = old_first
return val
end
- SPECIALS["eval-compiler"] = _189_
doc_special("eval-compiler", {"..."}, "Evaluate the body at compile-time. Use the macro system instead if possible.", true)
- return {["wrap-env"] = wrap_env, ["current-global-names"] = current_global_names, doc = doc_2a, ["macro-loaded"] = macro_loaded, ["search-module"] = search_module, ["make-compiler-env"] = make_compiler_env, ["macro-searchers"] = macro_searchers, ["load-code"] = load_code, ["make-searcher"] = make_searcher}
+ return {doc = doc_2a, ["current-global-names"] = current_global_names, ["load-code"] = load_code, ["macro-loaded"] = macro_loaded, ["macro-searchers"] = macro_searchers, ["make-compiler-env"] = make_compiler_env, ["search-module"] = search_module, ["make-searcher"] = make_searcher, ["wrap-env"] = wrap_env}
end
- package.preload["fennel.specials"] = (package.preload["fennel.specials"] or _74_)
- local function _190_(...)
+ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or function(...)
local utils = require("fennel.utils")
local parser = require("fennel.parser")
local friend = require("fennel.friend")
@@ 2329,39 2333,46 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
local scopes = {}
local function make_scope(_3fparent)
local parent = (_3fparent or scopes.global)
- local _249_ = nil
+ local _268_
if parent then
- _249_ = ((parent.depth or 0) + 1)
+ _268_ = ((parent.depth or 0) + 1)
else
- _249_ = 0
+ _268_ = 0
end
- return {vararg = (parent and parent.vararg), autogensyms = setmetatable({}, {__index = (parent and parent.autogensyms)}), specials = setmetatable({}, {__index = (parent and parent.specials)}), symmeta = setmetatable({}, {__index = (parent and parent.symmeta)}), depth = _249_, refedglobals = {}, macros = setmetatable({}, {__index = (parent and parent.macros)}), parent = parent, gensyms = setmetatable({}, {__index = (parent and parent.gensyms)}), hashfn = (parent and parent.hashfn), manglings = setmetatable({}, {__index = (parent and parent.manglings)}), includes = setmetatable({}, {__index = (parent and parent.includes)}), unmanglings = setmetatable({}, {__index = (parent and parent.unmanglings)})}
+ return {includes = setmetatable({}, {__index = (parent and parent.includes)}), macros = setmetatable({}, {__index = (parent and parent.macros)}), manglings = setmetatable({}, {__index = (parent and parent.manglings)}), specials = setmetatable({}, {__index = (parent and parent.specials)}), symmeta = setmetatable({}, {__index = (parent and parent.symmeta)}), unmanglings = setmetatable({}, {__index = (parent and parent.unmanglings)}), gensyms = setmetatable({}, {__index = (parent and parent.gensyms)}), autogensyms = setmetatable({}, {__index = (parent and parent.autogensyms)}), vararg = (parent and parent.vararg), depth = _268_, hashfn = (parent and parent.hashfn), refedglobals = {}, parent = parent}
end
local function assert_msg(ast, msg)
- local ast_tbl = nil
+ local ast_tbl
if ("table" == type(ast)) then
ast_tbl = ast
else
ast_tbl = {}
end
local m = getmetatable(ast)
- local filename = (((m and m.filename) or ast_tbl.filename) or "unknown")
- local line = (((m and m.line) or ast_tbl.line) or "?")
- local col = (((m and m.col) or ast_tbl.col) or "?")
- local target = tostring(((utils["sym?"](ast_tbl[1]) or ast_tbl[1]) or "()"))
+ local filename = ((m and m.filename) or ast_tbl.filename or "unknown")
+ local line = ((m and m.line) or ast_tbl.line or "?")
+ local col = ((m and m.col) or ast_tbl.col or "?")
+ local target = tostring((utils["sym?"](ast_tbl[1]) or ast_tbl[1] or "()"))
return string.format("%s:%s:%s Compile error in '%s': %s", filename, line, col, target, msg)
end
- local function assert_compile(condition, msg, ast)
+ local function assert_compile(condition, msg, ast, _3ffallback_ast)
if not condition then
- local _let_252_ = (utils.root.options or {})
- local source = (_let_252_).source
- local unfriendly = (_let_252_).unfriendly
- if (nil == utils.hook("assert-compile", condition, msg, ast, utils.root.reset)) then
+ local _let_271_ = (utils.root.options or {})
+ local source = _let_271_["source"]
+ local unfriendly = _let_271_["unfriendly"]
+ local error_pinpoint = _let_271_["error-pinpoint"]
+ local ast0
+ if next(utils["ast-source"](ast)) then
+ ast0 = ast
+ else
+ ast0 = (_3ffallback_ast or {})
+ end
+ if (nil == utils.hook("assert-compile", condition, msg, ast0, utils.root.reset)) then
utils.root.reset()
- if (((unfriendly or not friend) or not _G.io) or not _G.io.read) then
- error(assert_msg(ast, msg), 0)
+ if (unfriendly or not friend or not _G.io or not _G.io.read) then
+ error(assert_msg(ast0, msg), 0)
else
- friend["assert-compile"](condition, msg, ast, source)
+ friend["assert-compile"](condition, msg, ast0, source, {["error-pinpoint"] = error_pinpoint})
end
else
end
@@ 2373,35 2384,35 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
scopes.global.vararg = true
scopes.compiler = make_scope(scopes.global)
scopes.macro = scopes.global
- local serialize_subst = {["\9"] = "\\t", ["\n"] = "n", ["\12"] = "\\f", ["\11"] = "\\v", ["\8"] = "\\b", ["\7"] = "\\a"}
+ local serialize_subst = {["\7"] = "\\a", ["\8"] = "\\b", ["\9"] = "\\t", ["\n"] = "n", ["\11"] = "\\v", ["\12"] = "\\f"}
local function serialize_string(str)
- local function _256_(_241)
+ local function _276_(_241)
return ("\\" .. _241:byte())
end
- return string.gsub(string.gsub(string.format("%q", str), ".", serialize_subst), "[\128-\255]", _256_)
+ return string.gsub(string.gsub(string.format("%q", str), ".", serialize_subst), "[\128-\255]", _276_)
end
local function global_mangling(str)
if utils["valid-lua-identifier?"](str) then
return str
else
- local function _257_(_241)
+ local function _277_(_241)
return string.format("_%02x", _241:byte())
end
- return ("__fnl_global__" .. str:gsub("[^%w]", _257_))
+ return ("__fnl_global__" .. str:gsub("[^%w]", _277_))
end
end
local function global_unmangling(identifier)
- local _259_ = string.match(identifier, "^__fnl_global__(.*)$")
- if (nil ~= _259_) then
- local rest = _259_
- local _260_ = nil
- local function _261_(_241)
+ local _279_ = string.match(identifier, "^__fnl_global__(.*)$")
+ if (nil ~= _279_) then
+ local rest = _279_
+ local _280_
+ local function _281_(_241)
return string.char(tonumber(_241:sub(2), 16))
end
- _260_ = string.gsub(rest, "_[%da-f][%da-f]", _261_)
- return _260_
+ _280_ = string.gsub(rest, "_[%da-f][%da-f]", _281_)
+ return _280_
elseif true then
- local _ = _259_
+ local _ = _279_
return identifier
else
return nil
@@ 2420,35 2431,29 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
local function local_mangling(str, scope, ast, _3ftemp_manglings)
assert_compile(not utils["multi-sym?"](str), ("unexpected multi symbol " .. str), ast)
- local raw = nil
+ local raw
if ((utils["lua-keywords"])[str] or str:match("^%d")) then
raw = ("_" .. str)
else
raw = str
end
- local mangling = nil
- local function _265_(_241)
+ local mangling
+ local function _285_(_241)
return string.format("_%02x", _241:byte())
end
- mangling = string.gsub(string.gsub(raw, "-", "_"), "[^%w_]", _265_)
+ mangling = string.gsub(string.gsub(raw, "-", "_"), "[^%w_]", _285_)
local unique = unique_mangling(mangling, mangling, scope, 0)
- do
- end
- scope.unmanglings[unique] = str
+ do end (scope.unmanglings)[unique] = str
do
local manglings = (_3ftemp_manglings or scope.manglings)
- do
- end
- manglings[str] = unique
+ do end (manglings)[str] = unique
end
return unique
end
local function apply_manglings(scope, new_manglings, ast)
for raw, mangled in pairs(new_manglings) do
assert_compile(not scope.refedglobals[mangled], ("use of global " .. raw .. " is aliased by a local"), ast)
- do
- end
- scope.manglings[raw] = mangled
+ do end (scope.manglings)[raw] = mangled
end
return nil
end
@@ 2477,9 2482,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
mangling = ((_3fbase or "") .. next_append() .. (_3fsuffix or ""))
end
scope.unmanglings[mangling] = (_3fbase or true)
- do
- end
- scope.gensyms[mangling] = true
+ do end (scope.gensyms)[mangling] = true
return mangling
end
local function combine_auto_gensym(parts, first)
@@ 2491,38 2494,43 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return table.concat(parts, ".")
end
local function autogensym(base, scope)
- local _268_ = utils["multi-sym?"](base)
- if (nil ~= _268_) then
- local parts = _268_
+ local _288_ = utils["multi-sym?"](base)
+ if (nil ~= _288_) then
+ local parts = _288_
return combine_auto_gensym(parts, autogensym(parts[1], scope))
elseif true then
- local _ = _268_
- local function _269_()
+ local _ = _288_
+ local function _289_()
local mangling = gensym(scope, base:sub(1, ( - 2)), "auto")
- do
- end
- scope.autogensyms[base] = mangling
+ do end (scope.autogensyms)[base] = mangling
return mangling
end
- return (scope.autogensyms[base] or _269_())
+ return (scope.autogensyms[base] or _289_())
else
return nil
end
end
- local function check_binding_valid(symbol, scope, ast)
+ local function check_binding_valid(symbol, scope, ast, _3fopts)
local name = tostring(symbol)
- assert_compile(not name:find("&"), "invalid character: &")
- assert_compile(not name:find("^%."), "invalid character: .")
- assert_compile(not (scope.specials[name] or scope.macros[name]), ("local %s was overshadowed by a special form or macro"):format(name), ast)
+ local macro_3f
+ do
+ local t_291_ = _3fopts
+ if (nil ~= t_291_) then
+ t_291_ = (t_291_)["macro?"]
+ else
+ end
+ macro_3f = t_291_
+ end
+ assert_compile(not name:find("&"), "invalid character: &", symbol)
+ assert_compile(not name:find("^%."), "invalid character: .", symbol)
+ assert_compile(not (scope.specials[name] or (not macro_3f and scope.macros[name])), ("local %s was overshadowed by a special form or macro"):format(name), ast)
return assert_compile(not utils["quoted?"](symbol), string.format("macro tried to bind %s without gensym", name), symbol)
end
local function declare_local(symbol, meta, scope, ast, _3ftemp_manglings)
check_binding_valid(symbol, scope, ast)
local name = tostring(symbol)
assert_compile(not utils["multi-sym?"](name), ("unexpected multi symbol " .. name), ast)
- do
- end
- scope.symmeta[name] = meta
+ do end (scope.symmeta)[name] = meta
return local_mangling(name, scope, ast, _3ftemp_manglings)
end
local function hashfn_arg_name(name, multi_sym_parts, scope)
@@ 2552,10 2560,10 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
scope.symmeta[parts[1]]["used"] = true
else
end
- assert_compile(not scope.macros[parts[1]], "tried to reference a macro at runtime", symbol)
- assert_compile((not scope.specials[parts[1]] or ("require" == parts[1])), "tried to reference a special form at runtime", symbol)
- assert_compile((((not _3freference_3f or local_3f) or ("_ENV" == parts[1])) or global_allowed_3f(parts[1])), ("unknown identifier in strict mode: " .. tostring(parts[1])), symbol)
- if ((allowed_globals and not local_3f) and scope.parent) then
+ assert_compile(not scope.macros[parts[1]], "tried to reference a macro without calling it", symbol)
+ assert_compile((not scope.specials[parts[1]] or ("require" == parts[1])), "tried to reference a special form without calling it", symbol)
+ assert_compile((not _3freference_3f or local_3f or ("_ENV" == parts[1]) or global_allowed_3f(parts[1])), ("unknown identifier: " .. tostring(parts[1])), symbol)
+ if (allowed_globals and not local_3f and scope.parent) then
scope.parent.refedglobals[parts[1]] = true
else
end
@@ 2571,7 2579,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
local function peephole(chunk)
if chunk.leaf then
return chunk
- elseif ((((3 <= #chunk) and ((chunk[(#chunk - 2)]).leaf == "do")) and not (chunk[(#chunk - 1)]).leaf) and (chunk[#chunk].leaf == "end")) then
+ elseif ((3 <= #chunk) and (chunk[(#chunk - 2)].leaf == "do") and not chunk[(#chunk - 1)].leaf and (chunk[#chunk].leaf == "end")) then
local kid = peephole(chunk[(#chunk - 1)])
local new_chunk = {ast = chunk.ast}
for i = 1, (#chunk - 3) do
@@ 2615,26 2623,24 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
return table.concat(out, "\n")
end
- local function flatten_chunk(sm, chunk, tab, depth)
+ local function flatten_chunk(file_sourcemap, chunk, tab, depth)
if chunk.leaf then
- local code = chunk.leaf
- local info = chunk.ast
- if sm then
- table.insert(sm, {(info and info.filename), (info and info.line)})
- else
- end
- return code
+ local _let_303_ = utils["ast-source"](chunk.ast)
+ local filename = _let_303_["filename"]
+ local line = _let_303_["line"]
+ table.insert(file_sourcemap, {filename, line})
+ return chunk.leaf
else
- local tab0 = nil
+ local tab0
do
- local _282_ = tab
- if (_282_ == true) then
+ local _304_ = tab
+ if (_304_ == true) then
tab0 = " "
- elseif (_282_ == false) then
+ elseif (_304_ == false) then
tab0 = ""
- elseif (_282_ == tab) then
+ elseif (_304_ == tab) then
tab0 = tab
- elseif (_282_ == nil) then
+ elseif (_304_ == nil) then
tab0 = ""
else
tab0 = nil
@@ 2642,7 2648,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
local function parter(c)
if (c.leaf or (0 < #c)) then
- local sub = flatten_chunk(sm, c, tab0, (depth + 1))
+ local sub = flatten_chunk(file_sourcemap, c, tab0, (depth + 1))
if (0 < depth) then
return (tab0 .. sub:gsub("\n", ("\n" .. tab0)))
else
@@ 2669,37 2675,32 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
if options.correlate then
return flatten_chunk_correlated(chunk0, options), {}
else
- local sm = {}
- local ret = flatten_chunk(sm, chunk0, options.indent, 0)
- if sm then
- sm.short_src = (options.filename or make_short_src((options.source or ret)))
- if options.filename then
- sm.key = ("@" .. options.filename)
- else
- sm.key = ret
- end
- sourcemap[sm.key] = sm
+ local file_sourcemap = {}
+ local src = flatten_chunk(file_sourcemap, chunk0, options.indent, 0)
+ file_sourcemap.short_src = (options.filename or make_short_src((options.source or src)))
+ if options.filename then
+ file_sourcemap.key = ("@" .. options.filename)
else
+ file_sourcemap.key = src
end
- return ret, sm
+ sourcemap[file_sourcemap.key] = file_sourcemap
+ return src, file_sourcemap
end
end
local function make_metadata()
- local function _291_(self, tgt, key)
+ local function _312_(self, tgt, key)
if self[tgt] then
return self[tgt][key]
else
return nil
end
end
- local function _293_(self, tgt, key, value)
+ local function _314_(self, tgt, key, value)
self[tgt] = (self[tgt] or {})
- do
- end
- self[tgt][key] = value
+ do end (self[tgt])[key] = value
return tgt
end
- local function _294_(self, tgt, ...)
+ local function _315_(self, tgt, ...)
local kv_len = select("#", ...)
local kvs = {...}
if ((kv_len % 2) ~= 0) then
@@ 2712,7 2713,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
return tgt
end
- return setmetatable({}, {__mode = "k", __index = {get = _291_, setall = _294_, set = _293_}})
+ return setmetatable({}, {__index = {get = _312_, set = _314_, setall = _315_}, __mode = "k"})
end
local function exprs1(exprs)
return table.concat(utils.map(exprs, tostring), ", ")
@@ 2725,7 2726,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
emit(chunk, string.format("do local _ = %s end", tostring(se)), ast)
elseif (se.type == "statement") then
local code = tostring(se)
- local disambiguated = nil
+ local disambiguated
if (code:byte() == 40) then
disambiguated = ("do end " .. code)
else
@@ 2762,70 2763,69 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
if opts.target then
local result = exprs1(exprs)
- local function _302_()
+ local function _323_()
if (result == "") then
return "nil"
else
return result
end
end
- emit(parent, string.format("%s = %s", opts.target, _302_()), ast)
+ emit(parent, string.format("%s = %s", opts.target, _323_()), ast)
else
end
if (opts.tail or opts.target) then
return {returned = true}
else
- local _304_ = exprs
- _304_["returned"] = true
- return _304_
+ local _325_ = exprs
+ _325_["returned"] = true
+ return _325_
end
end
- local function find_macro(ast, scope, multi_sym_parts)
- local function find_in_table(t, i)
- if (i <= #multi_sym_parts) then
- return find_in_table((utils["table?"](t) and t[multi_sym_parts[i]]), (i + 1))
+ local function find_macro(ast, scope)
+ local macro_2a
+ do
+ local _327_ = utils["sym?"](ast[1])
+ if (_327_ ~= nil) then
+ local _328_ = tostring(_327_)
+ if (_328_ ~= nil) then
+ macro_2a = scope.macros[_328_]
+ else
+ macro_2a = _328_
+ end
else
- return t
+ macro_2a = _327_
end
end
- local macro_2a = (utils["sym?"](ast[1]) and scope.macros[tostring(ast[1])])
+ local multi_sym_parts = utils["multi-sym?"](ast[1])
if (not macro_2a and multi_sym_parts) then
- local nested_macro = find_in_table(scope.macros, 1)
+ local nested_macro = utils["get-in"](scope.macros, multi_sym_parts)
assert_compile((not scope.macros[multi_sym_parts[1]] or (type(nested_macro) == "function")), "macro not found in imported macro module", ast)
return nested_macro
else
return macro_2a
end
end
- local function propagate_trace_info(_308_, _index, node)
- local _arg_309_ = _308_
- local filename = (_arg_309_).filename
- local line = (_arg_309_).line
- local bytestart = (_arg_309_).bytestart
- local byteend = (_arg_309_).byteend
- if (("table" == type(node)) and (filename ~= node.filename)) then
+ local function propagate_trace_info(_332_, _index, node)
+ local _arg_333_ = _332_
+ local filename = _arg_333_["filename"]
+ local line = _arg_333_["line"]
+ local bytestart = _arg_333_["bytestart"]
+ local byteend = _arg_333_["byteend"]
+ do
local src = utils["ast-source"](node)
- src.filename, src.line, src["from-macro?"] = filename, line, true
- src.bytestart, src.byteend = bytestart, byteend
- else
- end
- return ("table" == type(node))
- end
- local function max_n(t)
- local n = 0
- for k in pairs(t) do
- if ("number" == type(k)) then
- n = math.max(k, n)
+ if (("table" == type(node)) and (filename ~= src.filename)) then
+ src.filename, src.line, src["from-macro?"] = filename, line, true
+ src.bytestart, src.byteend = bytestart, byteend
else
end
end
- return n
+ return ("table" == type(node))
end
local function quote_literal_nils(index, node, parent)
if (parent and utils["list?"](parent)) then
- for i = 1, max_n(parent) do
- local _312_ = parent[i]
- if (_312_ == nil) then
+ for i = 1, utils.maxn(parent) do
+ local _335_ = parent[i]
+ if (_335_ == nil) then
parent[i] = utils.sym("nil")
else
end
@@ 2835,58 2835,55 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return index, node, parent
end
local function comp(f, g)
- local function _315_(...)
+ local function _338_(...)
return f(g(...))
end
- return _315_
+ return _338_
end
local function built_in_3f(m)
local found_3f = false
for _, f in pairs(scopes.global.macros) do
- if found_3f then
- break
- else
- end
+ if found_3f then break end
found_3f = (f == m)
end
return found_3f
end
local function macroexpand_2a(ast, scope, _3fonce)
- local _316_ = nil
+ local _339_
if utils["list?"](ast) then
- _316_ = find_macro(ast, scope, utils["multi-sym?"](ast[1]))
+ _339_ = find_macro(ast, scope)
else
- _316_ = nil
+ _339_ = nil
end
- if (_316_ == false) then
+ if (_339_ == false) then
return ast
- elseif (nil ~= _316_) then
- local macro_2a = _316_
+ elseif (nil ~= _339_) then
+ local macro_2a = _339_
local old_scope = scopes.macro
- local _ = nil
+ local _
scopes.macro = scope
_ = nil
local ok, transformed = nil, nil
- local function _318_()
+ local function _341_()
return macro_2a(unpack(ast, 2))
end
- local function _319_()
+ local function _342_()
if built_in_3f(macro_2a) then
return tostring
else
return debug.traceback
end
end
- ok, transformed = xpcall(_318_, _319_())
- local _321_ = nil
+ ok, transformed = xpcall(_341_, _342_())
+ local _344_
do
- local _320_ = ast
- local function _322_(...)
- return propagate_trace_info(_320_, ...)
+ local _343_ = ast
+ local function _345_(...)
+ return propagate_trace_info(_343_, ...)
end
- _321_ = _322_
+ _344_ = _345_
end
- utils["walk-tree"](transformed, comp(_321_, quote_literal_nils))
+ utils["walk-tree"](transformed, comp(_344_, quote_literal_nils))
scopes.macro = old_scope
assert_compile(ok, transformed, ast)
if (_3fonce or not transformed) then
@@ 2895,7 2892,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return macroexpand_2a(transformed, scope)
end
elseif true then
- local _ = _316_
+ local _ = _339_
return ast
else
return nil
@@ 2903,13 2900,13 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
local function compile_special(ast, scope, parent, opts, special)
local exprs = (special(ast, scope, parent, opts) or utils.expr("nil", "literal"))
- local exprs0 = nil
+ local exprs0
if ("table" ~= type(exprs)) then
exprs0 = utils.expr(exprs, "expression")
else
exprs0 = exprs
end
- local exprs2 = nil
+ local exprs2
if utils["expr?"](exprs0) then
exprs2 = {exprs0}
else
@@ 2926,17 2923,17 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
local function compile_function_call(ast, scope, parent, opts, compile1, len)
local fargs = {}
local fcallee = (compile1(ast[1], scope, parent, {nval = 1}))[1]
- assert_compile(((utils["sym?"](ast[1]) or utils["list?"](ast[1])) or ("string" == type(ast[1]))), ("cannot call literal value " .. tostring(ast[1])), ast)
+ assert_compile((utils["sym?"](ast[1]) or utils["list?"](ast[1]) or ("string" == type(ast[1]))), ("cannot call literal value " .. tostring(ast[1])), ast)
for i = 2, len do
- local subexprs = nil
- local _328_ = nil
+ local subexprs
+ local _351_
if (i ~= len) then
- _328_ = 1
+ _351_ = 1
else
- _328_ = nil
+ _351_ = nil
end
- subexprs = compile1(ast[i], scope, parent, {nval = _328_})
- table.insert(fargs, (subexprs[1] or utils.expr("nil", "literal")))
+ subexprs = compile1(ast[i], scope, parent, {nval = _351_})
+ table.insert(fargs, subexprs[1])
if (i == len) then
for j = 2, #subexprs do
table.insert(fargs, subexprs[j])
@@ 2945,7 2942,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
keep_side_effects(subexprs, parent, 2, ast[i])
end
end
- local pat = nil
+ local pat
if ("string" == type(ast[1])) then
pat = "(%s)(%s)"
else
@@ 2973,19 2970,19 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
end
local function compile_varg(ast, scope, parent, opts)
- local _333_ = nil
+ local _356_
if scope.hashfn then
- _333_ = "use $... in hashfn"
+ _356_ = "use $... in hashfn"
else
- _333_ = "unexpected vararg"
+ _356_ = "unexpected vararg"
end
- assert_compile(scope.vararg, _333_, ast)
+ assert_compile(scope.vararg, _356_, ast)
return handle_compile_opts({utils.expr("...", "varg")}, parent, opts, ast)
end
local function compile_sym(ast, scope, parent, opts)
local multi_sym_parts = utils["multi-sym?"](ast)
assert_compile(not (multi_sym_parts and multi_sym_parts["multi-sym-method-call"]), "multisym method calls may only be in call position", ast)
- local e = nil
+ local e
if (ast[1] == "nil") then
e = utils.expr("nil", "literal")
else
@@ 2994,20 2991,20 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return handle_compile_opts({e}, parent, opts, ast)
end
local function serialize_number(n)
- local _336_ = string.gsub(tostring(n), ",", ".")
- return _336_
+ local _359_ = string.gsub(tostring(n), ",", ".")
+ return _359_
end
local function compile_scalar(ast, _scope, parent, opts)
- local serialize = nil
+ local serialize
do
- local _337_ = type(ast)
- if (_337_ == "nil") then
+ local _360_ = type(ast)
+ if (_360_ == "nil") then
serialize = tostring
- elseif (_337_ == "boolean") then
+ elseif (_360_ == "boolean") then
serialize = tostring
- elseif (_337_ == "string") then
+ elseif (_360_ == "string") then
serialize = serialize_string
- elseif (_337_ == "number") then
+ elseif (_360_ == "number") then
serialize = serialize_number
else
serialize = nil
@@ 3016,51 3013,53 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return handle_compile_opts({utils.expr(serialize(ast), "literal")}, parent, opts)
end
local function compile_table(ast, scope, parent, opts, compile1)
- local buffer = {}
- local function write_other_values(k)
- if ((((type(k) ~= "number") or (math.floor(k) ~= k)) or (k < 1)) or (#ast < k)) then
- if ((type(k) == "string") and utils["valid-lua-identifier?"](k)) then
- return {k, k}
- else
- local _let_339_ = compile1(k, scope, parent, {nval = 1})
- local compiled = (_let_339_)[1]
- local kstr = ("[" .. tostring(compiled) .. "]")
- return {kstr, k}
- end
+ local function escape_key(k)
+ if ((type(k) == "string") and utils["valid-lua-identifier?"](k)) then
+ return k
else
- return nil
+ local _let_362_ = compile1(k, scope, parent, {nval = 1})
+ local compiled = _let_362_[1]
+ return ("[" .. tostring(compiled) .. "]")
end
end
+ local keys = {}
+ local buffer
do
- local keys = nil
- do
- local tbl_14_auto = {}
- local i_15_auto = #tbl_14_auto
- for k, v in utils.stablepairs(ast) do
- local val_16_auto = write_other_values(k, v)
- if (nil ~= val_16_auto) then
- i_15_auto = (i_15_auto + 1)
- do
- end
- tbl_14_auto[i_15_auto] = val_16_auto
- else
- end
+ local tbl_16_auto = {}
+ local i_17_auto = #tbl_16_auto
+ for i, elem in ipairs(ast) do
+ local val_18_auto
+ do
+ local nval = ((nil ~= ast[(i + 1)]) and 1)
+ do end (keys)[i] = true
+ val_18_auto = exprs1(compile1(elem, scope, parent, {nval = nval}))
+ end
+ if (nil ~= val_18_auto) then
+ i_17_auto = (i_17_auto + 1)
+ do end (tbl_16_auto)[i_17_auto] = val_18_auto
+ else
end
- keys = tbl_14_auto
- end
- local function _345_(_343_)
- local _arg_344_ = _343_
- local k1 = (_arg_344_)[1]
- local k2 = (_arg_344_)[2]
- local _let_346_ = compile1(ast[k2], scope, parent, {nval = 1})
- local v = (_let_346_)[1]
- return string.format("%s = %s", k1, tostring(v))
end
- utils.map(keys, _345_, buffer)
+ buffer = tbl_16_auto
end
- for i = 1, #ast do
- local nval = ((i ~= #ast) and 1)
- table.insert(buffer, exprs1(compile1(ast[i], scope, parent, {nval = nval})))
+ do
+ local tbl_16_auto = buffer
+ local i_17_auto = #tbl_16_auto
+ for k, v in utils.stablepairs(ast) do
+ local val_18_auto
+ if not keys[k] then
+ local _let_365_ = compile1(ast[k], scope, parent, {nval = 1})
+ local v0 = _let_365_[1]
+ val_18_auto = string.format("%s = %s", escape_key(k), tostring(v0))
+ else
+ val_18_auto = nil
+ end
+ if (nil ~= val_18_auto) then
+ i_17_auto = (i_17_auto + 1)
+ do end (tbl_16_auto)[i_17_auto] = val_18_auto
+ else
+ end
+ end
end
return handle_compile_opts({utils.expr(("{" .. table.concat(buffer, ", ") .. "}"), "expression")}, parent, opts, ast)
end
@@ 3075,7 3074,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return compile_sym(ast0, scope, parent, opts)
elseif (type(ast0) == "table") then
return compile_table(ast0, scope, parent, opts, compile1)
- elseif ((((type(ast0) == "nil") or (type(ast0) == "boolean")) or (type(ast0) == "number")) or (type(ast0) == "string")) then
+ elseif ((type(ast0) == "nil") or (type(ast0) == "boolean") or (type(ast0) == "number") or (type(ast0) == "string")) then
return compile_scalar(ast0, scope, parent, opts)
else
return assert_compile(false, ("could not compile value of type " .. type(ast0)), ast0)
@@ 3083,14 3082,14 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
local function destructure(to, from, ast, scope, parent, opts)
local opts0 = (opts or {})
- local _let_348_ = opts0
- local isvar = (_let_348_).isvar
- local declaration = (_let_348_).declaration
- local forceglobal = (_let_348_).forceglobal
- local forceset = (_let_348_).forceset
- local symtype = (_let_348_).symtype
+ local _let_369_ = opts0
+ local isvar = _let_369_["isvar"]
+ local declaration = _let_369_["declaration"]
+ local forceglobal = _let_369_["forceglobal"]
+ local forceset = _let_369_["forceset"]
+ local symtype = _let_369_["symtype"]
local symtype0 = ("_" .. (symtype or "dst"))
- local setter = nil
+ local setter
if declaration then
setter = "local %s = %s"
else
@@ 3109,17 3108,13 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
if ((#parts == 1) and not forceset) then
assert_compile(not (forceglobal and meta), string.format("global %s conflicts with local", tostring(symbol)), symbol)
assert_compile(not (meta and not meta.var), ("expected var " .. raw), symbol)
- assert_compile((meta or not opts0.noundef), ("expected local " .. parts[1]), symbol)
else
end
+ assert_compile((meta or not opts0.noundef or global_allowed_3f(parts[1])), ("expected local " .. parts[1]), symbol)
if forceglobal then
assert_compile(not scope.symmeta[scope.unmanglings[raw]], ("global " .. raw .. " conflicts with local"), symbol)
- do
- end
- scope.manglings[raw] = global_mangling(raw)
- do
- end
- scope.unmanglings[global_mangling(raw)] = raw
+ do end (scope.manglings)[raw] = global_mangling(raw)
+ do end (scope.unmanglings)[global_mangling(raw)] = raw
if allowed_globals then
table.insert(allowed_globals, raw)
else
@@ 3130,15 3125,15 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
end
local function compile_top_target(lvalues)
- local inits = nil
- local function _354_(_241)
+ local inits
+ local function _375_(_241)
if scope.manglings[_241] then
return _241
else
return "nil"
end
end
- inits = utils.map(lvalues, _354_)
+ inits = utils.map(lvalues, _375_)
local init = table.concat(inits, ", ")
local lvalue = table.concat(lvalues, ", ")
local plast = parent[#parent]
@@ 3179,24 3174,22 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
local unpack_fn = "function (t, k, e)\n local mt = getmetatable(t)\n if 'table' == type(mt) and mt.__fennelrest then\n return mt.__fennelrest(t, k)\n elseif e then\n local rest = {}\n for k, v in pairs(t) do\n if not e[k] then rest[k] = v end\n end\n return rest\n else\n return {(table.unpack or unpack)(t, k)}\n end\n end"
local function destructure_kv_rest(s, v, left, excluded_keys, destructure1)
- local exclude_str = nil
- local _361_ = nil
+ local exclude_str
+ local _382_
do
- local tbl_14_auto = {}
- local i_15_auto = #tbl_14_auto
+ local tbl_16_auto = {}
+ local i_17_auto = #tbl_16_auto
for _, k in ipairs(excluded_keys) do
- local val_16_auto = string.format("[%s] = true", serialize_string(k))
- if (nil ~= val_16_auto) then
- i_15_auto = (i_15_auto + 1)
- do
- end
- tbl_14_auto[i_15_auto] = val_16_auto
+ local val_18_auto = string.format("[%s] = true", serialize_string(k))
+ if (nil ~= val_18_auto) then
+ i_17_auto = (i_17_auto + 1)
+ do end (tbl_16_auto)[i_17_auto] = val_18_auto
else
end
end
- _361_ = tbl_14_auto
+ _382_ = tbl_16_auto
end
- exclude_str = table.concat(_361_, ", ")
+ exclude_str = table.concat(_382_, ", ")
local subexpr = utils.expr(string.format(string.gsub(("(" .. unpack_fn .. ")(%s, %s, {%s})"), "\n%s*", " "), s, tostring(v), exclude_str), "expression")
return destructure1(v, {subexpr}, left)
end
@@ 3209,18 3202,18 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
local function destructure_table(left, rightexprs, top_3f, destructure1)
local s = gensym(scope, symtype0)
- local right = nil
+ local right
do
- local _363_ = nil
+ local _384_
if top_3f then
- _363_ = exprs1(compile1(from, scope, parent))
+ _384_ = exprs1(compile1(from, scope, parent))
else
- _363_ = exprs1(rightexprs)
+ _384_ = exprs1(rightexprs)
end
- if (_363_ == "") then
+ if (_384_ == "") then
right = "nil"
- elseif (nil ~= _363_) then
- local right0 = _363_
+ elseif (nil ~= _384_) then
+ local right0 = _384_
right = right0
else
right = nil
@@ 3241,7 3234,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
assert_compile((nil == trailing), "expected &as argument before last parameter", left)
destructure_sym(next_sym, {utils.expr(tostring(s))}, left)
else
- local key = nil
+ local key
if (type(k) == "string") then
key = serialize_string(k)
else
@@ 3267,9 3260,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
else
local symname = gensym(scope, symtype0)
table.insert(left_names, symname)
- do
- end
- tables[i] = {name, utils.expr(symname, "sym")}
+ do end (tables)[i] = {name, utils.expr(symname, "sym")}
end
end
assert_compile(left[1], "must provide at least one value", left)
@@ 3311,14 3302,13 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return ret
end
local function require_include(ast, scope, parent, opts)
- local function _281_(e, no_warn)
+ opts.fallback = function(e, no_warn)
if (not no_warn and ("literal" == e.type)) then
utils.warn(("include module not found, falling back to require: %s"):format(tostring(e)))
else
end
return utils.expr(string.format("require(%s)", tostring(e)), "statement")
end
- opts.fallback = _281_
return scopes.global.specials.include(ast, scope, parent, opts)
end
local function compile_stream(strm, options)
@@ 3327,12 3317,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
local scope = (opts.scope or make_scope(scopes.global))
local vals = {}
local chunk = {}
- do
- end
- local function _283_(tgt, m, ...)
- return tgt[m](tgt, ...)
- end
- _283_(utils.root, "set-reset")
+ do end (function(tgt, m, ...) return tgt[m](tgt, ...) end)(utils.root, "set-reset")
allowed_globals = opts.allowedGlobals
if (opts.indent == nil) then
opts.indent = " "
@@ 3358,20 3343,16 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
utils.root.reset()
return flatten(chunk, opts)
end
- local function compile_string(str, opts)
- return compile_stream(parser["string-stream"](str), (opts or {}))
+ local function compile_string(str, _3fopts)
+ local opts = (_3fopts or {})
+ return compile_stream(parser["string-stream"](str, opts), opts)
end
local function compile(ast, opts)
local opts0 = utils.copy(opts)
local old_globals = allowed_globals
local chunk = {}
local scope = (opts0.scope or make_scope(scopes.global))
- do
- end
- local function _287_(tgt, m, ...)
- return tgt[m](tgt, ...)
- end
- _287_(utils.root, "set-reset")
+ do end (function(tgt, m, ...) return tgt[m](tgt, ...) end)(utils.root, "set-reset")
allowed_globals = opts0.allowedGlobals
if (opts0.indent == nil) then
opts0.indent = " "
@@ 3398,22 3379,22 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
local remap = sourcemap[info.source]
if (remap and remap[info.currentline]) then
if ((remap[info.currentline][1] or "unknown") ~= "unknown") then
- info.short_src = (sourcemap[("@" .. remap[info.currentline][1])]).short_src
+ info.short_src = sourcemap[("@" .. remap[info.currentline][1])].short_src
else
info.short_src = remap.short_src
end
- info.currentline = (remap[info.currentline][2] or ( - 1))
+ info.currentline = (remap[info.currentline][2] or -1)
else
end
if (info.what == "Lua") then
- local function _383_()
+ local function _404_()
if info.name then
return ("'" .. info.name .. "'")
else
return "?"
end
end
- return string.format(" %s:%d: in function %s", info.short_src, info.currentline, _383_())
+ return string.format(" %s:%d: in function %s", info.short_src, info.currentline, _404_())
elseif (info.short_src == "(tail call)") then
return " (tail call)"
else
@@ 3423,11 3404,11 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
local function traceback(_3fmsg, _3fstart)
local msg = tostring((_3fmsg or ""))
- if ((msg:find("^Compile error") or msg:find("^Parse error")) and not utils["debug-on?"]("trace")) then
+ if ((msg:find("^%g+:%d+:%d+ Compile error:.*") or msg:find("^%g+:%d+:%d+ Parse error:.*")) and not utils["debug-on?"]("trace")) then
return msg
else
local lines = {}
- if (msg:find(":%d+: Compile error") or msg:find(":%d+: Parse error")) then
+ if (msg:find("^%g+:%d+:%d+ Compile error:") or msg:find("^%g+:%d+:%d+ Parse error:")) then
table.insert(lines, msg)
else
local newmsg = msg:gsub("^[^:]*:%d+:%s+", "runtime error: ")
@@ 3437,11 3418,11 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
local done_3f, level = false, (_3fstart or 2)
while not done_3f do
do
- local _387_ = debug.getinfo(level, "Sln")
- if (_387_ == nil) then
+ local _408_ = debug.getinfo(level, "Sln")
+ if (_408_ == nil) then
done_3f = true
- elseif (nil ~= _387_) then
- local info = _387_
+ elseif (nil ~= _408_) then
+ local info = _408_
table.insert(lines, traceback_frame(info))
else
end
@@ 3452,14 3433,14 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
end
local function entry_transform(fk, fv)
- local function _390_(k, v)
+ local function _411_(k, v)
if (type(k) == "number") then
return k, fv(v)
else
return fk(k), fv(v)
end
end
- return _390_
+ return _411_
end
local function mixed_concat(t, joiner)
local seen = {}
@@ 3486,7 3467,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
assert_compile(not runtime_3f, "quoted ... may only be used at compile time", form)
return "_VARARG"
elseif utils["sym?"](form) then
- local filename = nil
+ local filename
if form.filename then
filename = string.format("%q", form.filename)
else
@@ 3499,17 3480,17 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
else
return string.format("sym('%s', {quoted=true, filename=%s, line=%s})", symstr, filename, (form.line or "nil"))
end
- elseif ((utils["list?"](form) and utils["sym?"](form[1])) and (tostring(form[1]) == "unquote")) then
+ elseif (utils["list?"](form) and utils["sym?"](form[1]) and (tostring(form[1]) == "unquote")) then
local payload = form[2]
local res = unpack(compile1(payload, scope, parent))
return res[1]
elseif utils["list?"](form) then
- local mapped = nil
- local function _395_()
+ local mapped
+ local function _416_()
return nil
end
- mapped = utils.kvmap(form, entry_transform(_395_, q))
- local filename = nil
+ mapped = utils.kvmap(form, entry_transform(_416_, q))
+ local filename
if form.filename then
filename = string.format("%q", form.filename)
else
@@ 3520,68 3501,71 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
elseif utils["sequence?"](form) then
local mapped = utils.kvmap(form, entry_transform(q, q))
local source = getmetatable(form)
- local filename = nil
+ local filename
if source.filename then
filename = string.format("%q", source.filename)
else
filename = "nil"
end
- local _398_ = nil
+ local _419_
if source then
- _398_ = source.line
+ _419_ = source.line
else
- _398_ = "nil"
+ _419_ = "nil"
end
- return string.format("setmetatable({%s}, {filename=%s, line=%s, sequence=%s})", mixed_concat(mapped, ", "), filename, _398_, "(getmetatable(sequence()))['sequence']")
+ return string.format("setmetatable({%s}, {filename=%s, line=%s, sequence=%s})", mixed_concat(mapped, ", "), filename, _419_, "(getmetatable(sequence()))['sequence']")
elseif (type(form) == "table") then
local mapped = utils.kvmap(form, entry_transform(q, q))
local source = getmetatable(form)
- local filename = nil
+ local filename
if source.filename then
filename = string.format("%q", source.filename)
else
filename = "nil"
end
- local function _401_()
+ local function _422_()
if source then
return source.line
else
return "nil"
end
end
- return string.format("setmetatable({%s}, {filename=%s, line=%s})", mixed_concat(mapped, ", "), filename, _401_())
+ return string.format("setmetatable({%s}, {filename=%s, line=%s})", mixed_concat(mapped, ", "), filename, _422_())
elseif (type(form) == "string") then
return serialize_string(form)
else
return tostring(form)
end
end
- return {["keep-side-effects"] = keep_side_effects, assert = assert_compile, ["compile-string"] = compile_string, scopes = scopes, compile1 = compile1, gensym = gensym, ["declare-local"] = declare_local, compile = compile, destructure = destructure, autogensym = autogensym, macroexpand = macroexpand_2a, emit = emit, ["compile-stream"] = compile_stream, sourcemap = sourcemap, metadata = make_metadata(), traceback = traceback, ["global-unmangling"] = global_unmangling, ["global-mangling"] = global_mangling, ["check-binding-valid"] = check_binding_valid, ["make-scope"] = make_scope, ["require-include"] = require_include, ["symbol-to-expression"] = symbol_to_expression, ["do-quote"] = do_quote, ["apply-manglings"] = apply_manglings}
+ return {compile = compile, compile1 = compile1, ["compile-stream"] = compile_stream, ["compile-string"] = compile_string, ["check-binding-valid"] = check_binding_valid, emit = emit, destructure = destructure, ["require-include"] = require_include, autogensym = autogensym, gensym = gensym, ["do-quote"] = do_quote, ["global-mangling"] = global_mangling, ["global-unmangling"] = global_unmangling, ["apply-manglings"] = apply_manglings, macroexpand = macroexpand_2a, ["declare-local"] = declare_local, ["make-scope"] = make_scope, ["keep-side-effects"] = keep_side_effects, ["symbol-to-expression"] = symbol_to_expression, assert = assert_compile, scopes = scopes, traceback = traceback, metadata = make_metadata(), sourcemap = sourcemap}
end
- package.preload["fennel.compiler"] = (package.preload["fennel.compiler"] or _190_)
- local function _308_(...)
+ package.preload["fennel.friend"] = package.preload["fennel.friend"] or function(...)
local utils = require("fennel.utils")
local utf8_ok_3f, utf8 = pcall(require, "utf8")
- local suggestions = {["expected even number of name/value bindings"] = {"finding where the identifier or value is missing"}, ["can't start multisym segment with a digit"] = {"removing the digit", "adding a non-digit before the digit"}, ["tried to reference a special form at runtime"] = {"wrapping the special in a function if you need it to be first class"}, ["expected vararg as last parameter"] = {"moving the \"...\" to the end of the parameter list"}, ["expected whitespace before opening delimiter"] = {"adding whitespace"}, ["expected body expression"] = {"putting some code in the body of this form after the bindings"}, ["unable to bind (.*)"] = {"replacing the %s with an identifier"}, ["could not compile value of type "] = {"debugging the macro you're calling to return a list or table"}, ["use of global (.*) is aliased by a local"] = {"renaming local %s", "refer to the global using _G.%s instead of directly"}, ["expected parameters"] = {"adding function parameters as a list of identifiers in brackets"}, ["expected var (.*)"] = {"declaring %s using var instead of let/local", "introducing a new local instead of changing the value of %s"}, ["expected binding sequence"] = {"placing a table here in square brackets containing identifiers to bind"}, ["expected even number of values in table literal"] = {"removing a key", "adding a value"}, ["local (.*) was overshadowed by a special form or macro"] = {"renaming local %s"}, ["tried to reference a macro at runtime"] = {"renaming the macro so as not to conflict with locals"}, ["unexpected arguments"] = {"removing an argument", "checking for typos"}, ["expected binding and iterator"] = {"making sure you haven't omitted a local name or iterator"}, ["expected even number of pattern/body pairs"] = {"checking that every pattern has a body to go with it", "adding _ before the final body"}, ["unexpected iterator clause"] = {"removing an argument", "checking for typos"}, ["$ and $... in hashfn are mutually exclusive"] = {"modifying the hashfn so it only contains $... or $, $1, $2, $3, etc"}, ["method must be last component"] = {"using a period instead of a colon for field access", "removing segments after the colon", "making the method call, then looking up the field on the result"}, ["malformed multisym"] = {"ensuring each period or colon is not followed by another period or colon"}, ["expected macros to be table"] = {"ensuring your macro definitions return a table"}, ["could not read number (.*)"] = {"removing the non-digit character", "beginning the identifier with a non-digit if it is not meant to be a number"}, ["unknown identifier in strict mode: (.*)"] = {"looking to see if there's a typo", "using the _G table instead, eg. _G.%s if you really want a global", "moving this code to somewhere that %s is in scope", "binding %s as a local in the scope of this code"}, ["multisym method calls may only be in call position"] = {"using a period instead of a colon to reference a table's fields", "putting parens around this"}, ["cannot call literal value"] = {"checking for typos", "checking for a missing function name"}, ["unused local (.*)"] = {"renaming the local to _%s if it is meant to be unused", "fixing a typo so %s is used", "disabling the linter which checks for unused locals"}, ["macro tried to bind (.*) without gensym"] = {"changing to %s# when introducing identifiers inside macros"}, ["mismatched closing delimiter (.), expected (.)"] = {"replacing %s with %s", "deleting %s", "adding matching opening delimiter earlier"}, ["invalid character: (.)"] = {"deleting or replacing %s", "avoiding reserved characters like \", \\, ', ~, ;, @, `, and comma"}, ["global (.*) conflicts with local"] = {"renaming local %s"}, ["expected a function.* to call"] = {"removing the empty parentheses", "using square brackets if you want an empty table"}, ["expected each macro to be function"] = {"ensuring that the value for each key in your macros table contains a function", "avoid defining nested macro tables"}, ["unexpected multi symbol (.*)"] = {"removing periods or colons from %s"}, ["macro not found in macro module"] = {"checking the keys of the imported macro module's returned table"}, ["expected local"] = {"looking for a typo", "looking for a local which is used out of its scope"}, ["may only be used at compile time"] = {"moving this to inside a macro if you need to manipulate symbols/lists", "using square brackets instead of parens to construct a table"}, ["expected rest argument before last parameter"] = {"moving & to right before the final identifier when destructuring"}, ["unexpected vararg"] = {"putting \"...\" at the end of the fn parameters if the vararg was intended"}, ["expected symbol for function parameter: (.*)"] = {"changing %s to an identifier instead of a literal value"}, ["unexpected closing delimiter (.)"] = {"deleting %s", "adding matching opening delimiter earlier"}}
+ local suggestions = {["unexpected multi symbol (.*)"] = {"removing periods or colons from %s"}, ["use of global (.*) is aliased by a local"] = {"renaming local %s", "refer to the global using _G.%s instead of directly"}, ["local (.*) was overshadowed by a special form or macro"] = {"renaming local %s"}, ["global (.*) conflicts with local"] = {"renaming local %s"}, ["expected var (.*)"] = {"declaring %s using var instead of let/local", "introducing a new local instead of changing the value of %s"}, ["expected macros to be table"] = {"ensuring your macro definitions return a table"}, ["expected each macro to be function"] = {"ensuring that the value for each key in your macros table contains a function", "avoid defining nested macro tables"}, ["macro not found in macro module"] = {"checking the keys of the imported macro module's returned table"}, ["macro tried to bind (.*) without gensym"] = {"changing to %s# when introducing identifiers inside macros"}, ["unknown identifier: (.*)"] = {"looking to see if there's a typo", "using the _G table instead, eg. _G.%s if you really want a global", "moving this code to somewhere that %s is in scope", "binding %s as a local in the scope of this code"}, ["expected a function.* to call"] = {"removing the empty parentheses", "using square brackets if you want an empty table"}, ["cannot call literal value"] = {"checking for typos", "checking for a missing function name", "making sure to use prefix operators, not infix"}, ["unexpected vararg"] = {"putting \"...\" at the end of the fn parameters if the vararg was intended"}, ["multisym method calls may only be in call position"] = {"using a period instead of a colon to reference a table's fields", "putting parens around this"}, ["unused local (.*)"] = {"renaming the local to _%s if it is meant to be unused", "fixing a typo so %s is used", "disabling the linter which checks for unused locals"}, ["expected parameters"] = {"adding function parameters as a list of identifiers in brackets"}, ["unable to bind (.*)"] = {"replacing the %s with an identifier"}, ["expected rest argument before last parameter"] = {"moving & to right before the final identifier when destructuring"}, ["expected vararg as last parameter"] = {"moving the \"...\" to the end of the parameter list"}, ["expected symbol for function parameter: (.*)"] = {"changing %s to an identifier instead of a literal value"}, ["could not compile value of type "] = {"debugging the macro you're calling to return a list or table"}, ["expected local"] = {"looking for a typo", "looking for a local which is used out of its scope"}, ["expected body expression"] = {"putting some code in the body of this form after the bindings"}, ["expected binding and iterator"] = {"making sure you haven't omitted a local name or iterator"}, ["expected binding sequence"] = {"placing a table here in square brackets containing identifiers to bind"}, ["expected even number of name/value bindings"] = {"finding where the identifier or value is missing"}, ["may only be used at compile time"] = {"moving this to inside a macro if you need to manipulate symbols/lists", "using square brackets instead of parens to construct a table"}, ["unexpected closing delimiter (.)"] = {"deleting %s", "adding matching opening delimiter earlier"}, ["mismatched closing delimiter (.), expected (.)"] = {"replacing %s with %s", "deleting %s", "adding matching opening delimiter earlier"}, ["expected even number of values in table literal"] = {"removing a key", "adding a value"}, ["expected whitespace before opening delimiter"] = {"adding whitespace"}, ["invalid character: (.)"] = {"deleting or replacing %s", "avoiding reserved characters like \", \\, ', ~, ;, @, `, and comma"}, ["could not read number (.*)"] = {"removing the non-digit character", "beginning the identifier with a non-digit if it is not meant to be a number"}, ["can't start multisym segment with a digit"] = {"removing the digit", "adding a non-digit before the digit"}, ["malformed multisym"] = {"ensuring each period or colon is not followed by another period or colon"}, ["method must be last component"] = {"using a period instead of a colon for field access", "removing segments after the colon", "making the method call, then looking up the field on the result"}, ["$ and $... in hashfn are mutually exclusive"] = {"modifying the hashfn so it only contains $... or $, $1, $2, $3, etc"}, ["tried to reference a macro without calling it"] = {"renaming the macro so as not to conflict with locals"}, ["tried to reference a special form without calling it"] = {"making sure to use prefix operators, not infix", "wrapping the special in a function if you need it to be first class"}, ["missing subject"] = {"adding an item to operate on"}, ["expected even number of pattern/body pairs"] = {"checking that every pattern has a body to go with it", "adding _ before the final body"}, ["expected at least one pattern/body pair"] = {"adding a pattern and a body to execute when the pattern matches"}, ["unexpected arguments"] = {"removing an argument", "checking for typos"}, ["unexpected iterator clause"] = {"removing an argument", "checking for typos"}}
local unpack = (table.unpack or _G.unpack)
local function suggest(msg)
- local suggestion = nil
+ local s = nil
for pat, sug in pairs(suggestions) do
+ if s then break end
local matches = {msg:match(pat)}
if (0 < #matches) then
- if ("table" == type(sug)) then
- local out = {}
- for _, s in ipairs(sug) do
- table.insert(out, s:format(unpack(matches)))
+ local tbl_16_auto = {}
+ local i_17_auto = #tbl_16_auto
+ for _, s0 in ipairs(sug) do
+ local val_18_auto = s0:format(unpack(matches))
+ if (nil ~= val_18_auto) then
+ i_17_auto = (i_17_auto + 1)
+ do end (tbl_16_auto)[i_17_auto] = val_18_auto
+ else
end
- suggestion = out
- else
- suggestion = sug(matches)
end
+ s = tbl_16_auto
else
+ s = nil
end
end
- return suggestion
+ return s
end
local function read_line(filename, line, _3fsource)
if _3fsource then
@@ 3600,17 3584,17 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return error(..., 0)
end
end
- local function _173_()
+ local function _185_()
for _ = 2, line do
f:read()
end
return f:read()
end
- return close_handlers_8_auto(_G.xpcall(_173_, (package.loaded.fennel or debug).traceback))
+ return close_handlers_8_auto(_G.xpcall(_185_, (package.loaded.fennel or debug).traceback))
end
end
local function sub(str, start, _end)
- if (_end < start) then
+ if ((_end < start) or (#str < start) or (#str < _end)) then
return ""
elseif utf8_ok_3f then
return string.sub(str, utf8.offset(str, start), ((utf8.offset(str, (_end + 1)) or (utf8.len(str) + 1)) - 1))
@@ 3618,27 3602,36 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return string.sub(str, start, math.min(_end, str:len()))
end
end
- local function highlight_line(codeline, col, _3fendcol)
- local endcol = (_3fendcol or col)
- local eol = nil
- if utf8_ok_3f then
- eol = utf8.len(codeline)
+ local function highlight_line(codeline, col, _3fendcol, opts)
+ if ((opts and (false == opts["error-pinpoint"])) or (os and os.getenv and os.getenv("NO_COLOR"))) then
+ return codeline
else
- eol = string.len(codeline)
+ local _let_188_ = (opts or {})
+ local error_pinpoint = _let_188_["error-pinpoint"]
+ local endcol = (_3fendcol or col)
+ local eol
+ if utf8_ok_3f then
+ eol = utf8.len(codeline)
+ else
+ eol = string.len(codeline)
+ end
+ local _let_190_ = (error_pinpoint or {"\27[7m", "\27[0m"})
+ local open = _let_190_[1]
+ local close = _let_190_[2]
+ return (sub(codeline, 1, col) .. open .. sub(codeline, (col + 1), (endcol + 1)) .. close .. sub(codeline, (endcol + 2), eol))
end
- return (sub(codeline, 1, col) .. "\27[7m" .. sub(codeline, (col + 1), (endcol + 1)) .. "\27[0m" .. sub(codeline, (endcol + 2), eol))
end
- local function friendly_msg(msg, _177_, source)
- local _arg_178_ = _177_
- local filename = (_arg_178_).filename
- local line = (_arg_178_).line
- local col = (_arg_178_).col
- local endcol = (_arg_178_).endcol
+ local function friendly_msg(msg, _192_, source, opts)
+ local _arg_193_ = _192_
+ local filename = _arg_193_["filename"]
+ local line = _arg_193_["line"]
+ local col = _arg_193_["col"]
+ local endcol = _arg_193_["endcol"]
local ok, codeline = pcall(read_line, filename, line, source)
local out = {msg, ""}
if (ok and codeline) then
if col then
- table.insert(out, highlight_line(codeline, col, endcol))
+ table.insert(out, highlight_line(codeline, col, endcol, opts))
else
table.insert(out, codeline)
end
@@ 3649,48 3642,47 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
return table.concat(out, "\n")
end
- local function assert_compile(condition, msg, ast, source)
+ local function assert_compile(condition, msg, ast, source, opts)
if not condition then
- local _let_181_ = utils["ast-source"](ast)
- local filename = (_let_181_).filename
- local line = (_let_181_).line
- local col = (_let_181_).col
- error(friendly_msg(("Compile error in %s:%s:%s\n %s"):format((filename or "unknown"), (line or "?"), (col or "?"), msg), utils["ast-source"](ast), source), 0)
+ local _let_196_ = utils["ast-source"](ast)
+ local filename = _let_196_["filename"]
+ local line = _let_196_["line"]
+ local col = _let_196_["col"]
+ error(friendly_msg(("%s:%s:%s Compile error: %s"):format((filename or "unknown"), (line or "?"), (col or "?"), msg), utils["ast-source"](ast), source, opts), 0)
else
end
return condition
end
- local function parse_error(msg, filename, line, col, source)
- return error(friendly_msg(("Parse error in %s:%s:%s\n %s"):format(filename, line, col, msg), {filename = filename, line = line, col = col}, source), 0)
+ local function parse_error(msg, filename, line, col, source, opts)
+ return error(friendly_msg(("%s:%s:%s Parse error: %s"):format(filename, line, col, msg), {filename = filename, line = line, col = col}, source, opts), 0)
end
return {["assert-compile"] = assert_compile, ["parse-error"] = parse_error}
end
- package.preload["fennel.friend"] = (package.preload["fennel.friend"] or _308_)
- local function _318_(...)
+ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function(...)
local utils = require("fennel.utils")
local friend = require("fennel.friend")
local unpack = (table.unpack or _G.unpack)
local function granulate(getchunk)
local c, index, done_3f = "", 1, false
- local function _183_(parser_state)
+ local function _198_(parser_state)
if not done_3f then
if (index <= #c) then
local b = c:byte(index)
index = (index + 1)
return b
else
- local _184_ = getchunk(parser_state)
- local function _185_()
- local char = _184_
+ local _199_ = getchunk(parser_state)
+ local function _200_()
+ local char = _199_
return (char ~= "")
end
- if ((nil ~= _184_) and _185_()) then
- local char = _184_
+ if ((nil ~= _199_) and _200_()) then
+ local char = _199_
c = char
index = 2
return c:byte()
elseif true then
- local _ = _184_
+ local _ = _199_
done_3f = true
return nil
else
@@ 3701,54 3693,46 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return nil
end
end
- local function _189_()
+ local function _204_()
c = ""
return nil
end
- return _183_, _189_
+ return _198_, _204_
end
- local function string_stream(str)
+ local function string_stream(str, _3foptions)
local str0 = str:gsub("^#!", ";;")
+ if _3foptions then
+ _3foptions.source = str0
+ else
+ end
local index = 1
- local function _190_()
+ local function _206_()
local r = str0:byte(index)
index = (index + 1)
return r
end
- return _190_
- end
- local delims = {[125] = true, [123] = 125, [91] = 93, [41] = true, [40] = 41, [93] = true}
- local function whitespace_3f(b)
- local function _322_(_191_, _192_, _193_)
- return ((_191_ <= _192_) and (_192_ <= _193_))
- end
- return ((b == 32) or _322_(9, b, 13))
+ return _206_
end
+ local delims = {[40] = 41, [41] = true, [91] = 93, [93] = true, [123] = 125, [125] = true}
local function sym_char_3f(b)
- local b0 = nil
+ local b0
if ("number" == type(b)) then
b0 = b
else
b0 = string.byte(b)
end
- return ((((((((((32 < b0) and not delims[b0]) and (b0 ~= 127)) and (b0 ~= 34)) and (b0 ~= 39)) and (b0 ~= 126)) and (b0 ~= 59)) and (b0 ~= 44)) and (b0 ~= 64)) and (b0 ~= 96))
+ return ((32 < b0) and not delims[b0] and (b0 ~= 127) and (b0 ~= 34) and (b0 ~= 39) and (b0 ~= 126) and (b0 ~= 59) and (b0 ~= 44) and (b0 ~= 64) and (b0 ~= 96))
end
- local prefixes = {[35] = "hashfn", [96] = "quote", [44] = "unquote", [39] = "quote"}
+ local prefixes = {[35] = "hashfn", [39] = "quote", [44] = "unquote", [96] = "quote"}
local function char_starter_3f(b)
- local function _324_(_195_, _196_, _197_)
- return ((_195_ < _196_) and (_196_ < _197_))
- end
- local function _325_(_198_, _199_, _200_)
- return ((_198_ < _199_) and (_199_ < _200_))
- end
- return (_324_(1, b, 127) or _325_(192, b, 247))
- end
- local function parser_fn(getbyte, filename, _201_)
- local _arg_202_ = _201_
- local source = (_arg_202_).source
- local unfriendly = (_arg_202_).unfriendly
- local comments = (_arg_202_).comments
- local options = _arg_202_
+ return ((function(_208_,_209_,_210_) return (_208_ < _209_) and (_209_ < _210_) end)(1,b,127) or (function(_211_,_212_,_213_) return (_211_ < _212_) and (_212_ < _213_) end)(192,b,247))
+ end
+ local function parser_fn(getbyte, filename, _214_)
+ local _arg_215_ = _214_
+ local source = _arg_215_["source"]
+ local unfriendly = _arg_215_["unfriendly"]
+ local comments = _arg_215_["comments"]
+ local options = _arg_215_
local stack = {}
local line, byteindex, col, prev_col, lastb = 1, 0, 0, 0, nil
local function ungetb(ub)
@@ 3782,14 3766,25 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
return r
end
+ local function whitespace_3f(b)
+ local function _225_()
+ local t_224_ = options.whitespace
+ if (nil ~= t_224_) then
+ t_224_ = (t_224_)[b]
+ else
+ end
+ return t_224_
+ end
+ return ((b == 32) or (function(_221_,_222_,_223_) return (_221_ <= _222_) and (_222_ <= _223_) end)(9,b,13) or _225_())
+ end
local function parse_error(msg, _3fcol_adjust)
- local col0 = (col + (_3fcol_adjust or ( - 1)))
+ local col0 = (col + (_3fcol_adjust or -1))
if (nil == utils["hook-opts"]("parse-error", options, msg, filename, (line or "?"), col0, source, utils.root.reset)) then
utils.root.reset()
- if ((unfriendly or not _G.io) or not _G.io.read) then
+ if (unfriendly or not _G.io or not _G.io.read) then
return error(string.format("%s:%s:%s Parse error: %s", filename, (line or "?"), col0, msg), 0)
else
- return friend["parse-error"](msg, filename, (line or "?"), col0, source)
+ return friend["parse-error"](msg, filename, (line or "?"), col0, source, options)
end
else
return nil
@@ 3802,25 3797,25 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return nil
end
local function dispatch(v)
- local _210_ = stack[#stack]
- if (_210_ == nil) then
+ local _229_ = stack[#stack]
+ if (_229_ == nil) then
retval, done_3f, whitespace_since_dispatch = v, true, false
return nil
- elseif ((_G.type(_210_) == "table") and (nil ~= _210_.prefix)) then
- local prefix = _210_.prefix
- local source0 = nil
+ elseif ((_G.type(_229_) == "table") and (nil ~= (_229_).prefix)) then
+ local prefix = (_229_).prefix
+ local source0
do
- local _211_ = table.remove(stack)
- set_source_fields(_211_)
- source0 = _211_
+ local _230_ = table.remove(stack)
+ set_source_fields(_230_)
+ source0 = _230_
end
local list = utils.list(utils.sym(prefix, source0), v)
for k, v0 in pairs(source0) do
list[k] = v0
end
return dispatch(list)
- elseif (nil ~= _210_) then
- local top = _210_
+ elseif (nil ~= _229_) then
+ local top = _229_
whitespace_since_dispatch = false
return table.insert(top, v)
else
@@ 3829,13 3824,13 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
local function badend()
local accum = utils.map(stack, "closer")
- local _213_ = nil
+ local _232_
if (#stack == 1) then
- _213_ = ""
+ _232_ = ""
else
- _213_ = "s"
+ _232_ = "s"
end
- return parse_error(string.format("expected closing delimiter%s %s", _213_, string.char(unpack(accum))))
+ return parse_error(string.format("expected closing delimiter%s %s", _232_, string.char(unpack(accum))))
end
local function skip_whitespace(b)
if (b and whitespace_3f(b)) then
@@ 3849,16 3844,17 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
local function parse_comment(b, contents)
if (b and (10 ~= b)) then
- local function _217_()
- local _216_ = contents
- table.insert(_216_, string.char(b))
- return _216_
+ local function _236_()
+ local _235_ = contents
+ table.insert(_235_, string.char(b))
+ return _235_
end
- return parse_comment(getb(), _217_())
+ return parse_comment(getb(), _236_())
elseif comments then
- return dispatch(utils.comment(table.concat(contents), {line = (line - 1), filename = filename}))
+ ungetb(10)
+ return dispatch(utils.comment(table.concat(contents), {line = line, filename = filename}))
else
- return b
+ return nil
end
end
local function open_table(b)
@@ 3866,7 3862,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
parse_error(("expected whitespace before opening delimiter " .. string.char(b)))
else
end
- return table.insert(stack, {filename = filename, col = (col - 1), closer = delims[b], line = line, bytestart = byteindex})
+ return table.insert(stack, {bytestart = byteindex, closer = delims[b], filename = filename, line = line, col = (col - 1)})
end
local function close_list(list)
return dispatch(setmetatable(list, getmetatable(utils.list())))
@@ 3879,12 3875,12 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return dispatch(val)
end
local function add_comment_at(comments0, index, node)
- local _220_ = (comments0)[index]
- if (nil ~= _220_) then
- local existing = _220_
+ local _239_ = (comments0)[index]
+ if (nil ~= _239_) then
+ local existing = _239_
return table.insert(existing, node)
elseif true then
- local _ = _220_
+ local _ = _239_
comments0[index] = {node}
return nil
else
@@ 3894,12 3890,14 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
local function next_noncomment(tbl, i)
if utils["comment?"](tbl[i]) then
return next_noncomment(tbl, (i + 1))
+ elseif (utils.sym(":") == tbl[i]) then
+ return tostring(tbl[(i + 1)])
else
return tbl[i]
end
end
local function extract_comments(tbl)
- local comments0 = {last = {}, keys = {}, values = {}}
+ local comments0 = {keys = {}, values = {}, last = {}}
while utils["comment?"](tbl[#tbl]) do
table.insert(comments0.last, 1, table.remove(tbl))
end
@@ 3913,7 3911,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
add_comment_at(comments0.keys, next_noncomment(tbl, i), node)
end
end
- for i = #tbl, 1, ( - 1) do
+ for i = #tbl, 1, -1 do
if utils["comment?"](tbl[i]) then
table.remove(tbl, i)
else
@@ 3932,7 3930,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
setmetatable(val, tbl)
for i = 1, #tbl, 2 do
- if (((tostring(tbl[i]) == ":") and utils["sym?"](tbl[(i + 1)])) and utils["sym?"](tbl[i])) then
+ if ((tostring(tbl[i]) == ":") and utils["sym?"](tbl[(i + 1)]) and utils["sym?"](tbl[i])) then
tbl[i] = tostring(tbl[(i + 1)])
else
end
@@ 3964,18 3962,18 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
local function parse_string_loop(chars, b, state)
table.insert(chars, b)
- local state0 = nil
+ local state0
do
- local _230_ = {state, b}
- if (((_G.type(_230_) == "table") and ((_230_)[1] == "base")) and ((_230_)[2] == 92)) then
+ local _249_ = {state, b}
+ if ((_G.type(_249_) == "table") and ((_249_)[1] == "base") and ((_249_)[2] == 92)) then
state0 = "backslash"
- elseif (((_G.type(_230_) == "table") and ((_230_)[1] == "base")) and ((_230_)[2] == 34)) then
+ elseif ((_G.type(_249_) == "table") and ((_249_)[1] == "base") and ((_249_)[2] == 34)) then
state0 = "done"
- elseif (((_G.type(_230_) == "table") and ((_230_)[1] == "backslash")) and ((_230_)[2] == 10)) then
+ elseif ((_G.type(_249_) == "table") and ((_249_)[1] == "backslash") and ((_249_)[2] == 10)) then
table.remove(chars, (#chars - 1))
state0 = "base"
elseif true then
- local _ = _230_
+ local _ = _249_
state0 = "base"
else
state0 = nil
@@ 4000,18 3998,18 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
table.remove(stack)
local raw = string.char(unpack(chars))
local formatted = raw:gsub("[\7-\13]", escape_char)
- local _234_ = (rawget(_G, "loadstring") or load)(("return " .. formatted))
- if (nil ~= _234_) then
- local load_fn = _234_
+ local _253_ = (rawget(_G, "loadstring") or load)(("return " .. formatted))
+ if (nil ~= _253_) then
+ local load_fn = _253_
return dispatch(load_fn())
- elseif (_234_ == nil) then
+ elseif (_253_ == nil) then
return parse_error(("Invalid string: " .. raw))
else
return nil
end
end
local function parse_prefix(b)
- table.insert(stack, {filename = filename, col = (col - 1), line = line, prefix = prefixes[b], bytestart = byteindex})
+ table.insert(stack, {prefix = prefixes[b], filename = filename, line = line, bytestart = byteindex, col = (col - 1)})
local nextb = getb()
if (whitespace_3f(nextb) or (true == delims[nextb])) then
if (b ~= 35) then
@@ 4042,13 4040,13 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
dispatch((tonumber(number_with_stripped_underscores) or parse_error(("could not read number \"" .. rawstr .. "\""))))
return true
else
- local _240_ = tonumber(number_with_stripped_underscores)
- if (nil ~= _240_) then
- local x = _240_
+ local _259_ = tonumber(number_with_stripped_underscores)
+ if (nil ~= _259_) then
+ local x = _259_
dispatch(x)
return true
elseif true then
- local _ = _240_
+ local _ = _259_
return false
else
return nil
@@ 4057,13 4055,13 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
local function check_malformed_sym(rawstr)
local function col_adjust(pat)
- return ((rawstr:find(pat) - utils.len(rawstr)) - 1)
+ return (rawstr:find(pat) - utils.len(rawstr) - 1)
end
if (rawstr:match("^~") and (rawstr ~= "~=")) then
return parse_error("invalid character: ~")
elseif rawstr:match("%.[0-9]") then
return parse_error(("can't start multisym segment with a digit: " .. rawstr), col_adjust("%.[0-9]"))
- elseif ((rawstr:match("[%.:][%.:]") and (rawstr ~= "..")) and (rawstr ~= "$...")) then
+ elseif (rawstr:match("[%.:][%.:]") and (rawstr ~= "..") and (rawstr ~= "$...")) then
return parse_error(("malformed multisym: " .. rawstr), col_adjust("[%.:][%.:]"))
elseif ((rawstr ~= ":") and rawstr:match(":$")) then
return parse_error(("malformed multisym: " .. rawstr), col_adjust(":$"))
@@ 4074,7 4072,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
end
local function parse_sym(b)
- local source0 = {filename = filename, col = (col - 1), line = line, bytestart = byteindex}
+ local source0 = {bytestart = byteindex, filename = filename, line = line, col = (col - 1)}
local rawstr = string.char(unpack(parse_sym_loop({b}, getb())))
set_source_fields(source0)
if (rawstr == "true") then
@@ 4119,34 4117,34 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
return parse_loop(skip_whitespace(getb()))
end
- local function _247_()
+ local function _266_()
stack, line, byteindex, col, lastb = {}, 1, 0, 0, nil
return nil
end
- return parse_stream, _247_
+ return parse_stream, _266_
end
local function parser(stream_or_string, _3ffilename, _3foptions)
local filename = (_3ffilename or "unknown")
- local options = ((_3foptions or utils.root.options) or {})
+ local options = (_3foptions or utils.root.options or {})
assert(("string" == type(filename)), "expected filename as second argument to parser")
if ("string" == type(stream_or_string)) then
- return parser_fn(string_stream(stream_or_string), filename, options)
+ return parser_fn(string_stream(stream_or_string, options), filename, options)
else
return parser_fn(stream_or_string, filename, options)
end
end
- return {["sym-char?"] = sym_char_3f, granulate = granulate, ["string-stream"] = string_stream, parser = parser}
+ return {granulate = granulate, parser = parser, ["string-stream"] = string_stream, ["sym-char?"] = sym_char_3f}
end
- package.preload["fennel.parser"] = (package.preload["fennel.parser"] or _318_)
- local utils = nil
- local function _362_(...)
- local type_order = {number = 1, thread = 7, string = 3, userdata = 6, ["function"] = 5, boolean = 2, table = 4}
+ local utils
+ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...)
+ local type_order = {number = 1, boolean = 2, string = 3, table = 4, ["function"] = 5, userdata = 6, thread = 7}
+ local default_opts = {["one-line?"] = false, ["detect-cycles?"] = true, ["empty-as-sequence?"] = false, ["metamethod?"] = true, ["prefer-colon?"] = false, ["escape-newlines?"] = false, ["utf8?"] = true, ["line-length"] = 80, depth = 128, ["max-sparse-gap"] = 10}
local lua_pairs = pairs
local lua_ipairs = ipairs
local function pairs(t)
local _1_ = getmetatable(t)
- if ((_G.type(_1_) == "table") and (nil ~= _1_.__pairs)) then
- local p = _1_.__pairs
+ if ((_G.type(_1_) == "table") and (nil ~= (_1_).__pairs)) then
+ local p = (_1_).__pairs
return p(t)
elseif true then
local _ = _1_
@@ 4157,8 4155,8 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
local function ipairs(t)
local _3_ = getmetatable(t)
- if ((_G.type(_3_) == "table") and (nil ~= _3_.__ipairs)) then
- local i = _3_.__ipairs
+ if ((_G.type(_3_) == "table") and (nil ~= (_3_).__ipairs)) then
+ local i = (_3_).__ipairs
return i(t)
elseif true then
local _ = _3_
@@ 4169,8 4167,8 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
local function length_2a(t)
local _5_ = getmetatable(t)
- if ((_G.type(_5_) == "table") and (nil ~= _5_.__len)) then
- local l = _5_.__len
+ if ((_G.type(_5_) == "table") and (nil ~= (_5_).__len)) then
+ local l = (_5_).__len
return l(t)
elseif true then
local _ = _5_
@@ 4179,11 4177,66 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return nil
end
end
- local function sort_keys(_7_, _9_)
- local _arg_8_ = _7_
- local a = (_arg_8_)[1]
- local _arg_10_ = _9_
- local b = (_arg_10_)[1]
+ local function get_default(key)
+ local _7_ = default_opts[key]
+ if (_7_ == nil) then
+ return error(("option '%s' doesn't have a default value, use the :after key to set it"):format(tostring(key)))
+ elseif (nil ~= _7_) then
+ local v = _7_
+ return v
+ else
+ return nil
+ end
+ end
+ local function getopt(options, key)
+ local val = options[key]
+ local _9_ = val
+ if ((_G.type(_9_) == "table") and (nil ~= (_9_).once)) then
+ local val_2a = (_9_).once
+ return val_2a
+ elseif true then
+ local _ = _9_
+ return val
+ else
+ return nil
+ end
+ end
+ local function normalize_opts(options)
+ local tbl_13_auto = {}
+ for k, v in pairs(options) do
+ local k_14_auto, v_15_auto = nil, nil
+ local function _12_()
+ local _11_ = v
+ if ((_G.type(_11_) == "table") and (nil ~= (_11_).after)) then
+ local val = (_11_).after
+ return val
+ else
+ local function _13_()
+ return v.once
+ end
+ if ((_G.type(_11_) == "table") and _13_()) then
+ return get_default(k)
+ elseif true then
+ local _ = _11_
+ return v
+ else
+ return nil
+ end
+ end
+ end
+ k_14_auto, v_15_auto = k, _12_()
+ if ((k_14_auto ~= nil) and (v_15_auto ~= nil)) then
+ tbl_13_auto[k_14_auto] = v_15_auto
+ else
+ end
+ end
+ return tbl_13_auto
+ end
+ local function sort_keys(_16_, _18_)
+ local _arg_17_ = _16_
+ local a = _arg_17_[1]
+ local _arg_19_ = _18_
+ local b = _arg_19_[1]
local ta = type(a)
local tb = type(b)
if ((ta == tb) and ((ta == "string") or (ta == "number"))) then
@@ 4206,9 4259,9 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
local gap = 0
if (0 < length_2a(kv)) then
local i = 0
- for _, _13_ in ipairs(kv) do
- local _each_14_ = _13_
- local k = (_each_14_)[1]
+ for _, _22_ in ipairs(kv) do
+ local _each_23_ = _22_
+ local k = _each_23_[1]
if (gap < (k - i)) then
gap = (k - i)
else
@@ 4222,9 4275,9 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
local function fill_gaps(kv)
local missing_indexes = {}
local i = 0
- for _, _17_ in ipairs(kv) do
- local _each_18_ = _17_
- local j = (_each_18_)[1]
+ for _, _26_ in ipairs(kv) do
+ local _each_27_ = _26_
+ local j = _each_27_[1]
i = (i + 1)
while (i < j) do
table.insert(missing_indexes, i)
@@ 4259,14 4312,14 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
if (length_2a(kv) == 0) then
return kv, "empty"
else
- local function _22_()
+ local function _31_()
if assoc_3f then
return "table"
else
return "seq"
end
end
- return kv, _22_()
+ return kv, _31_()
end
end
local function count_table_appearances(t, appearances)
@@ 4297,11 4350,11 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
local function detect_cycle(t, seen, _3fk)
if ("table" == type(t)) then
seen[t] = true
- local _27_, _28_ = next(t, _3fk)
- if ((nil ~= _27_) and (nil ~= _28_)) then
- local k = _27_
- local v = _28_
- return ((((seen[k] or detect_cycle(k, seen)) or seen[v]) or detect_cycle(v, seen)) or detect_cycle(t, seen, k))
+ local _36_, _37_ = next(t, _3fk)
+ if ((nil ~= _36_) and (nil ~= _37_)) then
+ local k = _36_
+ local v = _37_
+ return (seen[k] or detect_cycle(k, seen) or seen[v] or detect_cycle(v, seen) or detect_cycle(t, seen, k))
else
return nil
end
@@ 4310,10 4363,10 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
end
local function visible_cycle_3f(t, options)
- return (((options["detect-cycles?"] and detect_cycle(t, {})) and save_table(t, options.seen)) and (1 < (options.appearances[t] or 0)))
+ return (getopt(options, "detect-cycles?") and detect_cycle(t, {}) and save_table(t, options.seen) and (1 < (options.appearances[t] or 0)))
end
local function table_indent(indent, id)
- local opener_length = nil
+ local opener_length
if id then
opener_length = (length_2a(tostring(id)) + 2)
else
@@ 4324,31 4377,31 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
local pp = nil
local function concat_table_lines(elements, options, multiline_3f, indent, table_type, prefix, last_comment_3f)
local indent_str = ("\n" .. string.rep(" ", indent))
- local open = nil
- local function _32_()
+ local open
+ local function _41_()
if ("seq" == table_type) then
return "["
else
return "{"
end
end
- open = ((prefix or "") .. _32_())
- local close = nil
+ open = ((prefix or "") .. _41_())
+ local close
if ("seq" == table_type) then
close = "]"
else
close = "}"
end
local oneline = (open .. table.concat(elements, " ") .. close)
- if (not options["one-line?"] and ((multiline_3f or (options["line-length"] < (indent + length_2a(oneline)))) or last_comment_3f)) then
- local function _34_()
+ if (not getopt(options, "one-line?") and (multiline_3f or (options["line-length"] < (indent + length_2a(oneline))) or last_comment_3f)) then
+ local function _43_()
if last_comment_3f then
return indent_str
else
return ""
end
end
- return (open .. table.concat(elements, indent_str) .. _34_() .. close)
+ return (open .. table.concat(elements, indent_str) .. _43_() .. close)
else
return oneline
end
@@ 4373,51 4426,50 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
local id = options.seen[t]
if (options.depth <= options.level) then
return "{...}"
- elseif (id and options["detect-cycles?"]) then
+ elseif (id and getopt(options, "detect-cycles?")) then
return ("@" .. id .. "{...}")
else
local visible_cycle_3f0 = visible_cycle_3f(t, options)
local id0 = (visible_cycle_3f0 and options.seen[t])
local indent0 = table_indent(indent, id0)
- local slength = nil
- if options["utf8?"] then
+ local slength
+ if getopt(options, "utf8?") then
slength = utf8_len
else
- local function _37_(_241)
+ local function _46_(_241)
return #_241
end
- slength = _37_
+ slength = _46_
end
- local prefix = nil
+ local prefix
if visible_cycle_3f0 then
prefix = ("@" .. id0)
else
prefix = ""
end
- local items = nil
+ local items
do
- local tbl_14_auto = {}
- local i_15_auto = #tbl_14_auto
- for _, _40_ in pairs(kv) do
- local _each_41_ = _40_
- local k = (_each_41_)[1]
- local v = (_each_41_)[2]
- local val_16_auto = nil
+ local options0 = normalize_opts(options)
+ local tbl_16_auto = {}
+ local i_17_auto = #tbl_16_auto
+ for _, _49_ in ipairs(kv) do
+ local _each_50_ = _49_
+ local k = _each_50_[1]
+ local v = _each_50_[2]
+ local val_18_auto
do
- local k0 = pp(k, options, (indent0 + 1), true)
- local v0 = pp(v, options, ((indent0 + slength(k0)) + 1))
- multiline_3f = ((multiline_3f or k0:find("\n")) or v0:find("\n"))
- val_16_auto = (k0 .. " " .. v0)
+ local k0 = pp(k, options0, (indent0 + 1), true)
+ local v0 = pp(v, options0, (indent0 + slength(k0) + 1))
+ multiline_3f = (multiline_3f or k0:find("\n") or v0:find("\n"))
+ val_18_auto = (k0 .. " " .. v0)
end
- if (nil ~= val_16_auto) then
- i_15_auto = (i_15_auto + 1)
- do
- end
- tbl_14_auto[i_15_auto] = val_16_auto
+ if (nil ~= val_18_auto) then
+ i_17_auto = (i_17_auto + 1)
+ do end (tbl_16_auto)[i_17_auto] = val_18_auto
else
end
end
- items = tbl_14_auto
+ items = tbl_16_auto
end
return concat_table_lines(items, options, multiline_3f, indent0, "table", prefix, false)
end
@@ 4427,73 4479,70 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
local id = options.seen[t]
if (options.depth <= options.level) then
return "[...]"
- elseif (id and options["detect-cycles?"]) then
+ elseif (id and getopt(options, "detect-cycles?")) then
return ("@" .. id .. "[...]")
else
local visible_cycle_3f0 = visible_cycle_3f(t, options)
local id0 = (visible_cycle_3f0 and options.seen[t])
local indent0 = table_indent(indent, id0)
- local prefix = nil
+ local prefix
if visible_cycle_3f0 then
prefix = ("@" .. id0)
else
prefix = ""
end
local last_comment_3f = comment_3f(t[#t])
- local items = nil
+ local items
do
- local tbl_14_auto = {}
- local i_15_auto = #tbl_14_auto
- for _, _45_ in pairs(kv) do
- local _each_46_ = _45_
- local _0 = (_each_46_)[1]
- local v = (_each_46_)[2]
- local val_16_auto = nil
+ local options0 = normalize_opts(options)
+ local tbl_16_auto = {}
+ local i_17_auto = #tbl_16_auto
+ for _, _54_ in ipairs(kv) do
+ local _each_55_ = _54_
+ local _0 = _each_55_[1]
+ local v = _each_55_[2]
+ local val_18_auto
do
- local v0 = pp(v, options, indent0)
- multiline_3f = ((multiline_3f or v0:find("\n")) or v0:find("^;"))
- val_16_auto = v0
+ local v0 = pp(v, options0, indent0)
+ multiline_3f = (multiline_3f or v0:find("\n") or v0:find("^;"))
+ val_18_auto = v0
end
- if (nil ~= val_16_auto) then
- i_15_auto = (i_15_auto + 1)
- do
- end
- tbl_14_auto[i_15_auto] = val_16_auto
+ if (nil ~= val_18_auto) then
+ i_17_auto = (i_17_auto + 1)
+ do end (tbl_16_auto)[i_17_auto] = val_18_auto
else
end
end
- items = tbl_14_auto
+ items = tbl_16_auto
end
return concat_table_lines(items, options, multiline_3f, indent0, "seq", prefix, last_comment_3f)
end
end
local function concat_lines(lines, options, indent, force_multi_line_3f)
if (length_2a(lines) == 0) then
- if options["empty-as-sequence?"] then
+ if getopt(options, "empty-as-sequence?") then
return "[]"
else
return "{}"
end
else
- local oneline = nil
- local _50_ = nil
+ local oneline
+ local _59_
do
- local tbl_14_auto = {}
- local i_15_auto = #tbl_14_auto
+ local tbl_16_auto = {}
+ local i_17_auto = #tbl_16_auto
for _, line in ipairs(lines) do
- local val_16_auto = line:gsub("^%s+", "")
- if (nil ~= val_16_auto) then
- i_15_auto = (i_15_auto + 1)
- do
- end
- tbl_14_auto[i_15_auto] = val_16_auto
+ local val_18_auto = line:gsub("^%s+", "")
+ if (nil ~= val_18_auto) then
+ i_17_auto = (i_17_auto + 1)
+ do end (tbl_16_auto)[i_17_auto] = val_18_auto
else
end
end
- _50_ = tbl_14_auto
+ _59_ = tbl_16_auto
end
- oneline = table.concat(_50_, " ")
- if (not options["one-line?"] and ((force_multi_line_3f or oneline:find("\n")) or (options["line-length"] < (indent + length_2a(oneline))))) then
+ oneline = table.concat(_59_, " ")
+ if (not getopt(options, "one-line?") and (force_multi_line_3f or oneline:find("\n") or (options["line-length"] < (indent + length_2a(oneline))))) then
return table.concat(lines, ("\n" .. string.rep(" ", indent)))
else
return oneline
@@ 4502,27 4551,31 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
local function pp_metamethod(t, metamethod, options, indent)
if (options.depth <= options.level) then
- if options["empty-as-sequence?"] then
+ if getopt(options, "empty-as-sequence?") then
return "[...]"
else
return "{...}"
end
else
- local _ = nil
- local function _55_(_241)
+ local _
+ local function _64_(_241)
return visible_cycle_3f(_241, options)
end
- options["visible-cycle?"] = _55_
+ options["visible-cycle?"] = _64_
_ = nil
- local lines, force_multi_line_3f = metamethod(t, pp, options, indent)
- do end (options)["visible-cycle?"] = nil
- local _56_ = type(lines)
- if (_56_ == "string") then
+ local lines, force_multi_line_3f = nil, nil
+ do
+ local options0 = normalize_opts(options)
+ lines, force_multi_line_3f = metamethod(t, pp, options0, indent)
+ end
+ options["visible-cycle?"] = nil
+ local _65_ = type(lines)
+ if (_65_ == "string") then
return lines
- elseif (_56_ == "table") then
+ elseif (_65_ == "table") then
return concat_lines(lines, options, indent, force_multi_line_3f)
elseif true then
- local _0 = _56_
+ local _0 = _65_
return error("__fennelview metamethod must return a table of lines")
else
return nil
@@ 4531,42 4584,42 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
local function pp_table(x, options, indent)
options.level = (options.level + 1)
- local x0 = nil
+ local x0
do
- local _59_ = nil
- if options["metamethod?"] then
- local _60_ = x
- if (nil ~= _60_) then
- local _61_ = getmetatable(_60_)
- if (nil ~= _61_) then
- _59_ = _61_.__fennelview
+ local _68_
+ if getopt(options, "metamethod?") then
+ local _69_ = x
+ if (nil ~= _69_) then
+ local _70_ = getmetatable(_69_)
+ if (nil ~= _70_) then
+ _68_ = (_70_).__fennelview
else
- _59_ = _61_
+ _68_ = _70_
end
else
- _59_ = _60_
+ _68_ = _69_
end
else
- _59_ = nil
+ _68_ = nil
end
- if (nil ~= _59_) then
- local metamethod = _59_
+ if (nil ~= _68_) then
+ local metamethod = _68_
x0 = pp_metamethod(x, metamethod, options, indent)
elseif true then
- local _ = _59_
- local _65_, _66_ = table_kv_pairs(x, options)
- if (true and (_66_ == "empty")) then
- local _0 = _65_
- if options["empty-as-sequence?"] then
+ local _ = _68_
+ local _74_, _75_ = table_kv_pairs(x, options)
+ if (true and (_75_ == "empty")) then
+ local _0 = _74_
+ if getopt(options, "empty-as-sequence?") then
x0 = "[]"
else
x0 = "{}"
end
- elseif ((nil ~= _65_) and (_66_ == "table")) then
- local kv = _65_
+ elseif ((nil ~= _74_) and (_75_ == "table")) then
+ local kv = _74_
x0 = pp_associative(x, kv, options, indent)
- elseif ((nil ~= _65_) and (_66_ == "seq")) then
- local kv = _65_
+ elseif ((nil ~= _74_) and (_75_ == "seq")) then
+ local kv = _74_
x0 = pp_sequence(x, kv, options, indent)
else
x0 = nil
@@ 4579,57 4632,42 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return x0
end
local function number__3estring(n)
- local _70_ = string.gsub(tostring(n), ",", ".")
- return _70_
+ local _79_ = string.gsub(tostring(n), ",", ".")
+ return _79_
end
local function colon_string_3f(s)
return s:find("^[-%w?^_!$%&*+./@|<=>]+$")
end
- local utf8_inits = {{["min-code"] = 0, ["max-code"] = 127, ["max-byte"] = 127, len = 1, ["min-byte"] = 0}, {["min-code"] = 128, ["max-code"] = 2047, ["max-byte"] = 223, len = 2, ["min-byte"] = 192}, {["min-code"] = 2048, ["max-code"] = 65535, ["max-byte"] = 239, len = 3, ["min-byte"] = 224}, {["min-code"] = 65536, ["max-code"] = 1114111, ["max-byte"] = 247, len = 4, ["min-byte"] = 240}}
+ local utf8_inits = {{["min-byte"] = 0, ["max-byte"] = 127, ["min-code"] = 0, ["max-code"] = 127, len = 1}, {["min-byte"] = 192, ["max-byte"] = 223, ["min-code"] = 128, ["max-code"] = 2047, len = 2}, {["min-byte"] = 224, ["max-byte"] = 239, ["min-code"] = 2048, ["max-code"] = 65535, len = 3}, {["min-byte"] = 240, ["max-byte"] = 247, ["min-code"] = 65536, ["max-code"] = 1114111, len = 4}}
local function utf8_escape(str)
local function validate_utf8(str0, index)
local inits = utf8_inits
local byte = string.byte(str0, index)
- local init = nil
+ local init
do
local ret = nil
for _, init0 in ipairs(inits) do
- if ret then
- break
- else
- end
- local function _407_(_71_, _72_, _73_)
- return ((_71_ <= _72_) and (_72_ <= _73_))
- end
- ret = ((byte and _407_((init0)["min-byte"], byte, (init0)["max-byte"])) and init0)
+ if ret then break end
+ ret = (byte and (function(_80_,_81_,_82_) return (_80_ <= _81_) and (_81_ <= _82_) end)(init0["min-byte"],byte,init0["max-byte"]) and init0)
end
init = ret
end
- local code = nil
- local function _74_()
- local code0 = nil
+ local code
+ local function _83_()
+ local code0
if init then
code0 = (byte - init["min-byte"])
else
code0 = nil
end
- for i = (index + 1), ((index + init.len) + ( - 1)) do
+ for i = (index + 1), (index + init.len + -1) do
local byte0 = string.byte(str0, i)
- local function _409_(_76_, _77_, _78_)
- return ((_76_ <= _77_) and (_77_ <= _78_))
- end
- code0 = (((byte0 and code0) and _409_(128, byte0, 191)) and ((code0 * 64) + (byte0 - 128)))
+ code0 = (byte0 and code0 and (function(_85_,_86_,_87_) return (_85_ <= _86_) and (_86_ <= _87_) end)(128,byte0,191) and ((code0 * 64) + (byte0 - 128)))
end
return code0
end
- code = (init and _74_())
- local function _410_(_79_, _80_, _81_)
- return ((_79_ <= _80_) and (_80_ <= _81_))
- end
- local function _411_(_82_, _83_, _84_)
- return ((_82_ <= _83_) and (_83_ <= _84_))
- end
- if ((code and _410_(init["min-code"], code, init["max-code"])) and not _411_(55296, code, 57343)) then
+ code = (init and _83_())
+ if (code and (function(_88_,_89_,_90_) return (_88_ <= _89_) and (_89_ <= _90_) end)(init["min-code"],code,init["max-code"]) and not (function(_91_,_92_,_93_) return (_91_ <= _92_) and (_92_ <= _93_) end)(55296,code,57343)) then
return init.len
else
return nil
@@ 4640,7 4678,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
while (index <= #str) do
local nexti = (string.find(str, "[\128-\255]", index) or (#str + 1))
local len = validate_utf8(str, nexti)
- table.insert(output, string.sub(str, index, ((nexti + (len or 0)) + ( - 1))))
+ table.insert(output, string.sub(str, index, (nexti + (len or 0) + -1)))
if (not len and (nexti <= #str)) then
table.insert(output, string.format("\\%03d", string.byte(str, nexti)))
else
@@ 4654,27 4692,40 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return table.concat(output)
end
local function pp_string(str, options, indent)
- local escs = nil
- local _88_ = nil
- if (options["escape-newlines?"] and (length_2a(str) < (options["line-length"] - indent))) then
- _88_ = "\\n"
+ local len = length_2a(str)
+ local esc_newline_3f = ((len < 2) or (getopt(options, "escape-newlines?") and (len < (options["line-length"] - indent))))
+ local escs
+ local _97_
+ if esc_newline_3f then
+ _97_ = "\\n"
else
- _88_ = "\n"
+ _97_ = "\n"
end
- local function _90_(_241, _242)
+ local function _99_(_241, _242)
return ("\\%03d"):format(_242:byte())
end
- escs = setmetatable({["\11"] = "\\v", ["\n"] = _88_, ["\8"] = "\\b", ["\12"] = "\\f", ["\""] = "\\\"", ["\13"] = "\\r", ["\\"] = "\\\\", ["\9"] = "\\t", ["\7"] = "\\a"}, {__index = _90_})
+ escs = setmetatable({["\7"] = "\\a", ["\8"] = "\\b", ["\12"] = "\\f", ["\11"] = "\\v", ["\13"] = "\\r", ["\9"] = "\\t", ["\\"] = "\\\\", ["\""] = "\\\"", ["\n"] = _97_}, {__index = _99_})
local str0 = ("\"" .. str:gsub("[%c\\\"]", escs) .. "\"")
- if options["utf8?"] then
+ if getopt(options, "utf8?") then
return utf8_escape(str0)
else
return str0
end
end
local function make_options(t, options)
- local defaults = {["utf8?"] = true, ["metamethod?"] = true, depth = 128, ["line-length"] = 80, ["detect-cycles?"] = true, ["max-sparse-gap"] = 10, ["escape-newlines?"] = false, ["one-line?"] = false, ["prefer-colon?"] = false, ["empty-as-sequence?"] = false}
- local overrides = {level = 0, seen = {len = 0}, appearances = count_table_appearances(t, {})}
+ local defaults
+ do
+ local tbl_13_auto = {}
+ for k, v in pairs(default_opts) do
+ local k_14_auto, v_15_auto = k, v
+ if ((k_14_auto ~= nil) and (v_15_auto ~= nil)) then
+ tbl_13_auto[k_14_auto] = v_15_auto
+ else
+ end
+ end
+ defaults = tbl_13_auto
+ end
+ local overrides = {level = 0, appearances = count_table_appearances(t, {}), seen = {len = 0}}
for k, v in pairs((options or {})) do
defaults[k] = v
end
@@ 4683,39 4734,39 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
return defaults
end
- local function _92_(x, options, indent, colon_3f)
+ local function _102_(x, options, indent, colon_3f)
local indent0 = (indent or 0)
local options0 = (options or make_options(x))
- local x0 = nil
+ local x0
if options0.preprocess then
x0 = options0.preprocess(x, options0)
else
x0 = x
end
local tv = type(x0)
- local function _95_()
- local _94_ = getmetatable(x0)
- if (nil ~= _94_) then
- return _94_.__fennelview
+ local function _105_()
+ local _104_ = getmetatable(x0)
+ if (nil ~= _104_) then
+ return (_104_).__fennelview
else
- return _94_
+ return _104_
end
end
- if ((tv == "table") or ((tv == "userdata") and _95_())) then
+ if ((tv == "table") or ((tv == "userdata") and _105_())) then
return pp_table(x0, options0, indent0)
elseif (tv == "number") then
return number__3estring(x0)
else
- local function _97_()
+ local function _107_()
if (colon_3f ~= nil) then
return colon_3f
- elseif ("function" == type((options0)["prefer-colon?"])) then
- return (options0)["prefer-colon?"](x0)
+ elseif ("function" == type(options0["prefer-colon?"])) then
+ return options0["prefer-colon?"](x0)
else
- return (options0)["prefer-colon?"]
+ return getopt(options0, "prefer-colon?")
end
end
- if (((tv == "string") and colon_string_3f(x0)) and _97_()) then
+ if ((tv == "string") and colon_string_3f(x0) and _107_()) then
return (":" .. x0)
elseif (tv == "string") then
return pp_string(x0, options0, indent0)
@@ 4726,21 4777,20 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
end
end
- pp = _92_
+ pp = _102_
local function view(x, _3foptions)
return pp(x, make_options(x, _3foptions), 0)
end
return view
end
- package.preload["fennel.view"] = (package.preload["fennel.view"] or _362_)
- local function _422_(...)
+ package.preload["fennel.utils"] = package.preload["fennel.utils"] or function(...)
local view = require("fennel.view")
- local version = "1.2.0-dev"
+ local version = "1.3.0"
local function luajit_vm_3f()
- return (((((nil ~= _G.jit) and (type(_G.jit) == "table")) and (nil ~= _G.jit.on)) and (nil ~= _G.jit.off)) and (type(_G.jit.version_num) == "number"))
+ return ((nil ~= _G.jit) and (type(_G.jit) == "table") and (nil ~= _G.jit.on) and (nil ~= _G.jit.off) and (type(_G.jit.version_num) == "number"))
end
local function luajit_vm_version()
- local jit_os = nil
+ local jit_os
if (_G.jit.os == "OSX") then
jit_os = "macOS"
else
@@ 4749,7 4799,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return (_G.jit.version .. " " .. jit_os .. "/" .. _G.jit.arch)
end
local function fengari_vm_3f()
- return ((((nil ~= _G.fengari) and (type(_G.fengari) == "table")) and (nil ~= _G.fengari.VERSION)) and (type(_G.fengari.VERSION_NUM) == "number"))
+ return ((nil ~= _G.fengari) and (type(_G.fengari) == "table") and (nil ~= _G.fengari.VERSION) and (type(_G.fengari.VERSION_NUM) == "number"))
end
local function fengari_vm_version()
return (_G.fengari.RELEASE .. " (" .. _VERSION .. ")")
@@ 4773,14 4823,14 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return nil
end
end
- local len = nil
+ local len
do
- local _102_, _103_ = pcall(require, "utf8")
- if ((_102_ == true) and (nil ~= _103_)) then
- local utf8 = _103_
+ local _112_, _113_ = pcall(require, "utf8")
+ if ((_112_ == true) and (nil ~= _113_)) then
+ local utf8 = _113_
len = utf8.len
elseif true then
- local _ = _102_
+ local _ = _112_
len = string.len
else
len = nil
@@ 4788,7 4838,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
local function mt_keys_in_order(t, out, used_keys)
for _, k in ipairs(getmetatable(t).keys) do
- if t[k] then
+ if (t[k] and not used_keys[k]) then
used_keys[k] = true
table.insert(out, k)
else
@@ 4803,57 4853,53 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
return out
end
local function stablepairs(t)
- local keys = nil
- local _108_ = nil
+ local keys
+ local _118_
do
- local t_107_ = getmetatable(t)
- if (nil ~= t_107_) then
- t_107_ = t_107_.keys
+ local t_117_ = getmetatable(t)
+ if (nil ~= t_117_) then
+ t_117_ = (t_117_).keys
else
end
- _108_ = t_107_
+ _118_ = t_117_
end
- if _108_ then
+ if _118_ then
keys = mt_keys_in_order(t, {}, {})
else
- local _110_ = nil
+ local _120_
do
- local tbl_14_auto = {}
- local i_15_auto = #tbl_14_auto
+ local tbl_16_auto = {}
+ local i_17_auto = #tbl_16_auto
for k in pairs(t) do
- local val_16_auto = k
- if (nil ~= val_16_auto) then
- i_15_auto = (i_15_auto + 1)
- do
- end
- tbl_14_auto[i_15_auto] = val_16_auto
+ local val_18_auto = k
+ if (nil ~= val_18_auto) then
+ i_17_auto = (i_17_auto + 1)
+ do end (tbl_16_auto)[i_17_auto] = val_18_auto
else
end
end
- _110_ = tbl_14_auto
+ _120_ = tbl_16_auto
end
- local function _112_(_241, _242)
+ local function _122_(_241, _242)
return (tostring(_241) < tostring(_242))
end
- table.sort(_110_, _112_)
- keys = _110_
+ table.sort(_120_, _122_)
+ keys = _120_
end
- local succ = nil
+ local succ
do
- local tbl_11_auto = {}
+ local tbl_13_auto = {}
for i, k in ipairs(keys) do
- local _114_, _115_ = k, keys[(i + 1)]
- if ((nil ~= _114_) and (nil ~= _115_)) then
- local k_12_auto = _114_
- local v_13_auto = _115_
- tbl_11_auto[k_12_auto] = v_13_auto
+ local k_14_auto, v_15_auto = k, keys[(i + 1)]
+ if ((k_14_auto ~= nil) and (v_15_auto ~= nil)) then
+ tbl_13_auto[k_14_auto] = v_15_auto
else
end
end
- succ = tbl_11_auto
+ succ = tbl_13_auto
end
local function stablenext(tbl, key)
- local next_key = nil
+ local next_key
if (key == nil) then
next_key = keys[1]
else
@@ 4863,21 4909,51 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end
return stablenext, t, nil
end
+ local function get_in(tbl, path, _3ffallback)
+ assert(("table" == type(tbl)), "get-in expects path to be a table")
+ if (0 == #path) then
+ return _3ffallback
+ else
+ local _126_
+ do
+ local t = tbl
+ for _, k in ipairs(path) do
+ if (nil == t) then break end
+ local _127_ = type(t)
+ if (_127_ == "table") then
+ t = t[k]
+ else
+ t = nil
+ end
+ end
+ _126_ = t
+ end
+ if (nil ~= _126_) then
+ local res = _126_
+ return res
+ elseif true then
+ local _ = _126_
+ return _3ffallback
+ else
+ return nil
+ end
+ end
+ end
local function map(t, f, _3fout)
local out = (_3fout or {})
- local f0 = nil
+ local f0
if (type(f) == "function") then
f0 = f
else
- local function _118_(_241)
+ local function _131_(_241)
return (_241)[f]
end
- f0 = _118_
+ f0 = _131_
end
for _, x in ipairs(t) do
- local _120_ = f0(x)
- if (nil ~= _120_) then
- local v = _120_
+ local _133_ = f0(x)
+ if (nil ~= _133_) then
+ local v = _133_
table.insert(out, v)
else
end
@@ 4886,23 4962,23 @@ package.preload["fennel"] = package.preload["fennel"] or function(...)
end