chore(tvix/eval): thread a codemap::File reference to the compiler
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>
This commit is contained in:
parent
b9566da5c9
commit
c5a8b93eaf
2 changed files with 21 additions and 5 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue