Skip to content

Commit 2219c44

Browse files
committed
misc cleanup
1 parent 45ba49f commit 2219c44

File tree

7 files changed

+13
-51
lines changed

7 files changed

+13
-51
lines changed

moonscript/compile.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ Block_ = (function()
380380
return nil
381381
end,
382382
ret_stms = function(self, stms, ret)
383-
if not ret then
384-
ret = default_return
383+
if ret == nil then
384+
ret = error("missing return handler")
385385
end
386386
local last_exp_id = 0
387387
for i = #stms, 1, -1 do

moonscript/compile.moon

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,7 @@ class Block_
258258
@add out if out
259259
nil
260260

261-
ret_stms: (stms, ret) =>
262-
if not ret
263-
ret = default_return
264-
261+
ret_stms: (stms, ret=error"missing return handler") =>
265262
-- find last exp for explicit return
266263
last_exp_id = 0
267264
for i = #stms, 1, -1

moonscript/compile/format.lua

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,10 @@ local manual_return = Set({
2424
"for",
2525
"while"
2626
})
27-
default_return = function(exp)
28-
local t = ntype(exp)
29-
if t == "chain" and exp[2] == "return" then
30-
local items = {
31-
"explist"
32-
}
33-
local _list_0 = exp[3][2]
34-
for _index_0 = 1, #_list_0 do
35-
local v = _list_0[_index_0]
36-
insert(items, v)
37-
end
38-
return {
39-
"return",
40-
items
41-
}
42-
elseif manual_return[t] then
43-
return exp
44-
else
45-
return {
46-
"return",
47-
exp
48-
}
49-
end
50-
end
27+
cascading = Set({
28+
"if",
29+
"with"
30+
})
5131
moonlib = {
5232
bind = function(tbl, name)
5333
return concat({
@@ -61,10 +41,6 @@ moonlib = {
6141
})
6242
end
6343
}
64-
cascading = Set({
65-
"if",
66-
"with"
67-
})
6844
non_atomic = Set({
6945
"update"
7046
})

moonscript/compile/format.moon

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,13 @@ user_error = (...) ->
1616
error {"user-error", ...}
1717

1818
manual_return = Set{"foreach", "for", "while"}
19+
cascading = Set{ "if", "with" }
1920

20-
default_return = (exp) ->
21-
t = ntype exp
22-
if t == "chain" and exp[2] == "return" -- return is a first class citizen now
23-
-- extract the return
24-
items = {"explist"}
25-
insert items, v for v in *exp[3][2]
26-
{"return", items}
27-
elseif manual_return[t]
28-
exp
29-
else
30-
{"return", exp}
31-
21+
-- TODO get RID OF THIAS
3222
moonlib =
3323
bind: (tbl, name) ->
3424
concat {"moon.bind(", tbl, ".", name, ", ", tbl, ")"}
3525

36-
cascading = Set{ "if", "with" }
37-
3826
-- an action that can't be completed in a single line
3927
non_atomic = Set{ "update" }
4028

moonscript/compile/line.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ do
99
ntype = _table_0.ntype
1010
end
1111
local concat, insert = table.concat, table.insert
12-
local constructor_name = "new"
1312
line_compile = {
1413
raw = function(self, node)
1514
local _, text = unpack(node)

moonscript/compile/line.moon

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import concat, insert from table
1111

1212
export line_compile
1313

14-
constructor_name = "new"
15-
1614
line_compile =
1715
raw: (node) =>
1816
_, text = unpack node

moonscript/compile/value.moon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ table_append = (name, len, value) ->
1919
}
2020

2121
value_compile =
22+
-- list of values separated by binary operators
2223
exp: (node) =>
2324
_comp = (i, value) ->
2425
if i % 2 == 1 and value == "!="
@@ -28,11 +29,13 @@ value_compile =
2829
with @line!
2930
\append_list [_comp i,v for i,v in ipairs node when i > 1], " "
3031

32+
-- TODO refactor
3133
update: (node) =>
3234
_, name = unpack node
3335
@stm node
3436
@name name
3537

38+
-- list of expressions separated by paretheses
3639
explist: (node) =>
3740
with @line!
3841
\append_list [@value v for v in *node[2,]], ", "
@@ -176,6 +179,7 @@ value_compile =
176179
self_colon: (node) =>
177180
"self:"..@value node[2]
178181

182+
-- catch all pure string values
179183
raw_value: (value) =>
180184
if value == "..."
181185
@has_varargs = true

0 commit comments

Comments
 (0)