From a43b59539c634ac51b3cf5f228cb7e057b84f1f1 Mon Sep 17 00:00:00 2001 From: David Mak Date: Thu, 3 Oct 2024 12:39:36 +0800 Subject: [PATCH] [meta] Move variables declarations closer to where they are first used --- nac3core/src/codegen/mod.rs | 3 +-- nac3core/src/toplevel/composer.rs | 7 +++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/nac3core/src/codegen/mod.rs b/nac3core/src/codegen/mod.rs index 145eab6a..74a0244d 100644 --- a/nac3core/src/codegen/mod.rs +++ b/nac3core/src/codegen/mod.rs @@ -853,10 +853,9 @@ pub fn gen_func_impl< builder.position_at_end(init_bb); 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 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) { let param = fn_val.get_nth_param((n as u32) + offset).unwrap(); let local_type = get_llvm_type( diff --git a/nac3core/src/toplevel/composer.rs b/nac3core/src/toplevel/composer.rs index 619cc50b..d3103894 100644 --- a/nac3core/src/toplevel/composer.rs +++ b/nac3core/src/toplevel/composer.rs @@ -500,6 +500,7 @@ impl TopLevelComposer { } Ok(()) }; + let mut errors = HashSet::new(); for (class_def, class_ast) in def_list.iter().skip(self.builtin_num) { if class_ast.is_none() { @@ -853,7 +854,6 @@ impl TopLevelComposer { let unifier = self.unifier.borrow_mut(); let primitives_store = &self.primitives_ty; - let mut errors = HashSet::new(); let mut analyze = |function_def: &Arc>, function_ast: &Option| { let mut function_def = function_def.write(); let function_def = &mut *function_def; @@ -1128,6 +1128,8 @@ impl TopLevelComposer { })?; Ok(()) }; + + let mut errors = HashSet::new(); for (function_def, function_ast) in def_list.iter().skip(self.builtin_num) { if function_ast.is_none() { continue; @@ -1702,7 +1704,6 @@ impl TopLevelComposer { } } - let mut errors = HashSet::new(); let mut analyze = |i, def: &Arc>, ast: &Option| { let class_def = def.read(); if let TopLevelDef::Class { @@ -1845,6 +1846,8 @@ impl TopLevelComposer { } Ok(()) }; + + let mut errors = HashSet::new(); for (i, (def, ast)) in definition_ast_list.iter().enumerate().skip(self.builtin_num) { if ast.is_none() { continue;