diff --git a/lib/fennel b/lib/fennel index f72b948..fea2a0c 100755 --- a/lib/fennel +++ b/lib/fennel @@ -1,17 +1,22 @@ #!/usr/bin/env lua package.preload["fennel.binary"] = package.preload["fennel.binary"] or function(...) local fennel = require("fennel") + local _local_656_ = require("fennel.utils") + local warn = _local_656_["warn"] + local copy = _local_656_["copy"] local function shellout(command) local f = io.popen(command) local stdout = f:read("*all") return (f:close() and stdout) end local function execute(cmd) - local _601_ = os.execute(cmd) - if (_601_ == 0) then + local _657_ = os.execute(cmd) + if (_657_ == 0) then return true - elseif (_601_ == true) then + elseif (_657_ == true) then return true + else + return nil end end local function string__3ec_hex_literal(characters) @@ -33,14 +38,45 @@ package.preload["fennel.binary"] = package.preload["fennel.binary"] or function( f:close() return lua_code end - local function native_loader(native) + local function native_loader(native, _3foptions) + local opts = (_3foptions or {["rename-modules"] = {}}) + local rename = (opts["rename-modules"] or {}) + local used_renames = {} local nm = (os.getenv("NM") or "nm") local out = {" /* native libraries */"} for _, path in ipairs(native) do + local opens = {} for open in shellout((nm .. " " .. path)):gmatch("[^dDt] _?luaopen_([%a%p%d]+)") do + table.insert(opens, open) + end + if (0 == #opens) then + warn((("Native module %s did not contain any luaopen_* symbols. " .. "Did you mean to use --native-library instead of --native-module?")):format(path)) + else + end + for _0, open in ipairs(opens) do + local require_name + do + local _661_ = rename[open] + if (nil ~= _661_) then + local renamed = _661_ + used_renames[open] = true + require_name = renamed + elseif true then + local _1 = _661_ + require_name = open + else + require_name = nil + end + end table.insert(out, (" int luaopen_%s(lua_State *L);"):format(open)) table.insert(out, (" lua_pushcfunction(L, luaopen_%s);"):format(open)) - table.insert(out, (" lua_setfield(L, -2, \"%s\");\n"):format((open:sub(1, 1) .. open:sub(2):gsub("_", ".")))) + table.insert(out, (" lua_setfield(L, -2, \"%s\");\n"):format(require_name)) + end + end + for key, val in pairs(rename) do + if not used_renames[key] then + warn((("unused --rename-native-module %s %s argument. " .. "Did you mean to include a native module?")):format(key, val)) + else end end return table.concat(out, "\n") @@ -51,13 +87,15 @@ package.preload["fennel.binary"] = package.preload["fennel.binary"] or function( local dotpath = filename:gsub("^%.%/", ""):gsub("[\\/]", ".") local dotpath_noextension = (dotpath:match("(.+)%.") or dotpath) local fennel_loader - local _604_ + local _664_ do - _604_ = "(do (local bundle_2_auto ...) (fn loader_3_auto [name_4_auto] (match (or (. bundle_2_auto name_4_auto) (. bundle_2_auto (.. name_4_auto \".init\"))) (mod_5_auto ? (= \"function\" (type mod_5_auto))) mod_5_auto (mod_5_auto ? (= \"string\" (type mod_5_auto))) (assert (if (= _VERSION \"Lua 5.1\") (loadstring mod_5_auto name_4_auto) (load mod_5_auto name_4_auto))) nil (values nil (: \"\n\\tmodule '%%s' not found in fennel bundle\" \"format\" name_4_auto)))) (table.insert (or package.loaders package.searchers) 2 loader_3_auto) ((assert (loader_3_auto \"%s\")) ((or unpack table.unpack) arg)))" + _664_ = "(do (local bundle_2_auto ...) (fn loader_3_auto [name_4_auto] (match (or (. bundle_2_auto name_4_auto) (. bundle_2_auto (.. name_4_auto \".init\"))) (mod_5_auto ? (= \"function\" (type mod_5_auto))) mod_5_auto (mod_5_auto ? (= \"string\" (type mod_5_auto))) (assert (if (= _VERSION \"Lua 5.1\") (loadstring mod_5_auto name_4_auto) (load mod_5_auto name_4_auto))) nil (values nil (: \"\n\\tmodule '%%s' not found in fennel bundle\" \"format\" name_4_auto)))) (table.insert (or package.loaders package.searchers) 2 loader_3_auto) ((assert (loader_3_auto \"%s\")) ((or unpack table.unpack) arg)))" end - fennel_loader = _604_:format(dotpath_noextension) + fennel_loader = _664_:format(dotpath_noextension) local lua_loader = fennel["compile-string"](fennel_loader) - return c_shim:format(string__3ec_hex_literal(lua_loader), basename_noextension, string__3ec_hex_literal(compile_fennel(filename, options)), dotpath_noextension, native_loader(native)) + local _let_665_ = options + local rename_modules = _let_665_["rename-modules"] + return c_shim:format(string__3ec_hex_literal(lua_loader), basename_noextension, string__3ec_hex_literal(compile_fennel(filename, options)), dotpath_noextension, native_loader(native, {["rename-modules"] = rename_modules})) end local function write_c(filename, native, options) local out_filename = (filename .. "_binary.c") @@ -69,82 +107,105 @@ package.preload["fennel.binary"] = package.preload["fennel.binary"] or function( local function compile_binary(lua_c_path, executable_name, static_lua, lua_include_dir, native) local cc = (os.getenv("CC") or "cc") local rdynamic, bin_extension, ldl_3f = nil, nil, nil - local _606_ + local _667_ do - local _605_ = shellout((cc .. " -dumpmachine")) - if _605_ then - _606_ = _605_:match("mingw") + local _666_ = shellout((cc .. " -dumpmachine")) + if (nil ~= _666_) then + _667_ = _666_:match("mingw") else - _606_ = _605_ + _667_ = _666_ end end - if _606_ then + if _667_ then rdynamic, bin_extension, ldl_3f = "", ".exe", false else rdynamic, bin_extension, ldl_3f = "-rdynamic", "", true end local compile_command - local _609_ + local _670_ if ldl_3f then - _609_ = "-ldl" + _670_ = "-ldl" else - _609_ = "" + _670_ = "" end - compile_command = {cc, "-Os", lua_c_path, table.concat(native, " "), static_lua, rdynamic, "-lm", _609_, "-o", (executable_name .. bin_extension), "-I", lua_include_dir, os.getenv("CC_OPTS")} + compile_command = {cc, "-Os", lua_c_path, table.concat(native, " "), static_lua, rdynamic, "-lm", _670_, "-o", (executable_name .. bin_extension), "-I", lua_include_dir, os.getenv("CC_OPTS")} if os.getenv("FENNEL_DEBUG") then print("Compiling with", table.concat(compile_command, " ")) + else end if not execute(table.concat(compile_command, " ")) then print("failed:", table.concat(compile_command, " ")) os.exit(1) + else end if not os.getenv("FENNEL_DEBUG") then os.remove(lua_c_path) + else end return os.exit(0) end local function native_path_3f(path) - local _614_ = path:match("%.(%a+)$") - if (_614_ == "a") then - return path - elseif (_614_ == "o") then - return path - elseif (_614_ == "so") then - return path - elseif (_614_ == "dylib") then - return path - else - local _ = _614_ + local extension, version_extension = path:match("%.(%a+)(%.?%d*)$") + if (version_extension and not (version_extension == "") and not version_extension:match("%.%d+")) then return false + else + local _675_ = extension + if (_675_ == "a") then + return path + elseif (_675_ == "o") then + return path + elseif (_675_ == "so") then + return path + elseif (_675_ == "dylib") then + return path + elseif true then + local _ = _675_ + return false + else + return nil + end end end local function extract_native_args(args) - local native = {modules = {}, libraries = {}} + local native = {modules = {}, libraries = {}, ["rename-modules"] = {}} for i = #args, 1, -1 do if ("--native-module" == args[i]) then local path = assert(native_path_3f(table.remove(args, (i + 1)))) table.insert(native.modules, 1, path) table.insert(native.libraries, 1, path) table.remove(args, i) + else end if ("--native-library" == args[i]) then table.insert(native.libraries, 1, assert(native_path_3f(table.remove(args, (i + 1))))) table.remove(args, i) + else + end + if ("--rename-native-module" == args[i]) then + local original = table.remove(args, (i + 1)) + local new = table.remove(args, (i + 1)) + do end (native["rename-modules"])[original] = new + table.remove(args, i) + else end end if (0 < #args) then print(table.concat(args, " ")) error(("Unknown args: " .. table.concat(args, " "))) + else end return native end local function compile(filename, executable_name, static_lua, lua_include_dir, options, args) - local _let_619_ = extract_native_args(args) - local modules = _let_619_["modules"] - local libraries = _let_619_["libraries"] - return compile_binary(write_c(filename, modules, options), executable_name, static_lua, lua_include_dir, libraries) + local _let_682_ = extract_native_args(args) + local modules = _let_682_["modules"] + local libraries = _let_682_["libraries"] + local rename_modules = _let_682_["rename-modules"] + local opts = {["rename-modules"] = rename_modules} + copy(options, opts) + return compile_binary(write_c(filename, modules, opts), executable_name, static_lua, lua_include_dir, libraries) end - local help = ("\nUsage: %s --compile-binary FILE OUT STATIC_LUA_LIB LUA_INCLUDE_DIR\n\nCompile a binary from your Fennel program.\n\nRequires a C compiler, a copy of liblua, and Lua's dev headers. Implies\nthe --require-as-include option.\n\n FILE: the Fennel source being compiled.\n OUT: the name of the executable to generate\n STATIC_LUA_LIB: the path to the Lua library to use in the executable\n LUA_INCLUDE_DIR: the path to the directory of Lua C header files\n\nFor example, on a Debian system, to compile a file called program.fnl using\nLua 5.3, you would use this:\n\n $ %s --compile-binary program.fnl program \\\n /usr/lib/x86_64-linux-gnu/liblua5.3.a /usr/include/lua5.3\n\nThe program will be compiled to Lua, then compiled to C, then compiled to\nmachine code. You can set the CC environment variable to change the compiler\nused (default: cc) or set CC_OPTS to pass in compiler options. For example\nset CC_OPTS=-static to generate a binary with static linking.\n\nTo include C libraries that contain Lua modules, add --native-module path/to.so,\nand to include C libraries without modules, use --native-library path/to.so.\nThese options are unstable, barely tested, and even more likely to break.\n\nThis method is currently limited to programs do not transitively require Lua\nmodules. Requiring a Lua module directly will work, but requiring a Lua module\nwhich requires another will fail."):format(arg[0], arg[0]) + local help = ("\nUsage: %s --compile-binary FILE OUT STATIC_LUA_LIB LUA_INCLUDE_DIR\n\nCompile a binary from your Fennel program.\n\nRequires a C compiler, a copy of liblua, and Lua's dev headers. Implies\nthe --require-as-include option.\n\n FILE: the Fennel source being compiled.\n OUT: the name of the executable to generate\n STATIC_LUA_LIB: the path to the Lua library to use in the executable\n LUA_INCLUDE_DIR: the path to the directory of Lua C header files\n\nFor example, on a Debian system, to compile a file called program.fnl using\nLua 5.3, you would use this:\n\n $ %s --compile-binary program.fnl program \\\n /usr/lib/x86_64-linux-gnu/liblua5.3.a /usr/include/lua5.3\n\nThe program will be compiled to Lua, then compiled to C, then compiled to\nmachine code. You can set the CC environment variable to change the compiler\nused (default: cc) or set CC_OPTS to pass in compiler options. For example\nset CC_OPTS=-static to generate a binary with static linking.\n\nThis method is currently limited to programs do not transitively require Lua\nmodules. Requiring a Lua module directly will work, but requiring a Lua module\nwhich requires another will fail.\n\nTo include C libraries that contain Lua modules, add --native-module path/to.so,\nand to include C libraries without modules, use --native-library path/to.so.\nThese options are unstable, barely tested, and even more likely to break.\n\nIf you need to change the require name that a given native module is referenced\nas, you can use the --rename-native-module ORIGINAL NEW. ORIGINAL should be the\nsuffix of the luaopen_* symbol in the native module. NEW should be the string\nyou wish to pass to require to require the given native module. This can be used\nto handle cases where the name of an object file does not match the name of the\nluaopen_* symbol(s) within it. For example, the Lua readline bindings include a\nreadline.lua file which is usually required as \"readline\", and a C-readline.so\nfile which is required in the Lua half of the bindings like so:\n\n require 'C-readline'\n\nHowever, the symbol within the C-readline.so file is named luaopen_readline, so\nby default --compile-binary will make it so you can require it as \"readline\",\nwhich collides with the name of the readline.lua file and doesn't match the\nrequire call within readline.lua. In order to include the module within your\ncompiled binary and have it get picked up by readline.lua correctly, you can\nspecify the name used to refer to it in a require call by compiling it like\nso (this is assuming that program.fnl requires the Lua bindings):\n\n $ %s --compile-binary program.fnl program \\\n /usr/lib/x86_64-linux-gnu/liblua5.3.a /usr/include/lua5.3 \\\n --native-module C-readline.so \\\n --rename-native-module readline C-readline\n"):format(arg[0], arg[0], arg[0]) return {compile = compile, help = help} end local fennel @@ -153,16 +214,17 @@ package.preload["fennel.repl"] = package.preload["fennel.repl"] or function(...) local parser = require("fennel.parser") local compiler = require("fennel.compiler") local specials = require("fennel.specials") + local view = require("fennel.view") local unpack = (table.unpack or _G.unpack) local function default_read_chunk(parser_state) - local function _481_() + local function _519_() if (0 < parser_state["stack-size"]) then return ".." else return ">> " end end - io.write(_481_()) + io.write(_519_()) io.flush() local input = io.read() return (input and (input .. "\n")) @@ -172,22 +234,23 @@ package.preload["fennel.repl"] = package.preload["fennel.repl"] or function(...) return io.write("\n") end local function default_on_error(errtype, err, lua_source) - local function _483_() - local _482_ = errtype - if (_482_ == "Lua Compile") then + local function _521_() + local _520_ = errtype + if (_520_ == "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 (_482_ == "Runtime") then + elseif (_520_ == "Runtime") then return (compiler.traceback(tostring(err), 4) .. "\n") - else - local _ = _482_ + elseif true then + local _ = _520_ return ("%s error: %s\n"):format(errtype, tostring(err)) + else + return nil end end - return io.write(_483_()) + return io.write(_521_()) 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) - env.___replLocals___ = (env.___replLocals___ or {}) local spliced_source = {} local bind = "local %s = ___replLocals___['%s']" for line in lua_source:gmatch("([^\n]+)\n?") do @@ -198,6 +261,7 @@ package.preload["fennel.repl"] = package.preload["fennel.repl"] or function(...) end if ((1 < #spliced_source) and (spliced_source[#spliced_source]):match("^ *return .*$")) then table.insert(spliced_source, #spliced_source, save_source) + else end return table.concat(spliced_source, "\n") end @@ -214,14 +278,15 @@ package.preload["fennel.repl"] = package.preload["fennel.repl"] or function(...) k0 = k end if ((#matches < 2000) and (type(k0) == "string") and (input == k0:sub(0, #input)) and (not method_3f or ("function" == type(tbl[k0])))) then - local function _487_() + local function _525_() if method_3f then return (prefix .. ":" .. k0) else return (prefix .. k0) end end - table.insert(matches, _487_()) + table.insert(matches, _525_()) + else end end return nil @@ -234,12 +299,7 @@ package.preload["fennel.repl"] = package.preload["fennel.repl"] or function(...) splitter = "^([^.]+)%.(.*)" end local head, tail = input:match(splitter) - local raw_head - if ((tbl == env) or (tbl == env.___replLocals___)) then - raw_head = scope.manglings[head] - else - raw_head = head - end + local raw_head = (scope.manglings[head] or head) if (type(tbl[raw_head]) == "table") then stop_looking_3f = true if method_3f then @@ -247,6 +307,8 @@ package.preload["fennel.repl"] = package.preload["fennel.repl"] or function(...) else return add_matches(tail, tbl[raw_head], (prefix .. head)) end + else + return nil end end local function add_matches(input, tbl, prefix) @@ -265,10 +327,8 @@ package.preload["fennel.repl"] = package.preload["fennel.repl"] 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 end add_matches(input_fragment, source) - if stop_looking_3f then - break - end end return matches end @@ -277,24 +337,30 @@ package.preload["fennel.repl"] = package.preload["fennel.repl"] or function(...) return input:match("^%s*,") end local function command_docs() - local _496_ + local _532_ do - local tbl_13_auto = {} + local tbl_14_auto = {} + local i_15_auto = #tbl_14_auto for name, f in pairs(commands) do - tbl_13_auto[(#tbl_13_auto + 1)] = (" ,%s - %s"):format(name, ((compiler.metadata):get(f, "fnl/docstring") or "undocumented")) + 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 + else + end end - _496_ = tbl_13_auto + _532_ = tbl_14_auto end - return table.concat(_496_, "\n") + return table.concat(_532_, "\n") end 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")}) + 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 do end (compiler.metadata):set(commands.help, "fnl/docstring", "Show this message.") local function reload(module_name, env, on_values, on_error) - local _497_, _498_ = pcall(specials["load-code"]("return require(...)", env), module_name) - if ((_497_ == true) and (nil ~= _498_)) then - local old = _498_ + local _534_, _535_ = pcall(specials["load-code"]("return require(...)", env), module_name) + if ((_534_ == true) and (nil ~= _535_)) then + local old = _535_ local _ package.loaded[module_name] = nil _ = nil @@ -313,36 +379,40 @@ package.preload["fennel.repl"] = package.preload["fennel.repl"] or function(...) for k in pairs(old) do if (nil == (new0)[k]) then old[k] = nil + else end end package.loaded[module_name] = old + else end return on_values({"ok"}) - elseif ((_497_ == false) and (nil ~= _498_)) then - local msg = _498_ - local function _503_() - local _502_ = msg:gsub("\n.*", "") - return _502_ + elseif ((_534_ == false) and (nil ~= _535_)) then + local msg = _535_ + local function _540_() + local _539_ = msg:gsub("\n.*", "") + return _539_ end - return on_error("Runtime", _503_()) + return on_error("Runtime", _540_()) + else + return nil end end local function run_command(read, on_error, f) - local _505_, _506_, _507_ = pcall(read) - if ((_505_ == true) and (_506_ == true) and (nil ~= _507_)) then - local val = _507_ + local _542_, _543_, _544_ = pcall(read) + if ((_542_ == true) and (_543_ == true) and (nil ~= _544_)) then + local val = _544_ return f(val) - elseif ((_505_ == false) and true and true) then - local _3fparse_ok = _506_ - local _3ferr = _507_ + elseif (_542_ == false) then return on_error("Parse", "Couldn't parse input.") + else + return nil end end commands.reload = function(env, read, on_values, on_error) - local function _509_(_241) + local function _546_(_241) return reload(tostring(_241), env, on_values, on_error) end - return run_command(read, on_error, _509_) + return run_command(read, on_error, _546_) end do end (compiler.metadata):set(commands.reload, "fnl/docstring", "Reload the specified module.") commands.reset = function(env, _, on_values) @@ -351,70 +421,84 @@ package.preload["fennel.repl"] = package.preload["fennel.repl"] or function(...) end do end (compiler.metadata):set(commands.reset, "fnl/docstring", "Erase all repl-local scope.") commands.complete = function(env, read, on_values, on_error, scope, chars) - local function _510_() + local function _547_() return on_values(completer(env, scope, string.char(unpack(chars)):gsub(",complete +", ""):sub(1, -2))) end - return run_command(read, on_error, _510_) + return run_command(read, on_error, _547_) end do end (compiler.metadata):set(commands.complete, "fnl/docstring", "Print all possible completions for a given input symbol.") - local function apropos_2a(pattern, module, prefix, seen, names) - for name, module0 in pairs(module) do - if (("string" == type(name)) and (package ~= module0)) then - local _511_ = type(module0) - if (_511_ == "function") then + 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 _548_ = type(subtbl) + if (_548_ == "function") then if ((prefix .. name)):match(pattern) then table.insert(names, (prefix .. name)) + else end - elseif (_511_ == "table") then - if not seen[module0] then - local _514_ + elseif (_548_ == "table") then + if not seen[subtbl] then + local _551_ do - local _513_ = seen - _513_[module0] = true - _514_ = _513_ + local _550_ = seen + _550_[subtbl] = true + _551_ = _550_ end - apropos_2a(pattern, module0, (prefix .. name:gsub("%.", "/") .. "."), _514_, names) + apropos_2a(pattern, subtbl, (prefix .. name:gsub("%.", "/") .. "."), _551_, names) + else end + else end + else end end return names end local function apropos(pattern) local names = apropos_2a(pattern, package.loaded, "", {}, {}) - local tbl_13_auto = {} + local tbl_14_auto = {} + local i_15_auto = #tbl_14_auto for _, name in ipairs(names) do - tbl_13_auto[(#tbl_13_auto + 1)] = name:gsub("^_G%.", "") + 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 + else + end end - return tbl_13_auto + return tbl_14_auto end - commands.apropos = function(env, read, on_values, on_error, scope) - local function _518_(_241) + commands.apropos = function(_env, read, on_values, on_error, _scope) + local function _556_(_241) return on_values(apropos(tostring(_241))) end - return run_command(read, on_error, _518_) + return run_command(read, on_error, _556_) 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 do - local tbl_13_auto = {} + local tbl_14_auto = {} + local i_15_auto = #tbl_14_auto for p in path:gmatch("[^%.]+") do - tbl_13_auto[(#tbl_13_auto + 1)] = p + 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 + else + end end - paths = tbl_13_auto + paths = tbl_14_auto end local tgt = package.loaded for _, path0 in ipairs(paths) do - local _520_ + if (nil == tgt) then break end + local _559_ do - local _519_ = path0:gsub("%/", ".") - _520_ = _519_ - end - tgt = tgt[_520_] - if (nil == tgt) then - break + local _558_ = path0:gsub("%/", ".") + _559_ = _558_ end + tgt = tgt[_559_] end return tgt end @@ -423,117 +507,198 @@ package.preload["fennel.repl"] = package.preload["fennel.repl"] or function(...) for _, path in ipairs(apropos(".*")) do local tgt = apropos_follow_path(path) if ("function" == type(tgt)) then - local _522_ = (compiler.metadata):get(tgt, "fnl/docstring") - if (nil ~= _522_) then - local docstr = _522_ + local _560_ = (compiler.metadata):get(tgt, "fnl/docstring") + if (nil ~= _560_) then + local docstr = _560_ if docstr:match(pattern) then table.insert(names, path) + else end + else end + else end end return names end - commands["apropos-doc"] = function(env, read, on_values, on_error, scope) - local function _526_(_241) + commands["apropos-doc"] = function(_env, read, on_values, on_error, _scope) + local function _564_(_241) return on_values(apropos_doc(tostring(_241))) end - return run_command(read, on_error, _526_) + return run_command(read, on_error, _564_) 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(pattern) + local function apropos_show_docs(on_values, pattern) for _, path in ipairs(apropos(pattern)) do local tgt = apropos_follow_path(path) if (("function" == type(tgt)) and (compiler.metadata):get(tgt, "fnl/docstring")) then - print(specials.doc(tgt, path)) - print() + on_values(specials.doc(tgt, path)) + on_values() + else end end return nil end - commands["apropos-show-docs"] = function(env, read, _, on_error, scope) - local function _528_(_241) - return apropos_show_docs(tostring(_241)) + commands["apropos-show-docs"] = function(_env, read, on_values, on_error) + local function _566_(_241) + return apropos_show_docs(on_values, tostring(_241)) end - return run_command(read, on_error, _528_) + return run_command(read, on_error, _566_) end do end (compiler.metadata):set(commands["apropos-show-docs"], "fnl/docstring", "Print all documentations matching a pattern in function name") - local function load_plugin_commands() - if (utils.root and utils.root.options and utils.root.options.plugins) then - for _, plugin in ipairs(utils.root.options.plugins) do - for name, f in pairs(plugin) do - local _529_ = name:match("^repl%-command%-(.*)") - if (nil ~= _529_) then - local cmd_name = _529_ - commands[cmd_name] = (commands[cmd_name] or f) + local function resolve(identifier, _567_, scope) + local _arg_568_ = _567_ + local ___replLocals___ = _arg_568_["___replLocals___"] + local env = _arg_568_ + local e + local function _569_(_241, _242) + return (___replLocals___[_242] or env[_242]) + end + e = setmetatable({}, {__index = _569_}) + local code = compiler["compile-string"](tostring(identifier), {scope = scope}) + return specials["load-code"](code, e)() + end + commands.find = function(env, read, on_values, on_error, scope) + local function _570_(_241) + local _571_ + do + local _572_ = utils["sym?"](_241) + if (nil ~= _572_) then + local _573_ = resolve(_572_, env, scope) + if (nil ~= _573_) then + _571_ = debug.getinfo(_573_) + else + _571_ = _573_ end + else + _571_ = _572_ end end - return nil + if ((_G.type(_571_) == "table") and ((_571_).what == "Lua") and (nil ~= (_571_).short_src) and (nil ~= (_571_).source) and (nil ~= (_571_).linedefined)) then + local src = (_571_).short_src + local source = (_571_).source + local line = (_571_).linedefined + local fnlsrc + do + local t_576_ = compiler.sourcemap + if (nil ~= t_576_) then + t_576_ = (t_576_)[source] + else + end + if (nil ~= t_576_) then + t_576_ = (t_576_)[line] + else + end + if (nil ~= t_576_) then + t_576_ = (t_576_)[2] + else + end + fnlsrc = t_576_ + end + return on_values({string.format("%s:%s", src, (fnlsrc or line))}) + elseif (_571_ == nil) then + return on_error("Repl", "Unknown value") + elseif true then + local _ = _571_ + return on_error("Repl", "No source info") + else + return nil + end end + return run_command(read, on_error, _570_) + end + do end (compiler.metadata):set(commands.find, "fnl/docstring", "Print the filename and line number for a given function") + commands.doc = function(env, read, on_values, on_error, scope) + local function _581_(_241) + local name = tostring(_241) + local target = (scope.specials[name] or scope.macros[name] or resolve(name, env, scope)) + return on_values({specials.doc(target, name)}) + end + return run_command(read, on_error, _581_) + end + do end (compiler.metadata):set(commands.doc, "fnl/docstring", "Print the docstring and arglist for a function, macro, or special form.") + local function load_plugin_commands(plugins) + for _, plugin in ipairs((plugins or {})) do + for name, f in pairs(plugin) do + local _582_ = name:match("^repl%-command%-(.*)") + if (nil ~= _582_) then + local cmd_name = _582_ + commands[cmd_name] = (commands[cmd_name] or f) + else + end + end + end + return nil end local function run_command_loop(input, read, loop, env, on_values, on_error, scope, chars) - load_plugin_commands() local command_name = input:match(",([^%s/]+)") do - local _532_ = commands[command_name] - if (nil ~= _532_) then - local command = _532_ + local _584_ = commands[command_name] + if (nil ~= _584_) then + local command = _584_ command(env, read, on_values, on_error, scope, chars) - else - local _ = _532_ + elseif true then + local _ = _584_ if ("exit" ~= command_name) then on_values({"Unknown command", command_name}) + else end + else end end if ("exit" ~= command_name) then return loop() + else + return nil end end local function repl(options) local old_root_options = utils.root.options - local env - if options.env then - env = specials["wrap-env"](options.env) - else - env = setmetatable({}, {__index = (rawget(_G, "_ENV") or _G)}) - end + local env = specials["wrap-env"]((options.env or (rawget(_G, "_ENV") or _G))) local save_locals_3f = ((options.saveLocals ~= false) and env.debug and env.debug.getlocal) - local opts = {} - local _ - for k, v in pairs(options) do - opts[k] = v - end - _ = nil + local opts = utils.copy(options) 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) - local pp = (opts.pp or tostring) + local pp = (opts.pp or view) local byte_stream, clear_stream = parser.granulate(read_chunk) local chars = {} local read, reset = nil, nil - local function _537_(parser_state) + local function _588_(parser_state) local c = byte_stream(parser_state) table.insert(chars, c) return c end - read, reset = parser.parser(_537_) - local scope = compiler["make-scope"]() + read, reset = parser.parser(_588_) + opts.env, opts.scope = env, compiler["make-scope"]() opts.useMetadata = (options.useMetadata ~= false) if (opts.allowedGlobals == nil) then - opts.allowedGlobals = specials["current-global-names"](opts.env) + opts.allowedGlobals = specials["current-global-names"](env) + else end if opts.registerCompleter then - local function _541_() - local _539_ = env - local _540_ = scope - local function _542_(...) - return completer(_539_, _540_, ...) + local function _592_() + local _590_ = env + local _591_ = opts.scope + local function _593_(...) + return completer(_590_, _591_, ...) end - return _542_ + return _593_ end - opts.registerCompleter(_541_()) + opts.registerCompleter(_592_()) + else + end + load_plugin_commands(opts.plugins) + if save_locals_3f then + local function newindex(t, k, v) + if opts.scope.unmanglings[k] then + return rawset(t, k, v) + else + return nil + end + end + env.___replLocals___ = setmetatable({}, {__newindex = newindex}) + else end local function print_values(...) local vals = {...} @@ -548,63 +713,64 @@ package.preload["fennel.repl"] = package.preload["fennel.repl"] or function(...) for k in pairs(chars) do chars[k] = nil end + reset() local ok, parse_ok_3f, x = pcall(read) local src_string = string.char(unpack(chars)) - reset() - utils.root.options = opts if not ok then on_error("Parse", parse_ok_3f) clear_stream() return loop() elseif command_3f(src_string) then - return run_command_loop(src_string, read, loop, env, on_values, on_error, scope, chars) + return run_command_loop(src_string, read, loop, env, on_values, on_error, opts.scope, chars) else if parse_ok_3f then do - local _544_, _545_ = nil, nil - local function _547_() - local _546_ = opts - _546_["env"] = env - _546_["source"] = src_string - _546_["scope"] = scope - return _546_ + local _597_, _598_ = nil, nil + local function _600_() + local _599_ = opts + _599_["source"] = src_string + return _599_ end - _544_, _545_ = pcall(compiler.compile, x, _547_()) - if ((_544_ == false) and (nil ~= _545_)) then - local msg = _545_ + _597_, _598_ = pcall(compiler.compile, x, _600_()) + if ((_597_ == false) and (nil ~= _598_)) then + local msg = _598_ clear_stream() on_error("Compile", msg) - elseif ((_544_ == true) and (nil ~= _545_)) then - local src = _545_ + elseif ((_597_ == true) and (nil ~= _598_)) then + local src = _598_ local src0 if save_locals_3f then - src0 = splice_save_locals(env, src) + src0 = splice_save_locals(env, src, opts.scope) else src0 = src end - local _549_, _550_ = pcall(specials["load-code"], src0, env) - if ((_549_ == false) and (nil ~= _550_)) then - local msg = _550_ + local _602_, _603_ = pcall(specials["load-code"], src0, env) + if ((_602_ == false) and (nil ~= _603_)) then + local msg = _603_ clear_stream() on_error("Lua Compile", msg, src0) - elseif (true and (nil ~= _550_)) then - local _0 = _549_ - local chunk = _550_ - local function _551_() + elseif (true and (nil ~= _603_)) then + local _ = _602_ + local chunk = _603_ + local function _604_() return print_values(chunk()) end - local function _552_() - local function _553_(...) + local function _605_() + local function _606_(...) return on_error("Runtime", ...) end - return _553_ + return _606_ end - xpcall(_551_, _552_()) + xpcall(_604_, _605_()) + else end + else end end utils.root.options = old_root_options return loop() + else + return nil end end end @@ -620,14 +786,14 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct local unpack = (table.unpack or _G.unpack) local SPECIALS = compiler.scopes.global.specials local function wrap_env(env) - local function _309_(_, key) + local function _345_(_, key) if (type(key) == "string") then return env[compiler["global-unmangling"](key)] else return env[key] end end - local function _311_(_, key, value) + local function _347_(_, key, value) if (type(key) == "string") then env[compiler["global-unmangling"](key)] = value return nil @@ -636,56 +802,54 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct return nil end end - local function _313_() + local function _349_() local function putenv(k, v) - local _314_ + local _350_ if (type(k) == "string") then - _314_ = compiler["global-unmangling"](k) + _350_ = compiler["global-unmangling"](k) else - _314_ = k + _350_ = k end - return _314_, v + return _350_, v end return next, utils.kvmap(env, putenv), nil end - return setmetatable({}, {__index = _309_, __newindex = _311_, __pairs = _313_}) + return setmetatable({}, {__index = _345_, __newindex = _347_, __pairs = _349_}) end - local function current_global_names(env) + local function current_global_names(_3fenv) local mt do - local _316_ = getmetatable(env) - local function _317_() - local __pairs = (_316_).__pairs - return __pairs - end - if (((_G.type(_316_) == "table") and true) and _317_()) then - local __pairs = (_316_).__pairs - local tbl_10_auto = {} - for k, v in __pairs(env) do - local _318_, _319_ = k, v - if ((nil ~= _318_) and (nil ~= _319_)) then - local k_11_auto = _318_ - local v_12_auto = _319_ - tbl_10_auto[k_11_auto] = v_12_auto + local _352_ = getmetatable(_3fenv) + if ((_G.type(_352_) == "table") and (nil ~= (_352_).__pairs)) then + local mtpairs = (_352_).__pairs + local tbl_11_auto = {} + for k, v in mtpairs(_3fenv) do + local _353_, _354_ = k, v + if ((nil ~= _353_) and (nil ~= _354_)) then + local k_12_auto = _353_ + local v_13_auto = _354_ + tbl_11_auto[k_12_auto] = v_13_auto + else end end - mt = tbl_10_auto - elseif (_316_ == nil) then - mt = (env or _G) + mt = tbl_11_auto + elseif (_352_ == nil) then + mt = (_3fenv or _G) else - mt = nil + mt = nil end end return (mt and utils.kvmap(mt, compiler["global-unmangling"])) end - local function load_code(code, environment, filename) - local environment0 = (environment or rawget(_G, "_ENV") or _G) + local function load_code(code, _3fenv, _3ffilename) + local env = (_3fenv or rawget(_G, "_ENV") or _G) if (rawget(_G, "setfenv") and rawget(_G, "loadstring")) then - local f = assert(_G.loadstring(code, filename)) - _G.setfenv(f, environment0) - return f + local f = assert(_G.loadstring(code, _3ffilename)) + local _357_ = f + setfenv(_357_, env) + return _357_ else - return assert(load(code, filename, "t", environment0)) + return assert(load(code, _3ffilename, "t", env)) end end local function doc_2a(tgt, name) @@ -696,13 +860,13 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct 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 {"#"}), " ") - local _323_ + local _359_ if (#arglist > 0) then - _323_ = " " + _359_ = " " else - _323_ = "" + _359_ = "" end - return string.format("(%s%s%s)\n %s", name, _323_, arglist, docstring) + return string.format("(%s%s%s)\n %s", name, _359_, arglist, docstring) else return string.format("%s\n %s", name, docstring) end @@ -712,36 +876,38 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct 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, start) - local start0 = (start or 2) + local function compile_do(ast, scope, parent, _3fstart) + local start = (_3fstart or 2) local len = #ast local sub_scope = compiler["make-scope"](scope) - for i = start0, len do + for i = start, len do compiler.compile1(ast[i], sub_scope, parent, {nval = 0}) end return nil end - SPECIALS["do"] = function(ast, scope, parent, opts, start, chunk, sub_scope, pre_syms) - local start0 = (start or 2) - local sub_scope0 = (sub_scope or compiler["make-scope"](scope)) - local chunk0 = (chunk or {}) + 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 {}) local len = #ast local retexprs = {returned = true} local function compile_body(outer_target, outer_tail, outer_retexprs) - if (len < start0) then - compiler.compile1(nil, sub_scope0, chunk0, {tail = outer_tail, target = outer_target}) + if (len < start) then + compiler.compile1(nil, sub_scope, chunk, {tail = outer_tail, target = outer_target}) else - for i = start0, len do + for i = start, len do 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_scope0, chunk0, subopts) + local subexprs = compiler.compile1(ast[i], sub_scope, chunk, subopts) if (i ~= len) then compiler["keep-side-effects"](subexprs, parent, nil, ast[i]) + else end end end - compiler.emit(parent, chunk0, ast) + compiler.emit(parent, chunk, ast) compiler.emit(parent, "end", ast) + utils.hook("do", ast, sub_scope) return (outer_retexprs or retexprs) end if (opts.target or (opts.nval == 0) or opts.tail) then @@ -750,7 +916,7 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct elseif opts.nval then local syms = {} for i = 1, opts.nval do - local s = ((pre_syms and pre_syms[i]) or compiler.gensym(scope)) + local s = ((_3fpre_syms and (_3fpre_syms)[i]) or compiler.gensym(scope)) do end (syms)[i] = s retexprs[i] = utils.expr(s, "sym") end @@ -767,7 +933,6 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct fargs = "" end compiler.emit(parent, string.format("local function %s(%s)", fname, fargs), ast) - utils.hook("do", ast, sub_scope0) return compile_body(nil, true, utils.expr((fname .. "(" .. fargs .. ")"), "statement")) end end @@ -782,33 +947,45 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct for j = 2, #subexprs do table.insert(exprs, subexprs[j]) end + else end end return exprs end doc_special("values", {"..."}, "Return multiple values from a function. Must be in tail position.") local function deep_tostring(x, key_3f) - local elems = {} if utils["sequence?"](x) then - local _332_ + local _368_ do - local tbl_13_auto = {} + local tbl_14_auto = {} + local i_15_auto = #tbl_14_auto for _, v in ipairs(x) do - tbl_13_auto[(#tbl_13_auto + 1)] = deep_tostring(v) + 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 - _332_ = tbl_13_auto + _368_ = tbl_14_auto end - return ("[" .. table.concat(_332_, " ") .. "]") + return ("[" .. table.concat(_368_, " ") .. "]") elseif utils["table?"](x) then - local _333_ + local _370_ do - local tbl_13_auto = {} + local tbl_14_auto = {} + local i_15_auto = #tbl_14_auto for k, v in pairs(x) do - tbl_13_auto[(#tbl_13_auto + 1)] = (deep_tostring(k, true) .. " " .. deep_tostring(v)) + 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 end - _333_ = tbl_13_auto + _370_ = tbl_14_auto end - return ("{" .. table.concat(_333_, " ") .. "}") + return ("{" .. table.concat(_370_, " ") .. "}") elseif (key_3f and (type(x) == "string") and x:find("^[-%w?\\^_!$%&*+./@:|<=>]+$")) then return (":" .. x) elseif (type(x) == "string") then @@ -820,28 +997,31 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct local function set_fn_metadata(arg_list, docstring, parent, fn_name) if utils.root.options.useMetadata then local args - local function _335_(_241) + local function _373_(_241) return ("\"%s\""):format(deep_tostring(_241)) end - args = utils.map(arg_list, _335_) + args = utils.map(arg_list, _373_) 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 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, ", "))) + else + return nil end end local function get_fn_name(ast, scope, fn_name, multi) if (fn_name and (fn_name[1] ~= "nil")) then - local _338_ + local _376_ if not multi then - _338_ = compiler["declare-local"](fn_name, {}, scope, ast) + _376_ = compiler["declare-local"](fn_name, {}, scope, ast) else - _338_ = (compiler["symbol-to-expression"](fn_name, scope))[1] + _376_ = (compiler["symbol-to-expression"](fn_name, scope))[1] end - return _338_, not multi, 3 + return _376_, not multi, 3 else return nil, true, 2 end @@ -850,13 +1030,13 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct 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 _341_ + local _379_ if local_3f then - _341_ = "local function %s(%s)" + _379_ = "local function %s(%s)" else - _341_ = "%s = function(%s)" + _379_ = "%s = function(%s)" end - compiler.emit(parent, string.format(_341_, fn_name, table.concat(arg_name_list, ", ")), ast) + compiler.emit(parent, string.format(_379_, fn_name, table.concat(arg_name_list, ", ")), ast) compiler.emit(parent, f_chunk, ast) compiler.emit(parent, "end", ast) set_fn_metadata(arg_list, docstring, parent, fn_name) @@ -870,9 +1050,9 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct SPECIALS.fn = function(ast, scope, parent) local f_scope do - local _343_ = compiler["make-scope"](scope) - do end (_343_)["vararg"] = false - f_scope = _343_ + local _381_ = compiler["make-scope"](scope) + do end (_381_)["vararg"] = false + f_scope = _381_ end local f_chunk = {} local fn_sym = utils["sym?"](ast[2]) @@ -893,7 +1073,7 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct compiler.destructure(arg, raw, ast, f_scope, f_chunk, {declaration = true, nomulti = true, symtype = "arg"}) return declared else - return compiler.assert(false, ("expected symbol for function parameter: %s"):format(tostring(arg)), ast[2]) + 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) @@ -912,50 +1092,39 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct doc_special("fn", {"name?", "args", "docstring?", "..."}, "Function syntax. May optionally include a name and docstring.\nIf a name is provided, the function will be bound in the current scope.\nWhen called with the wrong number of args, excess args will be discarded\nand lacking args will be nil, use lambda for arity-checked functions.", true) SPECIALS.lua = function(ast, _, parent) compiler.assert(((#ast == 2) or (#ast == 3)), "expected 1 or 2 arguments", ast) - local _348_ + local _386_ do - local _347_ = utils["sym?"](ast[2]) - if _347_ then - _348_ = tostring(_347_) + local _385_ = utils["sym?"](ast[2]) + if (nil ~= _385_) then + _386_ = tostring(_385_) else - _348_ = _347_ + _386_ = _385_ end end - if ("nil" ~= _348_) then + if ("nil" ~= _386_) then table.insert(parent, {ast = ast, leaf = tostring(ast[2])}) + else end - local _352_ + local _390_ do - local _351_ = utils["sym?"](ast[3]) - if _351_ then - _352_ = tostring(_351_) + local _389_ = utils["sym?"](ast[3]) + if (nil ~= _389_) then + _390_ = tostring(_389_) else - _352_ = _351_ + _390_ = _389_ end end - if ("nil" ~= _352_) then + if ("nil" ~= _390_) then return tostring(ast[3]) - end - end - SPECIALS.doc = function(ast, scope, parent) - assert(utils.root.options.useMetadata, "can't look up doc with metadata disabled.") - compiler.assert((#ast == 2), "expected one argument", ast) - local target = tostring(ast[2]) - local special_or_macro = (scope.specials[target] or scope.macros[target]) - if special_or_macro then - return ("print(%q)"):format(doc_2a(special_or_macro, target)) else - local _let_355_ = compiler.compile1(ast[2], scope, parent, {nval = 1}) - local value = _let_355_[1] - return ("print(require('%s').doc(%s, '%s'))"):format((utils.root.options.moduleName or "fennel"), tostring(value), tostring(ast[2])) + return nil end end - doc_special("doc", {"x"}, "Print the docstring and arglist for a function, macro, or special form.") local function dot(ast, scope, parent) compiler.assert((1 < #ast), "expected table argument", ast) local len = #ast - local _let_357_ = compiler.compile1(ast[2], scope, parent, {nval = 1}) - local lhs = _let_357_[1] + local _let_393_ = compiler.compile1(ast[2], scope, parent, {nval = 1}) + local lhs = _let_393_[1] if (len == 2) then return tostring(lhs) else @@ -965,8 +1134,8 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct if ((type(index) == "string") and utils["valid-lua-identifier?"](index)) then table.insert(indices, ("." .. index)) else - local _let_358_ = compiler.compile1(index, scope, parent, {nval = 1}) - local index0 = _let_358_[1] + local _let_394_ = compiler.compile1(index, scope, parent, {nval = 1}) + local index0 = _let_394_[1] table.insert(indices, ("[" .. tostring(index0) .. "]")) end end @@ -1011,21 +1180,26 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct end doc_special("var", {"name", "val"}, "Introduce new mutable local.") local function kv_3f(t) - local _362_ + local _398_ do - local tbl_13_auto = {} + local tbl_14_auto = {} + local i_15_auto = #tbl_14_auto for k in pairs(t) do - local _363_ + local val_16_auto if not ("number" == type(k)) then - _363_ = k + val_16_auto = k + else + val_16_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 else - _363_ = nil end - tbl_13_auto[(#tbl_13_auto + 1)] = _363_ end - _362_ = tbl_13_auto + _398_ = tbl_14_auto end - return (_362_)[1] + return (_398_)[1] end SPECIALS.let = function(ast, scope, parent, opts) local bindings = ast[2] @@ -1052,22 +1226,24 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct end end local function disambiguate_3f(rootstr, parent) - local function _367_() - local _366_ = get_prev_line(parent) - if (nil ~= _366_) then - local prev_line = _366_ + local function _403_() + local _402_ = get_prev_line(parent) + if (nil ~= _402_) then + local prev_line = _402_ return prev_line:match("%)$") + else + return nil end end - return (rootstr:match("^{") or _367_()) + return (rootstr:match("^{") or _403_()) end SPECIALS.tset = function(ast, scope, parent) compiler.assert((#ast > 3), "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_369_ = compiler.compile1(ast[i], scope, parent, {nval = 1}) - local key = _let_369_[1] + local _let_405_ = compiler.compile1(ast[i], scope, parent, {nval = 1}) + local key = _let_405_[1] table.insert(keys, tostring(key)) end local value = (compiler.compile1(ast[#ast], scope, parent, {nval = 1}))[1] @@ -1098,6 +1274,7 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct end end local function if_2a(ast, scope, parent, opts) + compiler.assert((2 < #ast), "expected condition and body", ast) local do_scope = compiler["make-scope"](scope) local branches = {} local wrapper, inner_tail, inner_target, target_exprs = calculate_target(scope, opts) @@ -1108,6 +1285,10 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct compiler["keep-side-effects"](compiler.compile1(ast[i], cscope, chunk, body_opts), chunk, nil, ast[i]) return {chunk = chunk, scope = cscope} end + if (1 == (#ast % 2)) then + table.insert(ast, utils.sym("nil")) + else + end for i = 2, (#ast - 1), 2 do local condchunk = {} local res = compiler.compile1(ast[i], do_scope, condchunk, {nval = 1}) @@ -1118,8 +1299,7 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct branch.nested = ((i ~= 2) and (next(condchunk, nil) == nil)) table.insert(branches, branch) end - local has_else_3f = ((#ast > 3) and ((#ast % 2) == 0)) - local else_branch = (has_else_3f and compile_body(#ast)) + local else_branch = compile_body(#ast) local s = compiler.gensym(scope) local buffer = {} local last_buffer = buffer @@ -1132,12 +1312,7 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct fstr = "elseif %s then" end local cond = tostring(branch.cond) - local cond_line - if ((cond == "true") and branch.nested and (i == #branches) and not has_else_3f) then - cond_line = "else" - else - cond_line = fstr:format(cond) - end + local cond_line = fstr:format(cond) if branch.nested then compiler.emit(last_buffer, branch.condchunk, ast) else @@ -1148,13 +1323,8 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct compiler.emit(last_buffer, cond_line, ast) compiler.emit(last_buffer, branch.chunk, ast) if (i == #branches) then - if has_else_3f then - compiler.emit(last_buffer, "else", ast) - compiler.emit(last_buffer, else_branch.chunk, ast) - elseif (inner_target and (cond_line ~= "else")) then - compiler.emit(last_buffer, "else", ast) - compiler.emit(last_buffer, ("%s = nil"):format(inner_target), ast) - end + compiler.emit(last_buffer, "else", ast) + compiler.emit(last_buffer, else_branch.chunk, ast) compiler.emit(last_buffer, "end", ast) elseif not (branches[(i + 1)]).nested then local next_buffer = {} @@ -1162,6 +1332,7 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct compiler.emit(last_buffer, next_buffer, ast) compiler.emit(last_buffer, "end", ast) last_buffer = next_buffer + else end end if (wrapper == "iife") then @@ -1189,13 +1360,17 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct if ("until" == bindings[(#bindings - 1)]) then table.remove(bindings, (#bindings - 1)) return table.remove(bindings) + else + return nil end end local function compile_until(condition, scope, chunk) if condition then - local _let_379_ = compiler.compile1(condition, scope, chunk, {nval = 1}) - local condition_lua = _let_379_[1] + local _let_414_ = compiler.compile1(condition, scope, chunk, {nval = 1}) + local condition_lua = _let_414_[1] return compiler.emit(chunk, ("if %s then break end"):format(tostring(condition_lua)), utils.expr(condition, "expression")) + else + return nil end end SPECIALS.each = function(ast, scope, parent) @@ -1218,7 +1393,7 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct end end local bind_vars = utils.map(binding, destructure_binding) - local vals = compiler.compile1(iter, sub_scope, parent) + local vals = compiler.compile1(iter, scope, parent) local val_names = utils.map(vals, tostring) local chunk = {} compiler.emit(parent, ("for %s in %s do"):format(table.concat(bind_vars, ", "), table.concat(val_names, ", ")), ast) @@ -1264,7 +1439,7 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct compiler.assert((#ast >= 3), "expected body expression", ast[1]) compiler.assert((#ranges <= 3), "unexpected arguments", ranges[4]) for i = 1, math.min(#ranges, 3) do - range_args[i] = tostring((compiler.compile1(ranges[i], sub_scope, parent, {nval = 1}))[1]) + range_args[i] = tostring((compiler.compile1(ranges[i], scope, parent, {nval = 1}))[1]) end compiler.emit(parent, ("for %s = %s do"):format(compiler["declare-local"](binding_sym, {}, sub_scope, ast), table.concat(range_args, ", ")), ast) compile_until(until_condition, sub_scope, chunk) @@ -1275,10 +1450,10 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct 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_383_ = ast - local _ = _let_383_[1] - local _0 = _let_383_[2] - local method_string = _let_383_[3] + local _let_418_ = ast + local _ = _let_418_[1] + local _0 = _let_418_[2] + local method_string = _let_418_[3] local call_string if ((target.type == "literal") or (target.type == "varg") or (target.type == "expression")) then call_string = "(%s):%s(%s)" @@ -1300,18 +1475,18 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct end local function method_call(ast, scope, parent) compiler.assert((2 < #ast), "expected at least 2 arguments", ast) - local _let_385_ = compiler.compile1(ast[2], scope, parent, {nval = 1}) - local target = _let_385_[1] + local _let_420_ = compiler.compile1(ast[2], scope, parent, {nval = 1}) + local target = _let_420_[1] local args = {} for i = 4, #ast do local subexprs - local _386_ + local _421_ if (i ~= #ast) then - _386_ = 1 + _421_ = 1 else - _386_ = nil + _421_ = nil end - subexprs = compiler.compile1(ast[i], scope, parent, {nval = _386_}) + subexprs = compiler.compile1(ast[i], scope, parent, {nval = _421_}) utils.map(subexprs, tostring, args) end if ((type(ast[3]) == "string") and utils["valid-lua-identifier?"](ast[3])) then @@ -1329,7 +1504,7 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct for i = 2, #ast do table.insert(els, view(ast[i], {["one-line?"] = true})) end - return compiler.emit(parent, ("-- " .. table.concat(els, " ")), ast) + return compiler.emit(parent, ("--[[ " .. table.concat(els, " ") .. " ]]--"), ast) end doc_special("comment", {"..."}, "Comment which will be emitted in Lua output.", true) local function hashfn_max_used(f_scope, i, max) @@ -1349,10 +1524,10 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct compiler.assert((#ast == 2), "expected one argument", ast) local f_scope do - local _391_ = compiler["make-scope"](scope) - do end (_391_)["vararg"] = false - _391_["hashfn"] = true - f_scope = _391_ + local _426_ = compiler["make-scope"](scope) + do end (_426_)["vararg"] = false + _426_["hashfn"] = true + f_scope = _426_ end local f_chunk = {} local name = compiler.gensym(scope) @@ -1376,6 +1551,7 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct local max_used = hashfn_max_used(f_scope, 1, 0) if f_scope.vararg then compiler.assert((max_used == 0), "$ and $... in hashfn are mutually exclusive", ast) + else end local arg_str if f_scope.vararg then @@ -1389,53 +1565,52 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct return utils.expr(name, "sym") end doc_special("hashfn", {"..."}, "Function literal shorthand; args are either $... OR $1, $2, etc.") - local function arithmetic_special(name, zero_arity, unary_prefix, nval, ast, scope, parent) + local function arithmetic_special(name, zero_arity, unary_prefix, ast, scope, parent) local len = #ast local operands = {} local padded_op = (" " .. name .. " ") for i = 2, len do - local subexprs - local _395_ - if (i < len) then - _395_ = 1 + local subexprs = compiler.compile1(ast[i], scope, parent) + if (i == len) then + utils.map(subexprs, tostring, operands) else - _395_ = nil + table.insert(operands, tostring(subexprs[1])) end - subexprs = compiler.compile1(ast[i], scope, parent, {nval = _395_}) - utils.map(subexprs, tostring, operands) end - local _397_ = #operands - if (_397_ == 0) then - local _399_ + local _431_ = #operands + if (_431_ == 0) then + local _433_ do - local _398_ = zero_arity - compiler.assert(_398_, "Expected more than 0 arguments", ast) - _399_ = _398_ + local _432_ = zero_arity + compiler.assert(_432_, "Expected more than 0 arguments", ast) + _433_ = _432_ end - return utils.expr(_399_, "literal") - elseif (_397_ == 1) then + return utils.expr(_433_, "literal") + elseif (_431_ == 1) then if unary_prefix then return ("(" .. unary_prefix .. padded_op .. operands[1] .. ")") else return operands[1] end - else - local _ = _397_ + elseif true then + local _ = _431_ return ("(" .. table.concat(operands, padded_op) .. ")") + else + return nil end end - local function define_arithmetic_special(name, zero_arity, unary_prefix, lua_name) - local _405_ + local function define_arithmetic_special(name, zero_arity, unary_prefix, _3flua_name) + local _439_ do - local _402_ = (lua_name or name) - local _403_ = zero_arity - local _404_ = unary_prefix - local function _406_(...) - return arithmetic_special(_402_, _403_, _404_, 1, ...) + local _436_ = (_3flua_name or name) + local _437_ = zero_arity + local _438_ = unary_prefix + local function _440_(...) + return arithmetic_special(_436_, _437_, _438_, ...) end - _405_ = _406_ + _439_ = _440_ end - SPECIALS[name] = _405_ + SPECIALS[name] = _439_ return doc_special(name, {"a", "b", "..."}, "Arithmetic operator; works the same as Lua but accepts more arguments.") end define_arithmetic_special("+", "0") @@ -1447,10 +1622,10 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct define_arithmetic_special("/", nil, "1") define_arithmetic_special("//", nil, "1") SPECIALS["or"] = function(ast, scope, parent) - return arithmetic_special("or", "false", nil, nil, ast, scope, parent) + return arithmetic_special("or", "false", nil, ast, scope, parent) end SPECIALS["and"] = function(ast, scope, parent) - return arithmetic_special("and", "true", nil, nil, ast, scope, parent) + return arithmetic_special("and", "true", nil, ast, scope, parent) end 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.") @@ -1464,13 +1639,13 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct local prefixed_lib_name = ("bit." .. lib_name) for i = 2, len do local subexprs - local _407_ + local _441_ if (i ~= len) then - _407_ = 1 + _441_ = 1 else - _407_ = nil + _441_ = nil end - subexprs = compiler.compile1(ast[i], scope, parent, {nval = _407_}) + subexprs = compiler.compile1(ast[i], scope, parent, {nval = _441_}) utils.map(subexprs, tostring, operands) end if (#operands == 1) then @@ -1489,18 +1664,18 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct end end local function define_bitop_special(name, zero_arity, unary_prefix, native) - local _417_ + local _451_ do - local _413_ = native - local _414_ = name - local _415_ = zero_arity - local _416_ = unary_prefix - local function _418_(...) - return bitop_special(_413_, _414_, _415_, _416_, ...) + local _447_ = native + local _448_ = name + local _449_ = zero_arity + local _450_ = unary_prefix + local function _452_(...) + return bitop_special(_447_, _448_, _449_, _450_, ...) end - _417_ = _418_ + _451_ = _452_ end - SPECIALS[name] = _417_ + SPECIALS[name] = _451_ return nil end define_bitop_special("lshift", nil, "1", "<<") @@ -1514,15 +1689,15 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct 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, _419_, scope, parent) - local _arg_420_ = _419_ - local _ = _arg_420_[1] - local lhs_ast = _arg_420_[2] - local rhs_ast = _arg_420_[3] - local _let_421_ = compiler.compile1(lhs_ast, scope, parent, {nval = 1}) - local lhs = _let_421_[1] - local _let_422_ = compiler.compile1(rhs_ast, scope, parent, {nval = 1}) - local rhs = _let_422_[1] + local function native_comparator(op, _453_, scope, parent) + local _arg_454_ = _453_ + local _ = _arg_454_[1] + local lhs_ast = _arg_454_[2] + local rhs_ast = _arg_454_[3] + local _let_455_ = compiler.compile1(lhs_ast, scope, parent, {nval = 1}) + local lhs = _let_455_[1] + local _let_456_ = compiler.compile1(rhs_ast, scope, parent, {nval = 1}) + local rhs = _let_456_[1] return string.format("(%s %s %s)", tostring(lhs), op, tostring(rhs)) end local function double_eval_protected_comparator(op, chain_op, ast, scope, parent) @@ -1539,15 +1714,15 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct end return string.format("(function(%s) return %s end)(%s)", table.concat(arglist, ","), table.concat(comparisons, chain), table.concat(vals, ",")) end - local function define_comparator_special(name, lua_op, chain_op) + local function define_comparator_special(name, _3flua_op, _3fchain_op) do - local op = (lua_op or name) + local op = (_3flua_op or name) local function opfn(ast, scope, parent) compiler.assert((2 < #ast), "expected at least two arguments", ast) if (3 == #ast) then return native_comparator(op, ast, scope, parent) else - return double_eval_protected_comparator(op, chain_op, ast, scope, parent) + return double_eval_protected_comparator(op, _3fchain_op, ast, scope, parent) end end SPECIALS[name] = opfn @@ -1560,11 +1735,11 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct define_comparator_special("<=") define_comparator_special("=", "==") define_comparator_special("not=", "~=", "or") - local function define_unary_special(op, realop) + local function define_unary_special(op, _3frealop) local function opfn(ast, scope, parent) compiler.assert((#ast == 2), "expected one argument", ast) local tail = compiler.compile1(ast[2], scope, parent, {nval = 1}) - return ((realop or op) .. tostring(tail[1])) + return ((_3frealop or op) .. tostring(tail[1])) end SPECIALS[op] = opfn return nil @@ -1578,12 +1753,13 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct do end (SPECIALS)["~="] = SPECIALS["not="] SPECIALS["#"] = SPECIALS.length SPECIALS.quote = function(ast, scope, parent) - compiler.assert((#ast == 2), "expected one argument") + compiler.assert((#ast == 2), "expected one argument", ast) local runtime, this_scope = true, scope while this_scope do this_scope = this_scope.parent if (this_scope == compiler.scopes.compiler) then runtime = false + else end end return compiler["do-quote"](ast[2], scope, parent, runtime) @@ -1597,16 +1773,17 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct end local safe_require = nil local function safe_compiler_env() - return {table = utils.copy(table), math = utils.copy(math), string = utils.copy(string), pairs = pairs, 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} + return {table = utils.copy(table), math = utils.copy(math), string = utils.copy(string), pairs = pairs, 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} end local function combined_mt_pairs(env) local combined = {} - local _let_425_ = getmetatable(env) - local __index = _let_425_["__index"] + local _let_459_ = getmetatable(env) + local __index = _let_459_["__index"] if ("table" == type(__index)) then for k, v in pairs(__index) do combined[k] = v end + else end for k, v in next, env, nil do combined[k] = v @@ -1616,178 +1793,205 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct local function make_compiler_env(ast, scope, parent, _3fopts) local provided do - local _427_ = (_3fopts or utils.root.options) - if ((_G.type(_427_) == "table") and ((_427_)["compiler-env"] == "strict")) then + local _461_ = (_3fopts or utils.root.options) + if ((_G.type(_461_) == "table") and ((_461_)["compiler-env"] == "strict")) then provided = safe_compiler_env() - elseif ((_G.type(_427_) == "table") and (nil ~= (_427_).compilerEnv)) then - local compilerEnv = (_427_).compilerEnv + elseif ((_G.type(_461_) == "table") and (nil ~= (_461_).compilerEnv)) then + local compilerEnv = (_461_).compilerEnv provided = compilerEnv - elseif ((_G.type(_427_) == "table") and (nil ~= (_427_)["compiler-env"])) then - local compiler_env = (_427_)["compiler-env"] + elseif ((_G.type(_461_) == "table") and (nil ~= (_461_)["compiler-env"])) then + local compiler_env = (_461_)["compiler-env"] provided = compiler_env - else - local _ = _427_ + elseif true then + local _ = _461_ provided = safe_compiler_env(false) + else + provided = nil end end local env - local function _429_(base) + local function _463_(base) return utils.sym(compiler.gensym((compiler.scopes.macro or scope), base)) end - local function _430_() + local function _464_() return compiler.scopes.macro end - local function _431_(symbol) + local function _465_(symbol) compiler.assert(compiler.scopes.macro, "must call from macro", ast) return compiler.scopes.macro.manglings[tostring(symbol)] end - local function _432_(form) + local function _466_(form) compiler.assert(compiler.scopes.macro, "must call from macro", ast) return compiler.macroexpand(form, compiler.scopes.macro) end - 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, list = utils.list, ["list?"] = utils["list?"], ["multi-sym?"] = utils["multi-sym?"], sequence = utils.sequence, ["sequence?"] = utils["sequence?"], sym = utils.sym, ["sym?"] = utils["sym?"], ["table?"] = utils["table?"], ["varg?"] = utils["varg?"], view = view, gensym = _429_, ["get-scope"] = _430_, ["in-scope?"] = _431_, macroexpand = _432_} + 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, 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 = _463_, ["get-scope"] = _464_, ["in-scope?"] = _465_, macroexpand = _466_} env._G = env return setmetatable(env, {__index = provided, __newindex = provided, __pairs = combined_mt_pairs}) end - local cfg = string.gmatch(package.config, "([^\n]+)") - local dirsep, pathsep, pathmark = (cfg() or "/"), (cfg() or ";"), (cfg() or "?") - local pkg_config = {dirsep = dirsep, pathmark = pathmark, pathsep = pathsep} + local function _468_(...) + local tbl_14_auto = {} + local i_15_auto = #tbl_14_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 + else + end + end + return tbl_14_auto + end + local _local_467_ = _468_(...) + local dirsep = _local_467_[1] + local pathsep = _local_467_[2] + local pathmark = _local_467_[3] + local pkg_config = {dirsep = (dirsep or "/"), pathmark = (pathmark or ";"), pathsep = (pathsep or "?")} local function escapepat(str) return string.gsub(str, "[^%w]", "%%%1") end - local function search_module(modulename, pathstring) + local function search_module(modulename, _3fpathstring) local pathsepesc = escapepat(pkg_config.pathsep) local pattern = ("([^%s]*)%s"):format(pathsepesc, pathsepesc) local no_dot_module = modulename:gsub("%.", pkg_config.dirsep) - local fullpath = ((pathstring 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 _433_ = (io.open(filename) or io.open(filename2)) - if (nil ~= _433_) then - local file = _433_ + local _470_ = (io.open(filename) or io.open(filename2)) + if (nil ~= _470_) then + local file = _470_ file:close() return filename + else + return nil end end local function find_in_path(start) - local _435_ = fullpath:match(pattern, start) - if (nil ~= _435_) then - local path = _435_ + local _472_ = fullpath:match(pattern, start) + if (nil ~= _472_) then + local path = _472_ return (try_path(path) or find_in_path((start + #path + 1))) + else + return nil end end return find_in_path(1) end - local function make_searcher(options) - local function _437_(module_name) + local function make_searcher(_3foptions) + local function _474_(module_name) local opts = utils.copy(utils.root.options) - for k, v in pairs((options or {})) do + for k, v in pairs((_3foptions or {})) do opts[k] = v end opts["module-name"] = module_name - local _438_ = search_module(module_name) - if (nil ~= _438_) then - local filename = _438_ - local _441_ + local _475_ = search_module(module_name) + if (nil ~= _475_) then + local filename = _475_ + local _478_ do - local _439_ = filename - local _440_ = opts - local function _442_(...) - return utils["fennel-module"].dofile(_439_, _440_, ...) + local _476_ = filename + local _477_ = opts + local function _479_(...) + return utils["fennel-module"].dofile(_476_, _477_, ...) end - _441_ = _442_ + _478_ = _479_ end - return _441_, filename + return _478_, filename + else + return nil end end - return _437_ - end - local function macro_globals(env, globals) - local allowed = current_global_names(env) - for _, k in pairs((globals or {})) do - table.insert(allowed, k) - end - return allowed + return _474_ end local function fennel_macro_searcher(module_name) local opts do - local _444_ = utils.copy(utils.root.options) - do end (_444_)["env"] = "_COMPILER" - _444_["allowedGlobals"] = nil - opts = _444_ + local _481_ = utils.copy(utils.root.options) + do end (_481_)["env"] = "_COMPILER" + _481_["requireAsInclude"] = false + _481_["allowedGlobals"] = nil + opts = _481_ end - local _445_ = search_module(module_name, utils["fennel-module"]["macro-path"]) - if (nil ~= _445_) then - local filename = _445_ - local _448_ + local _482_ = search_module(module_name, utils["fennel-module"]["macro-path"]) + if (nil ~= _482_) then + local filename = _482_ + local _485_ do - local _446_ = filename - local _447_ = opts - local function _449_(...) - return utils["fennel-module"].dofile(_446_, _447_, ...) + local _483_ = filename + local _484_ = opts + local function _486_(...) + return utils["fennel-module"].dofile(_483_, _484_, ...) end - _448_ = _449_ + _485_ = _486_ end - return _448_, filename + return _485_, filename + else + return nil end end local function lua_macro_searcher(module_name) - local _451_ = search_module(module_name, package.path) - if (nil ~= _451_) then - local filename = _451_ + local _488_ = search_module(module_name, package.path) + if (nil ~= _488_) then + local filename = _488_ local code do local f = io.open(filename) - local function close_handlers_7_auto(ok_8_auto, ...) + local function close_handlers_8_auto(ok_9_auto, ...) f:close() - if ok_8_auto then + if ok_9_auto then return ... else return error(..., 0) end end - local function _453_() + local function _490_() return assert(f:read("*a")) end - code = close_handlers_7_auto(_G.xpcall(_453_, (package.loaded.fennel or debug).traceback)) + code = close_handlers_8_auto(_G.xpcall(_490_, (package.loaded.fennel or debug).traceback)) end local chunk = load_code(code, make_compiler_env(), filename) return chunk, filename + else + return nil end end - local macro_searchers = {lua_macro_searcher, fennel_macro_searcher} + local macro_searchers = {fennel_macro_searcher, lua_macro_searcher} local function search_macro_module(modname, n) - local _455_ = macro_searchers[n] - if (nil ~= _455_) then - local f = _455_ - local _456_, _457_ = f(modname) - if ((nil ~= _456_) and true) then - local loader = _456_ - local _3ffilename = _457_ + local _492_ = macro_searchers[n] + if (nil ~= _492_) then + local f = _492_ + local _493_, _494_ = f(modname) + if ((nil ~= _493_) and true) then + local loader = _493_ + local _3ffilename = _494_ return loader, _3ffilename - else - local _ = _456_ + elseif true then + local _ = _493_ return search_macro_module(modname, (n + 1)) + else + return nil end + else + return nil end end local function metadata_only_fennel(modname) 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} + else + return nil end end - local function _461_(modname) - local function _462_() + local function _498_(modname) + local function _499_() local loader, filename = search_macro_module(modname, 1) compiler.assert(loader, (modname .. " module not found.")) do end (macro_loaded)[modname] = loader(modname, filename) return macro_loaded[modname] end - return (macro_loaded[modname] or metadata_only_fennel(modname) or _462_()) + return (macro_loaded[modname] or metadata_only_fennel(modname) or _499_()) end - safe_require = _461_ + safe_require = _498_ 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 @@ -1796,26 +2000,31 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct end return nil end - local function resolve_module_name(_463_, scope, parent, opts) - local _arg_464_ = _463_ - local filename = _arg_464_["filename"] - local second = _arg_464_[2] + local function resolve_module_name(_500_, _scope, _parent, opts) + local _arg_501_ = _500_ + local filename = _arg_501_["filename"] + local second = _arg_501_[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 - SPECIALS["require-macros"] = function(ast, scope, parent, real_ast) - compiler.assert((#ast == 2), "Expected one module name argument", (real_ast or 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(("string" == type(modname)), "module name must compile to string", (real_ast or ast)) + compiler.assert(("string" == type(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) + else + end + if ("import-macros" == tostring(ast[1])) then + return macro_loaded[modname] + else + return add_macros(macro_loaded[modname], ast, scope, parent) end - return add_macros(macro_loaded[modname], ast, scope, parent) end 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) @@ -1823,6 +2032,7 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct local forms = {} if utils.root.options.requireAsInclude then subscope.specials.require = compiler["require-include"] + else end for _, val in parser.parser(parser["string-stream"](src), path) do table.insert(forms, val) @@ -1844,18 +2054,18 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct local src do local f = assert(io.open(path)) - local function close_handlers_7_auto(ok_8_auto, ...) + local function close_handlers_8_auto(ok_9_auto, ...) f:close() - if ok_8_auto then + if ok_9_auto then return ... else return error(..., 0) end end - local function _469_() + local function _507_() return f:read("*all"):gsub("[\13\n]*$", "") end - src = close_handlers_7_auto(_G.xpcall(_469_, (package.loaded.fennel or debug).traceback)) + src = close_handlers_8_auto(_G.xpcall(_507_, (package.loaded.fennel or debug).traceback)) end local ret = utils.expr(("require(\"" .. mod .. "\")"), "statement") local target = ("package.preload[%q]"):format(mod) @@ -1879,22 +2089,23 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct if (utils.root.scope.includes[mod] == "fnl/loading") then compiler.assert(fallback, "circular include detected", ast) return fallback(modexpr) + else + return nil end end SPECIALS.include = function(ast, scope, parent, opts) compiler.assert((#ast == 2), "expected one argument", ast) local modexpr do - local _472_, _473_ = pcall(resolve_module_name, ast, scope, parent, opts) - if ((_472_ == true) and (nil ~= _473_)) then - local modname = _473_ + local _510_, _511_ = pcall(resolve_module_name, ast, scope, parent, opts) + if ((_510_ == true) and (nil ~= _511_)) then + local modname = _511_ modexpr = utils.expr(string.format("%q", modname), "literal") - elseif (true and (nil ~= _473_)) then - local _ = _472_ - local err = _473_ + elseif true then + local _ = _510_ modexpr = (compiler.compile1(ast[2], scope, parent, {nval = 1}))[1] else - modexpr = nil + modexpr = nil end end if ((modexpr.type ~= "literal") or ((modexpr[1]):byte() ~= 34)) then @@ -1910,13 +2121,13 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct utils.root.options["module-name"] = mod _ = nil local res - local function _477_() - local _476_ = search_module(mod) - if (nil ~= _476_) then - local fennel_path = _476_ + local function _515_() + local _514_ = search_module(mod) + if (nil ~= _514_) then + local fennel_path = _514_ return include_path(ast, opts, fennel_path, mod, true) - else - local _0 = _476_ + elseif true then + local _0 = _514_ local lua_path = search_module(mod, package.path) if lua_path then return include_path(ast, opts, lua_path, mod, false) @@ -1925,9 +2136,11 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct else return compiler.assert(false, ("module not found " .. mod), ast) end + else + return nil end end - res = ((utils["member?"](mod, (utils.root.options.skipInclude or {})) and utils.expr("nil --[[SKIPPED INCLUDE]]--", "literal")) or include_circular_fallback(mod, modexpr, opts.fallback, ast) or utils.root.scope.includes[mod] or _477_()) + res = ((utils["member?"](mod, (utils.root.options.skipInclude or {})) and utils.expr("nil --[[SKIPPED INCLUDE]]--", "literal")) or include_circular_fallback(mod, modexpr, opts.fallback, ast) or utils.root.scope.includes[mod] or _515_()) utils.root.options["module-name"] = oldmod return res end @@ -1937,7 +2150,7 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct 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 = macro_globals(env, current_global_names()) + opts.allowedGlobals = current_global_names(env) return load_code(compiler.compile(ast, opts), wrap_env(env))(opts["module-name"], ast.filename) end SPECIALS.macros = function(ast, scope, parent) @@ -1961,15 +2174,15 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct local friend = require("fennel.friend") local unpack = (table.unpack or _G.unpack) local scopes = {} - local function make_scope(parent) - local parent0 = (parent or scopes.global) - local _176_ - if parent0 then - _176_ = ((parent0.depth or 0) + 1) + local function make_scope(_3fparent) + local parent = (_3fparent or scopes.global) + local _203_ + if parent then + _203_ = ((parent.depth or 0) + 1) else - _176_ = 0 + _203_ = 0 end - return {includes = setmetatable({}, {__index = (parent0 and parent0.includes)}), macros = setmetatable({}, {__index = (parent0 and parent0.macros)}), manglings = setmetatable({}, {__index = (parent0 and parent0.manglings)}), refedglobals = setmetatable({}, {__index = (parent0 and parent0.refedglobals)}), specials = setmetatable({}, {__index = (parent0 and parent0.specials)}), symmeta = setmetatable({}, {__index = (parent0 and parent0.symmeta)}), unmanglings = setmetatable({}, {__index = (parent0 and parent0.unmanglings)}), gensyms = setmetatable({}, {__index = (parent0 and parent0.gensyms)}), autogensyms = setmetatable({}, {__index = (parent0 and parent0.autogensyms)}), vararg = (parent0 and parent0.vararg), depth = _176_, hashfn = (parent0 and parent0.hashfn), parent = parent0} + 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 = _203_, hashfn = (parent and parent.hashfn), refedglobals = {}, parent = parent} end local function assert_msg(ast, msg) local ast_tbl @@ -1986,15 +2199,19 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct end local function assert_compile(condition, msg, ast) if not condition then - local _let_179_ = (utils.root.options or {}) - local source = _let_179_["source"] - local unfriendly = _let_179_["unfriendly"] - utils.root.reset() - if (unfriendly or not friend or not _G.io or not _G.io.read) then - error(assert_msg(ast, msg), 0) + local _let_206_ = (utils.root.options or {}) + local source = _let_206_["source"] + local unfriendly = _let_206_["unfriendly"] + if (nil == utils.hook("assert-compile", condition, msg, ast, 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) + else + friend["assert-compile"](condition, msg, ast, source) + end else - friend["assert-compile"](condition, msg, ast, source) end + else end return condition end @@ -2004,34 +2221,36 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct scopes.macro = scopes.global local serialize_subst = {["\7"] = "\\a", ["\8"] = "\\b", ["\9"] = "\\t", ["\n"] = "n", ["\11"] = "\\v", ["\12"] = "\\f"} local function serialize_string(str) - local function _182_(_241) + local function _210_(_241) return ("\\" .. _241:byte()) end - return string.gsub(string.gsub(string.format("%q", str), ".", serialize_subst), "[\128-\255]", _182_) + return string.gsub(string.gsub(string.format("%q", str), ".", serialize_subst), "[\128-\255]", _210_) end local function global_mangling(str) if utils["valid-lua-identifier?"](str) then return str else - local function _183_(_241) + local function _211_(_241) return string.format("_%02x", _241:byte()) end - return ("__fnl_global__" .. str:gsub("[^%w]", _183_)) + return ("__fnl_global__" .. str:gsub("[^%w]", _211_)) end end local function global_unmangling(identifier) - local _185_ = string.match(identifier, "^__fnl_global__(.*)$") - if (nil ~= _185_) then - local rest = _185_ - local _186_ - local function _187_(_241) + local _213_ = string.match(identifier, "^__fnl_global__(.*)$") + if (nil ~= _213_) then + local rest = _213_ + local _214_ + local function _215_(_241) return string.char(tonumber(_241:sub(2), 16)) end - _186_ = string.gsub(rest, "_[%da-f][%da-f]", _187_) - return _186_ - else - local _ = _185_ + _214_ = string.gsub(rest, "_[%da-f][%da-f]", _215_) + return _214_ + elseif true then + local _ = _213_ return identifier + else + return nil end end local allowed_globals = nil @@ -2045,7 +2264,7 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct return mangling end end - local function local_mangling(str, scope, ast, temp_manglings) + local function local_mangling(str, scope, ast, _3ftemp_manglings) assert_compile(not utils["multi-sym?"](str), ("unexpected multi symbol " .. str), ast) local raw if ((utils["lua-keywords"])[str] or str:match("^%d")) then @@ -2054,14 +2273,14 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct raw = str end local mangling - local function _191_(_241) + local function _219_(_241) return string.format("_%02x", _241:byte()) end - mangling = string.gsub(string.gsub(raw, "-", "_"), "[^%w_]", _191_) + mangling = string.gsub(string.gsub(raw, "-", "_"), "[^%w_]", _219_) local unique = unique_mangling(mangling, mangling, scope, 0) do end (scope.unmanglings)[unique] = str do - local manglings = (temp_manglings or scope.manglings) + local manglings = (_3ftemp_manglings or scope.manglings) do end (manglings)[str] = unique end return unique @@ -2092,29 +2311,31 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct utils.root.scope["gensym-append"] = ((utils.root.scope["gensym-append"] or 0) + 1) return ("_" .. utils.root.scope["gensym-append"] .. "_") end - local function gensym(scope, base, _3fsuffix) - local mangling = ((base or "") .. next_append() .. (_3fsuffix or "")) + local function gensym(scope, _3fbase, _3fsuffix) + local mangling = ((_3fbase or "") .. next_append() .. (_3fsuffix or "")) while scope.unmanglings[mangling] do - mangling = ((base or "") .. next_append() .. (_3fsuffix or "")) + mangling = ((_3fbase or "") .. next_append() .. (_3fsuffix or "")) end - scope.unmanglings[mangling] = (base or true) + scope.unmanglings[mangling] = (_3fbase or true) do end (scope.gensyms)[mangling] = true return mangling end local function autogensym(base, scope) - local _194_ = utils["multi-sym?"](base) - if (nil ~= _194_) then - local parts = _194_ + local _222_ = utils["multi-sym?"](base) + if (nil ~= _222_) then + local parts = _222_ parts[1] = autogensym(parts[1], scope) return table.concat(parts, ((parts["multi-sym-method-call"] and ":") or ".")) - else - local _ = _194_ - local function _195_() + elseif true then + local _ = _222_ + local function _223_() local mangling = gensym(scope, base:sub(1, ( - 2)), "auto") do end (scope.autogensyms)[base] = mangling return mangling end - return (scope.autogensyms[base] or _195_()) + return (scope.autogensyms[base] or _223_()) + else + return nil end end local function check_binding_valid(symbol, scope, ast) @@ -2123,12 +2344,12 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct assert_compile(not (scope.specials[name] or 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, temp_manglings) + 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 - return local_mangling(name, scope, ast, temp_manglings) + return local_mangling(name, scope, ast, _3ftemp_manglings) end local function hashfn_arg_name(name, multi_sym_parts, scope) if not scope.hashfn then @@ -2138,12 +2359,15 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct elseif multi_sym_parts then if (multi_sym_parts and (multi_sym_parts[1] == "$")) then multi_sym_parts[1] = "$1" + else end return table.concat(multi_sym_parts, ".") + else + return nil end end - local function symbol_to_expression(symbol, scope, reference_3f) - utils.hook("symbol-to-expression", symbol, scope, reference_3f) + local function symbol_to_expression(symbol, scope, _3freference_3f) + utils.hook("symbol-to-expression", symbol, scope, _3freference_3f) local name = symbol[1] local multi_sym_parts = utils["multi-sym?"](name) local name0 = (hashfn_arg_name(name, multi_sym_parts, scope) or name) @@ -2152,19 +2376,21 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct local local_3f = scope.manglings[parts[1]] if (local_3f and scope.symmeta[parts[1]]) then 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 reference_3f or local_3f or ("_ENV" == parts[1]) or global_allowed_3f(parts[1])), ("unknown global in strict mode: " .. tostring(parts[1])), symbol) - if (allowed_globals and not local_3f) then - utils.root.scope.refedglobals[parts[1]] = true + 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 + scope.parent.refedglobals[parts[1]] = true + else end return utils.expr(combine_parts(parts, scope), etype) end - local function emit(chunk, out, ast) + local function emit(chunk, out, _3fast) if (type(out) == "table") then return table.insert(chunk, out) else - return table.insert(chunk, {ast = ast, leaf = out}) + return table.insert(chunk, {ast = _3fast, leaf = out}) end end local function peephole(chunk) @@ -2184,10 +2410,6 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct return utils.map(chunk, peephole) end end - local function ast_source(ast) - local m = getmetatable(ast) - return ((m and m.line and m) or (("table" == type(ast)) and ast) or {}) - end local function flatten_chunk_correlated(main_chunk, options) local function flatten(chunk, out, last_line, file) local last_line0 = last_line @@ -2196,11 +2418,13 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct else for _, subchunk in ipairs(chunk) do if (subchunk.leaf or (#subchunk > 0)) then - local source = ast_source(subchunk.ast) + local source = utils["ast-source"](subchunk.ast) if (file == source.filename) then last_line0 = math.max(last_line0, (source.line or 0)) + else end last_line0 = flatten(subchunk, out, last_line0, file) + else end end end @@ -2211,6 +2435,7 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct for i = 1, last do if (out[i] == nil) then out[i] = "" + else end end return table.concat(out, "\n") @@ -2221,22 +2446,23 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct local info = chunk.ast if sm then table.insert(sm, {(info and info.filename), (info and info.line)}) + else end return code else local tab0 do - local _208_ = tab - if (_208_ == true) then + local _236_ = tab + if (_236_ == true) then tab0 = " " - elseif (_208_ == false) then + elseif (_236_ == false) then tab0 = "" - elseif (_208_ == tab) then + elseif (_236_ == tab) then tab0 = tab - elseif (_208_ == nil) then + elseif (_236_ == nil) then tab0 = "" else - tab0 = nil + tab0 = nil end end local function parter(c) @@ -2247,12 +2473,14 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct else return sub end + else + return nil end end return table.concat(utils.map(chunk, parter), "\n") end end - local fennel_sourcemap = {} + local sourcemap = {} local function make_short_src(source) local source0 = source:gsub("\n", " ") if (#source0 <= 49) then @@ -2275,27 +2503,31 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct else sm.key = ret end - fennel_sourcemap[sm.key] = sm + sourcemap[sm.key] = sm + else end return ret, sm end end local function make_metadata() - local function _217_(self, tgt, key) + local function _245_(self, tgt, key) if self[tgt] then return self[tgt][key] + else + return nil end end - local function _219_(self, tgt, key, value) + local function _247_(self, tgt, key, value) self[tgt] = (self[tgt] or {}) do end (self[tgt])[key] = value return tgt end - local function _220_(self, tgt, ...) + local function _248_(self, tgt, ...) local kv_len = select("#", ...) local kvs = {...} if ((kv_len % 2) ~= 0) then error("metadata:setall() expected even number of k/v pairs") + else end self[tgt] = (self[tgt] or {}) for i = 1, kv_len, 2 do @@ -2303,7 +2535,7 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct end return tgt end - return setmetatable({}, {__index = {get = _217_, set = _219_, setall = _220_}, __mode = "k"}) + return setmetatable({}, {__index = {get = _245_, set = _247_, setall = _248_}, __mode = "k"}) end local function exprs1(exprs) return table.concat(utils.map(exprs, tostring), ", ") @@ -2323,6 +2555,7 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct disambiguated = code end emit(chunk, disambiguated, ast) + else end end return nil @@ -2342,28 +2575,32 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct exprs[i] = utils.expr("nil", "literal") end end + else end + else end if opts.tail then emit(parent, string.format("return %s", exprs1(exprs)), ast) + else end if opts.target then local result = exprs1(exprs) - local function _228_() + local function _256_() if (result == "") then return "nil" else return result end end - emit(parent, string.format("%s = %s", opts.target, _228_()), ast) + emit(parent, string.format("%s = %s", opts.target, _256_()), ast) + else end if (opts.tail or opts.target) then return {returned = true} else - local _230_ = exprs - _230_["returned"] = true - return _230_ + local _258_ = exprs + _258_["returned"] = true + return _258_ end end local function find_macro(ast, scope, multi_sym_parts) @@ -2383,36 +2620,60 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct return macro_2a end end - local function macroexpand_2a(ast, scope, once) - local _234_ - if utils["list?"](ast) then - _234_ = find_macro(ast, scope, utils["multi-sym?"](ast[1])) + local function propagate_trace_info(_262_, _index, node) + local _arg_263_ = _262_ + local filename = _arg_263_["filename"] + local line = _arg_263_["line"] + local bytestart = _arg_263_["bytestart"] + local byteend = _arg_263_["byteend"] + if (("table" == type(node)) and (filename ~= node.filename)) then + local src = utils["ast-source"](node) + src.filename, src.line = filename, line + src.bytestart, src.byteend = bytestart, byteend else - _234_ = nil end - if (_234_ == false) then + return ("table" == type(node)) + end + local function macroexpand_2a(ast, scope, _3fonce) + local _265_ + if utils["list?"](ast) then + _265_ = find_macro(ast, scope, utils["multi-sym?"](ast[1])) + else + _265_ = nil + end + if (_265_ == false) then return ast - elseif (nil ~= _234_) then - local macro_2a = _234_ + elseif (nil ~= _265_) then + local macro_2a = _265_ local old_scope = scopes.macro local _ scopes.macro = scope _ = nil local ok, transformed = nil, nil - local function _236_() + local function _267_() return macro_2a(unpack(ast, 2)) end - ok, transformed = xpcall(_236_, debug.traceback) + ok, transformed = xpcall(_267_, debug.traceback) + local function _269_() + local _268_ = ast + local function _270_(...) + return propagate_trace_info(_268_, ...) + end + return _270_ + end + utils["walk-tree"](transformed, _269_()) scopes.macro = old_scope assert_compile(ok, transformed, ast) - if (once or not transformed) then + if (_3fonce or not transformed) then return transformed else return macroexpand_2a(transformed, scope) end - else - local _ = _234_ + elseif true then + local _ = _265_ return ast + else + return nil end end local function compile_special(ast, scope, parent, opts, special) @@ -2443,13 +2704,13 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct assert_compile((("string" == type(ast[1])) or (fcallee.type ~= "literal")), ("cannot call literal value " .. tostring(ast[1])), ast) for i = 2, len do local subexprs - local _242_ + local _276_ if (i ~= len) then - _242_ = 1 + _276_ = 1 else - _242_ = nil + _276_ = nil end - subexprs = compile1(ast[i], scope, parent, {nval = _242_}) + subexprs = compile1(ast[i], scope, parent, {nval = _276_}) table.insert(fargs, (subexprs[1] or utils.expr("nil", "literal"))) if (i == len) then for j = 2, #subexprs do @@ -2502,91 +2763,99 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct return handle_compile_opts({e}, parent, opts, ast) end local function serialize_number(n) - local _248_ = string.gsub(tostring(n), ",", ".") - return _248_ + local _282_ = string.gsub(tostring(n), ",", ".") + return _282_ end local function compile_scalar(ast, _scope, parent, opts) local serialize do - local _249_ = type(ast) - if (_249_ == "nil") then + local _283_ = type(ast) + if (_283_ == "nil") then serialize = tostring - elseif (_249_ == "boolean") then + elseif (_283_ == "boolean") then serialize = tostring - elseif (_249_ == "string") then + elseif (_283_ == "string") then serialize = serialize_string - elseif (_249_ == "number") then + elseif (_283_ == "number") then serialize = serialize_number else - serialize = nil + serialize = nil end end return handle_compile_opts({utils.expr(serialize(ast), "literal")}, parent, opts) end local function compile_table(ast, scope, parent, opts, compile1) local buffer = {} - for i = 1, #ast do - local nval = ((i ~= #ast) and 1) - table.insert(buffer, exprs1(compile1(ast[i], scope, parent, {nval = nval}))) - end local function write_other_values(k) if ((type(k) ~= "number") or (math.floor(k) ~= k) or (k < 1) or (k > #ast)) then if ((type(k) == "string") and utils["valid-lua-identifier?"](k)) then return {k, k} else - local _let_251_ = compile1(k, scope, parent, {nval = 1}) - local compiled = _let_251_[1] + local _let_285_ = compile1(k, scope, parent, {nval = 1}) + local compiled = _let_285_[1] local kstr = ("[" .. tostring(compiled) .. "]") return {kstr, k} end + else + return nil end end do local keys do - local tbl_13_auto = {} + local tbl_14_auto = {} + local i_15_auto = #tbl_14_auto for k, v in utils.stablepairs(ast) do - tbl_13_auto[(#tbl_13_auto + 1)] = write_other_values(k, v) + 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 end - keys = tbl_13_auto + keys = tbl_14_auto end - local function _256_(_254_) - local _arg_255_ = _254_ - local k1 = _arg_255_[1] - local k2 = _arg_255_[2] - local _let_257_ = compile1(ast[k2], scope, parent, {nval = 1}) - local v = _let_257_[1] + local function _291_(_289_) + local _arg_290_ = _289_ + local k1 = _arg_290_[1] + local k2 = _arg_290_[2] + local _let_292_ = compile1(ast[k2], scope, parent, {nval = 1}) + local v = _let_292_[1] return string.format("%s = %s", k1, tostring(v)) end - utils.map(keys, _256_, buffer) + utils.map(keys, _291_, buffer) + end + for i = 1, #ast do + local nval = ((i ~= #ast) and 1) + table.insert(buffer, exprs1(compile1(ast[i], scope, parent, {nval = nval}))) end return handle_compile_opts({utils.expr(("{" .. table.concat(buffer, ", ") .. "}"), "expression")}, parent, opts, ast) end - local function compile1(ast, scope, parent, opts) - local opts0 = (opts or {}) + local function compile1(ast, scope, parent, _3fopts) + local opts = (_3fopts or {}) local ast0 = macroexpand_2a(ast, scope) if utils["list?"](ast0) then - return compile_call(ast0, scope, parent, opts0, compile1) + return compile_call(ast0, scope, parent, opts, compile1) elseif utils["varg?"](ast0) then - return compile_varg(ast0, scope, parent, opts0) + return compile_varg(ast0, scope, parent, opts) elseif utils["sym?"](ast0) then - return compile_sym(ast0, scope, parent, opts0) + return compile_sym(ast0, scope, parent, opts) elseif (type(ast0) == "table") then - return compile_table(ast0, scope, parent, opts0, compile1) + 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 - return compile_scalar(ast0, scope, parent, opts0) + return compile_scalar(ast0, scope, parent, opts) else return assert_compile(false, ("could not compile value of type " .. type(ast0)), ast0) end end local function destructure(to, from, ast, scope, parent, opts) local opts0 = (opts or {}) - local _let_259_ = opts0 - local isvar = _let_259_["isvar"] - local declaration = _let_259_["declaration"] - local forceglobal = _let_259_["forceglobal"] - local forceset = _let_259_["forceset"] - local symtype = _let_259_["symtype"] + local _let_294_ = opts0 + local isvar = _let_294_["isvar"] + local declaration = _let_294_["declaration"] + local forceglobal = _let_294_["forceglobal"] + local forceset = _let_294_["forceset"] + local symtype = _let_294_["symtype"] local symtype0 = ("_" .. (symtype or "dst")) local setter if declaration then @@ -2608,6 +2877,7 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct 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 if forceglobal then assert_compile(not scope.symmeta[scope.unmanglings[raw]], ("global " .. raw .. " conflicts with local"), symbol) @@ -2615,21 +2885,23 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct do end (scope.unmanglings)[global_mangling(raw)] = raw if allowed_globals then table.insert(allowed_globals, raw) + else end + else end return symbol_to_expression(symbol, scope)[1] end end local function compile_top_target(lvalues) local inits - local function _265_(_241) + local function _300_(_241) if scope.manglings[_241] then return _241 else return "nil" end end - inits = utils.map(lvalues, _265_) + inits = utils.map(lvalues, _300_) local init = table.concat(inits, ", ") local lvalue = table.concat(lvalues, ", ") local plen, plast = #parent, parent[#parent] @@ -2638,6 +2910,7 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct for pi = plen, #parent do if (parent[pi] == plast) then plen = pi + else end end if ((#parent == (plen + 1)) and parent[#parent].leaf) then @@ -2647,6 +2920,7 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct else table.insert(parent, (plen + 1), {ast = ast, leaf = ("local " .. lvalue .. " = " .. init)}) end + else end return ret end @@ -2661,33 +2935,35 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct if declaration then scope.symmeta[tostring(left)] = {var = isvar} return nil + else + return nil end end local function destructure_table(left, rightexprs, top_3f, destructure1) local s = gensym(scope, symtype0) local right do - local _272_ + local _307_ if top_3f then - _272_ = exprs1(compile1(from, scope, parent)) + _307_ = exprs1(compile1(from, scope, parent)) else - _272_ = exprs1(rightexprs) + _307_ = exprs1(rightexprs) end - if (_272_ == "") then + if (_307_ == "") then right = "nil" - elseif (nil ~= _272_) then - local right0 = _272_ + elseif (nil ~= _307_) then + local right0 = _307_ right = right0 else - right = nil + right = nil end end emit(parent, string.format("local %s = %s", s, right), left) for k, v in utils.stablepairs(left) do if not (("number" == type(k)) and tostring(left[(k - 1)]):find("^&")) then if (utils["sym?"](v) and (tostring(v) == "&")) then - local unpack_str = "{(table.unpack or unpack)(%s, %s)}" - local formatted = string.format(unpack_str, s, k) + local unpack_str = "(function (t, k)\n local mt = getmetatable(t)\n if \"table\" == type(mt) and mt.__fennelrest then\n return mt.__fennelrest(t, k)\n else\n return {(table.unpack or unpack)(t, k)}\n end\n end)(%s, %s)" + local formatted = string.format(string.gsub(unpack_str, "\n%s*", " "), s, k) local subexpr = utils.expr(formatted, "expression") assert_compile((utils["sequence?"](left) and (nil == left[(k + 2)])), "expected rest argument before last parameter", left) destructure1(left[(k + 1)], {subexpr}, left) @@ -2707,6 +2983,7 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct local subexpr = utils.expr(string.format("%s[%s]", s, key), "expression") destructure1(v, {subexpr}, left) end + else end end return nil @@ -2728,8 +3005,10 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct for _, sym in ipairs(left) do if utils["sym?"](sym) then scope.symmeta[tostring(sym)] = {var = isvar} + else end end + else end for _, pair in utils.stablepairs(tables) do destructure1(pair[1], {pair[2]}, left) @@ -2748,6 +3027,8 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct end if top_3f then return {returned = true} + else + return nil end end local ret = destructure1(to, nil, ast, true) @@ -2757,6 +3038,7 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct end local function require_include(ast, scope, parent, opts) opts.fallback = function(e) + utils.warn(("include module not found, falling back to require: %s"):format(tostring(e))) return utils.expr(string.format("require(%s)", tostring(e)), "statement") end return scopes.global.specials.include(ast, scope, parent, opts) @@ -2771,9 +3053,11 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct allowed_globals = opts.allowedGlobals if (opts.indent == nil) then opts.indent = " " + else end if opts.requireAsInclude then scope.specials.require = require_include + else end utils.root.chunk, utils.root.scope, utils.root.options = chunk, scope, opts for _, val in parser.parser(strm, opts.filename, opts) do @@ -2782,6 +3066,10 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct for i = 1, #vals do local exprs = compile1(vals[i], scope, chunk, {nval = (((i < #vals) and 0) or nil), tail = (i == #vals)}) keep_side_effects(exprs, chunk, nil, vals[i]) + if (i == #vals) then + utils.hook("chunk", vals[i], scope) + else + end end allowed_globals = old_globals utils.root.reset() @@ -2799,13 +3087,16 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct allowed_globals = opts0.allowedGlobals if (opts0.indent == nil) then opts0.indent = " " + else end if opts0.requireAsInclude then scope.specials.require = require_include + else end utils.root.chunk, utils.root.scope, utils.root.options = chunk, scope, opts0 local exprs = compile1(ast, scope, chunk, {tail = true}) keep_side_effects(exprs, chunk, nil, ast) + utils.hook("chunk", ast, scope) allowed_globals = old_globals utils.root.reset() return flatten(chunk, opts0) @@ -2816,24 +3107,25 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct elseif (info.what == "C") then return " [C]: in ?" else - local remap = fennel_sourcemap[info.source] + local remap = sourcemap[info.source] if (remap and remap[info.currentline]) then if remap[info.currentline][1] then - info.short_src = fennel_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) + else end if (info.what == "Lua") then - local function _289_() + local function _325_() if info.name then return ("'" .. info.name .. "'") else return "?" end end - return string.format(" %s:%d: in function %s", info.short_src, info.currentline, _289_()) + return string.format(" %s:%d: in function %s", info.short_src, info.currentline, _325_()) elseif (info.short_src == "(tail call)") then return " (tail call)" else @@ -2857,12 +3149,13 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct local done_3f, level = false, (start or 2) while not done_3f do do - local _293_ = debug.getinfo(level, "Sln") - if (_293_ == nil) then + local _329_ = debug.getinfo(level, "Sln") + if (_329_ == nil) then done_3f = true - elseif (nil ~= _293_) then - local info = _293_ + elseif (nil ~= _329_) then + local info = _329_ table.insert(lines, traceback_frame(info)) + else end end level = (level + 1) @@ -2871,14 +3164,14 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct end end local function entry_transform(fk, fv) - local function _296_(k, v) + local function _332_(k, v) if (type(k) == "number") then return k, fv(v) else return fk(k), fv(v) end end - return _296_ + return _332_ end local function mixed_concat(t, joiner) local seen = {} @@ -2892,6 +3185,7 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct if not seen[k] then ret = (ret .. s .. "[" .. k .. "]" .. "=" .. v) s = joiner + else end end return ret @@ -2923,10 +3217,10 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct return res[1] elseif utils["list?"](form) then local mapped - local function _301_() + local function _337_() return nil end - mapped = utils.kvmap(form, entry_transform(_301_, q)) + mapped = utils.kvmap(form, entry_transform(_337_, q)) local filename if form.filename then filename = string.format("%q", form.filename) @@ -2944,13 +3238,13 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct else filename = "nil" end - local _304_ + local _340_ if source then - _304_ = source.line + _340_ = source.line else - _304_ = "nil" + _340_ = "nil" end - return string.format("setmetatable({%s}, {filename=%s, line=%s, sequence=%s})", mixed_concat(mapped, ", "), filename, _304_, "(getmetatable(sequence()))['sequence']") + return string.format("setmetatable({%s}, {filename=%s, line=%s, sequence=%s})", mixed_concat(mapped, ", "), filename, _340_, "(getmetatable(sequence()))['sequence']") elseif (type(form) == "table") then local mapped = utils.kvmap(form, entry_transform(q, q)) local source = getmetatable(form) @@ -2960,28 +3254,25 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct else filename = "nil" end - local function _307_() + local function _343_() if source then return source.line else return "nil" end end - return string.format("setmetatable({%s}, {filename=%s, line=%s})", mixed_concat(mapped, ", "), filename, _307_()) + return string.format("setmetatable({%s}, {filename=%s, line=%s})", mixed_concat(mapped, ", "), filename, _343_()) elseif (type(form) == "string") then return serialize_string(form) else return tostring(form) end end - return {compile = compile, compile1 = compile1, ["compile-stream"] = compile_stream, ["compile-string"] = compile_string, 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()} + return {compile = compile, compile1 = compile1, ["compile-stream"] = compile_stream, ["compile-string"] = compile_string, 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.friend"] = package.preload["fennel.friend"] or function(...) - local function ast_source(ast) - local m = getmetatable(ast) - return ((m and m.line and m) or (("table" == type(ast)) and ast) or {}) - end - 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 global 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"}, ["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"}, ["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 (.*)"] = {"fixing a typo so %s is used", "renaming the local to _%s"}, ["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"}, ["illegal 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 at runtime"] = {"renaming the macro so as not to conflict with locals"}, ["expected even number of pattern/body pairs"] = {"checking that every pattern has a body to go with it", "adding _ before the final body"}, ["unexpected arguments"] = {"removing an argument", "checking for typos"}, ["unexpected iterator clause"] = {"removing an argument", "checking for typos"}} + local utils = require("fennel.utils") + 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 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"}, ["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"}, ["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"}, ["illegal 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 at runtime"] = {"renaming the macro so as not to conflict with locals"}, ["expected even number of pattern/body pairs"] = {"checking that every pattern has a body to go with it", "adding _ before the final body"}, ["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 @@ -2997,6 +3288,7 @@ package.preload["fennel.friend"] = package.preload["fennel.friend"] or function( else suggestion = sug(matches) end + else end end return suggestion @@ -3021,6 +3313,8 @@ package.preload["fennel.friend"] = package.preload["fennel.friend"] or function( return this_line, (bytes - #this_line - 1) elseif this_line then return read_line_from_string(matcher, target_line, (current_line + 1), bytes) + else + return nil end end local function read_line(filename, line, source) @@ -3030,38 +3324,43 @@ package.preload["fennel.friend"] = package.preload["fennel.friend"] or function( return read_line_from_file(filename, line) end end - local function friendly_msg(msg, _116_, source) - local _arg_117_ = _116_ - local filename = _arg_117_["filename"] - local line = _arg_117_["line"] - local bytestart = _arg_117_["bytestart"] - local byteend = _arg_117_["byteend"] + local function friendly_msg(msg, _142_, source) + local _arg_143_ = _142_ + local filename = _arg_143_["filename"] + local line = _arg_143_["line"] + local bytestart = _arg_143_["bytestart"] + local byteend = _arg_143_["byteend"] local ok, codeline, bol = pcall(read_line, filename, line, source) local suggestions0 = suggest(msg) local out = {msg, ""} if (ok and codeline) then table.insert(out, codeline) + else end if (ok and codeline and bytestart and byteend) then table.insert(out, (string.rep(" ", (bytestart - bol - 1)) .. "^" .. string.rep("^", math.min((byteend - bytestart), ((bol + #codeline) - bytestart))))) + else end if (ok and codeline and bytestart and not byteend) then table.insert(out, (string.rep("-", (bytestart - bol - 1)) .. "^")) table.insert(out, "") + else end if suggestions0 then for _, suggestion in ipairs(suggestions0) do table.insert(out, ("* Try %s."):format(suggestion)) end + else end return table.concat(out, "\n") end local function assert_compile(condition, msg, ast, source) if not condition then - local _let_122_ = ast_source(ast) - local filename = _let_122_["filename"] - local line = _let_122_["line"] - error(friendly_msg(("Compile error in %s:%s\n %s"):format((filename or "unknown"), (line or "?"), msg), ast_source(ast), source), 0) + local _let_148_ = utils["ast-source"](ast) + local filename = _let_148_["filename"] + local line = _let_148_["line"] + error(friendly_msg(("Compile error in %s:%s\n %s"):format((filename or "unknown"), (line or "?"), msg), utils["ast-source"](ast), source), 0) + else end return condition end @@ -3076,46 +3375,50 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( local unpack = (table.unpack or _G.unpack) local function granulate(getchunk) local c, index, done_3f = "", 1, false - local function _124_(parser_state) + local function _150_(parser_state) if not done_3f then if (index <= #c) then local b = c:byte(index) index = (index + 1) return b else - local _125_ = getchunk(parser_state) - local function _126_() - local char = _125_ + local _151_ = getchunk(parser_state) + local function _152_() + local char = _151_ return (char ~= "") end - if ((nil ~= _125_) and _126_()) then - local char = _125_ + if ((nil ~= _151_) and _152_()) then + local char = _151_ c = char index = 2 return c:byte() - else - local _ = _125_ + elseif true then + local _ = _151_ done_3f = true return nil + else + return nil end end + else + return nil end end - local function _130_() + local function _156_() c = "" return nil end - return _124_, _130_ + return _150_, _156_ end local function string_stream(str) local str0 = str:gsub("^#!", ";;") local index = 1 - local function _131_() + local function _157_() local r = str0:byte(index) index = (index + 1) return r end - return _131_ + return _157_ end local delims = {[40] = 41, [41] = true, [91] = 93, [93] = true, [123] = 125, [125] = true} local function whitespace_3f(b) @@ -3131,7 +3434,7 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( return ((b0 > 32) 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", [39] = "quote", [44] = "unquote", [96] = "quote"} - local function parser(getbyte, filename, options) + local function parser(getbyte, _3ffilename, _3foptions) local stack = {} local line = 1 local byteindex = 0 @@ -3139,6 +3442,7 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( local function ungetb(ub) if (ub == 10) then line = (line - 1) + else end byteindex = (byteindex - 1) lastb = ub @@ -3154,56 +3458,63 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( byteindex = (byteindex + 1) if (r == 10) then line = (line + 1) + else end return r end - assert(((nil == filename) or ("string" == type(filename))), "expected filename as second argument to parser") + assert(((nil == _3ffilename) or ("string" == type(_3ffilename))), "expected filename as second argument to parser") local function parse_error(msg, byteindex_override) - local _let_136_ = (options or utils.root.options or {}) - local source = _let_136_["source"] - local unfriendly = _let_136_["unfriendly"] - utils.root.reset() - if (unfriendly or not friend or not _G.io or not _G.io.read) then - return error(string.format("%s:%s: Parse error: %s", (filename or "unknown"), (line or "?"), msg), 0) + local _let_162_ = (_3foptions or utils.root.options or {}) + local source = _let_162_["source"] + local unfriendly = _let_162_["unfriendly"] + if (nil == utils.hook("parse-error", msg, (_3ffilename or "unknown"), (line or "?"), (byteindex_override or byteindex), source, utils.root.reset)) then + utils.root.reset() + if (unfriendly or not friend or not _G.io or not _G.io.read) then + return error(string.format("%s:%s: Parse error: %s", (_3ffilename or "unknown"), (line or "?"), msg), 0) + else + return friend["parse-error"](msg, (_3ffilename or "unknown"), (line or "?"), (byteindex_override or byteindex), source) + end else - return friend["parse-error"](msg, (filename or "unknown"), (line or "?"), (byteindex_override or byteindex), source) + return nil end end local function parse_stream() local whitespace_since_dispatch, done_3f, retval = true local function dispatch(v) - local _138_ = stack[#stack] - if (_138_ == nil) then + local _165_ = stack[#stack] + if (_165_ == nil) then retval, done_3f, whitespace_since_dispatch = v, true, false return nil - elseif ((_G.type(_138_) == "table") and (nil ~= (_138_).prefix)) then - local prefix = (_138_).prefix + elseif ((_G.type(_165_) == "table") and (nil ~= (_165_).prefix)) then + local prefix = (_165_).prefix local source do - local _139_ = table.remove(stack) - do end (_139_)["byteend"] = byteindex - source = _139_ + local _166_ = table.remove(stack) + do end (_166_)["byteend"] = byteindex + source = _166_ end local list = utils.list(utils.sym(prefix, source), v) for k, v0 in pairs(source) do list[k] = v0 end return dispatch(list) - elseif (nil ~= _138_) then - local top = _138_ + elseif (nil ~= _165_) then + local top = _165_ whitespace_since_dispatch = false return table.insert(top, v) + else + return nil end end local function badend() local accum = utils.map(stack, "closer") - local _141_ + local _168_ if (#stack == 1) then - _141_ = "" + _168_ = "" else - _141_ = "s" + _168_ = "s" end - return parse_error(string.format("expected closing delimiter%s %s", _141_, string.char(unpack(accum)))) + return parse_error(string.format("expected closing delimiter%s %s", _168_, string.char(unpack(accum)))) end local function skip_whitespace(b) if (b and whitespace_3f(b)) then @@ -3217,14 +3528,14 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( end local function parse_comment(b, contents) if (b and (10 ~= b)) then - local function _145_() - local _144_ = contents - table.insert(_144_, string.char(b)) - return _144_ + local function _172_() + local _171_ = contents + table.insert(_171_, string.char(b)) + return _171_ end - return parse_comment(getb(), _145_()) - elseif (options and options.comments) then - return dispatch(utils.comment(table.concat(contents), {line = (line - 1), filename = filename})) + return parse_comment(getb(), _172_()) + elseif (_3foptions and _3foptions.comments) then + return dispatch(utils.comment(table.concat(contents), {line = (line - 1), filename = _3ffilename})) else return b end @@ -3232,8 +3543,9 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( local function open_table(b) if not whitespace_since_dispatch then parse_error(("expected whitespace before opening delimiter " .. string.char(b))) + else end - return table.insert(stack, {bytestart = byteindex, closer = delims[b], filename = filename, line = line}) + return table.insert(stack, {bytestart = byteindex, closer = delims[b], filename = _3ffilename, line = line}) end local function close_list(list) return dispatch(setmetatable(list, getmetatable(utils.list()))) @@ -3246,14 +3558,16 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( return dispatch(val) end local function add_comment_at(comments, index, node) - local _148_ = comments[index] - if (nil ~= _148_) then - local existing = _148_ + local _175_ = comments[index] + if (nil ~= _175_) then + local existing = _175_ return table.insert(existing, node) - else - local _ = _148_ + elseif true then + local _ = _175_ comments[index] = {node} return nil + else + return nil end end local function next_noncomment(tbl, i) @@ -3281,6 +3595,7 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( for i = #tbl, 1, -1 do if utils["comment?"](tbl[i]) then table.remove(tbl, i) + else end end return comments @@ -3292,11 +3607,13 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( if ((#tbl % 2) ~= 0) then byteindex = (byteindex - 1) parse_error("expected even number of values in table literal") + else 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 tbl[i] = tostring(tbl[(i + 1)]) + else end val[tbl[i]] = tbl[(i + 1)] table.insert(keys, tbl[i]) @@ -3309,9 +3626,11 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( local top = table.remove(stack) if (top == nil) then parse_error(("unexpected closing delimiter " .. string.char(b))) + else end if (top.closer and (top.closer ~= b)) then parse_error(("mismatched closing delimiter " .. string.char(b) .. ", expected " .. string.char(top.closer))) + else end top.byteend = byteindex if (b == 41) then @@ -3326,14 +3645,19 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( table.insert(chars, b) local state0 do - local _158_ = {state, b} - if ((_G.type(_158_) == "table") and ((_158_)[1] == "base") and ((_158_)[2] == 92)) then + local _185_ = {state, b} + if ((_G.type(_185_) == "table") and ((_185_)[1] == "base") and ((_185_)[2] == 92)) then state0 = "backslash" - elseif ((_G.type(_158_) == "table") and ((_158_)[1] == "base") and ((_158_)[2] == 34)) then + elseif ((_G.type(_185_) == "table") and ((_185_)[1] == "base") and ((_185_)[2] == 34)) then state0 = "done" - else - local _ = _158_ + elseif ((_G.type(_185_) == "table") and ((_185_)[1] == "backslash") and ((_185_)[2] == 10)) then + table.remove(chars, (#chars - 1)) state0 = "base" + elseif true then + local _ = _185_ + state0 = "base" + else + state0 = nil end end if (b and (state0 ~= "done")) then @@ -3350,27 +3674,32 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( local chars = {34} if not parse_string_loop(chars, getb(), "base") then badend() + else end table.remove(stack) local raw = string.char(unpack(chars)) local formatted = raw:gsub("[\7-\13]", escape_char) - local _162_ = (rawget(_G, "loadstring") or load)(("return " .. formatted)) - if (nil ~= _162_) then - local load_fn = _162_ + local _189_ = (rawget(_G, "loadstring") or load)(("return " .. formatted)) + if (nil ~= _189_) then + local load_fn = _189_ return dispatch(load_fn()) - elseif (_162_ == nil) then + elseif (_189_ == nil) then return parse_error(("Invalid string: " .. raw)) + else + return nil end end local function parse_prefix(b) - table.insert(stack, {prefix = prefixes[b], filename = filename, line = line, bytestart = byteindex}) + table.insert(stack, {prefix = prefixes[b], filename = _3ffilename, line = line, bytestart = byteindex}) local nextb = getb() if (whitespace_3f(nextb) or (true == delims[nextb])) then if (b ~= 35) then parse_error("invalid whitespace after quoting prefix") + else end table.remove(stack) dispatch(utils.sym("#")) + else end return ungetb(nextb) end @@ -3381,6 +3710,7 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( else if b then ungetb(b) + else end return chars end @@ -3391,14 +3721,16 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( dispatch((tonumber(number_with_stripped_underscores) or parse_error(("could not read number \"" .. rawstr .. "\"")))) return true else - local _168_ = tonumber(number_with_stripped_underscores) - if (nil ~= _168_) then - local x = _168_ + local _195_ = tonumber(number_with_stripped_underscores) + if (nil ~= _195_) then + local x = _195_ dispatch(x) return true - else - local _ = _168_ + elseif true then + local _ = _195_ return false + else + return nil end end end @@ -3429,7 +3761,9 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( elseif rawstr:match("^:.+$") then return dispatch(rawstr:sub(2)) elseif not parse_number(rawstr) then - return dispatch(utils.sym(check_malformed_sym(rawstr), {byteend = byteindex, bytestart = bytestart, filename = filename, line = line})) + return dispatch(utils.sym(check_malformed_sym(rawstr), {byteend = byteindex, bytestart = bytestart, filename = _3ffilename, line = line})) + else + return nil end end local function parse_loop(b) @@ -3448,6 +3782,7 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( parse_sym(b) elseif not utils.hook("illegal-char", b, getb, ungetb, dispatch) then parse_error(("illegal character: " .. string.char(b))) + else end if not b then return nil @@ -3459,21 +3794,59 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( end return parse_loop(skip_whitespace(getb())) end - local function _175_() - stack, line, byteindex = {}, 1, 0 + local function _202_() + stack, line, byteindex, lastb = {}, 1, 0, nil return nil end - return parse_stream, _175_ + return parse_stream, _202_ end return {granulate = granulate, parser = parser, ["string-stream"] = string_stream, ["sym-char?"] = sym_char_3f} end 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 function sort_keys(_1_, _3_) - local _arg_2_ = _1_ - local a = _arg_2_[1] - local _arg_4_ = _3_ - local b = _arg_4_[1] + 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 + return p(t) + elseif true then + local _ = _1_ + return lua_pairs(t) + else + return nil + end + end + local function ipairs(t) + local _3_ = getmetatable(t) + if ((_G.type(_3_) == "table") and (nil ~= (_3_).__ipairs)) then + local i = (_3_).__ipairs + return i(t) + elseif true then + local _ = _3_ + return lua_ipairs(t) + else + return nil + end + end + local function length_2a(t) + local _5_ = getmetatable(t) + if ((_G.type(_5_) == "table") and (nil ~= (_5_).__len)) then + local l = (_5_).__len + return l(t) + elseif true then + local _ = _5_ + return #t + else + 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 ta = type(a) local tb = type(b) if ((ta == tb) and ((ta == "string") or (ta == "number"))) then @@ -3494,25 +3867,27 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) end local function max_index_gap(kv) local gap = 0 - if (#kv > 0) then + if (length_2a(kv) > 0) then local i = 0 - for _, _7_ in ipairs(kv) do - local _each_8_ = _7_ - local k = _each_8_[1] + for _, _13_ in ipairs(kv) do + local _each_14_ = _13_ + local k = _each_14_[1] if ((k - i) > gap) then gap = (k - i) + else end i = k end + else end return gap end local function fill_gaps(kv) local missing_indexes = {} local i = 0 - for _, _11_ in ipairs(kv) do - local _each_12_ = _11_ - local j = _each_12_[1] + for _, _17_ in ipairs(kv) do + local _each_18_ = _17_ + local j = _each_18_[1] i = (i + 1) while (i < j) do table.insert(missing_indexes, i) @@ -3529,31 +3904,32 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) local kv = {} local insert = table.insert for k, v in pairs(t) do - if (type(k) ~= "number") then + if ((type(k) ~= "number") or (k < 1)) then assoc_3f = true + else end insert(kv, {k, v}) end table.sort(kv, sort_keys) if not assoc_3f then - local gap = max_index_gap(kv) if (max_index_gap(kv) > options["max-sparse-gap"]) then assoc_3f = true else fill_gaps(kv) end + else end - if (#kv == 0) then + if (length_2a(kv) == 0) then return kv, "empty" else - local function _16_() + local function _22_() if assoc_3f then return "table" else return "seq" end end - return kv, _16_() + return kv, _22_() end end local function count_table_appearances(t, appearances) @@ -3567,6 +3943,7 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) else appearances[t] = ((appearances[t] or 0) + 1) end + else end return appearances end @@ -3576,27 +3953,32 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) if not (seen0)[t] then seen0[t] = id seen0.len = id + else end return seen0 end local function detect_cycle(t, seen, _3fk) if ("table" == type(t)) then seen[t] = true - local _21_, _22_ = next(t, _3fk) - if ((nil ~= _21_) and (nil ~= _22_)) then - local k = _21_ - local v = _22_ + 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)) + else + return nil end + else + return nil 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))) end - local function table_indent(t, indent, id) + local function table_indent(indent, id) local opener_length if id then - opener_length = (#tostring(id) + 2) + opener_length = (length_2a(tostring(id)) + 2) else opener_length = 1 end @@ -3606,13 +3988,14 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) local function concat_table_lines(elements, options, multiline_3f, indent, table_type, prefix) local indent_str = ("\n" .. string.rep(" ", indent)) local open - local _26_ - if ("seq" == table_type) then - _26_ = "[" - else - _26_ = "{" + local function _32_() + if ("seq" == table_type) then + return "[" + else + return "{" + end end - open = ((prefix or "") .. _26_) + open = ((prefix or "") .. _32_()) local close if ("seq" == table_type) then close = "]" @@ -3620,13 +4003,20 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) close = "}" end local oneline = (open .. table.concat(elements, " ") .. close) - if (not options["one-line?"] and (multiline_3f or ((indent + #oneline) > options["line-length"]))) then + if (not options["one-line?"] and (multiline_3f or ((indent + length_2a(oneline)) > options["line-length"]))) then return (open .. table.concat(elements, indent_str) .. close) else return oneline end end - local function pp_associative(t, kv, options, indent, key_3f) + local function utf8_len(x) + local n = 0 + for _ in string.gmatch(x, "[%z\1-\127\192-\247]") do + n = (n + 1) + end + return n + end + local function pp_associative(t, kv, options, indent) local multiline_3f = false local id = options.seen[t] if (options.level >= options.depth) then @@ -3636,20 +4026,16 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) else local visible_cycle_3f0 = visible_cycle_3f(t, options) local id0 = (visible_cycle_3f0 and options.seen[t]) - local indent0 = table_indent(t, indent, id0) + local indent0 = table_indent(indent, id0) local slength - local function _31_() - local _30_ = rawget(_G, "utf8") - if _30_ then - return (_30_).len - else - return _30_ + if options["utf8?"] then + slength = utf8_len + else + local function _35_(_241) + return #_241 end + slength = _35_ end - local function _33_(_241) - return #_241 - end - slength = ((options["utf8?"] and _31_()) or _33_) local prefix if visible_cycle_3f0 then prefix = ("@" .. id0) @@ -3658,21 +4044,26 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) end local items do - local tbl_13_auto = {} - for _, _35_ in pairs(kv) do - local _each_36_ = _35_ - local k = _each_36_[1] - local v = _each_36_[2] - local _37_ + local tbl_14_auto = {} + local i_15_auto = #tbl_14_auto + for _, _38_ in pairs(kv) do + local _each_39_ = _38_ + local k = _each_39_[1] + local v = _each_39_[2] + local val_16_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")) - _37_ = (k0 .. " " .. v0) + val_16_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 + else end - tbl_13_auto[(#tbl_13_auto + 1)] = _37_ end - items = tbl_13_auto + items = tbl_14_auto end return concat_table_lines(items, options, multiline_3f, indent0, "table", prefix) end @@ -3687,7 +4078,7 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) else local visible_cycle_3f0 = visible_cycle_3f(t, options) local id0 = (visible_cycle_3f0 and options.seen[t]) - local indent0 = table_indent(t, indent, id0) + local indent0 = table_indent(indent, id0) local prefix if visible_cycle_3f0 then prefix = ("@" .. id0) @@ -3696,26 +4087,31 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) end local items do - local tbl_13_auto = {} - for _, _40_ in pairs(kv) do - local _each_41_ = _40_ - local _0 = _each_41_[1] - local v = _each_41_[2] - local _42_ + local tbl_14_auto = {} + local i_15_auto = #tbl_14_auto + for _, _43_ in pairs(kv) do + local _each_44_ = _43_ + local _0 = _each_44_[1] + local v = _each_44_[2] + local val_16_auto do local v0 = pp(v, options, indent0) multiline_3f = (multiline_3f or v0:find("\n")) - _42_ = v0 + val_16_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 + else end - tbl_13_auto[(#tbl_13_auto + 1)] = _42_ end - items = tbl_13_auto + items = tbl_14_auto end return concat_table_lines(items, options, multiline_3f, indent0, "seq", prefix) end end local function concat_lines(lines, options, indent, force_multi_line_3f) - if (#lines == 0) then + if (length_2a(lines) == 0) then if options["empty-as-sequence?"] then return "[]" else @@ -3723,16 +4119,22 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) end else local oneline - local _45_ + local _48_ do - local tbl_13_auto = {} + local tbl_14_auto = {} + local i_15_auto = #tbl_14_auto for _, line in ipairs(lines) do - tbl_13_auto[(#tbl_13_auto + 1)] = line:gsub("^%s+", "") + 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 + else + end end - _45_ = tbl_13_auto + _48_ = tbl_14_auto end - oneline = table.concat(_45_, " ") - if (not options["one-line?"] and (force_multi_line_3f or oneline:find("\n") or ((indent + #oneline) > options["line-length"]))) then + oneline = table.concat(_48_, " ") + if (not options["one-line?"] and (force_multi_line_3f or oneline:find("\n") or ((indent + length_2a(oneline)) > options["line-length"]))) then return table.concat(lines, ("\n" .. string.rep(" ", indent))) else return oneline @@ -3748,21 +4150,23 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) end else local _ - local function _49_(_241) + local function _53_(_241) return visible_cycle_3f(_241, options) end - options["visible-cycle?"] = _49_ + options["visible-cycle?"] = _53_ _ = nil local lines, force_multi_line_3f = metamethod(t, pp, options, indent) options["visible-cycle?"] = nil - local _50_ = type(lines) - if (_50_ == "string") then + local _54_ = type(lines) + if (_54_ == "string") then return lines - elseif (_50_ == "table") then + elseif (_54_ == "table") then return concat_lines(lines, options, indent, force_multi_line_3f) - else - local _0 = _50_ + elseif true then + local _0 = _54_ return error("__fennelview metamethod must return a table of lines") + else + return nil end end end @@ -3770,69 +4174,129 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) options.level = (options.level + 1) local x0 do - local _53_ + local _57_ if options["metamethod?"] then - local _54_ = x - if _54_ then - local _55_ = getmetatable(_54_) - if _55_ then - _53_ = (_55_).__fennelview + local _58_ = x + if (nil ~= _58_) then + local _59_ = getmetatable(_58_) + if (nil ~= _59_) then + _57_ = (_59_).__fennelview else - _53_ = _55_ + _57_ = _59_ end else - _53_ = _54_ + _57_ = _58_ end else - _53_ = nil + _57_ = nil end - if (nil ~= _53_) then - local metamethod = _53_ + if (nil ~= _57_) then + local metamethod = _57_ x0 = pp_metamethod(x, metamethod, options, indent) - else - local _ = _53_ - local _59_, _60_ = table_kv_pairs(x, options) - if (true and (_60_ == "empty")) then - local _0 = _59_ + elseif true then + local _ = _57_ + local _63_, _64_ = table_kv_pairs(x, options) + if (true and (_64_ == "empty")) then + local _0 = _63_ if options["empty-as-sequence?"] then x0 = "[]" else x0 = "{}" end - elseif ((nil ~= _59_) and (_60_ == "table")) then - local kv = _59_ + elseif ((nil ~= _63_) and (_64_ == "table")) then + local kv = _63_ x0 = pp_associative(x, kv, options, indent) - elseif ((nil ~= _59_) and (_60_ == "seq")) then - local kv = _59_ + elseif ((nil ~= _63_) and (_64_ == "seq")) then + local kv = _63_ x0 = pp_sequence(x, kv, options, indent) else - x0 = nil + x0 = nil end + else + x0 = nil end end options.level = (options.level - 1) return x0 end local function number__3estring(n) - local _64_ = string.gsub(tostring(n), ",", ".") - return _64_ + local _68_ = string.gsub(tostring(n), ",", ".") + return _68_ end local function colon_string_3f(s) return s:find("^[-%w?^_!$%&*+./@|<=>]+$") end + 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 + do + local ret = nil + for _, init0 in ipairs(inits) do + if ret then break end + ret = (byte and (function(_69_,_70_,_71_) return (_69_ >= _70_) and (_70_ >= _71_) end)(init0["max-byte"],byte,init0["min-byte"]) and init0) + end + init = ret + end + local code + local function _72_() + local code0 + if init then + code0 = (byte - init["min-byte"]) + else + code0 = nil + end + for i = (index + 1), (index + init.len + -1) do + local byte0 = string.byte(str0, i) + code0 = (byte0 and code0 and (function(_74_,_75_,_76_) return (_74_ >= _75_) and (_75_ >= _76_) end)(191,byte0,128) and ((code0 * 64) + (byte0 - 128))) + end + return code0 + end + code = (init and _72_()) + if (code and (function(_77_,_78_,_79_) return (_77_ >= _78_) and (_78_ >= _79_) end)(init["max-code"],code,init["min-code"]) and not (function(_80_,_81_,_82_) return (_80_ >= _81_) and (_81_ >= _82_) end)(57343,code,55296)) then + return init.len + else + return nil + end + end + local index = 1 + local output = {} + 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))) + if (not len and (nexti <= #str)) then + table.insert(output, string.format("\\%03d", string.byte(str, nexti))) + else + end + if len then + index = (nexti + len) + else + index = (nexti + 1) + end + end + return table.concat(output) + end local function pp_string(str, options, indent) local escs - local _65_ - if (options["escape-newlines?"] and (#str < (options["line-length"] - indent))) then - _65_ = "\\n" + local _86_ + if (options["escape-newlines?"] and (length_2a(str) < (options["line-length"] - indent))) then + _86_ = "\\n" else - _65_ = "\n" + _86_ = "\n" end - local function _67_(_241, _242) + local function _88_(_241, _242) return ("\\%03d"):format(_242:byte()) end - escs = setmetatable({["\7"] = "\\a", ["\8"] = "\\b", ["\12"] = "\\f", ["\11"] = "\\v", ["\13"] = "\\r", ["\9"] = "\\t", ["\\"] = "\\\\", ["\""] = "\\\"", ["\n"] = _65_}, {__index = _67_}) - return ("\"" .. str:gsub("[%c\\\"]", escs) .. "\"") + escs = setmetatable({["\7"] = "\\a", ["\8"] = "\\b", ["\12"] = "\\f", ["\11"] = "\\v", ["\13"] = "\\r", ["\9"] = "\\t", ["\\"] = "\\\\", ["\""] = "\\\"", ["\n"] = _86_}, {__index = _88_}) + local str0 = ("\"" .. str:gsub("[%c\\\"]", escs) .. "\"") + if options["utf8?"] then + return utf8_escape(str0) + else + return str0 + end end local function make_options(t, options) local defaults = {["line-length"] = 80, ["one-line?"] = false, depth = 128, ["detect-cycles?"] = true, ["empty-as-sequence?"] = false, ["metamethod?"] = true, ["prefer-colon?"] = false, ["escape-newlines?"] = false, ["utf8?"] = true, ["max-sparse-gap"] = 10} @@ -3845,7 +4309,7 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) end return defaults end - local function _68_(x, options, indent, colon_3f) + local function _90_(x, options, indent, colon_3f) local indent0 = (indent or 0) local options0 = (options or make_options(x)) local x0 @@ -3855,20 +4319,20 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) x0 = x end local tv = type(x0) - local function _71_() - local _70_ = getmetatable(x0) - if _70_ then - return (_70_).__fennelview + local function _93_() + local _92_ = getmetatable(x0) + if (nil ~= _92_) then + return (_92_).__fennelview else - return _70_ + return _92_ end end - if ((tv == "table") or ((tv == "userdata") and _71_())) then + if ((tv == "table") or ((tv == "userdata") and _93_())) then return pp_table(x0, options0, indent0) elseif (tv == "number") then return number__3estring(x0) else - local function _73_() + local function _95_() if (colon_3f ~= nil) then return colon_3f elseif ("function" == type(options0["prefer-colon?"])) then @@ -3877,7 +4341,7 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) return options0["prefer-colon?"] end end - if ((tv == "string") and colon_string_3f(x0) and _73_()) then + if ((tv == "string") and colon_string_3f(x0) and _95_()) then return (":" .. x0) elseif (tv == "string") then return pp_string(x0, options0, indent0) @@ -3888,14 +4352,22 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) end end end - pp = _68_ - local function view(x, options) - return pp(x, make_options(x, options), 0) + pp = _90_ + local function view(x, _3foptions) + return pp(x, make_options(x, _3foptions), 0) end return view end package.preload["fennel.utils"] = package.preload["fennel.utils"] or function(...) local view = require("fennel.view") + local version = "1.0.0" + local function warn(message) + if (_G.io and _G.io.stderr) then + return (_G.io.stderr):write(("--WARNING: %s\n"):format(tostring(message))) + else + return nil + end + end local function stablepairs(t) local keys = {} local used_keys = {} @@ -3906,8 +4378,10 @@ package.preload["fennel.utils"] = package.preload["fennel.utils"] or function(.. for i = #keys, 1, -1 do if (keys[i] == k) then table.remove(keys, i) + else end end + else end used_keys[k] = true table.insert(keys, k) @@ -3916,10 +4390,10 @@ package.preload["fennel.utils"] = package.preload["fennel.utils"] or function(.. for k in pairs(t) do table.insert(keys, k) end - local function _77_(_241, _242) + local function _100_(_241, _242) return (tostring(_241) < tostring(_242)) end - table.sort(keys, _77_) + table.sort(keys, _100_) end for i, k in ipairs(keys) do succ[k] = keys[(i + 1)] @@ -3941,66 +4415,70 @@ package.preload["fennel.utils"] = package.preload["fennel.utils"] or function(.. end return stablenext, t, nil end - local function map(t, f, out) - local out0 = (out or {}) + local function map(t, f, _3fout) + local out = (_3fout or {}) local f0 if (type(f) == "function") then f0 = f else - local function _81_(_241) + local function _104_(_241) return (_241)[f] end - f0 = _81_ + f0 = _104_ end for _, x in ipairs(t) do - local _83_ = f0(x) - if (nil ~= _83_) then - local v = _83_ - table.insert(out0, v) + local _106_ = f0(x) + if (nil ~= _106_) then + local v = _106_ + table.insert(out, v) + else end end - return out0 + return out end - local function kvmap(t, f, out) - local out0 = (out or {}) + local function kvmap(t, f, _3fout) + local out = (_3fout or {}) local f0 if (type(f) == "function") then f0 = f else - local function _85_(_241) + local function _108_(_241) return (_241)[f] end - f0 = _85_ + f0 = _108_ end for k, x in stablepairs(t) do - local _87_, _88_ = f0(k, x) - if ((nil ~= _87_) and (nil ~= _88_)) then - local key = _87_ - local value = _88_ - out0[key] = value - elseif (nil ~= _87_) then - local value = _87_ - table.insert(out0, value) + local _110_, _111_ = f0(k, x) + if ((nil ~= _110_) and (nil ~= _111_)) then + local key = _110_ + local value = _111_ + out[key] = value + elseif (nil ~= _110_) then + local value = _110_ + table.insert(out, value) + else end end - return out0 + return out end - local function copy(from, to) - local to0 = (to or {}) + local function copy(from, _3fto) + local to = (_3fto or {}) for k, v in pairs((from or {})) do - to0[k] = v + to[k] = v end - return to0 + return to end - local function member_3f(x, tbl, n) - local _90_ = tbl[(n or 1)] - if (_90_ == x) then + local function member_3f(x, tbl, _3fn) + local _113_ = tbl[(_3fn or 1)] + if (_113_ == x) then return true - elseif (_90_ == nil) then + elseif (_113_ == nil) then return nil + elseif true then + local _ = _113_ + return member_3f(x, tbl, ((_3fn or 1) + 1)) else - local _ = _90_ - return member_3f(x, tbl, ((n or 1) + 1)) + return nil end end local function allpairs(tbl) @@ -4015,13 +4493,17 @@ package.preload["fennel.utils"] = package.preload["fennel.utils"] or function(.. seen[next_state] = true return next_state, value else - local _92_ = getmetatable(t) - if ((_G.type(_92_) == "table") and true) then - local __index = (_92_).__index + local _115_ = getmetatable(t) + if ((_G.type(_115_) == "table") and true) then + local __index = (_115_).__index if ("table" == type(__index)) then t = __index return allpairs_next(t) + else + return nil end + else + return nil end end end @@ -4031,17 +4513,18 @@ package.preload["fennel.utils"] = package.preload["fennel.utils"] or function(.. return self[1] end local nil_sym = nil - local function list__3estring(self, tostring2) + local function list__3estring(self, _3ftostring2) local safe, max = {}, 0 for k in pairs(self) do if ((type(k) == "number") and (k > max)) then max = k + else end end for i = 1, max do safe[i] = (((self[i] == nil) and nil_sym) or self[i]) end - return ("(" .. table.concat(map(safe, (tostring2 or view)), " ", 1, max) .. ")") + return ("(" .. table.concat(map(safe, (_3ftostring2 or view)), " ", 1, max) .. ")") end local function comment_view(c) return c, true @@ -4052,21 +4535,21 @@ package.preload["fennel.utils"] = package.preload["fennel.utils"] or function(.. local function sym_3c(a, b) return (a[1] < tostring(b)) end - local symbol_mt = {"SYMBOL", __fennelview = deref, __tostring = deref, __eq = sym_3d, __lt = sym_3c} + local symbol_mt = {__fennelview = deref, __tostring = deref, __eq = sym_3d, __lt = sym_3c, "SYMBOL"} local expr_mt - local function _97_(x) + local function _120_(x) return tostring(deref(x)) end - expr_mt = {"EXPR", __tostring = _97_} - local list_mt = {"LIST", __fennelview = list__3estring, __tostring = list__3estring} - local comment_mt = {"COMMENT", __fennelview = comment_view, __tostring = deref, __eq = sym_3d, __lt = sym_3c} + expr_mt = {__tostring = _120_, "EXPR"} + local list_mt = {__fennelview = list__3estring, __tostring = list__3estring, "LIST"} + local comment_mt = {__fennelview = comment_view, __tostring = deref, __eq = sym_3d, __lt = sym_3c, "COMMENT"} local sequence_marker = {"SEQUENCE"} - local vararg = setmetatable({"..."}, {"VARARG", __fennelview = deref, __tostring = deref}) + local vararg = setmetatable({"..."}, {__fennelview = deref, __tostring = deref, "VARARG"}) local getenv - local function _98_() + local function _121_() return nil end - getenv = ((os and os.getenv) or _98_) + getenv = ((os and os.getenv) or _121_) local function debug_on_3f(flag) local level = (getenv("FENNEL_DEBUG") or "") return ((level == "all") or level:find(flag)) @@ -4075,10 +4558,11 @@ package.preload["fennel.utils"] = package.preload["fennel.utils"] or function(.. return setmetatable({...}, list_mt) end local function sym(str, _3fsource, _3fscope) - local s = {str, ["?scope"] = _3fscope} + local s = {["?scope"] = _3fscope, str} for k, v in pairs((_3fsource or {})) do if (type(k) == "string") then s[k] = v + else end end return setmetatable(s, symbol_mt) @@ -4088,13 +4572,13 @@ package.preload["fennel.utils"] = package.preload["fennel.utils"] or function(.. return setmetatable({...}, {sequence = sequence_marker}) end local function expr(strcode, etype) - return setmetatable({strcode, type = etype}, expr_mt) + return setmetatable({type = etype, strcode}, expr_mt) end local function comment_2a(contents, _3fsource) - local _let_100_ = (_3fsource or {}) - local filename = _let_100_["filename"] - local line = _let_100_["line"] - return setmetatable({contents, filename = filename, line = line}, comment_mt) + local _let_123_ = (_3fsource or {}) + local filename = _let_123_["filename"] + local line = _let_123_["line"] + return setmetatable({filename = filename, line = line, contents}, comment_mt) end local function varg() return vararg @@ -4132,6 +4616,7 @@ package.preload["fennel.utils"] = package.preload["fennel.utils"] or function(.. local last_char = part:sub(( - 1)) if (last_char == ":") then parts["multi-sym-method-call"] = true + else end if ((last_char == ":") or (last_char == ".")) then parts[(#parts + 1)] = part:sub(1, ( - 2)) @@ -4145,16 +4630,27 @@ package.preload["fennel.utils"] = package.preload["fennel.utils"] or function(.. local function quoted_3f(symbol) return symbol.quoted end - local function walk_tree(root, f, custom_iterator) + local function ast_source(ast) + if table_3f(ast) then + return (getmetatable(ast) or {}) + elseif ("table" == type(ast)) then + return ast + else + return {} + end + end + local function walk_tree(root, f, _3fcustom_iterator) local function walk(iterfn, parent, idx, node) if f(idx, node, parent) then for k, v in iterfn(node) do walk(iterfn, node, k, v) end return nil + else + return nil end end - walk((custom_iterator or pairs), nil, nil, root) + walk((_3fcustom_iterator or pairs), nil, nil, root) return root end local lua_keywords = {"and", "break", "do", "else", "elseif", "end", "false", "for", "function", "if", "in", "local", "nil", "not", "or", "repeat", "return", "then", "true", "until", "while", "goto"} @@ -4172,40 +4668,52 @@ package.preload["fennel.utils"] = package.preload["fennel.utils"] or function(.. return subopts end local root - local function _105_() + local function _129_() end - root = {chunk = nil, scope = nil, options = nil, reset = _105_} - root["set-reset"] = function(_106_) - local _arg_107_ = _106_ - local chunk = _arg_107_["chunk"] - local scope = _arg_107_["scope"] - local options = _arg_107_["options"] - local reset = _arg_107_["reset"] + root = {chunk = nil, scope = nil, options = nil, reset = _129_} + root["set-reset"] = function(_130_) + local _arg_131_ = _130_ + local chunk = _arg_131_["chunk"] + local scope = _arg_131_["scope"] + local options = _arg_131_["options"] + local reset = _arg_131_["reset"] root.reset = function() root.chunk, root.scope, root.options, root.reset = chunk, scope, options, reset return nil end return root.reset end + local warned = {} + local function check_plugin_version(_132_) + local _arg_133_ = _132_ + local name = _arg_133_["name"] + local versions = _arg_133_["versions"] + local plugin = _arg_133_ + if (not member_3f(version:gsub("-dev", ""), (versions or {})) and not warned[plugin]) then + warned[plugin] = true + return warn(string.format("plugin %s does not support Fennel version %s", (name or "unknown"), version)) + else + return nil + end + end local function hook(event, ...) local result = nil if (root.options and root.options.plugins) then for _, plugin in ipairs(root.options.plugins) do - do - local _108_ = plugin[event] - if (nil ~= _108_) then - local f = _108_ - result = f(...) - end - end - if (nil ~= result) then - return result + if result then break end + check_plugin_version(plugin) + local _135_ = plugin[event] + if (nil ~= _135_) then + local f = _135_ + result = f(...) + else end end - return nil + else end + return result end - return {allpairs = allpairs, stablepairs = stablepairs, copy = copy, kvmap = kvmap, map = map, ["walk-tree"] = walk_tree, ["member?"] = member_3f, list = list, sequence = sequence, sym = sym, varg = varg, expr = expr, comment = comment_2a, ["comment?"] = comment_3f, ["expr?"] = expr_3f, ["list?"] = list_3f, ["multi-sym?"] = multi_sym_3f, ["sequence?"] = sequence_3f, ["sym?"] = sym_3f, ["table?"] = table_3f, ["varg?"] = varg_3f, ["quoted?"] = quoted_3f, ["valid-lua-identifier?"] = valid_lua_identifier_3f, ["lua-keywords"] = lua_keywords, hook = hook, ["propagate-options"] = propagate_options, root = root, ["debug-on?"] = debug_on_3f, path = table.concat({"./?.fnl", "./?/init.fnl", getenv("FENNEL_PATH")}, ";"), ["macro-path"] = table.concat({"./?.fnl", "./?/init-macros.fnl", "./?/init.fnl", getenv("FENNEL_MACRO_PATH")}, ";")} + return {warn = warn, allpairs = allpairs, stablepairs = stablepairs, copy = copy, kvmap = kvmap, map = map, ["walk-tree"] = walk_tree, ["member?"] = member_3f, list = list, sequence = sequence, sym = sym, varg = varg, expr = expr, comment = comment_2a, ["comment?"] = comment_3f, ["expr?"] = expr_3f, ["list?"] = list_3f, ["multi-sym?"] = multi_sym_3f, ["sequence?"] = sequence_3f, ["sym?"] = sym_3f, ["table?"] = table_3f, ["varg?"] = varg_3f, ["quoted?"] = quoted_3f, ["valid-lua-identifier?"] = valid_lua_identifier_3f, ["lua-keywords"] = lua_keywords, hook = hook, ["propagate-options"] = propagate_options, root = root, ["debug-on?"] = debug_on_3f, ["ast-source"] = ast_source, version = version, path = table.concat({"./?.fnl", "./?/init.fnl", getenv("FENNEL_PATH")}, ";"), ["macro-path"] = table.concat({"./?.fnl", "./?/init-macros.fnl", "./?/init.fnl", getenv("FENNEL_MACRO_PATH")}, ";")} end package.preload["fennel"] = package.preload["fennel"] or function(...) local utils = require("fennel.utils") @@ -4219,6 +4727,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...) local env0 = specials["make-compiler-env"](nil, compiler.scopes.compiler, {}, opts) if (opts.allowedGlobals == nil) then opts.allowedGlobals = specials["current-global-names"](env0) + else end return specials["wrap-env"](env0) else @@ -4229,12 +4738,15 @@ package.preload["fennel"] = package.preload["fennel"] or function(...) local opts = utils.copy(options) if (opts.allowedGlobals == nil) then opts.allowedGlobals = specials["current-global-names"](opts.env) + else end if (not opts.filename and not opts.source) then opts.source = str + else end if (opts.env == "_COMPILER") then opts.scope = compiler["make-scope"](compiler.scopes.compiler) + else end return opts end @@ -4243,14 +4755,14 @@ package.preload["fennel"] = package.preload["fennel"] or function(...) local env = eval_env(opts.env, opts) local lua_source = compiler["compile-string"](str, opts) local loader - local function _563_(...) + local function _616_(...) if opts.filename then return ("@" .. opts.filename) else return str end end - loader = specials["load-code"](lua_source, env, _563_(...)) + loader = specials["load-code"](lua_source, env, _616_(...)) opts.filename = nil return loader(...) end @@ -4275,21 +4787,23 @@ package.preload["fennel"] = package.preload["fennel"] or function(...) out[k] = {["macro?"] = true, ["body-form?"] = utils["member?"](k, body_3f), ["binding-form?"] = utils["member?"](k, binding_3f), ["define?"] = utils["member?"](k, define_3f)} end for k, v in pairs(_G) do - local _564_ = type(v) - if (_564_ == "function") then + local _617_ = type(v) + if (_617_ == "function") then out[k] = {["global?"] = true, ["function?"] = true} - elseif (_564_ == "table") then + elseif (_617_ == "table") then for k2, v2 in pairs(v) do if (("function" == type(v2)) and (k ~= "_G")) then out[(k .. "." .. k2)] = {["function?"] = true, ["global?"] = true} + else end end out[k] = {["global?"] = true} + else end end return out end - local mod = {list = utils.list, ["list?"] = utils["list?"], sym = utils.sym, ["sym?"] = utils["sym?"], sequence = utils.sequence, ["sequence?"] = utils["sequence?"], comment = utils.comment, ["comment?"] = utils["comment?"], varg = utils.varg, path = utils.path, ["macro-path"] = utils["macro-path"], ["sym-char?"] = parser["sym-char?"], parser = parser.parser, granulate = parser.granulate, ["string-stream"] = parser["string-stream"], compile = compiler.compile, ["compile-string"] = compiler["compile-string"], ["compile-stream"] = compiler["compile-stream"], compile1 = compiler.compile1, traceback = compiler.traceback, mangle = compiler["global-mangling"], unmangle = compiler["global-unmangling"], metadata = compiler.metadata, scope = compiler["make-scope"], gensym = compiler.gensym, ["load-code"] = specials["load-code"], ["macro-loaded"] = specials["macro-loaded"], ["macro-searchers"] = specials["macro-searchers"], ["search-module"] = specials["search-module"], ["make-searcher"] = specials["make-searcher"], makeSearcher = specials["make-searcher"], searcher = specials["make-searcher"](), doc = specials.doc, view = view, eval = eval, dofile = dofile_2a, version = "1.0.0-dev", repl = repl, syntax = syntax, loadCode = specials["load-code"], make_searcher = specials["make-searcher"], searchModule = specials["search-module"], macroLoaded = specials["macro-loaded"], compileStream = compiler["compile-stream"], compileString = compiler["compile-string"], stringStream = parser["string-stream"]} + local mod = {list = utils.list, ["list?"] = utils["list?"], sym = utils.sym, ["sym?"] = utils["sym?"], sequence = utils.sequence, ["sequence?"] = utils["sequence?"], comment = utils.comment, ["comment?"] = utils["comment?"], varg = utils.varg, path = utils.path, ["macro-path"] = utils["macro-path"], ["sym-char?"] = parser["sym-char?"], parser = parser.parser, granulate = parser.granulate, ["string-stream"] = parser["string-stream"], compile = compiler.compile, ["compile-string"] = compiler["compile-string"], ["compile-stream"] = compiler["compile-stream"], compile1 = compiler.compile1, traceback = compiler.traceback, mangle = compiler["global-mangling"], unmangle = compiler["global-unmangling"], metadata = compiler.metadata, scope = compiler["make-scope"], gensym = compiler.gensym, ["load-code"] = specials["load-code"], ["macro-loaded"] = specials["macro-loaded"], ["macro-searchers"] = specials["macro-searchers"], ["search-module"] = specials["search-module"], ["make-searcher"] = specials["make-searcher"], makeSearcher = specials["make-searcher"], searcher = specials["make-searcher"](), doc = specials.doc, view = view, eval = eval, dofile = dofile_2a, version = utils.version, repl = repl, syntax = syntax, loadCode = specials["load-code"], make_searcher = specials["make-searcher"], searchModule = specials["search-module"], macroLoaded = specials["macro-loaded"], compileStream = compiler["compile-stream"], compileString = compiler["compile-string"], stringStream = parser["string-stream"]} utils["fennel-module"] = mod do local builtin_macros = [===[;; This module contains all the built-in Fennel macros. Unlike all the other @@ -4318,7 +4832,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...) Same as ->, except splices the value into the last position of each form rather than the first." (var x val) - (each [_ e (pairs [...])] + (each [_ e (ipairs [...])] (let [elt (if (list? e) e (list e))] (table.insert elt x) (set x elt))) @@ -4335,7 +4849,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...) tmp (gensym)] (table.insert el 2 tmp) `(let [,tmp ,val] - (if ,tmp + (if (not= nil ,tmp) (-?> ,el ,(unpack els)) ,tmp))))) @@ -4350,7 +4864,7 @@ package.preload["fennel"] = package.preload["fennel"] or function(...) tmp (gensym)] (table.insert el tmp) `(let [,tmp ,val] - (if ,tmp + (if (not= ,tmp nil) (-?>> ,el ,(unpack els)) ,tmp))))) @@ -4371,9 +4885,10 @@ package.preload["fennel"] = package.preload["fennel"] or function(...) "Evaluates val and splices it into the first argument of subsequent forms." (let [name (gensym) form `(let [,name ,val])] - (each [_ elt (pairs [...])] - (table.insert elt 2 name) - (table.insert form elt)) + (each [_ elt (ipairs [...])] + (let [elt (if (list? elt) elt (list elt))] + (table.insert elt 2 name) + (table.insert form elt))) (table.insert form name) form)) @@ -4406,20 +4921,26 @@ package.preload["fennel"] = package.preload["fennel"] or function(...) (var into nil) (for [i (length iter-tbl) 2 -1] (if (= :into (. iter-tbl i)) - (do (set into (table.remove iter-tbl (+ i 1))) + (do (assert (not into) "expected only one :into clause") + (set into (table.remove iter-tbl (+ i 1))) (table.remove iter-tbl i)))) - (assert (or (not into) (table? into)) "expected table in :into clause") + (assert (or (not into) + (sym? into) + (table? into) + (list? into)) + "expected table, function call, or symbol in :into clause") (or into [])) - (fn collect* [iter-tbl key-value-expr ...] - "Returns a table made by running an iterator and evaluating an expression - that returns key-value pairs to be inserted sequentially into the table. - This can be thought of as a \"table comprehension\". The provided key-value - expression must return either 2 values, or nil. + (fn collect* [iter-tbl key-expr value-expr ...] + "Returns a table made by running an iterator and evaluating an expression that + returns key-value pairs to be inserted sequentially into the table. This can + be thought of as a table comprehension. The body should provide two + expressions (used as key and value) or nil, which causes it to be omitted from + the resulting table. For example, (collect [k v (pairs {:apple \"red\" :orange \"orange\"})] - (values v k)) + v k) returns {:red \"apple\" :orange \"orange\"} @@ -4427,24 +4948,26 @@ package.preload["fennel"] = package.preload["fennel"] or function(...) Supports early termination with an :until clause." (assert (and (sequence? iter-tbl) (>= (length iter-tbl) 2)) "expected iterator binding table") - (assert (not= nil key-value-expr) "expected key-value expression") + (assert (not= nil key-expr) "expected key and value expression") (assert (= nil ...) - "expected exactly one body expression. Wrap multiple expressions with do") - `(let [tbl# ,(into-val iter-tbl)] - (each ,iter-tbl - (match ,key-value-expr - (k# v#) (tset tbl# k# v#))) - tbl#)) + "expected 1 or 2 body expressions; wrap multiple expressions with do") + (let [kv-expr (if (= nil value-expr) key-expr `(values ,key-expr ,value-expr))] + `(let [tbl# ,(into-val iter-tbl)] + (each ,iter-tbl + (match ,kv-expr + (k# v#) (tset tbl# k# v#))) + tbl#))) (fn icollect* [iter-tbl value-expr ...] "Returns a sequential table made by running an iterator and evaluating an expression that returns values to be inserted sequentially into the table. - This can be thought of as a \"list comprehension\". + This can be thought of as a \"list comprehension\". If the body returns nil + that element is omitted from the resulting table. For example, - (icollect [_ v (ipairs [1 2 3 4 5])] (when (> v 2) (* v v))) + (icollect [_ v (ipairs [1 2 3 4 5])] (when (not= v 3) (* v v))) returns - [9 16 25] + [1 4 16 25] Supports an :into clause after the iterator to put results in an existing table. Supports early termination with an :until clause." @@ -4454,8 +4977,14 @@ package.preload["fennel"] = package.preload["fennel"] or function(...) (assert (= nil ...) "expected exactly one body expression. Wrap multiple expressions with do") `(let [tbl# ,(into-val iter-tbl)] + ;; believe it or not, using a var here has a pretty good performance boost: + ;; https://p.hagelb.org/icollect-performance.html + (var i# (length tbl#)) (each ,iter-tbl - (tset tbl# (+ (length tbl#) 1) ,value-expr)) + (let [val# ,value-expr] + (when (not= nil val#) + (set i# (+ i# 1)) + (tset tbl# i# val#)))) tbl#)) (fn accumulate* [iter-tbl accum-expr ...] @@ -4598,23 +5127,23 @@ package.preload["fennel"] = package.preload["fennel"] or function(...) (assert (and binding1 module-name1 (= 0 (% (select "#" ...) 2))) "expected even number of binding/modulename pairs") (for [i 1 (select "#" binding1 module-name1 ...) 2] + ;; delegate the actual loading of the macros to the require-macros + ;; special which already knows how to set up the compiler env and stuff. + ;; this is weird because require-macros is deprecated but it works. (let [(binding modname) (select i binding1 module-name1 ...) - ;; generate a subscope of current scope, use require-macros - ;; to bring in macro module. after that, we just copy the - ;; macros from subscope to scope. scope (get-scope) - subscope (fennel.scope scope)] - (_SPECIALS.require-macros `(require-macros ,modname) subscope {} ast) + macros* (_SPECIALS.require-macros `(import-macros ,modname) + scope {} binding1)] (if (sym? binding) ;; bind whole table of macros to table bound to symbol - (tset scope.macros (. binding 1) (. macro-loaded modname)) + (tset scope.macros (. binding 1) macros*) ;; 1-level table destructuring for importing individual macros (table? binding) (each [macro-name [import-key] (pairs binding)] - (assert (= :function (type (. subscope.macros macro-name))) + (assert (= :function (type (. macros* macro-name))) (.. "macro " macro-name " not found in module " (tostring modname))) - (tset scope.macros import-key (. subscope.macros macro-name)))))) + (tset scope.macros import-key (. macros* macro-name)))))) nil) ;;; Pattern matching @@ -4635,12 +5164,16 @@ package.preload["fennel"] = package.preload["fennel"] or function(...) bindings []] (each [k pat (pairs pattern)] (if (= pat `&) - (do + (let [rest-pat (. pattern (+ k 1)) + rest-val `(select ,k ((or table.unpack _G.unpack) ,val)) + subcondition (match-table `(pick-values 1 ,rest-val) + rest-pat unifications match-pattern)] + (if (not (sym? rest-pat)) + (table.insert condition subcondition)) (assert (= nil (. pattern (+ k 2))) "expected & rest argument before last parameter") - (table.insert bindings (. pattern (+ k 1))) - (table.insert bindings - [`(select ,k ((or table.unpack _G.unpack) ,val))])) + (table.insert bindings rest-pat) + (table.insert bindings [rest-val])) (= k `&as) (do (table.insert bindings pat) @@ -4829,17 +5362,17 @@ package.preload["fennel"] = package.preload["fennel"] or function(...) ]===] local module_name = "fennel.macros" local _ - local function _567_() + local function _620_() return mod end - package.preload[module_name] = _567_ + package.preload[module_name] = _620_ _ = nil local env do - local _568_ = specials["make-compiler-env"](nil, compiler.scopes.compiler, {}) - do end (_568_)["utils"] = utils - _568_["fennel"] = mod - env = _568_ + local _621_ = specials["make-compiler-env"](nil, compiler.scopes.compiler, {}) + do end (_621_)["utils"] = utils + _621_["fennel"] = mod + env = _621_ end local built_ins = eval(builtin_macros, {env = env, scope = compiler.scopes.compiler, allowedGlobals = false, useMetadata = true, filename = "src/fennel/macros.fnl", moduleName = module_name}) for k, v in pairs(built_ins) do @@ -4852,23 +5385,25 @@ package.preload["fennel"] = package.preload["fennel"] or function(...) end fennel = require("fennel") local unpack = (table.unpack or _G.unpack) -local help = "\nUsage: fennel [FLAG] [FILE]\n\nRun fennel, a lisp programming language for the Lua runtime.\n\n --repl : Command to launch an interactive repl session\n --compile FILES (-c) : Command to AOT compile files, writing Lua to stdout\n --eval SOURCE (-e) : Command to evaluate source code and print the result\n\n --no-searcher : Skip installing package.searchers entry\n --indent VAL : Indent compiler output with VAL\n --add-package-path PATH : Add PATH to package.path for finding Lua modules\n --add-fennel-path PATH : Add PATH to fennel.path for finding Fennel modules\n --globals G1[,G2...] : Allow these globals in addition to standard ones\n --globals-only G1[,G2] : Same as above, but exclude standard ones\n --require-as-include : Inline required modules in the output\n --skip-include M1[,M2] : Omit certain modules from output when included\n --use-bit-lib : Use LuaJITs bit library instead of operators\n --metadata : Enable function metadata, even in compiled output\n --no-metadata : Disable function metadata, even in REPL\n --correlate : Make Lua output line numbers match Fennel input\n --load FILE (-l) : Load the specified FILE before executing the command\n --lua LUA_EXE : Run in a child process with LUA_EXE\n --no-fennelrc : Skip loading ~/.fennelrc when launching repl\n --raw-errors : Disable friendly compile error reporting\n --plugin FILE : Activate the compiler plugin in FILE\n --compile-binary FILE\n OUT LUA_LIB LUA_DIR : Compile FILE to standalone binary OUT\n --compile-binary --help : Display further help for compiling binaries\n --no-compiler-sandbox : Do not limit compiler environment to minimal sandbox\n\n --help (-h) : Display this text\n --version (-v) : Show version\n\nGlobals are not checked when doing AOT (ahead-of-time) compilation unless\nthe --globals-only or --globals flag is provided. Use --globals \"*\" to disable\nstrict globals checking in other contexts.\n\nMetadata is typically considered a development feature and is not recommended\nfor production. It is used for docstrings and enabled by default in the REPL.\n\nWhen not given a command, runs the file given as the first argument.\nWhen given neither command nor file, launches a repl.\n\nIf ~/.fennelrc exists, it will be loaded before launching a repl." +local help = "\nUsage: fennel [FLAG] [FILE]\n\nRun fennel, a lisp programming language for the Lua runtime.\n\n --repl : Command to launch an interactive repl session\n --compile FILES (-c) : Command to AOT compile files, writing Lua to stdout\n --eval SOURCE (-e) : Command to evaluate source code and print the result\n\n --no-searcher : Skip installing package.searchers entry\n --indent VAL : Indent compiler output with VAL\n --add-package-path PATH : Add PATH to package.path for finding Lua modules\n --add-fennel-path PATH : Add PATH to fennel.path for finding Fennel modules\n --add-macro-path PATH : Add PATH to fennel.macro-path for finding Fennel macro modules\n --globals G1[,G2...] : Allow these globals in addition to standard ones\n --globals-only G1[,G2] : Same as above, but exclude standard ones\n --require-as-include : Inline required modules in the output\n --skip-include M1[,M2] : Omit certain modules from output when included\n --use-bit-lib : Use LuaJITs bit library instead of operators\n --metadata : Enable function metadata, even in compiled output\n --no-metadata : Disable function metadata, even in REPL\n --correlate : Make Lua output line numbers match Fennel input\n --load FILE (-l) : Load the specified FILE before executing the command\n --lua LUA_EXE : Run in a child process with LUA_EXE\n --no-fennelrc : Skip loading ~/.fennelrc when launching repl\n --raw-errors : Disable friendly compile error reporting\n --plugin FILE : Activate the compiler plugin in FILE\n --compile-binary FILE\n OUT LUA_LIB LUA_DIR : Compile FILE to standalone binary OUT\n --compile-binary --help : Display further help for compiling binaries\n --no-compiler-sandbox : Do not limit compiler environment to minimal sandbox\n\n --help (-h) : Display this text\n --version (-v) : Show version\n\nGlobals are not checked when doing AOT (ahead-of-time) compilation unless\nthe --globals-only or --globals flag is provided. Use --globals \"*\" to disable\nstrict globals checking in other contexts.\n\nMetadata is typically considered a development feature and is not recommended\nfor production. It is used for docstrings and enabled by default in the REPL.\n\nWhen not given a command, runs the file given as the first argument.\nWhen given neither command nor file, launches a repl.\n\nIf ~/.fennelrc exists, it will be loaded before launching a repl." local options = {plugins = {}} local function dosafely(f, ...) local args = {...} - local _569_, _570_ = nil, nil - local function _571_() + local _622_, _623_ = nil, nil + local function _624_() return f(unpack(args)) end - _569_, _570_ = xpcall(_571_, fennel.traceback) - if ((_569_ == true) and (nil ~= _570_)) then - local val = _570_ + _622_, _623_ = xpcall(_624_, fennel.traceback) + if ((_622_ == true) and (nil ~= _623_)) then + local val = _623_ return val - elseif (true and (nil ~= _570_)) then - local _ = _569_ - local msg = _570_ + elseif (true and (nil ~= _623_)) then + local _ = _622_ + local msg = _623_ do end (io.stderr):write((msg .. "\n")) return os.exit(1) + else + return nil end end local function allow_globals(global_names, globals) @@ -4877,11 +5412,17 @@ local function allow_globals(global_names, globals) return nil else do - local tbl_13_auto = {} + local tbl_14_auto = {} + local i_15_auto = #tbl_14_auto for g in global_names:gmatch("([^,]+),?") do - tbl_13_auto[(#tbl_13_auto + 1)] = g + local val_16_auto = 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 + else + end end - options.allowedGlobals = tbl_13_auto + options.allowedGlobals = tbl_14_auto end for global_name in pairs(globals) do table.insert(options.allowedGlobals, global_name) @@ -4902,93 +5443,106 @@ local function handle_lua(i) table.insert(cmd, string.format("%q", arg[i0])) end local ok = os.execute(table.concat(cmd, " ")) - local _574_ + local _628_ if ok then - _574_ = 0 + _628_ = 0 else - _574_ = 1 + _628_ = 1 end - return os.exit(_574_, true) + return os.exit(_628_, true) end for i = #arg, 1, -1 do - local _576_ = arg[i] - if (_576_ == "--lua") then + local _630_ = arg[i] + if (_630_ == "--lua") then handle_lua(i) + else end end for i = #arg, 1, -1 do - local _578_ = arg[i] - if (_578_ == "--no-searcher") then + local _632_ = arg[i] + if (_632_ == "--no-searcher") then options["no-searcher"] = true table.remove(arg, i) - elseif (_578_ == "--indent") then + elseif (_632_ == "--indent") then options.indent = table.remove(arg, (i + 1)) if (options.indent == "false") then options.indent = false + else end table.remove(arg, i) - elseif (_578_ == "--add-package-path") then + elseif (_632_ == "--add-package-path") then local entry = table.remove(arg, (i + 1)) package.path = (entry .. ";" .. package.path) table.remove(arg, i) - elseif (_578_ == "--add-fennel-path") then + elseif (_632_ == "--add-fennel-path") then local entry = table.remove(arg, (i + 1)) fennel.path = (entry .. ";" .. fennel.path) table.remove(arg, i) - elseif (_578_ == "--load") then + elseif (_632_ == "--add-macro-path") then + local entry = table.remove(arg, (i + 1)) + fennel["macro-path"] = (entry .. ";" .. fennel["macro-path"]) + table.remove(arg, i) + elseif (_632_ == "--load") then handle_load(i) - elseif (_578_ == "-l") then + elseif (_632_ == "-l") then handle_load(i) - elseif (_578_ == "--no-fennelrc") then + elseif (_632_ == "--no-fennelrc") then options.fennelrc = false table.remove(arg, i) - elseif (_578_ == "--correlate") then + elseif (_632_ == "--correlate") then options.correlate = true table.remove(arg, i) - elseif (_578_ == "--check-unused-locals") then + elseif (_632_ == "--check-unused-locals") then options.checkUnusedLocals = true table.remove(arg, i) - elseif (_578_ == "--globals") then + elseif (_632_ == "--globals") then allow_globals(table.remove(arg, (i + 1)), _G) table.remove(arg, i) - elseif (_578_ == "--globals-only") then + elseif (_632_ == "--globals-only") then allow_globals(table.remove(arg, (i + 1)), {}) table.remove(arg, i) - elseif (_578_ == "--require-as-include") then + elseif (_632_ == "--require-as-include") then options.requireAsInclude = true table.remove(arg, i) - elseif (_578_ == "--skip-include") then + elseif (_632_ == "--skip-include") then local skip_names = table.remove(arg, (i + 1)) local skip do - local tbl_13_auto = {} + local tbl_14_auto = {} + local i_15_auto = #tbl_14_auto for m in skip_names:gmatch("([^,]+)") do - tbl_13_auto[(#tbl_13_auto + 1)] = m + local val_16_auto = m + 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 - skip = tbl_13_auto + skip = tbl_14_auto end options.skipInclude = skip table.remove(arg, i) - elseif (_578_ == "--use-bit-lib") then + elseif (_632_ == "--use-bit-lib") then options.useBitLib = true table.remove(arg, i) - elseif (_578_ == "--metadata") then + elseif (_632_ == "--metadata") then options.useMetadata = true table.remove(arg, i) - elseif (_578_ == "--no-metadata") then + elseif (_632_ == "--no-metadata") then options.useMetadata = false table.remove(arg, i) - elseif (_578_ == "--no-compiler-sandbox") then + elseif (_632_ == "--no-compiler-sandbox") then options["compiler-env"] = _G table.remove(arg, i) - elseif (_578_ == "--raw-errors") then + elseif (_632_ == "--raw-errors") then options.unfriendly = true table.remove(arg, i) - elseif (_578_ == "--plugin") then + elseif (_632_ == "--plugin") then local opts = {env = "_COMPILER", useMetadata = true, ["compiler-env"] = _G} local plugin = fennel.dofile(table.remove(arg, (i + 1)), opts) table.insert(options.plugins, 1, plugin) table.remove(arg, i) + else end end local searcher_opts = {} @@ -4997,11 +5551,13 @@ if not options["no-searcher"] then searcher_opts[k] = v end table.insert((package.loaders or package.searchers), fennel["make-searcher"](searcher_opts)) +else end local function try_readline(ok, readline) if ok then if readline.set_readline_name then readline.set_readline_name("fennel") + else end readline.set_options({keeplines = 1000, histfile = ""}) options.readChunk = function(parser_state) @@ -5014,6 +5570,8 @@ local function try_readline(ok, readline) local str = readline.readline(prompt) if str then return (str .. "\n") + else + return nil end end local completer = nil @@ -5031,6 +5589,8 @@ local function try_readline(ok, readline) end readline.set_complete_function(repl_completer) return readline + else + return nil end end local function load_initfile() @@ -5049,33 +5609,38 @@ local function load_initfile() if init0 then init0:close() return dosafely(fennel.dofile, init_filename, options, options, fennel) + else + return nil end end local function repl() local readline = (("dumb" ~= os.getenv("TERM")) and try_readline(pcall(require, "readline"))) searcher_opts.useMetadata = (false ~= options.useMetadata) - options.pp = require("fennel.view") if (false ~= options.fennelrc) then load_initfile() + else end print(("Welcome to Fennel " .. fennel.version .. " on " .. _VERSION .. "!")) print("Use ,help to see available commands.") if (not readline and ("dumb" ~= os.getenv("TERM"))) then print("Try installing readline via luarocks for a better repl experience.") + else end fennel.repl(options) if readline then return readline.save_history() + else + return nil end end local function eval(form) - local _592_ + local _647_ if (form == "-") then - _592_ = (io.stdin):read("*a") + _647_ = (io.stdin):read("*a") else - _592_ = form + _647_ = form end - return print(dosafely(fennel.eval, _592_, options)) + return print(dosafely(fennel.eval, _647_, options)) end local function compile(files) for _, filename in ipairs(files) do @@ -5087,78 +5652,81 @@ local function compile(files) f = assert(io.open(filename, "rb")) end do - local _595_, _596_ = nil, nil - local function _597_() + local _650_, _651_ = nil, nil + local function _652_() return fennel["compile-string"](f:read("*a"), options) end - _595_, _596_ = xpcall(_597_, fennel.traceback) - if ((_595_ == true) and (nil ~= _596_)) then - local val = _596_ + _650_, _651_ = xpcall(_652_, fennel.traceback) + if ((_650_ == true) and (nil ~= _651_)) then + local val = _651_ print(val) - elseif (true and (nil ~= _596_)) then - local _0 = _595_ - local msg = _596_ + elseif (true and (nil ~= _651_)) then + local _0 = _650_ + local msg = _651_ do end (io.stderr):write((msg .. "\n")) os.exit(1) + else end end f:close() end return nil end -local _599_ = arg -local function _600_(...) +local _654_ = arg +local function _655_(...) return (0 == #arg) end -if ((_G.type(_599_) == "table") and _600_(...)) then +if ((_G.type(_654_) == "table") and _655_(...)) then return repl() -elseif ((_G.type(_599_) == "table") and ((_599_)[1] == "--repl")) then +elseif ((_G.type(_654_) == "table") and ((_654_)[1] == "--repl")) then return repl() -elseif ((_G.type(_599_) == "table") and ((_599_)[1] == "--compile")) then - local files = {select(2, (table.unpack or _G.unpack)(_599_))} +elseif ((_G.type(_654_) == "table") and ((_654_)[1] == "--compile")) then + local files = {select(2, (table.unpack or _G.unpack)(_654_))} return compile(files) -elseif ((_G.type(_599_) == "table") and ((_599_)[1] == "-c")) then - local files = {select(2, (table.unpack or _G.unpack)(_599_))} +elseif ((_G.type(_654_) == "table") and ((_654_)[1] == "-c")) then + local files = {select(2, (table.unpack or _G.unpack)(_654_))} return compile(files) -elseif ((_G.type(_599_) == "table") and ((_599_)[1] == "--compile-binary") and (nil ~= (_599_)[2]) and (nil ~= (_599_)[3]) and (nil ~= (_599_)[4]) and (nil ~= (_599_)[5])) then - local filename = (_599_)[2] - local out = (_599_)[3] - local static_lua = (_599_)[4] - local lua_include_dir = (_599_)[5] - local args = {select(6, (table.unpack or _G.unpack)(_599_))} +elseif ((_G.type(_654_) == "table") and ((_654_)[1] == "--compile-binary") and (nil ~= (_654_)[2]) and (nil ~= (_654_)[3]) and (nil ~= (_654_)[4]) and (nil ~= (_654_)[5])) then + local filename = (_654_)[2] + local out = (_654_)[3] + local static_lua = (_654_)[4] + local lua_include_dir = (_654_)[5] + local args = {select(6, (table.unpack or _G.unpack)(_654_))} local bin = require("fennel.binary") options.filename = filename options.requireAsInclude = true return bin.compile(filename, out, static_lua, lua_include_dir, options, args) -elseif ((_G.type(_599_) == "table") and ((_599_)[1] == "--compile-binary")) then +elseif ((_G.type(_654_) == "table") and ((_654_)[1] == "--compile-binary")) then return print((require("fennel.binary")).help) -elseif ((_G.type(_599_) == "table") and ((_599_)[1] == "--eval") and (nil ~= (_599_)[2])) then - local form = (_599_)[2] +elseif ((_G.type(_654_) == "table") and ((_654_)[1] == "--eval") and (nil ~= (_654_)[2])) then + local form = (_654_)[2] return eval(form) -elseif ((_G.type(_599_) == "table") and ((_599_)[1] == "-e") and (nil ~= (_599_)[2])) then - local form = (_599_)[2] +elseif ((_G.type(_654_) == "table") and ((_654_)[1] == "-e") and (nil ~= (_654_)[2])) then + local form = (_654_)[2] return eval(form) else - local function _620_(...) - local a = (_599_)[1] + local function _683_(...) + local a = (_654_)[1] return ((a == "-v") or (a == "--version")) end - if (((_G.type(_599_) == "table") and (nil ~= (_599_)[1])) and _620_(...)) then - local a = (_599_)[1] + if (((_G.type(_654_) == "table") and (nil ~= (_654_)[1])) and _683_(...)) then + local a = (_654_)[1] return print(("Fennel " .. fennel.version .. " on " .. _VERSION)) - elseif ((_G.type(_599_) == "table") and ((_599_)[1] == "--help")) then + elseif ((_G.type(_654_) == "table") and ((_654_)[1] == "--help")) then return print(help) - elseif ((_G.type(_599_) == "table") and ((_599_)[1] == "-h")) then + elseif ((_G.type(_654_) == "table") and ((_654_)[1] == "-h")) then return print(help) - elseif ((_G.type(_599_) == "table") and ((_599_)[1] == "-")) then - local args = {select(2, (table.unpack or _G.unpack)(_599_))} + elseif ((_G.type(_654_) == "table") and ((_654_)[1] == "-")) then + local args = {select(2, (table.unpack or _G.unpack)(_654_))} return dosafely(fennel.eval, (io.stdin):read("*a")) - elseif ((_G.type(_599_) == "table") and (nil ~= (_599_)[1])) then - local filename = (_599_)[1] - local args = {select(2, (table.unpack or _G.unpack)(_599_))} + elseif ((_G.type(_654_) == "table") and (nil ~= (_654_)[1])) then + local filename = (_654_)[1] + local args = {select(2, (table.unpack or _G.unpack)(_654_))} arg[-2] = arg[-1] arg[-1] = arg[0] arg[0] = table.remove(arg, 1) return dosafely(fennel.dofile, filename, options, unpack(args)) + else + return nil end end diff --git a/lib/fennel.lua b/lib/fennel.lua index 2ba28e3..8f158ee 100644 --- a/lib/fennel.lua +++ b/lib/fennel.lua @@ -3,16 +3,17 @@ package.preload["fennel.repl"] = package.preload["fennel.repl"] or function(...) local parser = require("fennel.parser") local compiler = require("fennel.compiler") local specials = require("fennel.specials") + local view = require("fennel.view") local unpack = (table.unpack or _G.unpack) local function default_read_chunk(parser_state) - local function _481_() + local function _519_() if (0 < parser_state["stack-size"]) then return ".." else return ">> " end end - io.write(_481_()) + io.write(_519_()) io.flush() local input = io.read() return (input and (input .. "\n")) @@ -22,22 +23,23 @@ package.preload["fennel.repl"] = package.preload["fennel.repl"] or function(...) return io.write("\n") end local function default_on_error(errtype, err, lua_source) - local function _483_() - local _482_ = errtype - if (_482_ == "Lua Compile") then + local function _521_() + local _520_ = errtype + if (_520_ == "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 (_482_ == "Runtime") then + elseif (_520_ == "Runtime") then return (compiler.traceback(tostring(err), 4) .. "\n") - else - local _ = _482_ + elseif true then + local _ = _520_ return ("%s error: %s\n"):format(errtype, tostring(err)) + else + return nil end end - return io.write(_483_()) + return io.write(_521_()) 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) - env.___replLocals___ = (env.___replLocals___ or {}) local spliced_source = {} local bind = "local %s = ___replLocals___['%s']" for line in lua_source:gmatch("([^\n]+)\n?") do @@ -48,6 +50,7 @@ package.preload["fennel.repl"] = package.preload["fennel.repl"] or function(...) end if ((1 < #spliced_source) and (spliced_source[#spliced_source]):match("^ *return .*$")) then table.insert(spliced_source, #spliced_source, save_source) + else end return table.concat(spliced_source, "\n") end @@ -64,14 +67,15 @@ package.preload["fennel.repl"] = package.preload["fennel.repl"] or function(...) k0 = k end if ((#matches < 2000) and (type(k0) == "string") and (input == k0:sub(0, #input)) and (not method_3f or ("function" == type(tbl[k0])))) then - local function _487_() + local function _525_() if method_3f then return (prefix .. ":" .. k0) else return (prefix .. k0) end end - table.insert(matches, _487_()) + table.insert(matches, _525_()) + else end end return nil @@ -84,12 +88,7 @@ package.preload["fennel.repl"] = package.preload["fennel.repl"] or function(...) splitter = "^([^.]+)%.(.*)" end local head, tail = input:match(splitter) - local raw_head - if ((tbl == env) or (tbl == env.___replLocals___)) then - raw_head = scope.manglings[head] - else - raw_head = head - end + local raw_head = (scope.manglings[head] or head) if (type(tbl[raw_head]) == "table") then stop_looking_3f = true if method_3f then @@ -97,6 +96,8 @@ package.preload["fennel.repl"] = package.preload["fennel.repl"] or function(...) else return add_matches(tail, tbl[raw_head], (prefix .. head)) end + else + return nil end end local function add_matches(input, tbl, prefix) @@ -115,10 +116,8 @@ package.preload["fennel.repl"] = package.preload["fennel.repl"] 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 end add_matches(input_fragment, source) - if stop_looking_3f then - break - end end return matches end @@ -127,24 +126,30 @@ package.preload["fennel.repl"] = package.preload["fennel.repl"] or function(...) return input:match("^%s*,") end local function command_docs() - local _496_ + local _532_ do - local tbl_13_auto = {} + local tbl_14_auto = {} + local i_15_auto = #tbl_14_auto for name, f in pairs(commands) do - tbl_13_auto[(#tbl_13_auto + 1)] = (" ,%s - %s"):format(name, ((compiler.metadata):get(f, "fnl/docstring") or "undocumented")) + 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 + else + end end - _496_ = tbl_13_auto + _532_ = tbl_14_auto end - return table.concat(_496_, "\n") + return table.concat(_532_, "\n") end 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")}) + 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 do end (compiler.metadata):set(commands.help, "fnl/docstring", "Show this message.") local function reload(module_name, env, on_values, on_error) - local _497_, _498_ = pcall(specials["load-code"]("return require(...)", env), module_name) - if ((_497_ == true) and (nil ~= _498_)) then - local old = _498_ + local _534_, _535_ = pcall(specials["load-code"]("return require(...)", env), module_name) + if ((_534_ == true) and (nil ~= _535_)) then + local old = _535_ local _ package.loaded[module_name] = nil _ = nil @@ -163,36 +168,40 @@ package.preload["fennel.repl"] = package.preload["fennel.repl"] or function(...) for k in pairs(old) do if (nil == (new0)[k]) then old[k] = nil + else end end package.loaded[module_name] = old + else end return on_values({"ok"}) - elseif ((_497_ == false) and (nil ~= _498_)) then - local msg = _498_ - local function _503_() - local _502_ = msg:gsub("\n.*", "") - return _502_ + elseif ((_534_ == false) and (nil ~= _535_)) then + local msg = _535_ + local function _540_() + local _539_ = msg:gsub("\n.*", "") + return _539_ end - return on_error("Runtime", _503_()) + return on_error("Runtime", _540_()) + else + return nil end end local function run_command(read, on_error, f) - local _505_, _506_, _507_ = pcall(read) - if ((_505_ == true) and (_506_ == true) and (nil ~= _507_)) then - local val = _507_ + local _542_, _543_, _544_ = pcall(read) + if ((_542_ == true) and (_543_ == true) and (nil ~= _544_)) then + local val = _544_ return f(val) - elseif ((_505_ == false) and true and true) then - local _3fparse_ok = _506_ - local _3ferr = _507_ + elseif (_542_ == false) then return on_error("Parse", "Couldn't parse input.") + else + return nil end end commands.reload = function(env, read, on_values, on_error) - local function _509_(_241) + local function _546_(_241) return reload(tostring(_241), env, on_values, on_error) end - return run_command(read, on_error, _509_) + return run_command(read, on_error, _546_) end do end (compiler.metadata):set(commands.reload, "fnl/docstring", "Reload the specified module.") commands.reset = function(env, _, on_values) @@ -201,70 +210,84 @@ package.preload["fennel.repl"] = package.preload["fennel.repl"] or function(...) end do end (compiler.metadata):set(commands.reset, "fnl/docstring", "Erase all repl-local scope.") commands.complete = function(env, read, on_values, on_error, scope, chars) - local function _510_() + local function _547_() return on_values(completer(env, scope, string.char(unpack(chars)):gsub(",complete +", ""):sub(1, -2))) end - return run_command(read, on_error, _510_) + return run_command(read, on_error, _547_) end do end (compiler.metadata):set(commands.complete, "fnl/docstring", "Print all possible completions for a given input symbol.") - local function apropos_2a(pattern, module, prefix, seen, names) - for name, module0 in pairs(module) do - if (("string" == type(name)) and (package ~= module0)) then - local _511_ = type(module0) - if (_511_ == "function") then + 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 _548_ = type(subtbl) + if (_548_ == "function") then if ((prefix .. name)):match(pattern) then table.insert(names, (prefix .. name)) + else end - elseif (_511_ == "table") then - if not seen[module0] then - local _514_ + elseif (_548_ == "table") then + if not seen[subtbl] then + local _551_ do - local _513_ = seen - _513_[module0] = true - _514_ = _513_ + local _550_ = seen + _550_[subtbl] = true + _551_ = _550_ end - apropos_2a(pattern, module0, (prefix .. name:gsub("%.", "/") .. "."), _514_, names) + apropos_2a(pattern, subtbl, (prefix .. name:gsub("%.", "/") .. "."), _551_, names) + else end + else end + else end end return names end local function apropos(pattern) local names = apropos_2a(pattern, package.loaded, "", {}, {}) - local tbl_13_auto = {} + local tbl_14_auto = {} + local i_15_auto = #tbl_14_auto for _, name in ipairs(names) do - tbl_13_auto[(#tbl_13_auto + 1)] = name:gsub("^_G%.", "") + 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 + else + end end - return tbl_13_auto + return tbl_14_auto end - commands.apropos = function(env, read, on_values, on_error, scope) - local function _518_(_241) + commands.apropos = function(_env, read, on_values, on_error, _scope) + local function _556_(_241) return on_values(apropos(tostring(_241))) end - return run_command(read, on_error, _518_) + return run_command(read, on_error, _556_) 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 do - local tbl_13_auto = {} + local tbl_14_auto = {} + local i_15_auto = #tbl_14_auto for p in path:gmatch("[^%.]+") do - tbl_13_auto[(#tbl_13_auto + 1)] = p + 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 + else + end end - paths = tbl_13_auto + paths = tbl_14_auto end local tgt = package.loaded for _, path0 in ipairs(paths) do - local _520_ + if (nil == tgt) then break end + local _559_ do - local _519_ = path0:gsub("%/", ".") - _520_ = _519_ - end - tgt = tgt[_520_] - if (nil == tgt) then - break + local _558_ = path0:gsub("%/", ".") + _559_ = _558_ end + tgt = tgt[_559_] end return tgt end @@ -273,117 +296,198 @@ package.preload["fennel.repl"] = package.preload["fennel.repl"] or function(...) for _, path in ipairs(apropos(".*")) do local tgt = apropos_follow_path(path) if ("function" == type(tgt)) then - local _522_ = (compiler.metadata):get(tgt, "fnl/docstring") - if (nil ~= _522_) then - local docstr = _522_ + local _560_ = (compiler.metadata):get(tgt, "fnl/docstring") + if (nil ~= _560_) then + local docstr = _560_ if docstr:match(pattern) then table.insert(names, path) + else end + else end + else end end return names end - commands["apropos-doc"] = function(env, read, on_values, on_error, scope) - local function _526_(_241) + commands["apropos-doc"] = function(_env, read, on_values, on_error, _scope) + local function _564_(_241) return on_values(apropos_doc(tostring(_241))) end - return run_command(read, on_error, _526_) + return run_command(read, on_error, _564_) 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(pattern) + local function apropos_show_docs(on_values, pattern) for _, path in ipairs(apropos(pattern)) do local tgt = apropos_follow_path(path) if (("function" == type(tgt)) and (compiler.metadata):get(tgt, "fnl/docstring")) then - print(specials.doc(tgt, path)) - print() + on_values(specials.doc(tgt, path)) + on_values() + else end end return nil end - commands["apropos-show-docs"] = function(env, read, _, on_error, scope) - local function _528_(_241) - return apropos_show_docs(tostring(_241)) + commands["apropos-show-docs"] = function(_env, read, on_values, on_error) + local function _566_(_241) + return apropos_show_docs(on_values, tostring(_241)) end - return run_command(read, on_error, _528_) + return run_command(read, on_error, _566_) end do end (compiler.metadata):set(commands["apropos-show-docs"], "fnl/docstring", "Print all documentations matching a pattern in function name") - local function load_plugin_commands() - if (utils.root and utils.root.options and utils.root.options.plugins) then - for _, plugin in ipairs(utils.root.options.plugins) do - for name, f in pairs(plugin) do - local _529_ = name:match("^repl%-command%-(.*)") - if (nil ~= _529_) then - local cmd_name = _529_ - commands[cmd_name] = (commands[cmd_name] or f) + local function resolve(identifier, _567_, scope) + local _arg_568_ = _567_ + local ___replLocals___ = _arg_568_["___replLocals___"] + local env = _arg_568_ + local e + local function _569_(_241, _242) + return (___replLocals___[_242] or env[_242]) + end + e = setmetatable({}, {__index = _569_}) + local code = compiler["compile-string"](tostring(identifier), {scope = scope}) + return specials["load-code"](code, e)() + end + commands.find = function(env, read, on_values, on_error, scope) + local function _570_(_241) + local _571_ + do + local _572_ = utils["sym?"](_241) + if (nil ~= _572_) then + local _573_ = resolve(_572_, env, scope) + if (nil ~= _573_) then + _571_ = debug.getinfo(_573_) + else + _571_ = _573_ end + else + _571_ = _572_ end end - return nil + if ((_G.type(_571_) == "table") and (nil ~= (_571_).short_src) and (nil ~= (_571_).linedefined) and ((_571_).what == "Lua") and (nil ~= (_571_).source)) then + local src = (_571_).short_src + local line = (_571_).linedefined + local source = (_571_).source + local fnlsrc + do + local t_576_ = compiler.sourcemap + if (nil ~= t_576_) then + t_576_ = (t_576_)[source] + else + end + if (nil ~= t_576_) then + t_576_ = (t_576_)[line] + else + end + if (nil ~= t_576_) then + t_576_ = (t_576_)[2] + else + end + fnlsrc = t_576_ + end + return on_values({string.format("%s:%s", src, (fnlsrc or line))}) + elseif (_571_ == nil) then + return on_error("Repl", "Unknown value") + elseif true then + local _ = _571_ + return on_error("Repl", "No source info") + else + return nil + end end + return run_command(read, on_error, _570_) + end + do end (compiler.metadata):set(commands.find, "fnl/docstring", "Print the filename and line number for a given function") + commands.doc = function(env, read, on_values, on_error, scope) + local function _581_(_241) + local name = tostring(_241) + local target = (scope.specials[name] or scope.macros[name] or resolve(name, env, scope)) + return on_values({specials.doc(target, name)}) + end + return run_command(read, on_error, _581_) + end + do end (compiler.metadata):set(commands.doc, "fnl/docstring", "Print the docstring and arglist for a function, macro, or special form.") + local function load_plugin_commands(plugins) + for _, plugin in ipairs((plugins or {})) do + for name, f in pairs(plugin) do + local _582_ = name:match("^repl%-command%-(.*)") + if (nil ~= _582_) then + local cmd_name = _582_ + commands[cmd_name] = (commands[cmd_name] or f) + else + end + end + end + return nil end local function run_command_loop(input, read, loop, env, on_values, on_error, scope, chars) - load_plugin_commands() local command_name = input:match(",([^%s/]+)") do - local _532_ = commands[command_name] - if (nil ~= _532_) then - local command = _532_ + local _584_ = commands[command_name] + if (nil ~= _584_) then + local command = _584_ command(env, read, on_values, on_error, scope, chars) - else - local _ = _532_ + elseif true then + local _ = _584_ if ("exit" ~= command_name) then on_values({"Unknown command", command_name}) + else end + else end end if ("exit" ~= command_name) then return loop() + else + return nil end end local function repl(options) local old_root_options = utils.root.options - local env - if options.env then - env = specials["wrap-env"](options.env) - else - env = setmetatable({}, {__index = (rawget(_G, "_ENV") or _G)}) - end + local env = specials["wrap-env"]((options.env or (rawget(_G, "_ENV") or _G))) local save_locals_3f = ((options.saveLocals ~= false) and env.debug and env.debug.getlocal) - local opts = {} - local _ - for k, v in pairs(options) do - opts[k] = v - end - _ = nil + local opts = utils.copy(options) 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) - local pp = (opts.pp or tostring) + local pp = (opts.pp or view) local byte_stream, clear_stream = parser.granulate(read_chunk) local chars = {} local read, reset = nil, nil - local function _537_(parser_state) + local function _588_(parser_state) local c = byte_stream(parser_state) table.insert(chars, c) return c end - read, reset = parser.parser(_537_) - local scope = compiler["make-scope"]() + read, reset = parser.parser(_588_) + opts.env, opts.scope = env, compiler["make-scope"]() opts.useMetadata = (options.useMetadata ~= false) if (opts.allowedGlobals == nil) then - opts.allowedGlobals = specials["current-global-names"](opts.env) + opts.allowedGlobals = specials["current-global-names"](env) + else end if opts.registerCompleter then - local function _541_() - local _539_ = env - local _540_ = scope - local function _542_(...) - return completer(_539_, _540_, ...) + local function _592_() + local _590_ = env + local _591_ = opts.scope + local function _593_(...) + return completer(_590_, _591_, ...) end - return _542_ + return _593_ end - opts.registerCompleter(_541_()) + opts.registerCompleter(_592_()) + else + end + load_plugin_commands(opts.plugins) + if save_locals_3f then + local function newindex(t, k, v) + if opts.scope.unmanglings[k] then + return rawset(t, k, v) + else + return nil + end + end + env.___replLocals___ = setmetatable({}, {__newindex = newindex}) + else end local function print_values(...) local vals = {...} @@ -398,63 +502,64 @@ package.preload["fennel.repl"] = package.preload["fennel.repl"] or function(...) for k in pairs(chars) do chars[k] = nil end + reset() local ok, parse_ok_3f, x = pcall(read) local src_string = string.char(unpack(chars)) - reset() - utils.root.options = opts if not ok then on_error("Parse", parse_ok_3f) clear_stream() return loop() elseif command_3f(src_string) then - return run_command_loop(src_string, read, loop, env, on_values, on_error, scope, chars) + return run_command_loop(src_string, read, loop, env, on_values, on_error, opts.scope, chars) else if parse_ok_3f then do - local _544_, _545_ = nil, nil - local function _547_() - local _546_ = opts - _546_["env"] = env - _546_["source"] = src_string - _546_["scope"] = scope - return _546_ + local _597_, _598_ = nil, nil + local function _600_() + local _599_ = opts + _599_["source"] = src_string + return _599_ end - _544_, _545_ = pcall(compiler.compile, x, _547_()) - if ((_544_ == false) and (nil ~= _545_)) then - local msg = _545_ + _597_, _598_ = pcall(compiler.compile, x, _600_()) + if ((_597_ == false) and (nil ~= _598_)) then + local msg = _598_ clear_stream() on_error("Compile", msg) - elseif ((_544_ == true) and (nil ~= _545_)) then - local src = _545_ + elseif ((_597_ == true) and (nil ~= _598_)) then + local src = _598_ local src0 if save_locals_3f then - src0 = splice_save_locals(env, src) + src0 = splice_save_locals(env, src, opts.scope) else src0 = src end - local _549_, _550_ = pcall(specials["load-code"], src0, env) - if ((_549_ == false) and (nil ~= _550_)) then - local msg = _550_ + local _602_, _603_ = pcall(specials["load-code"], src0, env) + if ((_602_ == false) and (nil ~= _603_)) then + local msg = _603_ clear_stream() on_error("Lua Compile", msg, src0) - elseif (true and (nil ~= _550_)) then - local _0 = _549_ - local chunk = _550_ - local function _551_() + elseif (true and (nil ~= _603_)) then + local _ = _602_ + local chunk = _603_ + local function _604_() return print_values(chunk()) end - local function _552_() - local function _553_(...) + local function _605_() + local function _606_(...) return on_error("Runtime", ...) end - return _553_ + return _606_ end - xpcall(_551_, _552_()) + xpcall(_604_, _605_()) + else end + else end end utils.root.options = old_root_options return loop() + else + return nil end end end @@ -470,14 +575,14 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct local unpack = (table.unpack or _G.unpack) local SPECIALS = compiler.scopes.global.specials local function wrap_env(env) - local function _309_(_, key) + local function _345_(_, key) if (type(key) == "string") then return env[compiler["global-unmangling"](key)] else return env[key] end end - local function _311_(_, key, value) + local function _347_(_, key, value) if (type(key) == "string") then env[compiler["global-unmangling"](key)] = value return nil @@ -486,56 +591,54 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct return nil end end - local function _313_() + local function _349_() local function putenv(k, v) - local _314_ + local _350_ if (type(k) == "string") then - _314_ = compiler["global-unmangling"](k) + _350_ = compiler["global-unmangling"](k) else - _314_ = k + _350_ = k end - return _314_, v + return _350_, v end return next, utils.kvmap(env, putenv), nil end - return setmetatable({}, {__index = _309_, __newindex = _311_, __pairs = _313_}) + return setmetatable({}, {__index = _345_, __newindex = _347_, __pairs = _349_}) end - local function current_global_names(env) + local function current_global_names(_3fenv) local mt do - local _316_ = getmetatable(env) - local function _317_() - local __pairs = (_316_).__pairs - return __pairs - end - if (((_G.type(_316_) == "table") and true) and _317_()) then - local __pairs = (_316_).__pairs - local tbl_10_auto = {} - for k, v in __pairs(env) do - local _318_, _319_ = k, v - if ((nil ~= _318_) and (nil ~= _319_)) then - local k_11_auto = _318_ - local v_12_auto = _319_ - tbl_10_auto[k_11_auto] = v_12_auto + local _352_ = getmetatable(_3fenv) + if ((_G.type(_352_) == "table") and (nil ~= (_352_).__pairs)) then + local mtpairs = (_352_).__pairs + local tbl_11_auto = {} + for k, v in mtpairs(_3fenv) do + local _353_, _354_ = k, v + if ((nil ~= _353_) and (nil ~= _354_)) then + local k_12_auto = _353_ + local v_13_auto = _354_ + tbl_11_auto[k_12_auto] = v_13_auto + else end end - mt = tbl_10_auto - elseif (_316_ == nil) then - mt = (env or _G) + mt = tbl_11_auto + elseif (_352_ == nil) then + mt = (_3fenv or _G) else - mt = nil + mt = nil end end return (mt and utils.kvmap(mt, compiler["global-unmangling"])) end - local function load_code(code, environment, filename) - local environment0 = (environment or rawget(_G, "_ENV") or _G) + local function load_code(code, _3fenv, _3ffilename) + local env = (_3fenv or rawget(_G, "_ENV") or _G) if (rawget(_G, "setfenv") and rawget(_G, "loadstring")) then - local f = assert(_G.loadstring(code, filename)) - _G.setfenv(f, environment0) - return f + local f = assert(_G.loadstring(code, _3ffilename)) + local _357_ = f + setfenv(_357_, env) + return _357_ else - return assert(load(code, filename, "t", environment0)) + return assert(load(code, _3ffilename, "t", env)) end end local function doc_2a(tgt, name) @@ -546,13 +649,13 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct 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 {"#"}), " ") - local _323_ + local _359_ if (#arglist > 0) then - _323_ = " " + _359_ = " " else - _323_ = "" + _359_ = "" end - return string.format("(%s%s%s)\n %s", name, _323_, arglist, docstring) + return string.format("(%s%s%s)\n %s", name, _359_, arglist, docstring) else return string.format("%s\n %s", name, docstring) end @@ -562,36 +665,38 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct 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, start) - local start0 = (start or 2) + local function compile_do(ast, scope, parent, _3fstart) + local start = (_3fstart or 2) local len = #ast local sub_scope = compiler["make-scope"](scope) - for i = start0, len do + for i = start, len do compiler.compile1(ast[i], sub_scope, parent, {nval = 0}) end return nil end - SPECIALS["do"] = function(ast, scope, parent, opts, start, chunk, sub_scope, pre_syms) - local start0 = (start or 2) - local sub_scope0 = (sub_scope or compiler["make-scope"](scope)) - local chunk0 = (chunk or {}) + 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 {}) local len = #ast local retexprs = {returned = true} local function compile_body(outer_target, outer_tail, outer_retexprs) - if (len < start0) then - compiler.compile1(nil, sub_scope0, chunk0, {tail = outer_tail, target = outer_target}) + if (len < start) then + compiler.compile1(nil, sub_scope, chunk, {tail = outer_tail, target = outer_target}) else - for i = start0, len do + for i = start, len do 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_scope0, chunk0, subopts) + local subexprs = compiler.compile1(ast[i], sub_scope, chunk, subopts) if (i ~= len) then compiler["keep-side-effects"](subexprs, parent, nil, ast[i]) + else end end end - compiler.emit(parent, chunk0, ast) + compiler.emit(parent, chunk, ast) compiler.emit(parent, "end", ast) + utils.hook("do", ast, sub_scope) return (outer_retexprs or retexprs) end if (opts.target or (opts.nval == 0) or opts.tail) then @@ -600,7 +705,7 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct elseif opts.nval then local syms = {} for i = 1, opts.nval do - local s = ((pre_syms and pre_syms[i]) or compiler.gensym(scope)) + local s = ((_3fpre_syms and (_3fpre_syms)[i]) or compiler.gensym(scope)) do end (syms)[i] = s retexprs[i] = utils.expr(s, "sym") end @@ -617,7 +722,6 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct fargs = "" end compiler.emit(parent, string.format("local function %s(%s)", fname, fargs), ast) - utils.hook("do", ast, sub_scope0) return compile_body(nil, true, utils.expr((fname .. "(" .. fargs .. ")"), "statement")) end end @@ -632,33 +736,45 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct for j = 2, #subexprs do table.insert(exprs, subexprs[j]) end + else end end return exprs end doc_special("values", {"..."}, "Return multiple values from a function. Must be in tail position.") local function deep_tostring(x, key_3f) - local elems = {} if utils["sequence?"](x) then - local _332_ + local _368_ do - local tbl_13_auto = {} + local tbl_14_auto = {} + local i_15_auto = #tbl_14_auto for _, v in ipairs(x) do - tbl_13_auto[(#tbl_13_auto + 1)] = deep_tostring(v) + 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 - _332_ = tbl_13_auto + _368_ = tbl_14_auto end - return ("[" .. table.concat(_332_, " ") .. "]") + return ("[" .. table.concat(_368_, " ") .. "]") elseif utils["table?"](x) then - local _333_ + local _370_ do - local tbl_13_auto = {} + local tbl_14_auto = {} + local i_15_auto = #tbl_14_auto for k, v in pairs(x) do - tbl_13_auto[(#tbl_13_auto + 1)] = (deep_tostring(k, true) .. " " .. deep_tostring(v)) + 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 end - _333_ = tbl_13_auto + _370_ = tbl_14_auto end - return ("{" .. table.concat(_333_, " ") .. "}") + return ("{" .. table.concat(_370_, " ") .. "}") elseif (key_3f and (type(x) == "string") and x:find("^[-%w?\\^_!$%&*+./@:|<=>]+$")) then return (":" .. x) elseif (type(x) == "string") then @@ -670,28 +786,31 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct local function set_fn_metadata(arg_list, docstring, parent, fn_name) if utils.root.options.useMetadata then local args - local function _335_(_241) + local function _373_(_241) return ("\"%s\""):format(deep_tostring(_241)) end - args = utils.map(arg_list, _335_) + args = utils.map(arg_list, _373_) 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 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, ", "))) + else + return nil end end local function get_fn_name(ast, scope, fn_name, multi) if (fn_name and (fn_name[1] ~= "nil")) then - local _338_ + local _376_ if not multi then - _338_ = compiler["declare-local"](fn_name, {}, scope, ast) + _376_ = compiler["declare-local"](fn_name, {}, scope, ast) else - _338_ = (compiler["symbol-to-expression"](fn_name, scope))[1] + _376_ = (compiler["symbol-to-expression"](fn_name, scope))[1] end - return _338_, not multi, 3 + return _376_, not multi, 3 else return nil, true, 2 end @@ -700,13 +819,13 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct 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 _341_ + local _379_ if local_3f then - _341_ = "local function %s(%s)" + _379_ = "local function %s(%s)" else - _341_ = "%s = function(%s)" + _379_ = "%s = function(%s)" end - compiler.emit(parent, string.format(_341_, fn_name, table.concat(arg_name_list, ", ")), ast) + compiler.emit(parent, string.format(_379_, fn_name, table.concat(arg_name_list, ", ")), ast) compiler.emit(parent, f_chunk, ast) compiler.emit(parent, "end", ast) set_fn_metadata(arg_list, docstring, parent, fn_name) @@ -720,9 +839,9 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct SPECIALS.fn = function(ast, scope, parent) local f_scope do - local _343_ = compiler["make-scope"](scope) - do end (_343_)["vararg"] = false - f_scope = _343_ + local _381_ = compiler["make-scope"](scope) + do end (_381_)["vararg"] = false + f_scope = _381_ end local f_chunk = {} local fn_sym = utils["sym?"](ast[2]) @@ -743,7 +862,7 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct compiler.destructure(arg, raw, ast, f_scope, f_chunk, {declaration = true, nomulti = true, symtype = "arg"}) return declared else - return compiler.assert(false, ("expected symbol for function parameter: %s"):format(tostring(arg)), ast[2]) + 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) @@ -762,50 +881,39 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct doc_special("fn", {"name?", "args", "docstring?", "..."}, "Function syntax. May optionally include a name and docstring.\nIf a name is provided, the function will be bound in the current scope.\nWhen called with the wrong number of args, excess args will be discarded\nand lacking args will be nil, use lambda for arity-checked functions.", true) SPECIALS.lua = function(ast, _, parent) compiler.assert(((#ast == 2) or (#ast == 3)), "expected 1 or 2 arguments", ast) - local _348_ + local _386_ do - local _347_ = utils["sym?"](ast[2]) - if _347_ then - _348_ = tostring(_347_) + local _385_ = utils["sym?"](ast[2]) + if (nil ~= _385_) then + _386_ = tostring(_385_) else - _348_ = _347_ + _386_ = _385_ end end - if ("nil" ~= _348_) then + if ("nil" ~= _386_) then table.insert(parent, {ast = ast, leaf = tostring(ast[2])}) + else end - local _352_ + local _390_ do - local _351_ = utils["sym?"](ast[3]) - if _351_ then - _352_ = tostring(_351_) + local _389_ = utils["sym?"](ast[3]) + if (nil ~= _389_) then + _390_ = tostring(_389_) else - _352_ = _351_ + _390_ = _389_ end end - if ("nil" ~= _352_) then + if ("nil" ~= _390_) then return tostring(ast[3]) - end - end - SPECIALS.doc = function(ast, scope, parent) - assert(utils.root.options.useMetadata, "can't look up doc with metadata disabled.") - compiler.assert((#ast == 2), "expected one argument", ast) - local target = tostring(ast[2]) - local special_or_macro = (scope.specials[target] or scope.macros[target]) - if special_or_macro then - return ("print(%q)"):format(doc_2a(special_or_macro, target)) else - local _let_355_ = compiler.compile1(ast[2], scope, parent, {nval = 1}) - local value = _let_355_[1] - return ("print(require('%s').doc(%s, '%s'))"):format((utils.root.options.moduleName or "fennel"), tostring(value), tostring(ast[2])) + return nil end end - doc_special("doc", {"x"}, "Print the docstring and arglist for a function, macro, or special form.") local function dot(ast, scope, parent) compiler.assert((1 < #ast), "expected table argument", ast) local len = #ast - local _let_357_ = compiler.compile1(ast[2], scope, parent, {nval = 1}) - local lhs = _let_357_[1] + local _let_393_ = compiler.compile1(ast[2], scope, parent, {nval = 1}) + local lhs = _let_393_[1] if (len == 2) then return tostring(lhs) else @@ -815,8 +923,8 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct if ((type(index) == "string") and utils["valid-lua-identifier?"](index)) then table.insert(indices, ("." .. index)) else - local _let_358_ = compiler.compile1(index, scope, parent, {nval = 1}) - local index0 = _let_358_[1] + local _let_394_ = compiler.compile1(index, scope, parent, {nval = 1}) + local index0 = _let_394_[1] table.insert(indices, ("[" .. tostring(index0) .. "]")) end end @@ -861,21 +969,26 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct end doc_special("var", {"name", "val"}, "Introduce new mutable local.") local function kv_3f(t) - local _362_ + local _398_ do - local tbl_13_auto = {} + local tbl_14_auto = {} + local i_15_auto = #tbl_14_auto for k in pairs(t) do - local _363_ + local val_16_auto if not ("number" == type(k)) then - _363_ = k + val_16_auto = k + else + val_16_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 else - _363_ = nil end - tbl_13_auto[(#tbl_13_auto + 1)] = _363_ end - _362_ = tbl_13_auto + _398_ = tbl_14_auto end - return (_362_)[1] + return (_398_)[1] end SPECIALS.let = function(ast, scope, parent, opts) local bindings = ast[2] @@ -902,22 +1015,24 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct end end local function disambiguate_3f(rootstr, parent) - local function _367_() - local _366_ = get_prev_line(parent) - if (nil ~= _366_) then - local prev_line = _366_ + local function _403_() + local _402_ = get_prev_line(parent) + if (nil ~= _402_) then + local prev_line = _402_ return prev_line:match("%)$") + else + return nil end end - return (rootstr:match("^{") or _367_()) + return (rootstr:match("^{") or _403_()) end SPECIALS.tset = function(ast, scope, parent) compiler.assert((#ast > 3), "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_369_ = compiler.compile1(ast[i], scope, parent, {nval = 1}) - local key = _let_369_[1] + local _let_405_ = compiler.compile1(ast[i], scope, parent, {nval = 1}) + local key = _let_405_[1] table.insert(keys, tostring(key)) end local value = (compiler.compile1(ast[#ast], scope, parent, {nval = 1}))[1] @@ -948,6 +1063,7 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct end end local function if_2a(ast, scope, parent, opts) + compiler.assert((2 < #ast), "expected condition and body", ast) local do_scope = compiler["make-scope"](scope) local branches = {} local wrapper, inner_tail, inner_target, target_exprs = calculate_target(scope, opts) @@ -958,6 +1074,10 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct compiler["keep-side-effects"](compiler.compile1(ast[i], cscope, chunk, body_opts), chunk, nil, ast[i]) return {chunk = chunk, scope = cscope} end + if (1 == (#ast % 2)) then + table.insert(ast, utils.sym("nil")) + else + end for i = 2, (#ast - 1), 2 do local condchunk = {} local res = compiler.compile1(ast[i], do_scope, condchunk, {nval = 1}) @@ -968,8 +1088,7 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct branch.nested = ((i ~= 2) and (next(condchunk, nil) == nil)) table.insert(branches, branch) end - local has_else_3f = ((#ast > 3) and ((#ast % 2) == 0)) - local else_branch = (has_else_3f and compile_body(#ast)) + local else_branch = compile_body(#ast) local s = compiler.gensym(scope) local buffer = {} local last_buffer = buffer @@ -982,12 +1101,7 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct fstr = "elseif %s then" end local cond = tostring(branch.cond) - local cond_line - if ((cond == "true") and branch.nested and (i == #branches) and not has_else_3f) then - cond_line = "else" - else - cond_line = fstr:format(cond) - end + local cond_line = fstr:format(cond) if branch.nested then compiler.emit(last_buffer, branch.condchunk, ast) else @@ -998,13 +1112,8 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct compiler.emit(last_buffer, cond_line, ast) compiler.emit(last_buffer, branch.chunk, ast) if (i == #branches) then - if has_else_3f then - compiler.emit(last_buffer, "else", ast) - compiler.emit(last_buffer, else_branch.chunk, ast) - elseif (inner_target and (cond_line ~= "else")) then - compiler.emit(last_buffer, "else", ast) - compiler.emit(last_buffer, ("%s = nil"):format(inner_target), ast) - end + compiler.emit(last_buffer, "else", ast) + compiler.emit(last_buffer, else_branch.chunk, ast) compiler.emit(last_buffer, "end", ast) elseif not (branches[(i + 1)]).nested then local next_buffer = {} @@ -1012,6 +1121,7 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct compiler.emit(last_buffer, next_buffer, ast) compiler.emit(last_buffer, "end", ast) last_buffer = next_buffer + else end end if (wrapper == "iife") then @@ -1039,13 +1149,17 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct if ("until" == bindings[(#bindings - 1)]) then table.remove(bindings, (#bindings - 1)) return table.remove(bindings) + else + return nil end end local function compile_until(condition, scope, chunk) if condition then - local _let_379_ = compiler.compile1(condition, scope, chunk, {nval = 1}) - local condition_lua = _let_379_[1] + local _let_414_ = compiler.compile1(condition, scope, chunk, {nval = 1}) + local condition_lua = _let_414_[1] return compiler.emit(chunk, ("if %s then break end"):format(tostring(condition_lua)), utils.expr(condition, "expression")) + else + return nil end end SPECIALS.each = function(ast, scope, parent) @@ -1068,7 +1182,7 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct end end local bind_vars = utils.map(binding, destructure_binding) - local vals = compiler.compile1(iter, sub_scope, parent) + local vals = compiler.compile1(iter, scope, parent) local val_names = utils.map(vals, tostring) local chunk = {} compiler.emit(parent, ("for %s in %s do"):format(table.concat(bind_vars, ", "), table.concat(val_names, ", ")), ast) @@ -1114,7 +1228,7 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct compiler.assert((#ast >= 3), "expected body expression", ast[1]) compiler.assert((#ranges <= 3), "unexpected arguments", ranges[4]) for i = 1, math.min(#ranges, 3) do - range_args[i] = tostring((compiler.compile1(ranges[i], sub_scope, parent, {nval = 1}))[1]) + range_args[i] = tostring((compiler.compile1(ranges[i], scope, parent, {nval = 1}))[1]) end compiler.emit(parent, ("for %s = %s do"):format(compiler["declare-local"](binding_sym, {}, sub_scope, ast), table.concat(range_args, ", ")), ast) compile_until(until_condition, sub_scope, chunk) @@ -1125,10 +1239,10 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct 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_383_ = ast - local _ = _let_383_[1] - local _0 = _let_383_[2] - local method_string = _let_383_[3] + local _let_418_ = ast + local _ = _let_418_[1] + local _0 = _let_418_[2] + local method_string = _let_418_[3] local call_string if ((target.type == "literal") or (target.type == "varg") or (target.type == "expression")) then call_string = "(%s):%s(%s)" @@ -1150,18 +1264,18 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct end local function method_call(ast, scope, parent) compiler.assert((2 < #ast), "expected at least 2 arguments", ast) - local _let_385_ = compiler.compile1(ast[2], scope, parent, {nval = 1}) - local target = _let_385_[1] + local _let_420_ = compiler.compile1(ast[2], scope, parent, {nval = 1}) + local target = _let_420_[1] local args = {} for i = 4, #ast do local subexprs - local _386_ + local _421_ if (i ~= #ast) then - _386_ = 1 + _421_ = 1 else - _386_ = nil + _421_ = nil end - subexprs = compiler.compile1(ast[i], scope, parent, {nval = _386_}) + subexprs = compiler.compile1(ast[i], scope, parent, {nval = _421_}) utils.map(subexprs, tostring, args) end if ((type(ast[3]) == "string") and utils["valid-lua-identifier?"](ast[3])) then @@ -1179,7 +1293,7 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct for i = 2, #ast do table.insert(els, view(ast[i], {["one-line?"] = true})) end - return compiler.emit(parent, ("-- " .. table.concat(els, " ")), ast) + return compiler.emit(parent, ("--[[ " .. table.concat(els, " ") .. " ]]--"), ast) end doc_special("comment", {"..."}, "Comment which will be emitted in Lua output.", true) local function hashfn_max_used(f_scope, i, max) @@ -1199,10 +1313,10 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct compiler.assert((#ast == 2), "expected one argument", ast) local f_scope do - local _391_ = compiler["make-scope"](scope) - do end (_391_)["vararg"] = false - _391_["hashfn"] = true - f_scope = _391_ + local _426_ = compiler["make-scope"](scope) + do end (_426_)["vararg"] = false + _426_["hashfn"] = true + f_scope = _426_ end local f_chunk = {} local name = compiler.gensym(scope) @@ -1226,6 +1340,7 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct local max_used = hashfn_max_used(f_scope, 1, 0) if f_scope.vararg then compiler.assert((max_used == 0), "$ and $... in hashfn are mutually exclusive", ast) + else end local arg_str if f_scope.vararg then @@ -1239,53 +1354,52 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct return utils.expr(name, "sym") end doc_special("hashfn", {"..."}, "Function literal shorthand; args are either $... OR $1, $2, etc.") - local function arithmetic_special(name, zero_arity, unary_prefix, nval, ast, scope, parent) + local function arithmetic_special(name, zero_arity, unary_prefix, ast, scope, parent) local len = #ast local operands = {} local padded_op = (" " .. name .. " ") for i = 2, len do - local subexprs - local _395_ - if (i < len) then - _395_ = 1 + local subexprs = compiler.compile1(ast[i], scope, parent) + if (i == len) then + utils.map(subexprs, tostring, operands) else - _395_ = nil + table.insert(operands, tostring(subexprs[1])) end - subexprs = compiler.compile1(ast[i], scope, parent, {nval = _395_}) - utils.map(subexprs, tostring, operands) end - local _397_ = #operands - if (_397_ == 0) then - local _399_ + local _431_ = #operands + if (_431_ == 0) then + local _433_ do - local _398_ = zero_arity - compiler.assert(_398_, "Expected more than 0 arguments", ast) - _399_ = _398_ + local _432_ = zero_arity + compiler.assert(_432_, "Expected more than 0 arguments", ast) + _433_ = _432_ end - return utils.expr(_399_, "literal") - elseif (_397_ == 1) then + return utils.expr(_433_, "literal") + elseif (_431_ == 1) then if unary_prefix then return ("(" .. unary_prefix .. padded_op .. operands[1] .. ")") else return operands[1] end - else - local _ = _397_ + elseif true then + local _ = _431_ return ("(" .. table.concat(operands, padded_op) .. ")") + else + return nil end end - local function define_arithmetic_special(name, zero_arity, unary_prefix, lua_name) - local _405_ + local function define_arithmetic_special(name, zero_arity, unary_prefix, _3flua_name) + local _439_ do - local _402_ = (lua_name or name) - local _403_ = zero_arity - local _404_ = unary_prefix - local function _406_(...) - return arithmetic_special(_402_, _403_, _404_, 1, ...) + local _436_ = (_3flua_name or name) + local _437_ = zero_arity + local _438_ = unary_prefix + local function _440_(...) + return arithmetic_special(_436_, _437_, _438_, ...) end - _405_ = _406_ + _439_ = _440_ end - SPECIALS[name] = _405_ + SPECIALS[name] = _439_ return doc_special(name, {"a", "b", "..."}, "Arithmetic operator; works the same as Lua but accepts more arguments.") end define_arithmetic_special("+", "0") @@ -1297,10 +1411,10 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct define_arithmetic_special("/", nil, "1") define_arithmetic_special("//", nil, "1") SPECIALS["or"] = function(ast, scope, parent) - return arithmetic_special("or", "false", nil, nil, ast, scope, parent) + return arithmetic_special("or", "false", nil, ast, scope, parent) end SPECIALS["and"] = function(ast, scope, parent) - return arithmetic_special("and", "true", nil, nil, ast, scope, parent) + return arithmetic_special("and", "true", nil, ast, scope, parent) end 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.") @@ -1314,13 +1428,13 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct local prefixed_lib_name = ("bit." .. lib_name) for i = 2, len do local subexprs - local _407_ + local _441_ if (i ~= len) then - _407_ = 1 + _441_ = 1 else - _407_ = nil + _441_ = nil end - subexprs = compiler.compile1(ast[i], scope, parent, {nval = _407_}) + subexprs = compiler.compile1(ast[i], scope, parent, {nval = _441_}) utils.map(subexprs, tostring, operands) end if (#operands == 1) then @@ -1339,18 +1453,18 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct end end local function define_bitop_special(name, zero_arity, unary_prefix, native) - local _417_ + local _451_ do - local _413_ = native - local _414_ = name - local _415_ = zero_arity - local _416_ = unary_prefix - local function _418_(...) - return bitop_special(_413_, _414_, _415_, _416_, ...) + local _447_ = native + local _448_ = name + local _449_ = zero_arity + local _450_ = unary_prefix + local function _452_(...) + return bitop_special(_447_, _448_, _449_, _450_, ...) end - _417_ = _418_ + _451_ = _452_ end - SPECIALS[name] = _417_ + SPECIALS[name] = _451_ return nil end define_bitop_special("lshift", nil, "1", "<<") @@ -1364,15 +1478,15 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct 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, _419_, scope, parent) - local _arg_420_ = _419_ - local _ = _arg_420_[1] - local lhs_ast = _arg_420_[2] - local rhs_ast = _arg_420_[3] - local _let_421_ = compiler.compile1(lhs_ast, scope, parent, {nval = 1}) - local lhs = _let_421_[1] - local _let_422_ = compiler.compile1(rhs_ast, scope, parent, {nval = 1}) - local rhs = _let_422_[1] + local function native_comparator(op, _453_, scope, parent) + local _arg_454_ = _453_ + local _ = _arg_454_[1] + local lhs_ast = _arg_454_[2] + local rhs_ast = _arg_454_[3] + local _let_455_ = compiler.compile1(lhs_ast, scope, parent, {nval = 1}) + local lhs = _let_455_[1] + local _let_456_ = compiler.compile1(rhs_ast, scope, parent, {nval = 1}) + local rhs = _let_456_[1] return string.format("(%s %s %s)", tostring(lhs), op, tostring(rhs)) end local function double_eval_protected_comparator(op, chain_op, ast, scope, parent) @@ -1389,15 +1503,15 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct end return string.format("(function(%s) return %s end)(%s)", table.concat(arglist, ","), table.concat(comparisons, chain), table.concat(vals, ",")) end - local function define_comparator_special(name, lua_op, chain_op) + local function define_comparator_special(name, _3flua_op, _3fchain_op) do - local op = (lua_op or name) + local op = (_3flua_op or name) local function opfn(ast, scope, parent) compiler.assert((2 < #ast), "expected at least two arguments", ast) if (3 == #ast) then return native_comparator(op, ast, scope, parent) else - return double_eval_protected_comparator(op, chain_op, ast, scope, parent) + return double_eval_protected_comparator(op, _3fchain_op, ast, scope, parent) end end SPECIALS[name] = opfn @@ -1410,11 +1524,11 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct define_comparator_special("<=") define_comparator_special("=", "==") define_comparator_special("not=", "~=", "or") - local function define_unary_special(op, realop) + local function define_unary_special(op, _3frealop) local function opfn(ast, scope, parent) compiler.assert((#ast == 2), "expected one argument", ast) local tail = compiler.compile1(ast[2], scope, parent, {nval = 1}) - return ((realop or op) .. tostring(tail[1])) + return ((_3frealop or op) .. tostring(tail[1])) end SPECIALS[op] = opfn return nil @@ -1428,12 +1542,13 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct do end (SPECIALS)["~="] = SPECIALS["not="] SPECIALS["#"] = SPECIALS.length SPECIALS.quote = function(ast, scope, parent) - compiler.assert((#ast == 2), "expected one argument") + compiler.assert((#ast == 2), "expected one argument", ast) local runtime, this_scope = true, scope while this_scope do this_scope = this_scope.parent if (this_scope == compiler.scopes.compiler) then runtime = false + else end end return compiler["do-quote"](ast[2], scope, parent, runtime) @@ -1447,16 +1562,17 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct end local safe_require = nil local function safe_compiler_env() - return {table = utils.copy(table), math = utils.copy(math), string = utils.copy(string), pairs = pairs, 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} + return {table = utils.copy(table), math = utils.copy(math), string = utils.copy(string), pairs = pairs, 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} end local function combined_mt_pairs(env) local combined = {} - local _let_425_ = getmetatable(env) - local __index = _let_425_["__index"] + local _let_459_ = getmetatable(env) + local __index = _let_459_["__index"] if ("table" == type(__index)) then for k, v in pairs(__index) do combined[k] = v end + else end for k, v in next, env, nil do combined[k] = v @@ -1466,178 +1582,205 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct local function make_compiler_env(ast, scope, parent, _3fopts) local provided do - local _427_ = (_3fopts or utils.root.options) - if ((_G.type(_427_) == "table") and ((_427_)["compiler-env"] == "strict")) then + local _461_ = (_3fopts or utils.root.options) + if ((_G.type(_461_) == "table") and ((_461_)["compiler-env"] == "strict")) then provided = safe_compiler_env() - elseif ((_G.type(_427_) == "table") and (nil ~= (_427_).compilerEnv)) then - local compilerEnv = (_427_).compilerEnv + elseif ((_G.type(_461_) == "table") and (nil ~= (_461_).compilerEnv)) then + local compilerEnv = (_461_).compilerEnv provided = compilerEnv - elseif ((_G.type(_427_) == "table") and (nil ~= (_427_)["compiler-env"])) then - local compiler_env = (_427_)["compiler-env"] + elseif ((_G.type(_461_) == "table") and (nil ~= (_461_)["compiler-env"])) then + local compiler_env = (_461_)["compiler-env"] provided = compiler_env - else - local _ = _427_ + elseif true then + local _ = _461_ provided = safe_compiler_env(false) + else + provided = nil end end local env - local function _429_(base) + local function _463_(base) return utils.sym(compiler.gensym((compiler.scopes.macro or scope), base)) end - local function _430_() + local function _464_() return compiler.scopes.macro end - local function _431_(symbol) + local function _465_(symbol) compiler.assert(compiler.scopes.macro, "must call from macro", ast) return compiler.scopes.macro.manglings[tostring(symbol)] end - local function _432_(form) + local function _466_(form) compiler.assert(compiler.scopes.macro, "must call from macro", ast) return compiler.macroexpand(form, compiler.scopes.macro) end - 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, list = utils.list, ["list?"] = utils["list?"], ["multi-sym?"] = utils["multi-sym?"], sequence = utils.sequence, ["sequence?"] = utils["sequence?"], sym = utils.sym, ["sym?"] = utils["sym?"], ["table?"] = utils["table?"], ["varg?"] = utils["varg?"], view = view, gensym = _429_, ["get-scope"] = _430_, ["in-scope?"] = _431_, macroexpand = _432_} + 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, 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 = _463_, ["get-scope"] = _464_, ["in-scope?"] = _465_, macroexpand = _466_} env._G = env return setmetatable(env, {__index = provided, __newindex = provided, __pairs = combined_mt_pairs}) end - local cfg = string.gmatch(package.config, "([^\n]+)") - local dirsep, pathsep, pathmark = (cfg() or "/"), (cfg() or ";"), (cfg() or "?") - local pkg_config = {dirsep = dirsep, pathmark = pathmark, pathsep = pathsep} + local function _468_(...) + local tbl_14_auto = {} + local i_15_auto = #tbl_14_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 + else + end + end + return tbl_14_auto + end + local _local_467_ = _468_(...) + local dirsep = _local_467_[1] + local pathsep = _local_467_[2] + local pathmark = _local_467_[3] + local pkg_config = {dirsep = (dirsep or "/"), pathmark = (pathmark or ";"), pathsep = (pathsep or "?")} local function escapepat(str) return string.gsub(str, "[^%w]", "%%%1") end - local function search_module(modulename, pathstring) + local function search_module(modulename, _3fpathstring) local pathsepesc = escapepat(pkg_config.pathsep) local pattern = ("([^%s]*)%s"):format(pathsepesc, pathsepesc) local no_dot_module = modulename:gsub("%.", pkg_config.dirsep) - local fullpath = ((pathstring 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 _433_ = (io.open(filename) or io.open(filename2)) - if (nil ~= _433_) then - local file = _433_ + local _470_ = (io.open(filename) or io.open(filename2)) + if (nil ~= _470_) then + local file = _470_ file:close() return filename + else + return nil end end local function find_in_path(start) - local _435_ = fullpath:match(pattern, start) - if (nil ~= _435_) then - local path = _435_ + local _472_ = fullpath:match(pattern, start) + if (nil ~= _472_) then + local path = _472_ return (try_path(path) or find_in_path((start + #path + 1))) + else + return nil end end return find_in_path(1) end - local function make_searcher(options) - local function _437_(module_name) + local function make_searcher(_3foptions) + local function _474_(module_name) local opts = utils.copy(utils.root.options) - for k, v in pairs((options or {})) do + for k, v in pairs((_3foptions or {})) do opts[k] = v end opts["module-name"] = module_name - local _438_ = search_module(module_name) - if (nil ~= _438_) then - local filename = _438_ - local _441_ + local _475_ = search_module(module_name) + if (nil ~= _475_) then + local filename = _475_ + local _478_ do - local _439_ = filename - local _440_ = opts - local function _442_(...) - return utils["fennel-module"].dofile(_439_, _440_, ...) + local _476_ = filename + local _477_ = opts + local function _479_(...) + return utils["fennel-module"].dofile(_476_, _477_, ...) end - _441_ = _442_ + _478_ = _479_ end - return _441_, filename + return _478_, filename + else + return nil end end - return _437_ - end - local function macro_globals(env, globals) - local allowed = current_global_names(env) - for _, k in pairs((globals or {})) do - table.insert(allowed, k) - end - return allowed + return _474_ end local function fennel_macro_searcher(module_name) local opts do - local _444_ = utils.copy(utils.root.options) - do end (_444_)["env"] = "_COMPILER" - _444_["allowedGlobals"] = nil - opts = _444_ + local _481_ = utils.copy(utils.root.options) + do end (_481_)["env"] = "_COMPILER" + _481_["requireAsInclude"] = false + _481_["allowedGlobals"] = nil + opts = _481_ end - local _445_ = search_module(module_name, utils["fennel-module"]["macro-path"]) - if (nil ~= _445_) then - local filename = _445_ - local _448_ + local _482_ = search_module(module_name, utils["fennel-module"]["macro-path"]) + if (nil ~= _482_) then + local filename = _482_ + local _485_ do - local _446_ = filename - local _447_ = opts - local function _449_(...) - return utils["fennel-module"].dofile(_446_, _447_, ...) + local _483_ = filename + local _484_ = opts + local function _486_(...) + return utils["fennel-module"].dofile(_483_, _484_, ...) end - _448_ = _449_ + _485_ = _486_ end - return _448_, filename + return _485_, filename + else + return nil end end local function lua_macro_searcher(module_name) - local _451_ = search_module(module_name, package.path) - if (nil ~= _451_) then - local filename = _451_ + local _488_ = search_module(module_name, package.path) + if (nil ~= _488_) then + local filename = _488_ local code do local f = io.open(filename) - local function close_handlers_7_auto(ok_8_auto, ...) + local function close_handlers_8_auto(ok_9_auto, ...) f:close() - if ok_8_auto then + if ok_9_auto then return ... else return error(..., 0) end end - local function _453_() + local function _490_() return assert(f:read("*a")) end - code = close_handlers_7_auto(_G.xpcall(_453_, (package.loaded.fennel or debug).traceback)) + code = close_handlers_8_auto(_G.xpcall(_490_, (package.loaded.fennel or debug).traceback)) end local chunk = load_code(code, make_compiler_env(), filename) return chunk, filename + else + return nil end end - local macro_searchers = {lua_macro_searcher, fennel_macro_searcher} + local macro_searchers = {fennel_macro_searcher, lua_macro_searcher} local function search_macro_module(modname, n) - local _455_ = macro_searchers[n] - if (nil ~= _455_) then - local f = _455_ - local _456_, _457_ = f(modname) - if ((nil ~= _456_) and true) then - local loader = _456_ - local _3ffilename = _457_ + local _492_ = macro_searchers[n] + if (nil ~= _492_) then + local f = _492_ + local _493_, _494_ = f(modname) + if ((nil ~= _493_) and true) then + local loader = _493_ + local _3ffilename = _494_ return loader, _3ffilename - else - local _ = _456_ + elseif true then + local _ = _493_ return search_macro_module(modname, (n + 1)) + else + return nil end + else + return nil end end local function metadata_only_fennel(modname) 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} + else + return nil end end - local function _461_(modname) - local function _462_() + local function _498_(modname) + local function _499_() local loader, filename = search_macro_module(modname, 1) compiler.assert(loader, (modname .. " module not found.")) do end (macro_loaded)[modname] = loader(modname, filename) return macro_loaded[modname] end - return (macro_loaded[modname] or metadata_only_fennel(modname) or _462_()) + return (macro_loaded[modname] or metadata_only_fennel(modname) or _499_()) end - safe_require = _461_ + safe_require = _498_ 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 @@ -1646,26 +1789,31 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct end return nil end - local function resolve_module_name(_463_, scope, parent, opts) - local _arg_464_ = _463_ - local filename = _arg_464_["filename"] - local second = _arg_464_[2] + local function resolve_module_name(_500_, _scope, _parent, opts) + local _arg_501_ = _500_ + local filename = _arg_501_["filename"] + local second = _arg_501_[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 - SPECIALS["require-macros"] = function(ast, scope, parent, real_ast) - compiler.assert((#ast == 2), "Expected one module name argument", (real_ast or 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(("string" == type(modname)), "module name must compile to string", (real_ast or ast)) + compiler.assert(("string" == type(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) + else + end + if ("import-macros" == tostring(ast[1])) then + return macro_loaded[modname] + else + return add_macros(macro_loaded[modname], ast, scope, parent) end - return add_macros(macro_loaded[modname], ast, scope, parent) end 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) @@ -1673,6 +1821,7 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct local forms = {} if utils.root.options.requireAsInclude then subscope.specials.require = compiler["require-include"] + else end for _, val in parser.parser(parser["string-stream"](src), path) do table.insert(forms, val) @@ -1694,18 +1843,18 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct local src do local f = assert(io.open(path)) - local function close_handlers_7_auto(ok_8_auto, ...) + local function close_handlers_8_auto(ok_9_auto, ...) f:close() - if ok_8_auto then + if ok_9_auto then return ... else return error(..., 0) end end - local function _469_() + local function _507_() return f:read("*all"):gsub("[\13\n]*$", "") end - src = close_handlers_7_auto(_G.xpcall(_469_, (package.loaded.fennel or debug).traceback)) + src = close_handlers_8_auto(_G.xpcall(_507_, (package.loaded.fennel or debug).traceback)) end local ret = utils.expr(("require(\"" .. mod .. "\")"), "statement") local target = ("package.preload[%q]"):format(mod) @@ -1729,22 +1878,23 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct if (utils.root.scope.includes[mod] == "fnl/loading") then compiler.assert(fallback, "circular include detected", ast) return fallback(modexpr) + else + return nil end end SPECIALS.include = function(ast, scope, parent, opts) compiler.assert((#ast == 2), "expected one argument", ast) local modexpr do - local _472_, _473_ = pcall(resolve_module_name, ast, scope, parent, opts) - if ((_472_ == true) and (nil ~= _473_)) then - local modname = _473_ + local _510_, _511_ = pcall(resolve_module_name, ast, scope, parent, opts) + if ((_510_ == true) and (nil ~= _511_)) then + local modname = _511_ modexpr = utils.expr(string.format("%q", modname), "literal") - elseif (true and (nil ~= _473_)) then - local _ = _472_ - local err = _473_ + elseif true then + local _ = _510_ modexpr = (compiler.compile1(ast[2], scope, parent, {nval = 1}))[1] else - modexpr = nil + modexpr = nil end end if ((modexpr.type ~= "literal") or ((modexpr[1]):byte() ~= 34)) then @@ -1760,13 +1910,13 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct utils.root.options["module-name"] = mod _ = nil local res - local function _477_() - local _476_ = search_module(mod) - if (nil ~= _476_) then - local fennel_path = _476_ + local function _515_() + local _514_ = search_module(mod) + if (nil ~= _514_) then + local fennel_path = _514_ return include_path(ast, opts, fennel_path, mod, true) - else - local _0 = _476_ + elseif true then + local _0 = _514_ local lua_path = search_module(mod, package.path) if lua_path then return include_path(ast, opts, lua_path, mod, false) @@ -1775,9 +1925,11 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct else return compiler.assert(false, ("module not found " .. mod), ast) end + else + return nil end end - res = ((utils["member?"](mod, (utils.root.options.skipInclude or {})) and utils.expr("nil --[[SKIPPED INCLUDE]]--", "literal")) or include_circular_fallback(mod, modexpr, opts.fallback, ast) or utils.root.scope.includes[mod] or _477_()) + res = ((utils["member?"](mod, (utils.root.options.skipInclude or {})) and utils.expr("nil --[[SKIPPED INCLUDE]]--", "literal")) or include_circular_fallback(mod, modexpr, opts.fallback, ast) or utils.root.scope.includes[mod] or _515_()) utils.root.options["module-name"] = oldmod return res end @@ -1787,7 +1939,7 @@ package.preload["fennel.specials"] = package.preload["fennel.specials"] or funct 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 = macro_globals(env, current_global_names()) + opts.allowedGlobals = current_global_names(env) return load_code(compiler.compile(ast, opts), wrap_env(env))(opts["module-name"], ast.filename) end SPECIALS.macros = function(ast, scope, parent) @@ -1811,15 +1963,15 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct local friend = require("fennel.friend") local unpack = (table.unpack or _G.unpack) local scopes = {} - local function make_scope(parent) - local parent0 = (parent or scopes.global) - local _176_ - if parent0 then - _176_ = ((parent0.depth or 0) + 1) + local function make_scope(_3fparent) + local parent = (_3fparent or scopes.global) + local _203_ + if parent then + _203_ = ((parent.depth or 0) + 1) else - _176_ = 0 + _203_ = 0 end - return {includes = setmetatable({}, {__index = (parent0 and parent0.includes)}), macros = setmetatable({}, {__index = (parent0 and parent0.macros)}), manglings = setmetatable({}, {__index = (parent0 and parent0.manglings)}), refedglobals = setmetatable({}, {__index = (parent0 and parent0.refedglobals)}), specials = setmetatable({}, {__index = (parent0 and parent0.specials)}), symmeta = setmetatable({}, {__index = (parent0 and parent0.symmeta)}), unmanglings = setmetatable({}, {__index = (parent0 and parent0.unmanglings)}), gensyms = setmetatable({}, {__index = (parent0 and parent0.gensyms)}), autogensyms = setmetatable({}, {__index = (parent0 and parent0.autogensyms)}), vararg = (parent0 and parent0.vararg), depth = _176_, hashfn = (parent0 and parent0.hashfn), parent = parent0} + 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 = _203_, hashfn = (parent and parent.hashfn), refedglobals = {}, parent = parent} end local function assert_msg(ast, msg) local ast_tbl @@ -1836,15 +1988,19 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct end local function assert_compile(condition, msg, ast) if not condition then - local _let_179_ = (utils.root.options or {}) - local source = _let_179_["source"] - local unfriendly = _let_179_["unfriendly"] - utils.root.reset() - if (unfriendly or not friend or not _G.io or not _G.io.read) then - error(assert_msg(ast, msg), 0) + local _let_206_ = (utils.root.options or {}) + local source = _let_206_["source"] + local unfriendly = _let_206_["unfriendly"] + if (nil == utils.hook("assert-compile", condition, msg, ast, 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) + else + friend["assert-compile"](condition, msg, ast, source) + end else - friend["assert-compile"](condition, msg, ast, source) end + else end return condition end @@ -1854,34 +2010,36 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct scopes.macro = scopes.global local serialize_subst = {["\7"] = "\\a", ["\8"] = "\\b", ["\9"] = "\\t", ["\n"] = "n", ["\11"] = "\\v", ["\12"] = "\\f"} local function serialize_string(str) - local function _182_(_241) + local function _210_(_241) return ("\\" .. _241:byte()) end - return string.gsub(string.gsub(string.format("%q", str), ".", serialize_subst), "[\128-\255]", _182_) + return string.gsub(string.gsub(string.format("%q", str), ".", serialize_subst), "[\128-\255]", _210_) end local function global_mangling(str) if utils["valid-lua-identifier?"](str) then return str else - local function _183_(_241) + local function _211_(_241) return string.format("_%02x", _241:byte()) end - return ("__fnl_global__" .. str:gsub("[^%w]", _183_)) + return ("__fnl_global__" .. str:gsub("[^%w]", _211_)) end end local function global_unmangling(identifier) - local _185_ = string.match(identifier, "^__fnl_global__(.*)$") - if (nil ~= _185_) then - local rest = _185_ - local _186_ - local function _187_(_241) + local _213_ = string.match(identifier, "^__fnl_global__(.*)$") + if (nil ~= _213_) then + local rest = _213_ + local _214_ + local function _215_(_241) return string.char(tonumber(_241:sub(2), 16)) end - _186_ = string.gsub(rest, "_[%da-f][%da-f]", _187_) - return _186_ - else - local _ = _185_ + _214_ = string.gsub(rest, "_[%da-f][%da-f]", _215_) + return _214_ + elseif true then + local _ = _213_ return identifier + else + return nil end end local allowed_globals = nil @@ -1895,7 +2053,7 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct return mangling end end - local function local_mangling(str, scope, ast, temp_manglings) + local function local_mangling(str, scope, ast, _3ftemp_manglings) assert_compile(not utils["multi-sym?"](str), ("unexpected multi symbol " .. str), ast) local raw if ((utils["lua-keywords"])[str] or str:match("^%d")) then @@ -1904,14 +2062,14 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct raw = str end local mangling - local function _191_(_241) + local function _219_(_241) return string.format("_%02x", _241:byte()) end - mangling = string.gsub(string.gsub(raw, "-", "_"), "[^%w_]", _191_) + mangling = string.gsub(string.gsub(raw, "-", "_"), "[^%w_]", _219_) local unique = unique_mangling(mangling, mangling, scope, 0) do end (scope.unmanglings)[unique] = str do - local manglings = (temp_manglings or scope.manglings) + local manglings = (_3ftemp_manglings or scope.manglings) do end (manglings)[str] = unique end return unique @@ -1942,29 +2100,31 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct utils.root.scope["gensym-append"] = ((utils.root.scope["gensym-append"] or 0) + 1) return ("_" .. utils.root.scope["gensym-append"] .. "_") end - local function gensym(scope, base, _3fsuffix) - local mangling = ((base or "") .. next_append() .. (_3fsuffix or "")) + local function gensym(scope, _3fbase, _3fsuffix) + local mangling = ((_3fbase or "") .. next_append() .. (_3fsuffix or "")) while scope.unmanglings[mangling] do - mangling = ((base or "") .. next_append() .. (_3fsuffix or "")) + mangling = ((_3fbase or "") .. next_append() .. (_3fsuffix or "")) end - scope.unmanglings[mangling] = (base or true) + scope.unmanglings[mangling] = (_3fbase or true) do end (scope.gensyms)[mangling] = true return mangling end local function autogensym(base, scope) - local _194_ = utils["multi-sym?"](base) - if (nil ~= _194_) then - local parts = _194_ + local _222_ = utils["multi-sym?"](base) + if (nil ~= _222_) then + local parts = _222_ parts[1] = autogensym(parts[1], scope) return table.concat(parts, ((parts["multi-sym-method-call"] and ":") or ".")) - else - local _ = _194_ - local function _195_() + elseif true then + local _ = _222_ + local function _223_() local mangling = gensym(scope, base:sub(1, ( - 2)), "auto") do end (scope.autogensyms)[base] = mangling return mangling end - return (scope.autogensyms[base] or _195_()) + return (scope.autogensyms[base] or _223_()) + else + return nil end end local function check_binding_valid(symbol, scope, ast) @@ -1973,12 +2133,12 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct assert_compile(not (scope.specials[name] or 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, temp_manglings) + 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 - return local_mangling(name, scope, ast, temp_manglings) + return local_mangling(name, scope, ast, _3ftemp_manglings) end local function hashfn_arg_name(name, multi_sym_parts, scope) if not scope.hashfn then @@ -1988,12 +2148,15 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct elseif multi_sym_parts then if (multi_sym_parts and (multi_sym_parts[1] == "$")) then multi_sym_parts[1] = "$1" + else end return table.concat(multi_sym_parts, ".") + else + return nil end end - local function symbol_to_expression(symbol, scope, reference_3f) - utils.hook("symbol-to-expression", symbol, scope, reference_3f) + local function symbol_to_expression(symbol, scope, _3freference_3f) + utils.hook("symbol-to-expression", symbol, scope, _3freference_3f) local name = symbol[1] local multi_sym_parts = utils["multi-sym?"](name) local name0 = (hashfn_arg_name(name, multi_sym_parts, scope) or name) @@ -2002,19 +2165,21 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct local local_3f = scope.manglings[parts[1]] if (local_3f and scope.symmeta[parts[1]]) then 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 reference_3f or local_3f or ("_ENV" == parts[1]) or global_allowed_3f(parts[1])), ("unknown global in strict mode: " .. tostring(parts[1])), symbol) - if (allowed_globals and not local_3f) then - utils.root.scope.refedglobals[parts[1]] = true + 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 + scope.parent.refedglobals[parts[1]] = true + else end return utils.expr(combine_parts(parts, scope), etype) end - local function emit(chunk, out, ast) + local function emit(chunk, out, _3fast) if (type(out) == "table") then return table.insert(chunk, out) else - return table.insert(chunk, {ast = ast, leaf = out}) + return table.insert(chunk, {ast = _3fast, leaf = out}) end end local function peephole(chunk) @@ -2034,10 +2199,6 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct return utils.map(chunk, peephole) end end - local function ast_source(ast) - local m = getmetatable(ast) - return ((m and m.line and m) or (("table" == type(ast)) and ast) or {}) - end local function flatten_chunk_correlated(main_chunk, options) local function flatten(chunk, out, last_line, file) local last_line0 = last_line @@ -2046,11 +2207,13 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct else for _, subchunk in ipairs(chunk) do if (subchunk.leaf or (#subchunk > 0)) then - local source = ast_source(subchunk.ast) + local source = utils["ast-source"](subchunk.ast) if (file == source.filename) then last_line0 = math.max(last_line0, (source.line or 0)) + else end last_line0 = flatten(subchunk, out, last_line0, file) + else end end end @@ -2061,6 +2224,7 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct for i = 1, last do if (out[i] == nil) then out[i] = "" + else end end return table.concat(out, "\n") @@ -2071,22 +2235,23 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct local info = chunk.ast if sm then table.insert(sm, {(info and info.filename), (info and info.line)}) + else end return code else local tab0 do - local _208_ = tab - if (_208_ == true) then + local _236_ = tab + if (_236_ == true) then tab0 = " " - elseif (_208_ == false) then + elseif (_236_ == false) then tab0 = "" - elseif (_208_ == tab) then + elseif (_236_ == tab) then tab0 = tab - elseif (_208_ == nil) then + elseif (_236_ == nil) then tab0 = "" else - tab0 = nil + tab0 = nil end end local function parter(c) @@ -2097,12 +2262,14 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct else return sub end + else + return nil end end return table.concat(utils.map(chunk, parter), "\n") end end - local fennel_sourcemap = {} + local sourcemap = {} local function make_short_src(source) local source0 = source:gsub("\n", " ") if (#source0 <= 49) then @@ -2125,27 +2292,31 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct else sm.key = ret end - fennel_sourcemap[sm.key] = sm + sourcemap[sm.key] = sm + else end return ret, sm end end local function make_metadata() - local function _217_(self, tgt, key) + local function _245_(self, tgt, key) if self[tgt] then return self[tgt][key] + else + return nil end end - local function _219_(self, tgt, key, value) + local function _247_(self, tgt, key, value) self[tgt] = (self[tgt] or {}) do end (self[tgt])[key] = value return tgt end - local function _220_(self, tgt, ...) + local function _248_(self, tgt, ...) local kv_len = select("#", ...) local kvs = {...} if ((kv_len % 2) ~= 0) then error("metadata:setall() expected even number of k/v pairs") + else end self[tgt] = (self[tgt] or {}) for i = 1, kv_len, 2 do @@ -2153,7 +2324,7 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct end return tgt end - return setmetatable({}, {__index = {get = _217_, set = _219_, setall = _220_}, __mode = "k"}) + return setmetatable({}, {__index = {get = _245_, set = _247_, setall = _248_}, __mode = "k"}) end local function exprs1(exprs) return table.concat(utils.map(exprs, tostring), ", ") @@ -2173,6 +2344,7 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct disambiguated = code end emit(chunk, disambiguated, ast) + else end end return nil @@ -2192,28 +2364,32 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct exprs[i] = utils.expr("nil", "literal") end end + else end + else end if opts.tail then emit(parent, string.format("return %s", exprs1(exprs)), ast) + else end if opts.target then local result = exprs1(exprs) - local function _228_() + local function _256_() if (result == "") then return "nil" else return result end end - emit(parent, string.format("%s = %s", opts.target, _228_()), ast) + emit(parent, string.format("%s = %s", opts.target, _256_()), ast) + else end if (opts.tail or opts.target) then return {returned = true} else - local _230_ = exprs - _230_["returned"] = true - return _230_ + local _258_ = exprs + _258_["returned"] = true + return _258_ end end local function find_macro(ast, scope, multi_sym_parts) @@ -2233,36 +2409,60 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct return macro_2a end end - local function macroexpand_2a(ast, scope, once) - local _234_ - if utils["list?"](ast) then - _234_ = find_macro(ast, scope, utils["multi-sym?"](ast[1])) + local function propagate_trace_info(_262_, _index, node) + local _arg_263_ = _262_ + local filename = _arg_263_["filename"] + local line = _arg_263_["line"] + local bytestart = _arg_263_["bytestart"] + local byteend = _arg_263_["byteend"] + if (("table" == type(node)) and (filename ~= node.filename)) then + local src = utils["ast-source"](node) + src.filename, src.line = filename, line + src.bytestart, src.byteend = bytestart, byteend else - _234_ = nil end - if (_234_ == false) then + return ("table" == type(node)) + end + local function macroexpand_2a(ast, scope, _3fonce) + local _265_ + if utils["list?"](ast) then + _265_ = find_macro(ast, scope, utils["multi-sym?"](ast[1])) + else + _265_ = nil + end + if (_265_ == false) then return ast - elseif (nil ~= _234_) then - local macro_2a = _234_ + elseif (nil ~= _265_) then + local macro_2a = _265_ local old_scope = scopes.macro local _ scopes.macro = scope _ = nil local ok, transformed = nil, nil - local function _236_() + local function _267_() return macro_2a(unpack(ast, 2)) end - ok, transformed = xpcall(_236_, debug.traceback) + ok, transformed = xpcall(_267_, debug.traceback) + local function _269_() + local _268_ = ast + local function _270_(...) + return propagate_trace_info(_268_, ...) + end + return _270_ + end + utils["walk-tree"](transformed, _269_()) scopes.macro = old_scope assert_compile(ok, transformed, ast) - if (once or not transformed) then + if (_3fonce or not transformed) then return transformed else return macroexpand_2a(transformed, scope) end - else - local _ = _234_ + elseif true then + local _ = _265_ return ast + else + return nil end end local function compile_special(ast, scope, parent, opts, special) @@ -2293,13 +2493,13 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct assert_compile((("string" == type(ast[1])) or (fcallee.type ~= "literal")), ("cannot call literal value " .. tostring(ast[1])), ast) for i = 2, len do local subexprs - local _242_ + local _276_ if (i ~= len) then - _242_ = 1 + _276_ = 1 else - _242_ = nil + _276_ = nil end - subexprs = compile1(ast[i], scope, parent, {nval = _242_}) + subexprs = compile1(ast[i], scope, parent, {nval = _276_}) table.insert(fargs, (subexprs[1] or utils.expr("nil", "literal"))) if (i == len) then for j = 2, #subexprs do @@ -2352,91 +2552,99 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct return handle_compile_opts({e}, parent, opts, ast) end local function serialize_number(n) - local _248_ = string.gsub(tostring(n), ",", ".") - return _248_ + local _282_ = string.gsub(tostring(n), ",", ".") + return _282_ end local function compile_scalar(ast, _scope, parent, opts) local serialize do - local _249_ = type(ast) - if (_249_ == "nil") then + local _283_ = type(ast) + if (_283_ == "nil") then serialize = tostring - elseif (_249_ == "boolean") then + elseif (_283_ == "boolean") then serialize = tostring - elseif (_249_ == "string") then + elseif (_283_ == "string") then serialize = serialize_string - elseif (_249_ == "number") then + elseif (_283_ == "number") then serialize = serialize_number else - serialize = nil + serialize = nil end end return handle_compile_opts({utils.expr(serialize(ast), "literal")}, parent, opts) end local function compile_table(ast, scope, parent, opts, compile1) local buffer = {} - for i = 1, #ast do - local nval = ((i ~= #ast) and 1) - table.insert(buffer, exprs1(compile1(ast[i], scope, parent, {nval = nval}))) - end local function write_other_values(k) if ((type(k) ~= "number") or (math.floor(k) ~= k) or (k < 1) or (k > #ast)) then if ((type(k) == "string") and utils["valid-lua-identifier?"](k)) then return {k, k} else - local _let_251_ = compile1(k, scope, parent, {nval = 1}) - local compiled = _let_251_[1] + local _let_285_ = compile1(k, scope, parent, {nval = 1}) + local compiled = _let_285_[1] local kstr = ("[" .. tostring(compiled) .. "]") return {kstr, k} end + else + return nil end end do local keys do - local tbl_13_auto = {} + local tbl_14_auto = {} + local i_15_auto = #tbl_14_auto for k, v in utils.stablepairs(ast) do - tbl_13_auto[(#tbl_13_auto + 1)] = write_other_values(k, v) + 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 end - keys = tbl_13_auto + keys = tbl_14_auto end - local function _256_(_254_) - local _arg_255_ = _254_ - local k1 = _arg_255_[1] - local k2 = _arg_255_[2] - local _let_257_ = compile1(ast[k2], scope, parent, {nval = 1}) - local v = _let_257_[1] + local function _291_(_289_) + local _arg_290_ = _289_ + local k1 = _arg_290_[1] + local k2 = _arg_290_[2] + local _let_292_ = compile1(ast[k2], scope, parent, {nval = 1}) + local v = _let_292_[1] return string.format("%s = %s", k1, tostring(v)) end - utils.map(keys, _256_, buffer) + utils.map(keys, _291_, buffer) + end + for i = 1, #ast do + local nval = ((i ~= #ast) and 1) + table.insert(buffer, exprs1(compile1(ast[i], scope, parent, {nval = nval}))) end return handle_compile_opts({utils.expr(("{" .. table.concat(buffer, ", ") .. "}"), "expression")}, parent, opts, ast) end - local function compile1(ast, scope, parent, opts) - local opts0 = (opts or {}) + local function compile1(ast, scope, parent, _3fopts) + local opts = (_3fopts or {}) local ast0 = macroexpand_2a(ast, scope) if utils["list?"](ast0) then - return compile_call(ast0, scope, parent, opts0, compile1) + return compile_call(ast0, scope, parent, opts, compile1) elseif utils["varg?"](ast0) then - return compile_varg(ast0, scope, parent, opts0) + return compile_varg(ast0, scope, parent, opts) elseif utils["sym?"](ast0) then - return compile_sym(ast0, scope, parent, opts0) + return compile_sym(ast0, scope, parent, opts) elseif (type(ast0) == "table") then - return compile_table(ast0, scope, parent, opts0, compile1) + 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 - return compile_scalar(ast0, scope, parent, opts0) + return compile_scalar(ast0, scope, parent, opts) else return assert_compile(false, ("could not compile value of type " .. type(ast0)), ast0) end end local function destructure(to, from, ast, scope, parent, opts) local opts0 = (opts or {}) - local _let_259_ = opts0 - local isvar = _let_259_["isvar"] - local declaration = _let_259_["declaration"] - local forceglobal = _let_259_["forceglobal"] - local forceset = _let_259_["forceset"] - local symtype = _let_259_["symtype"] + local _let_294_ = opts0 + local isvar = _let_294_["isvar"] + local declaration = _let_294_["declaration"] + local forceglobal = _let_294_["forceglobal"] + local forceset = _let_294_["forceset"] + local symtype = _let_294_["symtype"] local symtype0 = ("_" .. (symtype or "dst")) local setter if declaration then @@ -2458,6 +2666,7 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct 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 if forceglobal then assert_compile(not scope.symmeta[scope.unmanglings[raw]], ("global " .. raw .. " conflicts with local"), symbol) @@ -2465,21 +2674,23 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct do end (scope.unmanglings)[global_mangling(raw)] = raw if allowed_globals then table.insert(allowed_globals, raw) + else end + else end return symbol_to_expression(symbol, scope)[1] end end local function compile_top_target(lvalues) local inits - local function _265_(_241) + local function _300_(_241) if scope.manglings[_241] then return _241 else return "nil" end end - inits = utils.map(lvalues, _265_) + inits = utils.map(lvalues, _300_) local init = table.concat(inits, ", ") local lvalue = table.concat(lvalues, ", ") local plen, plast = #parent, parent[#parent] @@ -2488,6 +2699,7 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct for pi = plen, #parent do if (parent[pi] == plast) then plen = pi + else end end if ((#parent == (plen + 1)) and parent[#parent].leaf) then @@ -2497,6 +2709,7 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct else table.insert(parent, (plen + 1), {ast = ast, leaf = ("local " .. lvalue .. " = " .. init)}) end + else end return ret end @@ -2511,33 +2724,35 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct if declaration then scope.symmeta[tostring(left)] = {var = isvar} return nil + else + return nil end end local function destructure_table(left, rightexprs, top_3f, destructure1) local s = gensym(scope, symtype0) local right do - local _272_ + local _307_ if top_3f then - _272_ = exprs1(compile1(from, scope, parent)) + _307_ = exprs1(compile1(from, scope, parent)) else - _272_ = exprs1(rightexprs) + _307_ = exprs1(rightexprs) end - if (_272_ == "") then + if (_307_ == "") then right = "nil" - elseif (nil ~= _272_) then - local right0 = _272_ + elseif (nil ~= _307_) then + local right0 = _307_ right = right0 else - right = nil + right = nil end end emit(parent, string.format("local %s = %s", s, right), left) for k, v in utils.stablepairs(left) do if not (("number" == type(k)) and tostring(left[(k - 1)]):find("^&")) then if (utils["sym?"](v) and (tostring(v) == "&")) then - local unpack_str = "{(table.unpack or unpack)(%s, %s)}" - local formatted = string.format(unpack_str, s, k) + local unpack_str = "(function (t, k)\n local mt = getmetatable(t)\n if \"table\" == type(mt) and mt.__fennelrest then\n return mt.__fennelrest(t, k)\n else\n return {(table.unpack or unpack)(t, k)}\n end\n end)(%s, %s)" + local formatted = string.format(string.gsub(unpack_str, "\n%s*", " "), s, k) local subexpr = utils.expr(formatted, "expression") assert_compile((utils["sequence?"](left) and (nil == left[(k + 2)])), "expected rest argument before last parameter", left) destructure1(left[(k + 1)], {subexpr}, left) @@ -2557,6 +2772,7 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct local subexpr = utils.expr(string.format("%s[%s]", s, key), "expression") destructure1(v, {subexpr}, left) end + else end end return nil @@ -2578,8 +2794,10 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct for _, sym in ipairs(left) do if utils["sym?"](sym) then scope.symmeta[tostring(sym)] = {var = isvar} + else end end + else end for _, pair in utils.stablepairs(tables) do destructure1(pair[1], {pair[2]}, left) @@ -2598,6 +2816,8 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct end if top_3f then return {returned = true} + else + return nil end end local ret = destructure1(to, nil, ast, true) @@ -2607,6 +2827,7 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct end local function require_include(ast, scope, parent, opts) opts.fallback = function(e) + utils.warn(("include module not found, falling back to require: %s"):format(tostring(e))) return utils.expr(string.format("require(%s)", tostring(e)), "statement") end return scopes.global.specials.include(ast, scope, parent, opts) @@ -2621,9 +2842,11 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct allowed_globals = opts.allowedGlobals if (opts.indent == nil) then opts.indent = " " + else end if opts.requireAsInclude then scope.specials.require = require_include + else end utils.root.chunk, utils.root.scope, utils.root.options = chunk, scope, opts for _, val in parser.parser(strm, opts.filename, opts) do @@ -2632,6 +2855,10 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct for i = 1, #vals do local exprs = compile1(vals[i], scope, chunk, {nval = (((i < #vals) and 0) or nil), tail = (i == #vals)}) keep_side_effects(exprs, chunk, nil, vals[i]) + if (i == #vals) then + utils.hook("chunk", vals[i], scope) + else + end end allowed_globals = old_globals utils.root.reset() @@ -2649,13 +2876,16 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct allowed_globals = opts0.allowedGlobals if (opts0.indent == nil) then opts0.indent = " " + else end if opts0.requireAsInclude then scope.specials.require = require_include + else end utils.root.chunk, utils.root.scope, utils.root.options = chunk, scope, opts0 local exprs = compile1(ast, scope, chunk, {tail = true}) keep_side_effects(exprs, chunk, nil, ast) + utils.hook("chunk", ast, scope) allowed_globals = old_globals utils.root.reset() return flatten(chunk, opts0) @@ -2666,24 +2896,25 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct elseif (info.what == "C") then return " [C]: in ?" else - local remap = fennel_sourcemap[info.source] + local remap = sourcemap[info.source] if (remap and remap[info.currentline]) then if remap[info.currentline][1] then - info.short_src = fennel_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) + else end if (info.what == "Lua") then - local function _289_() + local function _325_() if info.name then return ("'" .. info.name .. "'") else return "?" end end - return string.format(" %s:%d: in function %s", info.short_src, info.currentline, _289_()) + return string.format(" %s:%d: in function %s", info.short_src, info.currentline, _325_()) elseif (info.short_src == "(tail call)") then return " (tail call)" else @@ -2707,12 +2938,13 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct local done_3f, level = false, (start or 2) while not done_3f do do - local _293_ = debug.getinfo(level, "Sln") - if (_293_ == nil) then + local _329_ = debug.getinfo(level, "Sln") + if (_329_ == nil) then done_3f = true - elseif (nil ~= _293_) then - local info = _293_ + elseif (nil ~= _329_) then + local info = _329_ table.insert(lines, traceback_frame(info)) + else end end level = (level + 1) @@ -2721,14 +2953,14 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct end end local function entry_transform(fk, fv) - local function _296_(k, v) + local function _332_(k, v) if (type(k) == "number") then return k, fv(v) else return fk(k), fv(v) end end - return _296_ + return _332_ end local function mixed_concat(t, joiner) local seen = {} @@ -2742,6 +2974,7 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct if not seen[k] then ret = (ret .. s .. "[" .. k .. "]" .. "=" .. v) s = joiner + else end end return ret @@ -2773,10 +3006,10 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct return res[1] elseif utils["list?"](form) then local mapped - local function _301_() + local function _337_() return nil end - mapped = utils.kvmap(form, entry_transform(_301_, q)) + mapped = utils.kvmap(form, entry_transform(_337_, q)) local filename if form.filename then filename = string.format("%q", form.filename) @@ -2794,13 +3027,13 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct else filename = "nil" end - local _304_ + local _340_ if source then - _304_ = source.line + _340_ = source.line else - _304_ = "nil" + _340_ = "nil" end - return string.format("setmetatable({%s}, {filename=%s, line=%s, sequence=%s})", mixed_concat(mapped, ", "), filename, _304_, "(getmetatable(sequence()))['sequence']") + return string.format("setmetatable({%s}, {filename=%s, line=%s, sequence=%s})", mixed_concat(mapped, ", "), filename, _340_, "(getmetatable(sequence()))['sequence']") elseif (type(form) == "table") then local mapped = utils.kvmap(form, entry_transform(q, q)) local source = getmetatable(form) @@ -2810,28 +3043,25 @@ package.preload["fennel.compiler"] = package.preload["fennel.compiler"] or funct else filename = "nil" end - local function _307_() + local function _343_() if source then return source.line else return "nil" end end - return string.format("setmetatable({%s}, {filename=%s, line=%s})", mixed_concat(mapped, ", "), filename, _307_()) + return string.format("setmetatable({%s}, {filename=%s, line=%s})", mixed_concat(mapped, ", "), filename, _343_()) elseif (type(form) == "string") then return serialize_string(form) else return tostring(form) end end - return {compile = compile, compile1 = compile1, ["compile-stream"] = compile_stream, ["compile-string"] = compile_string, 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()} + return {compile = compile, compile1 = compile1, ["compile-stream"] = compile_stream, ["compile-string"] = compile_string, 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.friend"] = package.preload["fennel.friend"] or function(...) - local function ast_source(ast) - local m = getmetatable(ast) - return ((m and m.line and m) or (("table" == type(ast)) and ast) or {}) - end - 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 global 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"}, ["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"}, ["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 (.*)"] = {"fixing a typo so %s is used", "renaming the local to _%s"}, ["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"}, ["illegal 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 at runtime"] = {"renaming the macro so as not to conflict with locals"}, ["expected even number of pattern/body pairs"] = {"checking that every pattern has a body to go with it", "adding _ before the final body"}, ["unexpected arguments"] = {"removing an argument", "checking for typos"}, ["unexpected iterator clause"] = {"removing an argument", "checking for typos"}} + local utils = require("fennel.utils") + 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 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"}, ["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"}, ["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"}, ["illegal 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 at runtime"] = {"renaming the macro so as not to conflict with locals"}, ["expected even number of pattern/body pairs"] = {"checking that every pattern has a body to go with it", "adding _ before the final body"}, ["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 @@ -2847,6 +3077,7 @@ package.preload["fennel.friend"] = package.preload["fennel.friend"] or function( else suggestion = sug(matches) end + else end end return suggestion @@ -2871,6 +3102,8 @@ package.preload["fennel.friend"] = package.preload["fennel.friend"] or function( return this_line, (bytes - #this_line - 1) elseif this_line then return read_line_from_string(matcher, target_line, (current_line + 1), bytes) + else + return nil end end local function read_line(filename, line, source) @@ -2880,38 +3113,43 @@ package.preload["fennel.friend"] = package.preload["fennel.friend"] or function( return read_line_from_file(filename, line) end end - local function friendly_msg(msg, _116_, source) - local _arg_117_ = _116_ - local filename = _arg_117_["filename"] - local line = _arg_117_["line"] - local bytestart = _arg_117_["bytestart"] - local byteend = _arg_117_["byteend"] + local function friendly_msg(msg, _142_, source) + local _arg_143_ = _142_ + local filename = _arg_143_["filename"] + local line = _arg_143_["line"] + local bytestart = _arg_143_["bytestart"] + local byteend = _arg_143_["byteend"] local ok, codeline, bol = pcall(read_line, filename, line, source) local suggestions0 = suggest(msg) local out = {msg, ""} if (ok and codeline) then table.insert(out, codeline) + else end if (ok and codeline and bytestart and byteend) then table.insert(out, (string.rep(" ", (bytestart - bol - 1)) .. "^" .. string.rep("^", math.min((byteend - bytestart), ((bol + #codeline) - bytestart))))) + else end if (ok and codeline and bytestart and not byteend) then table.insert(out, (string.rep("-", (bytestart - bol - 1)) .. "^")) table.insert(out, "") + else end if suggestions0 then for _, suggestion in ipairs(suggestions0) do table.insert(out, ("* Try %s."):format(suggestion)) end + else end return table.concat(out, "\n") end local function assert_compile(condition, msg, ast, source) if not condition then - local _let_122_ = ast_source(ast) - local filename = _let_122_["filename"] - local line = _let_122_["line"] - error(friendly_msg(("Compile error in %s:%s\n %s"):format((filename or "unknown"), (line or "?"), msg), ast_source(ast), source), 0) + local _let_148_ = utils["ast-source"](ast) + local filename = _let_148_["filename"] + local line = _let_148_["line"] + error(friendly_msg(("Compile error in %s:%s\n %s"):format((filename or "unknown"), (line or "?"), msg), utils["ast-source"](ast), source), 0) + else end return condition end @@ -2926,46 +3164,50 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( local unpack = (table.unpack or _G.unpack) local function granulate(getchunk) local c, index, done_3f = "", 1, false - local function _124_(parser_state) + local function _150_(parser_state) if not done_3f then if (index <= #c) then local b = c:byte(index) index = (index + 1) return b else - local _125_ = getchunk(parser_state) - local function _126_() - local char = _125_ + local _151_ = getchunk(parser_state) + local function _152_() + local char = _151_ return (char ~= "") end - if ((nil ~= _125_) and _126_()) then - local char = _125_ + if ((nil ~= _151_) and _152_()) then + local char = _151_ c = char index = 2 return c:byte() - else - local _ = _125_ + elseif true then + local _ = _151_ done_3f = true return nil + else + return nil end end + else + return nil end end - local function _130_() + local function _156_() c = "" return nil end - return _124_, _130_ + return _150_, _156_ end local function string_stream(str) local str0 = str:gsub("^#!", ";;") local index = 1 - local function _131_() + local function _157_() local r = str0:byte(index) index = (index + 1) return r end - return _131_ + return _157_ end local delims = {[40] = 41, [41] = true, [91] = 93, [93] = true, [123] = 125, [125] = true} local function whitespace_3f(b) @@ -2981,7 +3223,7 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( return ((b0 > 32) 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", [39] = "quote", [44] = "unquote", [96] = "quote"} - local function parser(getbyte, filename, options) + local function parser(getbyte, _3ffilename, _3foptions) local stack = {} local line = 1 local byteindex = 0 @@ -2989,6 +3231,7 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( local function ungetb(ub) if (ub == 10) then line = (line - 1) + else end byteindex = (byteindex - 1) lastb = ub @@ -3004,56 +3247,63 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( byteindex = (byteindex + 1) if (r == 10) then line = (line + 1) + else end return r end - assert(((nil == filename) or ("string" == type(filename))), "expected filename as second argument to parser") + assert(((nil == _3ffilename) or ("string" == type(_3ffilename))), "expected filename as second argument to parser") local function parse_error(msg, byteindex_override) - local _let_136_ = (options or utils.root.options or {}) - local source = _let_136_["source"] - local unfriendly = _let_136_["unfriendly"] - utils.root.reset() - if (unfriendly or not friend or not _G.io or not _G.io.read) then - return error(string.format("%s:%s: Parse error: %s", (filename or "unknown"), (line or "?"), msg), 0) + local _let_162_ = (_3foptions or utils.root.options or {}) + local source = _let_162_["source"] + local unfriendly = _let_162_["unfriendly"] + if (nil == utils.hook("parse-error", msg, (_3ffilename or "unknown"), (line or "?"), (byteindex_override or byteindex), source, utils.root.reset)) then + utils.root.reset() + if (unfriendly or not friend or not _G.io or not _G.io.read) then + return error(string.format("%s:%s: Parse error: %s", (_3ffilename or "unknown"), (line or "?"), msg), 0) + else + return friend["parse-error"](msg, (_3ffilename or "unknown"), (line or "?"), (byteindex_override or byteindex), source) + end else - return friend["parse-error"](msg, (filename or "unknown"), (line or "?"), (byteindex_override or byteindex), source) + return nil end end local function parse_stream() local whitespace_since_dispatch, done_3f, retval = true local function dispatch(v) - local _138_ = stack[#stack] - if (_138_ == nil) then + local _165_ = stack[#stack] + if (_165_ == nil) then retval, done_3f, whitespace_since_dispatch = v, true, false return nil - elseif ((_G.type(_138_) == "table") and (nil ~= (_138_).prefix)) then - local prefix = (_138_).prefix + elseif ((_G.type(_165_) == "table") and (nil ~= (_165_).prefix)) then + local prefix = (_165_).prefix local source do - local _139_ = table.remove(stack) - do end (_139_)["byteend"] = byteindex - source = _139_ + local _166_ = table.remove(stack) + do end (_166_)["byteend"] = byteindex + source = _166_ end local list = utils.list(utils.sym(prefix, source), v) for k, v0 in pairs(source) do list[k] = v0 end return dispatch(list) - elseif (nil ~= _138_) then - local top = _138_ + elseif (nil ~= _165_) then + local top = _165_ whitespace_since_dispatch = false return table.insert(top, v) + else + return nil end end local function badend() local accum = utils.map(stack, "closer") - local _141_ + local _168_ if (#stack == 1) then - _141_ = "" + _168_ = "" else - _141_ = "s" + _168_ = "s" end - return parse_error(string.format("expected closing delimiter%s %s", _141_, string.char(unpack(accum)))) + return parse_error(string.format("expected closing delimiter%s %s", _168_, string.char(unpack(accum)))) end local function skip_whitespace(b) if (b and whitespace_3f(b)) then @@ -3067,14 +3317,14 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( end local function parse_comment(b, contents) if (b and (10 ~= b)) then - local function _145_() - local _144_ = contents - table.insert(_144_, string.char(b)) - return _144_ + local function _172_() + local _171_ = contents + table.insert(_171_, string.char(b)) + return _171_ end - return parse_comment(getb(), _145_()) - elseif (options and options.comments) then - return dispatch(utils.comment(table.concat(contents), {line = (line - 1), filename = filename})) + return parse_comment(getb(), _172_()) + elseif (_3foptions and _3foptions.comments) then + return dispatch(utils.comment(table.concat(contents), {line = (line - 1), filename = _3ffilename})) else return b end @@ -3082,8 +3332,9 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( local function open_table(b) if not whitespace_since_dispatch then parse_error(("expected whitespace before opening delimiter " .. string.char(b))) + else end - return table.insert(stack, {bytestart = byteindex, closer = delims[b], filename = filename, line = line}) + return table.insert(stack, {bytestart = byteindex, closer = delims[b], filename = _3ffilename, line = line}) end local function close_list(list) return dispatch(setmetatable(list, getmetatable(utils.list()))) @@ -3096,14 +3347,16 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( return dispatch(val) end local function add_comment_at(comments, index, node) - local _148_ = comments[index] - if (nil ~= _148_) then - local existing = _148_ + local _175_ = comments[index] + if (nil ~= _175_) then + local existing = _175_ return table.insert(existing, node) - else - local _ = _148_ + elseif true then + local _ = _175_ comments[index] = {node} return nil + else + return nil end end local function next_noncomment(tbl, i) @@ -3131,6 +3384,7 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( for i = #tbl, 1, -1 do if utils["comment?"](tbl[i]) then table.remove(tbl, i) + else end end return comments @@ -3142,11 +3396,13 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( if ((#tbl % 2) ~= 0) then byteindex = (byteindex - 1) parse_error("expected even number of values in table literal") + else 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 tbl[i] = tostring(tbl[(i + 1)]) + else end val[tbl[i]] = tbl[(i + 1)] table.insert(keys, tbl[i]) @@ -3159,9 +3415,11 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( local top = table.remove(stack) if (top == nil) then parse_error(("unexpected closing delimiter " .. string.char(b))) + else end if (top.closer and (top.closer ~= b)) then parse_error(("mismatched closing delimiter " .. string.char(b) .. ", expected " .. string.char(top.closer))) + else end top.byteend = byteindex if (b == 41) then @@ -3176,14 +3434,19 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( table.insert(chars, b) local state0 do - local _158_ = {state, b} - if ((_G.type(_158_) == "table") and ((_158_)[1] == "base") and ((_158_)[2] == 92)) then + local _185_ = {state, b} + if ((_G.type(_185_) == "table") and ((_185_)[1] == "base") and ((_185_)[2] == 92)) then state0 = "backslash" - elseif ((_G.type(_158_) == "table") and ((_158_)[1] == "base") and ((_158_)[2] == 34)) then + elseif ((_G.type(_185_) == "table") and ((_185_)[1] == "base") and ((_185_)[2] == 34)) then state0 = "done" - else - local _ = _158_ + elseif ((_G.type(_185_) == "table") and ((_185_)[1] == "backslash") and ((_185_)[2] == 10)) then + table.remove(chars, (#chars - 1)) state0 = "base" + elseif true then + local _ = _185_ + state0 = "base" + else + state0 = nil end end if (b and (state0 ~= "done")) then @@ -3200,27 +3463,32 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( local chars = {34} if not parse_string_loop(chars, getb(), "base") then badend() + else end table.remove(stack) local raw = string.char(unpack(chars)) local formatted = raw:gsub("[\7-\13]", escape_char) - local _162_ = (rawget(_G, "loadstring") or load)(("return " .. formatted)) - if (nil ~= _162_) then - local load_fn = _162_ + local _189_ = (rawget(_G, "loadstring") or load)(("return " .. formatted)) + if (nil ~= _189_) then + local load_fn = _189_ return dispatch(load_fn()) - elseif (_162_ == nil) then + elseif (_189_ == nil) then return parse_error(("Invalid string: " .. raw)) + else + return nil end end local function parse_prefix(b) - table.insert(stack, {prefix = prefixes[b], filename = filename, line = line, bytestart = byteindex}) + table.insert(stack, {prefix = prefixes[b], filename = _3ffilename, line = line, bytestart = byteindex}) local nextb = getb() if (whitespace_3f(nextb) or (true == delims[nextb])) then if (b ~= 35) then parse_error("invalid whitespace after quoting prefix") + else end table.remove(stack) dispatch(utils.sym("#")) + else end return ungetb(nextb) end @@ -3231,6 +3499,7 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( else if b then ungetb(b) + else end return chars end @@ -3241,14 +3510,16 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( dispatch((tonumber(number_with_stripped_underscores) or parse_error(("could not read number \"" .. rawstr .. "\"")))) return true else - local _168_ = tonumber(number_with_stripped_underscores) - if (nil ~= _168_) then - local x = _168_ + local _195_ = tonumber(number_with_stripped_underscores) + if (nil ~= _195_) then + local x = _195_ dispatch(x) return true - else - local _ = _168_ + elseif true then + local _ = _195_ return false + else + return nil end end end @@ -3279,7 +3550,9 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( elseif rawstr:match("^:.+$") then return dispatch(rawstr:sub(2)) elseif not parse_number(rawstr) then - return dispatch(utils.sym(check_malformed_sym(rawstr), {byteend = byteindex, bytestart = bytestart, filename = filename, line = line})) + return dispatch(utils.sym(check_malformed_sym(rawstr), {byteend = byteindex, bytestart = bytestart, filename = _3ffilename, line = line})) + else + return nil end end local function parse_loop(b) @@ -3298,6 +3571,7 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( parse_sym(b) elseif not utils.hook("illegal-char", b, getb, ungetb, dispatch) then parse_error(("illegal character: " .. string.char(b))) + else end if not b then return nil @@ -3309,22 +3583,60 @@ package.preload["fennel.parser"] = package.preload["fennel.parser"] or function( end return parse_loop(skip_whitespace(getb())) end - local function _175_() - stack, line, byteindex = {}, 1, 0 + local function _202_() + stack, line, byteindex, lastb = {}, 1, 0, nil return nil end - return parse_stream, _175_ + return parse_stream, _202_ end return {granulate = granulate, parser = parser, ["string-stream"] = string_stream, ["sym-char?"] = sym_char_3f} end 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 function sort_keys(_1_, _3_) - local _arg_2_ = _1_ - local a = _arg_2_[1] - local _arg_4_ = _3_ - local b = _arg_4_[1] + 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 + return p(t) + elseif true then + local _ = _1_ + return lua_pairs(t) + else + return nil + end + end + local function ipairs(t) + local _3_ = getmetatable(t) + if ((_G.type(_3_) == "table") and (nil ~= (_3_).__ipairs)) then + local i = (_3_).__ipairs + return i(t) + elseif true then + local _ = _3_ + return lua_ipairs(t) + else + return nil + end + end + local function length_2a(t) + local _5_ = getmetatable(t) + if ((_G.type(_5_) == "table") and (nil ~= (_5_).__len)) then + local l = (_5_).__len + return l(t) + elseif true then + local _ = _5_ + return #t + else + 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 ta = type(a) local tb = type(b) if ((ta == tb) and ((ta == "string") or (ta == "number"))) then @@ -3345,25 +3657,27 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) end local function max_index_gap(kv) local gap = 0 - if (#kv > 0) then + if (length_2a(kv) > 0) then local i = 0 - for _, _7_ in ipairs(kv) do - local _each_8_ = _7_ - local k = _each_8_[1] + for _, _13_ in ipairs(kv) do + local _each_14_ = _13_ + local k = _each_14_[1] if ((k - i) > gap) then gap = (k - i) + else end i = k end + else end return gap end local function fill_gaps(kv) local missing_indexes = {} local i = 0 - for _, _11_ in ipairs(kv) do - local _each_12_ = _11_ - local j = _each_12_[1] + for _, _17_ in ipairs(kv) do + local _each_18_ = _17_ + local j = _each_18_[1] i = (i + 1) while (i < j) do table.insert(missing_indexes, i) @@ -3380,31 +3694,32 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) local kv = {} local insert = table.insert for k, v in pairs(t) do - if (type(k) ~= "number") then + if ((type(k) ~= "number") or (k < 1)) then assoc_3f = true + else end insert(kv, {k, v}) end table.sort(kv, sort_keys) if not assoc_3f then - local gap = max_index_gap(kv) if (max_index_gap(kv) > options["max-sparse-gap"]) then assoc_3f = true else fill_gaps(kv) end + else end - if (#kv == 0) then + if (length_2a(kv) == 0) then return kv, "empty" else - local function _16_() + local function _22_() if assoc_3f then return "table" else return "seq" end end - return kv, _16_() + return kv, _22_() end end local function count_table_appearances(t, appearances) @@ -3418,6 +3733,7 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) else appearances[t] = ((appearances[t] or 0) + 1) end + else end return appearances end @@ -3427,27 +3743,32 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) if not (seen0)[t] then seen0[t] = id seen0.len = id + else end return seen0 end local function detect_cycle(t, seen, _3fk) if ("table" == type(t)) then seen[t] = true - local _21_, _22_ = next(t, _3fk) - if ((nil ~= _21_) and (nil ~= _22_)) then - local k = _21_ - local v = _22_ + 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)) + else + return nil end + else + return nil 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))) end - local function table_indent(t, indent, id) + local function table_indent(indent, id) local opener_length if id then - opener_length = (#tostring(id) + 2) + opener_length = (length_2a(tostring(id)) + 2) else opener_length = 1 end @@ -3457,13 +3778,14 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) local function concat_table_lines(elements, options, multiline_3f, indent, table_type, prefix) local indent_str = ("\n" .. string.rep(" ", indent)) local open - local _26_ - if ("seq" == table_type) then - _26_ = "[" - else - _26_ = "{" + local function _32_() + if ("seq" == table_type) then + return "[" + else + return "{" + end end - open = ((prefix or "") .. _26_) + open = ((prefix or "") .. _32_()) local close if ("seq" == table_type) then close = "]" @@ -3471,13 +3793,20 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) close = "}" end local oneline = (open .. table.concat(elements, " ") .. close) - if (not options["one-line?"] and (multiline_3f or ((indent + #oneline) > options["line-length"]))) then + if (not options["one-line?"] and (multiline_3f or ((indent + length_2a(oneline)) > options["line-length"]))) then return (open .. table.concat(elements, indent_str) .. close) else return oneline end end - local function pp_associative(t, kv, options, indent, key_3f) + local function utf8_len(x) + local n = 0 + for _ in string.gmatch(x, "[%z\1-\127\192-\247]") do + n = (n + 1) + end + return n + end + local function pp_associative(t, kv, options, indent) local multiline_3f = false local id = options.seen[t] if (options.level >= options.depth) then @@ -3487,20 +3816,16 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) else local visible_cycle_3f0 = visible_cycle_3f(t, options) local id0 = (visible_cycle_3f0 and options.seen[t]) - local indent0 = table_indent(t, indent, id0) + local indent0 = table_indent(indent, id0) local slength - local function _31_() - local _30_ = rawget(_G, "utf8") - if _30_ then - return (_30_).len - else - return _30_ + if options["utf8?"] then + slength = utf8_len + else + local function _35_(_241) + return #_241 end + slength = _35_ end - local function _33_(_241) - return #_241 - end - slength = ((options["utf8?"] and _31_()) or _33_) local prefix if visible_cycle_3f0 then prefix = ("@" .. id0) @@ -3509,21 +3834,26 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) end local items do - local tbl_13_auto = {} - for _, _35_ in pairs(kv) do - local _each_36_ = _35_ - local k = _each_36_[1] - local v = _each_36_[2] - local _37_ + local tbl_14_auto = {} + local i_15_auto = #tbl_14_auto + for _, _38_ in pairs(kv) do + local _each_39_ = _38_ + local k = _each_39_[1] + local v = _each_39_[2] + local val_16_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")) - _37_ = (k0 .. " " .. v0) + val_16_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 + else end - tbl_13_auto[(#tbl_13_auto + 1)] = _37_ end - items = tbl_13_auto + items = tbl_14_auto end return concat_table_lines(items, options, multiline_3f, indent0, "table", prefix) end @@ -3538,7 +3868,7 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) else local visible_cycle_3f0 = visible_cycle_3f(t, options) local id0 = (visible_cycle_3f0 and options.seen[t]) - local indent0 = table_indent(t, indent, id0) + local indent0 = table_indent(indent, id0) local prefix if visible_cycle_3f0 then prefix = ("@" .. id0) @@ -3547,26 +3877,31 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) end local items do - local tbl_13_auto = {} - for _, _40_ in pairs(kv) do - local _each_41_ = _40_ - local _0 = _each_41_[1] - local v = _each_41_[2] - local _42_ + local tbl_14_auto = {} + local i_15_auto = #tbl_14_auto + for _, _43_ in pairs(kv) do + local _each_44_ = _43_ + local _0 = _each_44_[1] + local v = _each_44_[2] + local val_16_auto do local v0 = pp(v, options, indent0) multiline_3f = (multiline_3f or v0:find("\n")) - _42_ = v0 + val_16_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 + else end - tbl_13_auto[(#tbl_13_auto + 1)] = _42_ end - items = tbl_13_auto + items = tbl_14_auto end return concat_table_lines(items, options, multiline_3f, indent0, "seq", prefix) end end local function concat_lines(lines, options, indent, force_multi_line_3f) - if (#lines == 0) then + if (length_2a(lines) == 0) then if options["empty-as-sequence?"] then return "[]" else @@ -3574,16 +3909,22 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) end else local oneline - local _45_ + local _48_ do - local tbl_13_auto = {} + local tbl_14_auto = {} + local i_15_auto = #tbl_14_auto for _, line in ipairs(lines) do - tbl_13_auto[(#tbl_13_auto + 1)] = line:gsub("^%s+", "") + 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 + else + end end - _45_ = tbl_13_auto + _48_ = tbl_14_auto end - oneline = table.concat(_45_, " ") - if (not options["one-line?"] and (force_multi_line_3f or oneline:find("\n") or ((indent + #oneline) > options["line-length"]))) then + oneline = table.concat(_48_, " ") + if (not options["one-line?"] and (force_multi_line_3f or oneline:find("\n") or ((indent + length_2a(oneline)) > options["line-length"]))) then return table.concat(lines, ("\n" .. string.rep(" ", indent))) else return oneline @@ -3599,21 +3940,23 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) end else local _ - local function _49_(_241) + local function _53_(_241) return visible_cycle_3f(_241, options) end - options["visible-cycle?"] = _49_ + options["visible-cycle?"] = _53_ _ = nil local lines, force_multi_line_3f = metamethod(t, pp, options, indent) options["visible-cycle?"] = nil - local _50_ = type(lines) - if (_50_ == "string") then + local _54_ = type(lines) + if (_54_ == "string") then return lines - elseif (_50_ == "table") then + elseif (_54_ == "table") then return concat_lines(lines, options, indent, force_multi_line_3f) - else - local _0 = _50_ + elseif true then + local _0 = _54_ return error("__fennelview metamethod must return a table of lines") + else + return nil end end end @@ -3621,69 +3964,129 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) options.level = (options.level + 1) local x0 do - local _53_ + local _57_ if options["metamethod?"] then - local _54_ = x - if _54_ then - local _55_ = getmetatable(_54_) - if _55_ then - _53_ = (_55_).__fennelview + local _58_ = x + if (nil ~= _58_) then + local _59_ = getmetatable(_58_) + if (nil ~= _59_) then + _57_ = (_59_).__fennelview else - _53_ = _55_ + _57_ = _59_ end else - _53_ = _54_ + _57_ = _58_ end else - _53_ = nil + _57_ = nil end - if (nil ~= _53_) then - local metamethod = _53_ + if (nil ~= _57_) then + local metamethod = _57_ x0 = pp_metamethod(x, metamethod, options, indent) - else - local _ = _53_ - local _59_, _60_ = table_kv_pairs(x, options) - if (true and (_60_ == "empty")) then - local _0 = _59_ + elseif true then + local _ = _57_ + local _63_, _64_ = table_kv_pairs(x, options) + if (true and (_64_ == "empty")) then + local _0 = _63_ if options["empty-as-sequence?"] then x0 = "[]" else x0 = "{}" end - elseif ((nil ~= _59_) and (_60_ == "table")) then - local kv = _59_ + elseif ((nil ~= _63_) and (_64_ == "table")) then + local kv = _63_ x0 = pp_associative(x, kv, options, indent) - elseif ((nil ~= _59_) and (_60_ == "seq")) then - local kv = _59_ + elseif ((nil ~= _63_) and (_64_ == "seq")) then + local kv = _63_ x0 = pp_sequence(x, kv, options, indent) else - x0 = nil + x0 = nil end + else + x0 = nil end end options.level = (options.level - 1) return x0 end local function number__3estring(n) - local _64_ = string.gsub(tostring(n), ",", ".") - return _64_ + local _68_ = string.gsub(tostring(n), ",", ".") + return _68_ end local function colon_string_3f(s) return s:find("^[-%w?^_!$%&*+./@|<=>]+$") end + 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 + do + local ret = nil + for _, init0 in ipairs(inits) do + if ret then break end + ret = (byte and (function(_69_,_70_,_71_) return (_69_ >= _70_) and (_70_ >= _71_) end)(init0["max-byte"],byte,init0["min-byte"]) and init0) + end + init = ret + end + local code + local function _72_() + local code0 + if init then + code0 = (byte - init["min-byte"]) + else + code0 = nil + end + for i = (index + 1), (index + init.len + -1) do + local byte0 = string.byte(str0, i) + code0 = (byte0 and code0 and (function(_74_,_75_,_76_) return (_74_ >= _75_) and (_75_ >= _76_) end)(191,byte0,128) and ((code0 * 64) + (byte0 - 128))) + end + return code0 + end + code = (init and _72_()) + if (code and (function(_77_,_78_,_79_) return (_77_ >= _78_) and (_78_ >= _79_) end)(init["max-code"],code,init["min-code"]) and not (function(_80_,_81_,_82_) return (_80_ >= _81_) and (_81_ >= _82_) end)(57343,code,55296)) then + return init.len + else + return nil + end + end + local index = 1 + local output = {} + 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))) + if (not len and (nexti <= #str)) then + table.insert(output, string.format("\\%03d", string.byte(str, nexti))) + else + end + if len then + index = (nexti + len) + else + index = (nexti + 1) + end + end + return table.concat(output) + end local function pp_string(str, options, indent) local escs - local _65_ - if (options["escape-newlines?"] and (#str < (options["line-length"] - indent))) then - _65_ = "\\n" + local _86_ + if (options["escape-newlines?"] and (length_2a(str) < (options["line-length"] - indent))) then + _86_ = "\\n" else - _65_ = "\n" + _86_ = "\n" end - local function _67_(_241, _242) + local function _88_(_241, _242) return ("\\%03d"):format(_242:byte()) end - escs = setmetatable({["\7"] = "\\a", ["\8"] = "\\b", ["\12"] = "\\f", ["\11"] = "\\v", ["\13"] = "\\r", ["\9"] = "\\t", ["\\"] = "\\\\", ["\""] = "\\\"", ["\n"] = _65_}, {__index = _67_}) - return ("\"" .. str:gsub("[%c\\\"]", escs) .. "\"") + escs = setmetatable({["\7"] = "\\a", ["\8"] = "\\b", ["\12"] = "\\f", ["\11"] = "\\v", ["\13"] = "\\r", ["\9"] = "\\t", ["\\"] = "\\\\", ["\""] = "\\\"", ["\n"] = _86_}, {__index = _88_}) + local str0 = ("\"" .. str:gsub("[%c\\\"]", escs) .. "\"") + if options["utf8?"] then + return utf8_escape(str0) + else + return str0 + end end local function make_options(t, options) local defaults = {["line-length"] = 80, ["one-line?"] = false, depth = 128, ["detect-cycles?"] = true, ["empty-as-sequence?"] = false, ["metamethod?"] = true, ["prefer-colon?"] = false, ["escape-newlines?"] = false, ["utf8?"] = true, ["max-sparse-gap"] = 10} @@ -3696,7 +4099,7 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) end return defaults end - local function _68_(x, options, indent, colon_3f) + local function _90_(x, options, indent, colon_3f) local indent0 = (indent or 0) local options0 = (options or make_options(x)) local x0 @@ -3706,20 +4109,20 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) x0 = x end local tv = type(x0) - local function _71_() - local _70_ = getmetatable(x0) - if _70_ then - return (_70_).__fennelview + local function _93_() + local _92_ = getmetatable(x0) + if (nil ~= _92_) then + return (_92_).__fennelview else - return _70_ + return _92_ end end - if ((tv == "table") or ((tv == "userdata") and _71_())) then + if ((tv == "table") or ((tv == "userdata") and _93_())) then return pp_table(x0, options0, indent0) elseif (tv == "number") then return number__3estring(x0) else - local function _73_() + local function _95_() if (colon_3f ~= nil) then return colon_3f elseif ("function" == type(options0["prefer-colon?"])) then @@ -3728,7 +4131,7 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) return options0["prefer-colon?"] end end - if ((tv == "string") and colon_string_3f(x0) and _73_()) then + if ((tv == "string") and colon_string_3f(x0) and _95_()) then return (":" .. x0) elseif (tv == "string") then return pp_string(x0, options0, indent0) @@ -3739,14 +4142,22 @@ package.preload["fennel.view"] = package.preload["fennel.view"] or function(...) end end end - pp = _68_ - local function view(x, options) - return pp(x, make_options(x, options), 0) + pp = _90_ + local function view(x, _3foptions) + return pp(x, make_options(x, _3foptions), 0) end return view end package.preload["fennel.utils"] = package.preload["fennel.utils"] or function(...) local view = require("fennel.view") + local version = "1.0.0" + local function warn(message) + if (_G.io and _G.io.stderr) then + return (_G.io.stderr):write(("--WARNING: %s\n"):format(tostring(message))) + else + return nil + end + end local function stablepairs(t) local keys = {} local used_keys = {} @@ -3757,8 +4168,10 @@ package.preload["fennel.utils"] = package.preload["fennel.utils"] or function(.. for i = #keys, 1, -1 do if (keys[i] == k) then table.remove(keys, i) + else end end + else end used_keys[k] = true table.insert(keys, k) @@ -3767,10 +4180,10 @@ package.preload["fennel.utils"] = package.preload["fennel.utils"] or function(.. for k in pairs(t) do table.insert(keys, k) end - local function _77_(_241, _242) + local function _100_(_241, _242) return (tostring(_241) < tostring(_242)) end - table.sort(keys, _77_) + table.sort(keys, _100_) end for i, k in ipairs(keys) do succ[k] = keys[(i + 1)] @@ -3792,66 +4205,70 @@ package.preload["fennel.utils"] = package.preload["fennel.utils"] or function(.. end return stablenext, t, nil end - local function map(t, f, out) - local out0 = (out or {}) + local function map(t, f, _3fout) + local out = (_3fout or {}) local f0 if (type(f) == "function") then f0 = f else - local function _81_(_241) + local function _104_(_241) return (_241)[f] end - f0 = _81_ + f0 = _104_ end for _, x in ipairs(t) do - local _83_ = f0(x) - if (nil ~= _83_) then - local v = _83_ - table.insert(out0, v) + local _106_ = f0(x) + if (nil ~= _106_) then + local v = _106_ + table.insert(out, v) + else end end - return out0 + return out end - local function kvmap(t, f, out) - local out0 = (out or {}) + local function kvmap(t, f, _3fout) + local out = (_3fout or {}) local f0 if (type(f) == "function") then f0 = f else - local function _85_(_241) + local function _108_(_241) return (_241)[f] end - f0 = _85_ + f0 = _108_ end for k, x in stablepairs(t) do - local _87_, _88_ = f0(k, x) - if ((nil ~= _87_) and (nil ~= _88_)) then - local key = _87_ - local value = _88_ - out0[key] = value - elseif (nil ~= _87_) then - local value = _87_ - table.insert(out0, value) + local _110_, _111_ = f0(k, x) + if ((nil ~= _110_) and (nil ~= _111_)) then + local key = _110_ + local value = _111_ + out[key] = value + elseif (nil ~= _110_) then + local value = _110_ + table.insert(out, value) + else end end - return out0 + return out end - local function copy(from, to) - local to0 = (to or {}) + local function copy(from, _3fto) + local to = (_3fto or {}) for k, v in pairs((from or {})) do - to0[k] = v + to[k] = v end - return to0 + return to end - local function member_3f(x, tbl, n) - local _90_ = tbl[(n or 1)] - if (_90_ == x) then + local function member_3f(x, tbl, _3fn) + local _113_ = tbl[(_3fn or 1)] + if (_113_ == x) then return true - elseif (_90_ == nil) then + elseif (_113_ == nil) then return nil + elseif true then + local _ = _113_ + return member_3f(x, tbl, ((_3fn or 1) + 1)) else - local _ = _90_ - return member_3f(x, tbl, ((n or 1) + 1)) + return nil end end local function allpairs(tbl) @@ -3866,13 +4283,17 @@ package.preload["fennel.utils"] = package.preload["fennel.utils"] or function(.. seen[next_state] = true return next_state, value else - local _92_ = getmetatable(t) - if ((_G.type(_92_) == "table") and true) then - local __index = (_92_).__index + local _115_ = getmetatable(t) + if ((_G.type(_115_) == "table") and true) then + local __index = (_115_).__index if ("table" == type(__index)) then t = __index return allpairs_next(t) + else + return nil end + else + return nil end end end @@ -3882,17 +4303,18 @@ package.preload["fennel.utils"] = package.preload["fennel.utils"] or function(.. return self[1] end local nil_sym = nil - local function list__3estring(self, tostring2) + local function list__3estring(self, _3ftostring2) local safe, max = {}, 0 for k in pairs(self) do if ((type(k) == "number") and (k > max)) then max = k + else end end for i = 1, max do safe[i] = (((self[i] == nil) and nil_sym) or self[i]) end - return ("(" .. table.concat(map(safe, (tostring2 or view)), " ", 1, max) .. ")") + return ("(" .. table.concat(map(safe, (_3ftostring2 or view)), " ", 1, max) .. ")") end local function comment_view(c) return c, true @@ -3903,21 +4325,21 @@ package.preload["fennel.utils"] = package.preload["fennel.utils"] or function(.. local function sym_3c(a, b) return (a[1] < tostring(b)) end - local symbol_mt = {"SYMBOL", __fennelview = deref, __tostring = deref, __eq = sym_3d, __lt = sym_3c} + local symbol_mt = {__fennelview = deref, __tostring = deref, __eq = sym_3d, __lt = sym_3c, "SYMBOL"} local expr_mt - local function _97_(x) + local function _120_(x) return tostring(deref(x)) end - expr_mt = {"EXPR", __tostring = _97_} - local list_mt = {"LIST", __fennelview = list__3estring, __tostring = list__3estring} - local comment_mt = {"COMMENT", __fennelview = comment_view, __tostring = deref, __eq = sym_3d, __lt = sym_3c} + expr_mt = {__tostring = _120_, "EXPR"} + local list_mt = {__fennelview = list__3estring, __tostring = list__3estring, "LIST"} + local comment_mt = {__fennelview = comment_view, __tostring = deref, __eq = sym_3d, __lt = sym_3c, "COMMENT"} local sequence_marker = {"SEQUENCE"} - local vararg = setmetatable({"..."}, {"VARARG", __fennelview = deref, __tostring = deref}) + local vararg = setmetatable({"..."}, {__fennelview = deref, __tostring = deref, "VARARG"}) local getenv - local function _98_() + local function _121_() return nil end - getenv = ((os and os.getenv) or _98_) + getenv = ((os and os.getenv) or _121_) local function debug_on_3f(flag) local level = (getenv("FENNEL_DEBUG") or "") return ((level == "all") or level:find(flag)) @@ -3926,10 +4348,11 @@ package.preload["fennel.utils"] = package.preload["fennel.utils"] or function(.. return setmetatable({...}, list_mt) end local function sym(str, _3fsource, _3fscope) - local s = {str, ["?scope"] = _3fscope} + local s = {["?scope"] = _3fscope, str} for k, v in pairs((_3fsource or {})) do if (type(k) == "string") then s[k] = v + else end end return setmetatable(s, symbol_mt) @@ -3939,13 +4362,13 @@ package.preload["fennel.utils"] = package.preload["fennel.utils"] or function(.. return setmetatable({...}, {sequence = sequence_marker}) end local function expr(strcode, etype) - return setmetatable({strcode, type = etype}, expr_mt) + return setmetatable({type = etype, strcode}, expr_mt) end local function comment_2a(contents, _3fsource) - local _let_100_ = (_3fsource or {}) - local filename = _let_100_["filename"] - local line = _let_100_["line"] - return setmetatable({contents, filename = filename, line = line}, comment_mt) + local _let_123_ = (_3fsource or {}) + local filename = _let_123_["filename"] + local line = _let_123_["line"] + return setmetatable({filename = filename, line = line, contents}, comment_mt) end local function varg() return vararg @@ -3983,6 +4406,7 @@ package.preload["fennel.utils"] = package.preload["fennel.utils"] or function(.. local last_char = part:sub(( - 1)) if (last_char == ":") then parts["multi-sym-method-call"] = true + else end if ((last_char == ":") or (last_char == ".")) then parts[(#parts + 1)] = part:sub(1, ( - 2)) @@ -3996,16 +4420,27 @@ package.preload["fennel.utils"] = package.preload["fennel.utils"] or function(.. local function quoted_3f(symbol) return symbol.quoted end - local function walk_tree(root, f, custom_iterator) + local function ast_source(ast) + if table_3f(ast) then + return (getmetatable(ast) or {}) + elseif ("table" == type(ast)) then + return ast + else + return {} + end + end + local function walk_tree(root, f, _3fcustom_iterator) local function walk(iterfn, parent, idx, node) if f(idx, node, parent) then for k, v in iterfn(node) do walk(iterfn, node, k, v) end return nil + else + return nil end end - walk((custom_iterator or pairs), nil, nil, root) + walk((_3fcustom_iterator or pairs), nil, nil, root) return root end local lua_keywords = {"and", "break", "do", "else", "elseif", "end", "false", "for", "function", "if", "in", "local", "nil", "not", "or", "repeat", "return", "then", "true", "until", "while", "goto"} @@ -4023,40 +4458,52 @@ package.preload["fennel.utils"] = package.preload["fennel.utils"] or function(.. return subopts end local root - local function _105_() + local function _129_() end - root = {chunk = nil, scope = nil, options = nil, reset = _105_} - root["set-reset"] = function(_106_) - local _arg_107_ = _106_ - local chunk = _arg_107_["chunk"] - local scope = _arg_107_["scope"] - local options = _arg_107_["options"] - local reset = _arg_107_["reset"] + root = {chunk = nil, scope = nil, options = nil, reset = _129_} + root["set-reset"] = function(_130_) + local _arg_131_ = _130_ + local chunk = _arg_131_["chunk"] + local scope = _arg_131_["scope"] + local options = _arg_131_["options"] + local reset = _arg_131_["reset"] root.reset = function() root.chunk, root.scope, root.options, root.reset = chunk, scope, options, reset return nil end return root.reset end + local warned = {} + local function check_plugin_version(_132_) + local _arg_133_ = _132_ + local name = _arg_133_["name"] + local versions = _arg_133_["versions"] + local plugin = _arg_133_ + if (not member_3f(version:gsub("-dev", ""), (versions or {})) and not warned[plugin]) then + warned[plugin] = true + return warn(string.format("plugin %s does not support Fennel version %s", (name or "unknown"), version)) + else + return nil + end + end local function hook(event, ...) local result = nil if (root.options and root.options.plugins) then for _, plugin in ipairs(root.options.plugins) do - do - local _108_ = plugin[event] - if (nil ~= _108_) then - local f = _108_ - result = f(...) - end - end - if (nil ~= result) then - return result + if result then break end + check_plugin_version(plugin) + local _135_ = plugin[event] + if (nil ~= _135_) then + local f = _135_ + result = f(...) + else end end - return nil + else end + return result end - return {allpairs = allpairs, stablepairs = stablepairs, copy = copy, kvmap = kvmap, map = map, ["walk-tree"] = walk_tree, ["member?"] = member_3f, list = list, sequence = sequence, sym = sym, varg = varg, expr = expr, comment = comment_2a, ["comment?"] = comment_3f, ["expr?"] = expr_3f, ["list?"] = list_3f, ["multi-sym?"] = multi_sym_3f, ["sequence?"] = sequence_3f, ["sym?"] = sym_3f, ["table?"] = table_3f, ["varg?"] = varg_3f, ["quoted?"] = quoted_3f, ["valid-lua-identifier?"] = valid_lua_identifier_3f, ["lua-keywords"] = lua_keywords, hook = hook, ["propagate-options"] = propagate_options, root = root, ["debug-on?"] = debug_on_3f, path = table.concat({"./?.fnl", "./?/init.fnl", getenv("FENNEL_PATH")}, ";"), ["macro-path"] = table.concat({"./?.fnl", "./?/init-macros.fnl", "./?/init.fnl", getenv("FENNEL_MACRO_PATH")}, ";")} + return {warn = warn, allpairs = allpairs, stablepairs = stablepairs, copy = copy, kvmap = kvmap, map = map, ["walk-tree"] = walk_tree, ["member?"] = member_3f, list = list, sequence = sequence, sym = sym, varg = varg, expr = expr, comment = comment_2a, ["comment?"] = comment_3f, ["expr?"] = expr_3f, ["list?"] = list_3f, ["multi-sym?"] = multi_sym_3f, ["sequence?"] = sequence_3f, ["sym?"] = sym_3f, ["table?"] = table_3f, ["varg?"] = varg_3f, ["quoted?"] = quoted_3f, ["valid-lua-identifier?"] = valid_lua_identifier_3f, ["lua-keywords"] = lua_keywords, hook = hook, ["propagate-options"] = propagate_options, root = root, ["debug-on?"] = debug_on_3f, ["ast-source"] = ast_source, version = version, path = table.concat({"./?.fnl", "./?/init.fnl", getenv("FENNEL_PATH")}, ";"), ["macro-path"] = table.concat({"./?.fnl", "./?/init-macros.fnl", "./?/init.fnl", getenv("FENNEL_MACRO_PATH")}, ";")} end utils = require("fennel.utils") local parser = require("fennel.parser") @@ -4069,6 +4516,7 @@ local function eval_env(env, opts) local env0 = specials["make-compiler-env"](nil, compiler.scopes.compiler, {}, opts) if (opts.allowedGlobals == nil) then opts.allowedGlobals = specials["current-global-names"](env0) + else end return specials["wrap-env"](env0) else @@ -4079,12 +4527,15 @@ local function eval_opts(options, str) local opts = utils.copy(options) if (opts.allowedGlobals == nil) then opts.allowedGlobals = specials["current-global-names"](opts.env) + else end if (not opts.filename and not opts.source) then opts.source = str + else end if (opts.env == "_COMPILER") then opts.scope = compiler["make-scope"](compiler.scopes.compiler) + else end return opts end @@ -4093,14 +4544,14 @@ local function eval(str, options, ...) local env = eval_env(opts.env, opts) local lua_source = compiler["compile-string"](str, opts) local loader - local function _563_(...) + local function _616_(...) if opts.filename then return ("@" .. opts.filename) else return str end end - loader = specials["load-code"](lua_source, env, _563_(...)) + loader = specials["load-code"](lua_source, env, _616_(...)) opts.filename = nil return loader(...) end @@ -4125,21 +4576,23 @@ local function syntax() out[k] = {["macro?"] = true, ["body-form?"] = utils["member?"](k, body_3f), ["binding-form?"] = utils["member?"](k, binding_3f), ["define?"] = utils["member?"](k, define_3f)} end for k, v in pairs(_G) do - local _564_ = type(v) - if (_564_ == "function") then + local _617_ = type(v) + if (_617_ == "function") then out[k] = {["global?"] = true, ["function?"] = true} - elseif (_564_ == "table") then + elseif (_617_ == "table") then for k2, v2 in pairs(v) do if (("function" == type(v2)) and (k ~= "_G")) then out[(k .. "." .. k2)] = {["function?"] = true, ["global?"] = true} + else end end out[k] = {["global?"] = true} + else end end return out end -local mod = {list = utils.list, ["list?"] = utils["list?"], sym = utils.sym, ["sym?"] = utils["sym?"], sequence = utils.sequence, ["sequence?"] = utils["sequence?"], comment = utils.comment, ["comment?"] = utils["comment?"], varg = utils.varg, path = utils.path, ["macro-path"] = utils["macro-path"], ["sym-char?"] = parser["sym-char?"], parser = parser.parser, granulate = parser.granulate, ["string-stream"] = parser["string-stream"], compile = compiler.compile, ["compile-string"] = compiler["compile-string"], ["compile-stream"] = compiler["compile-stream"], compile1 = compiler.compile1, traceback = compiler.traceback, mangle = compiler["global-mangling"], unmangle = compiler["global-unmangling"], metadata = compiler.metadata, scope = compiler["make-scope"], gensym = compiler.gensym, ["load-code"] = specials["load-code"], ["macro-loaded"] = specials["macro-loaded"], ["macro-searchers"] = specials["macro-searchers"], ["search-module"] = specials["search-module"], ["make-searcher"] = specials["make-searcher"], makeSearcher = specials["make-searcher"], searcher = specials["make-searcher"](), doc = specials.doc, view = view, eval = eval, dofile = dofile_2a, version = "1.0.0-dev", repl = repl, syntax = syntax, loadCode = specials["load-code"], make_searcher = specials["make-searcher"], searchModule = specials["search-module"], macroLoaded = specials["macro-loaded"], compileStream = compiler["compile-stream"], compileString = compiler["compile-string"], stringStream = parser["string-stream"]} +local mod = {list = utils.list, ["list?"] = utils["list?"], sym = utils.sym, ["sym?"] = utils["sym?"], sequence = utils.sequence, ["sequence?"] = utils["sequence?"], comment = utils.comment, ["comment?"] = utils["comment?"], varg = utils.varg, path = utils.path, ["macro-path"] = utils["macro-path"], ["sym-char?"] = parser["sym-char?"], parser = parser.parser, granulate = parser.granulate, ["string-stream"] = parser["string-stream"], compile = compiler.compile, ["compile-string"] = compiler["compile-string"], ["compile-stream"] = compiler["compile-stream"], compile1 = compiler.compile1, traceback = compiler.traceback, mangle = compiler["global-mangling"], unmangle = compiler["global-unmangling"], metadata = compiler.metadata, scope = compiler["make-scope"], gensym = compiler.gensym, ["load-code"] = specials["load-code"], ["macro-loaded"] = specials["macro-loaded"], ["macro-searchers"] = specials["macro-searchers"], ["search-module"] = specials["search-module"], ["make-searcher"] = specials["make-searcher"], makeSearcher = specials["make-searcher"], searcher = specials["make-searcher"](), doc = specials.doc, view = view, eval = eval, dofile = dofile_2a, version = utils.version, repl = repl, syntax = syntax, loadCode = specials["load-code"], make_searcher = specials["make-searcher"], searchModule = specials["search-module"], macroLoaded = specials["macro-loaded"], compileStream = compiler["compile-stream"], compileString = compiler["compile-string"], stringStream = parser["string-stream"]} utils["fennel-module"] = mod do local builtin_macros = [===[;; This module contains all the built-in Fennel macros. Unlike all the other @@ -4168,7 +4621,7 @@ do Same as ->, except splices the value into the last position of each form rather than the first." (var x val) - (each [_ e (pairs [...])] + (each [_ e (ipairs [...])] (let [elt (if (list? e) e (list e))] (table.insert elt x) (set x elt))) @@ -4185,7 +4638,7 @@ do tmp (gensym)] (table.insert el 2 tmp) `(let [,tmp ,val] - (if ,tmp + (if (not= nil ,tmp) (-?> ,el ,(unpack els)) ,tmp))))) @@ -4200,7 +4653,7 @@ do tmp (gensym)] (table.insert el tmp) `(let [,tmp ,val] - (if ,tmp + (if (not= ,tmp nil) (-?>> ,el ,(unpack els)) ,tmp))))) @@ -4221,9 +4674,10 @@ do "Evaluates val and splices it into the first argument of subsequent forms." (let [name (gensym) form `(let [,name ,val])] - (each [_ elt (pairs [...])] - (table.insert elt 2 name) - (table.insert form elt)) + (each [_ elt (ipairs [...])] + (let [elt (if (list? elt) elt (list elt))] + (table.insert elt 2 name) + (table.insert form elt))) (table.insert form name) form)) @@ -4256,20 +4710,26 @@ do (var into nil) (for [i (length iter-tbl) 2 -1] (if (= :into (. iter-tbl i)) - (do (set into (table.remove iter-tbl (+ i 1))) + (do (assert (not into) "expected only one :into clause") + (set into (table.remove iter-tbl (+ i 1))) (table.remove iter-tbl i)))) - (assert (or (not into) (table? into)) "expected table in :into clause") + (assert (or (not into) + (sym? into) + (table? into) + (list? into)) + "expected table, function call, or symbol in :into clause") (or into [])) - (fn collect* [iter-tbl key-value-expr ...] - "Returns a table made by running an iterator and evaluating an expression - that returns key-value pairs to be inserted sequentially into the table. - This can be thought of as a \"table comprehension\". The provided key-value - expression must return either 2 values, or nil. + (fn collect* [iter-tbl key-expr value-expr ...] + "Returns a table made by running an iterator and evaluating an expression that + returns key-value pairs to be inserted sequentially into the table. This can + be thought of as a table comprehension. The body should provide two + expressions (used as key and value) or nil, which causes it to be omitted from + the resulting table. For example, (collect [k v (pairs {:apple \"red\" :orange \"orange\"})] - (values v k)) + v k) returns {:red \"apple\" :orange \"orange\"} @@ -4277,24 +4737,26 @@ do Supports early termination with an :until clause." (assert (and (sequence? iter-tbl) (>= (length iter-tbl) 2)) "expected iterator binding table") - (assert (not= nil key-value-expr) "expected key-value expression") + (assert (not= nil key-expr) "expected key and value expression") (assert (= nil ...) - "expected exactly one body expression. Wrap multiple expressions with do") - `(let [tbl# ,(into-val iter-tbl)] - (each ,iter-tbl - (match ,key-value-expr - (k# v#) (tset tbl# k# v#))) - tbl#)) + "expected 1 or 2 body expressions; wrap multiple expressions with do") + (let [kv-expr (if (= nil value-expr) key-expr `(values ,key-expr ,value-expr))] + `(let [tbl# ,(into-val iter-tbl)] + (each ,iter-tbl + (match ,kv-expr + (k# v#) (tset tbl# k# v#))) + tbl#))) (fn icollect* [iter-tbl value-expr ...] "Returns a sequential table made by running an iterator and evaluating an expression that returns values to be inserted sequentially into the table. - This can be thought of as a \"list comprehension\". + This can be thought of as a \"list comprehension\". If the body returns nil + that element is omitted from the resulting table. For example, - (icollect [_ v (ipairs [1 2 3 4 5])] (when (> v 2) (* v v))) + (icollect [_ v (ipairs [1 2 3 4 5])] (when (not= v 3) (* v v))) returns - [9 16 25] + [1 4 16 25] Supports an :into clause after the iterator to put results in an existing table. Supports early termination with an :until clause." @@ -4304,8 +4766,14 @@ do (assert (= nil ...) "expected exactly one body expression. Wrap multiple expressions with do") `(let [tbl# ,(into-val iter-tbl)] + ;; believe it or not, using a var here has a pretty good performance boost: + ;; https://p.hagelb.org/icollect-performance.html + (var i# (length tbl#)) (each ,iter-tbl - (tset tbl# (+ (length tbl#) 1) ,value-expr)) + (let [val# ,value-expr] + (when (not= nil val#) + (set i# (+ i# 1)) + (tset tbl# i# val#)))) tbl#)) (fn accumulate* [iter-tbl accum-expr ...] @@ -4448,23 +4916,23 @@ do (assert (and binding1 module-name1 (= 0 (% (select "#" ...) 2))) "expected even number of binding/modulename pairs") (for [i 1 (select "#" binding1 module-name1 ...) 2] + ;; delegate the actual loading of the macros to the require-macros + ;; special which already knows how to set up the compiler env and stuff. + ;; this is weird because require-macros is deprecated but it works. (let [(binding modname) (select i binding1 module-name1 ...) - ;; generate a subscope of current scope, use require-macros - ;; to bring in macro module. after that, we just copy the - ;; macros from subscope to scope. scope (get-scope) - subscope (fennel.scope scope)] - (_SPECIALS.require-macros `(require-macros ,modname) subscope {} ast) + macros* (_SPECIALS.require-macros `(import-macros ,modname) + scope {} binding1)] (if (sym? binding) ;; bind whole table of macros to table bound to symbol - (tset scope.macros (. binding 1) (. macro-loaded modname)) + (tset scope.macros (. binding 1) macros*) ;; 1-level table destructuring for importing individual macros (table? binding) (each [macro-name [import-key] (pairs binding)] - (assert (= :function (type (. subscope.macros macro-name))) + (assert (= :function (type (. macros* macro-name))) (.. "macro " macro-name " not found in module " (tostring modname))) - (tset scope.macros import-key (. subscope.macros macro-name)))))) + (tset scope.macros import-key (. macros* macro-name)))))) nil) ;;; Pattern matching @@ -4485,12 +4953,16 @@ do bindings []] (each [k pat (pairs pattern)] (if (= pat `&) - (do + (let [rest-pat (. pattern (+ k 1)) + rest-val `(select ,k ((or table.unpack _G.unpack) ,val)) + subcondition (match-table `(pick-values 1 ,rest-val) + rest-pat unifications match-pattern)] + (if (not (sym? rest-pat)) + (table.insert condition subcondition)) (assert (= nil (. pattern (+ k 2))) "expected & rest argument before last parameter") - (table.insert bindings (. pattern (+ k 1))) - (table.insert bindings - [`(select ,k ((or table.unpack _G.unpack) ,val))])) + (table.insert bindings rest-pat) + (table.insert bindings [rest-val])) (= k `&as) (do (table.insert bindings pat) @@ -4679,17 +5151,17 @@ do ]===] local module_name = "fennel.macros" local _ - local function _567_() + local function _620_() return mod end - package.preload[module_name] = _567_ + package.preload[module_name] = _620_ _ = nil local env do - local _568_ = specials["make-compiler-env"](nil, compiler.scopes.compiler, {}) - do end (_568_)["utils"] = utils - _568_["fennel"] = mod - env = _568_ + local _621_ = specials["make-compiler-env"](nil, compiler.scopes.compiler, {}) + do end (_621_)["utils"] = utils + _621_["fennel"] = mod + env = _621_ end local built_ins = eval(builtin_macros, {env = env, scope = compiler.scopes.compiler, allowedGlobals = false, useMetadata = true, filename = "src/fennel/macros.fnl", moduleName = module_name}) for k, v in pairs(built_ins) do