diff --git a/core/translate/expr.rs b/core/translate/expr.rs index 87e3029d1..349a5f2b3 100644 --- a/core/translate/expr.rs +++ b/core/translate/expr.rs @@ -23,13 +23,13 @@ fn emit_cond_jump(program: &mut ProgramBuilder, cond_meta: ConditionMetadata, re program.emit_insn(Insn::If { reg, target_pc: cond_meta.jump_target_when_true, - jump_if_null: reg, + jump_if_null: false, }); } else { program.emit_insn(Insn::IfNot { reg, target_pc: cond_meta.jump_target_when_false, - jump_if_null: reg, + jump_if_null: true, }); } } @@ -334,7 +334,7 @@ pub fn translate_condition_expr( lhs: lhs_reg, rhs: rhs_reg, target_pc: condition_metadata.jump_target_when_false, - jump_if_null: false, + jump_if_null: true, }); } } @@ -355,7 +355,7 @@ pub fn translate_condition_expr( lhs: lhs_reg, rhs: rhs_reg, target_pc: condition_metadata.jump_target_when_false, - jump_if_null: false, + jump_if_null: true, }); } // If we got here, then none of the conditions were a match, so we jump to the 'jump_target_when_true' label if 'jump_if_condition_is_true'. @@ -419,13 +419,13 @@ pub fn translate_condition_expr( program.emit_insn(Insn::IfNot { reg: cur_reg, target_pc: condition_metadata.jump_target_when_true, - jump_if_null: cur_reg, + jump_if_null: false, }); } else { program.emit_insn(Insn::If { reg: cur_reg, target_pc: condition_metadata.jump_target_when_false, - jump_if_null: cur_reg, + jump_if_null: true, }); } } @@ -725,7 +725,7 @@ pub fn translate_expr( None => program.emit_insn(Insn::IfNot { reg: expr_reg, target_pc: next_case_label, - jump_if_null: 1, + jump_if_null: true, }), }; // THEN... @@ -1079,7 +1079,7 @@ pub fn translate_expr( program.emit_insn(Insn::IfNot { reg: temp_reg, target_pc: jump_target_when_false, - jump_if_null: 1, + jump_if_null: true, }); translate_expr( program, diff --git a/core/translate/group_by.rs b/core/translate/group_by.rs index 6420b54d1..dfb92f20a 100644 --- a/core/translate/group_by.rs +++ b/core/translate/group_by.rs @@ -288,7 +288,7 @@ pub fn emit_group_by<'a>( program.emit_insn(Insn::If { target_pc: label_acc_indicator_set_flag_true, reg: reg_data_in_acc_flag, - jump_if_null: 0, // unused in this case + jump_if_null: false, }); // Read the group by columns for a finished group diff --git a/core/vdbe/insn.rs b/core/vdbe/insn.rs index 07c54fd0e..399aea8a8 100644 --- a/core/vdbe/insn.rs +++ b/core/vdbe/insn.rs @@ -159,14 +159,14 @@ pub enum Insn { reg: usize, // P1 target_pc: BranchOffset, // P2 /// P3. If r\[reg\] is null, jump iff r\[jump_if_null\] != 0 - jump_if_null: usize, + jump_if_null: bool, }, /// Jump to target_pc if r\[reg\] != 0 or (r\[reg\] == NULL && r\[jump_if_null\] != 0) IfNot { reg: usize, // P1 target_pc: BranchOffset, // P2 /// P3. If r\[reg\] is null, jump iff r\[jump_if_null\] != 0 - jump_if_null: usize, + jump_if_null: bool, }, // Open a cursor for reading. OpenReadAsync { diff --git a/core/vdbe/mod.rs b/core/vdbe/mod.rs index e7960b20a..b8c5f9474 100644 --- a/core/vdbe/mod.rs +++ b/core/vdbe/mod.rs @@ -676,11 +676,7 @@ impl Program { jump_if_null, } => { assert!(target_pc.is_offset()); - if exec_if( - &state.registers[*reg], - &state.registers[*jump_if_null], - false, - ) { + if exec_if(&state.registers[*reg], *jump_if_null, false) { state.pc = target_pc.to_offset_int(); } else { state.pc += 1; @@ -692,11 +688,7 @@ impl Program { jump_if_null, } => { assert!(target_pc.is_offset()); - if exec_if( - &state.registers[*reg], - &state.registers[*jump_if_null], - true, - ) { + if exec_if(&state.registers[*reg], *jump_if_null, true) { state.pc = target_pc.to_offset_int(); } else { state.pc += 1; @@ -3049,15 +3041,11 @@ fn exec_zeroblob(req: &OwnedValue) -> OwnedValue { } // exec_if returns whether you should jump -fn exec_if(reg: &OwnedValue, jump_if_null: &OwnedValue, not: bool) -> bool { +fn exec_if(reg: &OwnedValue, jump_if_null: bool, not: bool) -> bool { match reg { OwnedValue::Integer(0) | OwnedValue::Float(0.0) => not, OwnedValue::Integer(_) | OwnedValue::Float(_) => !not, - OwnedValue::Null => match jump_if_null { - OwnedValue::Integer(0) | OwnedValue::Float(0.0) => false, - OwnedValue::Integer(_) | OwnedValue::Float(_) => true, - _ => false, - }, + OwnedValue::Null => jump_if_null, _ => false, } } @@ -3879,29 +3867,24 @@ mod tests { #[test] fn test_exec_if() { let reg = OwnedValue::Integer(0); - let jump_if_null = OwnedValue::Integer(0); - assert!(!exec_if(®, &jump_if_null, false)); - assert!(exec_if(®, &jump_if_null, true)); + assert!(!exec_if(®, false, false)); + assert!(exec_if(®, false, true)); let reg = OwnedValue::Integer(1); - let jump_if_null = OwnedValue::Integer(0); - assert!(exec_if(®, &jump_if_null, false)); - assert!(!exec_if(®, &jump_if_null, true)); + assert!(exec_if(®, false, false)); + assert!(!exec_if(®, false, true)); let reg = OwnedValue::Null; - let jump_if_null = OwnedValue::Integer(0); - assert!(!exec_if(®, &jump_if_null, false)); - assert!(!exec_if(®, &jump_if_null, true)); + assert!(!exec_if(®, false, false)); + assert!(!exec_if(®, false, true)); let reg = OwnedValue::Null; - let jump_if_null = OwnedValue::Integer(1); - assert!(exec_if(®, &jump_if_null, false)); - assert!(exec_if(®, &jump_if_null, true)); + assert!(exec_if(®, true, false)); + assert!(exec_if(®, true, true)); let reg = OwnedValue::Null; - let jump_if_null = OwnedValue::Null; - assert!(!exec_if(®, &jump_if_null, false)); - assert!(!exec_if(®, &jump_if_null, true)); + assert!(!exec_if(®, false, false)); + assert!(!exec_if(®, false, true)); } #[test]