mirror of
https://github.com/leafo/moonscript.git
synced 2025-01-09 00:04:22 +00:00
remove concept of non atomic value
This commit is contained in:
parent
481e0f6c66
commit
bcb4327fd8
@ -32,9 +32,6 @@ moonlib = {
|
||||
})
|
||||
end
|
||||
}
|
||||
non_atomic = Set({
|
||||
"update"
|
||||
})
|
||||
has_value = function(node)
|
||||
if ntype(node) == "chain" then
|
||||
local ctype = ntype(node[#node])
|
||||
@ -43,9 +40,6 @@ has_value = function(node)
|
||||
return true
|
||||
end
|
||||
end
|
||||
is_non_atomic = function(node)
|
||||
return non_atomic[ntype(node)]
|
||||
end
|
||||
count_lines = function(str)
|
||||
local count = 1
|
||||
for _ in str:gmatch("\n") do
|
||||
|
@ -7,7 +7,7 @@ import Set from require "moonscript.data"
|
||||
import ntype from require "moonscript.types"
|
||||
import concat, insert from table
|
||||
|
||||
export indent_char, default_return, moonlib, cascading, non_atomic, has_value, is_non_atomic
|
||||
export indent_char, default_return, moonlib, cascading, has_value
|
||||
export count_lines, user_error
|
||||
|
||||
indent_char = " "
|
||||
@ -23,9 +23,6 @@ moonlib =
|
||||
bind: (tbl, name) ->
|
||||
concat {"moon.bind(", tbl, ".", name, ", ", tbl, ")"}
|
||||
|
||||
-- an action that can't be completed in a single line
|
||||
non_atomic = Set{ "update" }
|
||||
|
||||
-- does this always return a value
|
||||
has_value = (node) ->
|
||||
if ntype(node) == "chain"
|
||||
@ -34,9 +31,6 @@ has_value = (node) ->
|
||||
else
|
||||
true
|
||||
|
||||
is_non_atomic = (node) ->
|
||||
non_atomic[ntype(node)]
|
||||
|
||||
count_lines = (str) ->
|
||||
count = 1
|
||||
count += 1 for _ in str\gmatch "\n"
|
||||
|
@ -159,29 +159,11 @@ line_compile = {
|
||||
end,
|
||||
["while"] = function(self, node)
|
||||
local _, cond, block = unpack(node)
|
||||
local out
|
||||
if is_non_atomic(cond) then
|
||||
do
|
||||
local _with_0 = self:block("while true do")
|
||||
_with_0:stm({
|
||||
"if",
|
||||
{
|
||||
"not",
|
||||
cond
|
||||
},
|
||||
{
|
||||
{
|
||||
"break"
|
||||
}
|
||||
}
|
||||
})
|
||||
out = _with_0
|
||||
local _with_0 = self:block(self:line("while ", self:value(cond), " do"))
|
||||
_with_0:stms(block)
|
||||
return _with_0
|
||||
end
|
||||
else
|
||||
out = self:block(self:line("while ", self:value(cond), " do"))
|
||||
end
|
||||
out:stms(block)
|
||||
return out
|
||||
end,
|
||||
["for"] = function(self, node)
|
||||
local _, name, bounds, block = unpack(node)
|
||||
|
@ -92,15 +92,8 @@ line_compile =
|
||||
|
||||
while: (node) =>
|
||||
_, cond, block = unpack node
|
||||
|
||||
out = if is_non_atomic cond
|
||||
with @block "while true do"
|
||||
\stm {"if", {"not", cond}, {{"break"}}}
|
||||
else
|
||||
@block @line "while ", @value(cond), " do"
|
||||
|
||||
out\stms block
|
||||
out
|
||||
with @block @line "while ", @value(cond), " do"
|
||||
\stms block
|
||||
|
||||
for: (node) =>
|
||||
_, name, bounds, block = unpack node
|
||||
|
@ -34,11 +34,6 @@ value_compile = {
|
||||
return _with_0
|
||||
end
|
||||
end,
|
||||
update = function(self, node)
|
||||
local _, name = unpack(node)
|
||||
self:stm(node)
|
||||
return self:name(name)
|
||||
end,
|
||||
explist = function(self, node)
|
||||
do
|
||||
local _with_0 = self:line()
|
||||
|
@ -24,12 +24,6 @@ value_compile =
|
||||
with @line!
|
||||
\append_list [_comp i,v for i,v in ipairs node when i > 1], " "
|
||||
|
||||
-- TODO refactor
|
||||
update: (node) =>
|
||||
_, name = unpack node
|
||||
@stm node
|
||||
@name name
|
||||
|
||||
-- list of expressions separated by commas
|
||||
explist: (node) =>
|
||||
with @line!
|
||||
|
@ -134,8 +134,8 @@ x = (function()
|
||||
local _accum_0 = { }
|
||||
local _len_0 = 0
|
||||
while i < 10 do
|
||||
local _value_0
|
||||
i = i + 1
|
||||
local _value_0 = i
|
||||
if _value_0 ~= nil then
|
||||
_len_0 = _len_0 + 1
|
||||
_accum_0[_len_0] = _value_0
|
||||
|
@ -156,7 +156,6 @@ for _index_0 = 1, #_list_0 do
|
||||
_ = ((function()
|
||||
if ntype(v) == "fndef" then
|
||||
x = x + 1
|
||||
return x
|
||||
end
|
||||
end)())
|
||||
end
|
||||
@ -231,4 +230,3 @@ x["then"] = "hello"
|
||||
x["while"]["true"] = "hello"
|
||||
x = x or "hello"
|
||||
x = x and "hello"
|
||||
return x
|
Loading…
Reference in New Issue
Block a user