wrap class declaration in do instead of anonymous function

This commit is contained in:
leaf corcoran 2012-10-30 23:34:42 -07:00
parent 15dab06d31
commit b6987fe6d8
6 changed files with 80 additions and 89 deletions

View File

@ -20,7 +20,7 @@ local concat, insert = table.concat, table.insert
local pos_to_line, get_closest_line, trim = util.pos_to_line, util.get_closest_line, util.trim local pos_to_line, get_closest_line, trim = util.pos_to_line, util.get_closest_line, util.trim
local mtype = util.moon.type local mtype = util.moon.type
local Line, Lines local Line, Lines
Lines = (function() do
local _parent_0 = nil local _parent_0 = nil
local _base_0 = { local _base_0 = {
mark_pos = function(self, pos, line) mark_pos = function(self, pos, line)
@ -143,9 +143,9 @@ Lines = (function()
if _parent_0 and _parent_0.__inherited then if _parent_0 and _parent_0.__inherited then
_parent_0.__inherited(_parent_0, _class_0) _parent_0.__inherited(_parent_0, _class_0)
end end
return _class_0 Lines = _class_0
end)() end
Line = (function() do
local _parent_0 = nil local _parent_0 = nil
local _base_0 = { local _base_0 = {
pos = nil, pos = nil,
@ -251,9 +251,9 @@ Line = (function()
if _parent_0 and _parent_0.__inherited then if _parent_0 and _parent_0.__inherited then
_parent_0.__inherited(_parent_0, _class_0) _parent_0.__inherited(_parent_0, _class_0)
end end
return _class_0 Line = _class_0
end)() end
Block = (function() do
local _parent_0 = nil local _parent_0 = nil
local _base_0 = { local _base_0 = {
header = "do", header = "do",
@ -578,9 +578,9 @@ Block = (function()
if _parent_0 and _parent_0.__inherited then if _parent_0 and _parent_0.__inherited then
_parent_0.__inherited(_parent_0, _class_0) _parent_0.__inherited(_parent_0, _class_0)
end end
return _class_0 Block = _class_0
end)() end
RootBlock = (function() do
local _parent_0 = Block local _parent_0 = Block
local _base_0 = { local _base_0 = {
__tostring = function(self) __tostring = function(self)
@ -636,8 +636,8 @@ RootBlock = (function()
if _parent_0 and _parent_0.__inherited then if _parent_0 and _parent_0.__inherited then
_parent_0.__inherited(_parent_0, _class_0) _parent_0.__inherited(_parent_0, _class_0)
end end
return _class_0 RootBlock = _class_0
end)() end
format_error = function(msg, pos, file_str) format_error = function(msg, pos, file_str)
local line = pos_to_line(file_str, pos) local line = pos_to_line(file_str, pos)
local line_str local line_str

View File

@ -9,7 +9,7 @@ Set = function(items)
end end
return self return self
end end
Stack = (function() do
local _parent_0 = nil local _parent_0 = nil
local _base_0 = { local _base_0 = {
__tostring = function(self) __tostring = function(self)
@ -63,8 +63,8 @@ Stack = (function()
if _parent_0 and _parent_0.__inherited then if _parent_0 and _parent_0.__inherited then
_parent_0.__inherited(_parent_0, _class_0) _parent_0.__inherited(_parent_0, _class_0)
end end
return _class_0 Stack = _class_0
end)() end
lua_keywords = Set({ lua_keywords = Set({
'and', 'and',
'break', 'break',

View File

@ -6,7 +6,7 @@ local reversed = util.reversed
local ntype, build, smart_node, is_slice, value_is_singular = types.ntype, types.build, types.smart_node, types.is_slice, types.value_is_singular local ntype, build, smart_node, is_slice, value_is_singular = types.ntype, types.build, types.smart_node, types.is_slice, types.value_is_singular
local insert = table.insert local insert = table.insert
local implicitly_return local implicitly_return
LocalName = (function() do
local _parent_0 = nil local _parent_0 = nil
local _base_0 = { local _base_0 = {
get_name = function(self) get_name = function(self)
@ -44,9 +44,9 @@ LocalName = (function()
if _parent_0 and _parent_0.__inherited then if _parent_0 and _parent_0.__inherited then
_parent_0.__inherited(_parent_0, _class_0) _parent_0.__inherited(_parent_0, _class_0)
end end
return _class_0 LocalName = _class_0
end)() end
NameProxy = (function() do
local _parent_0 = nil local _parent_0 = nil
local _base_0 = { local _base_0 = {
get_name = function(self, scope) get_name = function(self, scope)
@ -134,9 +134,9 @@ NameProxy = (function()
if _parent_0 and _parent_0.__inherited then if _parent_0 and _parent_0.__inherited then
_parent_0.__inherited(_parent_0, _class_0) _parent_0.__inherited(_parent_0, _class_0)
end end
return _class_0 NameProxy = _class_0
end)() end
Run = (function() do
local _parent_0 = nil local _parent_0 = nil
local _base_0 = { local _base_0 = {
call = function(self, state) call = function(self, state)
@ -174,8 +174,8 @@ Run = (function()
if _parent_0 and _parent_0.__inherited then if _parent_0 and _parent_0.__inherited then
_parent_0.__inherited(_parent_0, _class_0) _parent_0.__inherited(_parent_0, _class_0)
end end
return _class_0 Run = _class_0
end)() end
local apply_to_last local apply_to_last
apply_to_last = function(stms, fn) apply_to_last = function(stms, fn)
local last_exp_id = 0 local last_exp_id = 0
@ -340,7 +340,7 @@ with_continue_listener = function(body)
} }
end end
local Transformer local Transformer
Transformer = (function() do
local _parent_0 = nil local _parent_0 = nil
local _base_0 = { local _base_0 = {
transform = function(self, scope, node, ...) transform = function(self, scope, node, ...)
@ -408,8 +408,8 @@ Transformer = (function()
if _parent_0 and _parent_0.__inherited then if _parent_0 and _parent_0.__inherited then
_parent_0.__inherited(_parent_0, _class_0) _parent_0.__inherited(_parent_0, _class_0)
end end
return _class_0 Transformer = _class_0
end)() end
local construct_comprehension local construct_comprehension
construct_comprehension = function(inner, clauses) construct_comprehension = function(inner, clauses)
local current_stms = inner local current_stms = inner
@ -1197,7 +1197,7 @@ Statement = Transformer({
}) })
} }
}), }),
cls_name _with_0.assign_one(name, cls_name)
} }
hoist_declarations(out_body) hoist_declarations(out_body)
value = _with_0.group({ value = _with_0.group({
@ -1206,14 +1206,7 @@ Statement = Transformer({
name name
} }
}), }),
_with_0.assign({ _with_0["do"](out_body),
names = {
name
},
values = {
_with_0.block_exp(out_body)
}
}),
(function() (function()
if ret then if ret then
return ret(name) return ret(name)
@ -1225,7 +1218,7 @@ Statement = Transformer({
end end
}) })
local Accumulator local Accumulator
Accumulator = (function() do
local _parent_0 = nil local _parent_0 = nil
local _base_0 = { local _base_0 = {
body_idx = { body_idx = {
@ -1332,8 +1325,8 @@ Accumulator = (function()
if _parent_0 and _parent_0.__inherited then if _parent_0 and _parent_0.__inherited then
_parent_0.__inherited(_parent_0, _class_0) _parent_0.__inherited(_parent_0, _class_0)
end end
return _class_0 Accumulator = _class_0
end)() end
local default_accumulator local default_accumulator
default_accumulator = function(self, node) default_accumulator = function(self, node)
return Accumulator():convert(node) return Accumulator():convert(node)

View File

@ -609,17 +609,15 @@ Statement = Transformer {
} }
} }
cls_name .assign_one name, cls_name
} }
hoist_declarations out_body hoist_declarations out_body
value = .group { value = .group {
.declare names: {name} .declare names: {name}
.assign { .do out_body
names: {name}
values: {.block_exp out_body}
}
if ret if ret
ret name ret name
} }

View File

@ -1,5 +1,5 @@
local Hello local Hello
Hello = (function() do
local _parent_0 = nil local _parent_0 = nil
local _base_0 = { local _base_0 = {
hello = function(self) hello = function(self)
@ -40,13 +40,13 @@ Hello = (function()
if _parent_0 and _parent_0.__inherited then if _parent_0 and _parent_0.__inherited then
_parent_0.__inherited(_parent_0, _class_0) _parent_0.__inherited(_parent_0, _class_0)
end end
return _class_0 Hello = _class_0
end)() end
local x = Hello(1, 2) local x = Hello(1, 2)
x:hello() x:hello()
print(x) print(x)
local Simple local Simple
Simple = (function() do
local _parent_0 = nil local _parent_0 = nil
local _base_0 = { local _base_0 = {
cool = function(self) cool = function(self)
@ -85,10 +85,10 @@ Simple = (function()
if _parent_0 and _parent_0.__inherited then if _parent_0 and _parent_0.__inherited then
_parent_0.__inherited(_parent_0, _class_0) _parent_0.__inherited(_parent_0, _class_0)
end end
return _class_0 Simple = _class_0
end)() end
local Yikes local Yikes
Yikes = (function() do
local _parent_0 = Simple local _parent_0 = Simple
local _base_0 = { } local _base_0 = { }
_base_0.__index = _base_0 _base_0.__index = _base_0
@ -121,12 +121,12 @@ Yikes = (function()
if _parent_0 and _parent_0.__inherited then if _parent_0 and _parent_0.__inherited then
_parent_0.__inherited(_parent_0, _class_0) _parent_0.__inherited(_parent_0, _class_0)
end end
return _class_0 Yikes = _class_0
end)() end
x = Yikes() x = Yikes()
x:cool() x:cool()
local Hi local Hi
Hi = (function() do
local _parent_0 = nil local _parent_0 = nil
local _base_0 = { local _base_0 = {
cool = function(self, num) cool = function(self, num)
@ -163,9 +163,9 @@ Hi = (function()
if _parent_0 and _parent_0.__inherited then if _parent_0 and _parent_0.__inherited then
_parent_0.__inherited(_parent_0, _class_0) _parent_0.__inherited(_parent_0, _class_0)
end end
return _class_0 Hi = _class_0
end)() end
Simple = (function() do
local _parent_0 = Hi local _parent_0 = Hi
local _base_0 = { local _base_0 = {
cool = function(self) cool = function(self)
@ -202,13 +202,13 @@ Simple = (function()
if _parent_0 and _parent_0.__inherited then if _parent_0 and _parent_0.__inherited then
_parent_0.__inherited(_parent_0, _class_0) _parent_0.__inherited(_parent_0, _class_0)
end end
return _class_0 Simple = _class_0
end)() end
x = Simple() x = Simple()
x:cool() x:cool()
print(x.__class == Simple) print(x.__class == Simple)
local Okay local Okay
Okay = (function() do
local _parent_0 = nil local _parent_0 = nil
local _base_0 = { local _base_0 = {
something = 20323 something = 20323
@ -245,10 +245,10 @@ Okay = (function()
if _parent_0 and _parent_0.__inherited then if _parent_0 and _parent_0.__inherited then
_parent_0.__inherited(_parent_0, _class_0) _parent_0.__inherited(_parent_0, _class_0)
end end
return _class_0 Okay = _class_0
end)() end
local Biggie local Biggie
Biggie = (function() do
local _parent_0 = Okay local _parent_0 = Okay
local _base_0 = { local _base_0 = {
something = function(self) something = function(self)
@ -289,10 +289,10 @@ Biggie = (function()
if _parent_0 and _parent_0.__inherited then if _parent_0 and _parent_0.__inherited then
_parent_0.__inherited(_parent_0, _class_0) _parent_0.__inherited(_parent_0, _class_0)
end end
return _class_0 Biggie = _class_0
end)() end
local Yeah local Yeah
Yeah = (function() do
local _parent_0 = nil local _parent_0 = nil
local _base_0 = { local _base_0 = {
okay = function(self) okay = function(self)
@ -331,10 +331,10 @@ Yeah = (function()
if _parent_0 and _parent_0.__inherited then if _parent_0 and _parent_0.__inherited then
_parent_0.__inherited(_parent_0, _class_0) _parent_0.__inherited(_parent_0, _class_0)
end end
return _class_0 Yeah = _class_0
end)() end
local What local What
What = (function() do
local _parent_0 = nil local _parent_0 = nil
local _base_0 = { local _base_0 = {
something = function(self) something = function(self)
@ -373,9 +373,9 @@ What = (function()
if _parent_0 and _parent_0.__inherited then if _parent_0 and _parent_0.__inherited then
_parent_0.__inherited(_parent_0, _class_0) _parent_0.__inherited(_parent_0, _class_0)
end end
return _class_0 What = _class_0
end)() end
Hello = (function() do
local _parent_0 = What local _parent_0 = What
local _base_0 = { local _base_0 = {
val = 2323, val = 2323,
@ -421,8 +421,8 @@ Hello = (function()
if _parent_0 and _parent_0.__inherited then if _parent_0 and _parent_0.__inherited then
_parent_0.__inherited(_parent_0, _class_0) _parent_0.__inherited(_parent_0, _class_0)
end end
return _class_0 Hello = _class_0
end)() end
do do
local _with_0 = Hello() local _with_0 = Hello()
x = _with_0:something() x = _with_0:something()
@ -430,7 +430,7 @@ do
x() x()
end end
local CoolSuper local CoolSuper
CoolSuper = (function() do
local _parent_0 = nil local _parent_0 = nil
local _base_0 = { local _base_0 = {
hi = function(self) hi = function(self)
@ -475,8 +475,8 @@ CoolSuper = (function()
if _parent_0 and _parent_0.__inherited then if _parent_0 and _parent_0.__inherited then
_parent_0.__inherited(_parent_0, _class_0) _parent_0.__inherited(_parent_0, _class_0)
end end
return _class_0 CoolSuper = _class_0
end)() end
x = self.hello x = self.hello
x = self.__class.hello x = self.__class.hello
self:hello("world") self:hello("world")
@ -487,7 +487,7 @@ xx = function(hello, world, cool)
self.hello, self.__class.world = hello, world self.hello, self.__class.world = hello, world
end end
local ClassMan local ClassMan
ClassMan = (function() do
local _parent_0 = nil local _parent_0 = nil
local _base_0 = { local _base_0 = {
blue = function(self) end, blue = function(self) end,
@ -530,8 +530,8 @@ ClassMan = (function()
if _parent_0 and _parent_0.__inherited then if _parent_0 and _parent_0.__inherited then
_parent_0.__inherited(_parent_0, _class_0) _parent_0.__inherited(_parent_0, _class_0)
end end
return _class_0 ClassMan = _class_0
end)() end
x = self x = self
local y = self.__class local y = self.__class
self(something) self(something)
@ -541,7 +541,7 @@ self = 343
self.hello(2, 3, 4) self.hello(2, 3, 4)
local _ = hello[self].world local _ = hello[self].world
local Whacko local Whacko
Whacko = (function() do
local hello local hello
local _parent_0 = nil local _parent_0 = nil
local _base_0 = { } local _base_0 = { }
@ -587,13 +587,13 @@ Whacko = (function()
if _parent_0 and _parent_0.__inherited then if _parent_0 and _parent_0.__inherited then
_parent_0.__inherited(_parent_0, _class_0) _parent_0.__inherited(_parent_0, _class_0)
end end
return _class_0 Whacko = _class_0
end)() end
print("hello") print("hello")
local yyy local yyy
yyy = function() yyy = function()
local Cool local Cool
Cool = (function() do
local _parent_0 = nil local _parent_0 = nil
local _base_0 = { } local _base_0 = { }
_base_0.__index = _base_0 _base_0.__index = _base_0
@ -630,7 +630,7 @@ yyy = function()
if _parent_0 and _parent_0.__inherited then if _parent_0 and _parent_0.__inherited then
_parent_0.__inherited(_parent_0, _class_0) _parent_0.__inherited(_parent_0, _class_0)
end end
return _class_0 Cool = _class_0
end)() end
return Cool return Cool
end end

View File

@ -1,6 +1,6 @@
a, b, c = 223, 343 a, b, c = 223, 343
cool = "dad" cool = "dad"
Something = (function() do
local _parent_0 = nil local _parent_0 = nil
local _base_0 = { local _base_0 = {
umm = "cool" umm = "cool"
@ -37,8 +37,8 @@ Something = (function()
if _parent_0 and _parent_0.__inherited then if _parent_0 and _parent_0.__inherited then
_parent_0.__inherited(_parent_0, _class_0) _parent_0.__inherited(_parent_0, _class_0)
end end
return _class_0 Something = _class_0
end)() end
local What local What
if this then if this then
What = 232 What = 232