allow multiple name proxy of same type in names of for in loop

This commit is contained in:
leaf corcoran 2012-11-29 01:05:22 -08:00
parent 25b997e71f
commit 252e875833
8 changed files with 29 additions and 24 deletions

View File

@ -436,8 +436,8 @@ do
local t = ntype(node)
return value_compilers[t] ~= nil or t == "value"
end,
name = function(self, node)
return self:value(node)
name = function(self, node, ...)
return self:value(node, ...)
end,
value = function(self, node, ...)
node = self.transform.value(node)

View File

@ -279,7 +279,8 @@ class Block
value_compilers[t] != nil or t == "value"
-- line wise compile functions
name: (node) => @value node
name: (node, ...) => @value node, ...
value: (node, ...) =>
node = @transform.value node
action = if type(node) != "table"

View File

@ -185,19 +185,23 @@ local statement_compilers = {
do
local _with_0 = self:line()
_with_0:append("for ")
_with_0:append_list((function()
loop = _with_0
end
do
local _with_0 = self:block(loop)
loop:append_list((function()
local _accum_0 = { }
local _len_0 = 0
local _list_0 = names
for _index_0 = 1, #_list_0 do
local name = _list_0[_index_0]
_len_0 = _len_0 + 1
_accum_0[_len_0] = self:name(name)
_accum_0[_len_0] = _with_0:name(name, false)
end
return _accum_0
end)(), ", ")
_with_0:append(" in ")
_with_0:append_list((function()
loop:append(" in ")
loop:append_list((function()
local _accum_0 = { }
local _len_0 = 0
local _list_0 = exps
@ -208,11 +212,7 @@ local statement_compilers = {
end
return _accum_0
end)(), ",")
_with_0:append(" do")
loop = _with_0
end
do
local _with_0 = self:block(loop)
loop:append(" do")
_with_0:declare(names)
_with_0:stms(block)
return _with_0

View File

@ -100,12 +100,13 @@ statement_compilers =
loop = with @line!
\append "for "
\append_list [@name name for name in *names], ", "
\append " in "
\append_list [@value exp for exp in *exps], ","
\append " do"
with @block loop
loop\append_list [\name name, false for name in *names], ", "
loop\append " in "
loop\append_list [@value exp for exp in *exps], ","
loop\append " do"
\declare names
\stms block

View File

@ -266,8 +266,8 @@ local value_compilers = {
minus = function(self, node)
return self:line("-", self:value(node[2]))
end,
temp_name = function(self, node)
return node:get_name(self)
temp_name = function(self, node, ...)
return node:get_name(self, ...)
end,
number = function(self, node)
return node[2]

View File

@ -150,8 +150,8 @@ value_compilers =
minus: (node) =>
@line "-", @value node[2]
temp_name: (node) =>
node\get_name self
temp_name: (node, ...) =>
node\get_name self, ...
number: (node) =>
node[2]

View File

@ -48,9 +48,12 @@ local NameProxy
do
local _parent_0 = nil
local _base_0 = {
get_name = function(self, scope)
get_name = function(self, scope, dont_put)
if dont_put == nil then
dont_put = true
end
if not self.name then
self.name = scope:free_name(self.prefix, true)
self.name = scope:free_name(self.prefix, dont_put)
end
return self.name
end,

View File

@ -11,9 +11,9 @@ class NameProxy
new: (@prefix) =>
self[1] = "temp_name"
get_name: (scope) =>
get_name: (scope, dont_put=true) =>
if not @name
@name = scope\free_name @prefix, true
@name = scope\free_name @prefix, dont_put
@name
chain: (...) =>