aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-04-12 17:45:02 +0000
committers-ol <s-ol@users.noreply.github.com>2020-04-12 17:45:02 +0000
commit98ed2cdbd1bce20d38fda1c830ef68807975ea93 (patch)
tree106881049995b4dc8e5979dc88b7c06ec34f0fdd
parenttime/every: allow specifying event (diff)
downloadalive-98ed2cdbd1bce20d38fda1c830ef68807975ea93.tar.gz
alive-98ed2cdbd1bce20d38fda1c830ef68807975ea93.zip
rename Action to Builtin
-rw-r--r--core/base/builtin.moon (renamed from core/base/action.moon)28
-rw-r--r--core/base/init.moon6
-rw-r--r--core/builtin.moon28
-rw-r--r--core/cell.moon8
-rw-r--r--core/extensions.md16
-rw-r--r--core/invoke.moon21
-rw-r--r--core/stream/base.moon2
-rw-r--r--core/stream/event.moon2
-rw-r--r--core/stream/value.moon4
-rw-r--r--core/tag.moon2
-rw-r--r--spec/core/value_spec.moon8
11 files changed, 63 insertions, 62 deletions
diff --git a/core/base/action.moon b/core/base/builtin.moon
index d10712f..fd36c69 100644
--- a/core/base/action.moon
+++ b/core/base/builtin.moon
@@ -5,12 +5,12 @@
-- up `Op`s, updating the current `Scope`, etc.
-- See `builtin` and `invoke` for examples.
--
--- @classmod Action
+-- @classmod Builtin
-class Action
---- Action interface.
+class Builtin
+--- Builtin interface.
--
--- methods that have to be implemented by `Action` implementations.
+-- methods that have to be implemented by `Builtin` implementations.
-- @section interface
--- create a new instance.
@@ -39,13 +39,13 @@ class Action
--- setup or copy state from previous instance of same type.
--
- -- `prev` is only passed if Action types of prev and current expression match.
+ -- `prev` is only passed if Builtin types of prev and current expression match.
-- Otherwise, or when no previous expression exists, `nil` is passed.
--
- -- @tparam ?Action prev the previous Action instance
+ -- @tparam ?Builtin prev the previous Builtin instance
setup: (prev) =>
- --- the `Cell` this Action was created for.
+ --- the `Cell` this Builtin was created for.
-- @tfield Cell cell
--- the evaluated head of `cell`.
@@ -57,11 +57,11 @@ class Action
--- static functions
-- @section static
- --- create and setup an `Action` for a given tag, then evaluate it.
+ --- create and setup a `Builtin` for a given tag, then evaluate it.
--
-- 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 `Action` with `tag`, evaluate it
+ -- it pass it to `setup`. Register the `Builtin` with `tag`, evaluate it
-- and return the `Result`.
--
-- @tparam Cell cell the `Cell` being evaluated
@@ -79,18 +79,18 @@ class Action
else
"initializing #{cell.tag} <#{@__name} #{head}>"
- action = @ cell, head
+ builtin = @ cell, head
if compatible
- action\setup last
+ builtin\setup last
else
last\destroy! if last
- action\setup nil
+ builtin\setup nil
- action\eval scope, cell\tail!
+ builtin\eval scope, cell\tail!
__tostring: => "<#{@@__name} #{@head}>"
__inherited: (cls) => cls.__base.__tostring = @__tostring
{
- :Action
+ :Builtin
}
diff --git a/core/base/init.moon b/core/base/init.moon
index 1b71086..9153f79 100644
--- a/core/base/init.moon
+++ b/core/base/init.moon
@@ -6,7 +6,7 @@
--
-- @module base
-- @see Op
--- @see Action
+-- @see Builtin
-- @see FnDef
-- @see Input
-- @see base.match.val
@@ -18,7 +18,7 @@
-- @see Error
import Op from require 'core.base.op'
-import Action from require 'core.base.action'
+import Builtin from require 'core.base.builtin'
import FnDef from require 'core.base.fndef'
import Input from require 'core.base.input'
import val, evt from require 'core.base.match'
@@ -28,7 +28,7 @@ import Error from require 'core.error'
{
:Op
- :Action
+ :Builtin
:FnDef
:Input
:val, :evt
diff --git a/core/builtin.moon b/core/builtin.moon
index abc6f49..68b825c 100644
--- a/core/builtin.moon
+++ b/core/builtin.moon
@@ -1,11 +1,11 @@
----
--- Builtin `Action`s and `Op`s.
+-- Builtin `Builtin`s and `Op`s.
--
-- Please see the [reference](../../reference/index.html#builtins) for
-- documentation.
--
-- @module builtin
-import Action, Op, FnDef, Input, val, evt from require 'core.base'
+import Builtin, Op, FnDef, Input, val, evt from require 'core.base'
import ValueStream, LiteralValue from require 'core.stream.value'
import Result from require 'core.result'
import Cell from require 'core.cell'
@@ -20,7 +20,7 @@ doc = ValueStream.meta
examples: { '(doc sym)' }
description: "Print the documentation for `sym` to the console"
- value: class extends Action
+ value: class extends Builtin
format_meta = =>
str = @summary
if @examples
@@ -47,7 +47,7 @@ def = ValueStream.meta
Define the symbols `sym1`, `sym2`, … to resolve to the values of `val-expr1`,
`val-expr2`, …."
- value: class extends Action
+ value: class extends Builtin
eval: (scope, tail) =>
L\trace "evaling #{@}"
assert #tail > 1, "'def' requires at least 2 arguments"
@@ -72,7 +72,7 @@ use = ValueStream.meta
Copy all symbol definitions from `scope1`, `scope2`, … to the current scope.
All arguments have to be evaltime constant."
- value: class extends Action
+ value: class extends Builtin
eval: (scope, tail) =>
L\trace "evaling #{@}"
for child in *tail
@@ -89,7 +89,7 @@ require_ = ValueStream.meta
examples: { '(require name)' }
description: "Load a module and return its scope."
- value: class extends Action
+ value: class extends Builtin
eval: (scope, tail) =>
L\trace "evaling #{@}"
assert #tail == 1, "'require' takes exactly one parameter"
@@ -110,7 +110,7 @@ import_ = ValueStream.meta
Requires modules `sym1`, `sym2`, … and define them as `sym1`, `sym2`, … in the
current scope."
- value: class extends Action
+ value: class extends Builtin
eval: (scope, tail) =>
L\trace "evaling #{@}"
assert #tail > 0, "'import' requires at least one arguments"
@@ -129,7 +129,7 @@ import_star = ValueStream.meta
description: "
Requires modules `sym1`, `sym2`, … and merges them into the current scope."
- value: class extends Action
+ value: class extends Builtin
eval: (scope, tail) =>
L\trace "evaling #{@}"
assert #tail > 0, "'import' requires at least one arguments"
@@ -151,7 +151,7 @@ fn = ValueStream.meta
The symbols `p1`, `p2`, ... will resolve to the arguments passed when the
function is invoked."
- value: class extends Action
+ value: class extends Builtin
eval: (scope, tail) =>
L\trace "evaling #{@}"
assert #tail == 2, "'fn' takes exactly two arguments"
@@ -179,7 +179,7 @@ Declare a function and define it as `name-sym` in the current scope.
The symbols `p1`, `p2`, ... will resolve to the arguments passed when the
function is invoked."
- value: class extends Action
+ value: class extends Builtin
eval: (scope, tail) =>
L\trace "evaling #{@}"
assert #tail == 3, "'defn' takes exactly three arguments"
@@ -210,7 +210,7 @@ do_expr = ValueStream.meta
description: "
Evaluate `expr1`, `expr2`, … and return the value of the last expression."
- value: class extends Action
+ value: class extends Builtin
eval: (scope, tail) =>
scope = Scope scope
Result children: [expr\eval scope for expr in *tail]
@@ -224,7 +224,7 @@ if_ = ValueStream.meta
`bool` has to be an evaltime constant. If it is truthy, this expression is equivalent
to `then-expr`, otherwise it is equivalent to `else-xpr` if given, or nil otherwise."
- value: class extends Action
+ value: class extends Builtin
eval: (scope, tail) =>
L\trace "evaling #{@}"
assert #tail >= 2, "'if' needs at least two parameters"
@@ -246,7 +246,7 @@ trace_ = ValueStream.meta
summary: "Trace an expression's value at evaltime."
examples: { '(trace! expr)' }
- value: class extends Action
+ value: class extends Builtin
eval: (scope, tail) =>
L\trace "evaling #{@}"
assert #tail == 1, "'trace!' takes exactly one parameter"
@@ -260,7 +260,7 @@ trace = ValueStream.meta
summary: "Trace an expression's values at runtime."
examples: { '(trace expr)' }
- value: class extends Action
+ value: class extends Builtin
class traceOp extends Op
setup: (inputs) =>
super
diff --git a/core/cell.moon b/core/cell.moon
index 91634f8..b028f14 100644
--- a/core/cell.moon
+++ b/core/cell.moon
@@ -59,20 +59,20 @@ class Cell
--- evaluate this Cell.
--
-- `AST:eval`uates the head of the expression, and finds the appropriate
- -- `Action` to invoke:
+ -- `Builtin` to invoke:
--
-- - if head is an `opdef`, use `invoke.op_invoke`
-- - if head is a `fndef`, use `invoke.fn_invoke`
-- - if head is a `builtin`, unwrap it
--
- -- then calls `Action:eval_cell` on it.
+ -- then calls `Builtin:eval_cell` on it.
--
-- @tparam Scope scope the scope to evaluate in
-- @treturn Result the evaluation result
eval: (scope) =>
head = assert @head!, Error 'syntax', "cannot evaluate empty expr"
head = (head\eval scope)\const!
- Action = switch head.type
+ Builtin = switch head.type
when 'opdef'
-- scope\get 'op-invoke'
op_invoke
@@ -84,7 +84,7 @@ class Cell
else
error Error 'type', "#{head} is not an opdef, fndef or builtin"
- Action\eval_cell @, scope, head
+ Builtin\eval_cell @, scope, head
--- quote this Cell, preserving its identity.
--
diff --git a/core/extensions.md b/core/extensions.md
index 19cb5aa..6af9bca 100644
--- a/core/extensions.md
+++ b/core/extensions.md
@@ -168,15 +168,15 @@ There are three types of `Stream`s that can be created:
Op's main logic will go. Generally here it should be checked which input(s)
changed, and then internal state and the output value may be updated.
-## defining `Action`s
-Actions are more powerful than Ops, because they control whether, which and
+## defining `Builtin`s
+Builtins are more powerful than Ops, because they control whether, which and
how their arguments are evaluated. They roughly correspond to *macros* in Lisps.
-There is less of a concrete guideline for implementing Actions because there
-are a lot more options, and it really depends a lot on what the Action should
-achieve. Nevertheless, a good starting point is to read the `Action` class
-documentation, take a look at the builtin `Action`s in `core/builtin.moon` and
-get familiar with the relevant internal interfaces (especially `AST`, `Result`
-, and `Scope`).
+There is less of a concrete guideline for implementing Builtins because there
+are a lot more options, and it really depends a lot on what the Builtin should
+achieve. Nevertheless, a good starting point is to read the `Builtin` class
+documentation, take a look at `Builtin`s in `core/builtin.moon` and get
+familiar with the relevant internal interfaces (especially `AST`, `Result`, and
+`Scope`).
## defining `IOStream`s
`IOStream`s are `EventStream`s that can 'magically' create events out of
diff --git a/core/invoke.moon b/core/invoke.moon
index 539a778..8fcb525 100644
--- a/core/invoke.moon
+++ b/core/invoke.moon
@@ -3,7 +3,7 @@
--
-- @module invoke
import Result from require 'core.result'
-import Action from require 'core.base'
+import Builtin from require 'core.base'
import Scope from require 'core.scope'
import Error from require 'core.error'
@@ -21,11 +21,11 @@ get_name = (value, raw) ->
else
"(unnamed)"
---- `Action` implementation that invokes an `Op`.
+--- `Builtin` implementation that invokes an `Op`.
--
-- @type op_invoke
-class op_invoke extends Action
- --- `Action:setup` implementation.
+class op_invoke extends Builtin
+ --- `Builtin:setup` implementation.
--
-- `Op:fork`s the `prev`'s `Op` instance if given. Creates a new instance
-- otherwise.
@@ -36,7 +36,7 @@ class op_invoke extends Action
def = @head\unwrap 'opdef', "cant op-invoke #{@head}"
@op = def!
- --- `Action:destroy` implementation.
+ --- `Builtin:destroy` implementation.
--
-- calls `op`:@{Op:destroy|destroy}.
destroy: => @op\destroy!
@@ -76,17 +76,17 @@ class op_invoke extends Action
--
-- @tfield Op op
---- `Action` implementation that invokes a `FnDef`.
+--- `Builtin` implementation that invokes a `FnDef`.
--
-- @type fn_invoke
-class fn_invoke extends Action
+class fn_invoke extends Builtin
--- evaluate a user-function invocation.
--
-- Creates a new `Scope` that inherits from `FnDef.scope` and has
-- `outer_scope` as an additional parent for dynamic symbol resolution.
-- Then `AST:eval`s the tail in `outer_scope`, and defines the results to the
-- names in `FnDef.params` in the newly created scope. Lastly, `AST:clone`s
- -- `FnDef.body` with the prefix `Action.tag`, and `AST:eval`s it in the newly
+ -- `FnDef.body` with the prefix `Builtin.tag`, and `AST:eval`s it in the newly
-- created `Scope`.
--
-- The `Result` contains the `Stream` from the cloned AST, and its children
@@ -102,8 +102,9 @@ class fn_invoke extends Action
{ :params, :body, :scope } = @head\unwrap 'fndef', "cant fn-invoke #{@head}"
if #params != #tail
- error with Error 'argument', "expected #{#params} arguments, found #{#tail}"
- \add_frame frame
+ err = Error 'argument', "expected #{#params} arguments, found #{#tail}"
+ err\add_frame frame
+ error err
fn_scope = Scope scope, outer_scope
diff --git a/core/stream/base.moon b/core/stream/base.moon
index cdccdc2..37cc8a4 100644
--- a/core/stream/base.moon
+++ b/core/stream/base.moon
@@ -35,7 +35,7 @@ class Stream
-- - `bool` - booleans, `value` is a Lua boolean
-- - `bang` - trigger signals, `value` is a Lua boolean
-- - `opdef` - `value` is an `Op` subclass
- -- - `builtin` - `value` is an `Action` subclass
+ -- - `builtin` - `value` is a `Builtin` subclass
-- - `fndef` - `value` is a `FnDef` instance
-- - `scope` - `value` is a `Scope` instance
--
diff --git a/core/stream/event.moon b/core/stream/event.moon
index f7b49c4..7712fc4 100644
--- a/core/stream/event.moon
+++ b/core/stream/event.moon
@@ -68,7 +68,7 @@ class EventStream extends Stream
-- - `bool` - booleans, `value` is a Lua boolean
-- - `bang` - trigger signals, `value` is a Lua boolean
-- - `opdef` - `value` is an `Op` subclass
- -- - `builtin` - `value` is an `Action` subclass
+ -- - `builtin` - `value` is a `Builtin` subclass
-- - `fndef` - `value` is a `FnDef` instance
-- - `scope` - `value` is a `Scope` instance
--
diff --git a/core/stream/value.moon b/core/stream/value.moon
index ce3ffc7..68e16b0 100644
--- a/core/stream/value.moon
+++ b/core/stream/value.moon
@@ -81,7 +81,7 @@ class ValueStream extends Stream
-- - `bool` - booleans, `value` is a Lua boolean
-- - `bang` - trigger signals, `value` is a Lua boolean
-- - `opdef` - `value` is an `Op` subclass
- -- - `builtin` - `value` is an `Action` subclass
+ -- - `builtin` - `value` is a `Builtin` subclass
-- - `fndef` - `value` is a `FnDef` instance
-- - `scope` - `value` is a `Scope` instance
--
@@ -179,7 +179,7 @@ class ValueStream extends Stream
-- a class
switch ancestor val
when base.Op then 'opdef'
- when base.Action then 'builtin'
+ when base.Builtin then 'builtin'
else
error "#{name}: cannot wrap class '#{val.__name}'"
elseif val.__class
diff --git a/core/tag.moon b/core/tag.moon
index 55cd472..3c90998 100644
--- a/core/tag.moon
+++ b/core/tag.moon
@@ -1,5 +1,5 @@
----
--- Identity provider for `Cell`s and `Action`s.
+-- Identity provider for `Cell`s and `Builtin`s.
--
-- Tags are one of:
-- - 'blank' (`[?]`, to be auto-assigned by the Copilot)
diff --git a/spec/core/value_spec.moon b/spec/core/value_spec.moon
index b447d32..b09e8f7 100644
--- a/spec/core/value_spec.moon
+++ b/spec/core/value_spec.moon
@@ -1,12 +1,12 @@
import ValueStream, Result, Scope, SimpleRegistry from require 'core'
-import Op, Action from require 'core.base'
+import Op, Builtin from require 'core.base'
import Logger from require 'logger'
Logger.init 'silent'
class TestOp extends Op
new: (...) => super ...
-class TestAction extends Action
+class TestBuiltin extends Builtin
new: (...) =>
reg = SimpleRegistry!
@@ -38,10 +38,10 @@ describe 'ValueStream', ->
assert.is.equal TestOp, got.value
it 'wraps Bultins', ->
- got = ValueStream.wrap TestAction
+ got = ValueStream.wrap TestBuiltin
assert.is.equal 'builtin', got.type
- assert.is.equal TestAction, got.value
+ assert.is.equal TestBuiltin, got.value
it 'wraps Scopes', ->
sub = Scope!