diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2019-01-25 15:49:29 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2019-01-25 15:50:51 -0800 |
| commit | a1b559a3a269bbee1ae9a33061b08a868ea52f5c (patch) | |
| tree | 51f2368c6542efe47dd2a4007ba92e22650236b9 /nomsu_compiler.moon | |
| parent | 1713a0e38f12f8ed167575ac5a84a0eb8dd59a44 (diff) | |
Added metatables for bool, number, function, coroutine. Added
run-time check to make sure precompiled code used the same version of
Lua. Methods can now be used in (* compiles to *), etc.
Diffstat (limited to 'nomsu_compiler.moon')
| -rw-r--r-- | nomsu_compiler.moon | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/nomsu_compiler.moon b/nomsu_compiler.moon index 1b3e952..068173e 100644 --- a/nomsu_compiler.moon +++ b/nomsu_compiler.moon @@ -62,8 +62,6 @@ compile = (tree)=> if compile_action args = [arg for arg in *tree when type(arg) != "string"] - -- Force Lua to avoid tail call optimization for debugging purposes - -- TODO: use tail call? ret = compile_action(@, tree, unpack(args)) if ret == nil info = debug.getinfo(compile_action, "S") @@ -92,6 +90,24 @@ compile = (tree)=> return lua when "MethodCall" + stub = tree\get_stub! + compile_action = @COMPILE_RULES[stub] + if compile_action + args = tree\get_args! + ret = compile_action(@, tree, unpack(args)) + if ret == nil + info = debug.getinfo(compile_action, "S") + filename = Source\from_string(info.source).filename + fail_at tree, + ("Compile error: The compile-time method here (#{stub}) failed to return any value. ".. + "Hint: Look at the implementation of (#{stub}) in #{filename}:#{info.linedefined} ".. + "and make sure it's returning something.") + unless SyntaxTree\is_instance(ret) + ret.source or= tree.source + return ret + if ret != tree + return @compile(ret) + lua = LuaCode\from tree.source target_lua = @compile tree[1] target_text = target_lua\text! |
