mirror of
https://github.com/leafo/moonscript.git
synced 2024-11-22 02:44:23 +00:00
change how super method name is set
This commit is contained in:
parent
76454f61ae
commit
4b26091c9f
@ -27,7 +27,7 @@ import concat, insert from table
|
|||||||
_, names, values = unpack node
|
_, names, values = unpack node
|
||||||
|
|
||||||
undeclared = @declare names
|
undeclared = @declare names
|
||||||
declare = "local "..concat(undeclared, ", ")
|
declare = "local " .. concat(undeclared, ", ")
|
||||||
|
|
||||||
has_fndef = false
|
has_fndef = false
|
||||||
i = 1
|
i = 1
|
||||||
|
@ -17,6 +17,16 @@ local string_chars = {
|
|||||||
["\n"] = "\\n"
|
["\n"] = "\\n"
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
scoped = function(self, node)
|
||||||
|
local _, before, value, after
|
||||||
|
_, before, value, after = node[1], node[2], node[3], node[4]
|
||||||
|
_ = before and before:call(self)
|
||||||
|
do
|
||||||
|
local _with_0 = self:value(value)
|
||||||
|
_ = after and after:call(self)
|
||||||
|
return _with_0
|
||||||
|
end
|
||||||
|
end,
|
||||||
exp = function(self, node)
|
exp = function(self, node)
|
||||||
local _comp
|
local _comp
|
||||||
_comp = function(i, value)
|
_comp = function(i, value)
|
||||||
@ -248,9 +258,7 @@ return {
|
|||||||
else
|
else
|
||||||
assign = self:line("[", _with_0:value(key), "]")
|
assign = self:line("[", _with_0:value(key), "]")
|
||||||
end
|
end
|
||||||
_with_0:set("current_block", key)
|
|
||||||
local out = self:line(assign, " = ", _with_0:value(value))
|
local out = self:line(assign, " = ", _with_0:value(value))
|
||||||
_with_0:set("current_block", nil)
|
|
||||||
return out
|
return out
|
||||||
else
|
else
|
||||||
return self:line(_with_0:value(tuple[1]))
|
return self:line(_with_0:value(tuple[1]))
|
||||||
|
@ -15,6 +15,12 @@ string_chars = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
scoped: (node) =>
|
||||||
|
{_, before, value, after} = node
|
||||||
|
before and before\call @
|
||||||
|
with @value value
|
||||||
|
after and after\call @
|
||||||
|
|
||||||
-- list of values separated by binary operators
|
-- list of values separated by binary operators
|
||||||
exp: (node) =>
|
exp: (node) =>
|
||||||
_comp = (i, value) ->
|
_comp = (i, value) ->
|
||||||
@ -146,9 +152,7 @@ string_chars = {
|
|||||||
else
|
else
|
||||||
@line "[", \value(key), "]"
|
@line "[", \value(key), "]"
|
||||||
|
|
||||||
\set "current_block", key
|
|
||||||
out = @line assign, " = ", \value(value)
|
out = @line assign, " = ", \value(value)
|
||||||
\set "current_block", nil
|
|
||||||
out
|
out
|
||||||
else
|
else
|
||||||
@line \value tuple[1]
|
@line \value tuple[1]
|
||||||
|
@ -13,6 +13,21 @@ do
|
|||||||
local _obj_0 = require("moonscript.types")
|
local _obj_0 = require("moonscript.types")
|
||||||
build, ntype, NOOP = _obj_0.build, _obj_0.ntype, _obj_0.NOOP
|
build, ntype, NOOP = _obj_0.build, _obj_0.ntype, _obj_0.NOOP
|
||||||
end
|
end
|
||||||
|
local super_scope
|
||||||
|
super_scope = function(value, key)
|
||||||
|
local prev_method
|
||||||
|
return {
|
||||||
|
"scoped",
|
||||||
|
Run(function(self)
|
||||||
|
prev_method = self:get("current_method")
|
||||||
|
return self:set("current_method", key)
|
||||||
|
end),
|
||||||
|
value,
|
||||||
|
Run(function(self)
|
||||||
|
return self:set("current_method", prev_method)
|
||||||
|
end)
|
||||||
|
}
|
||||||
|
end
|
||||||
return function(self, node, ret, parent_assign)
|
return function(self, node, ret, parent_assign)
|
||||||
local _, name, parent_val, body = unpack(node)
|
local _, name, parent_val, body = unpack(node)
|
||||||
if parent_val == "" then
|
if parent_val == "" then
|
||||||
@ -51,7 +66,12 @@ return function(self, node, ret, parent_assign)
|
|||||||
_continue_0 = true
|
_continue_0 = true
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
_value_0 = tuple
|
local val
|
||||||
|
key, val = tuple[1], tuple[2]
|
||||||
|
_value_0 = {
|
||||||
|
key,
|
||||||
|
super_scope(val, key)
|
||||||
|
}
|
||||||
end
|
end
|
||||||
_accum_0[_len_0] = _value_0
|
_accum_0[_len_0] = _value_0
|
||||||
_len_0 = _len_0 + 1
|
_len_0 = _len_0 + 1
|
||||||
@ -129,7 +149,10 @@ return function(self, node, ret, parent_assign)
|
|||||||
local cls = build.table({
|
local cls = build.table({
|
||||||
{
|
{
|
||||||
"__init",
|
"__init",
|
||||||
constructor
|
super_scope(constructor, {
|
||||||
|
"key_literal",
|
||||||
|
"__init"
|
||||||
|
})
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"__base",
|
"__base",
|
||||||
@ -304,7 +327,7 @@ return function(self, node, ret, parent_assign)
|
|||||||
local new_chain = relative_parent
|
local new_chain = relative_parent
|
||||||
local _exp_1 = head[1]
|
local _exp_1 = head[1]
|
||||||
if "call" == _exp_1 then
|
if "call" == _exp_1 then
|
||||||
local calling_name = block:get("current_block")
|
local calling_name = block:get("current_method")
|
||||||
assert(calling_name, "missing calling name")
|
assert(calling_name, "missing calling name")
|
||||||
chain_tail[1] = {
|
chain_tail[1] = {
|
||||||
"call",
|
"call",
|
||||||
|
@ -6,6 +6,19 @@ CONSTRUCTOR_NAME = "new"
|
|||||||
import insert from table
|
import insert from table
|
||||||
import build, ntype, NOOP from require "moonscript.types"
|
import build, ntype, NOOP from require "moonscript.types"
|
||||||
|
|
||||||
|
super_scope = (value, key) ->
|
||||||
|
local prev_method
|
||||||
|
|
||||||
|
{
|
||||||
|
"scoped",
|
||||||
|
Run =>
|
||||||
|
prev_method = @get "current_method"
|
||||||
|
@set "current_method", key
|
||||||
|
value
|
||||||
|
Run =>
|
||||||
|
@set "current_method", prev_method
|
||||||
|
}
|
||||||
|
|
||||||
(node, ret, parent_assign) =>
|
(node, ret, parent_assign) =>
|
||||||
_, name, parent_val, body = unpack node
|
_, name, parent_val, body = unpack node
|
||||||
parent_val = nil if parent_val == ""
|
parent_val = nil if parent_val == ""
|
||||||
@ -32,7 +45,8 @@ import build, ntype, NOOP from require "moonscript.types"
|
|||||||
constructor = tuple[2]
|
constructor = tuple[2]
|
||||||
continue
|
continue
|
||||||
else
|
else
|
||||||
tuple
|
{key, val} = tuple
|
||||||
|
{key, super_scope val, key}
|
||||||
|
|
||||||
parent_cls_name = NameProxy "parent"
|
parent_cls_name = NameProxy "parent"
|
||||||
base_name = NameProxy "base"
|
base_name = NameProxy "base"
|
||||||
@ -77,7 +91,7 @@ import build, ntype, NOOP from require "moonscript.types"
|
|||||||
{"string", '"', flattened_name}
|
{"string", '"', flattened_name}
|
||||||
|
|
||||||
cls = build.table {
|
cls = build.table {
|
||||||
{"__init", constructor}
|
{"__init", super_scope constructor, {"key_literal", "__init"}}
|
||||||
{"__base", base_name}
|
{"__base", base_name}
|
||||||
{"__name", real_name} -- "quote the string"
|
{"__name", real_name} -- "quote the string"
|
||||||
parent_val and {"__parent", parent_cls_name} or nil
|
parent_val and {"__parent", parent_cls_name} or nil
|
||||||
@ -173,7 +187,7 @@ import build, ntype, NOOP from require "moonscript.types"
|
|||||||
switch head[1]
|
switch head[1]
|
||||||
-- calling super, inject calling name and self into chain
|
-- calling super, inject calling name and self into chain
|
||||||
when "call"
|
when "call"
|
||||||
calling_name = block\get"current_block"
|
calling_name = block\get "current_method"
|
||||||
assert calling_name, "missing calling name"
|
assert calling_name, "missing calling name"
|
||||||
chain_tail[1] = {"call", {"self", unpack head[2]}}
|
chain_tail[1] = {"call", {"self", unpack head[2]}}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user