aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/control_flow.nom23
-rw-r--r--lib/object.nom34
-rw-r--r--nomsu.lua4
-rwxr-xr-xnomsu.moon4
-rw-r--r--tests/control_flow.nom5
-rw-r--r--tests/object.nom2
6 files changed, 36 insertions, 36 deletions
diff --git a/core/control_flow.nom b/core/control_flow.nom
index 9120356..77e55c6 100644
--- a/core/control_flow.nom
+++ b/core/control_flow.nom
@@ -373,11 +373,11 @@ immediately
end)
if ok then
\(%success as lua statements)
- end
- if not ok then
+ if not fell_through then
+ return ret
+ end
+ else
\(%fallback as lua statements)
- elseif not fell_through then
- return ret
end
end
parse [try %action] as
@@ -401,19 +401,14 @@ immediately
Lua ".."
do
local fell_through = false
- local ok, ret1 = pcall(function()
+ local ok, ret = pcall(function()
\(%action as lua statements)
fell_through = true
end)
- local ok2, ret2 = pcall(function()
- \(%final_action as lua statements)
- end)
- if not ok then error(ret1) end
- if not ok2 then error(ret2) end
- if not fell_through then
- return ret1
- end
- end --do-then-always
+ \(%final_action as lua statements)
+ if not ok then error(ret) end
+ if not fell_through then return ret end
+ end
# Inline thunk:
immediately
diff --git a/lib/object.nom b/lib/object.nom
index 9229d21..eb9beb8 100644
--- a/lib/object.nom
+++ b/lib/object.nom
@@ -11,22 +11,26 @@ action [new %classname %inst]
immediately
parse [new %classname] as: new %classname {}
-parse [as %instance %body] as
- lua> "local self;"
- do
- using
- lua> ".."
- self = \%instance
- local cls = self.class
- local old_self = self.class:set_self(self)
- ACTIONS = cls.ACTIONS
- COMPILE_ACTIONS = cls.COMPILE_ACTIONS
- ARG_ORDERS = cls.ARG_ORDERS
- ..do
- %body
- ..then always
- lua> ".."
+compile [as %instance %body] to
+ Lua ".."
+ do
+ local self = \(%instance as lua expr)
+ local old_self = self.class:set_self(self)
+ old_actions, ACTIONS = ACTIONS, self.class.ACTIONS
+ old_compile_actions, COMPILE_ACTIONS = COMPILE_ACTIONS, self.class.COMPILE_ACTIONS
+ old_arg_orders, ARG_ORDERS = ARG_ORDERS, self.class.ARG_ORDERS
+ local fell_through = false
+ local ok, ret = pcall(function()
+ \(%body as lua statements)
+ fell_through = true
+ end)
self.class:set_self(old_self)
+ ACTIONS = old_actions
+ COMPILE_ACTIONS = old_compile_actions
+ ARG_ORDERS = old_arg_orders
+ if not ok then error(ret) end
+ if not fell_through then return ret end
+ end
parse [object %classname %class_body] as
using
diff --git a/nomsu.lua b/nomsu.lua
index 5a51cb3..729a0d2 100644
--- a/nomsu.lua
+++ b/nomsu.lua
@@ -1339,10 +1339,10 @@ do
varname = (NOMSU_DEFS.ident_char ^ 1 * ((-P("'") * NOMSU_DEFS.operator_char ^ 1) + NOMSU_DEFS.ident_char ^ 1) ^ 0) ^ -1
}
end
- stub_pattern = re.compile([=[ stub <- {| tok ([ ]* tok)* |} !.
+ stub_pattern = re.compile([=[ stub <- {| tok (([ ])* tok)* |} !.
tok <- ({'%'} %varname) / {%word}
]=], stub_defs)
- var_pattern = re.compile("{| ((('%' {%varname}) / %word) [ ]*)+ !. |}", stub_defs)
+ var_pattern = re.compile("{| ((('%' {%varname}) / %word) ([ ])*)+ !. |}", stub_defs)
_running_files = { }
MAX_LINE = 80
math_expression = re.compile([[ ([+-] " ")* "%" (" " [*/^+-] (" " [+-])* " %")+ !. ]])
diff --git a/nomsu.moon b/nomsu.moon
index 6d53d58..232e759 100755
--- a/nomsu.moon
+++ b/nomsu.moon
@@ -290,10 +290,10 @@ class NomsuCompiler
varname: (.ident_char^1 * ((-P("'") * .operator_char^1) + .ident_char^1)^0)^-1
}
stub_pattern = re.compile [=[
- stub <- {| tok ([ ]* tok)* |} !.
+ stub <- {| tok (([ ])* tok)* |} !.
tok <- ({'%'} %varname) / {%word}
]=], stub_defs
- var_pattern = re.compile "{| ((('%' {%varname}) / %word) [ ]*)+ !. |}", stub_defs
+ var_pattern = re.compile "{| ((('%' {%varname}) / %word) ([ ])*)+ !. |}", stub_defs
define_action: (signature, fn, is_compile_action=false)=>
if type(fn) != 'function'
error("Not a function: #{repr fn}")
diff --git a/tests/control_flow.nom b/tests/control_flow.nom
index 40b344f..886b59c 100644
--- a/tests/control_flow.nom
+++ b/tests/control_flow.nom
@@ -178,9 +178,10 @@ try
do
barf
..then always
- %x <- 1
+ %x <- 3
..and if it barfs: do nothing
-assume (%x = 1) or barf "do/then always failed"
+lua> "collectgarbage()"
+assume (%x = 3) or barf "do/then always failed"
say "Control flow test passed."
diff --git a/tests/object.nom b/tests/object.nom
index aeeb559..041b784 100644
--- a/tests/object.nom
+++ b/tests/object.nom
@@ -26,9 +26,9 @@ as: new "Dog" {barks:1}
action [foo]
as: new "Dog" {barks:23}
return: (me).barks
- barf "Reached unreachable code"
assume: (foo) = 23
+..or barf: "Oops, \(foo) != 23"
as: new "Dog" {barks:101}
try: as (new "Dog" {barks:8}) (barf)