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
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

View File

@ -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

View File

@ -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"
})

View File

@ -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" }

View File

@ -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)

View File

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

View File

@ -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