Shop Learn
flexspin compiler for P2: Assembly, Spin, BASIC, and C in one compiler - Page 83 — Parallax Forums

flexspin compiler for P2: Assembly, Spin, BASIC, and C in one compiler

17980818385

Comments

  • ersmithersmith Posts: 4,904

    At the moment there's probably not very much you can do to reduce COG usage. Breaking large functions/subroutines up into smaller ones might help, and of course if you have any code explicitly placed in COG you should move it to LUT or HUB. I'm working on making the COG space used selectable via the --fcache option, which will make it possible to tweak the space for your application.

  • ersmithersmith Posts: 4,904

    @JRoark : I've posted an updated beta on Patreon that has a smaller default for the FCACHE area (so more COG ram available) and also the ability to specify a different the FCACHE area size on the command line.

  • @ersmith said:
    @JRoark : I've posted an updated beta on Patreon that has a smaller default for the FCACHE area (so more COG ram available) and also the ability to specify a different the FCACHE area size on the command line.

    Awesome! I’ll see how she flies in a bit. Thanks, Eric.

  • @ersmith Live code testing will have to wait until tomorrow (the bleeping cat ate my USB cable), but I've been playing with the compiler today sans download capability and have some things to report:

    1. The problem I had with any/all optimization levels has been fixed. No more errors.
    2. The long-standing problem I had where -O2 (full optimization) broke the compiler when used on large .BAS files is cured! SWEET!!

    I also discovered some "hidden" gems that are not documented in the FlexBASIC doc, but appear to work are look to be deriviatives of functions found in the general compiler docs. They are:

    • WAITX(x) is an undocumented alias of WAITCNT(x)
    • WAITMS(x) is an undocumented alias of DELAYMS(x)
    • WAITUS(x) is an undocumented alias of DELAYUS(x)
    • COGCHK(x) is an undocumented alias of CPUCHK(x)
  • RS_JimRS_Jim Posts: 1,463

    @ersmith Live code testing will have to wait until tomorrow (the bleeping cat ate my USB cable), but I've been playing with the compiler today sans download capability and have some things to report:@ersmith Live code testing will have to wait until tomorrow (the bleeping cat ate my USB cable), but I've been playing with the compiler today sans download capability and have some things to report:

    Is that like the dog ate my homework?
    Jim

  • @RS_Jim said:
    Is that like the dog ate my homework?
    Jim

    Lol. Yep, pretty much. Except this is a 500 lb gully cat who answers to “Satan”.
    Warning: thread drift. :)

  • RaymanRayman Posts: 12,032
    edited 2021-04-24 14:49

    @ersmith Should C defines act line Spin2 constants in included .spin2 files?

    I tried this:
    #define VGA_BASEPIN 48

    But, it says unknown symbol, so I'm guessing this doesn't work... Should/Can it?

    Not a big deal either way. Just thought it would work...

  • ersmithersmith Posts: 4,904

    @Rayman said:
    @ersmith Should C defines act line Spin2 constants in included .spin2 files?

    I tried this:
    #define VGA_BASEPIN 48

    But, it says unknown symbol, so I'm guessing this doesn't work... Should/Can it?

    No, for several reasons:

    (1) Objects created in C with "struct __using" are like objects created with OBJ in Spin2. The constants in the top level file don't go down into the sub-objects; similarly, constants in the C file don't go into the objects either.

    (2) #define is actually even weaker than constants in CON. A #define creates a macro where every occurance of the symbol is replaced with the text after it. So after
    #define VGA_BASEPIN 48the result is literally as if you did a search-and-replace inside the .c file and replaced every instance of VGA_BASEPIN with 48. It's a text substitution only, and only works within that specific file.

  • @ersmith said:
    @deets : the version in github now has support for DEBUG_BAUD.

    Sorry for the delay, but I'm a bit too knackered under the week to get to my playtime stuff. But I just verified - works as advertised, thanks for the quick implementation! It seems the default is 230400, pnut allegedly uses 2_000_000. Just FYI if congruence is relevant to you here. Or the spin doc is wrong :)

  • @ersmith On the subject of suggestions, I have two for your consideration:

    1. The predefined symbol __FLEXBASIC__ is defined as the compiler version (currently "5"). Could we change this (or create a new symbol) that includes the major, minor, revision, (ie, "5.4.0")?
    2. Would it be possible to have another predefined symbol that contains the host date/time when the file was compiled? Something like Sun 25Aug2021 12:34:56 or whatever format the standard C language uses?
  • ersmithersmith Posts: 4,904
    edited 2021-04-26 12:58

    @JRoark : Those sound like good ideas, thanks. To get all 4 components of the version into the symbol it'll have to be a string rather than an integer, so I think I'll make a new symbol __FLEXBASIC_VERSION__ for that.

    EDIT: Looks like there's already a __VERSION__symbol defined. I guess I forgot to document that, I'll add it to the manual.

  • RaymanRayman Posts: 12,032

    Should things like _rnd() also be in the manual? Or, should there be Propeller2.h manual that is separate?

    I was also thinking about getting the time in there somehow... Maybe better with loadp2? Was thinking about an easy way to initialize a real time clock...

  • ersmithersmith Posts: 4,904

    Yes, _rnd() should be documented. There's probably quite a lot of stuff missing from the documentation, sorry. Although I'm always happy to accept pull requests :).

    As for time, not sure what the best approach to that is. Probably a new function call that communicates with the host via loadp2 to get the time, something like the existing file server. Is that the kind of thing you were thinking of?

  • RaymanRayman Posts: 12,032
    edited 2021-04-26 20:41

    Maybe Plan9 provides time already? If not directly, maybe I could create a new dummy file and then get the time from that file stats?

  • ersmithersmith Posts: 4,904

    @Rayman said:
    Maybe Plan9 provides time already? If not directly, maybe I could create a new dummy file and then get the time from that file stats?

    You're right, if you create a dummy file on the host and then do a stat() on it you could get the time that way. That's a nice idea, and saves having to add anything to loadp2.

  • TonyB_TonyB_ Posts: 1,728

    Could FlexSpin please support/tolerate a colon at the end of a label?

    One could then search for routine: without matching all the call #routine

  • ersmithersmith Posts: 4,904
    edited 2021-04-27 12:45

    @TonyB_ said:
    Could FlexSpin please support/tolerate a colon at the end of a label?

    One could then search for routine: without matching all the call #routine

    PNut doesn't support this though, does it? I'm reluctant to introduce more incompatibilities with PNut, especially in the assembly language.

    One work-around would be to use a capital letter in the actual label definition (like Routine) and lower case in the uses (call #routine). Spin is case insensitive, so this should work in all assemblers.

  • TonyB_TonyB_ Posts: 1,728
    edited 2021-05-01 10:32

    @ersmith said:

    @TonyB_ said:
    Could FlexSpin please support/tolerate a colon at the end of a label?

    One could then search for routine: without matching all the call #routine

    PNut doesn't support this though, does it? I'm reluctant to introduce more incompatibilities with PNut, especially in the assembly language.

    One work-around would be to use a capital letter in the actual label definition (like Routine) and lower case in the uses (call #routine). Spin is case insensitive, so this should work in all assemblers.

    Is colon a valid character in a PASM2 label, in either PNut or FlexSpin? I can't run PNut and I need to use FlexSpin anyway as #include is vital.

    Changing the subject, is it possible to concatenate binary constants? E.g. if a = %1011 and b = %0010 can I combine a and b to get %10110010? This would be very handy for skip pattern bits.

  • ersmithersmith Posts: 4,904

    @TonyB_ said:
    Changing the subject, is it possible to concatenate binary constants? E.g. if a = %1011 and b = %0010 can I combine a and b to get %10110010? This would be very handy for skip pattern bits.

    a and b are stored as 32 bit values internally, so leading 0's are lost. So no, you can't concatenate them, because once they're parsed there's no way to know how wide they're "supposed" to be.

  • RaymanRayman Posts: 12,032

    Is there a way to access the values of an enum that is inside a structure in C?

    I'm trying to replicate the way you this in Spin for CON values in a Spin object...

  • @Rayman ,

    enum become defines so there use is just the value that is assigned.

    enum {
    five = 5,
    six,
    seven,
    eight,
    twelve = 12,
    thirteen,
    fourteen,
    fifteen
    } whatever;

    Mike

  • RaymanRayman Posts: 12,032
    edited 2021-05-20 15:48

    I'm trying to replicate an I2C Spin code in C like this:

    typedef struct I2C_Port
    {//I2C port instance
        enum PullupOptions { PU_NONE, PU_1K5, PU_3K3, PU_15K };
        enum AckOrNak { ACK, NAK }; //I2C responses
    

    There doesn't seem to be a way to get to the PullupOptions values from outside the structure...
    Was thinking this would work:
    i2c_Port::PU_15K

    But it doesn't...

    I could leave them outside the structure, but it would be cleaner if they were inside...

  • RaymanRayman Posts: 12,032
    edited 2021-05-20 16:01

    I guess the above usage is C++ an so not going to work here...

    Looks like inline assembly doesn't work inside a structure. Have to see if I can work around that...

  • RaymanRayman Posts: 12,032

    Ok, maybe the above idea is just not a good idea...

    Instead of making an I2C code structure, I'll do what other C I2C codes I've seen do and create a structure that just has port specific things like timing and pin #s in it.

    That should make everything work better.

  • RaymanRayman Posts: 12,032

    Not sure if this is a bug or not...

    Using the $-1 like this in inline assembly doesn't seem to work
    if_nc jmp $-1

  • ersmithersmith Posts: 4,904

    @Rayman said:
    I guess the above usage is C++ an so not going to work here...

    Yes, in C enums are always global, this is part of the language spec so I can't change it. In C++ they can be part of classes though, and flexspin will use that semantics if the file ends in ".cpp" or ".c++"; then they can be accessed by something like "x.THE_CONSTANT".

    Looks like inline assembly doesn't work inside a structure. Have to see if I can work around that...

    Seems to work for me. Here's foo.cpp which compiles and runs:

    class pin {
      int thepin;
      enum { DFLTPIN = 56, DFLTPIN2 = 57 };
      void outlo() {
        int x = thepin;
        __asm {
          drvl x
        }
      }  
      void outhi() {
        int x = thepin;
        __asm {
          drvh x
        }
      }
      void setpin(int x) {
        thepin = x;
      }
      int getpin() { return thepin; }
    } c;
    
    int main()
    {
      c.setpin(c.DFLTPIN);
      for(;;) {
        c.outlo();
        _waitx(20_000_000);
        c.outhi();
        _waitx(20_000_000);
      }
      return 0;
    }
    
  • RaymanRayman Posts: 12,032

    Thanks. I see now that I should have given that file a ".cpp" or ".c++" extension and used "class" instead of "struct" for converting a Spin object...
    But, I think I'm happy with the way it worked out doing it the C way...

    Your example works for me too, guess I did something wrong.

  • @Rayman said:
    [...] and used "class" instead of "struct" for converting a Spin object...

    Not sure how FlexC does it, but in standard C++, you can use either struct or class, the only difference is the default visibility of members (public for struct, private for class).

  • RaymanRayman Posts: 12,032

    Thanks @Wuerfel_21 , I suppose "struct" would be better for Spin conversions then.

  • Dave HeinDave Hein Posts: 6,298
    edited 2021-05-20 19:32

    @Rayman said:
    Not sure if this is a bug or not...

    Using the $-1 like this in inline assembly doesn't seem to work
    if_nc jmp $-1

    I don't know the rules for inline assembly, but in normal assembly you need to used the "#" character for the jmp target. Also, you would use "jmp #$-1" to jump back to the previous instruction for cog code, and "jmp #$-4" for hub code. I'm guessing that inline assembly generates hub code.

Sign In or Register to comment.