From 7d55b776de29cfaa70a2ab9ae61b6cabe70ed637 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Wed, 10 Aug 2022 21:09:59 +0300 Subject: feat(tvix): implement not-equals (!=) operator Change-Id: Ic259d6d0cf30553e944682a0d1d2c610df7fe5c2 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6141 Reviewed-by: sterni Tested-by: BuildkiteCI --- tvix/eval/src/compiler.rs | 21 +++++++++++++-------- .../src/tests/tvix_tests/eval-okay-eq-float.exp | 1 + .../src/tests/tvix_tests/eval-okay-eq-float.nix | 1 + tvix/eval/src/tests/tvix_tests/eval-okay-eq-int.exp | 1 + tvix/eval/src/tests/tvix_tests/eval-okay-eq-int.nix | 1 + tvix/eval/src/tests/tvix_tests/eval-okay-ne-int.exp | 1 + tvix/eval/src/tests/tvix_tests/eval-okay-ne-int.nix | 1 + .../src/tests/tvix_tests/eval-okay-ne-string.exp | 1 + .../src/tests/tvix_tests/eval-okay-ne-string.nix | 1 + 9 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-eq-float.exp create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-eq-float.nix create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-eq-int.exp create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-eq-int.nix create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-ne-int.exp create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-ne-int.nix create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-ne-string.exp create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-ne-string.nix (limited to 'tvix/eval') diff --git a/tvix/eval/src/compiler.rs b/tvix/eval/src/compiler.rs index 4aadfaba80e7..d48490dde7a6 100644 --- a/tvix/eval/src/compiler.rs +++ b/tvix/eval/src/compiler.rs @@ -130,17 +130,22 @@ impl Compiler { use rnix::types::BinOpKind; - let opcode = match op.operator().unwrap() { - BinOpKind::Add => OpCode::OpAdd, - BinOpKind::Sub => OpCode::OpSub, - BinOpKind::Mul => OpCode::OpMul, - BinOpKind::Div => OpCode::OpDiv, - BinOpKind::Equal => OpCode::OpEqual, - BinOpKind::Update => OpCode::OpAttrsUpdate, + match op.operator().unwrap() { + BinOpKind::Add => self.chunk.add_op(OpCode::OpAdd), + BinOpKind::Sub => self.chunk.add_op(OpCode::OpSub), + BinOpKind::Mul => self.chunk.add_op(OpCode::OpMul), + BinOpKind::Div => self.chunk.add_op(OpCode::OpDiv), + BinOpKind::Update => self.chunk.add_op(OpCode::OpAttrsUpdate), + BinOpKind::Equal => self.chunk.add_op(OpCode::OpEqual), + + BinOpKind::NotEqual => { + self.chunk.add_op(OpCode::OpEqual); + self.chunk.add_op(OpCode::OpInvert) + } + _ => todo!(), }; - self.chunk.add_op(opcode); Ok(()) } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-eq-float.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-eq-float.exp new file mode 100644 index 000000000000..27ba77ddaf61 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-eq-float.exp @@ -0,0 +1 @@ +true diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-eq-float.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-eq-float.nix new file mode 100644 index 000000000000..398f4a9dfc55 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-eq-float.nix @@ -0,0 +1 @@ +4.2 == 4.2 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-eq-int.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-eq-int.exp new file mode 100644 index 000000000000..27ba77ddaf61 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-eq-int.exp @@ -0,0 +1 @@ +true diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-eq-int.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-eq-int.nix new file mode 100644 index 000000000000..dc52ba112a60 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-eq-int.nix @@ -0,0 +1 @@ +42 == 42 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-ne-int.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-ne-int.exp new file mode 100644 index 000000000000..27ba77ddaf61 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-ne-int.exp @@ -0,0 +1 @@ +true diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-ne-int.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-ne-int.nix new file mode 100644 index 000000000000..e06b571a28bf --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-ne-int.nix @@ -0,0 +1 @@ +42 != 69 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-ne-string.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-ne-string.exp new file mode 100644 index 000000000000..27ba77ddaf61 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-ne-string.exp @@ -0,0 +1 @@ +true diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-ne-string.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-ne-string.nix new file mode 100644 index 000000000000..a83471e500ce --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-ne-string.nix @@ -0,0 +1 @@ +"this" != "that" -- cgit 1.4.1