From 3530404a4a1cc363d87e559ac24780aa318adb19 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Tue, 4 Oct 2022 17:05:34 +0300 Subject: refactor(tvix/eval): introduce source::SourceCode type 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 --- tvix/eval/src/eval.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'tvix/eval/src/eval.rs') 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, options: Options) -> EvalResult { - 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, 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, 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, options: Options) -> Eva }; if let Err(err) = &result { - err.fancy_format_stderr(&codemap); + err.fancy_format_stderr(&source); } result -- cgit 1.4.1