Add current snapshot1 WASI spec as test + fixes (#31)

* Add WASI spec (minus unions)

* Fill in all WASI shims

* Clean up derives and fix noncopy struct write method

This commit does three things:
* it uses the full, current snapshot1 WASI spec as a compilation test
* it fixes noncopy struct write method (which was incorrectly resolved
  in certain cases to the inherent method of the `GuestPtrMut` rather
  than the interface method `GuestType::write`
* it cleans up derives for structs and unions which should not auto-derive
  `PartialEq`, `Eq`, or `Hash` since their members are not guaranteed to
  be compatible
This commit is contained in:
Jakub Konka
2020-03-02 23:28:13 +01:00
committed by GitHub
parent f4f4156c9d
commit db8fec354d
5 changed files with 1607 additions and 5 deletions

View File

@@ -50,7 +50,7 @@ fn define_copy_struct(names: &Names, name: &witx::Id, s: &witx::StructDatatype)
quote! {
#[repr(C)]
#[derive(Copy, Clone, Debug, ::std::hash::Hash, Eq, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct #ident {
#(#member_decls),*
}
@@ -185,12 +185,12 @@ fn define_ptr_struct(names: &Names, name: &witx::Id, s: &witx::StructDatatype) -
let name = names.struct_member(&ml.member.name);
let offset = ml.offset as u32;
quote! {
self.#name.write(&location.cast(#offset).expect("cast to inner member"));
wiggle_runtime::GuestType::write(&self.#name, &location.cast(#offset).expect("cast to inner member"));
}
});
quote! {
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct #ident<'a> {
#(#member_decls),*
}

View File

@@ -71,7 +71,7 @@ pub(super) fn define_union(names: &Names, name: &witx::Id, u: &witx::UnionDataty
if !u.needs_lifetime() {
// Type does not have a lifetime parameter:
quote! {
#[derive(Clone, Debug, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum #ident {
#(#variants),*
}
@@ -112,7 +112,7 @@ pub(super) fn define_union(names: &Names, name: &witx::Id, u: &witx::UnionDataty
}
} else {
quote! {
#[derive(Clone)]
#[derive(Clone, Debug)]
pub enum #ident<#lifetime> {
#(#variants),*
}