diff options
author | Vincent Ambo <mail@tazj.in> | 2022-09-04T14·57+0300 |
---|---|---|
committer | tazjin <tazjin@tvl.su> | 2022-09-04T17·15+0000 |
commit | 010a96e52502a70f1746f59b17e385fb2f5930dd (patch) | |
tree | 99c20599daf5f8d5d678d9f76641cc43d2aba8f7 /corp/tvixbolt/src/main.rs | |
parent | 8655440ae3f42543ad5d2a980cef389529867f4b (diff) |
refactor(corp/tvixbolt): adapt for tvix-eval's upcoming observer API r/4631
Instead of the previous hack which painfully threaded through a structure that the disassembler could write to, Tvix's evaluator is gaining a new "Observer" API which lets library clients observe compilation output (and, soon!, runtime tracing). This adapts tvixbolt to use this observer interface (with the default `DisassemblingObserver`) to populate the `bytecode` field of its output. This is purely a mechanical change, no functionality is impacted. Change-Id: I22bd2218629f30fd7351d4cc5ddcf639c12fea14 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6316 Tested-by: BuildkiteCI Reviewed-by: tazjin <tazjin@tvl.su>
Diffstat (limited to 'corp/tvixbolt/src/main.rs')
-rw-r--r-- | corp/tvixbolt/src/main.rs | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/corp/tvixbolt/src/main.rs b/corp/tvixbolt/src/main.rs index 9ed79aa0da82..122a84e0ac6a 100644 --- a/corp/tvixbolt/src/main.rs +++ b/corp/tvixbolt/src/main.rs @@ -1,4 +1,7 @@ -use std::{fmt::Write, rc::Rc}; +use std::fmt::Write; + +use std::rc::Rc; +use tvix_eval::observer::DisassemblingObserver; use web_sys::HtmlTextAreaElement; use yew::prelude::*; use yew::TargetCast; @@ -107,7 +110,7 @@ impl Output { fn eval(code: &str) -> Output { let mut out = Output::default(); - if code == "" { + if code.is_empty() { return out; } @@ -131,21 +134,18 @@ fn eval(code: &str) -> Output { .expr() .expect("expression should exist if no errors occured"); - let mut result = tvix_eval::compiler::compile( + let codemap = Rc::new(codemap); + let mut compilation_observer = DisassemblingObserver::new(codemap, &mut out.bytecode); + + let result = tvix_eval::compile( root_expr, Some("/nixbolt".into()), &file, - tvix_eval::builtins::global_builtins(), - Rc::new(codemap), + tvix_eval::global_builtins(), + &mut compilation_observer, ) .unwrap(); - let lambda = Rc::new(result.lambda); - - tvix_eval::disassembler::disassemble_lambda(&mut out.bytecode, lambda.clone()); - - out.bytecode.append(&mut result.output); - for warning in result.warnings { writeln!( &mut out.warnings, @@ -172,7 +172,7 @@ fn eval(code: &str) -> Output { return out; } - let result = tvix_eval::vm::run_lambda(lambda); + let result = tvix_eval::run_lambda(result.lambda); match result { Ok(value) => writeln!(&mut out.output, "{}", value).unwrap(), |