new memory model. not quite complete
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ pub fn from_witx(args: TokenStream) -> TokenStream {
|
||||
mod #modname {
|
||||
use super::WasiCtx;
|
||||
use super::types::*;
|
||||
#(#fs)*
|
||||
// #(#fs)*
|
||||
|
||||
#modtrait
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user