about summary refs log tree commit diff
path: root/tvix/eval/src/lib.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-12-12T14·38+0300
committertazjin <tazjin@tvl.su>2022-12-21T22·37+0000
commitc3c4d752c91f64eff8e7f7f7b21fbcc1209d27a6 (patch)
tree290dba7b8cf36dfbca53a499891dcddaf3cbe735 /tvix/eval/src/lib.rs
parent25fc6b7c25d75075461e7976b27b81ba6a8140fe (diff)
feat(tvix/eval): add EvalIO to public crate API r/5459
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
Diffstat (limited to 'tvix/eval/src/lib.rs')
-rw-r--r--tvix/eval/src/lib.rs15
1 files changed, 14 insertions, 1 deletions
diff --git a/tvix/eval/src/lib.rs b/tvix/eval/src/lib.rs
index c9a6ac103eba..8cf9fe6e1bba 100644
--- a/tvix/eval/src/lib.rs
+++ b/tvix/eval/src/lib.rs
@@ -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) => {