invoke_resumable does not need to take &args anymore

This commit is contained in:
Andrew Dirksen 2018-11-19 14:02:08 -08:00
parent df3bce60d3
commit 9dd258c2bb
2 changed files with 11 additions and 18 deletions

View File

@ -184,26 +184,24 @@ impl FuncInstance {
/// [`Trap`]: #enum.Trap.html /// [`Trap`]: #enum.Trap.html
/// [`start_execution`]: struct.FuncInvocation.html#method.start_execution /// [`start_execution`]: struct.FuncInvocation.html#method.start_execution
/// [`resume_execution`]: struct.FuncInvocation.html#method.resume_execution /// [`resume_execution`]: struct.FuncInvocation.html#method.resume_execution
pub fn invoke_resumable<'args>(func: &FuncRef, args: &'args [RuntimeValue]) -> Result<FuncInvocation<'args>, Trap> { pub fn invoke_resumable(func: &FuncRef) -> FuncInvocation {
check_function_args(func.signature(), &args)?;
match *func.as_internal() { match *func.as_internal() {
FuncInstanceInternal::Internal { .. } => { FuncInstanceInternal::Internal { .. } => {
let value_stack = StackWithLimit::with_size(StackSize::from_element_count(DEFAULT_VALUE_STACK_LIMIT)); let value_stack = StackWithLimit::with_size(StackSize::from_element_count(DEFAULT_VALUE_STACK_LIMIT));
let call_stack = StackWithLimit::with_size(StackSize::from_element_count(DEFAULT_CALL_STACK_LIMIT)); let call_stack = StackWithLimit::with_size(StackSize::from_element_count(DEFAULT_CALL_STACK_LIMIT));
let interpreter = Interpreter::new(value_stack, call_stack); let interpreter = Interpreter::new(value_stack, call_stack);
Ok(FuncInvocation { FuncInvocation {
kind: FuncInvocationKind::Internal(interpreter), kind: FuncInvocationKind::Internal(interpreter),
}) }
} }
FuncInstanceInternal::Host { FuncInstanceInternal::Host {
ref host_func_index, .. ref host_func_index, ..
} => Ok(FuncInvocation { } => FuncInvocation {
kind: FuncInvocationKind::Host { kind: FuncInvocationKind::Host {
args,
host_func_index: *host_func_index, host_func_index: *host_func_index,
finished: false, finished: false,
}, },
}), },
} }
} }
} }
@ -239,20 +237,16 @@ impl From<Trap> for ResumableError {
} }
/// A resumable invocation handle. This struct is returned by `FuncInstance::invoke_resumable`. /// A resumable invocation handle. This struct is returned by `FuncInstance::invoke_resumable`.
pub struct FuncInvocation<'args> { pub struct FuncInvocation {
kind: FuncInvocationKind<'args>, kind: FuncInvocationKind,
} }
enum FuncInvocationKind<'args> { enum FuncInvocationKind {
Internal(Interpreter), Internal(Interpreter),
Host { Host { host_func_index: usize, finished: bool },
args: &'args [RuntimeValue],
host_func_index: usize,
finished: bool,
},
} }
impl<'args> FuncInvocation<'args> { impl FuncInvocation {
/// Whether this invocation is currently resumable. /// Whether this invocation is currently resumable.
pub fn is_resumable(&self) -> bool { pub fn is_resumable(&self) -> bool {
match &self.kind { match &self.kind {
@ -288,7 +282,6 @@ impl<'args> FuncInvocation<'args> {
Ok(interpreter.start_execution(externals, func, args, return_type)?) Ok(interpreter.start_execution(externals, func, args, return_type)?)
} }
FuncInvocationKind::Host { FuncInvocationKind::Host {
ref args,
ref mut finished, ref mut finished,
ref host_func_index, ref host_func_index,
} => { } => {

View File

@ -266,7 +266,7 @@ fn resume_call_host_func() {
let func_instance = export.as_func().unwrap(); let func_instance = export.as_func().unwrap();
let return_type = func_instance.signature().return_type(); let return_type = func_instance.signature().return_type();
let mut invocation = FuncInstance::invoke_resumable(&func_instance, &[]).unwrap(); let mut invocation = FuncInstance::invoke_resumable(&func_instance);
let result = invocation.start_execution(&mut env, func_instance, &[], return_type); let result = invocation.start_execution(&mut env, func_instance, &[], return_type);
match result { match result {
Err(ResumableError::Trap(_)) => {} Err(ResumableError::Trap(_)) => {}