diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-04-13 18:40:35 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2020-04-14 08:46:54 +0000 |
| commit | 1a8debe87762072b3a63b769aa515ebf63b4c70d (patch) | |
| tree | 33b42866307d11d2c0878b23e0ec0bb8925d3fcc | |
| parent | spec base.match __tostring (diff) | |
| download | alive-1a8debe87762072b3a63b769aa515ebf63b4c70d.tar.gz alive-1a8debe87762072b3a63b769aa515ebf63b4c70d.zip | |
move into proper Lua module (`alv`)
| -rw-r--r-- | Makefile | 12 | ||||
| -rw-r--r-- | alv/ast.moon (renamed from core/ast.moon) | 0 | ||||
| -rw-r--r-- | alv/base/builtin.moon (renamed from core/base/builtin.moon) | 0 | ||||
| -rw-r--r-- | alv/base/fndef.moon (renamed from core/base/fndef.moon) | 0 | ||||
| -rw-r--r-- | alv/base/init.moon (renamed from core/base/init.moon) | 16 | ||||
| -rw-r--r-- | alv/base/input.moon (renamed from core/base/input.moon) | 4 | ||||
| -rw-r--r-- | alv/base/match.moon (renamed from core/base/match.moon) | 4 | ||||
| -rw-r--r-- | alv/base/op.moon (renamed from core/base/op.moon) | 0 | ||||
| -rw-r--r-- | alv/builtin.moon (renamed from core/builtin.moon) | 14 | ||||
| -rw-r--r-- | alv/cell.moon (renamed from core/cell.moon) | 8 | ||||
| -rw-r--r-- | alv/config.ld (renamed from core/config.ld) | 2 | ||||
| -rw-r--r-- | alv/copilot.moon (renamed from copilot.moon) | 26 | ||||
| -rw-r--r-- | alv/cycle.moon (renamed from core/cycle.moon) | 6 | ||||
| -rw-r--r-- | alv/error.moon (renamed from core/error.moon) | 0 | ||||
| -rw-r--r-- | alv/extensions.md (renamed from core/extensions.md) | 10 | ||||
| -rw-r--r-- | alv/init.moon (renamed from core/init.moon) | 33 | ||||
| -rw-r--r-- | alv/invoke.moon (renamed from core/invoke.moon) | 8 | ||||
| -rw-r--r-- | alv/logger.moon (renamed from logger.moon) | 73 | ||||
| -rw-r--r-- | alv/parsing.moon (renamed from core/parsing.moon) | 6 | ||||
| -rw-r--r-- | alv/registry.moon (renamed from core/registry.moon) | 4 | ||||
| -rw-r--r-- | alv/result.moon (renamed from core/result.moon) | 0 | ||||
| -rw-r--r-- | alv/scope.moon (renamed from core/scope.moon) | 6 | ||||
| -rw-r--r-- | alv/stream/base.moon (renamed from core/stream/base.moon) | 0 | ||||
| -rw-r--r-- | alv/stream/event.moon (renamed from core/stream/event.moon) | 8 | ||||
| -rw-r--r-- | alv/stream/init.moon (renamed from core/stream/init.moon) | 6 | ||||
| -rw-r--r-- | alv/stream/io.moon (renamed from core/stream/io.moon) | 2 | ||||
| -rw-r--r-- | alv/stream/value.moon (renamed from core/stream/value.moon) | 8 | ||||
| -rw-r--r-- | alv/tag.moon (renamed from core/tag.moon) | 2 | ||||
| -rw-r--r-- | alv/version.moon (renamed from core/version.moon) | 0 | ||||
| -rwxr-xr-x[-rw-r--r--] | bin/alv (renamed from init.moon) | 15 | ||||
| -rw-r--r-- | bin/copilot.bat | 6 | ||||
| -rwxr-xr-x | bin/copilot.sh | 23 | ||||
| -rw-r--r-- | extra/docs.moon | 4 | ||||
| -rw-r--r-- | extra/layout.moon | 2 | ||||
| -rw-r--r-- | lib/logic.moon | 2 | ||||
| -rw-r--r-- | lib/math.moon | 2 | ||||
| -rw-r--r-- | lib/midi.moon | 2 | ||||
| -rw-r--r-- | lib/midi/core.moon | 2 | ||||
| -rw-r--r-- | lib/midi/launchctl.moon | 2 | ||||
| -rw-r--r-- | lib/osc.moon | 2 | ||||
| -rw-r--r-- | lib/pilot.moon | 2 | ||||
| -rw-r--r-- | lib/random.moon | 2 | ||||
| -rw-r--r-- | lib/sc.moon | 41 | ||||
| -rw-r--r-- | lib/string.moon | 2 | ||||
| -rw-r--r-- | lib/time.moon | 2 | ||||
| -rw-r--r-- | lib/util.moon | 2 |
46 files changed, 238 insertions, 133 deletions
@@ -1,7 +1,7 @@ MODULES=$(wildcard lib/*.moon) lib/midi/launchctl.moon MODREFS=$(MODULES:lib/%.moon=docs/reference/%.html) -CORE=$(wildcard core/*.moon core/**/*.moon) $(wildcard core/*.md) -DEPS=core/version.moon extra/docs.moon extra/layout.moon extra/dom.moon +CORE=$(wildcard alv/*.moon alv/**/*.moon) $(wildcard alv/*.md) +DEPS=alv/version.moon extra/docs.moon extra/layout.moon extra/dom.moon .PHONY: docs reference internals release clean @@ -10,8 +10,8 @@ reference: $(MODREFS) docs/reference/index.html internals: docs/internals/index.html release: - rm -f core/version.moon - extra/git-version.sh >core/version.moon + rm -f alv/version.moon + extra/git-version.sh >alv/version.moon docs/%.html: docs/%.md $(DEPS) @echo "building page $<" @@ -31,8 +31,8 @@ docs/ldoc.css: docs/style.css docs/ldoc.ltp: $(DEPS) moon extra/docs.moon $@ ldoc -docs/internals/index.html: core/config.ld docs/ldoc.ltp docs/ldoc.css $(CORE) - ldoc core +docs/internals/index.html: alv/config.ld docs/ldoc.ltp docs/ldoc.css $(CORE) + ldoc alv clean: rm -rf docs/reference diff --git a/core/ast.moon b/alv/ast.moon index a25d1cd..a25d1cd 100644 --- a/core/ast.moon +++ b/alv/ast.moon diff --git a/core/base/builtin.moon b/alv/base/builtin.moon index fd36c69..fd36c69 100644 --- a/core/base/builtin.moon +++ b/alv/base/builtin.moon diff --git a/core/base/fndef.moon b/alv/base/fndef.moon index b79ad85..b79ad85 100644 --- a/core/base/fndef.moon +++ b/alv/base/fndef.moon diff --git a/core/base/init.moon b/alv/base/init.moon index 9153f79..c37d85c 100644 --- a/core/base/init.moon +++ b/alv/base/init.moon @@ -17,14 +17,14 @@ -- @see Result -- @see Error -import Op from require 'core.base.op' -import Builtin from require 'core.base.builtin' -import FnDef from require 'core.base.fndef' -import Input from require 'core.base.input' -import val, evt from require 'core.base.match' -import ValueStream, EventStream, IOStream from require 'core.stream' -import Result from require 'core.result' -import Error from require 'core.error' +import Op from require 'alv.base.op' +import Builtin from require 'alv.base.builtin' +import FnDef from require 'alv.base.fndef' +import Input from require 'alv.base.input' +import val, evt from require 'alv.base.match' +import ValueStream, EventStream, IOStream from require 'alv.stream' +import Result from require 'alv.result' +import Error from require 'alv.error' { :Op diff --git a/core/base/input.moon b/alv/base/input.moon index bcf188e..19e55a4 100644 --- a/core/base/input.moon +++ b/alv/base/input.moon @@ -2,8 +2,8 @@ -- Update scheduling policy for `Op` arguments. -- -- @classmod Input -import ValueStream, EventStream, IOStream from require 'core.stream' -import Result from require 'core.result' +import ValueStream, EventStream, IOStream from require 'alv.stream' +import Result from require 'alv.result' inherits = (klass, frm) -> assert klass, "cant find the ancestor of nil" diff --git a/core/base/match.moon b/alv/base/match.moon index 700b50d..62075c0 100644 --- a/core/base/match.moon +++ b/alv/base/match.moon @@ -44,8 +44,8 @@ -- -- returns { {key='a', value=1}, {key='b', value=2}, ...} -- -- @module base.match -import Error from require 'core.error' -import ValueStream, EventStream from require 'core.stream' +import Error from require 'alv.error' +import ValueStream, EventStream from require 'alv.stream' local Repeat, Sequence, Choice, Optional diff --git a/core/base/op.moon b/alv/base/op.moon index b0a83dc..b0a83dc 100644 --- a/core/base/op.moon +++ b/alv/base/op.moon diff --git a/core/builtin.moon b/alv/builtin.moon index 68b825c..23412bf 100644 --- a/core/builtin.moon +++ b/alv/builtin.moon @@ -5,13 +5,13 @@ -- documentation. -- -- @module builtin -import Builtin, Op, FnDef, Input, val, evt from require 'core.base' -import ValueStream, LiteralValue from require 'core.stream.value' -import Result from require 'core.result' -import Cell from require 'core.cell' -import Scope from require 'core.scope' -import Tag from require 'core.tag' -import op_invoke from require 'core.invoke' +import Builtin, Op, FnDef, Input, val, evt from require 'alv.base' +import ValueStream, LiteralValue from require 'alv.stream.value' +import Result from require 'alv.result' +import Cell from require 'alv.cell' +import Scope from require 'alv.scope' +import Tag from require 'alv.tag' +import op_invoke from require 'alv.invoke' doc = ValueStream.meta meta: diff --git a/core/cell.moon b/alv/cell.moon index b028f14..f7e9773 100644 --- a/core/cell.moon +++ b/alv/cell.moon @@ -5,10 +5,10 @@ -- nodes), a `Tag`, and optionally the internal whitespace as parsed. -- -- @classmod Cell -import ValueStream from require 'core.stream' -import Error from require 'core.error' -import op_invoke, fn_invoke from require 'core.invoke' -import Tag from require 'core.tag' +import ValueStream from require 'alv.stream' +import Error from require 'alv.error' +import op_invoke, fn_invoke from require 'alv.invoke' +import Tag from require 'alv.tag' local RootCell diff --git a/core/config.ld b/alv/config.ld index f00deba..01160f8 100644 --- a/core/config.ld +++ b/alv/config.ld @@ -12,5 +12,5 @@ If you are looking for the language reference for users, head over to the format = 'discount' style = 'docs' template = 'docs' -topics={'core/extensions.md'} +topics={'alv/extensions.md'} dir = 'docs/internals' diff --git a/copilot.moon b/alv/copilot.moon index 8f98ab6..478cbae 100644 --- a/copilot.moon +++ b/alv/copilot.moon @@ -1,5 +1,13 @@ +---- +-- File watcher and CLI entrypoint. +-- +-- @classmod Copilot lfs = require 'lfs' -import parse, globals, Scope, Error, Registry from require 'core' +import Scope from require 'alv.scope' +import Registry from require 'alv.registry' +import Error from require 'alv.error' +import program from require 'alv.parsing' +globals = Scope.from_table require 'alv.builtin' slurp = (file) -> file = io.open file, 'r' @@ -12,6 +20,12 @@ spit = (file, str) -> file\close! class Copilot +--- static functions +-- @section static + + --- create a new Copilot. + -- @classmethod + -- @tparam string file name/path of the alive file to watch and execute new: (@file) => @registry = Registry! @@ -21,6 +35,10 @@ class Copilot if mode != 'file' error "not a file: #{@file}" +--- members +-- @section members + + --- poll for changes and tick. tick: => @poll! @@ -35,9 +53,9 @@ class Copilot eval: => @registry\begin_eval! - ok, ast = Error.try "parsing '#{@file}'", parse, slurp @file - if not ok - print ast + ok, ast = Error.try "parsing '#{@file}'", program\match, slurp @file + if not (ok and ast) + print ast or Error 'syntax', "failed to parse" @registry\rollback_eval! return diff --git a/core/cycle.moon b/alv/cycle.moon index 57d4a75..f5b7e15 100644 --- a/core/cycle.moon +++ b/alv/cycle.moon @@ -3,12 +3,12 @@ -- this module provides a proxy for resolving values from modules which cannot -- be loaded due to cyclic dependencies. Instead of -- --- import Something from require 'core.somewhere' +-- import Something from require 'alv.somewhere' -- Something ... -- -- use -- --- import somewhere from require 'core.cycle' +-- import somewhere from require 'alv.cycle' -- somewhere.Something ... -- -- Make sure cycle:load() is called before you access or dereference @@ -16,7 +16,7 @@ load = => for name, module in pairs @ - for k, v in pairs require "core.#{name}" + for k, v in pairs require "alv.#{name}" module[k] = v setmetatable {}, __index: (key) => diff --git a/core/error.moon b/alv/error.moon index e72cc5f..e72cc5f 100644 --- a/core/error.moon +++ b/alv/error.moon diff --git a/core/extensions.md b/alv/extensions.md index 6af9bca..82a4d10 100644 --- a/core/extensions.md +++ b/alv/extensions.md @@ -15,7 +15,7 @@ The lua module should return a `Scope` or a table that will be converted using which attaches a `meta` table to the value that is used for error messages, documentation generation and [`(doc)`][builtins-doc]. - import ValueStream from require 'core.base' + import ValueStream from require 'alv.base' two = ValueStream.meta meta: @@ -43,7 +43,7 @@ Most extensions will want to define a number of *Op*s to be used by the user. They are implemented by deriving from the `Op` class and implementing at least the `Op:setup` and `Op:tick` methods. - import ValueStream, Op, Input, evt from require 'core.base' + import ValueStream, Op, Input, evt from require 'alv.base' total_sum = ValueStream.meta meta: @@ -84,7 +84,7 @@ and `base.match.evt` are used to build complex patterns that can parse and validate the Op arguments into complex structures (see the module documentation for more information). - import val, evt from require 'core.base' + import val, evt from require 'alv.base' pattern = evt.bang + val.str + val.num*3 + -evt! { trig, str, numbers, optional } = pattern\match inputs @@ -174,7 +174,7 @@ how their arguments are evaluated. They roughly correspond to *macros* in Lisps. There is less of a concrete guideline for implementing Builtins because there are a lot more options, and it really depends a lot on what the Builtin should achieve. Nevertheless, a good starting point is to read the `Builtin` class -documentation, take a look at `Builtin`s in `core/builtin.moon` and get +documentation, take a look at `Builtin`s in `alv/builtin.moon` and get familiar with the relevant internal interfaces (especially `AST`, `Result`, and `Scope`). @@ -187,7 +187,7 @@ will be necessary. To implement a custom IOStream, create it as a class that inherits from the `IOStream` base and implement the constructor and `IOStream:tick`: - import IOStream from require 'core.base' + import IOStream from require 'alv.base' class UnreliableStream extends IOStream new: => super 'bang' diff --git a/core/init.moon b/alv/init.moon index 6e23fa7..d86cd1f 100644 --- a/core/init.moon +++ b/alv/init.moon @@ -2,22 +2,29 @@ -- `alive` public API. -- -- @module init -L or= setmetatable {}, __index: => -> +if _VERSION == 'Lua 5.1' + export assert + assert = (a, msg, ...) -> + if not a + error msg + a, msg, ... -import ValueStream, EventStream, IOStream from require 'core.stream' -import Result from require 'core.result' -import Scope from require 'core.scope' -import Error from require 'core.error' -import Registry, SimpleRegistry from require 'core.registry' -import Tag from require 'core.tag' +import Logger from require 'alv.logger' +import ValueStream, EventStream, IOStream from require 'alv.stream' +import Result from require 'alv.result' +import Scope from require 'alv.scope' +import Error from require 'alv.error' +import Registry, SimpleRegistry from require 'alv.registry' +import Tag from require 'alv.tag' -import Cell from require 'core.cell' -import cell, program from require 'core.parsing' +import Cell, RootCell from require 'alv.cell' +import program from require 'alv.parsing' -with require 'core.cycle' +with require 'alv.cycle' \load! -globals = Scope.from_table require 'core.builtin' +import Copilot from require 'alv.copilot' +globals = Scope.from_table require 'alv.builtin' --- exports -- @table exports @@ -31,6 +38,8 @@ globals = Scope.from_table require 'core.builtin' -- @tfield Error Error -- @tfield Registry Registry -- @tfield Tag Tag +-- @tfield Copilot Copilot +-- @tfield Logger Logger -- @tfield Scope globals global definitons -- @tfield parse function to turn a `string` into a root `Cell` { @@ -42,6 +51,8 @@ globals = Scope.from_table require 'core.builtin' :globals + :Copilot, :Logger + parse: (str) -> assert (program\match str), Error 'syntax', "failed to parse" diff --git a/core/invoke.moon b/alv/invoke.moon index 8fcb525..6afa57a 100644 --- a/core/invoke.moon +++ b/alv/invoke.moon @@ -2,10 +2,10 @@ -- Builtins for invoking `Op`s and `FnDef`s. -- -- @module invoke -import Result from require 'core.result' -import Builtin from require 'core.base' -import Scope from require 'core.scope' -import Error from require 'core.error' +import Result from require 'alv.result' +import Builtin from require 'alv.base' +import Scope from require 'alv.scope' +import Error from require 'alv.error' get_name = (value, raw) -> meta = if value.meta then value.meta.name diff --git a/logger.moon b/alv/logger.moon index cd41cc8..973e8b5 100644 --- a/logger.moon +++ b/alv/logger.moon @@ -1,5 +1,12 @@ +---- +-- Logger implementation. +-- +-- @classmod Logger unpack or= table.unpack +export L +L or= setmetatable {}, __index: => -> + class Logger levels = { debug: 0 @@ -11,7 +18,31 @@ class Logger silent: 6 } - mklog = (max_level) -> +--- members +-- @section members + + --- push an indentation level and execute a function in it. + -- @tparam function fn the function to execute + -- @param ... parameters to `fn` + push: (fn, ...) => + last = @prefix + @prefix ..= ' ' + + res = { xpcall fn, debug.traceback, ... } + + @prefix = last + + if ok = table.remove res, 1 + unpack res + else + error unpack res + +--- static functions +-- @section static + + --- create a new Logger. + -- @classmethod + -- @tparam string level the log-level to log at. new: (level='log') => @level = levels[level] or level @prefix = '' @@ -30,32 +61,20 @@ class Logger if level == levels.print @push = (fn, ...) => fn ... - push: (fn, ...) => - last = @prefix - @prefix ..= ' ' - - res = { xpcall fn, debug.traceback, ... } - - @prefix = last - - if ok = table.remove res, 1 - unpack res - else - error unpack res - - try: (msg, fn, ...) => - result = { xpcall fn, debug.traceback, ... } - ok = table.remove result, 1 - - if not ok - @error msg, unpack result - return - - unpack result - --- static - init: (...) -> - export L + --- set up the global Logger singleton. + -- + -- The available log-levels are: + -- + -- - `'debug'` + -- - `'trace'` + -- - `'log'` (the default) + -- - `'warn'` + -- - `'error'` + -- - `'print'` + -- - `'silent'` + -- + -- @tparam ?string level the level to initialize the logger at. + @init: (...) -> L = Logger ... { diff --git a/core/parsing.moon b/alv/parsing.moon index aadcab4..f9d6f98 100644 --- a/core/parsing.moon +++ b/alv/parsing.moon @@ -2,9 +2,9 @@ -- Lpeg Grammar for parsing `alive` code. -- -- @module parsing -import ValueStream from require 'core.stream' -import Cell from require 'core.cell' -import Tag from require 'core.tag' +import ValueStream from require 'alv.stream' +import Cell from require 'alv.cell' +import Tag from require 'alv.tag' import R, S, P, V, C, Ct from require 'lpeg' -- whitespace diff --git a/core/registry.moon b/alv/registry.moon index a0134ec..c41e684 100644 --- a/core/registry.moon +++ b/alv/registry.moon @@ -2,8 +2,8 @@ -- `Tag` Registry. -- -- @classmod Registry -import Result from require 'core.result' -import Error from require 'core.error' +import Result from require 'alv.result' +import Error from require 'alv.error' class Registry --- internals for `Tag` diff --git a/core/result.moon b/alv/result.moon index 6c994cb..6c994cb 100644 --- a/core/result.moon +++ b/alv/result.moon diff --git a/core/scope.moon b/alv/scope.moon index 526ca8d..6a0e2a5 100644 --- a/core/scope.moon +++ b/alv/scope.moon @@ -2,9 +2,9 @@ -- Mapping from `sym`s to `Result`s. -- -- @classmod Scope -import ValueStream from require 'core.stream' -import Result from require 'core.result' -import Error from require 'core.error' +import ValueStream from require 'alv.stream' +import Result from require 'alv.result' +import Error from require 'alv.error' class Scope --- members diff --git a/core/stream/base.moon b/alv/stream/base.moon index 37cc8a4..37cc8a4 100644 --- a/core/stream/base.moon +++ b/alv/stream/base.moon diff --git a/core/stream/event.moon b/alv/stream/event.moon index 7712fc4..97570a2 100644 --- a/core/stream/event.moon +++ b/alv/stream/event.moon @@ -2,10 +2,10 @@ -- Stream of momentary events. -- -- @classmod EventStream -import Stream from require 'core.stream.base' -import Result from require 'core.result' -import Error from require 'core.error' -import scope, base, registry from require 'core.cycle' +import Stream from require 'alv.stream.base' +import Result from require 'alv.result' +import Error from require 'alv.error' +import scope, base, registry from require 'alv.cycle' class EventStream extends Stream --- members diff --git a/core/stream/init.moon b/alv/stream/init.moon index 3fff136..f9393b0 100644 --- a/core/stream/init.moon +++ b/alv/stream/init.moon @@ -7,9 +7,9 @@ -- @see IOStream -- -- @module stream -import ValueStream from require 'core.stream.value' -import EventStream from require 'core.stream.event' -import IOStream from require 'core.stream.io' +import ValueStream from require 'alv.stream.value' +import EventStream from require 'alv.stream.event' +import IOStream from require 'alv.stream.io' { :ValueStream diff --git a/core/stream/io.moon b/alv/stream/io.moon index e3e59a2..9b0159c 100644 --- a/core/stream/io.moon +++ b/alv/stream/io.moon @@ -7,7 +7,7 @@ -- updates, which ripple through the `Result` tree. -- -- @classmod IOStream -import EventStream from require 'core.stream.event' +import EventStream from require 'alv.stream.event' class IOStream extends EventStream --- IOStream interface. diff --git a/core/stream/value.moon b/alv/stream/value.moon index 68e16b0..213a26c 100644 --- a/core/stream/value.moon +++ b/alv/stream/value.moon @@ -4,10 +4,10 @@ -- Implements the `Stream` and `AST` intefaces. -- -- @classmod ValueStream -import Stream from require 'core.stream.base' -import Result from require 'core.result' -import Error from require 'core.error' -import scope, base, registry from require 'core.cycle' +import Stream from require 'alv.stream.base' +import Result from require 'alv.result' +import Error from require 'alv.error' +import scope, base, registry from require 'alv.cycle' ancestor = (klass) -> assert klass, "cant find the ancestor of nil" diff --git a/core/tag.moon b/alv/tag.moon index 3c90998..904cd20 100644 --- a/core/tag.moon +++ b/alv/tag.moon @@ -7,7 +7,7 @@ -- - cloned (`[X.Y]`, obtained by cloning Y with parent X) -- -- @classmod Tag -import Registry from require 'core.registry' +import Registry from require 'alv.registry' local ClonedTag diff --git a/core/version.moon b/alv/version.moon index 6cee1b1..6cee1b1 100644 --- a/core/version.moon +++ b/alv/version.moon @@ -1,16 +1,5 @@ -if _VERSION == 'Lua 5.1' - package.path ..= ';./?/init.lua' - package.moonpath ..= ';./?/init.moon' - - export assert - assert = (a, msg, ...) -> - if not a - error msg - a, msg, ... - --- run from CLI -import Logger from require 'logger' -import Copilot from require 'copilot' +#!/usr/bin/env moon +import Copilot, Logger from require 'alv' import sleep from require 'system' arguments, key = {} diff --git a/bin/copilot.bat b/bin/copilot.bat new file mode 100644 index 0000000..58c1bf9 --- /dev/null +++ b/bin/copilot.bat @@ -0,0 +1,6 @@ +@echo off +setlocal +set PATH=%PATH%;%~dp0\lua\lua\bin +set LUA_PATH=%LUA_PATH%;%~dp0\?.lua;%~dp0\alive\?\init.lua +moon %~dp0\init.moon %* +exit /b %ERRORLEVEL% diff --git a/bin/copilot.sh b/bin/copilot.sh new file mode 100755 index 0000000..68e8ebd --- /dev/null +++ b/bin/copilot.sh @@ -0,0 +1,23 @@ +#!/bin/sh +set -e + +tmpdir=$(mktemp -d) +trap 'rm -rf "$tmpdir"' EXIT INT TERM HUP + +ARGS="$@" +FIFO=$tmpdir/fifo +CONF=$tmpdir/conf +LIBDIR=$(dirname $0) +LUA_PATH="$LIBDIR/?.lua;$LIBDIR/?/init.lua;$LUA_PATH" + +cat > "$CONF" << 'EOF' +split +focus +screen -t evaltime sh -c 'tty > "$FIFO"; read done < "$FIFO"' +focus +screen -t runtime sh -c 'read tty < "$FIFO"; moon "$LIBDIR/alv/copilot.moon" $ARGS 2> "$tty"; echo "[press enter to exit]"; read prompt; echo done > "$FIFO"' +EOF + +mkfifo "$FIFO" +export FIFO ARGS LIBDIR LUA_PATH +exec screen -mc "$CONF" diff --git a/extra/docs.moon b/extra/docs.moon index 19c272b..aee7970 100644 --- a/extra/docs.moon +++ b/extra/docs.moon @@ -1,4 +1,4 @@ -import ValueStream, Scope from require 'core' +import ValueStream, Scope from require 'alv' import render, layout, autoref from require 'extra.layout' import section, h1, h2, h3, p, ul, li, a, code, r from require 'extra.dom' @@ -67,7 +67,7 @@ spit OUT, switch command h2 a "builtins", href: '#builtins' p "These definitions are automatically loaded into the global Scope of every alive session." - ul for key, val in opairs require 'core.builtin' + ul for key, val in opairs require 'alv.builtin' li render key, ValueStream.wrap val } } diff --git a/extra/layout.moon b/extra/layout.moon index e64b736..a0d8df1 100644 --- a/extra/layout.moon +++ b/extra/layout.moon @@ -1,4 +1,4 @@ -version = require 'core.version' +version = require 'alv.version' import compile from require 'discount' render_meta = (meta) -> diff --git a/lib/logic.moon b/lib/logic.moon index 27de579..62de1c1 100644 --- a/lib/logic.moon +++ b/lib/logic.moon @@ -1,4 +1,4 @@ -import Op, ValueStream, Input, Error, val from require 'core.base' +import Op, ValueStream, Input, Error, val from require 'alv.base' all_same = (first, list) -> for v in *list diff --git a/lib/math.moon b/lib/math.moon index b2f4ce0..6f5f3fb 100644 --- a/lib/math.moon +++ b/lib/math.moon @@ -1,4 +1,4 @@ -import Op, ValueStream, Error, Input, val from require 'core.base' +import Op, ValueStream, Error, Input, val from require 'alv.base' unpack or= table.unpack class ReduceOp extends Op diff --git a/lib/midi.moon b/lib/midi.moon index 2f3a109..e83b05d 100644 --- a/lib/midi.moon +++ b/lib/midi.moon @@ -1,4 +1,4 @@ -import ValueStream, EventStream, Op, Input, val, evt from require 'core.base' +import ValueStream, EventStream, Op, Input, val, evt from require 'alv.base' import input, output, inout, apply_range from require 'lib.midi.core' gate = ValueStream.meta diff --git a/lib/midi/core.moon b/lib/midi/core.moon index e520bbf..ddb1e8a 100644 --- a/lib/midi/core.moon +++ b/lib/midi/core.moon @@ -1,4 +1,4 @@ -import ValueStream, IOStream, Op, Input, Error, val from require 'core.base' +import ValueStream, IOStream, Op, Input, Error, val from require 'alv.base' import RtMidiIn, RtMidiOut, RtMidi from require 'luartmidi' bit = do diff --git a/lib/midi/launchctl.moon b/lib/midi/launchctl.moon index cbabe5a..42837f0 100644 --- a/lib/midi/launchctl.moon +++ b/lib/midi/launchctl.moon @@ -1,4 +1,4 @@ -import ValueStream, EventStream, Op, Input, val, evt from require 'core.base' +import ValueStream, EventStream, Op, Input, val, evt from require 'alv.base' import apply_range, bit from require 'lib.midi.core' import bor, lshift from bit diff --git a/lib/osc.moon b/lib/osc.moon index 2819e97..b7e25e7 100644 --- a/lib/osc.moon +++ b/lib/osc.moon @@ -1,4 +1,4 @@ -import Op, ValueStream, Input, val, evt from require 'core.base' +import Op, ValueStream, Input, val, evt from require 'alv.base' import pack from require 'osc' import dns, udp from require 'socket' diff --git a/lib/pilot.moon b/lib/pilot.moon index 00d2d3a..0d6eefb 100644 --- a/lib/pilot.moon +++ b/lib/pilot.moon @@ -1,4 +1,4 @@ -import Op, ValueStream, Input, val, evt from require 'core.base' +import Op, ValueStream, Input, val, evt from require 'alv.base' import udp from require 'socket' local conn diff --git a/lib/random.moon b/lib/random.moon index 49da2b9..8c4d096 100644 --- a/lib/random.moon +++ b/lib/random.moon @@ -1,4 +1,4 @@ -import ValueStream, Error, Op, Input, val, evt from require 'core.base' +import ValueStream, Error, Op, Input, val, evt from require 'alv.base' apply_range = (range, val) -> if range\type! == 'str' diff --git a/lib/sc.moon b/lib/sc.moon index c92d4f7..2857392 100644 --- a/lib/sc.moon +++ b/lib/sc.moon @@ -1,4 +1,4 @@ -import Op, ValueStream, Input, val, evt from require 'core.base' +import Op, ValueStream, Input, val, evt from require 'alv.base' import pack from require 'osc' import dns, udp from require 'socket' @@ -39,6 +39,45 @@ Plays the synth `synth` on the `udp/socket` `socket` whenever `trig` is live. msg = pack '/s_new', synth, -1, 0, 1, unpack ctrls socket\send msg +play_ = ValueStream.meta + meta: + name: 'play!' + summary: 'Play a SuperCollider SynthDef on events.' + examples: { '(play [socket] synth [param evt/val…])' } + description: " +Plays the synth `synth` on the `udp/socket` `socket` whenever any `evt` is live. + +- `socket` should be a `udp/socket` value. This argument can be omitted and the + value be passed as a dynamic definition in `*sock*` instead. +- `synth` is the SC synthdef name. It should be a string-value. +- `param` is the name of a synthdef parameter. It should be a string-value. +- `val` and `evt` are the parameter values to send. They should be number + streams. Incoming events will cause a note to be played, while value changes + will not." + value: class extends Op + pattern = -val['udp/socket'] + val.str + (val.str + (val.num / evt.num))\rep 0 + setup: (inputs, scope) => + { socket, synth, trig, ctrls } = pattern\match inputs + + flat = {} + for { key, value } in *ctrls + table.insert flat, Input.cold key + table.insert flat, if value\metatype! == 'event' + Input.hot value + else + Input.cold value + + super + socket: Input.cold socket or scope\get '*sock*' + synth: Input.cold synth + ctrls: flat + + tick: => + { :socket, :synth, :ctrls } = @unwrap_all! + msg = pack '/s_new', synth, -1, 0, 1, unpack ctrls + socket\send msg + { :play + 'play!': play_ } diff --git a/lib/string.moon b/lib/string.moon index 3f9b28b..faa7ab3 100644 --- a/lib/string.moon +++ b/lib/string.moon @@ -1,4 +1,4 @@ -import Op, ValueStream, Input from require 'core.base' +import Op, ValueStream, Input from require 'alv.base' str = ValueStream.meta meta: diff --git a/lib/time.moon b/lib/time.moon index 344b5fa..2589d96 100644 --- a/lib/time.moon +++ b/lib/time.moon @@ -1,7 +1,7 @@ import ValueStream, EventStream, IOStream, Error, Op, Input, val, evt -from require 'core.base' +from require 'alv.base' import monotime from require 'system' class Clock extends IOStream diff --git a/lib/util.moon b/lib/util.moon index d760a64..dc133e4 100644 --- a/lib/util.moon +++ b/lib/util.moon @@ -1,4 +1,4 @@ -import Op, ValueStream, EventStream, Input, val, evt from require 'core.base' +import Op, ValueStream, EventStream, Input, val, evt from require 'alv.base' all_same = (list) -> for v in *list[2,] |
