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.rs29
1 files changed, 28 insertions, 1 deletions
diff --git a/tvix/eval/src/compiler.rs b/tvix/eval/src/compiler.rs
index 297d23d3d8..4526bf16d6 100644
--- a/tvix/eval/src/compiler.rs
+++ b/tvix/eval/src/compiler.rs
@@ -6,7 +6,7 @@ use crate::errors::EvalResult;
 use crate::opcode::OpCode;
 use crate::value::Value;
 use rnix;
-use rnix::types::{TypedNode, Wrapper};
+use rnix::types::{TokenWrapper, TypedNode, Wrapper};
 
 struct Compiler {
     chunk: Chunk,
@@ -41,6 +41,11 @@ impl Compiler {
                 self.compile(node.inner().unwrap())
             }
 
+            rnix::SyntaxKind::NODE_IDENT => {
+                let node = rnix::types::Ident::cast(node).unwrap();
+                self.compile_ident(node)
+            }
+
             kind => {
                 println!("visiting unsupported node: {:?}", kind);
                 Ok(())
@@ -98,6 +103,28 @@ impl Compiler {
         self.chunk.add_op(opcode);
         Ok(())
     }
+
+    fn compile_ident(&mut self, node: rnix::types::Ident) -> EvalResult<()> {
+        match node.as_str() {
+            // TODO(tazjin): Nix technically allows code like
+            //
+            //   let null = 1; in null
+            //   => 1
+            //
+            // which we do *not* want to check at runtime. Once
+            // scoping is introduced, the compiler should carry some
+            // optimised information about any "weird" stuff that's
+            // happened to the scope (such as overrides of these
+            // literals, or builtins).
+            "true" => self.chunk.add_op(OpCode::OpTrue),
+            "false" => self.chunk.add_op(OpCode::OpFalse),
+            "null" => self.chunk.add_op(OpCode::OpNull),
+
+            _ => todo!("identifier access"),
+        };
+
+        Ok(())
+    }
 }
 
 pub fn compile(ast: rnix::AST) -> EvalResult<Chunk> {