fixed super dot access, made super available as a value

This commit is contained in:
leaf corcoran 2011-12-02 20:07:42 -08:00
parent 68e209cd1f
commit 6a07d50277
6 changed files with 102 additions and 37 deletions

View File

@ -309,6 +309,9 @@ value_compile = {
return "self:" .. self:value(node[2]) return "self:" .. self:value(node[2])
end, end,
raw_value = function(self, value) raw_value = function(self, value)
if value == "super" then
return self:value(self:get("super")(self))
end
if value == "..." then if value == "..." then
self.has_varargs = true self.has_varargs = true
end end

View File

@ -181,6 +181,10 @@ value_compile =
-- catch all pure string values -- catch all pure string values
raw_value: (value) => raw_value: (value) =>
if value == "super"
return @value @get"super" self
if value == "..." if value == "..."
@has_varargs = true @has_varargs = true
tostring value tostring value

View File

@ -656,7 +656,7 @@ Statement = Transformer({
value = _with_0.block_exp({ value = _with_0.block_exp({
Run(function(self) Run(function(self)
return self:set("super", function(block, chain) return self:set("super", function(block, chain)
local calling_name = block:get("current_block") if chain then
local slice = (function() local slice = (function()
local _accum_0 = { } local _accum_0 = { }
local _len_0 = 0 local _len_0 = 0
@ -668,6 +668,12 @@ Statement = Transformer({
end end
return _accum_0 return _accum_0
end)() end)()
local new_chain = {
"chain",
parent_cls_name
}
if slice[1][1] == "call" then
local calling_name = block:get("current_block")
slice[1] = { slice[1] = {
"call", "call",
{ {
@ -681,15 +687,20 @@ Statement = Transformer({
else else
act = "dot" act = "dot"
end end
return { insert(new_chain, {
"chain",
parent_cls_name,
{
act, act,
calling_name calling_name
}, })
unpack(slice) end
} local _list_0 = slice
for _index_0 = 1, #_list_0 do
local item = _list_0[_index_0]
insert(new_chain, item)
end
return new_chain
else
return parent_cls_name
end
end) end)
end), end),
_with_0.assign_one(parent_cls_name, parent_val == "" and "nil" or parent_val), _with_0.assign_one(parent_cls_name, parent_val == "" and "nil" or parent_val),

View File

@ -368,13 +368,22 @@ Statement = Transformer {
value = .block_exp { value = .block_exp {
Run => Run =>
@set "super", (block, chain) -> @set "super", (block, chain) ->
calling_name = block\get"current_block" if chain
slice = [item for item in *chain[3,]] slice = [item for item in *chain[3,]]
-- inject self new_chain = {"chain", parent_cls_name}
slice[1] = {"call", {"self", unpack slice[1][2]}}
-- calling super, inject calling name and self into chain
if slice[1][1] == "call"
calling_name = block\get"current_block"
slice[1] = {"call", {"self", unpack slice[1][2]}}
act = if ntype(calling_name) != "value" then "index" else "dot" act = if ntype(calling_name) != "value" then "index" else "dot"
{"chain", parent_cls_name, {act, calling_name}, unpack slice} insert new_chain, {act, calling_name}
insert new_chain, item for item in *slice
new_chain
else
parent_cls_name
.assign_one parent_cls_name, parent_val == "" and "nil" or parent_val .assign_one parent_cls_name, parent_val == "" and "nil" or parent_val
.assign_one base_name, tbl .assign_one base_name, tbl

View File

@ -44,3 +44,10 @@ class Okay
something: 20323 something: 20323
-- yeaha -- yeaha
class Biggie extends Okay
something: =>
super 1,2,3,4
super.something another_self, 1,2,3,4
assert super == Okay

View File

@ -169,3 +169,34 @@ Okay = (function()
_base_0.__class = _class_0 _base_0.__class = _class_0
return _class_0 return _class_0
end)() end)()
local Biggie
Biggie = (function()
local _parent_0 = Okay
local _base_0 = {
something = function(self)
_parent_0.something(self, 1, 2, 3, 4)
_parent_0.something(another_self, 1, 2, 3, 4)
return assert(_parent_0 == Okay)
end
}
_base_0.__index = _base_0
if _parent_0 then
setmetatable(_base_0, getmetatable(_parent_0).__index)
end
local _class_0 = setmetatable({
__init = function(self, ...)
if _parent_0 then
return _parent_0.__init(self, ...)
end
end
}, {
__index = _base_0,
__call = function(cls, ...)
local _self_0 = setmetatable({}, _base_0)
cls.__init(_self_0, ...)
return _self_0
end
})
_base_0.__class = _class_0
return _class_0
end)()