Skip to content

Commit bcb4327

Browse files
committed
remove concept of non atomic value
1 parent 481e0f6 commit bcb4327

File tree

8 files changed

+9
-59
lines changed

8 files changed

+9
-59
lines changed

moonscript/compile/format.lua

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ moonlib = {
3232
})
3333
end
3434
}
35-
non_atomic = Set({
36-
"update"
37-
})
3835
has_value = function(node)
3936
if ntype(node) == "chain" then
4037
local ctype = ntype(node[#node])
@@ -43,9 +40,6 @@ has_value = function(node)
4340
return true
4441
end
4542
end
46-
is_non_atomic = function(node)
47-
return non_atomic[ntype(node)]
48-
end
4943
count_lines = function(str)
5044
local count = 1
5145
for _ in str:gmatch("\n") do

moonscript/compile/format.moon

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Set from require "moonscript.data"
77
import ntype from require "moonscript.types"
88
import concat, insert from table
99

10-
export indent_char, default_return, moonlib, cascading, non_atomic, has_value, is_non_atomic
10+
export indent_char, default_return, moonlib, cascading, has_value
1111
export count_lines, user_error
1212

1313
indent_char = " "
@@ -23,9 +23,6 @@ moonlib =
2323
bind: (tbl, name) ->
2424
concat {"moon.bind(", tbl, ".", name, ", ", tbl, ")"}
2525

26-
-- an action that can't be completed in a single line
27-
non_atomic = Set{ "update" }
28-
2926
-- does this always return a value
3027
has_value = (node) ->
3128
if ntype(node) == "chain"
@@ -34,9 +31,6 @@ has_value = (node) ->
3431
else
3532
true
3633

37-
is_non_atomic = (node) ->
38-
non_atomic[ntype(node)]
39-
4034
count_lines = (str) ->
4135
count = 1
4236
count += 1 for _ in str\gmatch "\n"

moonscript/compile/statement.lua

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -159,29 +159,11 @@ line_compile = {
159159
end,
160160
["while"] = function(self, node)
161161
local _, cond, block = unpack(node)
162-
local out
163-
if is_non_atomic(cond) then
164-
do
165-
local _with_0 = self:block("while true do")
166-
_with_0:stm({
167-
"if",
168-
{
169-
"not",
170-
cond
171-
},
172-
{
173-
{
174-
"break"
175-
}
176-
}
177-
})
178-
out = _with_0
179-
end
180-
else
181-
out = self:block(self:line("while ", self:value(cond), " do"))
162+
do
163+
local _with_0 = self:block(self:line("while ", self:value(cond), " do"))
164+
_with_0:stms(block)
165+
return _with_0
182166
end
183-
out:stms(block)
184-
return out
185167
end,
186168
["for"] = function(self, node)
187169
local _, name, bounds, block = unpack(node)

moonscript/compile/statement.moon

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,8 @@ line_compile =
9292

9393
while: (node) =>
9494
_, cond, block = unpack node
95-
96-
out = if is_non_atomic cond
97-
with @block "while true do"
98-
\stm {"if", {"not", cond}, {{"break"}}}
99-
else
100-
@block @line "while ", @value(cond), " do"
101-
102-
out\stms block
103-
out
95+
with @block @line "while ", @value(cond), " do"
96+
\stms block
10497

10598
for: (node) =>
10699
_, name, bounds, block = unpack node

moonscript/compile/value.lua

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ value_compile = {
3434
return _with_0
3535
end
3636
end,
37-
update = function(self, node)
38-
local _, name = unpack(node)
39-
self:stm(node)
40-
return self:name(name)
41-
end,
4237
explist = function(self, node)
4338
do
4439
local _with_0 = self:line()

moonscript/compile/value.moon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ value_compile =
2424
with @line!
2525
\append_list [_comp i,v for i,v in ipairs node when i > 1], " "
2626

27-
-- TODO refactor
28-
update: (node) =>
29-
_, name = unpack node
30-
@stm node
31-
@name name
32-
3327
-- list of expressions separated by commas
3428
explist: (node) =>
3529
with @line!

tests/outputs/loops.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ x = (function()
134134
local _accum_0 = { }
135135
local _len_0 = 0
136136
while i < 10 do
137+
local _value_0
137138
i = i + 1
138-
local _value_0 = i
139139
if _value_0 ~= nil then
140140
_len_0 = _len_0 + 1
141141
_accum_0[_len_0] = _value_0

tests/outputs/syntax.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ for _index_0 = 1, #_list_0 do
156156
_ = ((function()
157157
if ntype(v) == "fndef" then
158158
x = x + 1
159-
return x
160159
end
161160
end)())
162161
end
@@ -230,5 +229,4 @@ a = a / func("cool")
230229
x["then"] = "hello"
231230
x["while"]["true"] = "hello"
232231
x = x or "hello"
233-
x = x and "hello"
234-
return x
232+
x = x and "hello"

0 commit comments

Comments
 (0)