mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-22 18:19:54 -04:00
REFACTOR: JumpIfNotEqual -> SelectJump
This commit is contained in:
parent
673cb8f8b7
commit
c1f84c4861
@ -102,7 +102,7 @@ pub enum Op {
|
||||
Jump(i32),
|
||||
JumpIfTrue(i32),
|
||||
JumpIfFalse(i32),
|
||||
JumpIfNotEqual(i32),
|
||||
SelectJump(i32),
|
||||
// FIXME(jwall): Short circuiting operations
|
||||
// - And(usize)
|
||||
// - Or(usize)
|
||||
@ -184,7 +184,7 @@ impl<'a> VM<'a> {
|
||||
Op::Jump(jp) => self.op_jump(*jp)?,
|
||||
Op::JumpIfTrue(jp) => self.op_jump_if_true(*jp)?,
|
||||
Op::JumpIfFalse(jp) => self.op_jump_if_false(*jp)?,
|
||||
Op::JumpIfNotEqual(jp) => self.op_jump_if_not_equal(*jp)?,
|
||||
Op::SelectJump(jp) => self.op_select_jump(*jp)?,
|
||||
Op::Module(mptr) => self.op_module(idx, *mptr)?,
|
||||
Op::Func(jptr) => self.op_func(idx, *jptr)?,
|
||||
Op::FCall => self.op_fcall()?,
|
||||
@ -230,7 +230,7 @@ impl<'a> VM<'a> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn op_jump_if_not_equal(&mut self, jp: i32) -> Result<(), Error> {
|
||||
fn op_select_jump(&mut self, jp: i32) -> Result<(), Error> {
|
||||
// pop field value off
|
||||
let field_name = dbg!(self.pop())?;
|
||||
// pop search value off
|
||||
|
@ -16,8 +16,7 @@ use super::scope::Stack;
|
||||
use super::Composite::{List, Tuple};
|
||||
use super::Op::{
|
||||
Add, Bang, Bind, Cp, DeRef, Div, Element, Equal, FCall, Field, Func, InitList, InitThunk,
|
||||
InitTuple, Jump, JumpIfFalse, JumpIfNotEqual, JumpIfTrue, Module, Mul, Noop, Return, Sub, Sym,
|
||||
Val,
|
||||
InitTuple, Jump, JumpIfFalse, JumpIfTrue, Module, Mul, Noop, Return, SelectJump, Sub, Sym, Val,
|
||||
};
|
||||
use super::Primitive::{Bool, Float, Int, Str};
|
||||
use super::Value::{C, P};
|
||||
@ -406,11 +405,11 @@ fn test_select_short_circuit() {
|
||||
vec![
|
||||
Sym("field".to_owned()), // 0 // search field
|
||||
Sym("not_field".to_owned()), // 1 // first field to compare
|
||||
JumpIfNotEqual(2), // 2
|
||||
SelectJump(2), // 2
|
||||
Val(Str("not our value".to_owned())), // 3 // expression for first field
|
||||
Jump(4), // 4
|
||||
Sym("field".to_owned()), // 5 // second field to compare
|
||||
JumpIfNotEqual(2), // 6
|
||||
SelectJump(2), // 6
|
||||
Val(Int(1)), // 7 // expression for second field
|
||||
Jump(1), // 8
|
||||
Bang, // 9 // default case
|
||||
|
Loading…
x
Reference in New Issue
Block a user