diff options
Diffstat (limited to 'tvix/eval/src/compiler.rs')
-rw-r--r-- | tvix/eval/src/compiler.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tvix/eval/src/compiler.rs b/tvix/eval/src/compiler.rs index 193b4a0f33ed..27e917c54569 100644 --- a/tvix/eval/src/compiler.rs +++ b/tvix/eval/src/compiler.rs @@ -170,6 +170,11 @@ impl Compiler { self.compile_with(node) } + rnix::SyntaxKind::NODE_ASSERT => { + let node = rnix::types::Assert::cast(node).unwrap(); + self.compile_assert(node) + } + kind => panic!("visiting unsupported node: {:?}", kind), } } @@ -795,6 +800,17 @@ impl Compiler { self.compile(node.body().unwrap()) } + fn compile_assert(&mut self, node: rnix::types::Assert) -> EvalResult<()> { + // Compile the assertion condition to leave its value on the stack. + self.compile(node.condition().unwrap())?; + self.chunk.push_op(OpCode::OpAssert); + + // The runtime will abort evaluation at this point if the + // assertion failed, if not the body simply continues on like + // normal. + self.compile(node.body().unwrap()) + } + // Emit the literal string value of an identifier. Required for // several operations related to attribute sets, where identifiers // are used as string keys. |