diff --git a/src/compiler/ast.rs b/src/compiler/ast.rs index 7bfbd273..aa452ba3 100644 --- a/src/compiler/ast.rs +++ b/src/compiler/ast.rs @@ -16,6 +16,7 @@ use rust_i18n::t; use std::{ cell::RefCell, collections::{HashMap, HashSet}, + iter::Cloned, mem::swap, path::PathBuf, rc::Rc, @@ -44,11 +45,12 @@ pub struct ModuleUnit<'a> { pub self_scope: Rc>, process_info: lexprocess::LexProcess, cache: Cache, - // record if the first func is defined + /// record if the first func is defined first_func: bool, - // 对哈希表去重,并且记录每个dll的函数起始索引 + /// 对哈希表去重,并且记录每个dll的函数起始索引 modules_dll_dup: HashSet, modules_info: HashMap, + /// 引用的dll modules_dll: Vec, module_manager: Rc>>, compiler_data: Rc>, @@ -58,13 +60,13 @@ type AstError = RuntimeResult; macro_rules! tmp_expe_function_gen { ($tmpfuncname:ident, $next_item_func:ident, $($accepted_token:path),*) => { - fn $tmpfuncname(&mut self, istry: bool, extend: usize) -> AstError<()> { + fn $tmpfuncname(&mut self, istry: bool, extend: ClassIdxId) -> AstError<()> { let next_sym = self.token_lexer.borrow_mut().next_token()?; match next_sym { $($accepted_token => { self.$next_item_func(istry)?; // 读取IOType检查 - let func_obj = self.self_scope.borrow().get_class_by_class_id(ClassIdxId(extend)).expect(&format!("Class {} not found", extend)); + let func_obj = self.self_scope.borrow().get_class_by_class_id(extend).expect(&format!("Class {} not found", *extend)); let io_check = func_obj.get_override_func(match $accepted_token.convert_to_override() { Some(v) => v, None => { @@ -373,7 +375,7 @@ impl<'a> ModuleUnit<'a> { } /// 解析出函数参数 - fn opt_args(&mut self, lex_func_obj: &Rc) -> AstError> { + fn opt_args(&mut self, lex_func_obj: &Rc) -> AstError> { let mut ret = vec![]; let mut var_params_num = 0; let io_tmp = lex_func_obj.get_io(); @@ -426,7 +428,7 @@ impl<'a> ModuleUnit<'a> { } } - fn load_var_opcode(&mut self, ty: TyIdxTy) -> (Opcode, usize) { + fn load_var_opcode(&mut self, ty: ClassIdxId) -> (Opcode, usize) { let ret_opcode = if self.process_info.is_global { Opcode::LoadGlobalVar } else { @@ -682,7 +684,7 @@ impl<'a> ModuleUnit<'a> { fn lex_case( &mut self, - expected_ty: ScopeAllocIdTy, + expected_ty: ClassIdxId, mut add_expr_addr: impl FnMut(usize), mut add_case_final_addr: impl FnMut(usize), ) -> AstError { @@ -784,7 +786,7 @@ impl<'a> ModuleUnit<'a> { // lex args self.get_token_checked(Token::LeftSmallBrace)?; let mut argname: ArgsNameTy = vec![]; - let mut ty_list: Vec = vec![]; + let mut ty_list: Vec = vec![]; loop { let t = self.next_token()?; if t == Token::RightSmallBrace { @@ -885,8 +887,9 @@ impl<'a> ModuleUnit<'a> { self.self_scope.borrow_mut().in_class = true; let name = self.get_token_checked_with_val(Token::ID(0))?; let name_id = self.insert_sym_with_error(name)?; + // FIXME:BUG!CLASS ID SHOULD BE ALLOCATED let mut class_obj = CustomType::new( - name_id, + ClassIdxId(name_id), self.token_lexer.borrow_mut().get_constpool().id_name[name].clone(), ); self.get_token_checked(Token::LeftBigBrace)?; diff --git a/src/compiler/manager.rs b/src/compiler/manager.rs index 4df5a6e7..30b06fb4 100644 --- a/src/compiler/manager.rs +++ b/src/compiler/manager.rs @@ -4,8 +4,8 @@ use crate::{ cfg, compiler::{ast::ModuleUnit, linker::link, optimizer::optimize_module, Compiler, CompilerImpl}, }; -use libcore::utils; use libcore::StaticData; +use libcore::{utils, FuncIdxTy}; use std::{ cell::RefCell, collections::{hash_map::IterMut, HashMap}, @@ -112,16 +112,16 @@ impl<'a> ModuleManager<'a> { // 对应模块不存在,返回None } - pub fn alloc_custom_function_id(&mut self) -> usize { + pub fn alloc_custom_function_id(&mut self) -> FuncIdxTy { let ret = self.global_custom_function_id; self.global_custom_function_id += 1; - ret + FuncIdxTy(ret) } - pub fn alloc_extern_function_id(&mut self) -> usize { + pub fn alloc_extern_function_id(&mut self) -> FuncIdxTy { let ret = self.global_extern_function_id; self.global_extern_function_id += 1; - ret + FuncIdxTy(ret) } /// 执行优化 diff --git a/src/compiler/scope.rs b/src/compiler/scope.rs index 3c0661dd..ba2212e6 100644 --- a/src/compiler/scope.rs +++ b/src/compiler/scope.rs @@ -63,7 +63,7 @@ pub struct CustomType { funcs: Vec, pub name: ClassIdxId, pub origin_name: String, - pub id_to_attr: HashMap, + pub id_to_attr: HashMap, } impl Display for CustomType { @@ -81,7 +81,7 @@ impl CustomType { } } - pub fn add_attr(&mut self, attrname: ScopeAllocIdTy, attrty: TyIdxTy) -> Option { + pub fn add_attr(&mut self, attrname: ScopeAllocIdTy, attrty: ClassIdxId) -> Option { self.id_to_attr.insert(attrname, attrty) } @@ -121,7 +121,7 @@ pub type FuncBodyTy = Vec<(Token, usize)>; #[derive(Clone, Debug, Copy)] pub struct VarInfo { - pub ty: TyIdxTy, + pub ty: ClassIdxId, pub var_idx: usize, pub addr: usize, }