consistent naming

This commit is contained in:
Sebastien Bourdeauducq 2021-12-02 10:45:46 +08:00
parent b030aec191
commit 1c31aa6e8e
3 changed files with 24 additions and 24 deletions

View File

@ -8,7 +8,7 @@ type BuiltinInfo = (
&'static [&'static str] &'static [&'static str]
); );
pub fn get_built_ins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo { pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
let int32 = primitives.0.int32; let int32 = primitives.0.int32;
let int64 = primitives.0.int64; let int64 = primitives.0.int64;
let float = primitives.0.float; let float = primitives.0.float;

View File

@ -24,7 +24,7 @@ pub struct TopLevelComposer {
// get the class def id of a class method // get the class def id of a class method
pub method_class: HashMap<DefinitionId, DefinitionId>, pub method_class: HashMap<DefinitionId, DefinitionId>,
// number of built-in function and classes in the definition list, later skip // number of built-in function and classes in the definition list, later skip
pub built_in_num: usize, pub builtin_num: usize,
} }
impl Default for TopLevelComposer { impl Default for TopLevelComposer {
@ -40,7 +40,7 @@ impl TopLevelComposer {
builtins: Vec<(StrRef, FunSignature, Arc<GenCall>)>, builtins: Vec<(StrRef, FunSignature, Arc<GenCall>)>,
) -> (Self, HashMap<StrRef, DefinitionId>, HashMap<StrRef, Type>) { ) -> (Self, HashMap<StrRef, DefinitionId>, HashMap<StrRef, Type>) {
let mut primitives = Self::make_primitives(); let mut primitives = Self::make_primitives();
let (mut definition_ast_list, builtin_name_list) = builtins::get_built_ins(&mut primitives); let (mut definition_ast_list, builtin_name_list) = builtins::get_builtins(&mut primitives);
let primitives_ty = primitives.0; let primitives_ty = primitives.0;
let mut unifier = primitives.1; let mut unifier = primitives.1;
let mut keyword_list: HashSet<StrRef> = HashSet::from_iter(vec![ let mut keyword_list: HashSet<StrRef> = HashSet::from_iter(vec![
@ -63,8 +63,8 @@ impl TopLevelComposer {
let defined_names: HashSet<String> = Default::default(); let defined_names: HashSet<String> = Default::default();
let method_class: HashMap<DefinitionId, DefinitionId> = Default::default(); let method_class: HashMap<DefinitionId, DefinitionId> = Default::default();
let mut built_in_id: HashMap<StrRef, DefinitionId> = Default::default(); let mut builtin_id: HashMap<StrRef, DefinitionId> = Default::default();
let mut built_in_ty: HashMap<StrRef, Type> = Default::default(); let mut builtin_ty: HashMap<StrRef, Type> = Default::default();
for (id, name) in builtin_name_list.iter().rev().enumerate() { for (id, name) in builtin_name_list.iter().rev().enumerate() {
let name = (**name).into(); let name = (**name).into();
@ -72,8 +72,8 @@ impl TopLevelComposer {
let def = definition_ast_list[id].0.read(); let def = definition_ast_list[id].0.read();
if let TopLevelDef::Function { simple_name, signature, .. } = &*def { if let TopLevelDef::Function { simple_name, signature, .. } = &*def {
assert!(name == *simple_name); assert!(name == *simple_name);
built_in_ty.insert(name, *signature); builtin_ty.insert(name, *signature);
built_in_id.insert(name, DefinitionId(id)); builtin_id.insert(name, DefinitionId(id));
} else { } else {
unreachable!() unreachable!()
} }
@ -81,8 +81,8 @@ impl TopLevelComposer {
for (name, sig, codegen_callback) in builtins { for (name, sig, codegen_callback) in builtins {
let fun_sig = unifier.add_ty(TypeEnum::TFunc(RefCell::new(sig))); let fun_sig = unifier.add_ty(TypeEnum::TFunc(RefCell::new(sig)));
built_in_ty.insert(name, fun_sig); builtin_ty.insert(name, fun_sig);
built_in_id.insert(name, DefinitionId(definition_ast_list.len())); builtin_id.insert(name, DefinitionId(definition_ast_list.len()));
definition_ast_list.push(( definition_ast_list.push((
Arc::new(RwLock::new(TopLevelDef::Function { Arc::new(RwLock::new(TopLevelDef::Function {
name: name.into(), name: name.into(),
@ -101,7 +101,7 @@ impl TopLevelComposer {
( (
TopLevelComposer { TopLevelComposer {
built_in_num: definition_ast_list.len(), builtin_num: definition_ast_list.len(),
definition_ast_list, definition_ast_list,
primitives_ty, primitives_ty,
unifier, unifier,
@ -109,8 +109,8 @@ impl TopLevelComposer {
defined_names, defined_names,
method_class, method_class,
}, },
built_in_id, builtin_id,
built_in_ty, builtin_ty,
) )
} }
@ -320,7 +320,7 @@ impl TopLevelComposer {
let primitives_store = &self.primitives_ty; let primitives_store = &self.primitives_ty;
// skip 5 to skip analyzing the primitives // skip 5 to skip analyzing the primitives
for (class_def, class_ast) in def_list.iter().skip(self.built_in_num) { for (class_def, class_ast) in def_list.iter().skip(self.builtin_num) {
// only deal with class def here // only deal with class def here
let mut class_def = class_def.write(); let mut class_def = class_def.write();
let (class_bases_ast, class_def_type_vars, class_resolver) = { let (class_bases_ast, class_def_type_vars, class_resolver) = {
@ -426,7 +426,7 @@ impl TopLevelComposer {
// first, only push direct parent into the list // first, only push direct parent into the list
// skip 5 to skip analyzing the primitives // skip 5 to skip analyzing the primitives
for (class_def, class_ast) in self.definition_ast_list.iter_mut().skip(self.built_in_num) { for (class_def, class_ast) in self.definition_ast_list.iter_mut().skip(self.builtin_num) {
let mut class_def = class_def.write(); let mut class_def = class_def.write();
let (class_def_id, class_bases, class_ancestors, class_resolver, class_type_vars) = { let (class_def_id, class_bases, class_ancestors, class_resolver, class_type_vars) = {
if let TopLevelDef::Class { ancestors, resolver, object_id, type_vars, .. } = if let TopLevelDef::Class { ancestors, resolver, object_id, type_vars, .. } =
@ -490,7 +490,7 @@ impl TopLevelComposer {
// second, get all ancestors // second, get all ancestors
let mut ancestors_store: HashMap<DefinitionId, Vec<TypeAnnotation>> = Default::default(); let mut ancestors_store: HashMap<DefinitionId, Vec<TypeAnnotation>> = Default::default();
// skip 5 to skip analyzing the primitives // skip 5 to skip analyzing the primitives
for (class_def, _) in self.definition_ast_list.iter().skip(self.built_in_num) { for (class_def, _) in self.definition_ast_list.iter().skip(self.builtin_num) {
let class_def = class_def.read(); let class_def = class_def.read();
let (class_ancestors, class_id) = { let (class_ancestors, class_id) = {
if let TopLevelDef::Class { ancestors, object_id, .. } = class_def.deref() { if let TopLevelDef::Class { ancestors, object_id, .. } = class_def.deref() {
@ -512,7 +512,7 @@ impl TopLevelComposer {
// insert the ancestors to the def list // insert the ancestors to the def list
// skip 5 to skip analyzing the primitives // skip 5 to skip analyzing the primitives
for (class_def, _) in self.definition_ast_list.iter_mut().skip(self.built_in_num) { for (class_def, _) in self.definition_ast_list.iter_mut().skip(self.builtin_num) {
let mut class_def = class_def.write(); let mut class_def = class_def.write();
let (class_ancestors, class_id, class_type_vars) = { let (class_ancestors, class_id, class_type_vars) = {
if let TopLevelDef::Class { ancestors, object_id, type_vars, .. } = if let TopLevelDef::Class { ancestors, object_id, type_vars, .. } =
@ -545,7 +545,7 @@ impl TopLevelComposer {
let mut type_var_to_concrete_def: HashMap<Type, TypeAnnotation> = HashMap::new(); let mut type_var_to_concrete_def: HashMap<Type, TypeAnnotation> = HashMap::new();
// skip 5 to skip analyzing the primitives // skip 5 to skip analyzing the primitives
for (class_def, class_ast) in def_ast_list.iter().skip(self.built_in_num) { for (class_def, class_ast) in def_ast_list.iter().skip(self.builtin_num) {
if matches!(&*class_def.read(), TopLevelDef::Class { .. }) { if matches!(&*class_def.read(), TopLevelDef::Class { .. }) {
Self::analyze_single_class_methods_fields( Self::analyze_single_class_methods_fields(
class_def.clone(), class_def.clone(),
@ -566,7 +566,7 @@ impl TopLevelComposer {
loop { loop {
let mut finished = true; let mut finished = true;
for (class_def, _) in def_ast_list.iter().skip(self.built_in_num) { for (class_def, _) in def_ast_list.iter().skip(self.builtin_num) {
let mut class_def = class_def.write(); let mut class_def = class_def.write();
if let TopLevelDef::Class { ancestors, .. } = class_def.deref() { if let TopLevelDef::Class { ancestors, .. } = class_def.deref() {
// if the length of the ancestor is equal to the current depth // if the length of the ancestor is equal to the current depth
@ -625,7 +625,7 @@ impl TopLevelComposer {
let primitives_store = &self.primitives_ty; let primitives_store = &self.primitives_ty;
// skip 5 to skip analyzing the primitives // skip 5 to skip analyzing the primitives
for (function_def, function_ast) in def_list.iter().skip(self.built_in_num) { for (function_def, function_ast) in def_list.iter().skip(self.builtin_num) {
let mut function_def = function_def.write(); let mut function_def = function_def.write();
let function_def = function_def.deref_mut(); let function_def = function_def.deref_mut();
let function_ast = if let Some(x) = function_ast.as_ref() { let function_ast = if let Some(x) = function_ast.as_ref() {
@ -1235,7 +1235,7 @@ impl TopLevelComposer {
fn analyze_function_instance(&mut self) -> Result<(), String> { fn analyze_function_instance(&mut self) -> Result<(), String> {
// first get the class contructor type correct for the following type check in function body // first get the class contructor type correct for the following type check in function body
// also do class field instantiation check // also do class field instantiation check
for (def, ast) in self.definition_ast_list.iter().skip(self.built_in_num) { for (def, ast) in self.definition_ast_list.iter().skip(self.builtin_num) {
let class_def = def.read(); let class_def = def.read();
if let TopLevelDef::Class { if let TopLevelDef::Class {
constructor, constructor,
@ -1306,7 +1306,7 @@ impl TopLevelComposer {
let ctx = Arc::new(self.make_top_level_context()); let ctx = Arc::new(self.make_top_level_context());
// type inference inside function body // type inference inside function body
for (id, (def, ast)) in self.definition_ast_list.iter().enumerate().skip(self.built_in_num) for (id, (def, ast)) in self.definition_ast_list.iter().enumerate().skip(self.builtin_num)
{ {
let mut function_def = def.write(); let mut function_def = def.write();
if let TopLevelDef::Function { if let TopLevelDef::Function {

View File

@ -162,7 +162,7 @@ fn test_simple_function_analyze(source: Vec<&str>, tys: Vec<&str>, names: Vec<&s
composer.start_analysis(true).unwrap(); composer.start_analysis(true).unwrap();
for (i, (def, _)) in composer.definition_ast_list.iter().skip(composer.built_in_num).enumerate() for (i, (def, _)) in composer.definition_ast_list.iter().skip(composer.builtin_num).enumerate()
{ {
let def = &*def.read(); let def = &*def.read();
if let TopLevelDef::Function { signature, name, .. } = def { if let TopLevelDef::Function { signature, name, .. } = def {
@ -530,7 +530,7 @@ fn test_analyze(source: Vec<&str>, res: Vec<&str>) {
} else { } else {
// skip 5 to skip primitives // skip 5 to skip primitives
let mut res_vec: Vec<String> = Vec::new(); let mut res_vec: Vec<String> = Vec::new();
for (def, _) in composer.definition_ast_list.iter().skip(composer.built_in_num) { for (def, _) in composer.definition_ast_list.iter().skip(composer.builtin_num) {
let def = &*def.read(); let def = &*def.read();
res_vec.push(format!("{}\n", def.to_string(composer.unifier.borrow_mut()))); res_vec.push(format!("{}\n", def.to_string(composer.unifier.borrow_mut())));
} }
@ -715,7 +715,7 @@ fn test_inference(source: Vec<&str>, res: Vec<&str>) {
// skip 5 to skip primitives // skip 5 to skip primitives
let mut stringify_folder = TypeToStringFolder { unifier: &mut composer.unifier }; let mut stringify_folder = TypeToStringFolder { unifier: &mut composer.unifier };
for (_i, (def, _)) in for (_i, (def, _)) in
composer.definition_ast_list.iter().skip(composer.built_in_num).enumerate() composer.definition_ast_list.iter().skip(composer.builtin_num).enumerate()
{ {
let def = &*def.read(); let def = &*def.read();