aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/collections.nom4
-rw-r--r--core/control_flow.nom21
-rw-r--r--core/io.nom4
-rw-r--r--core/metaprogramming.nom4
-rw-r--r--core/operators.nom10
5 files changed, 29 insertions, 14 deletions
diff --git a/core/collections.nom b/core/collections.nom
index 6ba806a..abd4a3a 100644
--- a/core/collections.nom
+++ b/core/collections.nom
@@ -50,10 +50,10 @@ compile [append %item to %list, add %item to %list, to %list add %item, to %list
Lua "table.insert(\(%list as lua expr), \(%item as lua expr))"
compile [pop from %list, remove last from %list] to
- Lua "table.remove(\(%list as lua expr))"
+ Lua value "table.remove(\(%list as lua expr))"
compile [remove index %index from %list] to
- Lua "table.remove(\(%list as lua expr), \(%index as lua expr))"
+ Lua value "table.remove(\(%list as lua expr), \(%index as lua expr))"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/core/control_flow.nom b/core/control_flow.nom
index 4a007df..9aae937 100644
--- a/core/control_flow.nom
+++ b/core/control_flow.nom
@@ -135,6 +135,11 @@ compile [stop %var] to
compile [do next %var] to
Lua "goto continue_\(%var as lua identifier)"
+compile [=== stop %var ===, --- stop %var ---, *** stop %var ***] to
+ Lua "::stop_\(%var as lua identifier)::"
+compile [=== next %var ===, --- next %var ---, *** next %var ***] to
+ Lua "::continue_\(%var as lua identifier)::"
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Numeric range for loops
@@ -153,7 +158,7 @@ compile [..]
(%.type = "Action") and
(%.stub is "do next %") and
%.(3).1 = %var.1
- ..: to %lua write "\n ::continue_\(%var as lua identifier)::"
+ ..: to %lua write "\n \(compile as: === next %var ===)"
to %lua write "\nend --numeric for-loop"
if
@@ -166,7 +171,7 @@ compile [..]
Lua ".."
do -- scope for stopping for-loop
\%lua
- ::stop_\(%var as lua identifier)::
+ \(compile as: === stop %var ===)
end -- end of scope for stopping for-loop
return %lua
@@ -188,7 +193,7 @@ compile [for %var in %iterable %body] to
(%.type = "Action") and
(%.stub is "do next %") and
%.3.(1) = %var.(1)
- ..: to %lua write (Lua "\n::continue_\(%var as lua identifier)::")
+ ..: to %lua write (Lua "\n\(compile as: === next %var ===)")
to %lua write "\nend --foreach-loop"
if
%body has subtree % where
@@ -200,7 +205,7 @@ compile [for %var in %iterable %body] to
Lua ".."
do -- scope for stopping for-loop
\%lua
- ::stop_\(%var as lua identifier)::
+ \(compile as: === stop %var ===)
end -- end of scope for stopping for-loop
return %lua
@@ -221,14 +226,14 @@ compile [..]
(%.type = "Action") and
(%.stub is "do next %") and
%.3.(1) = %key.(1)
- ..: to %lua write (Lua "\n::continue_\(%key as lua identifier)::")
+ ..: to %lua write (Lua "\n\(compile as: === next %key ===)")
if
%body has subtree % where
(%.type = "Action") and
(%.stub is "do next %") and
%.3.(1) = %value.(1)
- ..: to %lua write (Lua "\n::continue_\(%value as lua identifier)::")
+ ..: to %lua write (Lua "\n\(compile as: === next %value ===)")
to %lua write "\nend --foreach-loop"
%stop_labels <- (Lua "")
@@ -237,14 +242,14 @@ compile [..]
(%.type = "Action") and
(%.stub is "stop %") and
%.2.(1) = %key.(1)
- ..: to %stop_labels write "\n::stop_\(%key as lua identifier)::"
+ ..: to %stop_labels write "\n\(compile as: === stop %key ===)"
if
%body has subtree % where
(%.type = "Action") and
(%.stub is "stop %") and
%.2.(1) = %value.(1)
- ..: to %stop_labels write "\n::stop_\(%value as lua identifier)::"
+ ..: to %stop_labels write "\n\(compile as: === stop %value ===)"
if: (length of "\%stop_labels") > 0
%lua <-
diff --git a/core/io.nom b/core/io.nom
index 751650d..48db71f 100644
--- a/core/io.nom
+++ b/core/io.nom
@@ -6,9 +6,9 @@ use "core/metaprogramming.nom"
compile [say %message] to
lua> ".."
if \%message.type == "Text" then
- return LuaCode(tree.source, "io.write(", \(%message as lua expr), ", '\\\\n');");
+ return LuaCode(tree.source, "print(", \(%message as lua expr), ");");
else
- return LuaCode(tree.source, "io.write(tostring(", \(%message as lua expr), "), '\\\\n');");
+ return LuaCode(tree.source, "print(tostring(", \(%message as lua expr), "));");
end
compile [ask %prompt] to
diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom
index 8911b59..1e167d0 100644
--- a/core/metaprogramming.nom
+++ b/core/metaprogramming.nom
@@ -4,7 +4,7 @@
lua> ".."
nomsu.COMPILE_ACTIONS["% -> %"] = function(nomsu, tree, \%args, \%body)
- local lua = LuaCode(tree.source, "function(")
+ local lua = LuaCode.Value(tree.source, "function(")
if AST.is_syntax_tree(\%args, "Action") then \%args = \%args:get_args() end
local lua_args = table.map(\%args, function(a) return AST.is_syntax_tree(a) and tostring(nomsu:compile(a)) or a end)
lua:concat_append(lua_args, ", ")
@@ -163,7 +163,7 @@ compile [declare locals %locals in %code] to
compile [remove free vars %vars from %code] to
Lua "\(%code as lua expr):remove_free_vars(\(%vars as lua expr));"
-parse [%lua <-write %code, to %lua write %code] as: lua> "\%lua:append(\%code);"
+compile [%lua <-write %code, to %lua write %code] to: Lua "\(%lua as lua expr):append(\(%code as lua expr));"
compile [quote %s] to
Lua value ".."
diff --git a/core/operators.nom b/core/operators.nom
index 0756751..c81760d 100644
--- a/core/operators.nom
+++ b/core/operators.nom
@@ -130,6 +130,16 @@ compile [with %assignments %body] to
\%lua
end -- 'with' block
+compile [local %var_or_vars] to
+ %lua <- (Lua "")
+ lua> ".."
+ if \%var_or_vars.type == "List" then
+ \%lua:add_free_vars(table.map(\%var_or_vars, function(v) return tostring(nomsu:compile(v)) end))
+ else
+ \%lua:add_free_vars({tostring(nomsu:compile(\%var_or_vars))})
+ end
+ return %lua
+
# Math Operators
compile [%x wrapped around %y, %x mod %y] to: Lua value "(\(%x as lua expr) % \(%y as lua expr))"