Skip to content
This repository was archived by the owner on Aug 18, 2025. It is now read-only.

Commit 3618cbf

Browse files
committed
Refactor expression evaluation logic to streamline JIT compilation for integer expressions. Simplify method call checks and enhance variable handling within JIT expressions, improving performance and robustness of the interpreter.
1 parent 93c27c1 commit 3618cbf

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/interpreter/expression_evaluator.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,26 @@ impl<'a> ExpressionEvaluator for Interpreter<'a> {
1515
fn evaluate_expression(&mut self, expr: &Expression) -> Value {
1616
// 检查是否包含方法调用,如果包含则跳过JIT编译
1717
if !self.contains_method_call(expr) && self.is_pure_int_expression(expr) {
18-
if let Some(val) = jit::jit_eval_const_expr(expr) {
19-
return val;
18+
if let Some(val) = jit::jit_eval_const_expr(expr) {
19+
return val;
20+
}
21+
// 尝试整体JIT int型带变量表达式
22+
if let Some(jit_expr) = jit::jit_compile_int_expr(expr) {
23+
// 收集变量名和当前作用域变量值
24+
let mut vars = std::collections::HashMap::new();
25+
for name in &jit_expr.var_names {
26+
// 只支持Int类型变量
27+
let val = if let Some(Value::Int(i)) = self.local_env.get(name) {
28+
*i as i64
29+
} else if let Some(Value::Int(i)) = self.global_env.get(name) {
30+
*i as i64
31+
} else {
32+
panic!("JIT表达式变量{}未赋Int值", name);
33+
};
34+
vars.insert(name.clone(), val);
2035
}
21-
// 尝试整体JIT int型带变量表达式
22-
if let Some(jit_expr) = jit::jit_compile_int_expr(expr) {
23-
// 收集变量名和当前作用域变量值
24-
let mut vars = std::collections::HashMap::new();
25-
for name in &jit_expr.var_names {
26-
// 只支持Int类型变量
27-
let val = if let Some(Value::Int(i)) = self.local_env.get(name) {
28-
*i as i64
29-
} else if let Some(Value::Int(i)) = self.global_env.get(name) {
30-
*i as i64
31-
} else {
32-
panic!("JIT表达式变量{}未赋Int值", name);
33-
};
34-
vars.insert(name.clone(), val);
35-
}
36-
let result = jit_expr.call(&vars);
37-
return Value::Int(result as i32);
36+
let result = jit_expr.call(&vars);
37+
return Value::Int(result as i32);
3838
}
3939
}
4040
match expr {

0 commit comments

Comments
 (0)