aboutsummaryrefslogtreecommitdiffstats
path: root/src/vm.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/vm.rs')
-rw-r--r--src/vm.rs9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/vm.rs b/src/vm.rs
index ea15b5d..485d449 100644
--- a/src/vm.rs
+++ b/src/vm.rs
@@ -34,8 +34,7 @@ macro_rules! one_op {
macro_rules! two_op {
( $self:expr, $op:expr, $fun:expr ) => {
- let b = $self.pop();
- let a = $self.pop();
+ let (a, b) = $self.poppop();
let c = $fun(&a, &b);
if c.is_nil() {
$self.push(c);
@@ -115,6 +114,12 @@ impl VM {
self.stack.pop().unwrap()
}
+ fn poppop(&mut self) -> (Value, Value) {
+ let (a, b) = (self.stack.remove(self.stack.len() - 1),
+ self.stack.remove(self.stack.len() - 1));
+ (b, a) // this matches the order they were on the stack
+ }
+
fn push(&mut self, value: Value) {
self.stack.push(value)
}