diff --git a/tvix/eval/src/eval.rs b/tvix/eval/src/eval.rs index 89a375b69..0c4900e7e 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 { + 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 55365efab..4cfa0a137 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), } }