new memory model. not quite complete

This commit is contained in:
Pat Hickey
2020-01-27 18:20:47 -08:00
parent e6a4ae205c
commit ec456e9e50
8 changed files with 287 additions and 179 deletions

View File

@@ -74,7 +74,8 @@ pub fn define_func(names: &Names, func: &witx::InterfaceFunc) -> TokenStream {
let marshal_args = func
.params
.iter()
.map(|p| marshal_arg(names, p, error_handling.clone()));
//.map(|p| marshal_arg(names, p, error_handling.clone()));
.map(|_p| quote!(unimplemented!(); )); // FIXME
let trait_args = func
.params
.iter()
@@ -98,7 +99,8 @@ pub fn define_func(names: &Names, func: &witx::InterfaceFunc) -> TokenStream {
.results
.iter()
.skip(1)
.map(|result| marshal_result(names, result, error_handling.clone()));
//.map(|result| marshal_result(names, result, error_handling.clone()));
.map(|_result| (quote!(unimplemented!();), quote!(unimplemented!();))); // FIXME
let marshal_rets_pre = marshal_rets.clone().map(|(pre, _post)| pre);
let marshal_rets_post = marshal_rets.map(|(_pre, post)| post);

View File

@@ -34,7 +34,7 @@ pub fn from_witx(args: TokenStream) -> TokenStream {
mod #modname {
use super::WasiCtx;
use super::types::*;
#(#fs)*
// #(#fs)*
#modtrait
}

View File

@@ -89,24 +89,30 @@ fn define_enum(names: &Names, name: &witx::Id, e: &witx::EnumDatatype) -> TokenS
fn size() -> u32 {
::std::mem::size_of::<#repr>() as u32
}
fn name() -> &'static str {
stringify!(#ident)
fn align() -> u32 {
::std::mem::align_of::<#repr>() as u32
}
fn name() -> String {
stringify!(#ident).to_owned()
}
fn validate<'a>(location: &::memory::GuestPtr<'a, #ident>) -> Result<(), ::memory::GuestError> {
use ::std::convert::TryFrom;
let raw: #repr = unsafe { (location.as_raw() as *const #repr).read() };
let _ = #ident::try_from(raw)?;
Ok(())
}
}
impl ::memory::GuestTypeCopy for #ident {
fn read_val<'a, P: ::memory::GuestPtrRead<'a, #ident>>(src: &P) -> Result<#ident, ::memory::GuestError> {
use ::std::convert::TryInto;
let val = unsafe { ::std::ptr::read_unaligned(src.ptr() as *const #repr) };
val.try_into()
}
fn write_val(val: #ident, dest: &::memory::GuestPtrMut<#ident>) {
let val: #repr = val.into();
unsafe {
::std::ptr::write_unaligned(dest.ptr_mut() as *mut #repr, val)
};
impl ::memory::GuestTypeCopy for #ident {}
impl ::memory::GuestTypeClone for #ident {
fn from_guest(location: &::memory::GuestPtr<#ident>) -> Result<#ident, ::memory::GuestError> {
use ::std::convert::TryFrom;
let raw: #repr = unsafe { (location.as_raw() as *const #repr).read() };
let val = #ident::try_from(raw)?;
Ok(val)
}
}
}
}