let colon stubs in assignments get simplified

This commit is contained in:
leaf corcoran 2014-02-05 09:29:39 -08:00
parent a926e96813
commit 9d2665f8dc
4 changed files with 30 additions and 16 deletions

View File

@ -378,6 +378,11 @@ Statement = Transformer({
if num_names == 1 and num_values == 1 then
local first_value = values[1]
local first_name = names[1]
local first_type = ntype(first_value)
if first_type == "chain" then
first_value = Value:transform_once(self, first_value)
first_type = ntype(first_value)
end
local _exp_0 = ntype(first_value)
if "block_exp" == _exp_0 then
local block_body = first_value[2]
@ -397,6 +402,8 @@ 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:transform_once(self, first_value))
else
values[1] = first_value
end
end
local transformed
@ -1538,7 +1545,7 @@ Value = Transformer({
local base_name = NameProxy("base")
local fn_name = NameProxy("fn")
local is_super = ntype(node[2]) == "ref" and node[2][2] == "super"
return self.transform.value(build.block_exp({
return build.block_exp({
build.assign({
names = {
base_name
@ -1580,7 +1587,7 @@ Value = Transformer({
})
}
})
}))
})
end
end,
block_exp = function(self, node)

View File

@ -206,6 +206,12 @@ Statement = Transformer {
if num_names == 1 and num_values == 1
first_value = values[1]
first_name = names[1]
first_type = ntype first_value
-- reduce colon stub chain to block exp
if first_type == "chain"
first_value = Value\transform_once @, first_value
first_type = ntype first_value
switch ntype first_value
when "block_exp"
@ -220,6 +226,8 @@ Statement = Transformer {
when "comprehension", "tblcomprehension", "foreach", "for", "while"
return build.assign_one first_name, Value\transform_once @, first_value
else
values[1] = first_value
-- bubble cascading assigns
transformed = if num_values == 1
@ -922,7 +930,7 @@ Value = Transformer {
fn_name = NameProxy "fn"
is_super = ntype(node[2]) == "ref" and node[2][2] == "super"
@transform.value build.block_exp {
build.block_exp {
build.assign {
names: {base_name}
values: {node}

View File

@ -266,13 +266,11 @@ do
local _base_0 = {
val = 2323,
something = function(self)
return (function()
local _base_1 = _parent_0
local _fn_0 = _base_1.something
return function(...)
return _fn_0(self, ...)
end
end)()
local _base_1 = _parent_0
local _fn_0 = _base_1.something
return function(...)
return _fn_0(self, ...)
end
end
}
_base_0.__index = _base_0

View File

@ -4,19 +4,20 @@ local x = {
return print(self.val)
end
}
local fn = (function()
local fn
do
local _base_0 = x
local _fn_0 = _base_0.val
return function(...)
fn = function(...)
return _fn_0(_base_0, ...)
end
end)()
end
print(fn())
print(x:val())
x = (function(...)
do
local _base_0 = hello(...)
local _fn_0 = _base_0.world
return function(...)
x = function(...)
return _fn_0(_base_0, ...)
end
end)(...)
end