diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-05-08 11:41:56 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2025-03-02 14:23:21 +0000 |
| commit | bec1ebf1209c5a56ad4208d820222cb497b5f98c (patch) | |
| tree | 0663fbbd99d580b55b7aa611b415afd946b738bb /alv | |
| parent | fix docs (diff) | |
| download | alive-bec1ebf1209c5a56ad4208d820222cb497b5f98c.tar.gz alive-bec1ebf1209c5a56ad4208d820222cb497b5f98c.zip | |
rename RTNode.value to RTNode.result (to match Result class)
Diffstat (limited to 'alv')
| -rw-r--r-- | alv/ast.moon | 4 | ||||
| -rw-r--r-- | alv/base/builtin.moon | 6 | ||||
| -rw-r--r-- | alv/base/input.moon | 13 | ||||
| -rw-r--r-- | alv/base/match.moon | 10 | ||||
| -rw-r--r-- | alv/base/op.moon | 14 | ||||
| -rw-r--r-- | alv/builtin.moon | 42 | ||||
| -rw-r--r-- | alv/cell.moon | 2 | ||||
| -rw-r--r-- | alv/copilot.moon | 2 | ||||
| -rw-r--r-- | alv/invoke.moon | 10 | ||||
| -rw-r--r-- | alv/module.moon | 4 | ||||
| -rw-r--r-- | alv/registry.moon | 2 | ||||
| -rw-r--r-- | alv/result/base.moon | 44 | ||||
| -rw-r--r-- | alv/result/const.moon | 27 | ||||
| -rw-r--r-- | alv/result/evt.moon | 63 | ||||
| -rw-r--r-- | alv/result/init.moon | 6 | ||||
| -rw-r--r-- | alv/result/sig.moon | 60 | ||||
| -rw-r--r-- | alv/rtnode.moon | 49 | ||||
| -rw-r--r-- | alv/scope.moon | 8 |
18 files changed, 170 insertions, 196 deletions
diff --git a/alv/ast.moon b/alv/ast.moon index cff8947..b8c14e6 100644 --- a/alv/ast.moon +++ b/alv/ast.moon @@ -10,11 +10,11 @@ --- evaluate this AST Node. -- - -- Evaluate this node and return a `Result`. + -- Evaluate this node and return a `RTNode`. -- -- @function eval -- @tparam Scope scope the scope to evaluate in - -- @treturn Result the evaluation result + -- @treturn RTNode the evaluation result --- create a clone with its own identity. -- diff --git a/alv/base/builtin.moon b/alv/base/builtin.moon index f675207..5f46f37 100644 --- a/alv/base/builtin.moon +++ b/alv/base/builtin.moon @@ -31,7 +31,7 @@ class Builtin -- -- @tparam Scope scope the active scope -- @tparam {AST,...} tail the arguments to this expression - -- @treturn Result the result of this evaluation + -- @treturn RTNode the result of this evaluation eval: (scope, tail) => error "not implemented" --- free resources @@ -62,12 +62,12 @@ class Builtin -- Create a new instance using `tag` and `head` and call `setup` on it. -- If a previous instance with the same `tag` exists and has the same `head`, -- it pass it to `setup`. Register the `Builtin` with `tag`, evaluate it - -- and return the `Result`. + -- and return the `RTNode`. -- -- @tparam Cell cell the `Cell` being evaluated -- @tparam Scope scope the active scope -- @tparam Value head the (`AST:eval`d) head of the `Cell` being evaluated - -- @treturn Result the result of evaluation + -- @treturn RTNode the result of evaluation @eval_cell: (cell, scope, head) => last = cell.tag\last! compatible = last and (last.__class == @) and last.head == head diff --git a/alv/base/input.moon b/alv/base/input.moon index dea91c9..a9f0e32 100644 --- a/alv/base/input.moon +++ b/alv/base/input.moon @@ -35,7 +35,7 @@ class Input --- create a new Input. -- -- @classmethod - -- @tparam Stream stream + -- @tparam Result stream new: (@stream) => assert @stream, "nil passed to Input: #{value}" @@ -98,26 +98,27 @@ class Input -- Never marked dirty. Use this for input streams that are only read when -- another `Input` is dirty. -- - -- @tparam Stream|RTNode value + -- @tparam Result|RTNode value @cold: (value) -> if value.__class == RTNode - value = assert value.value, "Input from result without value!" + value = assert value.result, "Input from node without result!" ColdInput value --- Create a `hot` `Input`. -- - -- Behaviour depends on what kind of `Stream` `value` is: + -- Behaviour depends on what kind of `Result` `value` is: -- + -- - `Constant`: treated like `cold`. -- - `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|RTNode value + -- @tparam Result|RTNode value @hot: (value) -> if value.__class == RTNode - value = assert value.value, "Input from result without value!" + value = assert value.result, "Input from node without result!" InputType = match_parent value, mapping assert InputType, "Input from unknown value: #{value}" diff --git a/alv/base/match.moon b/alv/base/match.moon index 3a2b3d5..926c970 100644 --- a/alv/base/match.moon +++ b/alv/base/match.moon @@ -49,14 +49,12 @@ import Primitive from require 'alv.type' local Repeat, Sequence, Choice, Optional -typestr = (result) -> tostring result.value - class Pattern match: (seq) => @reset! num, cap = @capture seq, 1 if num != #seq - args = table.concat [typestr arg for arg in *seq], ' ' + args = table.concat [arg.result\fulltype! for arg in *seq], ' ' msg = "couldn't match arguments (#{args}) against pattern #{@}" error Error 'argument', msg cap @@ -86,15 +84,15 @@ class Pattern cls.__base.__div or= @__div cls.__base.__unm or= @__unm ---- Base Stream Pattern. +--- Base Result Pattern. -- --- When instantiated with `type`, only succeeds for `Stream`s whose value and +-- When instantiated with `type`, only succeeds for `Result`s whose value and -- meta types match. -- -- Otherwise, matches Streams based only on `metatype` for the first match, but -- using both afterwards (recall mode). -- --- @function Stream +-- @function Type -- @tparam string metatype "value" or "event" -- @tparam ?string type type name class Type extends Pattern diff --git a/alv/base/op.moon b/alv/base/op.moon index b0a83dc..da90288 100644 --- a/alv/base/op.moon +++ b/alv/base/op.moon @@ -46,9 +46,9 @@ class Op -- -- @tfield table state - --- `Stream` instance representing this Op's computed output value. + --- `Result` instance representing this Op's computed output value. -- - -- Must be set to a `Stream` instance once `setup` finishes. Must not change + -- Must be set to a `Result` instance once `setup` finishes. Must not change -- type, be removed or replaced outside of `new` and `setup`. If it is a -- `ValueStream`, it should have a value assigned via `set` or the -- constructor once `tick` is called the first time. If `out`'s value is not @@ -56,7 +56,7 @@ class Op -- `tick``(true)` is called at least on the first eval-cycle the Op goes -- through, e.g. by using an `Input.hot` with a `ValueStream`. -- - -- @tfield Stream out + -- @tfield Result out --- table containing `Input`s to this Op. -- @@ -79,18 +79,18 @@ class Op -- -- @function new -- @classmethod - -- @tparam ?Stream out `out` + -- @tparam ?Result out `out` -- @tparam ?table state `state` --- parse arguments and patch self. -- - -- Called once every eval-cycle. `inputs` is a list of `Result`s that are the + -- Called once every eval-cycle. `inputs` is a list of `RTNode`s that are the -- argument to this op. The `inputs` have to be wrapped in `Input` instances -- to define update behaviour. Use `base.match` to parse them, then delegate to -- `super:setup` to patch the `Input` instances. -- -- @function setup - -- @tparam {Result,...} inputs a sequence of `Result`s + -- @tparam {RTNode,...} inputs a sequence of `RTNode`s -- @tparam Scope scope the active scope --- handle incoming events and update `out` (optional). @@ -120,7 +120,7 @@ class Op -- type is not known at this time. -- -- @classmethod - -- @tparam ?Stream out `out` + -- @tparam ?Result out `out` -- @tparam ?table state `state` new: (@out, @state) => diff --git a/alv/builtin.moon b/alv/builtin.moon index 58a1ecc..740da25 100644 --- a/alv/builtin.moon +++ b/alv/builtin.moon @@ -35,9 +35,9 @@ doc = Constant.meta eval: (scope, tail) => assert #tail == 1, "'doc' takes exactly one parameter" - result = L\push tail[1]\eval, scope + node = L\push tail[1]\eval, scope with RTNode children: { def } - meta = result.value.meta + meta = node.result.meta L\print "(doc #{tail[1]}):\n#{format_meta meta}\n" def = Constant.meta @@ -78,8 +78,8 @@ All arguments have to be evaltime constant." eval: (scope, tail) => L\trace "evaling #{@}" for child in *tail - result = L\push child\eval, scope - value = result\const! + node = L\push child\eval, scope + value = node\const! scope\use value\unwrap 'scope', "'use' only works on scopes" RTNode! @@ -96,8 +96,8 @@ require_ = Constant.meta L\trace "evaling #{@}" assert #tail == 1, "'require' takes exactly one parameter" - result = L\push tail[1]\eval, scope - name = result\const!\unwrap 'str' + node = L\push tail[1]\eval, scope + name = node\const!\unwrap 'str' L\trace @, "loading module #{name}" COPILOT\require name @@ -148,11 +148,11 @@ export_ = Constant.meta description: " Evaluate `expr1`, `expr2`, … in a new Scope and return scope." - value: class extends Builtin + value: class extends Builtin eval: (scope, tail) => new_scope = Scope scope children = [expr\eval new_scope for expr in *tail] - RTNode :children, value: Constant.wrap new_scope + RTNode :children, result: Constant.wrap new_scope export_star = Constant.meta meta: @@ -170,16 +170,16 @@ Copies the containing scope if no symbols are given." new_scope = Scope! children = if #tail == 0 - for k,result in pairs scope.values - new_scope\set k, result - result + for k,node in pairs scope.values + new_scope\set k, node + node else for child in *tail name = child\unwrap 'sym' - with result = scope\get name - new_scope\set name, result + with node = scope\get name + new_scope\set name, node - RTNode :children, value: Constant.wrap new_scope + RTNode :children, result: Constant.wrap new_scope fn = Constant.meta meta: @@ -201,7 +201,7 @@ function is invoked." assert param.type == 'sym', "function parameter declaration has to be a symbol" param - RTNode value: with Constant.wrap FnDef param_symbols, body, scope + RTNode result: with Constant.wrap FnDef param_symbols, body, scope .meta = { summary: "(user defined function)" examples: { "(??? #{table.concat [p! for p in *param_symbols], ' '})" } @@ -229,13 +229,13 @@ function is invoked." assert param.type == 'sym', "function parameter declaration has to be a symbol" param - value = with Constant.wrap FnDef param_symbols, body, scope + result = with Constant.wrap FnDef param_symbols, body, scope .meta = :name summary: "(user defined function)" examples: { "(#{name} #{table.concat [p! for p in *param_symbols], ' '})" } - scope\set name, RTNode :value + scope\set name, RTNode :result RTNode! do_expr = Constant.meta @@ -246,11 +246,11 @@ do_expr = Constant.meta description: " Evaluate `expr1`, `expr2`, … and return the value of the last expression." - value: class extends Builtin + value: class extends Builtin eval: (scope, tail) => scope = Scope scope children = [expr\eval scope for expr in *tail] - RTNode :children, value: children[#children].value + RTNode :children, result: children[#children].result if_ = Constant.meta meta: @@ -288,8 +288,8 @@ trace_ = Constant.meta L\trace "evaling #{@}" assert #tail == 1, "'trace!' takes exactly one parameter" - with result = L\push tail[1]\eval, scope - L\print "trace! #{tail[1]\stringify!}: #{result.value}" + with node = L\push tail[1]\eval, scope + L\print "trace! #{tail[1]\stringify!}: #{node.result}" trace = Constant.meta meta: diff --git a/alv/cell.moon b/alv/cell.moon index 933d292..a61f8de 100644 --- a/alv/cell.moon +++ b/alv/cell.moon @@ -69,7 +69,7 @@ class Cell -- then calls `Builtin:eval_cell` on it. -- -- @tparam Scope scope the scope to evaluate in - -- @treturn Result the evaluation result + -- @treturn RTNode the evaluation result eval: (scope) => head = assert @head!, Error 'syntax', "cannot evaluate empty expr" head = (head\eval scope)\const! diff --git a/alv/copilot.moon b/alv/copilot.moon index d9b674f..55e00c8 100644 --- a/alv/copilot.moon +++ b/alv/copilot.moon @@ -46,7 +46,7 @@ class Copilot Error.wrap "loading module '#{name}'", -> ok, lua = pcall require, "alv-lib.#{name}" if ok - RTNode value: Constant.wrap lua + RTNode result: Constant.wrap lua else assert @modules, "no current eval cycle?" if mod = @modules[name] diff --git a/alv/invoke.moon b/alv/invoke.moon index 03cf08e..0629b59 100644 --- a/alv/invoke.moon +++ b/alv/invoke.moon @@ -64,7 +64,7 @@ class op_invoke extends Builtin children = [L\push expr\eval, scope for expr in *tail] frame = "invoking op #{get_name @head, @cell\head!} at [#{@tag}]" - Error.wrap frame, @op\setup, [result for result in *children], scope + Error.wrap frame, @op\setup, [node for node in *children], scope any_dirty = false for input in @op\all_inputs! @@ -78,7 +78,7 @@ class op_invoke extends Builtin for input in @op\all_inputs! input\finish_setup! - RTNode :children, value: @op.out, op: @op + RTNode :children, result: @op.out, op: @op --- The `Op` instance. -- @@ -123,10 +123,10 @@ class fn_invoke extends Builtin fn_scope\set name, \make_ref! clone = body\clone @tag - result = Error.wrap frame, clone\eval, fn_scope + node = Error.wrap frame, clone\eval, fn_scope - table.insert children, result - RTNode :children, value: result.value + table.insert children, node + RTNode :children, result: node.result { :op_invoke, :fn_invoke diff --git a/alv/module.moon b/alv/module.moon index 8fc3ba7..7179ab6 100644 --- a/alv/module.moon +++ b/alv/module.moon @@ -67,8 +67,8 @@ class Module --- the last updated AST tree for this module. -- @tfield ?AST ast - --- the root Result of this module. - -- @tfield ?Result root + --- the runtime graph root of this module. + -- @tfield ?RTNode root { :Module diff --git a/alv/registry.moon b/alv/registry.moon index 1b24e9a..0d37a5c 100644 --- a/alv/registry.moon +++ b/alv/registry.moon @@ -2,8 +2,6 @@ -- `Tag` Registry. -- -- @classmod Registry -import Result from require 'alv.result' -import Error from require 'alv.error' class Registry --- internals for `Tag` diff --git a/alv/result/base.moon b/alv/result/base.moon index 26af4b4..bbbbeac 100644 --- a/alv/result/base.moon +++ b/alv/result/base.moon @@ -1,55 +1,45 @@ ---- --- base Stream interface. +-- base Result interface. -- -- implemented by `Constant`, `SigStream`, `EvtStream`, and `IOStream`. -- --- @classmod Stream +-- @classmod Result -class Stream ---- Stream interface. +class Result +--- Result interface. -- --- Methods that have to be implemented by `Stream` implementations +-- Methods that have to be implemented by `Result` implementations -- (`SigStream`, `EvtStream`, `IOStream`). -- -- @section interface - --- return whether this Stream was changed in the current tick. - -- + --- return whether this Result was changed in the current tick. -- @function dirty -- @treturn boolean - --- create a mutable copy of this Stream. + --- create a mutable copy of this Result. -- -- Used to insulate eval-cycles from each other. -- -- @function fork - -- @treturn Stream + -- @treturn Result __tostring: => "<#{@type}#{@metatype} #{@type\pp @value}>" __inherited: (cls) => cls.__base.__tostring or= @__tostring - --- the type name of this Stream's value. - -- - -- the following builtin typenames are used: - -- - -- - `str` - strings, `value` is a Lua string - -- - `sym` - symbols, `value` is a Lua string - -- - `num` - numbers, `value` is a Lua number - -- - `bool` - booleans, `value` is a Lua boolean - -- - `bang` - trigger signals, `value` is a Lua boolean - -- - `opdef` - `value` is an `Op` subclass - -- - `builtin` - `value` is a `Builtin` subclass - -- - `fndef` - `value` is a `FnDef` instance - -- - `scope` - `value` is a `Scope` instance - -- + --- the type name of this Result's value. -- @tfield string type - --- the metatype string for this Stream. + --- the metatype string for this Result. -- -- one of `=` (`Constant`), `~` (`SigStream`), -- `!` (`EvtStream` and `IOStream`). -- - -- @tfield string type + -- @tfield string metatype + + --- get the full typestring. + -- @treturn string `type .. metatype` + fulltype: => (tostring @type) .. @metatype --- documentation metadata. -- @@ -66,7 +56,7 @@ class Stream --- static functions -- @section static - --- construct a new Stream. + --- construct a new Result. -- -- @classmethod -- @tparam string type the type name @@ -74,5 +64,5 @@ class Stream new: (@type, @meta={}) => { - :Stream + :Result } diff --git a/alv/result/const.moon b/alv/result/const.moon index b9a7cf4..615e426 100644 --- a/alv/result/const.moon +++ b/alv/result/const.moon @@ -1,10 +1,10 @@ ---- -- Constant Value. -- --- Implements the `Stream` and `AST` inteface. +-- Implements the `Result` and `AST` inteface. -- -- @classmod Constant -import Stream from require 'alv.result.base' +import Result from require 'alv.result.base' import Primitive from require 'alv.type' import RTNode from require 'alv.rtnode' import Error from require 'alv.error' @@ -21,10 +21,14 @@ ancestor = (klass) -> klass = klass.__parent klass -class Constant extends Stream - --- Whether this Result is dirty. - -- - -- @treturn bool always `false`. +class Constant extends Result +--- Result interface +-- +-- `Constant` implements the `Result` interface. +-- @section result + + --- return whether this Result was changed in the current tick. + -- @treturn bool dirty: => false --- unwrap to the Lua type. @@ -53,14 +57,13 @@ class Constant extends Stream -- Compares two `SigStream`s by comparing their types and their Lua values. __eq: (other) => other.type == @type and other.value == @value - --- Stream metatype. - -- + --- Result metatype. -- @tfield string metatype (`=`) metatype: '=' --- AST interface -- --- `SignStream` implements the `AST` interface. +-- `Constant` implements the `AST` interface. -- @section ast --- evaluate this literal constant. @@ -72,11 +75,11 @@ class Constant extends Stream -- @tparam Scope scope the scope to evaluate in -- @treturn RTNode the evaluation result eval: (scope) => - return RTNode value: @ if @literal + return RTNode result: @ if @literal switch @type when num, str - RTNode value: @ + RTNode result: @ when sym Error.wrap "resolving symbol '#{@value}'", scope\get, @value else @@ -140,7 +143,7 @@ class Constant extends Stream switch ancestor val.__class when scope.Scope then 'scope' when base.FnDef then 'fndef' - when Stream then return val + when Result then return val else error "#{name}: cannot wrap '#{val.__class.__name}' instance" else diff --git a/alv/result/evt.moon b/alv/result/evt.moon index 0559a70..fdec85e 100644 --- a/alv/result/evt.moon +++ b/alv/result/evt.moon @@ -2,29 +2,18 @@ -- Stream of momentary events. -- -- @classmod EvtStream -import Stream from require 'alv.result.base' +import Result from require 'alv.result.base' -class EvtStream extends Stream ---- members --- @section members +class EvtStream extends Result +--- Result interface +-- +-- `EvtStream` implements the `Result` interface. +-- @section result - --- return whether this stream was changed in the current tick. - -- + --- return whether this Result was changed in the current tick. -- @treturn bool dirty: => @updated == COPILOT.T - --- push an event value into the stream. - -- - -- Marks this stream as dirty for the remainder of the current tick. - -- - -- @tparam any event - add: (event) => - if not @dirty! - @events = {} - - @updated = COPILOT.T - table.insert @events, event - --- get the sequence of current events (if any). -- -- Returns `events` if `dirty`, or an empty table otherwise. @@ -48,27 +37,13 @@ class EvtStream extends Stream __call: (...) => @unwrap ... __tostring: => "<#{@type}#{@metatype} #{@type\pp @value}>" - --- Stream metatype. - -- + --- the type name of this Result's value. + -- @tfield string type + + --- the metatype string for this Result. -- @tfield string metatype (`!`) metatype: '!' - --- the type name of the stream. - -- - -- the following builtin typenames are used: - -- - -- - `str` - strings, `value` is a Lua string - -- - `sym` - symbols, `value` is a Lua string - -- - `num` - numbers, `value` is a Lua number - -- - `bool` - booleans, `value` is a Lua boolean - -- - `bang` - trigger signals, `value` is a Lua boolean - -- - `opdef` - `value` is an `Op` subclass - -- - `builtin` - `value` is a `Builtin` subclass - -- - `fndef` - `value` is a `FnDef` instance - -- - `scope` - `value` is a `Scope` instance - -- - -- @tfield string type - --- documentation metadata. -- -- an optional table containing metadata for error messages and @@ -81,6 +56,22 @@ class EvtStream extends Stream -- -- @tfield ?table meta +--- members +-- @section members + + --- push an event value into the stream. + -- + -- Marks this stream as dirty for the remainder of the current tick. + -- + -- @tparam any event + add: (event) => + if not @dirty! + @events = {} + + @updated = COPILOT.T + table.insert @events, event + + --- static functions -- @section static diff --git a/alv/result/init.moon b/alv/result/init.moon index aa7a115..200e4e1 100644 --- a/alv/result/init.moon +++ b/alv/result/init.moon @@ -1,13 +1,13 @@ ---- --- `Stream` interface and implementations. +-- `Result` interface and implementations. -- --- @see Stream +-- @see Result -- @see Constant -- @see SigStream -- @see EvtStream -- @see IOStream -- --- @module stream +-- @module result import Constant from require 'alv.result.const' import SigStream from require 'alv.result.sig' import EvtStream from require 'alv.result.evt' diff --git a/alv/result/sig.moon b/alv/result/sig.moon index 6bcba65..8ca59b7 100644 --- a/alv/result/sig.moon +++ b/alv/result/sig.moon @@ -2,26 +2,19 @@ -- Continuous stream of values. -- -- @classmod SigStream -import Stream from require 'alv.result.base' +import Result from require 'alv.result.base' import Primitive from require 'alv.type' -class SigStream extends Stream ---- members --- @section members +class SigStream extends Result +--- Result interface +-- +-- `SigStream` implements the `Result` interface. +-- @section result - --- return whether this stream was changed in the current tick. - -- + --- return whether this Result was changed in the current tick. -- @treturn bool dirty: => @updated == COPILOT.T - --- update this stream's value. - -- - -- Marks this stream as dirty for the remainder of the current tick. - set: (value) => - if value != @value - @value = value - @updated = COPILOT.T - --- unwrap to the Lua type. -- -- Asserts `@type == type` if `type` is given. @@ -50,29 +43,12 @@ class SigStream extends Stream -- Compares two `SigStream`s by comparing their types and their Lua values. __eq: (other) => other.type == @type and other.value == @value - --- Stream metatype. - -- - -- @tfield string metatype (`~`) - metatype: '~' - - --- the type name of this stream. - -- - -- the following builtin typenames are used: - -- - -- - `str` - strings, `value` is a Lua string - -- - `sym` - symbols, `value` is a Lua string - -- - `num` - numbers, `value` is a Lua number - -- - `bool` - booleans, `value` is a Lua boolean - -- - `bang` - trigger signals, `value` is a Lua boolean - -- - `opdef` - `value` is an `Op` subclass - -- - `builtin` - `value` is a `Builtin` subclass - -- - `fndef` - `value` is a `FnDef` instance - -- - `scope` - `value` is a `Scope` instance - -- + --- the type name of this Result's value. -- @tfield string type - --- the wrapped Lua value. - -- @tfield any value + --- the metatype string for this Result. + -- @tfield string metatype (`~`) + metatype: '~' --- documentation metadata. -- @@ -86,6 +62,20 @@ class SigStream extends Stream -- -- @tfield ?table meta +--- members +-- @section members + + --- update this stream's value. + -- + -- Marks this stream as dirty for the remainder of the current tick. + set: (value) => + if value != @value + @value = value + @updated = COPILOT.T + + --- the wrapped Lua value. + -- @tfield any value + --- static functions -- @section static diff --git a/alv/rtnode.moon b/alv/rtnode.moon index dab4507..a8ebec3 100644 --- a/alv/rtnode.moon +++ b/alv/rtnode.moon @@ -9,33 +9,33 @@ class RTNode --- members -- @section members - --- return whether this RTNode's value is const. + --- return whether this RTNode's result is const. is_const: => not next @side_inputs - --- assert value-constness and return the value. + --- assert result-constness and return the result. -- @tparam[opt] string msg the error message to throw -- @treturn any const: (msg) => assert not (next @side_inputs), msg or "eval-time const expected" - @value + @result - --- assert this result has a value, return its type. + --- assert this result has a result, return its type. -- @treturn string type: => - assert @value, "RTNode with value expected" - @value.type + assert @result, "RTNode with result expected" + @result.type - --- assert this result has a value, returns its metatype. - -- @treturn string `"value"` or `"event"` + --- assert this result has a result, returns its metatype. + -- @treturn string `"result"` or `"event"` metatype: => - assert @value, "RTNode with value expected" - @value.metatype + assert @result, "RTNode with result expected" + @result.metatype - --- create a copy of this result with value-copy semantics. - -- the copy has the same @value and @side_inputs, but will not update + --- create a copy of this result with result-copy semantics. + -- the copy has the same @result and @side_inputs, but will not update -- anything on \tick. make_ref: => - with RTNode value: @value + with RTNode result: @result .side_inputs = @side_inputs --- poll all IOStream instances that are effecting this (sub)tree. @@ -73,15 +73,15 @@ class RTNode @op\tick! __tostring: => - buf = "<RT=#{@value}" + buf = "<RT=#{@result}" buf ..= " #{@op}" if @op buf ..= " (#{#@children} children)" if #@children > 0 buf ..= ">" buf - --- the `Stream` result + --- the `Result` result -- - -- @tfield ?Stream value + -- @tfield ?Result result --- an Op -- @@ -91,21 +91,21 @@ class RTNode -- -- @tfield {}|{RTNode,...} children - --- cached mapping of all `Stream`/`Input` pairs affecting this RTNode. + --- cached mapping of all `Result`/`Input` pairs affecting this RTNode. -- -- This is the union of all `children`s `side_inputs` and all `Input`s from - -- `op` that are not the `value` of any child. + -- `op` that are not the `result` of any child. -- - -- @tfield {[Stream]=Input,...} side_inputs + -- @tfield {[Result]=Input,...} side_inputs --- static functions -- @section static --- create a new RTNode. -- @classmethod - -- @param params table with optional keys op, value, children. default: {} + -- @param params table with optional keys op, result, children. default: {} new: (params={}) => - @value = params.value + @result = params.result @op = params.op @children = params.children or {} @@ -113,14 +113,17 @@ class RTNode for child in *@children for stream, input in pairs child.side_inputs @side_inputs[stream] = input - if child.value - is_child[child.value] = true + if child.result + is_child[child.result] = true if @op for input in @op\all_inputs! if input.io or not is_child[input.stream] @side_inputs[input.stream] = input + if @result and @result.metatype == '=' + assert not (next @side_inputs), "Const result has side_inputs" + { :RTNode } diff --git a/alv/scope.moon b/alv/scope.moon index c2c91e1..462d7a6 100644 --- a/alv/scope.moon +++ b/alv/scope.moon @@ -18,8 +18,8 @@ class Scope -- @tparam string key -- @tparam any val set_raw: (key, val) => - value = Constant.wrap val, key - @values[key] = RTNode :value + result = Constant.wrap val, key + @values[key] = RTNode :result --- set a symbol to a `RTNode`. -- @@ -28,7 +28,7 @@ class Scope set: (key, val) => L\trace "setting #{key} = #{val} in #{@}" assert val.__class == RTNode, "expected #{key}=#{val} to be RTNode" - assert val.value, Error 'type', "cannot define symbol to nil" + assert val.result, Error 'type', "cannot define symbol to nil" assert not @values[key], Error 'type', "cannot redefine symbol '#{key}'!" @values[key] = val @@ -59,7 +59,7 @@ class Scope error Error 'reference', "undefined symbol '#{start}'" if child\type! != (Primitive 'scope') error Error 'reference', "'#{start}' is not a scope" - child.value!\get rest, while_msg + child.result!\get rest, while_msg --- copy definitions from another scope. -- |
