aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2022-10-18 20:12:19 +0000
committers-ol <s+removethis@s-ol.nu>2025-03-02 14:24:49 +0000
commitc3a6d5fc0cf18ea4295f157a0da0b79b6d3d0e86 (patch)
tree6622d978a834a26efa3cf1bbf47a5e19bea48159
parentbuiltins: fix use (diff)
downloadalive-c3a6d5fc0cf18ea4295f157a0da0b79b6d3d0e86.tar.gz
alive-c3a6d5fc0cf18ea4295f157a0da0b79b6d3d0e86.zip
builltins: check symbols are literals in def, import, import*, export*
-rw-r--r--alv/builtins.moon11
1 files changed, 8 insertions, 3 deletions
diff --git a/alv/builtins.moon b/alv/builtins.moon
index 50380d5..9cd54bb 100644
--- a/alv/builtins.moon
+++ b/alv/builtins.moon
@@ -38,7 +38,7 @@ doc = Constant.meta
assert #tail == 1, "'doc' takes exactly one parameter"
node = L\push tail[1]\eval, scope
- super with RTNode children: { def }
+ super with RTNode!
meta = node.result.meta
L\print "(doc #{tail[1]}):\n#{format_meta meta}\n"
@@ -60,6 +60,8 @@ Define the symbols `sym1`, `sym2`, … to resolve to the values of `val-expr1`,
children = L\push ->
return for i=1,#tail,2
name, val_expr = tail[i], tail[i+1]
+
+ assert name.__class == Constant, "name is not a symbol"
name = name\unwrap T.sym
with val_expr\eval scope
@@ -116,9 +118,10 @@ current scope."
value: class extends Builtin
eval: (scope, tail) =>
L\trace "evaling #{@}"
- assert #tail > 0, "'import' requires at least one arguments"
+ assert #tail > 0, "'import' requires at least one argument"
children = for i, child in ipairs tail
+ assert child.__class == Constant, "'import' arguments need to be symbols"
name = child\unwrap T.sym
with COPILOT\require name
scope\set name, \make_ref!
@@ -135,9 +138,10 @@ Requires modules `sym1`, `sym2`, … and merges them into the current scope."
value: class extends Builtin
eval: (scope, tail) =>
L\trace "evaling #{@}"
- assert #tail > 0, "'import' requires at least one arguments"
+ assert #tail > 0, "'import*' requires at least one argument"
children = for i, child in ipairs tail
+ assert child.__class == Constant, "'import*' arguments need to be symbols"
with COPILOT\require child\unwrap T.sym
scope\use .result\unwrap T.scope
super RTNode :children
@@ -177,6 +181,7 @@ Copies the containing scope if no symbols are given."
node
else
for child in *tail
+ assert child.__class == Constant, "'export*' arguments need to be symbols"
name = child\unwrap T.sym
with node = scope\get name
new_scope\set name, node