about summary refs log tree commit diff
path: root/tvix/eval/src/compiler.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/eval/src/compiler.rs')
-rw-r--r--tvix/eval/src/compiler.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/tvix/eval/src/compiler.rs b/tvix/eval/src/compiler.rs
index 65b97cd56c..d71eda43aa 100644
--- a/tvix/eval/src/compiler.rs
+++ b/tvix/eval/src/compiler.rs
@@ -31,6 +31,11 @@ impl Compiler {
                 self.compile_binop(op)
             }
 
+            rnix::SyntaxKind::NODE_UNARY_OP => {
+                let op = rnix::types::UnaryOp::cast(node).expect("TODO: (should not be possible)");
+                self.compile_unary_op(op)
+            }
+
             kind => {
                 println!("visiting unsupported node: {:?}", kind);
                 Ok(())
@@ -77,6 +82,19 @@ impl Compiler {
         self.chunk.add_op(opcode);
         Ok(())
     }
+
+    fn compile_unary_op(&mut self, op: rnix::types::UnaryOp) -> EvalResult<()> {
+        self.compile(op.value().unwrap())?;
+
+        use rnix::types::UnaryOpKind;
+        let opcode = match op.operator() {
+            UnaryOpKind::Invert => OpCode::OpInvert,
+            UnaryOpKind::Negate => OpCode::OpNegate,
+        };
+
+        self.chunk.add_op(opcode);
+        Ok(())
+    }
 }
 
 pub fn compile(ast: rnix::AST) -> EvalResult<Chunk> {