Pre-calculate index for module-qualified calls.

This commit is contained in:
Stephen Chung
2020-05-08 22:38:56 +08:00
parent eb52bfa28a
commit e50fcc385f
5 changed files with 63 additions and 42 deletions

View File

@@ -114,23 +114,25 @@ fn test_module_from_ast() -> Result<(), Box<EvalAltResult>> {
// Final variable values become constant module variable values
foo = calc(foo);
hello = "hello, " + foo + " worlds!";
export x as abc, foo, hello, extra as foobar;
"#,
)?;
let module = Module::eval_ast_as_new(&ast, &engine)?;
let module = Module::eval_ast_as_new(Scope::new(), &ast, &engine)?;
let mut scope = Scope::new();
scope.push_module("testing", module);
assert_eq!(
engine.eval_expression_with_scope::<INT>(&mut scope, "testing::x")?,
engine.eval_expression_with_scope::<INT>(&mut scope, "testing::abc")?,
123
);
assert_eq!(
engine.eval_expression_with_scope::<INT>(&mut scope, "testing::foo")?,
42
);
assert!(engine.eval_expression_with_scope::<bool>(&mut scope, "testing::extra::foo")?);
assert!(engine.eval_expression_with_scope::<bool>(&mut scope, "testing::foobar::foo")?);
assert_eq!(
engine.eval_expression_with_scope::<String>(&mut scope, "testing::hello")?,
"hello, 42 worlds!"