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 /tvix/eval/src/eval.rs | |
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 'tvix/eval/src/eval.rs')
-rw-r--r-- | tvix/eval/src/eval.rs | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/tvix/eval/src/eval.rs b/tvix/eval/src/eval.rs index bc430e58043f..7b7d3983d4ec 100644 --- a/tvix/eval/src/eval.rs +++ b/tvix/eval/src/eval.rs @@ -1,10 +1,11 @@ -use std::{path::PathBuf, rc::Rc}; +use std::path::PathBuf; use crate::{ builtins::global_builtins, errors::{Error, ErrorKind, EvalResult}, observer::{DisassemblingObserver, NoOpObserver, TracingObserver}, value::Value, + SourceCode, }; /// Runtime options for the Tvix interpreter @@ -25,15 +26,14 @@ pub struct Options { } pub fn interpret(code: &str, location: Option<PathBuf>, options: Options) -> EvalResult<Value> { - let mut codemap = codemap::CodeMap::new(); - let file = codemap.add_file( + let source = SourceCode::new(); + let file = source.add_file( location .as_ref() .map(|p| p.to_string_lossy().to_string()) .unwrap_or_else(|| "[tvix-repl]".into()), code.into(), ); - let codemap = Rc::new(codemap); let parsed = rnix::ast::Root::parse(code); let errors = parsed.errors(); @@ -64,7 +64,7 @@ pub fn interpret(code: &str, location: Option<PathBuf>, options: Options) -> Eva location, file.clone(), global_builtins(), - &mut DisassemblingObserver::new(codemap.clone(), std::io::stderr()), + &mut DisassemblingObserver::new(source.clone(), std::io::stderr()), ) } else { crate::compiler::compile( @@ -77,11 +77,11 @@ pub fn interpret(code: &str, location: Option<PathBuf>, options: Options) -> Eva }?; for warning in result.warnings { - warning.fancy_format_stderr(&codemap); + warning.fancy_format_stderr(&source); } for error in &result.errors { - error.fancy_format_stderr(&codemap); + error.fancy_format_stderr(&source); } if let Some(err) = result.errors.last() { @@ -95,7 +95,7 @@ pub fn interpret(code: &str, location: Option<PathBuf>, options: Options) -> Eva }; if let Err(err) = &result { - err.fancy_format_stderr(&codemap); + err.fancy_format_stderr(&source); } result |