about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-09-04T17·10+0300
committertazjin <tazjin@tvl.su>2022-09-09T21·14+0000
commite2a942e4b2ccdf2caa2970201f90edf5be926c2b (patch)
tree6d096fc2eaff558e6ba03cbbdff0d797942ca346
parente03a729fa36287e236b5ac66f17d67d63a219d00 (diff)
chore(tvix/eval): clean up remains of previous disassembler impl r/4780
Change-Id: Ib402ea23a58dc52ed0c5a97178cb5d0e53d69300
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6454
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
-rw-r--r--tvix/eval/src/disassembler.rs41
-rw-r--r--tvix/eval/src/eval.rs6
-rw-r--r--tvix/eval/src/lib.rs1
3 files changed, 3 insertions, 45 deletions
diff --git a/tvix/eval/src/disassembler.rs b/tvix/eval/src/disassembler.rs
deleted file mode 100644
index 51d39c3910a1..000000000000
--- a/tvix/eval/src/disassembler.rs
+++ /dev/null
@@ -1,41 +0,0 @@
-//! Implements methods for disassembling and printing a representation
-//! of compiled code, as well as tracing the runtime stack during
-//! execution.
-use std::io::{Stderr, Write};
-use tabwriter::TabWriter;
-
-use crate::opcode::OpCode;
-use crate::value::Value;
-
-/// Helper struct to trace runtime values and automatically flush the
-/// output after the value is dropped (i.e. in both success and
-/// failure exits from the VM).
-pub struct Tracer(TabWriter<Stderr>);
-
-impl Default for Tracer {
-    fn default() -> Self {
-        Tracer(TabWriter::new(std::io::stderr()))
-    }
-}
-
-impl Tracer {
-    pub fn trace(&mut self, op: &OpCode, ip: usize, stack: &[Value]) {
-        let _ = write!(&mut self.0, "{:04} {:?}\t[ ", ip, op);
-
-        for val in stack {
-            let _ = write!(&mut self.0, "{} ", val);
-        }
-
-        let _ = writeln!(&mut self.0, "]");
-    }
-
-    pub fn literal(&mut self, line: &str) {
-        let _ = writeln!(&mut self.0, "{}", line);
-    }
-}
-
-impl Drop for Tracer {
-    fn drop(&mut self) {
-        let _ = self.0.flush();
-    }
-}
diff --git a/tvix/eval/src/eval.rs b/tvix/eval/src/eval.rs
index 47c7203d28ac..8f32c819d546 100644
--- a/tvix/eval/src/eval.rs
+++ b/tvix/eval/src/eval.rs
@@ -3,7 +3,7 @@ use std::{path::PathBuf, rc::Rc};
 use crate::{
     builtins::global_builtins,
     errors::{Error, ErrorKind, EvalResult},
-    observer::{DisassemblingObserver, NoOpObserver},
+    observer::{DisassemblingObserver, TracingObserver},
     value::Value,
 };
 
@@ -41,7 +41,7 @@ pub fn interpret(code: &str, location: Option<PathBuf>) -> EvalResult<Value> {
         println!("{:?}", root_expr);
     }
 
-    let mut observer = DisassemblingObserver::new(codemap.clone(), std::io::stderr());
+    let mut observer = DisassemblingObserver::new(codemap, std::io::stderr());
 
     let result =
         crate::compiler::compile(root_expr, location, &file, global_builtins(), &mut observer)?;
@@ -68,6 +68,6 @@ pub fn interpret(code: &str, location: Option<PathBuf>) -> EvalResult<Value> {
         return Err(err.clone());
     }
 
-    let mut tracer = NoOpObserver::default();
+    let mut tracer = TracingObserver::new(std::io::stderr());
     crate::vm::run_lambda(&mut tracer, result.lambda)
 }
diff --git a/tvix/eval/src/lib.rs b/tvix/eval/src/lib.rs
index 447c74cc0e4c..b0baf3c249e9 100644
--- a/tvix/eval/src/lib.rs
+++ b/tvix/eval/src/lib.rs
@@ -1,7 +1,6 @@
 mod builtins;
 mod chunk;
 mod compiler;
-mod disassembler;
 mod errors;
 mod eval;
 pub mod observer;