moonscript support fixes

This commit is contained in:
kepler155c@gmail.com
2020-06-13 12:19:13 -06:00
parent 1a166bdb22
commit 27c7d2dd18
8 changed files with 17 additions and 195 deletions

View File

@@ -1,80 +0,0 @@
--[[
-- a very simple debugger implementation
local dbg = require('debugger')
dbg.read = function(snapshot)
print(('%s: %d'):format(snapshot.info.source, snapshot.info.currentline))
write('> ')
return read()
end
dbg.stopIn(debug.getinfo(1).func)
]]
local function m2(a)
return a
end
local function method(times)
local a = 2
for _ = 1, times do
a = a * a
end
return m2(a)
end
local Event = require('opus.event')
Event.on('event1', function()
print('event1')
end)
Event.on('event2', function()
print('event2')
end)
Event.onTimeout(10, function()
Event.exitPullEvents()
end)
local function xx()
os.queueEvent('event1')
os.queueEvent('event2')
Event.pullEvents()
end
xx()
local chunk = load([[
local j = 5
for i = 1, 5 do
j = j * i
end
--table.insert(j, 5)
return j]], nil, nil, _ENV)
local j = chunk()
print(j)
local co = coroutine.create(function(args)
print('in coroutine')
return 'hi'
end)
local _, t = coroutine.resume(co, 'test')
while coroutine.status(co) ~= 'dead' do
coroutine.resume(co, os.pullEvent())
--print('alive')
end
print(coroutine.status(co))
print(t)
local i = 2
print(i)
local res = method(i)
dofile("rom/modules/main/cc/expect.lua")
print(res)
print('result: ' .. res)
table.insert(res, 5)

View File

@@ -1,7 +0,0 @@
moonscript must be run in compatibility mode:
> compat moon T.moon
> compat moonc T.moon
moon and moonc were modified to allow relative paths:
> cd /packages/moonscript
> compat moonc T.moon

View File

@@ -1,99 +0,0 @@
local Event = require('opus.event')
local UI = require('opus.ui')
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({
UI.MenuBar({
buttons = {
{
text = 'Activate',
event = 'activate'
},
{
text = 'Terminate',
event = 'terminate'
},
{
text = 'Inspect',
event = 'inspect'
}
}
}),
grid = UI.ScrollingGrid({
y = 2,
columns = {
{
heading = 'ID',
key = 'uid',
width = 3
},
{
heading = 'Title',
key = 'title'
},
{
heading = 'Status',
key = 'status'
},
{
heading = 'Time',
key = 'timestamp'
}
},
values = tasks,
sortColumn = 'uid',
autospace = true,
getDisplayValues = function(self, row)
local elapsed = os.clock() - row.timestamp
return {
uid = row.uid,
title = row.title,
status = row.isDead and 'error' or coroutine.status(row.co),
timestamp = elapsed < 60 and string.format("%ds", math.floor(elapsed)) or string.format("%sm", math.floor(elapsed / 6) / 10)
}
end
}),
accelerators = {
['control-q'] = 'quit',
[' '] = 'activate',
t = 'terminate'
},
eventHandler = function(self, event)
local t = self.grid:getSelected()
local _exp_0 = event.type
if 'activate' == _exp_0 or 'grid_select' == _exp_0 then
if t then
return multishell.setFocus(t.uid)
end
elseif 'terminate' == _exp_0 then
if t then
return multishell.terminate(t.uid)
end
elseif 'inspect' == _exp_0 then
if t then
return multishell.openTab(_ENV, {
path = 'sys/apps/Lua.lua',
args = {
t
},
focused = true
})
end
elseif 'quit' == _exp_0 then
return UI:quit()
else
return UI.Page.eventHandler(self, event)
end
end
})
Event.onInterval(1, function()
page.grid:update()
page.grid:draw()
return page:sync()
end)
UI:setPage(page)
return UI:start()

View File

@@ -1,7 +1,6 @@
local Map = require('opus.map')
local fs = _G.fs
local shell = _ENV.shell
local commands = Map.transpose {
'packages/moonscript/moon',
@@ -16,21 +15,28 @@ local function compatEnv(source)
return env
end
shell.registerHandler(function(args, env)
if args[1]:match('(.+)%.moon$') then
local function fix(env, args)
if #args > 0 then
args[1] = env.shell.resolve(args[1])
end
return args
end
_ENV.shell.registerHandler(function(env, command, args)
if command:match('(.+)%.moon$') then
return {
title = fs.getName(args[1]):match('([^%.]+)'),
title = fs.getName(command):match('([^%.]+)'),
path = 'packages/moonscript/moon',
args = args,
args = { env.shell.resolveProgram(command), table.unpack(args) },
load = loadfile,
env = compatEnv(env),
}
end
local command = shell.resolveProgram(args[1]) or ''
command = env.shell.resolveProgram(command) or ''
return commands[command] and {
title = fs.getName(command),
path = command,
args = { table.unpack(args, 2) },
args = fix(env, args),
load = loadfile,
env = compatEnv(env),
}

View File

@@ -1,5 +1,7 @@
packages/moonscript/repo gitfs leafo/moonscript/master
packages/moonscript/moon linkfs packages/moonscript/repo/bin/moon
packages/moonscript/moonc linkfs packages/moonscript/repo/bin/moonc
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/moonutil gitfs natnat-mc/moonutil/master/moonutil
rom/modules/main/argparse urlfs https://raw.githubusercontent.com/mpeterv/argparse/master/src/argparse.lua

View File

@@ -23,7 +23,7 @@
[ 'monitor' ] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/monitor/.package',
[ 'moonscript' ] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/moonscript/.package',
[ 'neural' ] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/neural/.package',
[ 'penlight' ] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/pl/.package',
[ 'pl' ] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/pl/.package',
-- [ 'pickup' ] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/pickup/.package',
[ 'recipeBook' ] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/recipeBook/.package',
[ 'screenSaver'] = 'https://raw.githubusercontent.com/kepler155c/opus-apps/develop-1.8/screenSaver/.package',