feat(tvix/eval): add EvalIO to public crate API
This lets users set the `io_handle` field on an `Evaluation`, which is then propagated to the VM. Change-Id: I616d7140724fb2b4db47c2ebf95451d5303a487a Reviewed-on: https://cl.tvl.fyi/c/depot/+/7566 Reviewed-by: grfn <grfn@gws.fyi> Tested-by: BuildkiteCI
This commit is contained in:
parent
25fc6b7c25
commit
c3c4d752c9
6 changed files with 42 additions and 14 deletions
|
@ -45,6 +45,7 @@ use std::sync::Arc;
|
|||
pub use crate::builtins::global_builtins;
|
||||
pub use crate::compiler::{compile, prepare_globals};
|
||||
pub use crate::errors::{Error, ErrorKind, EvalResult};
|
||||
pub use crate::io::{DummyIO, EvalIO, StdIO};
|
||||
use crate::observer::{CompilerObserver, RuntimeObserver};
|
||||
pub use crate::pretty_ast::pretty_print_expr;
|
||||
pub use crate::source::SourceCode;
|
||||
|
@ -86,6 +87,12 @@ pub struct Evaluation<'code, 'co, 'ro> {
|
|||
/// Top-level file reference for this code inside the source map.
|
||||
file: Arc<codemap::File>,
|
||||
|
||||
/// Implementation of file-IO to use during evaluation, e.g. for
|
||||
/// impure builtins.
|
||||
///
|
||||
/// Defaults to [`DummyIO`] if not set explicitly.
|
||||
pub io_handle: Box<dyn EvalIO>,
|
||||
|
||||
/// (optional) Nix search path, e.g. the value of `NIX_PATH` used
|
||||
/// for resolving items on the search path (such as `<nixpkgs>`).
|
||||
pub nix_path: Option<String>,
|
||||
|
@ -137,6 +144,7 @@ impl<'code, 'co, 'ro> Evaluation<'code, 'co, 'ro> {
|
|||
location,
|
||||
source_map,
|
||||
file,
|
||||
io_handle: Box::new(DummyIO {}),
|
||||
nix_path: None,
|
||||
compiler_observer: None,
|
||||
runtime_observer: None,
|
||||
|
@ -216,7 +224,12 @@ impl<'code, 'co, 'ro> Evaluation<'code, 'co, 'ro> {
|
|||
.unwrap_or_else(|| Default::default());
|
||||
|
||||
let runtime_observer = self.runtime_observer.take().unwrap_or(&mut noop_observer);
|
||||
let vm_result = run_lambda(nix_path, runtime_observer, compiler_result.lambda);
|
||||
let vm_result = run_lambda(
|
||||
nix_path,
|
||||
self.io_handle,
|
||||
runtime_observer,
|
||||
compiler_result.lambda,
|
||||
);
|
||||
|
||||
match vm_result {
|
||||
Ok(mut runtime_result) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue