about summary refs log tree commit diff
path: root/tvix/eval/src
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/eval/src')
-rw-r--r--tvix/eval/src/eval.rs23
-rw-r--r--tvix/eval/src/main.rs2
2 files changed, 22 insertions, 3 deletions
diff --git a/tvix/eval/src/eval.rs b/tvix/eval/src/eval.rs
index 89a375b69a32..0c4900e7e59d 100644
--- a/tvix/eval/src/eval.rs
+++ b/tvix/eval/src/eval.rs
@@ -1,5 +1,24 @@
+use rnix::{self, types::TypedNode};
+use std::fmt::Write;
+
 use crate::errors::{Error, EvalResult};
 
-pub fn interpret(code: String) -> EvalResult<()> {
-    Ok(())
+pub fn interpret(code: String) -> EvalResult<String> {
+    let ast = rnix::parse(&code);
+
+    let errors = ast.errors();
+    if !errors.is_empty() {
+        todo!()
+    }
+
+    let mut out = String::new();
+    writeln!(out, "{}", ast.root().dump()).ok();
+
+    let code = crate::compiler::compile(ast)?;
+    writeln!(out, "code: {:?}", code).ok();
+
+    let value = crate::vm::run_chunk(code)?;
+    writeln!(out, "value: {:?}", value).ok();
+
+    Ok(out)
 }
diff --git a/tvix/eval/src/main.rs b/tvix/eval/src/main.rs
index 55365efabd1b..4cfa0a137a1b 100644
--- a/tvix/eval/src/main.rs
+++ b/tvix/eval/src/main.rs
@@ -48,7 +48,7 @@ fn run_prompt() {
 
 fn run(code: String) {
     match eval::interpret(code) {
-        Ok(result) => println!("=> {:?}", result),
+        Ok(result) => println!("=> {}", result),
         Err(err) => eprintln!("{}", err),
     }
 }