moonscript, busted, penlight packages + debugger speed improvements

This commit is contained in:
kepler155c@gmail.com
2020-06-09 18:17:21 -06:00
parent de3d73de70
commit 0f7534d12c
19 changed files with 1065 additions and 1561 deletions

View File

@@ -1,5 +1,7 @@
running the compiler works fine...
moonc T.moon <-- OK
moonscript must be run in compatibility mode:
> compat moon T.moon
> compat moonc T.moon
working on getting the moon command to work properly
moon T.moon <-- NOPE
moon and moonc were modified to allow relative paths:
> cd /packages/moonscript
> compat moonc T.moon

View File

@@ -1,11 +1,13 @@
local Event = require('opus.event')
local UI = require('opus.ui')
local kernel = _G.kernel
local multishell = _ENV.multishell
local kernel
kernel = _G.kernel
local multishell
multishell = _ENV.multishell
local tasks = multishell and multishell.getTabs and multishell.getTabs() or kernel.routines
UI:configure('Tasks', ...)
local page = UI.Page({
menuBar = UI.MenuBar({
UI.MenuBar({
buttons = {
{
text = 'Activate',

View File

@@ -1,14 +1,15 @@
Event = require('opus.event')
UI = require('opus.ui')
kernel = _G.kernel
multishell = _ENV.multishell
tasks = multishell and multishell.getTabs and multishell.getTabs() or kernel.routines
import kernel from _G
import multishell from _ENV
tasks = multishell and multishell.getTabs and multishell.getTabs! or kernel.routines
UI\configure 'Tasks', ...
page = UI.Page {
menuBar: UI.MenuBar {
UI.MenuBar {
buttons: {
{ text: 'Activate', event: 'activate' },
{ text: 'Terminate', event: 'terminate' },
@@ -43,7 +44,7 @@ page = UI.Page {
t: 'terminate',
},
eventHandler: (event) =>
t = self.grid\getSelected!
t = @grid\getSelected!
switch event.type
when 'activate', 'grid_select'
multishell.setFocus t.uid if t

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,5 @@
packages/moonscript gitfs leafo/moonscript/master/bin
rom/modules/main/moonscript gitfs leafo/moonscript/master/moonscript
rom/modules/main/moon gitfs leafo/moonscript/master/moon
rom/modules/main/argparse.lua linkfs packages/moonscript/argparse.lua
packages/moonscript/repo gitfs leafo/moonscript/master
rom/modules/main/moonscript linkfs packages/moonscript/repo/moonscript
rom/modules/main/moon linkfs packages/moonscript/repo/moon
rom/modules/main/moonutil gitfs natnat-mc/moonutil/master/moonutil
rom/modules/main/argparse urlfs https://raw.githubusercontent.com/mpeterv/argparse/master/src/argparse.lua

116
moonscript/moon Normal file
View File

@@ -0,0 +1,116 @@
#!/usr/bin/env lua
local argparse = require("argparse")
local moonscript = require("moonscript.base")
local util = require("moonscript.util")
local errors = require("moonscript.errors")
local unpack = util.unpack
local argparser = argparse()({
name = "moon"
})
argparser:argument("script")
argparser:argument("args"):args("*")
argparser:option("-c --coverage", "Collect and print code coverage")
argparser:option("-d", "Disable stack trace rewriting")
argparser:option("-v --version", "Print version information")
local base = 0
local _list_0 = arg
for _index_0 = 1, #_list_0 do
local flag = _list_0[_index_0]
base = base + 1
if flag:sub(1, 1) ~= "-" then
break
end
end
local args = {
unpack(arg, 1, base)
}
local opts = argparser:parse(args)
local print_err
print_err = function(...)
local msg = table.concat((function(...)
local _accum_0 = { }
local _len_0 = 1
local _list_1 = {
...
}
for _index_0 = 1, #_list_1 do
local v = _list_1[_index_0]
_accum_0[_len_0] = tostring(v)
_len_0 = _len_0 + 1
end
return _accum_0
end)(...), "\t")
return io.stderr:write(msg .. "\n")
end
local run
run = function()
if opts.version then
require("moonscript.version").print_version()
os.exit()
end
local script_fname = shell.resolve(opts.script)
args = {
unpack(arg, base + 1)
}
args[-1] = arg[0]
args[0] = opts.script
local moonscript_chunk, lua_parse_error
local passed, err = pcall(function()
moonscript_chunk, lua_parse_error = moonscript.loadfile(script_fname, {
implicitly_return_root = false
})
end)
if not (passed) then
print_err(err)
os.exit(1)
end
if not (moonscript_chunk) then
if lua_parse_error then
print_err(lua_parse_error)
else
print_err("Can't file file: " .. tostring(script_fname))
end
os.exit(1)
end
util.getfenv(moonscript_chunk).arg = args
local run_chunk
run_chunk = function()
moonscript.insert_loader()
moonscript_chunk(unpack(args))
return moonscript.remove_loader()
end
if opts.d then
return run_chunk()
end
local err, trace, cov
if opts.coverage then
print("starting coverage")
local coverage = require("moonscript.cmd.coverage")
cov = coverage.CodeCoverage()
cov:start()
end
xpcall(run_chunk, function(_err)
err = _err
trace = debug.traceback("", 2)
end)
if err then
local truncated = errors.truncate_traceback(util.trim(trace))
local rewritten = errors.rewrite_traceback(truncated, err)
if rewritten then
print_err(rewritten)
else
print_err(table.concat({
err,
util.trim(trace)
}, "\n"))
end
return os.exit(1)
else
if cov then
cov:stop()
return cov:print_results()
end
end
end
return run()
-- vim: set filetype=lua:

235
moonscript/moonc Normal file
View File

@@ -0,0 +1,235 @@
#!/usr/bin/env lua
local argparse = require "argparse"
local lfs = require "lfs"
local parser = argparse()
parser:flag("-l --lint", "Perform a lint on the file instead of compiling")
parser:flag("-v --version", "Print version")
parser:flag("-w --watch", "Watch file/directory for updates")
parser:option("--transform", "Transform syntax tree with module")
parser:mutex(
parser:option("-t --output-to", "Specify where to place compiled files"),
parser:option("-o", "Write output to file"),
parser:flag("-p", "Write output to standard output"),
parser:flag("-T", "Write parse tree instead of code (to stdout)"),
parser:flag("-b", "Write parse and compile time instead of code(to stdout)"),
parser:flag("-X", "Write line rewrite map instead of code (to stdout)")
)
parser:flag("-",
"Read from standard in, print to standard out (Must be only argument)")
local read_stdin = arg[1] == "--" -- luacheck: ignore 113
if not read_stdin then
parser:argument("file/directory"):args("+")
end
local opts = parser:parse()
if opts.version then
local v = require "moonscript.version"
v.print_version()
os.exit()
end
function log_msg(...)
if not opts.p then
io.stderr:write(table.concat({...}, " ") .. "\n")
end
end
local moonc = require("moonscript.cmd.moonc")
local util = require "moonscript.util"
local normalize_dir = moonc.normalize_dir
local compile_and_write = moonc.compile_and_write
local path_to_target = moonc.path_to_target
local function scan_directory(root, collected)
root = normalize_dir(root)
collected = collected or {}
for fname in lfs.dir(root) do
if not fname:match("^%.") then
local full_path = root..fname
if lfs.attributes(full_path, "mode") == "directory" then
scan_directory(full_path, collected)
elseif fname:match("%.moon$") then
table.insert(collected, full_path)
end
end
end
return collected
end
local function remove_dups(tbl, key_fn)
local hash = {}
local final = {}
for _, v in ipairs(tbl) do
local dup_key = key_fn and key_fn(v) or v
if not hash[dup_key] then
table.insert(final, v)
hash[dup_key] = true
end
end
return final
end
-- creates tuples of input and target
local function get_files(fname, files)
files = files or {}
if lfs.attributes(fname, "mode") == "directory" then
for _, sub_fname in ipairs(scan_directory(fname)) do
table.insert(files, {
sub_fname,
path_to_target(sub_fname, opts.output_to, fname)
})
end
else
if fname:sub(1, 1) ~= '/' then
fname = lfs.currentdir() .. '/' .. fname
end
table.insert(files, {
fname,
path_to_target(fname, opts.output_to)
})
end
return files
end
if read_stdin then
local parse = require "moonscript.parse"
local compile = require "moonscript.compile"
local text = io.stdin:read("*a")
local tree, err = parse.string(text)
if not tree then error(err) end
local code, err, pos = compile.tree(tree)
if not code then
error(compile.format_error(err, pos, text))
end
print(code)
os.exit()
end
local inputs = opts["file/directory"]
local files = {}
for _, input in ipairs(inputs) do
get_files(input, files)
end
files = remove_dups(files, function(f)
return f[2]
end)
-- returns an iterator that returns files that have been updated
local function create_watcher(files)
local watchers = require("moonscript.cmd.watchers")
if watchers.InotifyWacher:available() then
return watchers.InotifyWacher(files):each_update()
end
return watchers.SleepWatcher(files):each_update()
end
if opts.watch then
-- build function to check for lint or compile in watch
local handle_file
if opts.lint then
local lint = require "moonscript.cmd.lint"
handle_file = lint.lint_file
else
handle_file = compile_and_write
end
local watcher = create_watcher(files)
-- catches interrupt error for ctl-c
local protected = function()
local status, file = true, watcher()
if status then
return file
elseif file ~= "interrupted!" then
error(file)
end
end
for fname in protected do
local target = path_to_target(fname, opts.t)
if opts.o then
target = opts.o
end
local success, err = handle_file(fname, target)
if opts.lint then
if success then
io.stderr:write(success .. "\n\n")
elseif err then
io.stderr:write(fname .. "\n" .. err .. "\n\n")
end
elseif not success then
io.stderr:write(table.concat({
"",
"Error: " .. fname,
err,
"\n",
}, "\n"))
elseif success == "build" then
log_msg("Built", fname, "->", target)
end
end
io.stderr:write("\nQuitting...\n")
elseif opts.lint then
local has_linted_with_error;
local lint = require "moonscript.cmd.lint"
for _, tuple in pairs(files) do
local fname = tuple[1]
local res, err = lint.lint_file(fname)
if res then
has_linted_with_error = true
io.stderr:write(res .. "\n\n")
elseif err then
has_linted_with_error = true
io.stderr:write(fname .. "\n" .. err.. "\n\n")
end
end
if has_linted_with_error then
os.exit(1)
end
else
for _, tuple in ipairs(files) do
local fname, target = util.unpack(tuple)
if opts.o then
target = opts.o
end
local success, err = compile_and_write(fname, target, {
print = opts.p,
fname = fname,
benchmark = opts.b,
show_posmap = opts.X,
show_parse_tree = opts.T,
transform_module = opts.transform
})
if not success then
io.stderr:write(fname .. "\t" .. err .. "\n")
os.exit(1)
end
end
end