Skip to content

Commit

Permalink
Merge 'Implement IsNot operator' from Vrishabh
Browse files Browse the repository at this point in the history
This PR adds support for IsNot Operator which was not working as shown
below.
```
❯ ./target/debug/limbo
Limbo v0.0.12
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database
limbo> select 1 is not 0;
thread 'main' panicked at core\translate\expr.rs:626:40:
not yet implemented: IsNot
stack backtrace:
```

Closes #731
  • Loading branch information
penberg committed Jan 18, 2025
2 parents 315d225 + b966351 commit 4a41736
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
13 changes: 13 additions & 0 deletions core/translate/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,19 @@ pub fn translate_expr(
if_true_label,
);
}
ast::Operator::IsNot => {
let if_true_label = program.allocate_label();
wrap_eval_jump_expr(
program,
Insn::Ne {
lhs: e1_reg,
rhs: e2_reg,
target_pc: if_true_label,
},
target_register,
if_true_label,
);
}
#[cfg(feature = "json")]
op @ (ast::Operator::ArrowRight | ast::Operator::ArrowRightShift) => {
let json_func = match op {
Expand Down
21 changes: 21 additions & 0 deletions testing/compare.test
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,25 @@ foreach {testname lhs rhs ans} {
text-text-2 'a' 'a' 1
} {
do_execsql_test compare-is-$testname "SELECT $lhs is $rhs" $::ans
}

foreach {testname lhs rhs ans} {
int-int-1 8 1 1
int-int-2 8 8 0
} {
do_execsql_test compare-is-not-$testname "SELECT $lhs is not $rhs" $::ans
}

foreach {testname lhs rhs ans} {
float-float-1 8.0 1.0 1
float-float-2 8.0 8.0 0
} {
do_execsql_test compare-is-not-$testname "SELECT $lhs is not $rhs" $::ans
}

foreach {testname lhs rhs ans} {
text-text-1 'a' 'b' 1
text-text-2 'a' 'a' 0
} {
do_execsql_test compare-is-not-$testname "SELECT $lhs is not $rhs" $::ans
}

0 comments on commit 4a41736

Please sign in to comment.