Shop OBEX P1 Docs P2 Docs Learn Events
SX/B 2.00.28 Beta now supports nested Conditional Compile Directives — Parallax Forums

SX/B 2.00.28 Beta now supports nested Conditional Compile Directives

BeanBean Posts: 8,129
edited 2009-12-24 09:28 in General Discussion
I can't remember who asked for this feature...I think is was Peter ???

But I have implemented it, so I'd like you guys to give it a good test case.

Here is what I used to test it:


DEVICE SX28, OSC4MHZ
FREQ 4_000_000
 
temp1   VAR BYTE
 
 PROGRAM Start NOSTARTUP
 
  Start:
  ' This three defines TEST0, TEST1 and TEST2 determine which of the seven FOR statements are compiled
 
  '{$UNDEFINE TEST2}
  '{$DEFINE TEST1}
  '{$DEFINE TEST0}
 
  '{$IFNDEF TEST2}
    '{$IFNDEF TEST1}
      '{$IFNDEF TEST0}
        FOR temp1 = 0 TO 255
      '{$ELSE}
        FOR temp1 = 1 TO 255
      '{$ENDIF}
    '{$ELSE}
      '{$IFNDEF TEST0}
        FOR temp1 = 2 TO 255
      '{$ELSE}
        FOR temp1 = 3 TO 255
      '{$ENDIF}
    '{$ENDIF}
  '{$ELSE}
    '{$IFNDEF TEST1}
      '{$IFNDEF TEST0}
        FOR temp1 = 4 TO 255
      '{$ELSE}
        FOR temp1 = 5 TO 255
      '{$ENDIF}
    '{$ELSE}
      '{$IFNDEF TEST0}
        FOR temp1 = 6 TO 255
      '{$ELSE}
        FOR temp1 = 7 TO 255
      '{$ENDIF}
    '{$ENDIF}
  '{$ENDIF}
 
  NEXT
 
END


Bean


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The needy are many, the deserving are few.

·

Comments

  • RS_JimRS_Jim Posts: 1,768
    edited 2009-07-13 12:55
    Thanks Bean,
    I will download and install later today! I recently was trying to do some stuff where nested compiler directives would have been very nice!
    RS_JIM
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2009-07-13 17:34
    Bean,

    Nested conditionals were already possible, but the condition was reset
    upon first $endif.
    I assume that is no longer the case and we have truly nested conditionals now.

    regards peter
  • BeanBean Posts: 8,129
    edited 2009-07-13 17:37
    Peter,
    Yes, they should be honest and truly nest-able now.

    The example program I show above will only generate a single FOR line depending on if TEST0, TEST1 and TEST2 are defined or undefined.

    Let me know if you get a chance to test it.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    The needy are many, the deserving are few.

    ·
  • BeanBean Posts: 8,129
    edited 2009-07-14 11:49
    Just wondering if anyone has had a chance to test 2.00.28 yet ?

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Does that byte of memory hold "A", 65, $41 or %01000001 ?
    Yes it does...


    ·
  • RS_JimRS_Jim Posts: 1,768
    edited 2009-07-14 15:09
    Haven't tested all of the features, but it has worked perfectly on everything I done with it so far.
    I will be trying some of the nested conditional directives later today, will let you know how they work!
    RS_JIM
  • CounterRotatingPropsCounterRotatingProps Posts: 1,132
    edited 2009-07-14 17:47
    Thanks Bean - nice improvement!
    I'll try it out over the next weeks.
    - Howard

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • RS_JimRS_Jim Posts: 1,768
    edited 2009-07-25 04:38
    @Bean,
    The following does not compile correctly:
    '
    ' Conditional Compilation Symbols
    '
    '{$DEFINE SERIAL}
    '

    '

    '
    ' INTERRUPT
    '
    '
    '{$IFDEF SERIAL}

    INTERRUPT NOPRESERVE 230_400
    '{$ELSE}
    INTERRUPT NOPRESERVE 100_000
    '{$ENDIF}
    '
    All of my other conditionals compile correctly including a nested one
    '{$IFDEF SERIAL}
    '{$IFDEF LCD_DSP}

    '{$ELSE }

    '{$ENDIF}
    IT Tries to use both interupt rates and the assemblier complains about overwriting the same program location. I can also tell from the __INTOPTION that it is picking up the second value (10,000) as it equats __INTOPTION to $80 not $88. If I don't use the conditional and just comment out the interupt option I don't want, it compiles/assembles correctly. I have conditionals burried in the interupt load file and that is working correctly.
    RS_JIM

    '{$ENDIF}
  • BeanBean Posts: 8,129
    edited 2009-07-25 15:01
    Jim,
    Could you post the entire program.
    I tried this and it seem to work properly.

    DEVICE SX28,OSCXT2
    FREQ 20_000_000
     
    ' -------------------------------------------------------------------------
    ' Conditional Compilation Symbols
    ' -------------------------------------------------------------------------
    '{$DEFINE SERIAL}
    ' -------------------------------------------------------------------------
    ' INTERRUPT
    ' -------------------------------------------------------------------------
    '{$IFDEF SERIAL}
    INTERRUPT NOPRESERVE 230_400
    '{$ELSE}
    INTERRUPT NOPRESERVE 100_000
    '{$ENDIF} 
    ' -------------------------------------------------------------------------
    RETURNINT
     
    PROGRAM Start
     
    Start:
    END
    


    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Does that byte of memory hold "A", 65, $41 or %01000001 ?
    Yes it does...


    ·
  • RS_JimRS_Jim Posts: 1,768
    edited 2009-07-26 13:28
    @Bean

    Thanks for checking.· Problem was with a redundant declaration of the program ID!

    RS_JIM
  • BrooksLBrooksL Posts: 17
    edited 2009-11-19 19:11
    I'm having·frustrating trouble with the conditional compile directives while porting our BS2px code to SX28AC with SX/B (need speed and interrupts).·

    I find it very confusing and odd that the syntax for these directives starts with the· '· comment delimiter.· Does that mean these lines can't be commented-out??· Using '' <-- that's two '· does not seem to work; the conditional compile is taken regardless.··· And, I must admit that I'm curious about the reason for implementing these this way.

    example:

    '{$DEFINE Bluetooth}······························ 'compile Bluetooth code if defined (true)
    ''{$DEFINE COMport}································ 'compile serial port I/O if defined (true)
    '{$DEFINE EnFilter}······························· 'enable digital filtering of sample data
    ''{$DEFINE DebugMode}······························ 'compile debug statements if defined (true)
    ''{$DEFINE DualAxis}·

    I could see changing DEFINE to unDEFINE, but it gets more difficult if I want to comment out the IFDEF...ELSE...ENDIF's

    Got·any helpful guidance?
    -- BrooksL
  • BrooksLBrooksL Posts: 17
    edited 2009-11-19 19:25
    Bean asked "...if anyone has had a chance to test 2.00.28 yet ?"

    What does that version number refer to? SX/B compiler version?

    Is SX/B 1.51.03 no longer the latest?

    --BrooksL
  • JonnyMacJonnyMac Posts: 9,212
    edited 2009-11-19 23:39
    Brooks,

    We moved past 1.5x a long time ago -- but you have to install it manually (the IDE installer hasn't been updated with the 2.x files). You can find what you need in a sticky post at the top of the SX forum.

    You cannot "comment out" conditional directives -- you can modify the define directive to turn things on and off. I tend to do things like this:

    ' {$DEFINE DEBUGGING}

    ...and when I want it off I change it to:

    ' {$DEFINE DEBUGGING_OFF}
  • BrooksLBrooksL Posts: 17
    edited 2009-11-20 00:26
    Thanks Jonny; where do I get the current SX/B compiler - AND documentation? I only saw 1.51 on the Parallax SX web page.

    I use conditional compile directives a lot for feature options. This ' comment delimter in the SX/B directive syntax is creating an annoyance for the porting of other code. ...and I can forsee it causing possible future difficulty.

    Today for example, I finally spotted '{$IF ... } instead of '{$IFDEF ... } and '{$IF ... } appears as a comment to the SX/B compiler so it fails to generate a syntax error!? That took hours to notice - as will any others that get in there!
    -- Brooks
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2009-11-20 02:01
    It's hiding here at the top of the SX Forum --

    http://forums.parallax.com/showthread.php?p=780347
  • PJMontyPJMonty Posts: 983
    edited 2009-11-20 02:27
    The IDE hasn't been updated because S/B is still in Beta. When SX/B comes out of Beta, then the IDE will be updated.

    Thanks,
    PeterM
  • BrooksLBrooksL Posts: 17
    edited 2009-11-20 03:07
    JohnnMac suggested:

    ' {$DEFINE DEBUGGING}

    ...and when I want it off I change it to:

    ' {$DEFINE DEBUGGING_OFF}

    ---
    The confusion comes in that with the ' comment delimiter, you can change it to just about anything:
    '{$DEFINE DEBUGGING_OFF} or
    '{$UNDEFINE DEBUGGING} or
    '{$NODEFINE DEBUGGING} or
    '{$STOPDEF DEBUGGING} or
    '{$DEF DEBUGGING} ....

    All but the first has the same effect and the compiler won't check or enforce a standard syntax with error messages - because they look like comments. :-/ More dangerous; what if you have a define (or any) directive like '{$DEFINE DEBUGGING} or {$DEFINE DEBUGGING} floating somewhere in a real 'comment statement - wil lthe compiler process it as a valid directive??

    ...Since SX/B 2.x is in beta... can this ' issue be "fixed" before release? - not just because it's bugging me right now (obviously, I'll have to work around it for the time being), but because there seems to be a lot of potential problems with it.

    -- BrooksL
  • ZootZoot Posts: 2,227
    edited 2009-11-20 04:54
    BrooksL said...
    More dangerous; what if you have a define (or any) directive like '{$DEFINE DEBUGGING} or {$DEFINE DEBUGGING} floating somewhere in a real 'comment statement - wil lthe compiler process it as a valid directive??

    No, they will not.

    '{$DEFINE XYZ}
    above means XYZ is defined (true)

    ''{$DEFINE XYZ}
    not defined

    ' { $DEFINE XYZ}
    not defined

    etc.

    Not sure what the issue is? Rather then even "undefining" I would just comment out the define, e.g.

    '{$DEFINE debugging}
    '{$IFDEF debugging}
      'lots of code  that will compile
    '{$ENDIF}
    
    



    ''{$DEFINE debugging}
    '{$IFDEF debugging}
      'lots of code  that will NOT compile
    '{$ENDIF}
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • JonnyMacJonnyMac Posts: 9,212
    edited 2009-11-20 05:07
    I stand corrected; thanks Zoot; I will "comment out" future directives when needed.
  • BrooksLBrooksL Posts: 17
    edited 2009-11-20 05:45
    Thanks, Zoot. my initial assesment was clouded by having '{IF ... } instead of '{IFDEF ... } and not having the compiler catch it as a syntax error - because it looks like a 'comment due to the ' - my tests of '{DEFINE ... } and ''{DEFINE ... } both appeared to have the effect of making the variable true.

    Thanks for listening. And, it sure would be nice if conditional compile directives were recognized as regular keyword syntax...
  • BrooksLBrooksL Posts: 17
    edited 2009-12-23 23:49
    Newbie question: is there a way to use the virtual peripherals with SX/BASIC?

    I'm hoping the answer is yes and that there's some guidance somewhere, but it's not obvious because I couldn't find an affirm or decline nor any mention in the SX/B manual.

    -- BrooksL
  • JonnyMacJonnyMac Posts: 9,212
    edited 2009-12-24 03:07
    @BrooksL: It's bad form to change the topic of a thread mid-stream. Start a new thread with an appropriate subject line. BTW... the answer is "Yes" -- get guidance by starting another thread.
  • BrooksLBrooksL Posts: 17
    edited 2009-12-24 09:28
    JonnyMac; oops, lost track of where I was posting; thought it was to the FAQ thread, but I'll start a new one.
    -- BrooksL
Sign In or Register to comment.