feat(tvix/eval): conditionally use tracing/disassembling observers
Gates the observes behind the envvars `TVIX_DUMP_BYTECODE` and `TVIX_TRACE_RUNTIME`. (hi grfn, yes, we should probably introduce CLI flags soon) Change-Id: I4fa194a84b04593d609b96b44471c3644fb30296 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6459 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
parent
6bbe7589c5
commit
83dd706a3a
1 changed files with 23 additions and 7 deletions
|
@ -3,7 +3,7 @@ use std::{path::PathBuf, rc::Rc};
|
|||
use crate::{
|
||||
builtins::global_builtins,
|
||||
errors::{Error, ErrorKind, EvalResult},
|
||||
observer::{DisassemblingObserver, TracingObserver},
|
||||
observer::{DisassemblingObserver, NoOpObserver, TracingObserver},
|
||||
value::Value,
|
||||
};
|
||||
|
||||
|
@ -41,10 +41,23 @@ pub fn interpret(code: &str, location: Option<PathBuf>) -> EvalResult<Value> {
|
|||
println!("{:?}", root_expr);
|
||||
}
|
||||
|
||||
let mut observer = DisassemblingObserver::new(codemap, std::io::stderr());
|
||||
|
||||
let result =
|
||||
crate::compiler::compile(root_expr, location, &file, global_builtins(), &mut observer)?;
|
||||
let result = if std::env::var("TVIX_DUMP_BYTECODE").is_ok() {
|
||||
crate::compiler::compile(
|
||||
root_expr,
|
||||
location,
|
||||
&file,
|
||||
global_builtins(),
|
||||
&mut DisassemblingObserver::new(codemap, std::io::stderr()),
|
||||
)
|
||||
} else {
|
||||
crate::compiler::compile(
|
||||
root_expr,
|
||||
location,
|
||||
&file,
|
||||
global_builtins(),
|
||||
&mut NoOpObserver::default(),
|
||||
)
|
||||
}?;
|
||||
|
||||
for warning in result.warnings {
|
||||
eprintln!(
|
||||
|
@ -68,6 +81,9 @@ pub fn interpret(code: &str, location: Option<PathBuf>) -> EvalResult<Value> {
|
|||
return Err(err.clone());
|
||||
}
|
||||
|
||||
let mut tracer = TracingObserver::new(std::io::stderr());
|
||||
crate::vm::run_lambda(&mut tracer, result.lambda)
|
||||
if std::env::var("TVIX_TRACE_RUNTIME").is_ok() {
|
||||
crate::vm::run_lambda(&mut TracingObserver::new(std::io::stderr()), result.lambda)
|
||||
} else {
|
||||
crate::vm::run_lambda(&mut NoOpObserver::default(), result.lambda)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue