Commit 05584663 authored by Kunshan Wang's avatar Kunshan Wang

API-GEN: Generated return value converters.

Now the API stubs (__api_impl_stubs.rs) should be ready for use.
parent 7ea266ca
......@@ -32,11 +32,11 @@ impl MuVM {
panic!("Not implemented")
}
pub fn id_of(&mut self, name: MuName) -> CMuID {
pub fn id_of(&mut self, name: MuName) -> MuID {
panic!("Not implemented")
}
pub fn name_of(&mut self, id: MuID) -> CMuName {
pub fn name_of(&mut self, id: MuID) -> CMuCString {
panic!("Not implemented")
}
......@@ -47,11 +47,11 @@ impl MuVM {
}
impl MuCtx {
pub fn id_of(&mut self, name: MuName) -> CMuID {
pub fn id_of(&mut self, name: MuName) -> MuID {
panic!("Not implemented")
}
pub fn name_of(&mut self, id: MuID) -> CMuName {
pub fn name_of(&mut self, id: MuID) -> CMuCString {
panic!("Not implemented")
}
......@@ -187,11 +187,11 @@ impl MuCtx {
panic!("Not implemented")
}
pub fn ref_eq(&mut self, lhs: &APIMuValue, rhs: &APIMuValue) -> CMuBool {
pub fn ref_eq(&mut self, lhs: &APIMuValue, rhs: &APIMuValue) -> bool {
panic!("Not implemented")
}
pub fn ref_ult(&mut self, lhs: &APIMuValue, rhs: &APIMuValue) -> CMuBool {
pub fn ref_ult(&mut self, lhs: &APIMuValue, rhs: &APIMuValue) -> bool {
panic!("Not implemented")
}
......@@ -303,15 +303,15 @@ impl MuCtx {
panic!("Not implemented")
}
pub fn cur_func(&mut self, cursor: &APIMuValue) -> CMuID {
pub fn cur_func(&mut self, cursor: &APIMuValue) -> MuID {
panic!("Not implemented")
}
pub fn cur_func_ver(&mut self, cursor: &APIMuValue) -> CMuID {
pub fn cur_func_ver(&mut self, cursor: &APIMuValue) -> MuID {
panic!("Not implemented")
}
pub fn cur_inst(&mut self, cursor: &APIMuValue) -> CMuID {
pub fn cur_inst(&mut self, cursor: &APIMuValue) -> MuID {
panic!("Not implemented")
}
......@@ -327,15 +327,15 @@ impl MuCtx {
panic!("Not implemented")
}
pub fn tr64_is_fp(&mut self, value: &APIMuValue) -> CMuBool {
pub fn tr64_is_fp(&mut self, value: &APIMuValue) -> bool {
panic!("Not implemented")
}
pub fn tr64_is_int(&mut self, value: &APIMuValue) -> CMuBool {
pub fn tr64_is_int(&mut self, value: &APIMuValue) -> bool {
panic!("Not implemented")
}
pub fn tr64_is_ref(&mut self, value: &APIMuValue) -> CMuBool {
pub fn tr64_is_ref(&mut self, value: &APIMuValue) -> bool {
panic!("Not implemented")
}
......@@ -414,7 +414,7 @@ impl MuIRBuilder {
panic!("Not implemented")
}
pub fn gen_sym(&mut self, name: Option<String>) -> CMuID {
pub fn gen_sym(&mut self, name: Option<String>) -> MuID {
panic!("Not implemented")
}
......
This diff is collapsed.
......@@ -485,11 +485,23 @@ _cty_to_high_level_ret_ty = {
"MuName": "CMuCString",
}
_cty_directly_returned = {
*_no_conversion,
# see above
"MuCString",
"MuName",
# To be safe, let the micro VM fill up the structs.
"MuVM*",
"MuCtx*",
"MuIRBuilder*",
}
def to_high_level_ret_ty(cty, rty):
assert cty != "void"
if cty in _cty_to_high_level_ret_ty:
hlt = _cty_to_high_level_ret_ty[cty]
if type_is_handle(cty):
elif type_is_handle(cty):
hlt = "*mut APIMuValue"
elif type_is_node(cty):
hlt = "MuID"
......@@ -630,16 +642,27 @@ def generate_forwarder_and_stub(st, meth) -> Tuple[str, str]:
other_args = args[1:]
args_joined = ", ".join(other_args)
ret_val_bind = "" if rust_ret_ty is None else "let _rv = "
stmts.append(" unsafe {")
call_stmt = ' {}(*{}).{}({});'.format(
ret_val_bind, self_arg, name, args_joined)
stmts.append(" {}unsafe {{".format(ret_val_bind))
call_stmt = ' (*{}).{}({})'.format(
self_arg, name, args_joined)
stmts.append(call_stmt)
stmts.append(" }")
stmts.append(" };")
# TODO: return values
# return values
stmts.append(' panic!("not implemented")')
if rust_ret_ty is not None:
if ret_ty in _cty_directly_returned:
converter = "_rv"
elif type_is_handle(ret_ty):
converter = "to_handle(_rv)"
elif type_is_node(ret_ty):
converter = "to_MuID(_rv)"
else:
converter = "to_{}(_rv)".format(ret_ty)
stmts.append(" let _rv_prep = {};".format(converter))
stmts.append(" _rv_prep")
# stmts.append(' panic!("not implemented")')
# forwarder
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment