Put source into AST.
This commit is contained in:
parent
d3894e8aef
commit
33f7c8557c
@ -89,11 +89,13 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut module = match engine
|
let module = match engine
|
||||||
.compile(&contents)
|
.compile(&contents)
|
||||||
.map_err(|err| err.into())
|
.map_err(|err| err.into())
|
||||||
.and_then(|ast| Module::eval_ast_as_new(Default::default(), &ast, &engine))
|
.and_then(|mut ast| {
|
||||||
{
|
ast.set_source(Some(&filename));
|
||||||
|
Module::eval_ast_as_new(Default::default(), &ast, &engine)
|
||||||
|
}) {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("{:=<1$}", "", filename.len());
|
eprintln!("{:=<1$}", "", filename.len());
|
||||||
eprintln!("{}", filename);
|
eprintln!("{}", filename);
|
||||||
@ -106,8 +108,6 @@ fn main() {
|
|||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
};
|
};
|
||||||
|
|
||||||
module.set_id(Some(&filename));
|
|
||||||
|
|
||||||
engine.register_global_module(module.into());
|
engine.register_global_module(module.into());
|
||||||
|
|
||||||
has_init_scripts = true;
|
has_init_scripts = true;
|
||||||
|
@ -188,27 +188,22 @@ impl ModuleResolver for FileModuleResolver {
|
|||||||
file_path.push(path);
|
file_path.push(path);
|
||||||
file_path.set_extension(&self.extension); // Force extension
|
file_path.set_extension(&self.extension); // Force extension
|
||||||
|
|
||||||
let scope = Default::default();
|
|
||||||
|
|
||||||
// See if it is cached
|
// See if it is cached
|
||||||
let mut module: Option<Shared<Module>> = None;
|
{
|
||||||
|
|
||||||
let mut module_ref = {
|
|
||||||
#[cfg(not(feature = "sync"))]
|
#[cfg(not(feature = "sync"))]
|
||||||
let c = self.cache.borrow();
|
let c = self.cache.borrow();
|
||||||
#[cfg(feature = "sync")]
|
#[cfg(feature = "sync")]
|
||||||
let c = self.cache.read().unwrap();
|
let c = self.cache.read().unwrap();
|
||||||
|
|
||||||
if let Some(module) = c.get(&file_path) {
|
if let Some(module) = c.get(&file_path) {
|
||||||
Some(module.clone())
|
return Ok(module.clone());
|
||||||
} else {
|
}
|
||||||
None
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
if module_ref.is_none() {
|
|
||||||
// Load the script file and compile it
|
// Load the script file and compile it
|
||||||
let ast = engine
|
let scope = Default::default();
|
||||||
|
|
||||||
|
let mut ast = engine
|
||||||
.compile_file(file_path.clone())
|
.compile_file(file_path.clone())
|
||||||
.map_err(|err| match *err {
|
.map_err(|err| match *err {
|
||||||
EvalAltResult::ErrorSystem(_, err) if err.is::<IoError>() => {
|
EvalAltResult::ErrorSystem(_, err) if err.is::<IoError>() => {
|
||||||
@ -217,23 +212,19 @@ impl ModuleResolver for FileModuleResolver {
|
|||||||
_ => Box::new(EvalAltResult::ErrorInModule(path.to_string(), err, pos)),
|
_ => Box::new(EvalAltResult::ErrorInModule(path.to_string(), err, pos)),
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let mut m = Module::eval_ast_as_new(scope, &ast, engine).map_err(|err| {
|
ast.set_source(Some(path));
|
||||||
Box::new(EvalAltResult::ErrorInModule(path.to_string(), err, pos))
|
|
||||||
})?;
|
|
||||||
|
|
||||||
m.set_id(Some(path));
|
// Make a module from the AST
|
||||||
module = Some(m.into());
|
let m: Shared<Module> = Module::eval_ast_as_new(scope, &ast, engine)
|
||||||
module_ref = module.clone();
|
.map_err(|err| Box::new(EvalAltResult::ErrorInModule(path.to_string(), err, pos)))?
|
||||||
};
|
.into();
|
||||||
|
|
||||||
if let Some(module) = module {
|
|
||||||
// Put it into the cache
|
// Put it into the cache
|
||||||
#[cfg(not(feature = "sync"))]
|
#[cfg(not(feature = "sync"))]
|
||||||
self.cache.borrow_mut().insert(file_path, module);
|
self.cache.borrow_mut().insert(file_path, m.clone());
|
||||||
#[cfg(feature = "sync")]
|
#[cfg(feature = "sync")]
|
||||||
self.cache.write().unwrap().insert(file_path, module);
|
self.cache.write().unwrap().insert(file_path, module);
|
||||||
}
|
|
||||||
|
|
||||||
Ok(module_ref.unwrap())
|
Ok(m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user