~sircmpwn/ipcgen

1c9af188c8d06bfc88b5e51879f8da5421340aa7 — Drew DeVault 2 months ago 7d2c825
gen/client: implement caps_out
1 files changed, 25 insertions(+), 3 deletions(-)

M gen/client.ha
M gen/client.ha => gen/client.ha +25 -3
@@ 25,7 25,7 @@ const c_iface_method_src: str =
	${caps_in_setup}const (tag, a1) = helios::call(ep,
		($iface_label::$methodid << 16) | ($ncap << 8) | $nparam,$params
	);
	assert(rt::label(tag) == 0); // TODO: Error handling
	assert(rt::label(tag) == 0); // TODO: Error handling${caps_out}
	return a1: $result;
};
`;


@@ 64,8 64,6 @@ fn c_meth(
	iface: *ast::interface,
	meth: *ast::method,
) (void | io::error) = {
	assert(len(meth.caps_out) == 0);  // TODO

	const id: ast::ident = [meth.name];
	const name = gen_name_upper(&id);
	defer free(name);


@@ 76,6 74,9 @@ fn c_meth(
	let caps_in_setup = strio::dynamic();
	defer io::close(&caps_in_setup)!;

	let caps_out = strio::dynamic();
	defer io::close(&caps_out)!;

	let ncap = strio::dynamic();
	defer io::close(&ncap)!;



@@ 111,6 112,26 @@ fn c_meth(
		ipc_type(&mparams, &param.param_type)!;
		fmt::fprint(&mparams, ",")!;
	};
	for (let i = 0z; i < len(meth.caps_out); i += 1) {
		const cap = &meth.caps_out[i];
		fmt::fprintf(&mparams, "\n\t")!;
		fmt::fprintf(&caps_out, "\n\t")!;
		if (cap.name != "") {
			fmt::fprintf(&mparams, "{}: *helios::cap", cap.name)!;
			fmt::fprintf(&caps_out, "*{} = rt::ipcbuf.caps[{}];",
				cap.name, i)!;
		} else if (len(meth.caps_out) == 1) {
			fmt::fprintf(&mparams, "out: *helios::cap")!;
			fmt::fprintf(&caps_out, "*out = rt::ipcbuf.caps[{}];", i)!;
		} else {
			fmt::fprintf(&mparams, "out{}: *helios::cap", i)!;
			fmt::fprintf(&caps_out, "*out{0} = rt::ipcbuf.caps[{0}];", i)!;
		};

		if (i + 1 < len(meth.caps_out)) {
			fmt::fprint(&mparams, ", ")!;
		};
	};

	let params = strio::dynamic();
	defer io::close(&params)!;


@@ 133,6 154,7 @@ fn c_meth(
		("ncap", strio::string(&ncap)),
		("cparams", strio::string(&cparams)),
		("caps_in_setup", strio::string(&caps_in_setup)),
		("caps_out", strio::string(&caps_out)),
		("mparams", strio::string(&mparams)),
		("params", strio::string(&params)),
	)?;