aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-09-04 12:14:06 +0000
committers-ol <s+removethis@s-ol.nu>2025-03-02 14:24:49 +0000
commitbe3b0f8cb054620274c00e4eed4314094599e078 (patch)
tree051a58aed43cd6cfd7b5b28d6255fdb22b7b3eae
parentreroll RTNode tests (diff)
downloadalive-be3b0f8cb054620274c00e4eed4314094599e078.tar.gz
alive-be3b0f8cb054620274c00e4eed4314094599e078.zip
have alv-lua modules return Results, not plain tables
-rw-r--r--alv/builtins.moon89
-rw-r--r--alv/copilot/base.moon9
-rw-r--r--alv/init.moon4
-rw-r--r--alv/module.moon2
-rw-r--r--alv/scope.moon5
-rw-r--r--spec/test_setup.moon5
6 files changed, 61 insertions, 53 deletions
diff --git a/alv/builtins.moon b/alv/builtins.moon
index d6a52b9..eb43b5a 100644
--- a/alv/builtins.moon
+++ b/alv/builtins.moon
@@ -620,46 +620,49 @@ bound to `nv2`…
super RTNode :children, result: node.result
-Scope.from_table {
- :doc
- :trace, 'trace=': trace_, print: print_
-
- :def, :use
- require: require_
- import: import_
- 'import*': import_star
- export: export_
- 'export*': export_star
-
- :fn, :defn
- 'do': do_
- 'if': if_
- 'when': when_
- 'switch': switch_
-
- '=': to_const
- '~': to_sig
- '!': to_evt
-
- :array, :struct
-
- :loop, :recur
-
- true: Constant.meta
- meta:
- name: 'true'
- summary: "The boolean constant `true`."
- value: Constant.bool true
-
- false: Constant.meta
- meta:
- name: 'false'
- summary: "The boolean constant `false`."
- value: Constant.bool false
-
- bang: Constant.meta
- meta:
- name: 'bang'
- summary: "A `bang` value-constant."
- value: Constant T.bang, true
-}
+Constant.meta
+ meta:
+ summary: "builtin operators and constants."
+
+ value:
+ :doc
+ :trace, 'trace=': trace_, print: print_
+
+ :def, :use
+ require: require_
+ import: import_
+ 'import*': import_star
+ export: export_
+ 'export*': export_star
+
+ :fn, :defn
+ 'do': do_
+ 'if': if_
+ 'when': when_
+ 'switch': switch_
+
+ '=': to_const
+ '~': to_sig
+ '!': to_evt
+
+ :array, :struct
+
+ :loop, :recur
+
+ true: Constant.meta
+ meta:
+ name: 'true'
+ summary: "The boolean constant `true`."
+ value: Constant.bool true
+
+ false: Constant.meta
+ meta:
+ name: 'false'
+ summary: "The boolean constant `false`."
+ value: Constant.bool false
+
+ bang: Constant.meta
+ meta:
+ name: 'bang'
+ summary: "A `bang` value-constant."
+ value: Constant T.bang, true
diff --git a/alv/copilot/base.moon b/alv/copilot/base.moon
index 642098b..96aea3b 100644
--- a/alv/copilot/base.moon
+++ b/alv/copilot/base.moon
@@ -72,11 +72,12 @@ class Copilot
-- @treturn RTNode root
require: (name) =>
Error.wrap "loading module '#{name}'", ->
- ok, lua = pcall require, "alv-lib.#{name}"
+ ok, result = pcall require, "alv-lib.#{name}"
if ok
- RTNode result: Constant.wrap lua
- elseif not lua\match "not found"
- error lua
+ result = RTNode :result unless result.__class == RTNode
+ result
+ elseif not result\match "not found"
+ error result
else
assert @modules, "no current eval cycle?"
if mod = @modules[name]
diff --git a/alv/init.moon b/alv/init.moon
index 3de3c9b..0637c5c 100644
--- a/alv/init.moon
+++ b/alv/init.moon
@@ -63,13 +63,13 @@ cycle\resolve!
:Registry, :SimpleRegistry, :Tag
:Logger
- :globals
+ globals: globals!
parse: (str) ->
assert (program\match str), Error 'syntax', "failed to parse"
eval: (str, inject) ->
- scope = Scope globals
+ scope = Scope globals!
scope\use inject if inject
ast = assert (program\match str), "failed to parse"
diff --git a/alv/module.moon b/alv/module.moon
index 0144263..8513192 100644
--- a/alv/module.moon
+++ b/alv/module.moon
@@ -42,7 +42,7 @@ class Module
@ast = Error.wrap "parsing '#{@name true}'", -> program\match @slurp!
assert @ast, Error 'syntax', "failed to parse"
- scope = Scope builtins
+ scope = Scope builtins!
@root = Error.wrap "evaluating '#{@name true}'", @ast\eval, scope, @registry
--- rollback the last evaluation cycle.
diff --git a/alv/scope.moon b/alv/scope.moon
index 7f4b14f..96dbfa2 100644
--- a/alv/scope.moon
+++ b/alv/scope.moon
@@ -113,7 +113,10 @@ class Scope
@from_table: (tbl) ->
with Scope!
for k, v in pairs tbl
- \set_raw k, v
+ if type(v) == 'table' and v.__class == RTNode
+ \set k, v
+ else
+ \set_raw k, v
{
:Scope
diff --git a/spec/test_setup.moon b/spec/test_setup.moon
index 16a3639..8e1efee 100644
--- a/spec/test_setup.moon
+++ b/spec/test_setup.moon
@@ -58,9 +58,10 @@ class TestPilot extends Copilot
require: (name) =>
Error.wrap "loading module '#{name}'", ->
- ok, lua = pcall require, "alv-lib.#{name}"
+ ok, result = pcall require, "alv-lib.#{name}"
if ok
- RTNode result: Constant.wrap lua
+ result = RTNode :result unless result.__class == RTNode
+ result
else
error Error 'import', "module not found"