about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-08-07T23·43+0300
committertazjin <tazjin@tvl.su>2022-08-12T13·24+0000
commit28f57abac1e4fc97b983af1b891d553db0a628d9 (patch)
treee43f9841afaaace070a8e0d603e226bda074fe62
parent18fe188c3e47a7662fa58a4066a9c3f7d9676cac (diff)
refactor(tvix/compiler): use rnix's typed AST for literal values r/4413
Change-Id: Ic56ab64ad82343c7cdf8168ef41ee0a97f7e1dd9
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6077
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
-rw-r--r--tvix/eval/src/compiler.rs12
1 files changed, 5 insertions, 7 deletions
diff --git a/tvix/eval/src/compiler.rs b/tvix/eval/src/compiler.rs
index 17fd016375..acbf018f81 100644
--- a/tvix/eval/src/compiler.rs
+++ b/tvix/eval/src/compiler.rs
@@ -22,8 +22,8 @@ impl Compiler {
             // Literals contain a single token comprising of the
             // literal itself.
             rnix::SyntaxKind::NODE_LITERAL => {
-                let token = node.first_token().expect("TODO");
-                self.compile_literal(token)
+                let value = rnix::types::Value::cast(node).unwrap();
+                self.compile_literal(value.to_value().expect("TODO"))
             }
 
             rnix::SyntaxKind::NODE_BIN_OP => {
@@ -37,8 +37,8 @@ impl Compiler {
             }
 
             rnix::SyntaxKind::NODE_PAREN => {
-                let op = rnix::types::Paren::cast(node).unwrap();
-                self.compile(op.inner().unwrap())
+                let node = rnix::types::Paren::cast(node).unwrap();
+                self.compile(node.inner().unwrap())
             }
 
             kind => {
@@ -48,9 +48,7 @@ impl Compiler {
         }
     }
 
-    fn compile_literal(&mut self, token: rnix::SyntaxToken) -> EvalResult<()> {
-        let value = rnix::value::Value::from_token(token.kind(), token.text()).expect("TODO");
-
+    fn compile_literal(&mut self, value: rnix::value::Value) -> EvalResult<()> {
         match value {
             rnix::NixValue::Float(f) => {
                 let idx = self.chunk.add_constant(Value::Float(f));