Improve AST evaluation efficiency by sharing functions.
This commit is contained in:
@@ -22,8 +22,7 @@ fn test_fn() -> Result<(), EvalAltResult> {
|
||||
fn test_call_fn() -> Result<(), EvalAltResult> {
|
||||
let mut engine = Engine::new();
|
||||
|
||||
engine.consume(
|
||||
true,
|
||||
let ast = engine.compile(
|
||||
r"
|
||||
fn hello(x, y) {
|
||||
x + y
|
||||
@@ -31,14 +30,20 @@ fn test_call_fn() -> Result<(), EvalAltResult> {
|
||||
fn hello(x) {
|
||||
x * 2
|
||||
}
|
||||
",
|
||||
fn hello() {
|
||||
42
|
||||
}
|
||||
",
|
||||
)?;
|
||||
|
||||
let r: i64 = engine.call_fn("hello", (42 as INT, 123 as INT))?;
|
||||
let r: i64 = engine.call_fn(&ast, "hello", (42 as INT, 123 as INT))?;
|
||||
assert_eq!(r, 165);
|
||||
|
||||
let r: i64 = engine.call_fn("hello", 123 as INT)?;
|
||||
let r: i64 = engine.call_fn1(&ast, "hello", 123 as INT)?;
|
||||
assert_eq!(r, 246);
|
||||
|
||||
let r: i64 = engine.call_fn0(&ast, "hello")?;
|
||||
assert_eq!(r, 42);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user