about summary refs log tree commit diff
path: root/tvix/eval/src/eval.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-09-04T13·56+0300
committertazjin <tazjin@tvl.su>2022-09-09T21·10+0000
commit8ee4d6d5db44d93c0fff67db87dcb4ae9f885351 (patch)
tree070d533eb3f1c775011695dc25a96c55aad05a8c /tvix/eval/src/eval.rs
parent7ae45342df28c7f3feb50334aee535a1d36e2bec (diff)
feat(tvix/eval): implement DisassemblingObserver for compiler r/4775
This type implements an observer that is called whenever the compiler
emits a chunk (after the toplevel, thunks, or lambdas) and prints the
output of the disassembler to its internal writer.

This replaces half of the uses of the `disassembler` feature, which
has been removed from the Cargo configuration.

Note that at this commit runtime tracing is not yet implemented as an
observer.

Change-Id: I7894ca1ba445761aba4ad51d98e4a7b6445f1aea
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6449
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/eval.rs')
-rw-r--r--tvix/eval/src/eval.rs18
1 files changed, 6 insertions, 12 deletions
diff --git a/tvix/eval/src/eval.rs b/tvix/eval/src/eval.rs
index c2fe7f151377..f510cb6a5eaf 100644
--- a/tvix/eval/src/eval.rs
+++ b/tvix/eval/src/eval.rs
@@ -3,6 +3,7 @@ use std::{path::PathBuf, rc::Rc};
 use crate::{
     builtins::global_builtins,
     errors::{Error, ErrorKind, EvalResult},
+    observer::DisassemblingObserver,
     value::Value,
 };
 
@@ -15,6 +16,7 @@ pub fn interpret(code: &str, location: Option<PathBuf>) -> EvalResult<Value> {
             .unwrap_or_else(|| "<repl>".into()),
         code.into(),
     );
+    let codemap = Rc::new(codemap);
 
     let parsed = rnix::ast::Root::parse(code);
     let errors = parsed.errors();
@@ -39,18 +41,10 @@ pub fn interpret(code: &str, location: Option<PathBuf>) -> EvalResult<Value> {
         println!("{:?}", root_expr);
     }
 
-    let result = crate::compiler::compile(
-        root_expr,
-        location,
-        &file,
-        global_builtins(),
-        #[cfg(feature = "disassembler")]
-        Rc::new(codemap),
-    )?;
-    let lambda = Rc::new(result.lambda);
+    let mut observer = DisassemblingObserver::new(codemap.clone(), std::io::stderr());
 
-    #[cfg(feature = "disassembler")]
-    crate::disassembler::disassemble_lambda(lambda.clone());
+    let result =
+        crate::compiler::compile(root_expr, location, &file, global_builtins(), &mut observer)?;
 
     for warning in result.warnings {
         eprintln!(
@@ -74,5 +68,5 @@ pub fn interpret(code: &str, location: Option<PathBuf>) -> EvalResult<Value> {
         return Err(err.clone());
     }
 
-    crate::vm::run_lambda(lambda)
+    crate::vm::run_lambda(result.lambda)
 }