aboutsummaryrefslogtreecommitdiff
path: root/lib/object.nom
diff options
context:
space:
mode:
Diffstat (limited to 'lib/object.nom')
-rw-r--r--lib/object.nom22
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/object.nom b/lib/object.nom
index 2f2f3ff..ca664b5 100644
--- a/lib/object.nom
+++ b/lib/object.nom
@@ -33,17 +33,21 @@ compile [define object %classname %class_body] to:
for %line in (%class_body's "value"):
if: (%line's "type") is "Comment"
do next %line
- assume (((%line's "type") == "FunctionCall") and ((%line's "stub") == "action % %"))
+ assume (((%line's "type") == "FunctionCall") and ((%line's stub) == "action % %"))
..or barf "Only action definitions are supported inside 'define object % %', not \(%line's "src")"
%actions <- (2nd in (%line's "value"))
%body <- (3rd in (%line's "value"))
lua> ".."
- local signature = {};
- for i, action in ipairs(\%actions.value) do signature[i] = action:get_src(); end
- local stubs = nomsu:get_stubs_from_signature(signature);
- local stub_args = nomsu:get_args_from_signature(signature);
+ local stubs = {};
+ for i, action in ipairs(\%actions.value) do
+ stubs[i] = nomsu:tree_to_named_stub(action);
+ end
+ local args = {};
+ for i,tok in ipairs(\%actions.value[1].value) do
+ if tok.type == "Var" then args[#args+1] = nomsu:var_to_lua_identifier(tok.value); end
+ end
local arg_set = {};
- for i, arg in ipairs(stub_args[1]) do arg_set[arg] = true; end
+ for i, arg in ipairs(args) do arg_set[arg] = true; end
local body_lua = nomsu:tree_to_lua(\%body);
local body_code = body_lua.statements or ("return "..body_lua.expr..";");
local undeclared_locals = {};
@@ -55,12 +59,12 @@ compile [define object %classname %class_body] to:
if #undeclared_locals > 0 then
body_code = "local "..table.concat(undeclared_locals, ", ")..";\\n"..body_code;
end
- local lua_fn_args = table.concat(stub_args[1], ", ");
+ local lua_fn_args = table.concat(args, ", ");
local def_tree = nomsu.compilestack[#nomsu.compilestack];
local code_location = ("%s:%s,%s"):format(def_tree.filename, def_tree.start, def_tree.stop);
local compiled_args = {};
- for i, arg in ipairs(stub_args[1]) do
+ for i, arg in ipairs(args) do
compiled_args[i] = "nomsu:tree_to_lua("..arg..").expr";
end
compiled_args = table.concat(compiled_args, "..', '..");
@@ -75,7 +79,7 @@ compile [define object %classname %class_body] to:
]==]):format(
\%class_identifier, repr(stubs[1]), lua_fn_args,
body_code,
- repr(signature), repr(code_location), lua_fn_args,
+ repr(stubs), repr(code_location), lua_fn_args,
repr(repr(stubs[1])), compiled_args,
\%class_identifier, repr(stubs[1]), repr(stubs[1])));