forked from M-Labs/nac3
1
0
Fork 0

[meta] Move variables declarations closer to where they are first used

This commit is contained in:
David Mak 2024-10-03 12:39:36 +08:00
parent fe06b2806f
commit a43b59539c
2 changed files with 6 additions and 4 deletions

View File

@ -853,10 +853,9 @@ pub fn gen_func_impl<
builder.position_at_end(init_bb); builder.position_at_end(init_bb);
let body_bb = context.append_basic_block(fn_val, "body"); let body_bb = context.append_basic_block(fn_val, "body");
// Store non-vararg argument values into local variables
let mut var_assignment = HashMap::new(); let mut var_assignment = HashMap::new();
let offset = u32::from(has_sret); let offset = u32::from(has_sret);
// Store non-vararg argument values into local variables
for (n, arg) in args.iter().enumerate().filter(|(_, arg)| !arg.is_vararg) { for (n, arg) in args.iter().enumerate().filter(|(_, arg)| !arg.is_vararg) {
let param = fn_val.get_nth_param((n as u32) + offset).unwrap(); let param = fn_val.get_nth_param((n as u32) + offset).unwrap();
let local_type = get_llvm_type( let local_type = get_llvm_type(

View File

@ -500,6 +500,7 @@ impl TopLevelComposer {
} }
Ok(()) Ok(())
}; };
let mut errors = HashSet::new(); let mut errors = HashSet::new();
for (class_def, class_ast) in def_list.iter().skip(self.builtin_num) { for (class_def, class_ast) in def_list.iter().skip(self.builtin_num) {
if class_ast.is_none() { if class_ast.is_none() {
@ -853,7 +854,6 @@ impl TopLevelComposer {
let unifier = self.unifier.borrow_mut(); let unifier = self.unifier.borrow_mut();
let primitives_store = &self.primitives_ty; let primitives_store = &self.primitives_ty;
let mut errors = HashSet::new();
let mut analyze = |function_def: &Arc<RwLock<TopLevelDef>>, function_ast: &Option<Stmt>| { let mut analyze = |function_def: &Arc<RwLock<TopLevelDef>>, function_ast: &Option<Stmt>| {
let mut function_def = function_def.write(); let mut function_def = function_def.write();
let function_def = &mut *function_def; let function_def = &mut *function_def;
@ -1128,6 +1128,8 @@ impl TopLevelComposer {
})?; })?;
Ok(()) Ok(())
}; };
let mut errors = HashSet::new();
for (function_def, function_ast) in def_list.iter().skip(self.builtin_num) { for (function_def, function_ast) in def_list.iter().skip(self.builtin_num) {
if function_ast.is_none() { if function_ast.is_none() {
continue; continue;
@ -1702,7 +1704,6 @@ impl TopLevelComposer {
} }
} }
let mut errors = HashSet::new();
let mut analyze = |i, def: &Arc<RwLock<TopLevelDef>>, ast: &Option<Stmt>| { let mut analyze = |i, def: &Arc<RwLock<TopLevelDef>>, ast: &Option<Stmt>| {
let class_def = def.read(); let class_def = def.read();
if let TopLevelDef::Class { if let TopLevelDef::Class {
@ -1845,6 +1846,8 @@ impl TopLevelComposer {
} }
Ok(()) Ok(())
}; };
let mut errors = HashSet::new();
for (i, (def, ast)) in definition_ast_list.iter().enumerate().skip(self.builtin_num) { for (i, (def, ast)) in definition_ast_list.iter().enumerate().skip(self.builtin_num) {
if ast.is_none() { if ast.is_none() {
continue; continue;