aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-04-24 20:09:39 +0000
committers-ol <s-ol@users.noreply.github.com>2020-04-24 20:09:39 +0000
commitd5e0b45649c755de98b78cbb0488483af2d270db (patch)
treeb6a34bd92dee18274e0ba1e8231f8e795d78a0d2
parentremove AST:quote() (diff)
downloadalive-d5e0b45649c755de98b78cbb0488483af2d270db.tar.gz
alive-d5e0b45649c755de98b78cbb0488483af2d270db.zip
code readability
-rw-r--r--alv-lib/midi/core.moon2
-rw-r--r--alv-lib/time.moon3
-rw-r--r--alv/ast.moon2
-rw-r--r--alv/base/input.moon5
-rw-r--r--alv/cell.moon2
-rw-r--r--alv/copilot.moon2
-rw-r--r--alv/extensions.md8
-rw-r--r--alv/invoke.moon17
-rw-r--r--alv/registry.moon17
-rw-r--r--alv/result.moon10
-rw-r--r--alv/stream/io.moon4
-rw-r--r--spec/result_spec.moon8
12 files changed, 40 insertions, 40 deletions
diff --git a/alv-lib/midi/core.moon b/alv-lib/midi/core.moon
index ddb1e8a..3adc401 100644
--- a/alv-lib/midi/core.moon
+++ b/alv-lib/midi/core.moon
@@ -37,7 +37,7 @@ class MidiPort extends IOStream
@inp = inp and find_port RtMidiIn, inp
@out = out and find_port RtMidiOut, out
- tick: =>
+ poll: =>
return unless @inp
while true
delta, bytes = @inp\getmessage!
diff --git a/alv-lib/time.moon b/alv-lib/time.moon
index 2589d96..ba7aa4a 100644
--- a/alv-lib/time.moon
+++ b/alv-lib/time.moon
@@ -11,9 +11,8 @@ class Clock extends IOStream
return unless monotime
@last = monotime!
@dt = 0
- @is_dirty = false
- tick: =>
+ poll: =>
time = monotime!
@dt = time - @last
if @dt >= @frametime
diff --git a/alv/ast.moon b/alv/ast.moon
index 044e330..7090869 100644
--- a/alv/ast.moon
+++ b/alv/ast.moon
@@ -1,7 +1,7 @@
----
-- AST Node Interface.
--
--- implemented by `Value` and `Cell`.
+-- implemented by `ValueStream` and `Cell`.
--
-- @classmod AST
diff --git a/alv/base/input.moon b/alv/base/input.moon
index 19e55a4..fe01f88 100644
--- a/alv/base/input.moon
+++ b/alv/base/input.moon
@@ -108,8 +108,9 @@ class Input
--
-- Behaviour depends on what kind of `Stream` `value` is:
--
- -- - `ValueStream`: Marked dirty for the eval-tick if old and new `ValueStream` differ.
- -- - `EventStream` and `IOStream`: Marked dirty only if the current `EventStream` is dirty.
+ -- - `ValueStream`: Marked dirty only if old and new `ValueStream` differ.
+ -- - `EventStream` and `IOStream`: Marked dirty only if the current
+ -- `EventStream` is dirty.
--
-- This is the most common `Input` strategy.
--
diff --git a/alv/cell.moon b/alv/cell.moon
index e9125d5..6d5e207 100644
--- a/alv/cell.moon
+++ b/alv/cell.moon
@@ -74,10 +74,8 @@ class Cell
head = (head\eval scope)\const!
Builtin = switch head.type
when 'opdef'
- -- scope\get 'op-invoke'
op_invoke
when 'fndef'
- -- scope\get 'fn-invoke'
fn_invoke
when 'builtin'
head\unwrap!
diff --git a/alv/copilot.moon b/alv/copilot.moon
index 0a9051f..1f612a3 100644
--- a/alv/copilot.moon
+++ b/alv/copilot.moon
@@ -68,7 +68,7 @@ class Copilot
if root and root.root
L\set_time 'run'
ok, error = Error.try "updating", ->
- root.root\tick_io!
+ root.root\poll_io!
root.root\tick!
if not ok
L\print error
diff --git a/alv/extensions.md b/alv/extensions.md
index 89d1a89..3dd38f9 100644
--- a/alv/extensions.md
+++ b/alv/extensions.md
@@ -156,7 +156,7 @@ There are three types of `Stream`s that can be created:
- `EventStream`s transmit *momentary events*. They can transmit multiple events
in a single tick. `EventStream`s do not keep a value set on the last tick on
the next tick. They are updated using `EventStream:add`.
-- `IOStream`s are like `EventStream`s, but their `IOStream:tick` method is
+- `IOStream`s are like `EventStream`s, but their `IOStream:poll` method is
polled by the event loop at the start of every tick. This gives them a chance
to effectively create changes 'out of thin air' and kickstart the execution
of the dataflow engine. All *runtime* execution is due to an `IOStream`
@@ -185,14 +185,14 @@ bring events into alive from an external protocol or application, an IOStream
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`:
+`IOStream` base and implement the constructor and `IOStream:poll`:
import IOStream from require 'alv.base'
class UnreliableStream extends IOStream
new: => super 'bang'
- tick: =>
+ poll: =>
if math.random! < 0.1
@add true
@@ -200,7 +200,7 @@ In the constructor, you should call the super-constructor `EventStream.new` to
set the event type. Often this will be a custom event that is only used inside
your extension (such as e.g. the `midi/port` type in the [midi][modules-midi]
module), but it can also be a primitive type like `'num'` in this example. In
-`:tick`, your IOStream is given a chance to communicate with the external world
+`:poll`, your IOStream is given a chance to communicate with the external world
and create any resulting events. The example stream above randomly sends bang
events out, with a 10% chance each 'tick' of the system. Note that there is no
guarantee about when or how often ticks occur, so you really shouldn't rely on
diff --git a/alv/invoke.moon b/alv/invoke.moon
index 6afa57a..fba6485 100644
--- a/alv/invoke.moon
+++ b/alv/invoke.moon
@@ -41,7 +41,7 @@ class op_invoke extends Builtin
-- calls `op`:@{Op:destroy|destroy}.
destroy: => @op\destroy!
- --- evaluate an `Op` invocation.
+ --- perform an `Op` invocation.
--
-- `AST:eval`s the tail, and passes the result to `op`:@{Op:setup|setup}. Then
-- checks if any of `op`:@{Op:all_inputs|all_inputs} are @{Input:dirty|dirty},
@@ -83,8 +83,8 @@ class fn_invoke extends Builtin
--- evaluate a user-function invocation.
--
-- Creates a new `Scope` that inherits from `FnDef.scope` and has
- -- `outer_scope` as an additional parent for dynamic symbol resolution.
- -- Then `AST:eval`s the tail in `outer_scope`, and defines the results to the
+ -- `caller_scope` as an additional parent for dynamic symbol resolution.
+ -- Then `AST:eval`s the tail in `caller_scope`, and defines the results to the
-- names in `FnDef.params` in the newly created scope. Lastly, `AST:clone`s
-- `FnDef.body` with the prefix `Builtin.tag`, and `AST:eval`s it in the newly
-- created `Scope`.
@@ -93,24 +93,25 @@ class fn_invoke extends Builtin
-- are all the `Result`s from evaluating the tail as well as the cloned
-- `AST`s.
--
- -- @tparam Scope outer_scope the active scope
+ -- @tparam Scope caller_scope the active scope
-- @tparam {AST,...} tail the arguments to this expression
-- @treturn Result the result of this evaluation
- eval: (outer_scope, tail) =>
+ eval: (caller_scope, tail) =>
name = get_name @head, @cell\head!
frame = "invoking function #{name} at [#{@tag}]"
- { :params, :body, :scope } = @head\unwrap 'fndef', "cant fn-invoke #{@head}"
+ fndef = @head\unwrap 'fndef', "cant fn-invoke #{@head}"
+ { :params, :body } = fndef
if #params != #tail
err = Error 'argument', "expected #{#params} arguments, found #{#tail}"
err\add_frame frame
error err
- fn_scope = Scope scope, outer_scope
+ fn_scope = Scope fndef.scope, caller_scope
children = for i=1,#params
name = params[i]\unwrap 'sym'
- with L\push tail[i]\eval, outer_scope
+ with L\push tail[i]\eval, caller_scope
fn_scope\set name, \make_ref!
clone = body\clone @tag
diff --git a/alv/registry.moon b/alv/registry.moon
index ba35a18..d4dcccc 100644
--- a/alv/registry.moon
+++ b/alv/registry.moon
@@ -23,15 +23,16 @@ class Registry
register: (tag, expr, ignore_dup=false) =>
index = tag\index!
- if index and (not @map[index] or ignore_dup)
- L\trace "reg: setting #{index} to #{expr}"
- @map[index] = expr
- else
- if index
- L\warn "duplicate tag [#{index}], reassigning repeated occurance"
- tag\set nil
+ if index
+ if not @map[index] or ignore_dup
+ L\trace "reg: setting #{index} to #{expr}"
+ @map[index] = expr
else
- L\trace "reg: init #{tag} to #{expr}"
+ L\warn "duplicate tag [#{index}], reassigning repeated occurrence"
+ tag\set nil
+ table.insert @pending, { :tag, :expr }
+ else
+ L\trace "reg: init #{tag} to #{expr}"
table.insert @pending, { :tag, :expr }
--- members
diff --git a/alv/result.moon b/alv/result.moon
index 6c994cb..6f5ea28 100644
--- a/alv/result.moon
+++ b/alv/result.moon
@@ -38,11 +38,11 @@ class Result
with Result value: @value
.side_inputs = @side_inputs
- --- tick all IOStream instances that are effecting this (sub)tree.
+ --- poll all IOStream instances that are effecting this (sub)tree.
-- should be called once per frame on the root, right before tick.
- tick_io: =>
+ poll_io: =>
for stream, input in pairs @side_inputs
- stream\tick! if input.io
+ stream\poll! if input.io
--- in depth-first order, tick all Ops which have dirty Inputs.
--
@@ -64,8 +64,8 @@ class Result
-- we have to check self_dirty here, because Inputs from children may
-- have become dirty due to \tick
self_dirty = false
- for stream in @op\all_inputs!
- if stream\dirty!
+ for input in @op\all_inputs!
+ if input\dirty!
self_dirty = true
return unless self_dirty
diff --git a/alv/stream/io.moon b/alv/stream/io.moon
index 9b0159c..e17daa8 100644
--- a/alv/stream/io.moon
+++ b/alv/stream/io.moon
@@ -34,13 +34,13 @@ class IOStream extends EventStream
--- poll for changes.
--
-- Called every frame by the main event loop to update internal state.
- tick: =>
+ poll: =>
--- check whether this adapter requires processing.
--
-- Must return a boolean indicating whether `Op`s that refer to this instance
-- via `Input.hot` should be notified (via `Op:tick`). May be called multiple
- -- times. May be called before `tick` on the first frame after construction.
+ -- times. May be called before `poll` on the first frame after construction.
--
-- If this is not overrided, the `EventStream` interface can be used, see
-- `EventStream.add`, `EventStream.unwrap`, and `EventStream.dirty`.
diff --git a/spec/result_spec.moon b/spec/result_spec.moon
index c254b42..be60677 100644
--- a/spec/result_spec.moon
+++ b/spec/result_spec.moon
@@ -170,15 +170,15 @@ describe 'Result', ->
assert.spy(s).was_not_called!
- describe ':tick_io', ->
- it 'ticks IOs referenced in side_inputs', ->
+ describe ':poll_io', ->
+ it 'polls IOs referenced in side_inputs', ->
io = DirtyIO!
input = Input.hot io
op = op_with_inputs { input }
result = Result :op
- s = spy.on io, 'tick'
+ s = spy.on io, 'poll'
assert.is.same { [io]: input }, result.side_inputs
- result\tick_io!
+ result\poll_io!
assert.spy(s).was_called_with match.ref io