Shop OBEX P1 Docs P2 Docs Learn Events
From BST to Flexspin for Prop1 Is #define #ifdef etc working in Flexspin? — Parallax Forums

From BST to Flexspin for Prop1 Is #define #ifdef etc working in Flexspin?

Hi,

I just tried to move a bigger P1 SPIN code project from BST to Flexspin.
Following some discussion here

#define MYSYMBOL
#ifdef MYSYMBOL 
   do something
#endif

should also work in Flexspin -
not globally but at least locally in each file.
For me the compiler always complains about it.
Maybe its only working for the P2 ?
I grepped recursive the whole example spin code for the P1 of the
spin-tools/examples/P1
directory. No ...define.. found.

Markus

Comments

  • It should work.

    Please post a full example file and the exact error message you get, we can not read your mind.

  • RossHRossH Posts: 5,476

    I have never used FlexSpin, but one problem I had was that every Spin compiler (especially on the Propeller 1, where we had so many) supported a different set of preprocessor directives (or none at all).

    In the end, I produced a standalone preprocessor that is a modified version of the C preprocessor cpp which I called spp - you will find it in the Catalina distribution. The changes to cpp are minimal and are mostly to do with telling it how to deal with Spin style comments. I use it to preprocess all my Spin and PASM code, to allow me to just use the standard C style preprocessor directives everywhere, on both the Propeller 1 and 2.

    Ross.

  • Hi Würfel_21,

    446 '' Compiler Preferences  - Non Parallax Extensions muss bei BST gesetzt sein, sonst gehen die ifdefs nicht
    447 #define DE      '' EN or DE
    448 #define KOMMA  '' KOMMA or PUNKT
    449 '#undef HC
    450 #undef LINKSRUM  '' dreht Rad um siehe auch rad.spin 
    451 '#define LINKSRUM  '' dreht Rad um
    
    

    And below the error message. Unfortunately I was not able to copy the text from the message window.
    I have added the line numbers to the code.

    The SW is FlexProp 6.8.1 for Linux.

    Markus

  • Sorry, cut and paste of the compiler output window works (w/o changing the color during marking the text) - here the compiler output as text:

    "/home/markus/entw/flexprop/bin/flexspin" --interp=rom --tabs=8 -D_BAUD=115200 -l -O1 -Wall   --charset=parallax -I "/home/markus/entw/flexpropX/include"  "/linuxserver2/tesisneu/combit/entw/us01/Vikasonic_05082011/vikasonic.spin"
    Propeller Spin/PASM Compiler 'FlexSpin' (c) 2011-2024 Total Spectrum Software Inc. and contributors
    Version 6.8.1-HEAD-v6.8.1 Compiled on: Jan 21 2024
    /linuxserver2/tesisneu/combit/entw/us01/Vikasonic_05082011/vikasonic.spin:448: error: syntax error, unexpected identifier `KOMMA', expecting end of line or ','
    /linuxserver2/tesisneu/combit/entw/us01/Vikasonic_05082011/vikasonic.spin:450: error: syntax error, unexpected identifier `LINKSRUM', expecting end of line or ','
    vikasonic.spin
    |-ST7565READOGM128.spin
    child process exited abnormally
    Finished at Wed Mar  6 10:30:50 2024
    
    

    Markus

  • @RossH said:
    I have never used FlexSpin, but one problem I had was that every Spin compiler (especially on the Propeller 1, where we had so many) supported a different set of preprocessor directives (or none at all).

    In the end, I produced a standalone preprocessor that is a modified version of the C preprocessor cpp which I called spp - you will find it in the Catalina distribution. The changes to cpp are minimal and are mostly to do with telling it how to deal with Spin style comments. I use it to preprocess all my Spin and PASM code, to allow me to just use the standard C style preprocessor directives everywhere, on both the Propeller 1 and 2.

    Ross.

    Ross,
    many thanks for the spp hint. I will test it.
    As far as I have seen yesterday, also in the PropellerTool there are no #define...options possible.
    Would be a real important feature.
    Markus

  • @MGreim said:
    Hi Würfel_21,

    446 '' Compiler Preferences  - Non Parallax Extensions muss bei BST gesetzt sein, sonst gehen die ifdefs nicht
    447 #define DE      '' EN or DE
    448 #define KOMMA  '' KOMMA or PUNKT
    449 '#undef HC
    450 #undef LINKSRUM  '' dreht Rad um siehe auch rad.spin 
    451 '#define LINKSRUM  '' dreht Rad um
    
    

    That is infact not a full example file. However, my best guess is that your preprocessor commands are not at the beginning of the line. They need to be. No spaces or tabs in front.

  • Its strange.:
    There have been no spaces or tabs in front.
    But it seems that the compile don't like trailing whitespaces or comments.
    I re-arranged the sourcecode a little bit and now the compiler is not complaining anymore.
    Its silly because, the compiler is not complaining about the #undef line.

    #define DE
    '' EN oder DE
    
    #define KOMMA
    
    '#undef HC
    #undef LINKSRUM  '' dreht Rad um siehe auch rad.spin PRI pos0 wenn Drehrad andere Rastung hat
    '#define LINKSRUM  '' dreht Rad um
    
    
    

    Markus

  • I think that behavior changed sometime last year; I don't remember exactly when. It used to be acceptable. You can still use the inline { } style comments at the end of the line though, if I remember correctly.

  • @avsa242 said:
    I think that behavior changed sometime last year; I don't remember exactly when. It used to be acceptable. You can still use the inline { } style comments at the end of the line though, if I remember correctly.

    yep - curly brackets work!
    Thanks!

    Another problem:
    This code snippet below works fine in BST and also in PropellerTool:

         case ||(einheit // 3)
              0: grossezahl(messwert, string("&s"), string ("ms"),1)
              1: grossezahl(schallgeschwindigkeit(messwert), string("m/s"), string("km/s"),1)
              2: grossezahl(emodul(messwert), string("MPa"), string ("GPa"),1)
    
    
    

    flexsping complains about the case statement in line 1435 then the compiler gives up:
    Below the "post mortem dump"

    "/home/markus/entw/flexprop/bin/flexspin" --interp=rom --tabs=8 -D_BAUD=115200 -l -O1 -Wall   --charset=parallax -I "/home/markus/entw/flexpropX/include"  "/linuxserver2/tesisneu/combit/entw/us01/Vikasonic_05082011/vikasonic.spin"
    Propeller Spin/PASM Compiler 'FlexSpin' (c) 2011-2024 Total Spectrum Software Inc. and contributors
    Version 6.8.1-HEAD-v6.8.1 Compiled on: Jan 21 2024
    /linuxserver2/tesisneu/combit/entw/us01/Vikasonic_05082011/vikasonic.spin:1451: warning: variable schreibzeit may be used before it is set in function anzeige
    /linuxserver2/tesisneu/combit/entw/us01/Vikasonic_05082011/vikasonic.spin:1677: warning: variable myltcnv may be used before it is set in function eingabetemperatur
    /linuxserver2/tesisneu/combit/entw/us01/Vikasonic_05082011/jm_i2c.spin:449: warning: variable i2cbyte may be used before it is set in function read
    /linuxserver2/tesisneu/combit/entw/us01/Vikasonic_05082011/vikasonic.spin:1435: error: Unhandled assign left kind 5
    /linuxserver2/tesisneu/combit/entw/us01/Vikasonic_05082011/vikasonic.spin:1435: error: Internal error, no memopNode
    vikasonic.spin
    |-ST7565READOGM128.spin
    
    

    Markus

  • @MGreim said:

    @RossH said:
    I have never used FlexSpin, but one problem I had was that every Spin compiler (especially on the Propeller 1, where we had so many) supported a different set of preprocessor directives (or none at all).

    In the end, I produced a standalone preprocessor that is a modified version of the C preprocessor cpp which I called spp - you will find it in the Catalina distribution. The changes to cpp are minimal and are mostly to do with telling it how to deal with Spin style comments. I use it to preprocess all my Spin and PASM code, to allow me to just use the standard C style preprocessor directives everywhere, on both the Propeller 1 and 2.

    Ross.

    I fear there is a small problem in spp:
    it eleminates everything after // including the // itself.
    So in a comment:

    Diese ist die umbenannte Datei:         
    http://www.ftdichip.com/Firmware/Precompiled/VDAPFUL-V3.69.ftd         
    nicht die Extension .rom verwenden diese ist zum direkten programmieren des Chips.     
    
    

    become:

    Diese ist die umbenannte Datei:                                                                                      
    http:                                                                                                               
    nicht die Extension .rom verwenden diese ist zum direkten programmieren des Chips.  
    
    

    thats not so severe, but:

    case || (einheit // 3 ) become case || (einheit

    that is dangerous.

    Markus

  • Wuerfel_21Wuerfel_21 Posts: 5,105
    edited 2024-03-06 16:15

    @MGreim said:
    Another problem:
    This code snippet below works fine in BST and also in PropellerTool:

         case ||(einheit // 3)
              0: grossezahl(messwert, string("&s"), string ("ms"),1)
              1: grossezahl(schallgeschwindigkeit(messwert), string("m/s"), string("km/s"),1)
              2: grossezahl(emodul(messwert), string("MPa"), string ("GPa"),1)
    
    
    

    flexsping complains about the case statement in line 1435 then the compiler gives up:

    Markus

    Bug regarding the distinction of unary inline operators vs. unary assignment operators. Fix submitted: https://github.com/totalspectrum/spin2cpp/pull/432 . Will likely show up in 6.9.0, but if urgent, you can build the pull branch yourself or grab the CI artifacts at https://github.com/totalspectrum/spin2cpp/actions/runs/8175115539?pr=432

  • Thanks!

  • RossHRossH Posts: 5,476

    @MGreim said:

    @MGreim said:

    @RossH said:
    I have never used FlexSpin, but one problem I had was that every Spin compiler (especially on the Propeller 1, where we had so many) supported a different set of preprocessor directives (or none at all).

    In the end, I produced a standalone preprocessor that is a modified version of the C preprocessor cpp which I called spp - you will find it in the Catalina distribution. The changes to cpp are minimal and are mostly to do with telling it how to deal with Spin style comments. I use it to preprocess all my Spin and PASM code, to allow me to just use the standard C style preprocessor directives everywhere, on both the Propeller 1 and 2.

    Ross.

    I fear there is a small problem in spp:
    it eleminates everything after // including the // itself.

    Thanks. I'll check that. It's possible I didn't disable the C style comments, just added the Spin style ones.

  • RossHRossH Posts: 5,476

    @RossH said:

    @MGreim said:

    @MGreim said:

    @RossH said:
    I have never used FlexSpin, but one problem I had was that every Spin compiler (especially on the Propeller 1, where we had so many) supported a different set of preprocessor directives (or none at all).

    In the end, I produced a standalone preprocessor that is a modified version of the C preprocessor cpp which I called spp - you will find it in the Catalina distribution. The changes to cpp are minimal and are mostly to do with telling it how to deal with Spin style comments. I use it to preprocess all my Spin and PASM code, to allow me to just use the standard C style preprocessor directives everywhere, on both the Propeller 1 and 2.

    Ross.

    I fear there is a small problem in spp:
    it eleminates everything after // including the // itself.

    Thanks. I'll check that. It's possible I didn't disable the C style comments, just added the Spin style ones.

    Yes, as I thought - I had not disabled the processing of C style comments in spp because I didn't realize // could also be a Spin operator.

    I will do some more testing before releasing an update.

    Ross.

Sign In or Register to comment.