feat(tvix/eval): introduce mechanism for defining builtins

Adds a new builtins module in which builtins can be constructed. The
functions in this module should return a correctly structured value to
be passed to the compiler's `globals`.

This is wired up all the way to the compiler with an example
`toString` builtin, available as a global. Note that this does not yet
actually behave like the real toString, which has some differences
from `Display`.

Change-Id: Ibb5f6fbe6207782fdf2434435567fc1bd80039a5
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6254
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
Vincent Ambo 2022-08-24 16:03:17 +03:00 committed by tazjin
parent ca90c0f45a
commit e1147b57c7
5 changed files with 48 additions and 6 deletions

View file

@ -3,6 +3,7 @@ use std::path::PathBuf;
use rnix;
use crate::{
builtins::global_builtins,
errors::{ErrorKind, EvalResult},
value::Value,
};
@ -28,7 +29,7 @@ pub fn interpret(code: &str, location: Option<PathBuf>) -> EvalResult<Value> {
println!("{:?}", root_expr);
}
let result = crate::compiler::compile(root_expr, location)?;
let result = crate::compiler::compile(root_expr, location, global_builtins())?;
#[cfg(feature = "disassembler")]
crate::disassembler::disassemble_chunk(&result.lambda.chunk);