core: reduce code duplication in codegen/builtin_fns #422

Merged
sb10q merged 7 commits from refactor-builtin-fns into master 2024-06-20 12:48:45 +08:00
Showing only changes of commit 86d1325261 - Show all commits

View File

@ -1157,6 +1157,7 @@ pub fn call_abs<'ctx, G: CodeGenerator + ?Sized>(
/// Helper macro. Used so we don't have to keep typing out the type signature of the function.
macro_rules! call_numpy {
($name:ident, $fn_name:literal, $get_ret_elem_type:expr, $on_elem:expr) => {
derppening marked this conversation as resolved Outdated

Documentation comments are to explain what this macro does.

/// Macro for generating unary functions accepting  `ndarray`-compatible values.
///
/// The only form of the macro accepts an identifier for the generated function, the name of the 
/// corresponding Python function, a closure of type `Fn(&mut CodeGenContext<'ctx, '_>, Type) -> 
/// Type` which obtains the elementwise return type, and a closure of type `Fn(&mut G, 
/// &mut CodeGenContext<'ctx, '_>, Type, BasicValueEnum<'ctx>) -> Option<BasicValueEnum<'ctx>>` 
/// which performs the operation on a single element.

Same for the macros below.

Documentation comments are to explain what this macro does. ```rs /// Macro for generating unary functions accepting `ndarray`-compatible values. /// /// The only form of the macro accepts an identifier for the generated function, the name of the /// corresponding Python function, a closure of type `Fn(&mut CodeGenContext<'ctx, '_>, Type) -> /// Type` which obtains the elementwise return type, and a closure of type `Fn(&mut G, /// &mut CodeGenContext<'ctx, '_>, Type, BasicValueEnum<'ctx>) -> Option<BasicValueEnum<'ctx>>` /// which performs the operation on a single element. ``` Same for the macros below.
#[allow(clippy::redundant_closure_call)]
derppening marked this conversation as resolved Outdated

I don't think it's appropriate to name the macro call_numpy, as it gives the impression that the macro actually invokes the function rather than generates a function which can in turn be used.

Same for the macros below.

I don't think it's appropriate to name the macro `call_numpy`, as it gives the impression that the macro actually invokes the function rather than generates a function which can in turn be used. Same for the macros below.
pub fn $name<'ctx, G: CodeGenerator + ?Sized>(
generator: &mut G,
ctx: &mut CodeGenContext<'ctx, '_>,