diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2017-09-22 11:44:07 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2017-09-22 11:44:07 -0700 |
| commit | 6882862d0ff226d73bc6a010d335896c44d8cde9 (patch) | |
| tree | fe91165713eacf3f55b3884be27bd305f9ad88a2 /nomsu.moon | |
| parent | d3a5fc73bc9aa37f58b2e159a9959afb53df73e3 (diff) | |
Cleaned up code generation to have less cruft.
Diffstat (limited to 'nomsu.moon')
| -rwxr-xr-x | nomsu.moon | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -318,13 +318,19 @@ class NomsuCompiler when "Thunk" assert tree.value.type == "Block", "Non-block value in Thunk" - return [[ + lua = @tree_to_lua(tree.value) + if #tree.value.value == 1 + if ret_value = lua\match("^%s*ret = (.*)") + return ([[ + (function(compiler, vars) + return %s + end)]])\format(ret_value) + return ([[ (function(compiler, vars) local ret - ]]..@tree_to_lua(tree.value).."\n"..[[ + %s return ret - end) - ]] + end)]])\format(lua) when "Statement" -- This case here is to prevent "ret =" from getting prepended when the macro might not want it @@ -543,7 +549,9 @@ class NomsuCompiler if kind == "Expression" then error("Expected to be in statement.") inner_vars = setmetatable({}, {__index:(_,key)-> "vars[#{repr(key)}]"}) lua = @tree_to_value(vars.lua_code, inner_vars) - return "do\n#{lua}\nend", true + if not lua\match("^do\n.*\nend$") + lua = "do\n#{lua}\nend" + return lua, true @defmacro "lua expr %lua_code", (vars, kind)=> lua_code = vars.lua_code.value |
