aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/collections.nom13
-rw-r--r--core/control_flow.nom89
-rw-r--r--core/coroutines.nom2
-rw-r--r--core/errors.nom3
-rw-r--r--core/io.nom2
-rw-r--r--core/math.nom10
-rw-r--r--core/metaprogramming.nom33
-rw-r--r--core/operators.nom12
-rw-r--r--core/scopes.nom2
-rw-r--r--core/text.nom4
10 files changed, 60 insertions, 110 deletions
diff --git a/core/collections.nom b/core/collections.nom
index f74b24d..6f2d4c8 100644
--- a/core/collections.nom
+++ b/core/collections.nom
@@ -29,7 +29,6 @@ test:
action [%item is in %list, %list contains %item, %list has %item]:
for %key = %value in %list:
if (%key is %item): return (yes)
-
return (no)
test:
@@ -41,7 +40,6 @@ action [..]
..:
for %key = %value in %list:
if (%key is %item): return (no)
-
return (yes)
test:
@@ -94,7 +92,6 @@ parse [%expression for %item in %iterable] as (..)
%comprehension = []
for %item in %iterable:
add %expression to %comprehension
-
return %comprehension
parse [..]
@@ -105,7 +102,6 @@ parse [..]
%comprehension = []
for %index in %start to %stop via %step:
add %expression to %comprehension
-
return %comprehension
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -127,10 +123,8 @@ parse [..]
%comprehension = []
for %key = %value in %iterable:
add %expression to %comprehension
-
return %comprehension
-
# Dict comprehensions
test:
assume (((% * %) = % for % in [1, 2, 3]) == {1:1, 4:2, 9:3})
@@ -141,7 +135,6 @@ parse [%key = %value for %item in %iterable, %key %value for %item in %iterable]
%comprehension = {}
for %item in %iterable:
%comprehension.%key = %value
-
return %comprehension
test:
@@ -155,7 +148,6 @@ parse [..]
%comprehension = {}
for %src_key = %src_value in %iterable:
%comprehension.%key = %value
-
return %comprehension
parse [..]
@@ -166,7 +158,6 @@ parse [..]
%comprehension = {}
for %item in %start to %stop via %step:
%comprehension.%key = %value
-
return %comprehension
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -186,7 +177,6 @@ action [%lists flattened]:
%flat = []
for %list in %lists:
for %item in %list: add %item to %flat
-
return %flat
test:
@@ -222,7 +212,6 @@ compile [%dict with fallback %key -> %value] to (..)
return value
end})
-
# Sorting
test:
%x = [3, 1, 2]
@@ -267,4 +256,4 @@ action [unique %items]:
add % to %unique
%seen.% = (yes)
- return %unique \ No newline at end of file
+ return %unique
diff --git a/core/control_flow.nom b/core/control_flow.nom
index 3492b68..b7cdba3 100644
--- a/core/control_flow.nom
+++ b/core/control_flow.nom
@@ -76,7 +76,6 @@ compile [..]
end
end)())
-
# GOTOs
test:
%i = 0
@@ -106,13 +105,13 @@ test:
%x += 1
if (yes): do next
barf "Failed to 'do next'"
-
+
assume (%x == 20)
repeat while (%x < 30):
%x += 1
if (yes): do next repeat
barf "Failed to 'do next repeat'"
-
+
assume (%x == 30)
compile [do next repeat] to (Lua "goto continue_repeat")
@@ -125,10 +124,8 @@ compile [repeat while %condition %body] to:
if (%body has subtree \(do next)):
to %lua write "\n ::continue::"
-
if (%body has subtree \(do next repeat)):
to %lua write "\n ::continue_repeat::"
-
to %lua write "\nend --while-loop"
if (%body has subtree \(stop repeating)):
%lua = (..)
@@ -142,7 +139,6 @@ compile [repeat while %condition %body] to:
parse [repeat %body] as (repeat while (yes) %body)
parse [repeat until %condition %body] as (repeat while (not %condition) %body)
-
test:
%x = 0
repeat 10 times: %x += 1
@@ -156,10 +152,8 @@ compile [repeat %n times %body] to:
if (%body has subtree \(do next)):
to %lua write "\n ::continue::"
-
if (%body has subtree \(do next repeat)):
to %lua write "\n ::continue_repeat::"
-
to %lua write "\nend --numeric for-loop"
if (%body has subtree \(stop repeating)):
%lua = (..)
@@ -185,19 +179,21 @@ compile [===next %var ===, ---next %var ---, ***next %var ***] to (..)
test:
%nums = []
for %x in 1 to 5: add %x to %nums
- assume (%nums == [1,2,3,4,5])
+ assume (%nums == [1, 2, 3, 4, 5])
%nums = []
for %x in 1 to 5 via 2: add %x to %nums
- assume (%nums == [1,3,5])
+ assume (%nums == [1, 3, 5])
%nums = []
for %outer in 1 to 100:
for %inner in %outer to (%outer + 2):
if (%inner == 2):
add -2 to %nums
do next %inner
+
add %inner to %nums
if (%inner == 5): stop %outer
- assume (%nums == [1,-2,3,-2,3,4,3,4,5])
+
+ assume (%nums == [1, -2, 3, -2, 3, 4, 3, 4, 5])
# Numeric range for loops
compile [..]
@@ -208,20 +204,17 @@ compile [..]
# This uses Lua's approach of only allowing loop-scoped variables in a loop
unless (%var.type is "Var"):
compile error at %var.source "Loop expected variable, not: %s"
-
%lua = (..)
Lua ".."
for \(%var as lua expr)=\(%start as lua expr),\(%stop as lua expr),\(..)
%step as lua expr
.. do
\(%body as lua statements)
-
+
if (%body has subtree \(do next)):
to %lua write "\n ::continue::"
-
if (%body has subtree (\(do next %v) with vars {v:%var})):
to %lua write "\n \(compile as (===next %var ===))"
-
to %lua write "\nend --numeric for-loop"
if (%body has subtree (\(stop %v) with vars {v:%var})):
%lua = (..)
@@ -239,7 +232,7 @@ parse [for %var in %start to %stop %body] as (..)
for %var in %start to %stop via 1 %body
test:
- %a = [10,20,30,40,50]
+ %a = [10, 20, 30, 40, 50]
%b = []
for %x in %a: add %x to %b
assume (%a == %b)
@@ -248,7 +241,8 @@ test:
if (%x == 10): do next %x
if (%x == 50): stop %x
add %x to %b
- assume (%b == [20,30,40])
+
+ assume (%b == [20, 30, 40])
# For-each loop (lua's "ipairs()")
compile [for %var in %iterable %body] to:
@@ -256,7 +250,6 @@ compile [for %var in %iterable %body] to:
# This uses Lua's approach of only allowing loop-scoped variables in a loop
unless (%var.type is "Var"):
compile error at %var.source "Loop expected variable, not: %s"
-
%lua = (..)
Lua ".."
for i,\(%var as lua identifier) in ipairs(\(%iterable as lua expr)) do
@@ -264,10 +257,8 @@ compile [for %var in %iterable %body] to:
if (%body has subtree \(do next)):
to %lua write "\n ::continue::"
-
if (%body has subtree (\(do next %v) with vars {v:%var})):
to %lua write (Lua "\n\(compile as (===next %var ===))")
-
to %lua write "\nend --foreach-loop"
if (%body has subtree (\(stop %v) with vars {v:%var})):
%lua = (..)
@@ -286,6 +277,7 @@ test:
if (%k == "a"): do next %k
if (%v == 20): do next %v
add "\%k = \%v" to %result
+
assume ((%result sorted) == ["c = 30", "d = 40", "e = 50"])
# Dict iteration (lua's "pairs()")
@@ -296,34 +288,27 @@ compile [..]
# This uses Lua's approach of only allowing loop-scoped variables in a loop
unless (%key.type is "Var"):
compile error at %key.source "Loop expected variable, not: %s"
-
unless (%value.type is "Var"):
compile error at %value.source "Loop expected variable, not: %s"
-
%lua = (..)
Lua ".."
for \(%key as lua identifier),\(%value as lua identifier) in pairs(\(..)
%iterable as lua expr
..) do
\(%body as lua statements)
-
+
if (%body has subtree \(do next)):
to %lua write "\n ::continue::"
-
if (%body has subtree (\(do next %v) with vars {v:%key})):
to %lua write (Lua "\n\(compile as (===next %key ===))")
-
if (%body has subtree (\(do next %v) with vars {v:%value})):
to %lua write (Lua "\n\(compile as (===next %value ===))")
-
to %lua write "\nend --foreach-loop"
%stop_labels = (Lua "")
if (%body has subtree (\(stop %v) with vars {v:%key})):
to %stop_labels write "\n\(compile as (===stop %key ===))"
-
if (%body has subtree (\(stop %v) with vars {v:%value})):
to %stop_labels write "\n\(compile as (===stop %value ===))"
-
if ((length of "\%stop_labels") > 0):
%lua = (..)
Lua ".."
@@ -337,11 +322,15 @@ compile [..]
test:
if:
- (1 == 2) (100 < 0): barf "bad conditional"
- (1 == 0) (1 == 1) (%not_a_variable.x): do nothing
- (1 == 1): barf "bad conditional"
- (1 == 2): barf "bad conditional"
- else: barf "bad conditional"
+ (1 == 2) (100 < 0):
+ barf "bad conditional"
+ (1 == 0) (1 == 1) %not_a_variable.x: do nothing
+ (1 == 1):
+ barf "bad conditional"
+ (1 == 2):
+ barf "bad conditional"
+ else:
+ barf "bad conditional"
# Multi-branch conditional (if..elseif..else)
compile [if %body, when %body] to:
@@ -350,7 +339,6 @@ compile [if %body, when %body] to:
%else_allowed = (yes)
unless (%body.type is "Block"):
compile error at %body.source "'if' expected a Block, but got: %s"
-
for %line in %body:
unless (..)
((%line.type is "Action") and ((length of %line) >= 2)) and (..)
@@ -364,7 +352,6 @@ compile [if %body, when %body] to:
if ((%line.1 is "else") and ((length of %line) == 2)):
unless %else_allowed:
compile error at %line.source "Can't have two 'else' blocks"
-
unless ((length of "\%code") > 0):
compile error at %line.source ".."
Can't have an 'else' block without a preceeding condition
@@ -385,7 +372,6 @@ compile [if %body, when %body] to:
if (%i > 1):
to %code write " or "
-
to %code write (%line.%i as lua expr)
to %code write ".."
@@ -396,16 +382,18 @@ compile [if %body, when %body] to:
if ((length of "\%code") == 0):
compile error at %body.source "'if' block has an empty body"
-
to %code write "\nend --when"
return %code
test:
if 5 is:
- 1 2 3: barf "bad switch statement"
+ 1 2 3:
+ barf "bad switch statement"
4 5: do nothing
- 5 6: barf "bad switch statement"
- else: barf "bad switch statement"
+ 5 6:
+ barf "bad switch statement"
+ else:
+ barf "bad switch statement"
# Switch statement
compile [if %branch_value is %body, when %branch_value is %body] to:
@@ -414,7 +402,6 @@ compile [if %branch_value is %body, when %branch_value is %body] to:
%else_allowed = (yes)
unless (%body.type is "Block"):
compile error at %body.source "'if' expected a Block, but got: %s"
-
for %line in %body:
unless (..)
((%line.type is "Action") and ((length of %line) >= 2)) and (..)
@@ -428,7 +415,6 @@ compile [if %branch_value is %body, when %branch_value is %body] to:
if ((%line.1 is "else") and ((length of %line) == 2)):
unless %else_allowed:
compile error at %line.source "Can't have two 'else' blocks"
-
unless ((length of "\%code") > 0):
compile error at %line.source ".."
Can't have an 'else' block without a preceeding condition
@@ -449,7 +435,6 @@ compile [if %branch_value is %body, when %branch_value is %body] to:
if (%i > 1):
to %code write " or "
-
to %code write "branch_value == \(%line.%i as lua expr)"
to %code write ".."
@@ -460,7 +445,6 @@ compile [if %branch_value is %body, when %branch_value is %body] to:
if ((length of "\%code") == 0):
compile error at %body.source "'if % is % %' block has an empty body"
-
to %code write "\nend --when"
return (..)
Lua ".."
@@ -469,7 +453,6 @@ compile [if %branch_value is %body, when %branch_value is %body] to:
\%code
end --if % is
-
# Do/finally
compile [do %action] to (..)
Lua ".."
@@ -483,9 +466,9 @@ test:
do:
%d.x = "bad"
barf
- ..then always:
- %d.x = "good"
+ ..then always: %d.x = "good"
..and if it barfs: do nothing
+
assume (%d.x == "good")
compile [do %action then always %final_action] to (..)
@@ -502,11 +485,10 @@ compile [do %action then always %final_action] to (..)
end
test:
- assume ((result of: return 99) == 99)
+ assume ((result of (: return 99)) == 99)
# Inline thunk:
compile [result of %body] to (Lua value "(\(compile as ([] -> %body)))()")
-
test:
%t = [1, [2, [[3], 4], 5, [[[6]]]]]
%flat = []
@@ -514,7 +496,7 @@ test:
if ((type of %) is "table"):
for %2 in %: recurse % on %2
..else: add % to %flat
-
+
assume ((sorted %flat) == [1, 2, 3, 4, 5, 6])
# Recurion control flow
@@ -522,7 +504,6 @@ compile [for %var in recursive %structure %body] to (..)
with local compile actions:
compile [recurse %v on %x] to (..)
Lua "table.insert(stack\(%v as lua id), \(%x as lua expr))"
-
%lua = (..)
Lua ".."
do
@@ -530,17 +511,13 @@ compile [for %var in recursive %structure %body] to (..)
while #stack\(%var as lua id) > 0 do
\(%var as lua expr) = table.remove(stack\(%var as lua id), 1)
\(%body as lua statements)
-
+
if (%body has subtree \(do next)):
to %lua write "\n ::continue::"
-
if (%body has subtree (\(do next %v) with vars {v:%var})):
to %lua write "\n \(compile as (===next %var ===))"
-
to %lua write "\n end -- Recursive loop"
if (%body has subtree (\(stop %v) with vars {v:%var})):
to %lua write "\n \(compile as (===stop %var ===))"
-
to %lua write "\nend -- Recursive scope"
-
return %lua
diff --git a/core/coroutines.nom b/core/coroutines.nom
index 6e7d9e3..77b3cb9 100644
--- a/core/coroutines.nom
+++ b/core/coroutines.nom
@@ -11,7 +11,7 @@ test:
-> 4
-> 5
repeat 3 times: -> 6
-
+
for % in coroutine %co: add % to %nums
assume (%nums == [4, 5, 6, 6, 6]) or barf "Coroutine iteration failed"
diff --git a/core/errors.nom b/core/errors.nom
index 53b06a2..297144d 100644
--- a/core/errors.nom
+++ b/core/errors.nom
@@ -14,7 +14,6 @@ compile [compile error at %source %msg] to (..)
compile [assume %condition] to:
lua> ".."
local \%assumption = 'Assumption failed: '..tostring(nomsu:tree_to_nomsu(\%condition))
-
return (..)
Lua ".."
if not \(%condition as lua expr) then
@@ -37,7 +36,7 @@ test:
%x = 2
do (barf) then always: %x = 3
..and if it barfs: do nothing
-
+
assume (%x == 3) or barf "do/then always failed"
# Try/except
diff --git a/core/io.nom b/core/io.nom
index 0b24ca5..34fca53 100644
--- a/core/io.nom
+++ b/core/io.nom
@@ -20,4 +20,4 @@ compile [ask %prompt] to (..)
return LuaCode.Value(tree.source, "(io.write(tostring(", \(..)
%prompt as lua expr
.., ")) and io.read())");
- end \ No newline at end of file
+ end
diff --git a/core/math.nom b/core/math.nom
index 0248956..a7b873e 100644
--- a/core/math.nom
+++ b/core/math.nom
@@ -10,7 +10,8 @@ use "core/collections.nom"
# Literals:
test:
- assume (all of [inf, NaN, pi, tau, golden ratio, e]) or barf "math constants failed"
+ assume (all of [inf, NaN, pi, tau, golden ratio, e]) or barf ".."
+ math constants failed
%nan = (NaN)
assume (%nan != %nan) or barf "NaN failed"
@@ -62,7 +63,6 @@ compile [log % base %base, log base %base of %] to (..)
compile [floor %] to (Lua value "math.floor(\(% as lua expr))")
compile [ceiling %, ceil %] to (Lua value "math.ceil(\(% as lua expr))")
compile [round %, % rounded] to (Lua value "math.floor(\(% as lua expr) + .5)")
-
test:
assume ((463 to the nearest 100) == 500) or barf "rounding failed"
assume ((2.6 to the nearest 0.25) == 2.5) or barf "rounding failed"
@@ -70,12 +70,10 @@ test:
action [%n to the nearest %rounder] (..)
=lua "(\%rounder)*math.floor((\%n / \%rounder) + .5)"
-
# Any/all/none
compile [all of %items, all %items] to:
unless (%items.type is "List"):
return (Lua value "utils.all(\(%items as lua expr))")
-
%clauses = ((% as lua expr) for % in %items)
return (Lua value "(\(%clauses joined with " and "))")
@@ -83,7 +81,6 @@ parse [not all of %items, not all %items] as (not (all of %items))
compile [any of %items, any %items] to:
unless (%items.type is "List"):
return (Lua value "utils.any(\(%items as lua expr))")
-
%clauses = ((% as lua expr) for % in %items)
return (Lua value "(\(%clauses joined with " or "))")
@@ -91,14 +88,12 @@ parse [none of %items, none %items] as (not (any of %items))
compile [sum of %items, sum %items] to:
unless (%items.type is "List"):
return (Lua value "utils.sum(\(%items as lua expr))")
-
%clauses = ((% as lua expr) for % in %items)
return (Lua value "(\(%clauses joined with " + "))")
compile [product of %items, product %items] to:
unless (%items.type is "List"):
return (Lua value "utils.product(\(%items as lua expr))")
-
%clauses = ((% as lua expr) for % in %items)
return (Lua value "(\(%clauses joined with " * "))")
@@ -133,7 +128,6 @@ parse [max of %items by %item = %value_expr] as (..)
return %best
-
# Random functions
action [seed random with %] (..)
lua> ".."
diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom
index b3c4356..21743ad 100644
--- a/core/metaprogramming.nom
+++ b/core/metaprogramming.nom
@@ -30,10 +30,13 @@ lua> ".."
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-test: compile [five] to (Lua value "5")
+test:
+ compile [five] to (Lua value "5")
+
test:
assume ((five) == 5) or barf "Compile to expression failed."
compile [loc x] to (Lua "local _x = 99;")
+
test:
lua> "do"
loc x
@@ -43,6 +46,7 @@ test:
compile [asdf] to:
%tmp = ""
return (Lua %tmp)
+
test:
asdf
assume (%tmp is (nil)) or barf "compile to is leaking variables"
@@ -81,18 +85,16 @@ compile [call %fn with %args] to (..)
return lua
test:
- local action [foo %x]:
- return "outer"
-
+ local action [foo %x]: return "outer"
with local [action (foo %)]:
local action [foo %x]:
%y = (%x + 1)
return %y
-
+
assume ((foo 10) == 11) or barf "Action didn't work."
assume (%y is (nil)) or barf "Action leaked a local into globals."
parse [baz %] as (foo %)
-
+
assume ((foo 1) == "outer")
compile [local action %actions %body] to (..)
@@ -137,7 +139,6 @@ test:
assume ((action (say %)) == (=lua "A_say_1"))
compile [action %action] to (Lua value (%action as lua id))
-
test:
parse [swap %x and %y] as (..)
do:
@@ -150,7 +151,6 @@ test:
swap %1 and %2
assume ((%1 == 2) and (%2 == 1)) or barf ".."
'parse % as %' failed on 'swap % and %'
-
set {%tmp:1, %tmp2:2}
swap %tmp and %tmp2
assume ((%tmp == 2) and (%tmp2 == 1)) or barf ".."
@@ -270,10 +270,14 @@ compile [to %lua write %code joined by %glue] to (..)
\(%lua as lua expr):concat_append(\(%code as lua expr), \(%glue as lua expr));
test:
- assume ((quote "one\n\"two\"") == "\"one\\n\\\"two\\\"\"")
+ assume (..)
+ (..)
+ quote ".."
+ one
+ "two"
+ ..== "\"one\\n\\\"two\\\"\""
compile [quote %s] to (Lua value "repr(\(%s as lua expr))")
-
test:
assume ((type of {}) == "table") or barf "type of failed."
@@ -284,9 +288,7 @@ compile [type of %obj] to (Lua value "type(\(%obj as lua expr))")
test:
assume ((parse "foo %") == \(foo %))
-compile [parse %text] to (..)
- Lua value "nomsu:parse(\(%text as lua expr))"
-
+compile [parse %text] to (Lua value "nomsu:parse(\(%text as lua expr))")
compile [parse %text from %filename] to (..)
Lua value ".."
nomsu:parse(NomsuCode(Source(\(%filename as lua expr), 1, #\(%text as lua expr)), \(..)
@@ -296,7 +298,8 @@ compile [parse %text from %filename] to (..)
test:
assume ((run "return (2 + 99)") == 101)
external %passed = (no)
- run \: external %passed = (yes)
+ run \:
+ external %passed = (yes)
assume %passed
compile [run %nomsu_code] to (..)
@@ -312,14 +315,12 @@ action [run tree %tree, %tree as value] (lua> "return nomsu:run(\%tree)")
compile [compile %block, compiled %block, %block compiled] to (..)
Lua value "nomsu:compile(\(%block as lua))"
-
# Return statement is wrapped in a do..end block because Lua is unhappy if you
put code after a return statement, unless you wrap it in a block.
compile [return] to (Lua "do return; end")
compile [return %return_value] to (..)
Lua "do return \(%return_value as lua expr) end"
-
# Literals
compile [yes] to (Lua value "true")
compile [no] to (Lua value "false")
diff --git a/core/operators.nom b/core/operators.nom
index 9a836bf..0c68d18 100644
--- a/core/operators.nom
+++ b/core/operators.nom
@@ -16,7 +16,6 @@ compile [%a is %b, %a == %b] to (..)
compile [%a isn't %b, %a is not %b, %a not= %b, %a != %b] to (..)
Lua value "(\(%a as lua expr) ~= \(%b as lua expr))"
-
# For strict identity checking, use (%x's id) is (%y's id)
lua> ".."
do
@@ -59,12 +58,10 @@ compile [%var = %value] to:
end
return lua
-
# Simultaneous mutli-assignments like: x,y,z = 1,x,3;
compile [set %assignments] to:
assume (%assignments.type is "Dict") or barf ".."
Expected a Dict for the assignments part of '<- %' statement, not \%assignments
-
lua> ".."
local lhs, rhs = LuaCode(tree.source), LuaCode(tree.source)
for i, item in ipairs(\%assignments) do
@@ -107,7 +104,6 @@ compile [with external %externs %body] to:
%body_lua = (%body as lua statements)
lua> ".."
\%body_lua:remove_free_vars(table.map(\%externs, function(v) return tostring(nomsu:compile(v)) end))
-
return %body_lua
compile [with %assignments %body] to:
@@ -144,12 +140,10 @@ compile [with %assignments %body] to:
\%lua
end -- 'with' block
-
# Math Operators
compile [%x wrapped around %y, %x mod %y] to (..)
Lua value "(\(%x as lua expr) % \(%y as lua expr))"
-
# 3-part chained comparisons
# (uses a lambda to avoid re-evaluating middle value, while still being an expression)
parse [%x < %y < %z] as (..)
@@ -176,7 +170,6 @@ parse [%x > %y >= %z] as (..)
parse [%x >= %y >= %z] as (..)
=lua "(function(x,y,z) return x >= y and y >= z; end)(\%x,\%y,\%z)"
-
# TODO: optimize for common case where x,y,z are all either variables or number literals
# Boolean Operators
compile [%x and %y] to (Lua value "(\(%x as lua expr) and \(%y as lua expr))")
@@ -201,7 +194,6 @@ compile [%x RSHIFT %shift, %x >>> %shift] to (..)
compile [%x ARSHIFT %shift, %x >> %shift] to (..)
Lua value "(\(%x as lua expr) >> \(%shift as lua expr))"
-
# TODO: implement OR, XOR, AND for multiple operands?
# Unary operators
compile [- %] to (Lua value "(- \(% as lua expr))")
@@ -209,7 +201,9 @@ compile [not %] to (Lua value "(not \(% as lua expr))")
test:
assume ((length of [1, 2, 3]) == 3)
-compile [length of %list, len %list, || %list ||] to (Lua value "(#\(%list as lua expr))")
+compile [length of %list, len %list, || %list ||] to (..)
+ Lua value "(#\(%list as lua expr))"
+
compile [%list is empty] to (Lua value "(#\(%list as lua expr) == 0)")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/core/scopes.nom b/core/scopes.nom
index f9dc758..a65b030 100644
--- a/core/scopes.nom
+++ b/core/scopes.nom
@@ -20,10 +20,8 @@ compile [with local %locals %body, with local %locals do %body] to:
"List":
declare locals ("\(% as lua)" for % in %locals) in %body_lua
-
"Var" "Action":
declare locals ["\(%locals as lua)"] in %body_lua
-
else:
compile error at %locals.source "Unexpected locals: %s"
diff --git a/core/text.nom b/core/text.nom
index 40e0451..83c25f7 100644
--- a/core/text.nom
+++ b/core/text.nom
@@ -54,9 +54,7 @@ compile [%text matches %pattern] to (..)
(\(%text as lua expr):match(\(%pattern as lua expr)) and true or false)
compile [%text matching %pattern] to (..)
- Lua value ".."
- \(%text as lua expr):match(\(%pattern as lua expr))
-
+ Lua value "\(%text as lua expr):match(\(%pattern as lua expr))"
# Text literals
lua> ".."