diff --git a/port/linux/package/pikascript/rust-msc-latest-linux b/port/linux/package/pikascript/rust-msc-latest-linux index 35ec2f56c..29fb8116a 100755 Binary files a/port/linux/package/pikascript/rust-msc-latest-linux and b/port/linux/package/pikascript/rust-msc-latest-linux differ diff --git a/tools/pikaCompiler/src/class_info.rs b/tools/pikaCompiler/src/class_info.rs index 30452809d..9459a8d0d 100644 --- a/tools/pikaCompiler/src/class_info.rs +++ b/tools/pikaCompiler/src/class_info.rs @@ -15,7 +15,10 @@ pub struct ClassInfo { } impl ClassInfo { - pub fn add_file_profix(file_name: &String, class_name: &String) -> String { + pub fn add_file_profix(file_name: &String, class_name: &String, isPackage: bool) -> String { + if isPackage { + return class_name.clone(); + } if file_name == "main" { return class_name.clone(); } else if class_name == "BaseObj" || class_name == "TinyObj" { @@ -25,7 +28,7 @@ impl ClassInfo { } } - pub fn new(file_name: &String, define: &String) -> Option { + pub fn new(file_name: &String, define: &String, is_package: bool) -> Option { let define = define.strip_prefix("class ").unwrap().to_string(); let define = define.replace(" ", ""); let super_class_name = match my_string::cut(&define, '(', ')') { @@ -33,14 +36,14 @@ impl ClassInfo { None => return None, }; let super_class_name = match super_class_name.find(".") { - None => ClassInfo::add_file_profix(&file_name, &super_class_name), + None => ClassInfo::add_file_profix(&file_name, &super_class_name, is_package), Some(x) => super_class_name.replace(".", "_"), }; let mut this_calss_name = match my_string::get_first_token(&define, '(') { Some(s) => s, None => return None, }; - this_calss_name = ClassInfo::add_file_profix(&file_name, &this_calss_name); + this_calss_name = ClassInfo::add_file_profix(&file_name, &this_calss_name, false); let new_class_info = ClassInfo { this_class_name: this_calss_name, super_class_name: super_class_name, @@ -161,7 +164,8 @@ mod tests { assert_eq!( ClassInfo::new( &String::from("Pkg"), - &String::from("class Test(SuperTest):") + &String::from("class Test(SuperTest):"), + false ) .unwrap() .this_class_name, @@ -170,7 +174,8 @@ mod tests { assert_eq!( ClassInfo::new( &String::from("Pkg"), - &String::from("class Test(SuperTest):") + &String::from("class Test(SuperTest):"), + false ) .unwrap() .super_class_name, @@ -182,6 +187,7 @@ mod tests { let mut class_info = ClassInfo::new( &String::from("Pkg"), &String::from("class Test(SuperTest):"), + false, ) .unwrap(); class_info.push_method(String::from("def test(data: str)-> str:")); @@ -220,6 +226,7 @@ mod tests { let mut class_info = ClassInfo::new( &String::from("Pkg"), &String::from("class Test(SuperTest):"), + false, ) .unwrap(); class_info.push_object(String::from("testObj = TestObj()"), &"Pkg".to_string()); @@ -249,6 +256,7 @@ mod tests { let mut class_info = ClassInfo::new( &String::from("Pkg"), &String::from("class Test(SuperTest):"), + false, ) .unwrap(); class_info.push_import(String::from("TestObj()"), &"Pkg".to_string()); diff --git a/tools/pikaCompiler/src/compiler.rs b/tools/pikaCompiler/src/compiler.rs index 3f088937f..47d4f81c9 100644 --- a/tools/pikaCompiler/src/compiler.rs +++ b/tools/pikaCompiler/src/compiler.rs @@ -9,6 +9,8 @@ pub struct Compiler { pub source_path: String, pub class_list: BTreeMap, pub class_now_name: Option, + pub package_list: BTreeMap, + pub package_now_name: Option, } impl Compiler { @@ -18,6 +20,8 @@ impl Compiler { source_path: source_path.clone(), class_now_name: None, class_list: BTreeMap::new(), + package_list: BTreeMap::new(), + package_now_name: None, }; return compiler; } @@ -30,6 +34,7 @@ impl Compiler { ClassInfo::new( &file_name, &"class PikaMain(PikaStdLib.SysObj):".to_string(), + false, ) .unwrap(), ), @@ -49,6 +54,13 @@ impl Compiler { pub fn analyze_file(mut compiler: Compiler, file_name: String) -> Compiler { println!("analyzing file: {}{}.py", compiler.source_path, file_name); let mut file = File::open(format!("{}{}.py", compiler.source_path, file_name)).unwrap(); + if file_name != "main" { + let pkg_define = format!("class {}(TinyObj):", &file_name); + let pacakge_now = match ClassInfo::new(&String::from(""), &pkg_define, true) { + Some(s) => s, + None => return compiler, + }; + } let mut file_str = String::new(); file.read_to_string(&mut file_str).unwrap(); let lines: Vec<&str> = file_str.split('\n').collect(); @@ -76,7 +88,7 @@ impl Compiler { } if line.starts_with("class") { - let class_now = match ClassInfo::new(&file_name, &line) { + let class_now = match ClassInfo::new(&file_name, &line, false) { Some(s) => s, None => return compiler, }; diff --git a/tools/pikaCompiler/src/import_info.rs b/tools/pikaCompiler/src/import_info.rs index 0afc124fd..6b471f58a 100644 --- a/tools/pikaCompiler/src/import_info.rs +++ b/tools/pikaCompiler/src/import_info.rs @@ -1,5 +1,5 @@ -use crate::my_string; use crate::class_info; +use crate::my_string; #[derive(Debug)] pub struct ImportInfo { pub class_name: String, @@ -18,7 +18,7 @@ impl ImportInfo { None => return None, }; import_class_name = match import_class_name.find(".") { - None => class_info::ClassInfo::add_file_profix(&file_name, &import_class_name), + None => class_info::ClassInfo::add_file_profix(&file_name, &import_class_name, false), Some(x) => import_class_name.replace(".", "_"), }; import_class_name = import_class_name.replace(".", "_"); diff --git a/tools/pikaCompiler/src/object_info.rs b/tools/pikaCompiler/src/object_info.rs index 08eac2e55..4f3396726 100644 --- a/tools/pikaCompiler/src/object_info.rs +++ b/tools/pikaCompiler/src/object_info.rs @@ -23,7 +23,7 @@ impl ObjectInfo { None => return None, }; import_class_name = match import_class_name.find(".") { - None => class_info::ClassInfo::add_file_profix(&file_name, &import_class_name), + None => class_info::ClassInfo::add_file_profix(&file_name, &import_class_name, false), Some(x) => import_class_name.replace(".", "_"), }; return Some(ObjectInfo {