diff options
author | Vincent Ambo <mail@tazj.in> | 2022-10-04T14·05+0300 |
---|---|---|
committer | tazjin <tazjin@tvl.su> | 2022-10-05T10·29+0000 |
commit | 3530404a4a1cc363d87e559ac24780aa318adb19 (patch) | |
tree | 71458cd9fdc83efd71c3c0187e2381a5434fc7f7 /corp/tvixbolt/src | |
parent | 2ff764ceb700a1ef18fb532fbbc1ff937ed63f8a (diff) |
refactor(tvix/eval): introduce source::SourceCode type r/5035
This type hides away the lower-level handling of most codemap data structures, especially to library consumers (see corresponding changes in tvixbolt). This will help with implement `import` by giving us central control over how the codemap works. Change-Id: Ifcea36776879725871b30c518aeb96ab5fda035a Reviewed-on: https://cl.tvl.fyi/c/depot/+/6855 Tested-by: BuildkiteCI Reviewed-by: wpcarro <wpcarro@gmail.com>
Diffstat (limited to 'corp/tvixbolt/src')
-rw-r--r-- | corp/tvixbolt/src/main.rs | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/corp/tvixbolt/src/main.rs b/corp/tvixbolt/src/main.rs index c4b28f0fd490..a389a33f04ed 100644 --- a/corp/tvixbolt/src/main.rs +++ b/corp/tvixbolt/src/main.rs @@ -1,9 +1,9 @@ use std::fmt::Write; use serde::{Deserialize, Serialize}; -use std::rc::Rc; use tvix_eval::observer::TracingObserver; use tvix_eval::observer::{DisassemblingObserver, NoOpObserver}; +use tvix_eval::SourceCode; use web_sys::HtmlInputElement; use web_sys::HtmlTextAreaElement; use yew::prelude::*; @@ -230,9 +230,6 @@ fn eval(trace: bool, code: &str) -> Output { return out; } - let mut codemap = codemap::CodeMap::new(); - let file = codemap.add_file("nixbolt".to_string(), code.into()); - let parsed = rnix::ast::Root::parse(code); let errors = parsed.errors(); @@ -250,8 +247,10 @@ fn eval(trace: bool, code: &str) -> Output { .expr() .expect("expression should exist if no errors occured"); - let codemap = Rc::new(codemap); - let mut compilation_observer = DisassemblingObserver::new(codemap.clone(), &mut out.bytecode); + let source = SourceCode::new(); + let file = source.add_file("nixbolt".to_string(), code.into()); + + let mut compilation_observer = DisassemblingObserver::new(source.clone(), &mut out.bytecode); let result = tvix_eval::compile( &root_expr, @@ -266,7 +265,7 @@ fn eval(trace: bool, code: &str) -> Output { writeln!( &mut out.warnings, "{}\n", - warning.fancy_format_str(&codemap).trim(), + warning.fancy_format_str(&source).trim(), ) .unwrap(); } @@ -276,7 +275,7 @@ fn eval(trace: bool, code: &str) -> Output { writeln!( &mut out.compiler_errors, "{}\n", - error.fancy_format_str(&codemap).trim(), + error.fancy_format_str(&source).trim(), ) .unwrap(); } @@ -295,7 +294,7 @@ fn eval(trace: bool, code: &str) -> Output { Err(err) => writeln!( &mut out.runtime_errors, "{}", - err.fancy_format_str(&codemap).trim() + err.fancy_format_str(&source).trim() ) .unwrap(), }; |