wiggle: introduce wiggle::Trap, which can be either a String or I32

also, make noreturn functions always return a Trap

wasmtime-wiggle can trivially turn a wiggle::Trap into a wasmtime::Trap.
lucet will have to do the same.
This commit is contained in:
Pat Hickey
2021-01-05 18:19:31 -08:00
parent 4018a06da2
commit f8f9b14c6f
5 changed files with 70 additions and 46 deletions

View File

@@ -48,28 +48,34 @@ pub fn define_module_trait(names: &Names, m: &Module, errxform: &ErrorTransform)
};
quote!(#arg_name: #arg_type)
});
let rets = f
.results
.iter()
.skip(1)
.map(|ret| names.type_ref(&ret.tref, lifetime.clone()));
let err = f
.results
.get(0)
.map(|err_result| {
if let Some(custom_err) = errxform.for_abi_error(&err_result.tref) {
let tn = custom_err.typename();
quote!(super::#tn)
} else {
names.type_ref(&err_result.tref, lifetime.clone())
}
})
.unwrap_or(quote!(()));
let result = if !f.noreturn {
let rets = f
.results
.iter()
.skip(1)
.map(|ret| names.type_ref(&ret.tref, lifetime.clone()));
let err = f
.results
.get(0)
.map(|err_result| {
if let Some(custom_err) = errxform.for_abi_error(&err_result.tref) {
let tn = custom_err.typename();
quote!(super::#tn)
} else {
names.type_ref(&err_result.tref, lifetime.clone())
}
})
.unwrap_or(quote!(()));
quote!( Result<(#(#rets),*), #err> )
} else {
quote!(wiggle::Trap)
};
if is_anonymous {
quote!(fn #funcname(&self, #(#args),*) -> Result<(#(#rets),*), #err>;)
quote!(fn #funcname(&self, #(#args),*) -> #result; )
} else {
quote!(fn #funcname<#lifetime>(&self, #(#args),*) -> Result<(#(#rets),*), #err>;)
quote!(fn #funcname<#lifetime>(&self, #(#args),*) -> #result;)
}
});
quote! {