bugmake - Bugs: bug #47421, Add support for doing plugin macro...

 
 

bug #47421: Add support for doing plugin macro overloading

Submitter:  Brian Vandenberg <phantal>
Submitted:  Tue 15 Mar 2016 04:30:57 PM UTC
   
 
Severity:  3 - Normal Item Group:  Enhancement
Status:  None Privacy:  Public
Assigned to:  None Open/Closed:  Open
Component Version:  4.1 Operating System:  Any
Fixed Release:  None Triage Status:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 15 Mar 2016 04:35:52 PM UTC, comment #1: 

I forgot to say this w/regard to the code snippets: the spots where I'm registering the same macro name is what I want to be able to do, whereas the makefile snippet is workable albeit with a single function with a fair amount of conditional logic.

Brian Vandenberg <phantal>
Tue 15 Mar 2016 04:30:57 PM UTC, original submission:  

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})) \
))


Brian Vandenberg <phantal>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by phantal (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    No changes have been made to this item

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code