feat(tvix/eval): implement DisassemblingObserver for compiler
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
This commit is contained in:
parent
7ae45342df
commit
8ee4d6d5db
7 changed files with 111 additions and 98 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue