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

Commit 5e55180

Browse files
committed
一些言语更改
1 parent 6e75ff8 commit 5e55180

19 files changed

+477
-697
lines changed

src/analyzer/type_checker.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl TypeCheckError {
3232
pub struct TypeChecker {
3333
// 变量类型表
3434
variable_types: HashMap<String, Type>,
35-
// 🚀 v0.6.2 新增:常量类型表
35+
// v0.6.2 新增:常量类型表
3636
constant_types: HashMap<String, Type>,
3737
// 函数签名表
3838
function_signatures: HashMap<String, (Vec<Type>, Type)>, // (参数类型, 返回类型)
@@ -42,7 +42,7 @@ pub struct TypeChecker {
4242
class_methods: HashMap<String, HashMap<String, (Vec<Type>, Type)>>, // 类名 -> 方法名 -> (参数类型, 返回类型)
4343
// 枚举定义表
4444
enum_definitions: HashMap<String, Vec<String>>, // 枚举名 -> 变体列表
45-
// 🚀 v0.8.4 新增:泛型支持
45+
// v0.8.4 新增:泛型支持
4646
// 泛型函数签名表
4747
generic_function_signatures: HashMap<String, (Vec<GenericParameter>, Vec<Type>, Type)>, // 函数名 -> (泛型参数, 参数类型, 返回类型)
4848
// 泛型类定义表
@@ -64,7 +64,7 @@ impl TypeChecker {
6464
class_definitions: HashMap::new(),
6565
class_methods: HashMap::new(),
6666
enum_definitions: HashMap::new(),
67-
// 🚀 v0.8.4 新增:泛型支持
67+
// v0.8.4 新增:泛型支持
6868
generic_function_signatures: HashMap::new(),
6969
generic_class_definitions: HashMap::new(),
7070
current_generic_context: HashMap::new(),
@@ -78,7 +78,7 @@ impl TypeChecker {
7878
// 第一遍:收集所有函数、类、枚举的定义
7979
self.collect_program_definitions(program);
8080

81-
// 🔧 修复:收集命名空间中的函数定义
81+
// 修复:收集命名空间中的函数定义
8282
for namespace in &program.namespaces {
8383
for function in &namespace.functions {
8484
let param_types: Vec<Type> = function.parameters.iter()
@@ -121,7 +121,7 @@ impl TypeChecker {
121121

122122
// 收集程序定义阶段
123123
fn collect_program_definitions(&mut self, program: &Program) {
124-
// 🚀 v0.6.2 收集常量定义
124+
// v0.6.2 收集常量定义
125125
for (name, const_type, _expr) in &program.constants {
126126
self.constant_types.insert(name.clone(), const_type.clone());
127127
}
@@ -137,8 +137,8 @@ impl TypeChecker {
137137
);
138138
}
139139

140-
// 🔧 修复:收集导入的命名空间中的库函数
141-
// 🔧 移除硬编码的函数签名,应该从动态库系统获取
140+
// 修复:收集导入的命名空间中的库函数
141+
// 移除硬编码的函数签名,应该从动态库系统获取
142142
// TODO: 实现从已加载库中动态获取函数签名的机制
143143
for (ns_type, path) in &program.imported_namespaces {
144144
match ns_type {
@@ -428,7 +428,7 @@ impl TypeChecker {
428428
Expression::LongLiteral(_) => Type::Long,
429429

430430
Expression::Variable(name) => {
431-
// 🚀 v0.6.2 先检查常量,再检查变量
431+
// v0.6.2 先检查常量,再检查变量
432432
if let Some(const_type) = self.constant_types.get(name) {
433433
const_type.clone()
434434
} else if let Some(var_type) = self.variable_types.get(name) {
@@ -729,7 +729,7 @@ impl TypeChecker {
729729

730730
// 检查函数调用
731731
fn check_function_call(&mut self, name: &str, args: &[Expression]) -> Type {
732-
// 🔧 首先检查是否是内置函数
732+
// 首先检查是否是内置函数
733733
match name {
734734
"println" | "print" => {
735735
// 内置输出函数,接受任意数量的参数
@@ -764,7 +764,7 @@ impl TypeChecker {
764764

765765
return_type
766766
} else {
767-
// 🚀 v0.6.2 修复:可能是导入的命名空间函数,假设为有效
767+
// v0.6.2 修复:可能是导入的命名空间函数,假设为有效
768768
// 在运行时会进行实际的函数查找和调用
769769
Type::Auto // 假设函数存在,返回Auto类型
770770
}
@@ -950,7 +950,7 @@ impl TypeChecker {
950950
self.types_compatible(expected_element, actual_element)
951951
},
952952

953-
// 🚀 v0.8.4 新增:泛型类型兼容性
953+
// v0.8.4 新增:泛型类型兼容性
954954
(Type::Generic(name1), Type::Generic(name2)) => name1 == name2,
955955
(Type::Generic(name), actual_type) => {
956956
// 检查泛型参数是否已绑定到具体类型
@@ -981,7 +981,7 @@ impl TypeChecker {
981981
}
982982
}
983983

984-
// 🚀 v0.8.4 新增:泛型类型检查方法
984+
// v0.8.4 新增:泛型类型检查方法
985985

986986
/// 检查泛型约束是否满足
987987
pub fn check_generic_constraints(&self, type_param: &str, actual_type: &Type, constraints: &[TypeConstraint]) -> bool {

src/interpreter/expression_evaluator.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,13 @@ impl<'a> Interpreter<'a> {
115115
// 尝试编译数学表达式
116116
match jit.compile_math_expression(expr, key.clone(), true) {
117117
Ok(_compiled) => {
118-
crate::jit_debug_println!(" 数学表达式JIT编译成功: {}", key);
118+
crate::jit_debug_println!(" 数学表达式JIT编译成功: {}", key);
119119
// 编译成功,记录在统计中
120120
// 注意:这里我们暂时返回None,因为实际执行需要更复杂的实现
121121
// 但是编译过程已经被记录在统计中
122122
},
123123
Err(e) => {
124-
println!(" 数学表达式JIT编译失败: {} - {}", key, e);
124+
println!(" 数学表达式JIT编译失败: {} - {}", key, e);
125125
// 编译失败,继续使用解释执行
126126
}
127127
}
@@ -207,7 +207,7 @@ impl<'a> ExpressionEvaluator for Interpreter<'a> {
207207
fn evaluate_expression(&mut self, expr: &Expression) -> Value {
208208
// 检查超时和操作次数限制
209209
if let Err(timeout_msg) = self.check_timeout() {
210-
eprintln!("️ 执行超时: {}", timeout_msg);
210+
eprintln!("️ 执行超时: {}", timeout_msg);
211211
return Value::None;
212212
}
213213

@@ -273,11 +273,11 @@ impl<'a> ExpressionEvaluator for Interpreter<'a> {
273273
Value::Array(values)
274274
},
275275
Expression::ArrayAccess(array_expr, index_expr) => {
276-
// 🧮 数组访问JIT编译检查
276+
// 数组访问JIT编译检查
277277
let array_key = format!("array_access_{:p}", expr as *const _);
278278
if jit::should_compile_array_operation(&array_key) {
279279
if let Ok(_compiled) = jit::compile_array_operation(expr, array_key.clone(), false) {
280-
println!(" 数组访问JIT编译成功: {}", array_key);
280+
println!(" 数组访问JIT编译成功: {}", array_key);
281281
}
282282
}
283283

@@ -498,15 +498,15 @@ impl<'a> ExpressionEvaluator for Interpreter<'a> {
498498
}
499499
},
500500
Expression::StaticMethodCall(class_name, method_name, args) => {
501-
// 🔧 首先检查是否是库命名空间函数调用
501+
// 首先检查是否是库命名空间函数调用
502502
if self.library_namespaces.contains_key(class_name) {
503503
debug_println(&format!("StaticMethodCall被识别为库命名空间函数调用: {}::{}", class_name, method_name));
504504
// 转换为命名空间函数调用
505505
let path = vec![class_name.clone(), method_name.clone()];
506506
return self.handle_namespaced_function_call(&path, args);
507507
}
508508

509-
// 🔧 新增:检查是否是代码命名空间函数调用
509+
// 新增:检查是否是代码命名空间函数调用
510510
let potential_ns_path = format!("{}::{}", class_name, method_name);
511511
if self.namespaced_functions.contains_key(&potential_ns_path) {
512512
debug_println(&format!("StaticMethodCall被识别为代码命名空间函数调用: {}", potential_ns_path));
@@ -599,11 +599,11 @@ impl<'a> ExpressionEvaluator for Interpreter<'a> {
599599
self.apply_function(func_value, arg_values)
600600
},
601601
Expression::ArrayMap(array_expr, lambda_expr) => {
602-
// 🧮 数组map操作JIT编译检查
602+
// 数组map操作JIT编译检查
603603
let map_key = format!("array_map_{:p}", expr as *const _);
604604
if jit::should_compile_array_operation(&map_key) {
605605
if let Ok(_compiled) = jit::compile_array_operation(expr, map_key.clone(), false) {
606-
println!(" 数组map操作JIT编译成功: {}", map_key);
606+
println!(" 数组map操作JIT编译成功: {}", map_key);
607607
}
608608
}
609609

@@ -613,11 +613,11 @@ impl<'a> ExpressionEvaluator for Interpreter<'a> {
613613
self.array_map(array_value, lambda_value)
614614
},
615615
Expression::ArrayFilter(array_expr, lambda_expr) => {
616-
// 🧮 数组filter操作JIT编译检查
616+
// 数组filter操作JIT编译检查
617617
let filter_key = format!("array_filter_{:p}", expr as *const _);
618618
if jit::should_compile_array_operation(&filter_key) {
619619
if let Ok(_compiled) = jit::compile_array_operation(expr, filter_key.clone(), false) {
620-
println!(" 数组filter操作JIT编译成功: {}", filter_key);
620+
println!(" 数组filter操作JIT编译成功: {}", filter_key);
621621
}
622622
}
623623

@@ -627,11 +627,11 @@ impl<'a> ExpressionEvaluator for Interpreter<'a> {
627627
self.array_filter(array_value, lambda_value)
628628
},
629629
Expression::ArrayReduce(array_expr, lambda_expr, initial_expr) => {
630-
// 🧮 数组reduce操作JIT编译检查
630+
// 数组reduce操作JIT编译检查
631631
let reduce_key = format!("array_reduce_{:p}", expr as *const _);
632632
if jit::should_compile_array_operation(&reduce_key) {
633633
if let Ok(_compiled) = jit::compile_array_operation(expr, reduce_key.clone(), false) {
634-
println!(" 数组reduce操作JIT编译成功: {}", reduce_key);
634+
println!(" 数组reduce操作JIT编译成功: {}", reduce_key);
635635
}
636636
}
637637

@@ -642,11 +642,11 @@ impl<'a> ExpressionEvaluator for Interpreter<'a> {
642642
self.array_reduce(array_value, lambda_value, initial_value)
643643
},
644644
Expression::ArrayForEach(array_expr, lambda_expr) => {
645-
// 🧮 数组forEach操作JIT编译检查
645+
// 数组forEach操作JIT编译检查
646646
let foreach_key = format!("array_foreach_{:p}", expr as *const _);
647647
if jit::should_compile_array_operation(&foreach_key) {
648648
if let Ok(_compiled) = jit::compile_array_operation(expr, foreach_key.clone(), false) {
649-
println!(" 数组forEach操作JIT编译成功: {}", foreach_key);
649+
println!(" 数组forEach操作JIT编译成功: {}", foreach_key);
650650
}
651651
}
652652

@@ -761,7 +761,7 @@ impl<'a> ExpressionEvaluator for Interpreter<'a> {
761761
self.evaluate_match_expression(*match_expr.clone(), arms.clone())
762762
},
763763

764-
// 🚀 v0.8.4 改进:泛型相关表达式
764+
// v0.8.4 改进:泛型相关表达式
765765
Expression::GenericFunctionCall(func_name, type_args, args) => {
766766
// 改进的泛型函数调用处理
767767
self.handle_generic_function_call(func_name, type_args, args).unwrap_or(Value::None)
@@ -1060,11 +1060,11 @@ impl<'a> Interpreter<'a> {
10601060
self.handle_string_method(&s, method_name, &evaluated_args)
10611061
},
10621062
Value::Array(arr) => {
1063-
// 🧮 数组方法调用JIT编译检查
1063+
// 数组方法调用JIT编译检查
10641064
let method_key = format!("array_method_{}_{:p}", method_name, obj_expr as *const _);
10651065
if jit::should_compile_array_operation(&method_key) {
10661066
if let Ok(_compiled) = jit::compile_array_operation(obj_expr, method_key.clone(), false) {
1067-
println!(" 数组方法{}JIT编译成功: {}", method_name, method_key);
1067+
println!(" 数组方法{}JIT编译成功: {}", method_name, method_key);
10681068
}
10691069
}
10701070

@@ -1875,7 +1875,7 @@ impl<'a> Interpreter<'a> {
18751875
arg_values.push(self.evaluate_expression(arg));
18761876
}
18771877

1878-
// 🧠 记忆化缓存检查(仅对记忆化方法)
1878+
// 记忆化缓存检查(仅对记忆化方法)
18791879
if method_clone.is_memoized {
18801880
let method_full_name = format!("{}::{}", obj.class_name, method_name);
18811881

@@ -1884,7 +1884,7 @@ impl<'a> Interpreter<'a> {
18841884
cache_args.extend(arg_values.clone());
18851885

18861886
if let Some(cached_result) = super::memoization::memo_get(&method_full_name, &cache_args) {
1887-
debug_println(&format!("🧠 方法记忆化缓存命中: {}({:?}) -> {:?}", method_full_name, cache_args, cached_result));
1887+
debug_println(&format!(" 方法记忆化缓存命中: {}({:?}) -> {:?}", method_full_name, cache_args, cached_result));
18881888
return cached_result;
18891889
}
18901890
}
@@ -1900,7 +1900,7 @@ impl<'a> Interpreter<'a> {
19001900
// 执行方法体,传递this对象和参数环境
19011901
let (result, updated_obj) = self.execute_method_body_with_context(&method_clone.body, &obj, &method_env);
19021902

1903-
// 🧠 记忆化缓存存储(仅对记忆化方法)
1903+
// 记忆化缓存存储(仅对记忆化方法)
19041904
if method_clone.is_memoized {
19051905
let method_full_name = format!("{}::{}", obj.class_name, method_name);
19061906

@@ -1909,7 +1909,7 @@ impl<'a> Interpreter<'a> {
19091909
cache_args.extend(arg_values.clone());
19101910

19111911
super::memoization::memo_put(&method_full_name, &cache_args, result.clone());
1912-
debug_println(&format!("🧠 方法记忆化缓存存储: {}({:?}) -> {:?}", method_full_name, cache_args, result));
1912+
debug_println(&format!(" 方法记忆化缓存存储: {}({:?}) -> {:?}", method_full_name, cache_args, result));
19131913
}
19141914

19151915
// 更新原始对象的状态
@@ -2299,7 +2299,7 @@ impl<'a> Interpreter<'a> {
22992299
return Value::None;
23002300
}
23012301

2302-
// 🧠 记忆化缓存检查(仅对记忆化方法)
2302+
// 记忆化缓存检查(仅对记忆化方法)
23032303
if method_clone.is_memoized {
23042304
let method_full_name = format!("{}::{}", this_obj.class_name, method_name);
23052305

@@ -2308,7 +2308,7 @@ impl<'a> Interpreter<'a> {
23082308
cache_args.extend(arg_values.clone());
23092309

23102310
if let Some(cached_result) = super::memoization::memo_get(&method_full_name, &cache_args) {
2311-
debug_println(&format!("🧠 this方法记忆化缓存命中: {}({:?}) -> {:?}", method_full_name, cache_args, cached_result));
2311+
debug_println(&format!(" this方法记忆化缓存命中: {}({:?}) -> {:?}", method_full_name, cache_args, cached_result));
23122312
return cached_result;
23132313
}
23142314
}
@@ -2324,7 +2324,7 @@ impl<'a> Interpreter<'a> {
23242324
// 执行方法体,传递this对象和参数环境
23252325
let (result, _updated_obj) = self.execute_method_body_with_context(&method_clone.body, this_obj, &method_env_new);
23262326

2327-
// 🧠 记忆化缓存存储(仅对记忆化方法)
2327+
// 记忆化缓存存储(仅对记忆化方法)
23282328
if method_clone.is_memoized {
23292329
let method_full_name = format!("{}::{}", this_obj.class_name, method_name);
23302330

@@ -2333,7 +2333,7 @@ impl<'a> Interpreter<'a> {
23332333
cache_args.extend(arg_values.clone());
23342334

23352335
super::memoization::memo_put(&method_full_name, &cache_args, result.clone());
2336-
debug_println(&format!("🧠 this方法记忆化缓存存储: {}({:?}) -> {:?}", method_full_name, cache_args, result));
2336+
debug_println(&format!(" this方法记忆化缓存存储: {}({:?}) -> {:?}", method_full_name, cache_args, result));
23372337
}
23382338

23392339
return result;
@@ -4210,7 +4210,7 @@ impl<'a> Interpreter<'a> {
42104210
}
42114211

42124212

4213-
// 🚀 v0.8.4 新增:改进的泛型表达式处理方法
4213+
// v0.8.4 新增:改进的泛型表达式处理方法
42144214

42154215
/// 处理泛型函数调用
42164216
fn handle_generic_function_call(&mut self, func_name: &str, type_args: &[Type], args: &[Expression]) -> Result<Value, String> {

0 commit comments

Comments
 (0)