core: Add GenCall::create_dummy

A simple abstraction for GenCalls that are already handled elsewhere.
David Mak 2024-04-23 14:36:29 +08:00
parent e503fd1ffd
commit 3791c1c6c6
2 changed files with 10 additions and 5 deletions

View File

@ -510,11 +510,9 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
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 {

View File

@ -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, '_>,