Menu ▾ ▴

#312 Additional Preprocessor command

open
nobody
2020-11-09
2019-12-17
No

I know that the preprocessor has the capability of evaluating a constant expression because it does it on the #IF command.

Therefore I would like to see a command like:

EQU name constant expression

the result of this command would be to create a #define name with either the value of the string expression specified or the STR(numeric expression). In addition if name exists, then replace the current value of name with the value of the expression.

So.

EQU a a+1

would replace the #define name "a" with the current value of a+1

This would be great in creating unique variable/label names. Or keep track of the next location in an array. It would make creating complex data structures at compile time a lot easier. All this done at compile time.

Related

Feature Requests: #312

Discussion

  • Jeff Marshall

    Jeff Marshall - 2020-11-09

    In fbc-1.08 can kind of do this. Not quite as nice as the proposed EQU sym expr syntax though. In this example, symbol name has to be quoted otherwise it gets replaced with the value of the symbol. EQU( "sym", expr )

    #macro do_undef( sym )
        __FB_UNQUOTE__( __FB_EVAL__( "#undef " + sym ) )
    #endmacro
    
    #macro do_define( sym, expr )
        __FB_UNQUOTE__( __FB_EVAL__( "#define " + sym + " " + __FB_QUOTE__( __FB_EVAL__( expr ) ) ) )
    #endmacro
    
    #macro EQU( sym, expr )
        do_undef( sym )
        do_define( sym, expr )
    #endmacro
    
    EQU( "a", 1 )
    print a
    
    EQU( "a", a+1 )
    print a
    
    EQU( "a", a+1 )
    print a
    
    EQU( "s", "hello" )
    print s
    
    EQU( "s", s + " world"  )
    print s
    
     

    Last edit: Jeff Marshall 2020-11-09
  • Wally Gazdzik

    Wally Gazdzik - 2020-11-09

    Thank you very much.

    Wally

    On November 8, 2020, at 7:13 PM, Jeff Marshall jeffmarshall@users.sourceforge.net wrote:

    In fbc-1.08 can kind of do this. Not quite as nice as the proposed EQU sym expr syntax though. In this example, symbol name has to be quoted otherwise it gets replaced with the value of the symbol. EQU( "sym", expr )

    #macro do_undef( sym ) 
    __FB_UNQUOTE__( __FB_EVAL__( "#undef " + sym ) ) 
    #endmacro 
    #macro do_define( sym, expr ) 
    __FB_UNQUOTE__( __FB_EVAL__( "#define " + sym + " " + __FB_QUOTE__( __FB_EVAL__( expr ) ) ) ) 
    #endmacro 
    #macro EQU( sym, expr ) 
    do_undef( sym ) 
    do_define( sym, expr ) 
    #endmacro 
    
    EQU( "a", 1 ) 
    print a 
    EQU( "a", a+1 ) 
    print a 
    EQU( "a", a+1 ) 
    print a 
    EQU( "s", "hello" ) 
    print s EQU( "s", s + " world" ) 
    print s 
    

    [feature-requests:#312] Additional Preprocessor command

    Status: open
    Labels: preprocessor
    Created: Tue Dec 17, 2019 05:35 AM UTC by Wally Gazdzik
    Last Updated: Tue Dec 17, 2019 05:35 AM UTC
    Owner: nobody

    I know that the preprocessor has the capability of evaluating a constant expression because it does it on the #IF command.

    Therefore I would like to see a command like:

    EQU name constant expression

    the result of this command would be to create a #define name with either the value of the string expression specified or the STR(numeric expression). In addition if name exists, then replace the current value of name with the value of the expression.

    So.

    EQU a a+1

    would replace the #define name "a" with the current value of a+1

    This would be great in creating unique variable/label names. Or keep track of the next location in an array. It would make creating complex data structures at compile time a lot easier. All this done at compile time.

    Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/fbc/feature-requests/312/

    To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

     

    Related

    Feature Requests: #312


    Last edit: Jeff Marshall 2020-11-09

Log in to post a comment.