about summary refs log blame commit diff
path: root/tvix/eval/src/eval.rs
blob: 0c4900e7e59dc1b0dea418acf91a07f4aa6b4c15 (plain) (tree)
1
2
3
4
5


                                   

                                       

















                                                      
 
use rnix::{self, types::TypedNode};
use std::fmt::Write;

use crate::errors::{Error, EvalResult};

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