Skip to content
Permalink
Browse files

eliminate more std

  • Loading branch information
syntacticsugarglider committed Dec 30, 2019
1 parent 9188063 commit cbe8a4c2f7db413be2184df0b4e7e8e1e07ef108
Showing with 17 additions and 15 deletions.
  1. +8 −6 derive/src/export.rs
  2. +9 −9 derive/src/object.rs
@@ -3,6 +3,7 @@ use quote::quote;

pub fn build(block: TokenStream) -> TokenStream {
quote! {
extern crate alloc as EXPORT_alloc;
#[cfg(target_arch = "wasm32")]
extern "C" {
fn _EXPORT_output(ptr: *const u8, len: usize);
@@ -16,7 +17,8 @@ pub fn build(block: TokenStream) -> TokenStream {
#[cfg(target_arch = "wasm32")]
#[no_mangle]
pub extern "C" fn _EXPORT_make_buffer(len: usize) -> *mut u8 {
use ::std::{mem::{size_of, forget, align_of}, ptr::write, alloc::{alloc, Layout}};
use ::core::{mem::{size_of, forget, align_of}, ptr::write};
use EXPORT_alloc::alloc::{alloc, Layout};
let len_size = size_of::<usize>();
unsafe {
let ptr = alloc(Layout::from_size_align(len + len_size, align_of::<u8>()).unwrap());
@@ -25,12 +27,12 @@ pub fn build(block: TokenStream) -> TokenStream {
}
}
::vessels::lazy_static::lazy_static! {
static ref DATA: ::vessels::futures::lock::Mutex<(::vessels::futures::channel::mpsc::UnboundedSender<Vec<u8>>, Option<::vessels::futures::channel::mpsc::UnboundedReceiver<Vec<u8>>>)> = { let (sender, receiver) = ::vessels::futures::channel::mpsc::unbounded(); ::vessels::futures::lock::Mutex::new((sender, Some(receiver))) };
static ref DATA: ::vessels::futures::lock::Mutex<(::vessels::futures::channel::mpsc::UnboundedSender<EXPORT_alloc::vec::Vec<u8>>, Option<::vessels::futures::channel::mpsc::UnboundedReceiver<EXPORT_alloc::vec::Vec<u8>>>)> = { let (sender, receiver) = ::vessels::futures::channel::mpsc::unbounded(); ::vessels::futures::lock::Mutex::new((sender, Some(receiver))) };
}
#[cfg(target_arch = "wasm32")]
#[no_mangle]
pub extern "C" fn _EXPORT_input(data: *mut u8) {
use ::std::{mem::size_of, slice};
use ::core::{mem::size_of, slice};
unsafe {
let len = Box::from_raw(data.sub(size_of::<usize>()) as *mut usize);
let data = slice::from_raw_parts_mut(data, *len).to_vec();
@@ -43,9 +45,9 @@ pub fn build(block: TokenStream) -> TokenStream {
#[cfg(target_arch = "wasm32")]
#[no_mangle]
pub extern "C" fn _EXPORT_initialize() {
std::panic::set_hook(Box::new(|info| {
use ::std::ops::Deref;
let cause = info.payload().downcast_ref::<String>().map(String::deref);
::std::panic::set_hook(Box::new(|info| {
use ::core::ops::Deref;
let cause = info.payload().downcast_ref::<EXPORT_alloc::string::String>().map(EXPORT_alloc::string::String::deref);
let cause = cause.unwrap_or_else(||
info.payload().downcast_ref::<&str>().map(|s| *s)
.unwrap_or("<cause unknown>")
@@ -250,13 +250,13 @@ pub fn build(_: TokenStream, item: &mut ItemTrait) -> TokenStream {
});
supertrait_impls.extend(quote! {
impl<#kind_bounded_params> ::vessels::reflect::Trait<dyn #path> for _DERIVED_Shim<#params> {
fn call(&self, index: ::vessels::reflect::MethodIndex, mut args: Vec<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>>) -> ::core::result::Result<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>, ::vessels::reflect::CallError> {
fn call(&self, index: ::vessels::reflect::MethodIndex, mut args: DERIVE_alloc::vec::Vec<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>>) -> ::core::result::Result<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>, ::vessels::reflect::CallError> {
::vessels::reflect::Trait::<dyn #path>::call(self.#id.lock().unwrap().as_ref() as &dyn #path, index, args)
}
fn call_mut(&mut self, index: ::vessels::reflect::MethodIndex, mut args: Vec<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>>) -> ::core::result::Result<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>, ::vessels::reflect::CallError> {
fn call_mut(&mut self, index: ::vessels::reflect::MethodIndex, mut args: DERIVE_alloc::vec::Vec<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>>) -> ::core::result::Result<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>, ::vessels::reflect::CallError> {
::vessels::reflect::Trait::<dyn #path>::call_mut(self.#id.lock().unwrap().as_mut() as &mut dyn #path, index, args)
}
fn call_move(self: DERIVE_alloc::boxed::Box<Self>, index: ::vessels::reflect::MethodIndex, mut args: Vec<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>>) -> ::core::result::Result<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>, ::vessels::reflect::CallError> {
fn call_move(self: DERIVE_alloc::boxed::Box<Self>, index: ::vessels::reflect::MethodIndex, mut args: DERIVE_alloc::vec::Vec<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>>) -> ::core::result::Result<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>, ::vessels::reflect::CallError> {
::vessels::reflect::Trait::<dyn #path>::call_move(DERIVE_alloc::sync::Arc::try_unwrap(self.#id).map_err(|_| panic!("arc is not held exclusively")).unwrap().into_inner().unwrap() as DERIVE_alloc::boxed::Box<dyn #path>, index, args)
}
fn by_name(&self, name: &'_ str) -> ::core::result::Result<::vessels::reflect::MethodIndex, ::vessels::reflect::NameError> {
@@ -360,13 +360,13 @@ pub fn build(_: TokenStream, item: &mut ItemTrait) -> TokenStream {
}
}
impl<#kind_bounded_params> ::vessels::reflect::Trait<::vessels::reflect::SomeTrait> for _DERIVED_ErasedShim<#params> {
fn call(&self, index: ::vessels::reflect::MethodIndex, mut args: Vec<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>>) -> ::core::result::Result<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>, ::vessels::reflect::CallError> {
fn call(&self, index: ::vessels::reflect::MethodIndex, mut args: DERIVE_alloc::vec::Vec<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>>) -> ::core::result::Result<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>, ::vessels::reflect::CallError> {
::vessels::reflect::Trait::call(self.0.as_ref(), index, args)
}
fn call_mut(&mut self, index: ::vessels::reflect::MethodIndex, mut args: Vec<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>>) -> ::core::result::Result<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>, ::vessels::reflect::CallError> {
fn call_mut(&mut self, index: ::vessels::reflect::MethodIndex, mut args: DERIVE_alloc::vec::Vec<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>>) -> ::core::result::Result<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>, ::vessels::reflect::CallError> {
::vessels::reflect::Trait::call_mut(self.0.as_mut(), index, args)
}
fn call_move(self: DERIVE_alloc::boxed::Box<Self>, index: ::vessels::reflect::MethodIndex, mut args: Vec<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>>) -> ::core::result::Result<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>, ::vessels::reflect::CallError> {
fn call_move(self: DERIVE_alloc::boxed::Box<Self>, index: ::vessels::reflect::MethodIndex, mut args: DERIVE_alloc::vec::Vec<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>>) -> ::core::result::Result<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>, ::vessels::reflect::CallError> {
::vessels::reflect::Trait::call_move(self.0, index, args)
}
fn by_name(&self, name: &'_ str) -> ::core::result::Result<::vessels::reflect::MethodIndex, ::vessels::reflect::NameError> {
@@ -399,7 +399,7 @@ pub fn build(_: TokenStream, item: &mut ItemTrait) -> TokenStream {
}
#[doc(hidden)]
impl<#kind_bounded_params> ::vessels::reflect::Trait<dyn #ident<#params>> for dyn #ident<#params> {
fn call(&self, index: ::vessels::reflect::MethodIndex, mut args: Vec<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>>) -> ::core::result::Result<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>, ::vessels::reflect::CallError> {
fn call(&self, index: ::vessels::reflect::MethodIndex, mut args: DERIVE_alloc::vec::Vec<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>>) -> ::core::result::Result<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>, ::vessels::reflect::CallError> {
args.reverse();
match index {
#call_arms
@@ -408,7 +408,7 @@ pub fn build(_: TokenStream, item: &mut ItemTrait) -> TokenStream {
})),
}
}
fn call_mut(&mut self, index: ::vessels::reflect::MethodIndex, mut args: Vec<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>>) -> ::core::result::Result<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>, ::vessels::reflect::CallError> {
fn call_mut(&mut self, index: ::vessels::reflect::MethodIndex, mut args: DERIVE_alloc::vec::Vec<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>>) -> ::core::result::Result<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>, ::vessels::reflect::CallError> {
args.reverse();
match index {
#call_mut_arms
@@ -417,7 +417,7 @@ pub fn build(_: TokenStream, item: &mut ItemTrait) -> TokenStream {
})),
}
}
fn call_move(self: DERIVE_alloc::boxed::Box<Self>, index: ::vessels::reflect::MethodIndex, mut args: Vec<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Sync + Send>>) -> ::core::result::Result<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>, ::vessels::reflect::CallError> {
fn call_move(self: DERIVE_alloc::boxed::Box<Self>, index: ::vessels::reflect::MethodIndex, mut args: DERIVE_alloc::vec::Vec<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Sync + Send>>) -> ::core::result::Result<DERIVE_alloc::boxed::Box<dyn ::core::any::Any + Send + Sync>, ::vessels::reflect::CallError> {
args.reverse();
match index {
#call_move_arms

0 comments on commit cbe8a4c

Please sign in to comment.
You can’t perform that action at this time.