misc cleanup

This commit is contained in:
leaf corcoran 2011-11-06 13:29:30 -08:00
parent 45ba49f16b
commit 2219c44b76
7 changed files with 13 additions and 51 deletions

View File

@ -380,8 +380,8 @@ Block_ = (function()
return nil return nil
end, end,
ret_stms = function(self, stms, ret) ret_stms = function(self, stms, ret)
if not ret then if ret == nil then
ret = default_return ret = error("missing return handler")
end end
local last_exp_id = 0 local last_exp_id = 0
for i = #stms, 1, -1 do for i = #stms, 1, -1 do

View File

@ -258,10 +258,7 @@ class Block_
@add out if out @add out if out
nil nil
ret_stms: (stms, ret) => ret_stms: (stms, ret=error"missing return handler") =>
if not ret
ret = default_return
-- find last exp for explicit return -- find last exp for explicit return
last_exp_id = 0 last_exp_id = 0
for i = #stms, 1, -1 for i = #stms, 1, -1

View File

@ -24,30 +24,10 @@ local manual_return = Set({
"for", "for",
"while" "while"
}) })
default_return = function(exp) cascading = Set({
local t = ntype(exp) "if",
if t == "chain" and exp[2] == "return" then "with"
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
moonlib = { moonlib = {
bind = function(tbl, name) bind = function(tbl, name)
return concat({ return concat({
@ -61,10 +41,6 @@ moonlib = {
}) })
end end
} }
cascading = Set({
"if",
"with"
})
non_atomic = Set({ non_atomic = Set({
"update" "update"
}) })

View File

@ -16,25 +16,13 @@ user_error = (...) ->
error {"user-error", ...} error {"user-error", ...}
manual_return = Set{"foreach", "for", "while"} manual_return = Set{"foreach", "for", "while"}
cascading = Set{ "if", "with" }
default_return = (exp) -> -- TODO get RID OF THIAS
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}
moonlib = moonlib =
bind: (tbl, name) -> bind: (tbl, name) ->
concat {"moon.bind(", tbl, ".", name, ", ", tbl, ")"} concat {"moon.bind(", tbl, ".", name, ", ", tbl, ")"}
cascading = Set{ "if", "with" }
-- an action that can't be completed in a single line -- an action that can't be completed in a single line
non_atomic = Set{ "update" } non_atomic = Set{ "update" }

View File

@ -9,7 +9,6 @@ do
ntype = _table_0.ntype ntype = _table_0.ntype
end end
local concat, insert = table.concat, table.insert local concat, insert = table.concat, table.insert
local constructor_name = "new"
line_compile = { line_compile = {
raw = function(self, node) raw = function(self, node)
local _, text = unpack(node) local _, text = unpack(node)

View File

@ -11,8 +11,6 @@ import concat, insert from table
export line_compile export line_compile
constructor_name = "new"
line_compile = line_compile =
raw: (node) => raw: (node) =>
_, text = unpack node _, text = unpack node

View File

@ -19,6 +19,7 @@ table_append = (name, len, value) ->
} }
value_compile = value_compile =
-- list of values separated by binary operators
exp: (node) => exp: (node) =>
_comp = (i, value) -> _comp = (i, value) ->
if i % 2 == 1 and value == "!=" if i % 2 == 1 and value == "!="
@ -28,11 +29,13 @@ 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) => update: (node) =>
_, name = unpack node _, name = unpack node
@stm node @stm node
@name name @name name
-- list of expressions separated by paretheses
explist: (node) => explist: (node) =>
with @line! with @line!
\append_list [@value v for v in *node[2,]], ", " \append_list [@value v for v in *node[2,]], ", "
@ -176,6 +179,7 @@ value_compile =
self_colon: (node) => self_colon: (node) =>
"self:"..@value node[2] "self:"..@value node[2]
-- catch all pure string values
raw_value: (value) => raw_value: (value) =>
if value == "..." if value == "..."
@has_varargs = true @has_varargs = true