mirror of
https://github.com/leafo/moonscript.git
synced 2024-11-22 02:44:23 +00:00
with moved to transformer
This commit is contained in:
parent
fd32503224
commit
45ba49f16b
@ -305,19 +305,6 @@ line_compile = {
|
||||
end
|
||||
return nil
|
||||
end,
|
||||
with = function(self, node, ret)
|
||||
local _, exp, block = unpack(node)
|
||||
do
|
||||
local _with_0 = self:block()
|
||||
local var = _with_0:init_free_var("with", exp)
|
||||
self:set("scope_var", var)
|
||||
_with_0:stms(block)
|
||||
if ret then
|
||||
_with_0:stm(ret(var))
|
||||
end
|
||||
return _with_0
|
||||
end
|
||||
end,
|
||||
run = function(self, code)
|
||||
code:call(self)
|
||||
return nil
|
||||
|
@ -167,15 +167,6 @@ line_compile =
|
||||
@declare names
|
||||
nil
|
||||
|
||||
with: (node, ret) =>
|
||||
_, exp, block = unpack node
|
||||
|
||||
with @block!
|
||||
var = \init_free_var "with", exp
|
||||
@set "scope_var", var
|
||||
\stms block
|
||||
\stm ret var if ret
|
||||
|
||||
run: (code) =>
|
||||
code\call self
|
||||
nil
|
||||
|
@ -89,20 +89,6 @@ value_compile = {
|
||||
local _, delim, inner, delim_end = unpack(node)
|
||||
return delim .. inner .. (delim_end or delim)
|
||||
end,
|
||||
with = function(self, node)
|
||||
do
|
||||
local _with_0 = self:block("(function()", "end)()")
|
||||
_with_0:stm(node, default_return)
|
||||
return _with_0
|
||||
end
|
||||
end,
|
||||
["if"] = function(self, node)
|
||||
do
|
||||
local _with_0 = self:block("(function()", "end)()")
|
||||
_with_0:stm(node, default_return)
|
||||
return _with_0
|
||||
end
|
||||
end,
|
||||
chain = function(self, node)
|
||||
local callee = node[2]
|
||||
if callee == -1 then
|
||||
|
@ -44,14 +44,6 @@ value_compile =
|
||||
_, delim, inner, delim_end = unpack node
|
||||
delim..inner..(delim_end or delim)
|
||||
|
||||
with: (node) =>
|
||||
with @block "(function()", "end)()"
|
||||
\stm node, default_return
|
||||
|
||||
if: (node) =>
|
||||
with @block "(function()", "end)()"
|
||||
\stm node, default_return
|
||||
|
||||
chain: (node) =>
|
||||
callee = node[2]
|
||||
|
||||
|
@ -224,8 +224,6 @@ Statement = Transformer({
|
||||
return current_stms[1]
|
||||
end,
|
||||
["if"] = function(node, ret)
|
||||
print("node:", node, "ret:", ret)
|
||||
print(util.dump(node))
|
||||
if ret then
|
||||
smart_node(node)
|
||||
node['then'] = apply_to_last(node['then'], ret)
|
||||
@ -237,6 +235,22 @@ Statement = Transformer({
|
||||
end
|
||||
return node
|
||||
end,
|
||||
with = function(node, ret)
|
||||
local _, exp, block = unpack(node)
|
||||
local scope_name = NameProxy("with")
|
||||
return build.group({
|
||||
build.assign_one(scope_name, exp),
|
||||
Run(function(self)
|
||||
return self:set("scope_var", scope_name)
|
||||
end),
|
||||
build.group(block),
|
||||
(function()
|
||||
if ret then
|
||||
return ret(scope_name)
|
||||
end
|
||||
end)()
|
||||
})
|
||||
end,
|
||||
foreach = function(node)
|
||||
smart_node(node)
|
||||
if ntype(node.iter) == "unpack" then
|
||||
@ -634,6 +648,16 @@ Value = Transformer({
|
||||
node.body = apply_to_last(node.body, implicitly_return)
|
||||
return node
|
||||
end,
|
||||
["if"] = function(node)
|
||||
return build.block_exp({
|
||||
node
|
||||
})
|
||||
end,
|
||||
with = function(node)
|
||||
return build.block_exp({
|
||||
node
|
||||
})
|
||||
end,
|
||||
chain = function(node)
|
||||
local stub = node[#node]
|
||||
if type(stub) == "table" and stub[1] == "colon_stub" then
|
||||
|
@ -128,8 +128,6 @@ Statement = Transformer {
|
||||
|
||||
-- handle cascading return decorator
|
||||
if: (node, ret) ->
|
||||
print "node:", node, "ret:", ret
|
||||
print util.dump node
|
||||
if ret
|
||||
smart_node node
|
||||
-- mutate all the bodies
|
||||
@ -140,6 +138,17 @@ Statement = Transformer {
|
||||
case[body_idx] = apply_to_last case[body_idx], ret
|
||||
node
|
||||
|
||||
with: (node, ret) ->
|
||||
_, exp, block = unpack node
|
||||
scope_name = NameProxy "with"
|
||||
build.group {
|
||||
build.assign_one scope_name, exp
|
||||
Run => @set "scope_var", scope_name
|
||||
build.group block
|
||||
if ret
|
||||
ret scope_name
|
||||
}
|
||||
|
||||
foreach: (node) ->
|
||||
smart_node node
|
||||
if ntype(node.iter) == "unpack"
|
||||
@ -366,6 +375,10 @@ Value = Transformer {
|
||||
smart_node node
|
||||
node.body = apply_to_last node.body, implicitly_return
|
||||
node
|
||||
|
||||
if: (node) -> build.block_exp { node }
|
||||
with: (node) -> build.block_exp { node }
|
||||
|
||||
-- pull out colon chain
|
||||
chain: (node) ->
|
||||
stub = node[#node]
|
||||
|
Loading…
Reference in New Issue
Block a user