diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-01-09 20:58:40 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-01-09 20:58:40 +0100 |
| commit | 3971c2a09ab6fedc6bdcf5b7597fbf3d0bafeb0d (patch) | |
| tree | 3f0c682df20e72a1bc85880c8947d602d28891ab /src/vm.rs | |
| parent | 6c7c6ca45e185bfd4cd6a4d371495d1258875769 (diff) | |
| download | sylt-3971c2a09ab6fedc6bdcf5b7597fbf3d0bafeb0d.tar.gz | |
assert operator
Diffstat (limited to 'src/vm.rs')
| -rw-r--r-- | src/vm.rs | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -21,10 +21,12 @@ pub enum Op { Or, Not, - Equal, // == - Less, // < + Equal, // == + Less, // < Greater, // > + AssertEqual, + Print, Return, } @@ -83,6 +85,10 @@ impl VM { (b, a) } + fn _peek_up(&self, amount: usize) -> Option<&Value> { + self.stack.get(self.stack.len() - amount) + } + pub fn run(&mut self) { const PRINT_WHILE_RUNNING: bool = true; const PRINT_BLOCK: bool = true; @@ -192,6 +198,14 @@ impl VM { } } + Op::AssertEqual => { + let (a, b) = self.pop_twice(); + if a != b { + println!("Assert failed for '{:?}' and '{:?}'", a, b); + } + self.stack.push(Value::Bool(a == b)); + } + Op::Print => { println!("PRINT: {:?}", self.stack.pop()); } |
