chore(tvix/eval): clean up remains of previous disassembler impl
Change-Id: Ib402ea23a58dc52ed0c5a97178cb5d0e53d69300 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6454 Reviewed-by: sterni <sternenseemann@systemli.org> Tested-by: BuildkiteCI
This commit is contained in:
parent
e03a729fa3
commit
e2a942e4b2
3 changed files with 3 additions and 45 deletions
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -3,7 +3,7 @@ use std::{path::PathBuf, rc::Rc};
|
||||||
use crate::{
|
use crate::{
|
||||||
builtins::global_builtins,
|
builtins::global_builtins,
|
||||||
errors::{Error, ErrorKind, EvalResult},
|
errors::{Error, ErrorKind, EvalResult},
|
||||||
observer::{DisassemblingObserver, NoOpObserver},
|
observer::{DisassemblingObserver, TracingObserver},
|
||||||
value::Value,
|
value::Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ pub fn interpret(code: &str, location: Option<PathBuf>) -> EvalResult<Value> {
|
||||||
println!("{:?}", root_expr);
|
println!("{:?}", root_expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut observer = DisassemblingObserver::new(codemap.clone(), std::io::stderr());
|
let mut observer = DisassemblingObserver::new(codemap, std::io::stderr());
|
||||||
|
|
||||||
let result =
|
let result =
|
||||||
crate::compiler::compile(root_expr, location, &file, global_builtins(), &mut observer)?;
|
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());
|
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)
|
crate::vm::run_lambda(&mut tracer, result.lambda)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
mod builtins;
|
mod builtins;
|
||||||
mod chunk;
|
mod chunk;
|
||||||
mod compiler;
|
mod compiler;
|
||||||
mod disassembler;
|
|
||||||
mod errors;
|
mod errors;
|
||||||
mod eval;
|
mod eval;
|
||||||
pub mod observer;
|
pub mod observer;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue