mirror of
https://github.com/leafo/moonscript.git
synced 2025-01-09 00:04:22 +00:00
replace has_value with functional value_can_be_statement
This commit is contained in:
parent
e4c4e8e0ee
commit
c4ad47c112
@ -8,10 +8,10 @@ do
|
|||||||
end
|
end
|
||||||
local Set
|
local Set
|
||||||
Set = require("moonscript.data").Set
|
Set = require("moonscript.data").Set
|
||||||
local ntype, has_value
|
local ntype, value_can_be_statement
|
||||||
do
|
do
|
||||||
local _obj_0 = require("moonscript.types")
|
local _obj_0 = require("moonscript.types")
|
||||||
ntype, has_value = _obj_0.ntype, _obj_0.has_value
|
ntype, value_can_be_statement = _obj_0.ntype, _obj_0.value_can_be_statement
|
||||||
end
|
end
|
||||||
local statement_compilers = require("moonscript.compile.statement")
|
local statement_compilers = require("moonscript.compile.statement")
|
||||||
local value_compilers = require("moonscript.compile.value")
|
local value_compilers = require("moonscript.compile.value")
|
||||||
@ -525,7 +525,9 @@ do
|
|||||||
if fn then
|
if fn then
|
||||||
result = fn(self, node, ...)
|
result = fn(self, node, ...)
|
||||||
else
|
else
|
||||||
if has_value(node) then
|
if value_can_be_statement(node) then
|
||||||
|
result = self:value(node)
|
||||||
|
else
|
||||||
result = self:stm({
|
result = self:stm({
|
||||||
"assign",
|
"assign",
|
||||||
{
|
{
|
||||||
@ -535,8 +537,6 @@ do
|
|||||||
node
|
node
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
else
|
|
||||||
result = self:value(node)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,7 +5,7 @@ transform = require "moonscript.transform"
|
|||||||
|
|
||||||
import NameProxy, LocalName from require "moonscript.transform.names"
|
import NameProxy, LocalName from require "moonscript.transform.names"
|
||||||
import Set from require "moonscript.data"
|
import Set from require "moonscript.data"
|
||||||
import ntype, has_value from require "moonscript.types"
|
import ntype, value_can_be_statement from require "moonscript.types"
|
||||||
|
|
||||||
statement_compilers = require "moonscript.compile.statement"
|
statement_compilers = require "moonscript.compile.statement"
|
||||||
value_compilers = require "moonscript.compile.value"
|
value_compilers = require "moonscript.compile.value"
|
||||||
@ -379,11 +379,11 @@ class Block
|
|||||||
result = if fn = @statement_compilers[ntype(node)]
|
result = if fn = @statement_compilers[ntype(node)]
|
||||||
fn @, node, ...
|
fn @, node, ...
|
||||||
else
|
else
|
||||||
-- coerce value into statement
|
if value_can_be_statement node
|
||||||
if has_value node
|
|
||||||
@stm {"assign", {"_"}, {node}}
|
|
||||||
else
|
|
||||||
@value node
|
@value node
|
||||||
|
else
|
||||||
|
-- coerce value into statement
|
||||||
|
@stm {"assign", {"_"}, {node}}
|
||||||
|
|
||||||
if result
|
if result
|
||||||
if type(node) == "table" and type(result) == "table" and node[-1]
|
if type(node) == "table" and type(result) == "table" and node[-1]
|
||||||
|
@ -45,14 +45,12 @@ do
|
|||||||
return moon_type(val)
|
return moon_type(val)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local has_value
|
local value_can_be_statement
|
||||||
has_value = function(node)
|
value_can_be_statement = function(node)
|
||||||
if ntype(node) == "chain" then
|
if not (ntype(node) == "chain") then
|
||||||
local ctype = ntype(node[#node])
|
return false
|
||||||
return ctype ~= "call" and ctype ~= "colon"
|
|
||||||
else
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
|
return ntype(node[#node]) == "call"
|
||||||
end
|
end
|
||||||
local is_value
|
local is_value
|
||||||
is_value = function(stm)
|
is_value = function(stm)
|
||||||
@ -320,7 +318,7 @@ return {
|
|||||||
cascading = cascading,
|
cascading = cascading,
|
||||||
value_is_singular = value_is_singular,
|
value_is_singular = value_is_singular,
|
||||||
comprehension_has_value = comprehension_has_value,
|
comprehension_has_value = comprehension_has_value,
|
||||||
has_value = has_value,
|
value_can_be_statement = value_can_be_statement,
|
||||||
mtype = mtype,
|
mtype = mtype,
|
||||||
terminating = terminating
|
terminating = terminating
|
||||||
}
|
}
|
||||||
|
@ -40,13 +40,11 @@ mtype = do
|
|||||||
return "table" if mt and mt.smart_node
|
return "table" if mt and mt.smart_node
|
||||||
moon_type val
|
moon_type val
|
||||||
|
|
||||||
-- does this always return a value
|
-- can this value be compiled in a line by itself
|
||||||
has_value = (node) ->
|
value_can_be_statement = (node) ->
|
||||||
if ntype(node) == "chain"
|
return false unless ntype(node) == "chain"
|
||||||
ctype = ntype(node[#node])
|
-- it's a function call
|
||||||
ctype != "call" and ctype != "colon"
|
ntype(node[#node]) == "call"
|
||||||
else
|
|
||||||
true
|
|
||||||
|
|
||||||
is_value = (stm) ->
|
is_value = (stm) ->
|
||||||
compile = require "moonscript.compile"
|
compile = require "moonscript.compile"
|
||||||
@ -193,6 +191,7 @@ smart_node = (node) ->
|
|||||||
|
|
||||||
{
|
{
|
||||||
:ntype, :smart_node, :build, :is_value, :is_slice, :manual_return,
|
:ntype, :smart_node, :build, :is_value, :is_slice, :manual_return,
|
||||||
:cascading, :value_is_singular, :comprehension_has_value, :has_value, :mtype, :terminating
|
:cascading, :value_is_singular, :comprehension_has_value,
|
||||||
|
:value_can_be_statement, :mtype, :terminating
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user