From d9d94eb27f283fdfdbcc4af5eb5069201765d623 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Thu, 11 Aug 2022 13:12:07 +0300 Subject: feat(tvix/eval): implement if/else expressions These expressions use simple jumps to skip the correct expression conditionally in the bytecode by advancing the instruction pointer. Note that these expressions are already covered by a test behind the `nix_tests` feature flag, but adding more is probably sensible. Change-Id: Ibe0eba95d216321c883d3b6b5816e2ab6fe7eef1 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6148 Tested-by: BuildkiteCI Reviewed-by: grfn Reviewed-by: sterni --- tvix/eval/src/opcode.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'tvix/eval/src/opcode.rs') diff --git a/tvix/eval/src/opcode.rs b/tvix/eval/src/opcode.rs index b1e6d32593..8bb8fe9a1f 100644 --- a/tvix/eval/src/opcode.rs +++ b/tvix/eval/src/opcode.rs @@ -12,6 +12,9 @@ pub enum OpCode { // Push a constant onto the stack. OpConstant(ConstantIdx), + // Discard a value from the stack. + OpPop, + // Push a literal value. OpNull, OpTrue, @@ -27,13 +30,17 @@ pub enum OpCode { OpMul, OpDiv, - // Logical binary operators + // Comparison operators OpEqual, OpLess, OpLessOrEq, OpMore, OpMoreOrEq, + // Logical operators & generic jumps + OpJump(usize), + OpJumpIfFalse(usize), + // Attribute sets OpAttrs(usize), OpAttrPath(usize), -- cgit 1.4.1