From 27c7d2dd18a0eeb320db92bcdabda31a02a41352 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Sat, 13 Jun 2020 12:19:13 -0600 Subject: [PATCH] moonscript support fixes --- debugger/example.lua | 80 ------------------------- moonscript/README.txt | 7 --- moonscript/T.lua | 99 ------------------------------- moonscript/autorun/startup.lua | 20 ++++--- moonscript/etc/fstab | 4 +- moonscript/{moon => moon.works} | 0 moonscript/{moonc => moonc.works} | 0 packages.list | 2 +- 8 files changed, 17 insertions(+), 195 deletions(-) delete mode 100644 debugger/example.lua delete mode 100644 moonscript/README.txt delete mode 100644 moonscript/T.lua rename moonscript/{moon => moon.works} (100%) rename moonscript/{moonc => moonc.works} (100%) diff --git a/debugger/example.lua b/debugger/example.lua deleted file mode 100644 index 20ce2f8..0000000 --- a/debugger/example.lua +++ /dev/null @@ -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) diff --git a/moonscript/README.txt b/moonscript/README.txt deleted file mode 100644 index d0b8bfa..0000000 --- a/moonscript/README.txt +++ /dev/null @@ -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 diff --git a/moonscript/T.lua b/moonscript/T.lua deleted file mode 100644 index cd0fa6d..0000000 --- a/moonscript/T.lua +++ /dev/null @@ -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() diff --git a/moonscript/autorun/startup.lua b/moonscript/autorun/startup.lua index 0f685cd..f3343e4 100644 --- a/moonscript/autorun/startup.lua +++ b/moonscript/autorun/startup.lua @@ -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), } diff --git a/moonscript/etc/fstab b/moonscript/etc/fstab index 4f45064..2fe25e2 100644 --- a/moonscript/etc/fstab +++ b/moonscript/etc/fstab @@ -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 diff --git a/moonscript/moon b/moonscript/moon.works similarity index 100% rename from moonscript/moon rename to moonscript/moon.works diff --git a/moonscript/moonc b/moonscript/moonc.works similarity index 100% rename from moonscript/moonc rename to moonscript/moonc.works diff --git a/packages.list b/packages.list index 2fde8e1..b738872 100644 --- a/packages.list +++ b/packages.list @@ -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',