aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-09-01 13:24:37 +0000
committers-ol <s-ol@users.noreply.github.com>2020-09-01 13:24:37 +0000
commitcd493d4152d7b9a2dc7a4383bb24e4650afb4ea4 (patch)
tree809d14f3ddfc51a5a3d90680cc4e4863169e16d4
parentupdate scm rockspec (diff)
downloadalive-cd493d4152d7b9a2dc7a4383bb24e4650afb4ea4.tar.gz
alive-cd493d4152d7b9a2dc7a4383bb24e4650afb4ea4.zip
support :vis() on builtins
-rw-r--r--alv/base/builtin.moon11
-rw-r--r--alv/builtins.moon7
-rw-r--r--alv/copilot/udp.moon2
-rw-r--r--alv/invoke.moon7
4 files changed, 25 insertions, 2 deletions
diff --git a/alv/base/builtin.moon b/alv/base/builtin.moon
index 54f7433..558a65a 100644
--- a/alv/base/builtin.moon
+++ b/alv/base/builtin.moon
@@ -53,6 +53,17 @@ class Builtin
-- @tparam ?Builtin prev the previous Builtin instance
setup: (prev) =>
+ --- collect visualisation data (optional).
+ --
+ -- This may return any simple Lua value, including Lua tables, as long as it
+ -- has no metatables, multiple references/loops, userdata etc.
+ --
+ -- This value is exposed to alv editors in order to render realtime
+ -- visualisations overlaid onto the program text.
+ --
+ -- @treturn table vis
+ vis: => {}
+
--- the `Cell` this Builtin was created for.
-- @tfield Cell cell
diff --git a/alv/builtins.moon b/alv/builtins.moon
index 8a08705..d6a52b9 100644
--- a/alv/builtins.moon
+++ b/alv/builtins.moon
@@ -279,6 +279,7 @@ to `then-expr`, otherwise it is equivalent to `else-xpr` if given, or nil otherw
msg = "'if'-expression needs to be constant, did you mean 'switch'?"
error Error 'argument', msg
xif = xif.result\unwrap!
+ @state = xif
super if xif
xthen\eval scope
@@ -287,6 +288,8 @@ to `then-expr`, otherwise it is equivalent to `else-xpr` if given, or nil otherw
else
RTNode!
+ vis: => step: if @state then 0 else 1
+
when_ = Constant.meta
meta:
name: 'when'
@@ -366,7 +369,9 @@ switch_ = Constant.meta
@out\set if v = values[@state + 1] then v!
- vis: => step: @state
+ vis: =>
+ with Op.vis @
+ .step = @state
trace_ = Constant.meta
meta:
diff --git a/alv/copilot/udp.moon b/alv/copilot/udp.moon
index 0640189..f5deb50 100644
--- a/alv/copilot/udp.moon
+++ b/alv/copilot/udp.moon
@@ -49,7 +49,7 @@ class UDPServer
if builtin and builtin.__class.__name ~= 'DummyReg'
res.head_meta = builtin.head.meta
res.result = encode_res builtin.node.result
- res.vis = if builtin.op then builtin.op\vis!
+ res.vis = builtin\vis!
res.kind = switch builtin.__class
when op_invoke then 'op'
when fn_invoke then 'fn'
diff --git a/alv/invoke.moon b/alv/invoke.moon
index 6962f4d..e40cbc4 100644
--- a/alv/invoke.moon
+++ b/alv/invoke.moon
@@ -77,6 +77,13 @@ class op_invoke extends Builtin
super RTNode :children, result: @op.out, op: @op
+ --- `Builtin:vis` implementation.
+ --
+ -- calls `op`:@{Op:vis|vis}.
+ --
+ -- @treturn table vis
+ vis: => if @op then @op\vis!
+
--- The `Op` instance.
--
-- @tfield Op op