diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-09-16 17:52:59 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-09-16 17:53:26 -0700 |
| commit | e3bf10196ae42463db8d702fe90a222bb7cb4d54 (patch) | |
| tree | 95948304fa2cd11e94f27c0e8b68184ec98f485d /nomsu_compiler.lua | |
| parent | f225a48367ca7b3e188bd34377f730370851e804 (diff) | |
Added support for compile actions returning syntax trees, which will get
recompiled until they produce Lua code.
Diffstat (limited to 'nomsu_compiler.lua')
| -rw-r--r-- | nomsu_compiler.lua | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/nomsu_compiler.lua b/nomsu_compiler.lua index 0fc3166..e2b0d89 100644 --- a/nomsu_compiler.lua +++ b/nomsu_compiler.lua @@ -617,7 +617,7 @@ do end NomsuCompiler.run_lua = function(self, lua) local lua_string = tostring(lua) - local run_lua_fn, err = load(lua_string, nil and tostring(source or lua.source), "t", self.environment) + local run_lua_fn, err = load(lua_string, tostring(source or lua.source), "t", self.environment) if not run_lua_fn then local line_numbered_lua = concat((function() local _accum_0 = { } @@ -702,9 +702,18 @@ do args = _accum_0 end local ret = compile_action(self, tree, unpack(args)) - if not ret then + if ret == nil then local info = debug.getinfo(compile_action, "S") - self:compile_error(tree, "The compile-time action here (" .. tostring(stub) .. ") failed to produce any Lua", "Look at the implementation of (" .. tostring(stub) .. ") in " .. tostring(info.short_src:sub(1, 200)) .. ":" .. tostring(info.linedefined) .. " and make sure it's returning Lua code.") + local filename = Source:from_string(info.source).filename + self:compile_error(tree, "The compile-time action here (" .. tostring(stub) .. ") failed to return any value.", "Look at the implementation of (" .. tostring(stub) .. ") in " .. tostring(filename) .. ":" .. tostring(info.linedefined) .. " and make sure it's returning something.") + end + if AST.is_syntax_tree(ret) then + if ret == tree then + local info = debug.getinfo(compile_action, "S") + local filename = Source:from_string(info.source).filename + self:compile_error(tree, "The compile-time action here (" .. tostring(stub) .. ") is producing an endless loop.", "Look at the implementation of (" .. tostring(stub) .. ") in " .. tostring(filename) .. ":" .. tostring(info.linedefined) .. " and make sure it's not just returning the original tree.") + end + return self:compile(ret, compile_actions) end return ret end |
