Update to the next version of the witx crate
This commit updates to the 0.9 version of the witx crate implemented in WebAssembly/wasi#395. This new version drastically changes code generation and how we interface with the crate. The intention is to abstract the code generation aspects and allow code generators to implement much more low-level instructions to enable more flexible APIs in the future. Additionally a bunch of `*.witx` files were updated in the WASI repository. It's worth pointing out, however, that `wasi-common` does not change as a result of this change. The shape of the APIs that we need to implement are effectively the same and the only difference is that the shim functions generated by wiggle are a bit different.
This commit is contained in:
committed by
Andrew Brown
parent
aed6de32d4
commit
df9c725fa0
@@ -7,17 +7,9 @@ use crate::names::Names;
|
||||
use witx::Module;
|
||||
|
||||
pub fn passed_by_reference(ty: &witx::Type) -> bool {
|
||||
let passed_by = match ty.passed_by() {
|
||||
witx::TypePassedBy::Value { .. } => false,
|
||||
witx::TypePassedBy::Pointer { .. } | witx::TypePassedBy::PointerLengthPair { .. } => true,
|
||||
};
|
||||
match ty {
|
||||
witx::Type::Builtin(b) => match &*b {
|
||||
witx::BuiltinType::String => true,
|
||||
_ => passed_by,
|
||||
},
|
||||
witx::Type::Pointer(_) | witx::Type::ConstPointer(_) | witx::Type::Array(_) => true,
|
||||
_ => passed_by,
|
||||
witx::Type::Pointer(_) | witx::Type::ConstPointer(_) | witx::Type::List(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,28 +41,36 @@ pub fn define_module_trait(names: &Names, m: &Module, errxform: &ErrorTransform)
|
||||
quote!(#arg_name: #arg_type)
|
||||
});
|
||||
|
||||
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 {
|
||||
let rt = names.runtime_mod();
|
||||
quote!(#rt::Trap)
|
||||
let rt = names.runtime_mod();
|
||||
let result = match f.results.len() {
|
||||
0 if f.noreturn => quote!(#rt::Trap),
|
||||
0 => quote!(()),
|
||||
1 => {
|
||||
let (ok, err) = match &**f.results[0].tref.type_() {
|
||||
witx::Type::Variant(v) => match v.as_expected() {
|
||||
Some(p) => p,
|
||||
None => unimplemented!("anonymous variant ref {:?}", v),
|
||||
},
|
||||
_ => unimplemented!(),
|
||||
};
|
||||
|
||||
let ok = match ok {
|
||||
Some(ty) => names.type_ref(ty, lifetime.clone()),
|
||||
None => quote!(()),
|
||||
};
|
||||
let err = match err {
|
||||
Some(ty) => match errxform.for_abi_error(ty) {
|
||||
Some(custom) => {
|
||||
let tn = custom.typename();
|
||||
quote!(super::#tn)
|
||||
}
|
||||
None => names.type_ref(ty, lifetime.clone()),
|
||||
},
|
||||
None => quote!(()),
|
||||
};
|
||||
quote!(Result<#ok, #err>)
|
||||
}
|
||||
_ => unimplemented!(),
|
||||
};
|
||||
|
||||
if is_anonymous {
|
||||
|
||||
Reference in New Issue
Block a user