Shop OBEX P1 Docs P2 Docs Learn Events
FlexBASIC request: STOP — Parallax Forums

FlexBASIC request: STOP

@ersmith Any chance of implementing STOP in FlexBASIC? I am longing for this feature for debugging. All it would need to do is stop further execution on the cog that calls it after printing a message like "STOP encountered in /module/routine/line" to the console. After that, it enters into an endless DO:LOOP. All other cogs would remain unaffected.

STOP encountered at line 534 in GPSLIB.BAS/GetWayPoint()

Maybe optionally pass it a message to print too?

STOP encountered at line 534 in GPSLIB.BAS/GetWayPoint()   MSG: Too many waypoints

What thinks ye?

Comments

  • In C you could easily just define that as a macro. Not sure if the BASIC preprocessor is powerful enough.

  • @Wuerfel_21 said:
    In C you could easily just define that as a macro. Not sure if the BASIC preprocessor is powerful enough.

    I'm not aware that FlexBASIC "knows" about macros at all. But macros would be a cool capability now that you mention it... :)

  • Infact, yes, you can create such a STOP command as a macro:

    #DEFINE STOP PRINT "STOP @",__FILE__,"LINE",__LINE__
    
  • @Wuerfel_21 said:
    Infact, yes, you can create such a STOP command as a macro:

    #DEFINE STOP PRINT "STOP @",__FILE__,"LINE",__LINE__
    

    Well I’ll be a monkey’s step-uncle! I had no idea. Is this even in the docs? Gotta try this when I get home. Thanks @Wuerfel_21

  • The preprocessor is documented in the FlexBASIC manual, but the full implications (including that yes, things like @Wuerfel_21 's macro are possible) may not be immediately obvious.

  • I finally got home and was able to play with this. New toys! The only "gotcha" is anything defined by #DEFINE seems to be case sensitive, and the BASIC language by default is not. So:

    #DEFINE STOP PRINT "STOP @",__FILE__,"LINE",__LINE__
    stop
    

    will fail, but...

    #DEFINE STOP PRINT "STOP @",__FILE__,"LINE",__LINE__
    STOP
    

    ...works a treat. Thanks for the heads-up @Wuerfel_21 and @ersmith.

  • @JRoark Maybe then you could create two #DEFINES, one for "STOP" and one for "stop"...so you can use either

    #DEFINE STOP PRINT "STOP @",__FILE__,"LINE",__LINE__
    #DEFINE stop PRINT "STOP @",__FILE__,"LINE",__LINE__
    
  • Wuerfel_21Wuerfel_21 Posts: 4,462
    edited 2021-10-10 08:36

    @rogloh said:
    @JRoark Maybe then you could create two #DEFINES, one for "STOP" and one for "stop"...so you can use either

    #DEFINE STOP PRINT "STOP @",__FILE__,"LINE",__LINE__
    #DEFINE stop PRINT "STOP @",__FILE__,"LINE",__LINE__
    

    Don't Repeat Yourself...

    #DEFINE STOP PRINT "STOP @",__FILE__,"LINE",__LINE__
    #DEFINE stop STOP
    

    Also, I just noticed the "slight problem" that __LINE__ doesn't actually evaluate the line that the macro is instantiated on, but the line that it is defined on, I think that's a bug.

  • Ouch! The LINE macro is being expanded at the wrong place. I'll have to look into that.

Sign In or Register to comment.