2022-08-07 22:40:29 +02:00
|
|
|
//! 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);
|
|
|
|
|
2022-08-12 16:19:14 +02:00
|
|
|
#[warn(variant_size_differences)]
|
2022-08-07 22:40:29 +02:00
|
|
|
#[derive(Clone, Copy, Debug)]
|
|
|
|
pub enum OpCode {
|
|
|
|
// Push a constant onto the stack.
|
|
|
|
OpConstant(ConstantIdx),
|
|
|
|
|
2022-08-11 12:12:07 +02:00
|
|
|
// Discard a value from the stack.
|
|
|
|
OpPop,
|
|
|
|
|
2022-08-07 22:40:29 +02:00
|
|
|
// Push a literal value.
|
|
|
|
OpNull,
|
|
|
|
OpTrue,
|
|
|
|
OpFalse,
|
2022-08-08 01:16:28 +02:00
|
|
|
|
2022-08-08 01:51:28 +02:00
|
|
|
// Unary operators
|
|
|
|
OpInvert,
|
|
|
|
OpNegate,
|
|
|
|
|
2022-08-08 01:32:07 +02:00
|
|
|
// Arithmetic binary operators
|
2022-08-08 01:16:28 +02:00
|
|
|
OpAdd,
|
|
|
|
OpSub,
|
|
|
|
OpMul,
|
|
|
|
OpDiv,
|
2022-08-08 01:32:07 +02:00
|
|
|
|
2022-08-11 12:12:07 +02:00
|
|
|
// Comparison operators
|
2022-08-08 01:51:28 +02:00
|
|
|
OpEqual,
|
2022-08-11 10:37:04 +02:00
|
|
|
OpLess,
|
|
|
|
OpLessOrEq,
|
|
|
|
OpMore,
|
|
|
|
OpMoreOrEq,
|
2022-08-09 15:53:09 +02:00
|
|
|
|
2022-08-11 12:12:07 +02:00
|
|
|
// Logical operators & generic jumps
|
|
|
|
OpJump(usize),
|
2022-08-11 13:38:38 +02:00
|
|
|
OpJumpIfTrue(usize),
|
2022-08-11 12:12:07 +02:00
|
|
|
OpJumpIfFalse(usize),
|
2022-08-11 21:01:45 +02:00
|
|
|
OpJumpIfNotFound(usize),
|
2022-08-11 12:12:07 +02:00
|
|
|
|
2022-08-09 15:53:09 +02:00
|
|
|
// Attribute sets
|
|
|
|
OpAttrs(usize),
|
2022-08-09 17:49:05 +02:00
|
|
|
OpAttrPath(usize),
|
2022-08-10 20:01:15 +02:00
|
|
|
OpAttrsUpdate,
|
2022-08-11 14:29:11 +02:00
|
|
|
OpAttrsSelect,
|
2022-08-11 21:01:45 +02:00
|
|
|
OpAttrOrNotFound,
|
2022-08-11 16:06:23 +02:00
|
|
|
OpAttrsIsSet,
|
2022-08-09 16:11:02 +02:00
|
|
|
|
2022-08-14 23:13:57 +02:00
|
|
|
// `with`-handling
|
|
|
|
OpPushWith(usize),
|
2022-08-14 23:38:30 +02:00
|
|
|
OpPopWith,
|
2022-08-15 00:13:17 +02:00
|
|
|
OpResolveWith,
|
2022-08-14 23:13:57 +02:00
|
|
|
|
2022-08-09 16:11:02 +02:00
|
|
|
// Lists
|
|
|
|
OpList(usize),
|
2022-08-11 10:50:38 +02:00
|
|
|
OpConcat,
|
2022-08-09 16:44:34 +02:00
|
|
|
|
|
|
|
// Strings
|
|
|
|
OpInterpolate(usize),
|
2022-08-11 13:56:27 +02:00
|
|
|
|
|
|
|
// Type assertion operators
|
|
|
|
OpAssertBool,
|
2022-08-13 16:34:20 +02:00
|
|
|
|
2022-08-13 19:17:25 +02:00
|
|
|
// Access local identifiers with statically known positions.
|
|
|
|
OpGetLocal(usize),
|
|
|
|
|
2022-08-13 16:34:20 +02:00
|
|
|
// Close scopes while leaving their expression value around.
|
|
|
|
OpCloseScope(usize), // number of locals to pop
|
2022-08-16 14:53:35 +02:00
|
|
|
|
|
|
|
// Asserts stack top is a boolean, and true.
|
|
|
|
OpAssert,
|
2022-08-24 01:26:58 +02:00
|
|
|
|
|
|
|
// Lambdas
|
|
|
|
OpCall,
|
2022-08-07 22:40:29 +02:00
|
|
|
}
|