Skip to content

Commit

Permalink
Fix jump_if_true to be a bool literal in places where it was used as …
Browse files Browse the repository at this point in the history
…a register number
  • Loading branch information
jussisaurio committed Jan 20, 2025
1 parent f88a4d6 commit 1813f71
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 25 deletions.
12 changes: 6 additions & 6 deletions core/translate/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
}
Expand Down Expand Up @@ -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,
});
}
}
Expand Down Expand Up @@ -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...
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion core/translate/group_by.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions core/vdbe/insn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 4 additions & 16 deletions core/vdbe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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,
}
}
Expand Down

0 comments on commit 1813f71

Please sign in to comment.