aboutsummaryrefslogtreecommitdiff
path: root/nomsu_compiler.lua
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2019-01-25 15:49:29 -0800
committerBruce Hill <bruce@bruce-hill.com>2019-01-25 15:50:51 -0800
commita1b559a3a269bbee1ae9a33061b08a868ea52f5c (patch)
tree51f2368c6542efe47dd2a4007ba92e22650236b9 /nomsu_compiler.lua
parent1713a0e38f12f8ed167575ac5a84a0eb8dd59a44 (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.lua')
-rw-r--r--nomsu_compiler.lua26
1 files changed, 26 insertions, 0 deletions
diff --git a/nomsu_compiler.lua b/nomsu_compiler.lua
index 7e562ea..096cdd1 100644
--- a/nomsu_compiler.lua
+++ b/nomsu_compiler.lua
@@ -52,6 +52,14 @@ local math_expression = re.compile([[ (([*/^+-] / [0-9]+) " ")* [*/^+-] !. ]])
local MAX_LINE = 80
local compile
compile = function(self, tree)
+ if not (SyntaxTree:is_instance(tree)) then
+ do
+ local as_lua = tree.as_lua
+ if as_lua then
+ return as_lua(tree)
+ end
+ end
+ end
local _exp_0 = tree.type
if "Action" == _exp_0 then
local stub = tree.stub
@@ -119,6 +127,24 @@ compile = function(self, tree)
lua:add(")")
return lua
elseif "MethodCall" == _exp_0 then
+ local stub = tree:get_stub()
+ local compile_action = self.COMPILE_RULES[stub]
+ if compile_action then
+ local args = tree:get_args()
+ local ret = compile_action(self, tree, unpack(args))
+ if ret == nil then
+ local info = debug.getinfo(compile_action, "S")
+ local filename = Source:from_string(info.source).filename
+ fail_at(tree, ("Compile error: The compile-time method here (" .. tostring(stub) .. ") failed to return any value. " .. "Hint: Look at the implementation of (" .. tostring(stub) .. ") in " .. tostring(filename) .. ":" .. tostring(info.linedefined) .. " " .. "and make sure it's returning something."))
+ end
+ if not (SyntaxTree:is_instance(ret)) then
+ ret.source = ret.source or tree.source
+ return ret
+ end
+ if ret ~= tree then
+ return self:compile(ret)
+ end
+ end
local lua = LuaCode:from(tree.source)
local target_lua = self:compile(tree[1])
local target_text = target_lua:text()