aboutsummaryrefslogtreecommitdiffstats
path: root/alv/base
diff options
context:
space:
mode:
Diffstat (limited to 'alv/base')
-rw-r--r--alv/base/init.moon15
-rw-r--r--alv/base/input.moon27
-rw-r--r--alv/base/match.moon29
3 files changed, 37 insertions, 34 deletions
diff --git a/alv/base/init.moon b/alv/base/init.moon
index c37d85c..71e9cea 100644
--- a/alv/base/init.moon
+++ b/alv/base/init.moon
@@ -11,10 +11,11 @@
-- @see Input
-- @see base.match.val
-- @see base.match.evt
--- @see ValueStream
--- @see EventStream
+-- @see Constant
+-- @see SigStream
+-- @see EvtStream
-- @see IOStream
--- @see Result
+-- @see RTNode
-- @see Error
import Op from require 'alv.base.op'
@@ -22,8 +23,8 @@ 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 Constant, SigStream, EvtStream, IOStream from require 'alv.result'
+import RTNode from require 'alv.rtnode'
import Error from require 'alv.error'
{
@@ -34,6 +35,6 @@ import Error from require 'alv.error'
:val, :evt
-- redundant exports, to keep anything an extension might need in one import
- :ValueStream, :EventStream, :IOStream
- :Result, :Error
+ :Constant, :SigStream, :EvtStream, :IOStream
+ :RTNode, :Error
}
diff --git a/alv/base/input.moon b/alv/base/input.moon
index fe01f88..dea91c9 100644
--- a/alv/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 'alv.stream'
-import Result from require 'alv.result'
+import Constant, SigStream, EvtStream, IOStream from require 'alv.result'
+import RTNode from require 'alv.rtnode'
inherits = (klass, frm) ->
assert klass, "cant find the ancestor of nil"
@@ -53,7 +53,7 @@ class Input
--
-- must return a boolean indicating whether `Op`s that refer to this instance
-- should be notified (via `Op:tick`). If not overwritten, delegates to
- -- `stream`:@{ValueStream:dirty|dirty}.
+ -- `stream`:@{SigStream:dirty|dirty}.
--
-- @treturn bool whether processing is necessary
dirty: => @stream\dirty!
@@ -77,7 +77,7 @@ class Input
--- the current value
--
- -- @tfield ValueStream stream
+ -- @tfield SigStream stream
--- members
-- @section members
@@ -98,9 +98,9 @@ class Input
-- Never marked dirty. Use this for input streams that are only read when
-- another `Input` is dirty.
--
- -- @tparam Stream|Result value
+ -- @tparam Stream|RTNode value
@cold: (value) ->
- if value.__class == Result
+ if value.__class == RTNode
value = assert value.value, "Input from result without value!"
ColdInput value
@@ -108,15 +108,15 @@ class Input
--
-- Behaviour depends on what kind of `Stream` `value` is:
--
- -- - `ValueStream`: Marked dirty only if old and new `ValueStream` differ.
- -- - `EventStream` and `IOStream`: Marked dirty only if the current
- -- `EventStream` is dirty.
+ -- - `SigStream`: Marked dirty only if old and new `SigStream` differ.
+ -- - `EvtStream` and `IOStream`: Marked dirty only if the current
+ -- `EvtStream` is dirty.
--
-- This is the most common `Input` strategy.
--
- -- @tparam Stream|Result value
+ -- @tparam Stream|RTNode value
@hot: (value) ->
- if value.__class == Result
+ if value.__class == RTNode
value = assert value.value, "Input from result without value!"
InputType = match_parent value, mapping
@@ -137,8 +137,9 @@ class IOInput extends Input
io: true
mapping = {
- [ValueStream]: ValueInput
- [EventStream]: Input
+ [Constant]: ColdInput
+ [SigStream]: ValueInput
+ [EvtStream]: Input
[IOStream]: IOInput
}
diff --git a/alv/base/match.moon b/alv/base/match.moon
index 62075c0..819b0b4 100644
--- a/alv/base/match.moon
+++ b/alv/base/match.moon
@@ -2,7 +2,7 @@
--- Pattern capturing for Op argument parsing.
--
-- There is only one basic buildings block for assembling patterns:
--- `Type`. It can match `ValueStream`s and `EventStream`s depending on its
+-- `Type`. It can match `SigStream`s and `EvtStream`s depending on its
-- metatype argument and can take an optional type name to match as an argument.
--
-- In addition to this primitive, the following modifiers are available:
@@ -21,12 +21,12 @@
-- - `-pat`: Shorthand for `Optional(pat)`
--
-- To perform the actual matching, call the `:match` method on a pattern and
--- pass a sequence of `Result`s. The method will either return the captured
--- `Result`s (or a table structuring them)
+-- pass a sequence of `RTNode`s. The method will either return the captured
+-- `RTNode`s (or a table structuring them)
--
-- Any ambiguous pattern can be set to 'recall mode' by invoking it.
--- Recalling patterns will memorize the first Result they match, and
--- only match further Results of the same type. For example
+-- Recalling patterns will memorize the first RTNode they match, and
+-- only match further RTNodes of the same type. For example
--
-- arg = (val.num / val.str)!
-- pattern = arg + arg
@@ -45,14 +45,11 @@
--
-- @module base.match
import Error from require 'alv.error'
-import ValueStream, EventStream from require 'alv.stream'
+import Primitive from require 'alv.types'
local Repeat, Sequence, Choice, Optional
-typestr = (result) ->
- str = result\type!
- str ..= '!' if result\metatype! == 'event'
- str
+typestr = (result) -> tostring result.value
class Pattern
match: (seq) =>
@@ -107,13 +104,17 @@ class Type extends Pattern
capture: (seq, i) =>
return unless seq[i]
type, mt = seq[i]\type!, seq[i]\metatype!
- return unless @metatype == mt
+ if @metatype == 'event'
+ return unless mt == '!'
+ else
+ return if mt == '!'
+
match = if @type then type == @type else @remember type
if match
1, seq[i]
__tostring: =>
- str = @type or @metatype
+ str = tostring @type or @metatype
str ..= '!' if @metatype == 'event'
str
@@ -272,7 +273,7 @@ class Optional extends Pattern
-- @table val
val = setmetatable {}, {
__index: (key) =>
- with v = Type 'value', key
+ with v = Type 'value', Primitive key
@[key] = v
__call: (...) => Type 'value', ...
@@ -290,7 +291,7 @@ val = setmetatable {}, {
-- @table evt
evt = setmetatable {}, {
__index: (key) =>
- with v = Type 'event', key
+ with v = Type 'event', Primitive key
@[key] = v
__call: (...) => Type 'event', ...