vararg bubbling works for block_exp

This commit is contained in:
leaf corcoran 2011-10-12 21:03:10 -07:00
parent cec8ba5f6f
commit a2f9ca0743
7 changed files with 175 additions and 44 deletions

View File

@ -61,6 +61,7 @@ Line = (function(_parent_0)
local c = self[i]
insert(buff, (function()
if util.moon.type(c) == Block then
c:bubble()
return c:render()
else
return c
@ -98,6 +99,13 @@ Block_ = (function(_parent_0)
footer = "end",
export_all = false,
export_proper = false,
bubble = function(self, other)
if other == nil then
other = self.parent
end
local has_varargs = self.has_varargs and not self:has_name("...")
other.has_varargs = other.has_varargs or has_varargs
end,
line_table = function(self)
return self._posmap
end,

View File

@ -42,6 +42,7 @@ class Line
for i = 1,#self
c = self[i]
insert buff, if util.moon.type(c) == Block
c\bubble!
c\render!
else
c
@ -68,6 +69,11 @@ class Block_
else
@indent = 0
-- bubble properties into parent
bubble: (other=@parent) =>
has_varargs = @has_varargs and not @has_name "..."
other.has_varargs = other.has_varargs or has_varargs
line_table: =>
@_posmap

View File

@ -0,0 +1,28 @@
-- vararg bubbling
f = (...) -> #{...}
dont_bubble = ->
[x for x in ((...)-> print ...)("hello")]
k = [x for x in ((...)-> print ...)("hello")]
j = for i=1,10
(...) -> print ...
-- bubble me
m = (...) ->
[x for x in *{...} when f(...) > 4]
x = for i in *{...} do i
y = [x for x in *{...}]
z = [x for x in hallo when f(...) > 4]
a = for i=1,10 do ...
b = for i=1,10
-> print ...

View File

@ -58,17 +58,10 @@ print y for y in *x[2:]
print y for y in *x[::2]
print y for y in *x[2::2]
-- vararg bubbling
f = (...) -> #{...}
x = (...) ->
[x*x for x in *{...} when f(...) > 4]
normal = (hello) ->
[x for x in yeah]
dont_bubble = ->
[x for x in ((...)-> print ...)("hello")]
test = x 1,2,3,4,5
print thing for thing in *test

131
tests/outputs/bubbling.lua Normal file
View File

@ -0,0 +1,131 @@
local f
f = function(...)
return #{
...
}
end
local dont_bubble
dont_bubble = function()
return (function()
local _accum_0 = { }
local _len_0 = 0
for x in (function(...)
return print(...)
end)("hello") do
_len_0 = _len_0 + 1
_accum_0[_len_0] = x
end
return _accum_0
end)()
end
local k = (function()
local _accum_0 = { }
local _len_0 = 0
for x in (function(...)
return print(...)
end)("hello") do
_len_0 = _len_0 + 1
_accum_0[_len_0] = x
end
return _accum_0
end)()
local j = (function()
local _accum_0 = { }
local _len_0 = 0
for i = 1, 10 do
local _value_0
_value_0 = function(...)
return print(...)
end
if _value_0 ~= nil then
_len_0 = _len_0 + 1
_accum_0[_len_0] = _value_0
end
end
return _accum_0
end)()
local m
m = function(...)
return (function()
local _accum_0 = { }
local _len_0 = 0
local _list_0 = {
...
}
for _index_0 = 1, #_list_0 do
local x = _list_0[_index_0]
if f(...) > 4 then
_len_0 = _len_0 + 1
_accum_0[_len_0] = x
end
end
return _accum_0
end)()
end
local x = (function(...)
local _accum_0 = { }
local _len_0 = 0
local _list_0 = {
...
}
for _index_0 = 1, #_list_0 do
local i = _list_0[_index_0]
local _value_0 = i
if _value_0 ~= nil then
_len_0 = _len_0 + 1
_accum_0[_len_0] = _value_0
end
end
return _accum_0
end)(...)
local y = (function(...)
local _accum_0 = { }
local _len_0 = 0
local _list_0 = {
...
}
for _index_0 = 1, #_list_0 do
x = _list_0[_index_0]
_len_0 = _len_0 + 1
_accum_0[_len_0] = x
end
return _accum_0
end)(...)
local z = (function(...)
local _accum_0 = { }
local _len_0 = 0
for x in hallo do
if f(...) > 4 then
_len_0 = _len_0 + 1
_accum_0[_len_0] = x
end
end
return _accum_0
end)(...)
local a = (function(...)
local _accum_0 = { }
local _len_0 = 0
for i = 1, 10 do
local _value_0 = ...
if _value_0 ~= nil then
_len_0 = _len_0 + 1
_accum_0[_len_0] = _value_0
end
end
return _accum_0
end)(...)
local b = (function(...)
local _accum_0 = { }
local _len_0 = 0
for i = 1, 10 do
local _value_0
_value_0 = function()
return print(...)
end
if _value_0 ~= nil then
_len_0 = _len_0 + 1
_accum_0[_len_0] = _value_0
end
end
return _accum_0
end)(...)

View File

@ -246,29 +246,6 @@ for _index_0 = 2, #_list_6, 2 do
local y = _list_6[_index_0]
print(y)
end
local f
f = function(...)
return #{
...
}
end
x = function(...)
return (function()
local _accum_0 = { }
local _len_0 = 0
local _list_7 = {
...
}
for _index_0 = 1, #_list_7 do
x = _list_7[_index_0]
if f(...) > 4 then
_len_0 = _len_0 + 1
_accum_0[_len_0] = x * x
end
end
return _accum_0
end)()
end
local normal
normal = function(hello)
return (function()
@ -281,20 +258,6 @@ normal = function(hello)
return _accum_0
end)()
end
local dont_bubble
dont_bubble = function()
return (function()
local _accum_0 = { }
local _len_0 = 0
for x in (function(...)
return print(...)
end)("hello") do
_len_0 = _len_0 + 1
_accum_0[_len_0] = x
end
return _accum_0
end)()
end
local test = x(1, 2, 3, 4, 5)
local _list_7 = test
for _index_0 = 1, #_list_7 do

2
todo
View File

@ -1,5 +1,7 @@
# TODO
- or= and=
- move stuff out of format that should be in types
- a do block for making a quick anon func and calling it