about summary refs log tree commit diff
path: root/tvix/eval/src
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-08-07T20·42+0300
committertazjin <tazjin@tvl.su>2022-08-12T13·05+0000
commite8253c70444a580d3b087a53118960d58fbe5984 (patch)
tree7b2b6f22073daa5c0b296c76f3093bdf255a0fea /tvix/eval/src
parentd59968649e843371db7d83ac1e2b327c08e70093 (diff)
chore(tvix/eval): wire things up for development flow r/4408
This creates a REPL which outputs compiled bytecode, constants, and VM
results for code snippets.

Change-Id: If63f79a961456afd6a4cdf59b994107ff7ab8b47
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6072
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
Autosubmit: tazjin <tazjin@tvl.su>
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),
     }
 }