diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs index 0b3fb27..ca3d3ea 100644 --- a/src/interpreter/mod.rs +++ b/src/interpreter/mod.rs @@ -139,7 +139,6 @@ mod memory; mod module; mod program; mod runner; -mod stack; mod table; mod value; mod host; diff --git a/src/interpreter/runner.rs b/src/interpreter/runner.rs index 07b4520..fca808b 100644 --- a/src/interpreter/runner.rs +++ b/src/interpreter/runner.rs @@ -1164,3 +1164,29 @@ pub fn prepare_function_args(function_type: &FunctionType, caller_stack: &mut St args.reverse(); Ok(args) } + +impl StackWithLimit { + fn pop_as(&mut self) -> Result + where + RuntimeValue: TryInto, + { + let value = self.pop()?; + TryInto::try_into(value) + } + + fn pop_pair_as(&mut self) -> Result<(T, T), Error> + where + RuntimeValue: TryInto, + { + 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)) + } +} diff --git a/src/interpreter/stack.rs b/src/interpreter/stack.rs deleted file mode 100644 index e0b8a3a..0000000 --- a/src/interpreter/stack.rs +++ /dev/null @@ -1,29 +0,0 @@ -use interpreter::{Error as InterpreterError}; -use interpreter::value::{RuntimeValue, TryInto}; -use common::stack::StackWithLimit; - -impl StackWithLimit { - pub fn pop_as(&mut self) -> Result - where - RuntimeValue: TryInto, - { - let value = self.pop()?; - TryInto::try_into(value) - } - - pub fn pop_pair_as(&mut self) -> Result<(T, T), InterpreterError> - where - RuntimeValue: TryInto, - { - 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)) - } -}