tvl-depot/tvix/eval/src/opcode.rs
Vincent Ambo 671915837a fix(tvix/eval): add operation to assert boolean type
This operation is required because both sides of the logical operators
are strictly evaluated by Nix, even if the resulting value is not used
further.

For example, in our implementation of `&&`, if the left-hand side is
`true`, then the result of the expression is simply the right-hand
side value. This value must be asserted to be a boolean for the
semantics of the language to work correctly.

Change-Id: I34f5364f2a444753fa1d8b0a1a2b2d9cdf7c6700
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6157
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Reviewed-by: grfn <grfn@gws.fyi>
2022-08-26 09:02:38 +00:00

59 lines
1 KiB
Rust

//! This module implements the instruction set running on the abstract
//! machine implemented by tvix.
#[derive(Clone, Copy, Debug)]
pub struct ConstantIdx(pub usize);
#[derive(Clone, Copy, Debug)]
pub struct CodeIdx(pub usize);
#[derive(Clone, Copy, Debug)]
pub enum OpCode {
// Push a constant onto the stack.
OpConstant(ConstantIdx),
// Discard a value from the stack.
OpPop,
// Push a literal value.
OpNull,
OpTrue,
OpFalse,
// Unary operators
OpInvert,
OpNegate,
// Arithmetic binary operators
OpAdd,
OpSub,
OpMul,
OpDiv,
// Comparison operators
OpEqual,
OpLess,
OpLessOrEq,
OpMore,
OpMoreOrEq,
// Logical operators & generic jumps
OpJump(usize),
OpJumpIfTrue(usize),
OpJumpIfFalse(usize),
// Attribute sets
OpAttrs(usize),
OpAttrPath(usize),
OpAttrsUpdate,
// Lists
OpList(usize),
OpConcat,
// Strings
OpInterpolate(usize),
// Type assertion operators
OpAssertBool,
}