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
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))
local out_f = io.open(to, "w")

View File

@ -416,6 +416,13 @@ local compiler_index = {
end
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 num_undeclared = #undeclared_names

View File

@ -54,8 +54,10 @@ for z in items do
end
end
require("util")
local dump = function(x) return print(util.dump(x)) end
local range = function(count)
local dump
dump = function(x) return print(util.dump(x)) end
local range
range = function(count)
local i = 0
return(coroutine.wrap(function()
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
_ = function()
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()
the(door)
local hello = function() return my(func) end
local hello
hello = function() return my(func) end
end)
local h = function() return hi end
local h
h = function() return hi end
eat(function() end, world)
local a = 1 + 2 * 3 / 6
local bunch, go, here
@ -17,7 +20,8 @@ a, bunch, go, here = another, world
func(arg1, arg2, another, arg3)
local we
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(lord)
hello(one, two)();