about summary refs log tree commit diff
path: root/tvix/eval/src/eval.rs
blob: 9d3f993ba2736ac1ec843c79064234f81cca2a1b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use rnix::{self, types::TypedNode};
use std::fmt::Write;

use crate::errors::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();
    println!("{}", ast.root().dump());

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