From eecba0b71dc35f59ba4afa54a5882b72f63a4bea Mon Sep 17 00:00:00 2001 From: David Mak Date: Tue, 23 Apr 2024 14:36:29 +0800 Subject: [PATCH] core: Add GenCall::create_dummy A simple abstraction for GenCalls that are already handled elsewhere. --- nac3core/src/toplevel/builtins.rs | 8 +++----- nac3core/src/toplevel/mod.rs | 7 +++++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/nac3core/src/toplevel/builtins.rs b/nac3core/src/toplevel/builtins.rs index 91065ceb..967dc018 100644 --- a/nac3core/src/toplevel/builtins.rs +++ b/nac3core/src/toplevel/builtins.rs @@ -514,11 +514,9 @@ pub fn get_builtins(unifier: &mut Unifier, primitives: &PrimitiveStore) -> Built instance_to_symbol: HashMap::default(), instance_to_stmt: HashMap::default(), resolver: None, - codegen_callback: Some(Arc::new(GenCall::new(Box::new( - |_, _, _, _, _| { - unreachable!("handled in gen_expr") - }, - )))), + codegen_callback: Some(Arc::new(GenCall::create_dummy( + String::from("handled in gen_expr"), + ))), loc: None, })), Arc::new(RwLock::new(TopLevelDef::Class { diff --git a/nac3core/src/toplevel/mod.rs b/nac3core/src/toplevel/mod.rs index 6edaeca5..e38207f7 100644 --- a/nac3core/src/toplevel/mod.rs +++ b/nac3core/src/toplevel/mod.rs @@ -53,6 +53,13 @@ impl GenCall { GenCall { fp } } + /// Creates a dummy instance of [`GenCall`], which invokes [`unreachable!()`] with the given + /// `reason`. + #[must_use] + pub fn create_dummy(reason: String) -> GenCall { + Self::new(Box::new(move |_, _, _, _, _| unreachable!("{reason}"))) + } + pub fn run<'ctx>( &self, ctx: &mut CodeGenContext<'ctx, '_>,