Move stack with limit utils to runner.rs

This commit is contained in:
Sergey Pepyakin 2018-01-08 18:02:37 +03:00
parent 604374442d
commit 97b74ed10e
3 changed files with 26 additions and 30 deletions

View File

@ -139,7 +139,6 @@ mod memory;
mod module;
mod program;
mod runner;
mod stack;
mod table;
mod value;
mod host;

View File

@ -1164,3 +1164,29 @@ pub fn prepare_function_args(function_type: &FunctionType, caller_stack: &mut St
args.reverse();
Ok(args)
}
impl StackWithLimit<RuntimeValue> {
fn pop_as<T>(&mut self) -> Result<T, Error>
where
RuntimeValue: TryInto<T, Error>,
{
let value = self.pop()?;
TryInto::try_into(value)
}
fn pop_pair_as<T>(&mut self) -> Result<(T, T), Error>
where
RuntimeValue: TryInto<T, Error>,
{
let right = self.pop_as()?;
let left = self.pop_as()?;
Ok((left, right))
}
fn pop_triple(&mut self) -> Result<(RuntimeValue, RuntimeValue, RuntimeValue), Error> {
let right = self.pop()?;
let mid = self.pop()?;
let left = self.pop()?;
Ok((left, mid, right))
}
}

View File

@ -1,29 +0,0 @@
use interpreter::{Error as InterpreterError};
use interpreter::value::{RuntimeValue, TryInto};
use common::stack::StackWithLimit;
impl StackWithLimit<RuntimeValue> {
pub fn pop_as<T>(&mut self) -> Result<T, InterpreterError>
where
RuntimeValue: TryInto<T, InterpreterError>,
{
let value = self.pop()?;
TryInto::try_into(value)
}
pub fn pop_pair_as<T>(&mut self) -> Result<(T, T), InterpreterError>
where
RuntimeValue: TryInto<T, InterpreterError>,
{
let right = self.pop_as()?;
let left = self.pop_as()?;
Ok((left, right))
}
pub fn pop_triple(&mut self) -> Result<(RuntimeValue, RuntimeValue, RuntimeValue), InterpreterError> {
let right = self.pop()?;
let mid = self.pop()?;
let left = self.pop()?;
Ok((left, mid, right))
}
}