no temporary functions when returning block_exp

This commit is contained in:
leaf corcoran 2013-06-30 23:28:51 -07:00
parent 7085304207
commit c8d671a931
7 changed files with 106 additions and 73 deletions

View File

@ -108,13 +108,11 @@ extend = function(...)
return tbls[1]
end
copy = function(self)
return (function()
local _tbl_0 = { }
for key, val in pairs(self) do
_tbl_0[key] = val
end
return _tbl_0
end)()
local _tbl_0 = { }
for key, val in pairs(self) do
_tbl_0[key] = val
end
return _tbl_0
end
mixin = function(self, cls, ...)
for key, val in pairs(cls.__base) do

View File

@ -119,16 +119,14 @@ do
local strip
strip = function(t)
if "table" == type(t) then
return (function()
local _accum_0 = { }
local _len_0 = 1
for _index_0 = 1, #t do
local v = t[_index_0]
_accum_0[_len_0] = strip(v)
_len_0 = _len_0 + 1
end
return _accum_0
end)()
local _accum_0 = { }
local _len_0 = 1
for _index_0 = 1, #t do
local v = t[_index_0]
_accum_0[_len_0] = strip(v)
_len_0 = _len_0 + 1
end
return _accum_0
else
return t
end

View File

@ -210,6 +210,18 @@ with_continue_listener = function(body)
end
do
local _base_0 = {
transform_once = function(self, scope, node, ...)
if self.seen_nodes[node] then
return node
end
self.seen_nodes[node] = true
local transformer = self.transformers[ntype(node)]
if transformer then
return transformer(scope, node, ...) or node
else
return node
end
end,
transform = function(self, scope, node, ...)
if self.seen_nodes[node] then
return node
@ -314,6 +326,18 @@ Statement = Transformer({
root_stms = function(self, body)
return apply_to_last(body, implicitly_return(self))
end,
["return"] = function(self, node)
node[2] = Value:transform_once(self, node[2])
if "block_exp" == ntype(node[2]) then
local block_exp = node[2]
local block_body = block_exp[2]
local idx = #block_body
node[2] = block_body[idx]
block_body[idx] = node
return build.group(block_body)
end
return node
end,
declare_glob = function(self, node)
local names = extract_declarations(self)
if node[2] == "^" then
@ -370,7 +394,7 @@ Statement = Transformer({
}
})
elseif "comprehension" == _exp_0 or "tblcomprehension" == _exp_0 or "foreach" == _exp_0 or "for" == _exp_0 or "while" == _exp_0 then
return build.assign_one(first_name, Value.transformers[first_value[1]](self, first_value))
return build.assign_one(first_name, Value:transform_once(self, first_value))
end
end
local transformed

View File

@ -108,6 +108,16 @@ class Transformer
new: (@transformers) =>
@seen_nodes = setmetatable {}, __mode: "k"
transform_once: (scope, node, ...) =>
return node if @seen_nodes[node]
@seen_nodes[node] = true
transformer = @transformers[ntype node]
if transformer
transformer(scope, node, ...) or node
else
node
transform: (scope, node, ...) =>
return node if @seen_nodes[node]
@seen_nodes[node] = true
@ -158,6 +168,20 @@ Statement = Transformer {
root_stms: (body) =>
apply_to_last body, implicitly_return @
return: (node) =>
node[2] = Value\transform_once @, node[2]
if "block_exp" == ntype node[2]
block_exp = node[2]
block_body = block_exp[2]
idx = #block_body
node[2] = block_body[idx]
block_body[idx] = node
return build.group block_body
node
declare_glob: (node) =>
names = extract_declarations @
@ -191,8 +215,7 @@ Statement = Transformer {
}
when "comprehension", "tblcomprehension", "foreach", "for", "while"
return build.assign_one first_name,
Value.transformers[first_value[1]] @, first_value
return build.assign_one first_name, Value\transform_once @, first_value
-- bubble cascading assigns
transformed = if num_values == 1

View File

@ -77,15 +77,13 @@ split = function(str, delim)
return { }
end
str = str .. delim
return (function()
local _accum_0 = { }
local _len_0 = 1
for m in str:gmatch("(.-)" .. delim) do
_accum_0[_len_0] = m
_len_0 = _len_0 + 1
end
return _accum_0
end)()
local _accum_0 = { }
local _len_0 = 1
for m in str:gmatch("(.-)" .. delim) do
_accum_0[_len_0] = m
_len_0 = _len_0 + 1
end
return _accum_0
end
local dump
dump = function(what)

View File

@ -6,17 +6,15 @@ f = function(...)
end
local dont_bubble
dont_bubble = function()
return (function()
local _accum_0 = { }
local _len_0 = 1
for x in (function(...)
return print(...)
end)("hello") do
_accum_0[_len_0] = x
_len_0 = _len_0 + 1
end
return _accum_0
end)()
local _accum_0 = { }
local _len_0 = 1
for x in (function(...)
return print(...)
end)("hello") do
_accum_0[_len_0] = x
_len_0 = _len_0 + 1
end
return _accum_0
end
local k
do
@ -44,21 +42,19 @@ do
end
local m
m = function(...)
return (function(...)
local _accum_0 = { }
local _len_0 = 1
local _list_0 = {
...
}
for _index_0 = 1, #_list_0 do
local x = _list_0[_index_0]
if f(...) > 4 then
_accum_0[_len_0] = x
_len_0 = _len_0 + 1
end
local _accum_0 = { }
local _len_0 = 1
local _list_0 = {
...
}
for _index_0 = 1, #_list_0 do
local x = _list_0[_index_0]
if f(...) > 4 then
_accum_0[_len_0] = x
_len_0 = _len_0 + 1
end
return _accum_0
end)(...)
end
return _accum_0
end
local x
do

View File

@ -251,15 +251,13 @@ for _index_0 = a, _max_2 < 0 and #x + _max_2 or _max_2, c do
end
local normal
normal = function(hello)
return (function()
local _accum_0 = { }
local _len_0 = 1
for x in yeah do
_accum_0[_len_0] = x
_len_0 = _len_0 + 1
end
return _accum_0
end)()
local _accum_0 = { }
local _len_0 = 1
for x in yeah do
_accum_0[_len_0] = x
_len_0 = _len_0 + 1
end
return _accum_0
end
local test = x(1, 2, 3, 4, 5)
for _index_0 = 1, #test do
@ -281,14 +279,12 @@ _ = function()
end
end
return function()
return (function()
local _accum_0 = { }
local _len_0 = 1
for _index_0 = 1, #things do
x = things[_index_0]
_accum_0[_len_0] = x
_len_0 = _len_0 + 1
end
return _accum_0
end)()
local _accum_0 = { }
local _len_0 = 1
for _index_0 = 1, #things do
x = things[_index_0]
_accum_0[_len_0] = x
_len_0 = _len_0 + 1
end
return _accum_0
end