don't create unecessary function with tblcomp and assign single

This commit is contained in:
leaf corcoran 2013-06-30 21:06:31 -07:00
parent 7735804508
commit 82f73842d8
3 changed files with 29 additions and 36 deletions

View File

@ -369,16 +369,8 @@ Statement = Transformer({
block_body
}
})
elseif "comprehension" == _exp_0 then
local a = Accumulator()
local action
action = function(exp)
return a:mutate_body({
exp
})
end
node = self.transform.statement(first_value, action, node)
return build.assign_one(first_name, a:wrap(node))
elseif "comprehension" == _exp_0 or "tblcomprehension" == _exp_0 then
return build.assign_one(first_name, Value.transformers[first_value[1]](self, first_value))
end
end
local transformed

View File

@ -190,11 +190,9 @@ Statement = Transformer {
{"do", block_body}
}
when "comprehension"
a = Accumulator!
action = (exp) -> a\mutate_body { exp }
node = @transform.statement first_value, action, node
return build.assign_one first_name, a\wrap node
when "comprehension", "tblcomprehension"
return build.assign_one first_name,
Value.transformers[first_value[1]] @, first_value
-- bubble cascading assigns
transformed = if num_values == 1

View File

@ -6,35 +6,38 @@ local items = {
5,
6
}
local out = (function()
local out
do
local _tbl_0 = { }
for k in items do
_tbl_0[k] = k * 2
end
return _tbl_0
end)()
out = _tbl_0
end
local x = {
hello = "world",
okay = 2323
}
local copy = (function()
local copy
do
local _tbl_0 = { }
for k, v in pairs(x) do
if k ~= "okay" then
_tbl_0[k] = v
end
end
return _tbl_0
end)()
local _ = (function()
copy = _tbl_0
end
local _
do
local _tbl_0 = { }
for x in yes do
local _key_0, _val_0 = unpack(x)
_tbl_0[_key_0] = _val_0
end
return _tbl_0
end)()
_ = (function()
_ = _tbl_0
end
do
local _tbl_0 = { }
local _list_0 = yes
for _index_0 = 1, #_list_0 do
@ -42,17 +45,17 @@ _ = (function()
local _key_0, _val_0 = unpack(x)
_tbl_0[_key_0] = _val_0
end
return _tbl_0
end)()
_ = (function()
_ = _tbl_0
end
do
local _tbl_0 = { }
for x in yes do
local _key_0, _val_0 = xxxx
_tbl_0[_key_0] = _val_0
end
return _tbl_0
end)()
_ = (function()
_ = _tbl_0
end
do
local _tbl_0 = { }
local _list_0 = {
{
@ -77,8 +80,8 @@ _ = (function()
end)())
_tbl_0[_key_0] = _val_0
end
return _tbl_0
end)()
_ = _tbl_0
end
local n1
do
local _accum_0 = { }
@ -158,11 +161,11 @@ do
end
dd = _accum_0
end
_ = (function()
do
local _tbl_0 = { }
for i = 1, 10 do
_tbl_0["hello"] = "world"
end
return _tbl_0
end)()
_ = _tbl_0
end
return nil