chore(tvix/eval): wire things up for development flow

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>
This commit is contained in:
Vincent Ambo 2022-08-07 23:42:33 +03:00 committed by tazjin
parent d59968649e
commit e8253c7044
2 changed files with 22 additions and 3 deletions

View file

@ -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)
}

View file

@ -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),
}
}