about summary refs log tree commit diff
path: root/tvix/eval/src/eval.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-09-01T13·38+0300
committertazjin <tazjin@tvl.su>2022-09-07T19·10+0000
commitc5a8b93eaff144d34361193a125a2da2a4a93ef7 (patch)
tree7c618d169ac8cd6b308a9cffffd2a18b2803e531 /tvix/eval/src/eval.rs
parentb9566da5c94c974eb3a25f66c6c86b90ccd02ca1 (diff)
chore(tvix/eval): thread a codemap::File reference to the compiler r/4711
This instantiates a codemap outside of the compiler and passes a
reference to the file currently under compilation to it. Note that the
"file" might just be a REPL line.

Change-Id: I131ae1ddb6d718e1374750da9ba0b99608c6058d
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6378
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'tvix/eval/src/eval.rs')
-rw-r--r--tvix/eval/src/eval.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/tvix/eval/src/eval.rs b/tvix/eval/src/eval.rs
index d61e51e6afc2..98e7520e8b2e 100644
--- a/tvix/eval/src/eval.rs
+++ b/tvix/eval/src/eval.rs
@@ -7,6 +7,15 @@ use crate::{
 };
 
 pub fn interpret(code: &str, location: Option<PathBuf>) -> EvalResult<Value> {
+    let mut codemap = codemap::CodeMap::new();
+    let file = codemap.add_file(
+        location
+            .as_ref()
+            .map(|p| p.to_string_lossy().to_string())
+            .unwrap_or_else(|| "<repl>".into()),
+        code.into(),
+    );
+
     let parsed = rnix::ast::Root::parse(code);
     let errors = parsed.errors();
 
@@ -27,7 +36,7 @@ pub fn interpret(code: &str, location: Option<PathBuf>) -> EvalResult<Value> {
         println!("{:?}", root_expr);
     }
 
-    let result = crate::compiler::compile(root_expr, location, global_builtins())?;
+    let result = crate::compiler::compile(root_expr, location, &file, global_builtins())?;
 
     #[cfg(feature = "disassembler")]
     crate::disassembler::disassemble_chunk(&result.lambda.chunk);