Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the long-defunkt Stack trait #1624

Merged
merged 1 commit into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 45 additions & 98 deletions crates/backend/src/codegen.rs

Large diffs are not rendered by default.

24 changes: 10 additions & 14 deletions src/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,8 @@ where
{
type Abi = u32;

fn into_abi(self, extra: &mut dyn Stack) -> u32 {
(&*self.js).into_abi(extra)
fn into_abi(self) -> u32 {
(&*self.js).into_abi()
}
}

Expand Down Expand Up @@ -561,13 +561,12 @@ macro_rules! doit {
let ret = {
let f: *const dyn Fn($($var),*) -> R =
FatPtr { fields: (a, b) }.ptr;
let mut _stack = GlobalStack::new();
$(
let $var = <$var as FromWasmAbi>::from_abi($var, &mut _stack);
let $var = <$var as FromWasmAbi>::from_abi($var);
)*
(*f)($($var),*)
};
ret.return_abi(&mut GlobalStack::new())
ret.return_abi()
}

inform(invoke::<$($var,)* R> as u32);
Expand Down Expand Up @@ -615,13 +614,12 @@ macro_rules! doit {
let f: *const dyn FnMut($($var),*) -> R =
FatPtr { fields: (a, b) }.ptr;
let f = f as *mut dyn FnMut($($var),*) -> R;
let mut _stack = GlobalStack::new();
$(
let $var = <$var as FromWasmAbi>::from_abi($var, &mut _stack);
let $var = <$var as FromWasmAbi>::from_abi($var);
)*
(*f)($($var),*)
};
ret.return_abi(&mut GlobalStack::new())
ret.return_abi()
}

inform(invoke::<$($var,)* R> as u32);
Expand Down Expand Up @@ -734,11 +732,10 @@ unsafe impl<A, R> WasmClosure for dyn Fn(&A) -> R
let ret = {
let f: *const dyn Fn(&A) -> R =
FatPtr { fields: (a, b) }.ptr;
let mut _stack = GlobalStack::new();
let arg = <A as RefFromWasmAbi>::ref_from_abi(arg, &mut _stack);
let arg = <A as RefFromWasmAbi>::ref_from_abi(arg);
(*f)(&*arg)
};
ret.return_abi(&mut GlobalStack::new())
ret.return_abi()
}

inform(invoke::<A, R> as u32);
Expand Down Expand Up @@ -782,11 +779,10 @@ unsafe impl<A, R> WasmClosure for dyn FnMut(&A) -> R
let f: *const dyn FnMut(&A) -> R =
FatPtr { fields: (a, b) }.ptr;
let f = f as *mut dyn FnMut(&A) -> R;
let mut _stack = GlobalStack::new();
let arg = <A as RefFromWasmAbi>::ref_from_abi(arg, &mut _stack);
let arg = <A as RefFromWasmAbi>::ref_from_abi(arg);
(*f)(&*arg)
};
ret.return_abi(&mut GlobalStack::new())
ret.return_abi()
}

inform(invoke::<A, R> as u32);
Expand Down
30 changes: 13 additions & 17 deletions src/convert/closures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::mem;

use crate::convert::slices::WasmSlice;
use crate::convert::RefFromWasmAbi;
use crate::convert::{FromWasmAbi, GlobalStack, IntoWasmAbi, ReturnWasmAbi, Stack};
use crate::convert::{FromWasmAbi, IntoWasmAbi, ReturnWasmAbi};
use crate::describe::{inform, WasmDescribe, FUNCTION};
use crate::throw_str;

Expand All @@ -14,7 +14,7 @@ macro_rules! stack_closures {
{
type Abi = WasmSlice;

fn into_abi(self, _extra: &mut dyn Stack) -> WasmSlice {
fn into_abi(self) -> WasmSlice {
unsafe {
let (a, b): (usize, usize) = mem::transmute(self);
WasmSlice { ptr: a as u32, len: b as u32 }
Expand All @@ -35,13 +35,12 @@ macro_rules! stack_closures {
// ensure they're all destroyed as `return_abi` may throw
let ret = {
let f: &dyn Fn($($var),*) -> R = mem::transmute((a, b));
let mut _stack = GlobalStack::new();
$(
let $var = <$var as FromWasmAbi>::from_abi($var, &mut _stack);
let $var = <$var as FromWasmAbi>::from_abi($var);
)*
f($($var),*)
};
ret.return_abi(&mut GlobalStack::new())
ret.return_abi()
}

impl<'a, $($var,)* R> WasmDescribe for dyn Fn($($var),*) -> R + 'a
Expand All @@ -63,7 +62,7 @@ macro_rules! stack_closures {
{
type Abi = WasmSlice;

fn into_abi(self, _extra: &mut dyn Stack) -> WasmSlice {
fn into_abi(self) -> WasmSlice {
unsafe {
let (a, b): (usize, usize) = mem::transmute(self);
WasmSlice { ptr: a as u32, len: b as u32 }
Expand All @@ -84,13 +83,12 @@ macro_rules! stack_closures {
// ensure they're all destroyed as `return_abi` may throw
let ret = {
let f: &mut dyn FnMut($($var),*) -> R = mem::transmute((a, b));
let mut _stack = GlobalStack::new();
$(
let $var = <$var as FromWasmAbi>::from_abi($var, &mut _stack);
let $var = <$var as FromWasmAbi>::from_abi($var);
)*
f($($var),*)
};
ret.return_abi(&mut GlobalStack::new())
ret.return_abi()
}

impl<'a, $($var,)* R> WasmDescribe for dyn FnMut($($var),*) -> R + 'a
Expand Down Expand Up @@ -127,7 +125,7 @@ where
{
type Abi = WasmSlice;

fn into_abi(self, _extra: &mut dyn Stack) -> WasmSlice {
fn into_abi(self) -> WasmSlice {
unsafe {
let (a, b): (usize, usize) = mem::transmute(self);
WasmSlice {
Expand All @@ -151,11 +149,10 @@ unsafe extern "C" fn invoke1_ref<A: RefFromWasmAbi, R: ReturnWasmAbi>(
// ensure they're all destroyed as `return_abi` may throw
let ret = {
let f: &dyn Fn(&A) -> R = mem::transmute((a, b));
let mut _stack = GlobalStack::new();
let arg = <A as RefFromWasmAbi>::ref_from_abi(arg, &mut _stack);
let arg = <A as RefFromWasmAbi>::ref_from_abi(arg);
f(&*arg)
};
ret.return_abi(&mut GlobalStack::new())
ret.return_abi()
}

impl<'a, A, R> WasmDescribe for dyn Fn(&A) -> R + 'a
Expand All @@ -179,7 +176,7 @@ where
{
type Abi = WasmSlice;

fn into_abi(self, _extra: &mut dyn Stack) -> WasmSlice {
fn into_abi(self) -> WasmSlice {
unsafe {
let (a, b): (usize, usize) = mem::transmute(self);
WasmSlice {
Expand All @@ -203,11 +200,10 @@ unsafe extern "C" fn invoke1_mut_ref<A: RefFromWasmAbi, R: ReturnWasmAbi>(
// ensure they're all destroyed as `return_abi` may throw
let ret = {
let f: &mut dyn FnMut(&A) -> R = mem::transmute((a, b));
let mut _stack = GlobalStack::new();
let arg = <A as RefFromWasmAbi>::ref_from_abi(arg, &mut _stack);
let arg = <A as RefFromWasmAbi>::ref_from_abi(arg);
f(&*arg)
};
ret.return_abi(&mut GlobalStack::new())
ret.return_abi()
}

impl<'a, A, R> WasmDescribe for dyn FnMut(&A) -> R + 'a
Expand Down
Loading