slices will reuse local vars for list

This commit is contained in:
leaf corcoran 2013-06-30 21:40:10 -07:00
parent 0848c1ea71
commit f04af88a8d
5 changed files with 28 additions and 21 deletions

View File

@ -389,6 +389,9 @@ do
if t == NameProxy or t == LocalName then
return true
end
if t == "table" and node[1] == "chain" and #node == 2 then
return self:is_local(node[2])
end
return false
end,
free_name = function(self, prefix, dont_put)

View File

@ -257,6 +257,10 @@ class Block
t = mtype node
return @has_name(node, false) if t == "string"
return true if t == NameProxy or t == LocalName
if t == "table" and node[1] == "chain" and #node == 2
return @is_local node[2]
false
free_name: (prefix, dont_put) =>

View File

@ -716,6 +716,9 @@ Statement = Transformer({
local slice = list[#list]
table.remove(list)
table.remove(slice, 1)
if self:is_local(list) then
list_name = list
end
if slice[2] and slice[2] ~= "" then
local max_tmp_name = NameProxy("max")
slice_var = build.assign_one(max_tmp_name, slice[2])

View File

@ -400,6 +400,7 @@ Statement = Transformer {
list = source[2]
index_name = NameProxy "index"
list_name = @is_local(list) and list or NameProxy "list"
slice_var = nil
@ -408,6 +409,8 @@ Statement = Transformer {
table.remove list
table.remove slice, 1
list_name = list if @is_local list
slice[2] = if slice[2] and slice[2] != ""
max_tmp_name = NameProxy "max"
slice_var = build.assign_one max_tmp_name, slice[2]

View File

@ -221,38 +221,32 @@ x = {
6,
7
}
local _list_0 = x
local _max_0 = -5
for _index_0 = 2, _max_0 < 0 and #_list_0 + _max_0 or _max_0, 2 do
local y = _list_0[_index_0]
for _index_0 = 2, _max_0 < 0 and #x + _max_0 or _max_0, 2 do
local y = x[_index_0]
print(y)
end
local _list_1 = x
local _max_1 = 3
for _index_0 = 1, _max_1 < 0 and #_list_1 + _max_1 or _max_1 do
local y = _list_1[_index_0]
for _index_0 = 1, _max_1 < 0 and #x + _max_1 or _max_1 do
local y = x[_index_0]
print(y)
end
local _list_2 = x
for _index_0 = 2, #_list_2 do
local y = _list_2[_index_0]
for _index_0 = 2, #x do
local y = x[_index_0]
print(y)
end
local _list_3 = x
for _index_0 = 1, #_list_3, 2 do
local y = _list_3[_index_0]
for _index_0 = 1, #x, 2 do
local y = x[_index_0]
print(y)
end
local _list_4 = x
for _index_0 = 2, #_list_4, 2 do
local y = _list_4[_index_0]
for _index_0 = 2, #x, 2 do
local y = x[_index_0]
print(y)
end
local a, b, c = 1, 5, 2
local _list_5 = x
local _max_2 = b
for _index_0 = a, _max_2 < 0 and #_list_5 + _max_2 or _max_2, c do
local y = _list_5[_index_0]
for _index_0 = a, _max_2 < 0 and #x + _max_2 or _max_2, c do
local y = x[_index_0]
print(y)
end
local normal
@ -274,9 +268,9 @@ for _index_0 = 1, #test do
end
local _
_ = function()
local _list_6 = rows
for _index_0 = 1, #_list_6 do
local row = _list_6[_index_0]
local _list_0 = rows
for _index_0 = 1, #_list_0 do
local row = _list_0[_index_0]
a = b
end
end