URL: <http://savannah.gnu.org/bugs/?47421>
Summary: Add support for doing plugin macro overloading Project: make Submitted by: phantal Submitted on: Tue 15 Mar 2016 04:30:57 PM GMT Severity: 3 - Normal Item Group: Enhancement Status: None Privacy: Public Assigned to: None Open/Closed: Open Discussion Lock: Any Component Version: 4.1 Operating System: Any Fixed Release: None Triage Status: None _______________________________________________________ Details: As a preface: I recognize that what I outline below could be done in other ways with existing make syntax. I'm not interested in suggestions for alternative ways to get similar results. ---- I had a situation arise a few weeks ago where I had wanted to be able to do macro overloading. I was experimenting with adding support for namespace-scoped variables. I had originally written it as one function (each namespace was registered to the same function) but its execution time was rather high. I tested its expansion time with another macro I wrote for repeatedly expanding expressions to see the avg/std of the expansion time. I had thought the problem might be the conditional logic. As a test I broke it up into separate macros with different names and it improved performance by an order of magnitude, but it was syntactically awkward because I needed a separate macro name for listing, setting, and getting as opposed to the more concise example below. I'm using C++14 with gnu extensions for my plugin, but the syntax should make it obvious what I'm doing. Here's a sketch of what I had going: extern "C" { #include <gnumake.h> } using plugin_function_t = typeof(*gmk_func_ptr()); plugin_function_t namespace_list; plugin_function_t namespace_add; plugin_function_t variable_list; plugin_function_t variable_getter; plugin_function_t variable_setter; /*...*/ gmk_add_function( gmk_api::strdup( "namespace" ), namespace_list, 0, 0, GMK_FUNC_DEFAULT ); gmk_add_function( gmk_api::strdup( "namespace" ), namespace_add, 1, 1, GMK_FUNC_DEFAULT ); /*...*/ gmk_add_function( gmk_api::strdup( argv[0], variable_list, 0, 0, GMK_FUNC_DEFAULT ); gmk_add_function( gmk_api::strdup( argv[0], variable_getter, 1, 1, GMK_FUNC_DEFAULT ); gmk_add_function( gmk_api::strdup( argv[0], variable_setter, 2, 2, GMK_FUNC_DEFAULT ); ... where it could be used like this: $(namespace asdf) $(namespace fdsa) $(asdf name1, value1) $(asdf name2, value2) $(asdf name3, value3) $(fdsa name1, value1) $(fdsa name2, value2) $(fdsa name3, value3) $(info Namespaces: $(namespace )) $(foreach x,\ $(namespace ) \ , $(foreach y,\ $(${x} ) \ , $(info In namespace ${x}, variable ${y} = $(${x} ${y})) \ )) _______________________________________________________ Reply to this item at: <http://savannah.gnu.org/bugs/?47421> _______________________________________________ Message sent via/by Savannah http://savannah.gnu.org/ _______________________________________________ Bug-make mailing list Bug-make@gnu.org https://lists.gnu.org/mailman/listinfo/bug-make