diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-05-10 14:25:09 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2025-03-02 14:23:21 +0000 |
| commit | d36259f60b3e6f6077710905d5f7fcfd9f1710fc (patch) | |
| tree | ec6975f00af35b0faf83f8c20b7ad0eab6e7ae7f /alv | |
| parent | add and test Type:eq(a,b) (diff) | |
| download | alive-d36259f60b3e6f6077710905d5f7fcfd9f1710fc.tar.gz alive-d36259f60b3e6f6077710905d5f7fcfd9f1710fc.zip | |
make <num! 4> == <num= 4>
Diffstat (limited to 'alv')
| -rw-r--r-- | alv/base/match.moon | 4 | ||||
| -rw-r--r-- | alv/result/base.moon | 11 | ||||
| -rw-r--r-- | alv/result/const.moon | 9 | ||||
| -rw-r--r-- | alv/result/evt.moon | 4 | ||||
| -rw-r--r-- | alv/result/sig.moon | 11 | ||||
| -rw-r--r-- | alv/type.moon | 1 | ||||
| -rw-r--r-- | alv/util.moon | 8 |
7 files changed, 25 insertions, 23 deletions
diff --git a/alv/base/match.moon b/alv/base/match.moon index 926c970..f19c4d8 100644 --- a/alv/base/match.moon +++ b/alv/base/match.moon @@ -50,11 +50,13 @@ import Primitive from require 'alv.type' local Repeat, Sequence, Choice, Optional class Pattern + fulltype = (res) -> (tostring res.type) .. res.metatype + match: (seq) => @reset! num, cap = @capture seq, 1 if num != #seq - args = table.concat [arg.result\fulltype! for arg in *seq], ' ' + args = table.concat [fulltype arg.result for arg in *seq], ' ' msg = "couldn't match arguments (#{args}) against pattern #{@}" error Error 'argument', msg cap diff --git a/alv/result/base.moon b/alv/result/base.moon index 7775349..734d614 100644 --- a/alv/result/base.moon +++ b/alv/result/base.moon @@ -4,6 +4,8 @@ -- implemented by `Constant`, `SigStream`, `EvtStream`, and `IOStream`. -- -- @classmod Result +import Type from require 'alv.type' +import ancestor from require 'alv.util' class Result --- Result interface. @@ -41,10 +43,6 @@ class Result -- -- @tfield string metatype - --- get the full typestring. - -- @treturn string `type .. metatype` - fulltype: => (tostring @type) .. @metatype - --- documentation metadata. -- -- an optional table containing metadata for error messages and @@ -60,15 +58,16 @@ class Result --- static functions -- @section static - _type = type --- construct a new Result. -- -- @classmethod -- @tparam type.Type type the type -- @tparam ?table meta the `meta` table new: (@type, @meta={}) => - assert @type and (_type @type) == 'table', "not a type: #{@type}" + assert @type and (ancestor @type.__class) == Type, "not a type: #{@type}" { :Result + __eq: (a, b) -> + a.type == b.type and a.type\eq a.value, b.value } diff --git a/alv/result/const.moon b/alv/result/const.moon index 077a2d8..72d5b96 100644 --- a/alv/result/const.moon +++ b/alv/result/const.moon @@ -4,17 +4,12 @@ -- Implements the `Result` and `AST` inteface. -- -- @classmod Constant -import Result from require 'alv.result.base' +import Result, __eq from require 'alv.result.base' import T from require 'alv.type' import RTNode from require 'alv.rtnode' import Error from require 'alv.error' import scope, base from require 'alv.cycle' - -ancestor = (klass) -> - assert klass, "cant find the ancestor of nil" - while klass.__parent - klass = klass.__parent - klass +import ancestor from require 'alv.util' class Constant extends Result --- Result interface diff --git a/alv/result/evt.moon b/alv/result/evt.moon index 7e6a249..ad4c102 100644 --- a/alv/result/evt.moon +++ b/alv/result/evt.moon @@ -65,8 +65,6 @@ class EvtStream extends Result --- 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 = {} @@ -74,6 +72,8 @@ class EvtStream extends Result @updated = COPILOT.T table.insert @events, event + --- the wrapped Lua value. + -- @tfield {any,...} events --- static functions -- @section static diff --git a/alv/result/sig.moon b/alv/result/sig.moon index b23afbe..7e9582f 100644 --- a/alv/result/sig.moon +++ b/alv/result/sig.moon @@ -2,7 +2,7 @@ -- Continuous stream of values. -- -- @classmod SigStream -import Result from require 'alv.result.base' +import Result, __eq from require 'alv.result.base' class SigStream extends Result --- Result interface @@ -37,11 +37,6 @@ class SigStream extends Result --- alias for `unwrap`. __call: (...) => @unwrap ... - --- compare two values. - -- - -- Compares two `SigStream`s by comparing their types and their Lua values. - __eq: (other) => other.type == @type and other.value == @value - --- the type of this Result's value. -- @tfield type.Type type @@ -68,10 +63,12 @@ class SigStream extends Result -- -- Marks this stream as dirty for the remainder of the current tick. set: (value) => - if value != @value + if not @type\eq value, @value @value = value @updated = COPILOT.T + :__eq + --- the wrapped Lua value. -- @tfield any value diff --git a/alv/type.moon b/alv/type.moon index c8808d4..686f6c0 100644 --- a/alv/type.moon +++ b/alv/type.moon @@ -144,6 +144,7 @@ T = setmetatable {}, __index: (key) => rawset @, key, type { + :Type :T :Primitive :Array diff --git a/alv/util.moon b/alv/util.moon index a93fe3f..316233b 100644 --- a/alv/util.moon +++ b/alv/util.moon @@ -24,6 +24,14 @@ opairs = (t, order_fn, only_strings=false) -> state = { :t, i: 0, index: sort t, order_fn, only_strings } onext, state, nil +--- find the ancestor of a MoonScript class +ancestor = (klass) -> + assert klass, "cant find the ancestor of nil" + while klass.__parent + klass = klass.__parent + klass + { :opairs + :ancestor } |
