remove concept of non atomic value

This commit is contained in:
leaf corcoran 2012-11-01 08:03:27 -07:00
parent 481e0f6c66
commit bcb4327fd8
8 changed files with 9 additions and 59 deletions

View File

@ -32,9 +32,6 @@ moonlib = {
}) })
end end
} }
non_atomic = Set({
"update"
})
has_value = function(node) has_value = function(node)
if ntype(node) == "chain" then if ntype(node) == "chain" then
local ctype = ntype(node[#node]) local ctype = ntype(node[#node])
@ -43,9 +40,6 @@ has_value = function(node)
return true return true
end end
end end
is_non_atomic = function(node)
return non_atomic[ntype(node)]
end
count_lines = function(str) count_lines = function(str)
local count = 1 local count = 1
for _ in str:gmatch("\n") do for _ in str:gmatch("\n") do

View File

@ -7,7 +7,7 @@ import Set from require "moonscript.data"
import ntype from require "moonscript.types" import ntype from require "moonscript.types"
import concat, insert from table 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 export count_lines, user_error
indent_char = " " indent_char = " "
@ -23,9 +23,6 @@ moonlib =
bind: (tbl, name) -> bind: (tbl, name) ->
concat {"moon.bind(", tbl, ".", name, ", ", tbl, ")"} 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 -- does this always return a value
has_value = (node) -> has_value = (node) ->
if ntype(node) == "chain" if ntype(node) == "chain"
@ -34,9 +31,6 @@ has_value = (node) ->
else else
true true
is_non_atomic = (node) ->
non_atomic[ntype(node)]
count_lines = (str) -> count_lines = (str) ->
count = 1 count = 1
count += 1 for _ in str\gmatch "\n" count += 1 for _ in str\gmatch "\n"

View File

@ -159,29 +159,11 @@ line_compile = {
end, end,
["while"] = function(self, node) ["while"] = function(self, node)
local _, cond, block = unpack(node) local _, cond, block = unpack(node)
local out do
if is_non_atomic(cond) then local _with_0 = self:block(self:line("while ", self:value(cond), " do"))
do _with_0:stms(block)
local _with_0 = self:block("while true do") return _with_0
_with_0:stm({
"if",
{
"not",
cond
},
{
{
"break"
}
}
})
out = _with_0
end
else
out = self:block(self:line("while ", self:value(cond), " do"))
end end
out:stms(block)
return out
end, end,
["for"] = function(self, node) ["for"] = function(self, node)
local _, name, bounds, block = unpack(node) local _, name, bounds, block = unpack(node)

View File

@ -92,15 +92,8 @@ line_compile =
while: (node) => while: (node) =>
_, cond, block = unpack node _, cond, block = unpack node
with @block @line "while ", @value(cond), " do"
out = if is_non_atomic cond \stms block
with @block "while true do"
\stm {"if", {"not", cond}, {{"break"}}}
else
@block @line "while ", @value(cond), " do"
out\stms block
out
for: (node) => for: (node) =>
_, name, bounds, block = unpack node _, name, bounds, block = unpack node

View File

@ -34,11 +34,6 @@ value_compile = {
return _with_0 return _with_0
end end
end, end,
update = function(self, node)
local _, name = unpack(node)
self:stm(node)
return self:name(name)
end,
explist = function(self, node) explist = function(self, node)
do do
local _with_0 = self:line() local _with_0 = self:line()

View File

@ -24,12 +24,6 @@ value_compile =
with @line! with @line!
\append_list [_comp i,v for i,v in ipairs node when i > 1], " " \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 -- list of expressions separated by commas
explist: (node) => explist: (node) =>
with @line! with @line!

View File

@ -134,8 +134,8 @@ x = (function()
local _accum_0 = { } local _accum_0 = { }
local _len_0 = 0 local _len_0 = 0
while i < 10 do while i < 10 do
local _value_0
i = i + 1 i = i + 1
local _value_0 = i
if _value_0 ~= nil then if _value_0 ~= nil then
_len_0 = _len_0 + 1 _len_0 = _len_0 + 1
_accum_0[_len_0] = _value_0 _accum_0[_len_0] = _value_0

View File

@ -156,7 +156,6 @@ for _index_0 = 1, #_list_0 do
_ = ((function() _ = ((function()
if ntype(v) == "fndef" then if ntype(v) == "fndef" then
x = x + 1 x = x + 1
return x
end end
end)()) end)())
end end
@ -231,4 +230,3 @@ x["then"] = "hello"
x["while"]["true"] = "hello" x["while"]["true"] = "hello"
x = x or "hello" x = x or "hello"
x = x and "hello" x = x and "hello"
return x