Refactor naming and crates info (#8)

* Refactor naming and crates info

This commit:
* changes workspace crates to have a `wiggle_` prefix in names
* rename `memory` module of `wiggle-memory` crate to `runtime`
* fixes authors of all crates

* Rename wiggle memory crate to runtime
This commit is contained in:
Jakub Konka
2020-02-13 22:40:42 +01:00
committed by GitHub
parent 44584bccfc
commit 48a218b5c5
17 changed files with 77 additions and 79 deletions

View File

@@ -30,7 +30,7 @@ pub fn define_func(names: &Names, func: &witx::InterfaceFunc) -> TokenStream {
});
let abi_args = quote!(
ctx: &mut #ctx_type, memory: &mut ::memory::GuestMemory,
ctx: &mut #ctx_type, memory: &mut wiggle_runtime::GuestMemory,
#(#params),*
);
let abi_ret = if let Some(ret) = &coretype.ret {
@@ -62,8 +62,8 @@ pub fn define_func(names: &Names, func: &witx::InterfaceFunc) -> TokenStream {
};
let err_typename = names.type_ref(&tref, anon_lifetime());
quote! {
let e = ::memory::GuestError::InFunc { funcname: #funcname, location: #location, err: Box::new(e) };
let err: #err_typename = ::memory::GuestErrorType::from_error(e, ctx);
let e = wiggle_runtime::GuestError::InFunc { funcname: #funcname, location: #location, err: Box::new(e) };
let err: #err_typename = wiggle_runtime::GuestErrorType::from_error(e, ctx);
return #abi_ret::from(err);
}
} else {
@@ -111,7 +111,7 @@ pub fn define_func(names: &Names, func: &witx::InterfaceFunc) -> TokenStream {
let success = if let Some(ref err_type) = err_type {
let err_typename = names.type_ref(&err_type, anon_lifetime());
quote! {
let success:#err_typename = ::memory::GuestErrorType::success();
let success:#err_typename = wiggle_runtime::GuestErrorType::success();
#abi_ret::from(success)
}
} else {

View File

@@ -62,11 +62,11 @@ impl Names {
witx::Type::Builtin(builtin) => self.builtin_type(*builtin),
witx::Type::Pointer(pointee) => {
let pointee_type = self.type_ref(&pointee, lifetime.clone());
quote!(::memory::GuestPtrMut<#lifetime, #pointee_type>)
quote!(wiggle_runtime::GuestPtrMut<#lifetime, #pointee_type>)
}
witx::Type::ConstPointer(pointee) => {
let pointee_type = self.type_ref(&pointee, lifetime.clone());
quote!(::memory::GuestPtr<#lifetime, #pointee_type>)
quote!(wiggle_runtime::GuestPtr<#lifetime, #pointee_type>)
}
_ => unimplemented!("anonymous type ref"),
},

View File

@@ -21,11 +21,14 @@ pub fn define_datatype(names: &Names, namedtype: &witx::NamedType) -> TokenStrea
witx::Type::Union(_) => unimplemented!("union types"),
witx::Type::Handle(_h) => unimplemented!("handle types"),
witx::Type::Builtin(b) => define_builtin(names, &namedtype.name, *b),
witx::Type::Pointer(p) => {
define_witx_pointer(names, &namedtype.name, quote!(::memory::GuestPtrMut), p)
}
witx::Type::Pointer(p) => define_witx_pointer(
names,
&namedtype.name,
quote!(wiggle_runtime::GuestPtrMut),
p,
),
witx::Type::ConstPointer(p) => {
define_witx_pointer(names, &namedtype.name, quote!(::memory::GuestPtr), p)
define_witx_pointer(names, &namedtype.name, quote!(wiggle_runtime::GuestPtr), p)
}
witx::Type::Array { .. } => unimplemented!("array types"),
},
@@ -69,18 +72,18 @@ fn define_enum(names: &Names, name: &witx::Id, e: &witx::EnumDatatype) -> TokenS
}
impl ::std::convert::TryFrom<#repr> for #ident {
type Error = ::memory::GuestError;
fn try_from(value: #repr) -> Result<#ident, ::memory::GuestError> {
type Error = wiggle_runtime::GuestError;
fn try_from(value: #repr) -> Result<#ident, wiggle_runtime::GuestError> {
match value as usize {
#(#tryfrom_repr_cases),*,
_ => Err(::memory::GuestError::InvalidEnumValue(stringify!(#ident))),
_ => Err(wiggle_runtime::GuestError::InvalidEnumValue(stringify!(#ident))),
}
}
}
impl ::std::convert::TryFrom<#abi_repr> for #ident {
type Error = ::memory::GuestError;
fn try_from(value: #abi_repr) -> Result<#ident, ::memory::GuestError> {
type Error = wiggle_runtime::GuestError;
fn try_from(value: #abi_repr) -> Result<#ident, wiggle_runtime::GuestError> {
#ident::try_from(value as #repr)
}
}
@@ -99,7 +102,7 @@ fn define_enum(names: &Names, name: &witx::Id, e: &witx::EnumDatatype) -> TokenS
}
}
impl ::memory::GuestType for #ident {
impl wiggle_runtime::GuestType for #ident {
fn size() -> u32 {
::std::mem::size_of::<#repr>() as u32
}
@@ -109,7 +112,7 @@ fn define_enum(names: &Names, name: &witx::Id, e: &witx::EnumDatatype) -> TokenS
fn name() -> String {
stringify!(#ident).to_owned()
}
fn validate<'a>(location: &::memory::GuestPtr<'a, #ident>) -> Result<(), ::memory::GuestError> {
fn validate<'a>(location: &wiggle_runtime::GuestPtr<'a, #ident>) -> Result<(), wiggle_runtime::GuestError> {
use ::std::convert::TryFrom;
let raw: #repr = unsafe { (location.as_raw() as *const #repr).read() };
let _ = #ident::try_from(raw)?;
@@ -117,15 +120,15 @@ fn define_enum(names: &Names, name: &witx::Id, e: &witx::EnumDatatype) -> TokenS
}
}
impl ::memory::GuestTypeCopy for #ident {}
impl ::memory::GuestTypeClone for #ident {
fn read_from_guest(location: &::memory::GuestPtr<#ident>) -> Result<#ident, ::memory::GuestError> {
impl wiggle_runtime::GuestTypeCopy for #ident {}
impl wiggle_runtime::GuestTypeClone for #ident {
fn read_from_guest(location: &wiggle_runtime::GuestPtr<#ident>) -> Result<#ident, wiggle_runtime::GuestError> {
use ::std::convert::TryFrom;
let raw: #repr = unsafe { (location.as_raw() as *const #repr).read() };
let val = #ident::try_from(raw)?;
Ok(val)
}
fn write_to_guest(&self, location: &::memory::GuestPtrMut<#ident>) {
fn write_to_guest(&self, location: &wiggle_runtime::GuestPtrMut<#ident>) {
let val: #repr = #repr::from(*self);
unsafe { (location.as_raw() as *mut #repr).write(val) };
}
@@ -192,13 +195,13 @@ fn define_copy_struct(names: &Names, name: &witx::Id, s: &witx::StructDatatype)
quote! {
#type_::validate(
&ptr.cast(#offset).map_err(|e|
::memory::GuestError::InDataField{
wiggle_runtime::GuestError::InDataField{
typename: stringify!(#ident).to_owned(),
field: stringify!(#fieldname).to_owned(),
err: Box::new(e),
})?
).map_err(|e|
::memory::GuestError::InDataField {
wiggle_runtime::GuestError::InDataField {
typename: stringify!(#ident).to_owned(),
field: stringify!(#fieldname).to_owned(),
err: Box::new(e),
@@ -213,7 +216,7 @@ fn define_copy_struct(names: &Names, name: &witx::Id, s: &witx::StructDatatype)
#(#member_decls),*
}
impl ::memory::GuestType for #ident {
impl wiggle_runtime::GuestType for #ident {
fn size() -> u32 {
#size
}
@@ -223,12 +226,12 @@ fn define_copy_struct(names: &Names, name: &witx::Id, s: &witx::StructDatatype)
fn name() -> String {
stringify!(#ident).to_owned()
}
fn validate(ptr: &::memory::GuestPtr<#ident>) -> Result<(), ::memory::GuestError> {
fn validate(ptr: &wiggle_runtime::GuestPtr<#ident>) -> Result<(), wiggle_runtime::GuestError> {
#(#member_valids)*
Ok(())
}
}
impl ::memory::GuestTypeCopy for #ident {}
impl wiggle_runtime::GuestTypeCopy for #ident {}
}
}
@@ -246,11 +249,11 @@ fn define_ptr_struct(names: &Names, name: &witx::Id, s: &witx::StructDatatype) -
witx::Type::Builtin(builtin) => names.builtin_type(*builtin),
witx::Type::Pointer(pointee) => {
let pointee_type = names.type_ref(&pointee, quote!('a));
quote!(::memory::GuestPtrMut<'a, #pointee_type>)
quote!(wiggle_runtime::GuestPtrMut<'a, #pointee_type>)
}
witx::Type::ConstPointer(pointee) => {
let pointee_type = names.type_ref(&pointee, quote!('a));
quote!(::memory::GuestPtr<'a, #pointee_type>)
quote!(wiggle_runtime::GuestPtr<'a, #pointee_type>)
}
_ => unimplemented!("other anonymous struct members"),
},
@@ -264,11 +267,11 @@ fn define_ptr_struct(names: &Names, name: &witx::Id, s: &witx::StructDatatype) -
witx::Type::Builtin(builtin) => names.builtin_type(*builtin),
witx::Type::Pointer(pointee) => {
let pointee_type = names.type_ref(&pointee, anon_lifetime());
quote!(::memory::GuestPtrMut::<#pointee_type>)
quote!(wiggle_runtime::GuestPtrMut::<#pointee_type>)
}
witx::Type::ConstPointer(pointee) => {
let pointee_type = names.type_ref(&pointee, anon_lifetime());
quote!(::memory::GuestPtr::<#pointee_type>)
quote!(wiggle_runtime::GuestPtr::<#pointee_type>)
}
_ => unimplemented!("other anonymous struct members"),
},
@@ -278,13 +281,13 @@ fn define_ptr_struct(names: &Names, name: &witx::Id, s: &witx::StructDatatype) -
quote! {
#type_::validate(
&ptr.cast(#offset).map_err(|e|
::memory::GuestError::InDataField{
wiggle_runtime::GuestError::InDataField{
typename: stringify!(#ident).to_owned(),
field: stringify!(#fieldname).to_owned(),
err: Box::new(e),
})?
).map_err(|e|
::memory::GuestError::InDataField {
wiggle_runtime::GuestError::InDataField {
typename: stringify!(#ident).to_owned(),
field: stringify!(#fieldname).to_owned(),
err: Box::new(e),
@@ -312,13 +315,13 @@ fn define_ptr_struct(names: &Names, name: &witx::Id, s: &witx::StructDatatype) -
witx::Type::Pointer(pointee) => {
let pointee_type = names.type_ref(&pointee, anon_lifetime());
quote! {
let #name = ::memory::GuestPtrMut::<#pointee_type>::read_from_guest(&location.cast(#offset)?)?;
let #name = wiggle_runtime::GuestPtrMut::<#pointee_type>::read_from_guest(&location.cast(#offset)?)?;
}
}
witx::Type::ConstPointer(pointee) => {
let pointee_type = names.type_ref(&pointee, anon_lifetime());
quote! {
let #name = ::memory::GuestPtr::<#pointee_type>::read_from_guest(&location.cast(#offset)?)?;
let #name = wiggle_runtime::GuestPtr::<#pointee_type>::read_from_guest(&location.cast(#offset)?)?;
}
}
_ => unimplemented!("other anonymous struct members"),
@@ -338,7 +341,7 @@ fn define_ptr_struct(names: &Names, name: &witx::Id, s: &witx::StructDatatype) -
#(#member_decls),*
}
impl<'a> ::memory::GuestType for #ident<'a> {
impl<'a> wiggle_runtime::GuestType for #ident<'a> {
fn size() -> u32 {
#size
}
@@ -348,17 +351,17 @@ fn define_ptr_struct(names: &Names, name: &witx::Id, s: &witx::StructDatatype) -
fn name() -> String {
stringify!(#ident).to_owned()
}
fn validate(ptr: &::memory::GuestPtr<#ident>) -> Result<(), ::memory::GuestError> {
fn validate(ptr: &wiggle_runtime::GuestPtr<#ident>) -> Result<(), wiggle_runtime::GuestError> {
#(#member_valids)*
Ok(())
}
}
impl<'a> ::memory::GuestTypePtr<'a> for #ident<'a> {
fn read_from_guest(location: &::memory::GuestPtr<'a, #ident<'a>>) -> Result<#ident<'a>, ::memory::GuestError> {
impl<'a> wiggle_runtime::GuestTypePtr<'a> for #ident<'a> {
fn read_from_guest(location: &wiggle_runtime::GuestPtr<'a, #ident<'a>>) -> Result<#ident<'a>, wiggle_runtime::GuestError> {
#(#member_reads)*
Ok(#ident { #(#member_names),* })
}
fn write_to_guest(&self, location: &::memory::GuestPtrMut<'a, Self>) {
fn write_to_guest(&self, location: &wiggle_runtime::GuestPtrMut<'a, Self>) {
#(#member_writes)*
}
}