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:
parent
d59968649e
commit
e8253c7044
2 changed files with 22 additions and 3 deletions
|
@ -1,5 +1,24 @@
|
||||||
|
use rnix::{self, types::TypedNode};
|
||||||
|
use std::fmt::Write;
|
||||||
|
|
||||||
use crate::errors::{Error, EvalResult};
|
use crate::errors::{Error, EvalResult};
|
||||||
|
|
||||||
pub fn interpret(code: String) -> EvalResult<()> {
|
pub fn interpret(code: String) -> EvalResult<String> {
|
||||||
Ok(())
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ fn run_prompt() {
|
||||||
|
|
||||||
fn run(code: String) {
|
fn run(code: String) {
|
||||||
match eval::interpret(code) {
|
match eval::interpret(code) {
|
||||||
Ok(result) => println!("=> {:?}", result),
|
Ok(result) => println!("=> {}", result),
|
||||||
Err(err) => eprintln!("{}", err),
|
Err(err) => eprintln!("{}", err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue