mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-20 07:25:14 +01:00
Fix jump_if_true to be a bool literal in places where it was used as a register number
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user