local declared before fndef to allow recursion

This commit is contained in:
leaf corcoran 2011-06-02 20:55:33 -07:00
parent 66fcb9593d
commit b9e8b3014d
4 changed files with 24 additions and 7 deletions

6
moonc
View File

@ -61,7 +61,11 @@ function compile_file(from, to)
return nil, err return nil, err
end end
local code = compile.tree(tree) local good, code = pcall(compile.tree, tree)
if not good then
return nil, "Compile critical failure: "..code
end
-- local code = compile.tree(tree)
mkdir(get_dir(to)) mkdir(get_dir(to))
local out_f = io.open(to, "w") local out_f = io.open(to, "w")

View File

@ -416,6 +416,13 @@ local compiler_index = {
end end
local compact = not block_statements[ntype(values)] and #undeclared_names == #names local compact = not block_statements[ntype(values)] and #undeclared_names == #names
-- if there is an fndef in there, don't do compact
for _, v in ipairs(values) do
if ntype(v) == "fndef" then
compact = false
break
end
end
local lines = {} local lines = {}
local num_undeclared = #undeclared_names local num_undeclared = #undeclared_names

View File

@ -54,8 +54,10 @@ for z in items do
end end
end end
require("util") require("util")
local dump = function(x) return print(util.dump(x)) end local dump
local range = function(count) dump = function(x) return print(util.dump(x)) end
local range
range = function(count)
local i = 0 local i = 0
return(coroutine.wrap(function() return(coroutine.wrap(function()
while i < count do while i < count do

View File

@ -1,4 +1,5 @@
local x = function() return print(what) end local x
x = function() return print(what) end
local _ = function() end local _ = function() end
_ = function() _ = function()
return function() return function() end end return function() return function() end end
@ -7,9 +8,11 @@ go(to(the(barn)))
open(function() return the(function() return door end) end) open(function() return the(function() return door end) end)
open(function() open(function()
the(door) the(door)
local hello = function() return my(func) end local hello
hello = function() return my(func) end
end) end)
local h = function() return hi end local h
h = function() return hi end
eat(function() end, world) eat(function() end, world)
local a = 1 + 2 * 3 / 6 local a = 1 + 2 * 3 / 6
local bunch, go, here local bunch, go, here
@ -17,7 +20,8 @@ a, bunch, go, here = another, world
func(arg1, arg2, another, arg3) func(arg1, arg2, another, arg3)
local we local we
here, we = function() end, yeah here, we = function() end, yeah
local the, different = function() return approach end, yeah local the, different
the, different = function() return approach end, yeah
dad() dad()
dad(lord) dad(lord)
hello(one, two)(); hello(one, two)();