aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/control_flow.nom34
-rw-r--r--core/coroutines.nom4
-rw-r--r--core/errors.nom6
-rw-r--r--core/metaprogramming.nom13
-rw-r--r--core/operators.nom4
-rw-r--r--core/scopes.nom2
-rw-r--r--core/text.nom2
-rw-r--r--examples/how_do_i.nom2
-rw-r--r--lib/object.nom2
-rw-r--r--lib/os.nom4
-rw-r--r--lib/things.nom2
-rw-r--r--nomsu_environment.lua4
-rw-r--r--nomsu_environment.moon3
13 files changed, 39 insertions, 43 deletions
diff --git a/core/control_flow.nom b/core/control_flow.nom
index 236c9a8..cba0777 100644
--- a/core/control_flow.nom
+++ b/core/control_flow.nom
@@ -20,7 +20,7 @@ test:
barf "conditional fail"
(if %condition %if_body) compiles to "\
..if \(%condition as lua expr) then
- \(%if_body as lua statements)
+ \(%if_body as lua)
end"
test:
@@ -31,9 +31,9 @@ test:
if %condition %if_body else %else_body, unless %condition %else_body else %if_body
..all compile to "\
..if \(%condition as lua expr) then
- \(%if_body as lua statements)
+ \(%if_body as lua)
else
- \(%else_body as lua statements)
+ \(%else_body as lua)
end"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -137,7 +137,7 @@ test:
%lua = (..)
Lua "\
..while \(%condition as lua expr) do
- \(%body as lua statements)"
+ \(%body as lua)"
if (%body has subtree \(do next)):
%lua::append "\n ::continue::"
@@ -165,7 +165,7 @@ test:
define mangler
%lua = (..)
Lua "for \(mangle "i")=1,\(%n as lua expr) do\n "
- %lua::append (%body as lua statements)
+ %lua::append (%body as lua)
if (%body has subtree \(do next)):
%lua::append "\n ::continue::"
if (%body has subtree \(do next repeat)):
@@ -216,7 +216,7 @@ test:
%step as lua expr
.. do"
- %lua::append "\n " (%body as lua statements)
+ %lua::append "\n " (%body as lua)
if (%body has subtree \(do next)):
%lua::append "\n ::continue::"
if (%body has subtree \(do next %var)):
@@ -256,7 +256,7 @@ test:
# This uses Lua's approach of only allowing loop-scoped variables in a loop
%lua = (..)
Lua "for \(mangle "i"),\(%var as lua identifier) in ipairs(\(%iterable as lua expr)) do\n "
- %lua::append (%body as lua statements)
+ %lua::append (%body as lua)
if (%body has subtree \(do next)):
%lua::append "\n ::continue::"
if (%body has subtree \(do next %var)):
@@ -277,7 +277,7 @@ test:
# This uses Lua's approach of only allowing loop-scoped variables in a loop
%lua = (..)
Lua "for \(%i as lua identifier),\(%var as lua identifier) in ipairs(\(%iterable as lua expr)) do\n "
- %lua::append (%body as lua statements)
+ %lua::append (%body as lua)
if (%body has subtree \(do next)):
%lua::append "\n ::continue::"
if (%body has subtree \(do next %var)):
@@ -318,7 +318,7 @@ test:
%iterable as lua expr
..) do"
- %lua::append "\n " (%body as lua statements)
+ %lua::append "\n " (%body as lua)
if (%body has subtree \(do next)):
%lua::append "\n ::continue::"
if (%body has subtree \(do next %key)):
@@ -387,7 +387,7 @@ test:
..need a conditional block around it. Otherwise, make sure the 'else' \
..block comes last."
- %code::append "\nelse\n " (%action as lua statements)
+ %code::append "\nelse\n " (%action as lua)
%else_allowed = (no)
..else:
%code::append %clause " "
@@ -396,7 +396,7 @@ test:
%code::append " or "
%code::append (%line.%i as lua expr)
- %code::append " then\n " (%action as lua statements)
+ %code::append " then\n " (%action as lua)
%clause = "\nelseif"
if ((size of "\%code") == 0):
@@ -445,7 +445,7 @@ test:
..need a conditional block around it. Otherwise, make sure the 'else' \
..block comes last."
- %code::append "\nelse\n " (%action as lua statements)
+ %code::append "\nelse\n " (%action as lua)
%else_allowed = (no)
..else:
%code::append %clause " "
@@ -454,7 +454,7 @@ test:
%code::append " or "
%code::append "\(mangle "branch value") == " (%line.%i as lua expr)
- %code::append " then\n " (%action as lua statements)
+ %code::append " then\n " (%action as lua)
%clause = "\nelseif"
if ((size of "\%code") == 0):
@@ -471,7 +471,7 @@ test:
# Do/finally
(do %action) compiles to "\
..do
- \(%action as lua statements)
+ \(%action as lua)
end -- do"
test:
@@ -489,10 +489,10 @@ test:
..do
local \(mangle "fell_through") = false
local \(mangle "ok"), \(mangle "ret") = pcall(function()
- \(%action as lua statements)
+ \(%action as lua)
\(mangle "fell_through") = true
end)
- \(%final_action as lua statements)
+ \(%final_action as lua)
if not \(mangle "ok") then error(ret, 0) end
if not \(mangle "fell_through") then return ret end
end"
@@ -525,7 +525,7 @@ test:
local \(mangle "stack \(%var.1)") = List{\(%structure as lua expr)}
while #\(mangle "stack \(%var.1)") > 0 do
\(%var as lua expr) = table.remove(\(mangle "stack \(%var.1)"), 1)
- \(%body as lua statements)"
+ \(%body as lua)"
if (%body has subtree \(do next)):
%lua::append "\n ::continue::"
if (%body has subtree \(do next %var)):
diff --git a/core/coroutines.nom b/core/coroutines.nom
index 782c20e..27797fa 100644
--- a/core/coroutines.nom
+++ b/core/coroutines.nom
@@ -18,11 +18,11 @@ test:
assume (%nums == [4, 5, 6, 6, 6]) or barf "Coroutine iteration failed"
[coroutine %body, generator %body] all compile to "\
..(function()
- \(%body as lua statements)
+ \(%body as lua)
end)"
(-> %) compiles to "coroutine.yield(true, \((% as lua expr) if % else "nil"))"
(for % in coroutine %co %body) compiles to "\
..for _junk,\(% as lua expr) in coroutine.wrap(\(%co as lua expr)) do
- \(%body as lua statements)
+ \(%body as lua)
end"
diff --git a/core/errors.nom b/core/errors.nom
index b2222ee..7cec344 100644
--- a/core/errors.nom
+++ b/core/errors.nom
@@ -63,16 +63,16 @@ test:
local fell_through = false
local err, erred = nil, false
local ok, ret = xpcall(function()
- \(%action as lua statements)
+ \(%action as lua)
fell_through = true
end, function(\(=lua "\%fallback and \(%msg as lua expr) or ''"))
local ok, ret = pcall(function()
- \((=lua "\%fallback or \%msg") as lua statements)
+ \((=lua "\%fallback or \%msg") as lua)
end)
if not ok then err, erred = ret, true end
end)
if ok then
- \(%success as lua statements)
+ \(%success as lua)
if not fell_through then
return ret
end
diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom
index 2ae8b1b..1f787c2 100644
--- a/core/metaprogramming.nom
+++ b/core/metaprogramming.nom
@@ -233,17 +233,10 @@ test:
[%action parses as %body] all parse as ([%action] all parse as %body)
(%tree as lua expr) compiles to "\
- ..compile(\(=lua "compile(\%tree, nil, true)"), nil, true)"
+ ..compile(\(=lua "compile(\%tree, true)"), true)"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-(%tree as lua) compiles to "compile(\(%tree as lua expr))"
-(%tree as lua statements) compiles to "\
- ..compile(\(%tree as lua expr)):as_statements()"
-
-(%tree as lua return) compiles to "\
- ..compile(\(%tree as lua expr)):as_statements('return ')"
-
externally [%var as lua identifier, %var as lua id] all mean:
lua> "\
..if lua_type_of(\%var) == 'string' then return \%var:as_lua_id()
@@ -265,7 +258,7 @@ externally (% is %kind syntax tree) means (..)
(%tree with %t -> %replacement) compiles to "\
..\(%tree as lua expr):map(function(\(%t as lua expr))
- \(%replacement as lua return)
+ \((%replacement as lua) if (%replacement.type == "Block") else ("return \(%replacement as lua expr)"))
end)"
externally (%tree with vars %replacements) means (..)
@@ -393,7 +386,7 @@ test:
--local compile = _1_forked(compile)
local old_action = compile.action
compile.action = _1_forked(old_action)
- \(%body as lua statements)
+ \(%body as lua)
compile.action = old_action
end"
diff --git a/core/operators.nom b/core/operators.nom
index 66185f7..38fc9a8 100644
--- a/core/operators.nom
+++ b/core/operators.nom
@@ -94,7 +94,7 @@ test:
assume ((%foozle == "inner") and (%y == "outer")) or barf "\
..'with external' failed."
(with external %externs %body) compiles to:
- %body_lua = (%body as lua statements)
+ %body_lua = (%body as lua)
lua> "\
..\%body_lua:remove_free_vars(table.map(\%externs, function(v) return compile(v):text() end))"
return %body_lua
@@ -109,7 +109,7 @@ test:
assume (%x == 1) or barf "'with' scoping failed"
assume (%z == (nil)) or barf "'with' scoping failed"
(with %assignments %body) compiles to:
- %lua = (%body as lua statements)
+ %lua = (%body as lua)
lua> "\
..local lhs, rhs = LuaCode(tree.source), LuaCode(tree.source)
local vars = {}
diff --git a/core/scopes.nom b/core/scopes.nom
index 47960d8..bd8b8a6 100644
--- a/core/scopes.nom
+++ b/core/scopes.nom
@@ -23,7 +23,7 @@ test:
assume ((foo) == "outer foo")
[with local %locals %body, with local %locals do %body] all compile to:
- %body_lua = (%body as lua statements)
+ %body_lua = (%body as lua)
if %locals.type is:
"Dict":
%body_lua = (..)
diff --git a/core/text.nom b/core/text.nom
index 1e297aa..2d72f01 100644
--- a/core/text.nom
+++ b/core/text.nom
@@ -38,7 +38,7 @@ test:
for \(%match as lua expr) in (\(%text as lua expr)):gmatch(\(..)
%patt as lua expr
..) do
- \(mangle "comprehension")[#\(mangle "comprehension")+1] = \(%expr as lua statements)
+ \(mangle "comprehension")[#\(mangle "comprehension")+1] = \(%expr as lua)
end
return \(mangle "comprehension")
end)()"
diff --git a/examples/how_do_i.nom b/examples/how_do_i.nom
index afa63e0..4dba722 100644
--- a/examples/how_do_i.nom
+++ b/examples/how_do_i.nom
@@ -267,7 +267,7 @@ say "The square root of 2 is \(square root of 2)"
# Or to transform nomsu code into custom lua code using "compile % to %"
(debug only %body) compiles to:
if %DEBUG_ENABLED:
- return (Lua "-- Debug code:\n\(%body as lua statements)")
+ return (Lua "-- Debug code:\n\(%body as lua)")
..else:
return (Lua "-- (debug code removed for production)")
diff --git a/lib/object.nom b/lib/object.nom
index 101499d..2af5412 100644
--- a/lib/object.nom
+++ b/lib/object.nom
@@ -101,7 +101,7 @@ test:
class.__tostring = function(inst)
return inst.name..getmetatable(_Dict{}).__tostring(inst)
end
- \(%class_body as lua statements)
+ \(%class_body as lua)
for stub,metamethod in pairs(globals.METAMETHOD_MAP) do
class[metamethod] = class[stub:as_lua_id()]
end
diff --git a/lib/os.nom b/lib/os.nom
index 64b46c2..fb705dc 100644
--- a/lib/os.nom
+++ b/lib/os.nom
@@ -23,7 +23,7 @@ test:
for file %f in "core": do nothing
(for file %f in %path %body) compiles to "\
..for i,\(%f as lua expr) in Files.walk(\(%path as lua expr)) do
- \(%body as lua statements)
+ \(%body as lua)
\(what (===next %f ===) compiles to)
end
\(what (===stop %f ===) compiles to)"
@@ -32,7 +32,7 @@ test:
..(function()
local ret = List{}
for i,\(%f as lua expr) in Files.walk(\(%path as lua expr)) do
- ret[#ret+1] = \(%expr as lua statements)
+ ret[#ret+1] = \(%expr as lua)
end
return ret
end)()"
diff --git a/lib/things.nom b/lib/things.nom
index f11ca23..4f15e68 100644
--- a/lib/things.nom
+++ b/lib/things.nom
@@ -124,7 +124,7 @@ test:
class.__tostring = function(inst)
return inst.name..dict_tostring(inst)
end
- \(%class_body as lua statements)
+ \(%class_body as lua)
for stub,metamethod in pairs(globals.METAMETHOD_MAP) do
class[metamethod] = class[stub:as_lua_id()]
end
diff --git a/nomsu_environment.lua b/nomsu_environment.lua
index 4735561..e72eb20 100644
--- a/nomsu_environment.lua
+++ b/nomsu_environment.lua
@@ -51,6 +51,7 @@ do
local _obj_0 = require("nomsu_decompiler")
tree_to_nomsu, tree_to_inline_nomsu = _obj_0.tree_to_nomsu, _obj_0.tree_to_inline_nomsu
end
+local compile = require('nomsu_compiler')
local nomsu_environment = Importer({
NOMSU_COMPILER_VERSION = 12,
NOMSU_SYNTAX_VERSION = max_parser_version,
@@ -105,7 +106,8 @@ local nomsu_environment = Importer({
SOURCE_MAP = Importer({ }),
_1_as_nomsu = tree_to_nomsu,
_1_as_inline_nomsu = tree_to_inline_nomsu,
- compile = require('nomsu_compiler'),
+ compile = compile,
+ _1_as_lua = compile,
_1_forked = _1_forked,
import_to_1_from = import_to_1_from,
_1_parsed = function(nomsu_code)
diff --git a/nomsu_environment.moon b/nomsu_environment.moon
index 4802ce7..b216242 100644
--- a/nomsu_environment.moon
+++ b/nomsu_environment.moon
@@ -31,6 +31,7 @@ for version=1,999
Parsers[version] = make_parser(peg_contents, make_tree)
{:tree_to_nomsu, :tree_to_inline_nomsu} = require "nomsu_decompiler"
+compile = require('nomsu_compiler')
nomsu_environment = Importer{
NOMSU_COMPILER_VERSION: 12, NOMSU_SYNTAX_VERSION: max_parser_version
-- Lua stuff:
@@ -50,7 +51,7 @@ nomsu_environment = Importer{
-- Nomsu functions:
_1_as_nomsu:tree_to_nomsu, _1_as_inline_nomsu:tree_to_inline_nomsu
- compile: require('nomsu_compiler')
+ compile: compile, _1_as_lua: compile,
:_1_forked, :import_to_1_from
_1_parsed: (nomsu_code)->