aboutsummaryrefslogtreecommitdiffstats
path: root/core/base.moon
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-02-19 21:17:46 +0000
committers-ol <s-ol@users.noreply.github.com>2020-02-19 21:17:53 +0000
commite62ef99244bb3aa906810a5cfd53c0dac68b0f37 (patch)
treee7379e2add7014e7124f678f4a7a8edc699fe914 /core/base.moon
parentmajor refactoring: Const, Stream + ResultNode (diff)
downloadalive-e62ef99244bb3aa906810a5cfd53c0dac68b0f37.tar.gz
alive-e62ef99244bb3aa906810a5cfd53c0dac68b0f37.zip
merge Const and Stream into Value; Dataflow logic
lib not fully ported / functonial
Diffstat (limited to 'core/base.moon')
-rw-r--r--core/base.moon37
1 files changed, 32 insertions, 5 deletions
diff --git a/core/base.moon b/core/base.moon
index 1b1be5d..60ee460 100644
--- a/core/base.moon
+++ b/core/base.moon
@@ -1,21 +1,47 @@
-- base definitions for extensions
+import Value from require 'core.value'
+
+unpack or= table.unpack
-- a persistent expression Operator
--
-- accepts Const or Stream inputs and produces a Stream output
class Op
- update: (dt) =>
+ new: (type, init) =>
+ @impulses = {}
+
+ if type
+ @out = Value type, init
+
+ -- (re)-initialize this Op with the given inputs
+ -- after this method finishes, :tick(true) is called once, after which
+ -- @impulses and @out have to be set and may not change until :setup()
+ -- is called again.
+ setup: (@inputs) =>
- -- set @out to a Value (Const or Stream)
- setup: (...) =>
+ -- called once per frame if any inputs or impulses are dirty, and once
+ -- immediately after :setup(). 'first' will be true in the latter case.
+ -- Should update @out.
+ tick: (first) =>
+ -- called once when the Op is destroyed
destroy: =>
+-- utilities
+ unwrap_inputs: =>
+ unpack [input! for input in *@inputs]
+
+ assert_types: (...) =>
+ num = select '#', ...
+ assert #@inputs >= num, "argument count mismatch"
+ for i = 1, num
+ expect = select i, ...
+ assert @inputs[i].type == expect, "expected argument #{i} of #{@} to be of type #{expect} but found #{@inputs[i]}"
+
-- static
__tostring: => "<op: #{@@__name}>"
__inherited: (cls) => cls.__base.__tostring = @__tostring
-
-- a builtin / special form / cell-evaluation strategy
--
-- responsible for quoting/evaluating subexpressions,
@@ -51,7 +77,7 @@ class Action
-- static
-- find & patch the action for the expression with Tag 'tag' if it exists,
-- and is compatible with the new Cell contents, otherwise instantiate it.
- -- register the action with the tag, evaluate it and return the ResultNode
+ -- register the action with the tag, evaluate it and return the Result
@eval_cell: (scope, tag, head, tail) =>
last = tag\last!
compatible = last and
@@ -93,6 +119,7 @@ class FnDef
"(fn (#{table.concat [p\stringify! for p in *@params], ' '}) ...)"
{
+ :Dispatcher
:Op
:Action
:FnDef