don't evaluate apply to last until the node is transormed

This commit is contained in:
leaf corcoran 2013-06-10 13:10:56 -07:00
parent 2b4ff60943
commit aa2d411693
4 changed files with 23 additions and 5 deletions

View File

@ -242,7 +242,8 @@ local statement_compilers = {
_with_0:stms(node[2])
return _with_0
end
end
end,
noop = function(self) end
}
return {
statement_compilers = statement_compilers

View File

@ -135,5 +135,7 @@ statement_compilers =
with @block!
\stms node[2]
noop: => -- nothing!
{ :statement_compilers }

View File

@ -67,7 +67,11 @@ apply_to_last = function(stms, fn)
local _len_0 = 1
for i, stm in ipairs(stms) do
if i == last_exp_id then
_accum_0[_len_0] = fn(stm)
_accum_0[_len_0] = {
"transform",
stm,
fn
}
else
_accum_0[_len_0] = stm
end
@ -331,6 +335,11 @@ construct_comprehension = function(inner, clauses)
return current_stms[1]
end
local Statement = Transformer({
transform = function(self, tuple)
local _, node, fn
_, node, fn = tuple[1], tuple[2], tuple[3]
return fn(node)
end,
root_stms = function(self, body)
return apply_to_last(body, implicitly_return(self))
end,
@ -1354,7 +1363,9 @@ implicitly_return = function(scope)
return scope.transform.statement(stm, fn)
elseif types.manual_return[t] or not types.is_value(stm) then
if is_top and t == "return" and stm[2] == "" then
return nil
return {
"noop"
}
else
return stm
end

View File

@ -32,7 +32,7 @@ apply_to_last = (stms, fn) ->
return for i, stm in ipairs stms
if i == last_exp_id
fn stm
{"transform", stm, fn}
else
stm
@ -150,6 +150,10 @@ construct_comprehension = (inner, clauses) ->
current_stms[1]
Statement = Transformer {
transform: (tuple) =>
{_, node, fn} = tuple
fn node
root_stms: (body) =>
apply_to_last body, implicitly_return @
@ -743,7 +747,7 @@ implicitly_return = (scope) ->
elseif types.manual_return[t] or not types.is_value stm
-- remove blank return statement
if is_top and t == "return" and stm[2] == ""
nil
{"noop"}
else
stm
else