diff --git a/moonscript/compile.lua b/moonscript/compile.lua index e3216e1..d1d303b 100644 --- a/moonscript/compile.lua +++ b/moonscript/compile.lua @@ -380,8 +380,8 @@ Block_ = (function() return nil end, ret_stms = function(self, stms, ret) - if not ret then - ret = default_return + if ret == nil then + ret = error("missing return handler") end local last_exp_id = 0 for i = #stms, 1, -1 do diff --git a/moonscript/compile.moon b/moonscript/compile.moon index 0d8f97f..b9c31da 100644 --- a/moonscript/compile.moon +++ b/moonscript/compile.moon @@ -258,10 +258,7 @@ class Block_ @add out if out nil - ret_stms: (stms, ret) => - if not ret - ret = default_return - + ret_stms: (stms, ret=error"missing return handler") => -- find last exp for explicit return last_exp_id = 0 for i = #stms, 1, -1 diff --git a/moonscript/compile/format.lua b/moonscript/compile/format.lua index 100e741..bc7f435 100644 --- a/moonscript/compile/format.lua +++ b/moonscript/compile/format.lua @@ -24,30 +24,10 @@ local manual_return = Set({ "for", "while" }) -default_return = function(exp) - local t = ntype(exp) - if t == "chain" and exp[2] == "return" then - local items = { - "explist" - } - local _list_0 = exp[3][2] - for _index_0 = 1, #_list_0 do - local v = _list_0[_index_0] - insert(items, v) - end - return { - "return", - items - } - elseif manual_return[t] then - return exp - else - return { - "return", - exp - } - end -end +cascading = Set({ + "if", + "with" +}) moonlib = { bind = function(tbl, name) return concat({ @@ -61,10 +41,6 @@ moonlib = { }) end } -cascading = Set({ - "if", - "with" -}) non_atomic = Set({ "update" }) diff --git a/moonscript/compile/format.moon b/moonscript/compile/format.moon index 3d3e3d3..3d1264c 100644 --- a/moonscript/compile/format.moon +++ b/moonscript/compile/format.moon @@ -16,25 +16,13 @@ user_error = (...) -> error {"user-error", ...} manual_return = Set{"foreach", "for", "while"} +cascading = Set{ "if", "with" } -default_return = (exp) -> - t = ntype exp - if t == "chain" and exp[2] == "return" -- return is a first class citizen now - -- extract the return - items = {"explist"} - insert items, v for v in *exp[3][2] - {"return", items} - elseif manual_return[t] - exp - else - {"return", exp} - +-- TODO get RID OF THIAS moonlib = bind: (tbl, name) -> concat {"moon.bind(", tbl, ".", name, ", ", tbl, ")"} -cascading = Set{ "if", "with" } - -- an action that can't be completed in a single line non_atomic = Set{ "update" } diff --git a/moonscript/compile/line.lua b/moonscript/compile/line.lua index 07e9c0f..c0012c5 100644 --- a/moonscript/compile/line.lua +++ b/moonscript/compile/line.lua @@ -9,7 +9,6 @@ do ntype = _table_0.ntype end local concat, insert = table.concat, table.insert -local constructor_name = "new" line_compile = { raw = function(self, node) local _, text = unpack(node) diff --git a/moonscript/compile/line.moon b/moonscript/compile/line.moon index 793dff8..ca952e6 100644 --- a/moonscript/compile/line.moon +++ b/moonscript/compile/line.moon @@ -11,8 +11,6 @@ import concat, insert from table export line_compile -constructor_name = "new" - line_compile = raw: (node) => _, text = unpack node diff --git a/moonscript/compile/value.moon b/moonscript/compile/value.moon index 2dcece9..3c37551 100644 --- a/moonscript/compile/value.moon +++ b/moonscript/compile/value.moon @@ -19,6 +19,7 @@ table_append = (name, len, value) -> } value_compile = + -- list of values separated by binary operators exp: (node) => _comp = (i, value) -> if i % 2 == 1 and value == "!=" @@ -28,11 +29,13 @@ 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 paretheses explist: (node) => with @line! \append_list [@value v for v in *node[2,]], ", " @@ -176,6 +179,7 @@ value_compile = self_colon: (node) => "self:"..@value node[2] + -- catch all pure string values raw_value: (value) => if value == "..." @has_varargs = true