Shop OBEX P1 Docs P2 Docs Learn Events
flexspin compiler for P2: Assembly, Spin, BASIC, and C in one compiler - Page 101 — Parallax Forums

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

19899101103104121

Comments

  • RaymanRayman Posts: 14,553

    Can I build from source? Not sure, never tried... Does it compile with Visual Studio?

    I hope you found the problem. Think I've isolated it to this code in wizchip_conf.c:

    _WIZCHIP  WIZCHIP =
    {
        _WIZCHIP_IO_MODE_,
        _WIZCHIP_ID_ ,
        {
            wizchip_cris_enter,
            wizchip_cris_exit
        },
        {
            wizchip_cs_select,
            wizchip_cs_deselect
        },
        {
            {
                //M20150601 : Rename the function 
                //wizchip_bus_readbyte,
                //wizchip_bus_writebyte
                wizchip_bus_readdata,
                wizchip_bus_writedata
            },
    
        }
    };
    

    Is this the same thing you found?

  • evanhevanh Posts: 15,848
    edited 2022-11-08 14:36

    To compile flexspin from source I download the master zip file to a directory in Ubuntu - which has all the build tools ready to go - then open a shell in the unzipped spin2cpp directory that has the make file and:

    $ git pull; make clean; make
    

    and you're done. The new flexspin compiler is in build sub-directory and new include files are in include sub-directory.

  • @evanh said:
    To compile flexspin from source I download the master zip file to a directory in Ubuntu

    Why download the zip file manually when git clone https://github.com/totalspectrum/spin2cpp will do?

  • evanhevanh Posts: 15,848
    edited 2022-11-08 14:45

    Because I don't remember that line. It's been a long time since I did anything other than git pull for an update.

  • RaymanRayman Posts: 14,553

    I just installed Cygwin and ran make. Seemed to work, but the fastspin.exe it made needs some dlls to work. Copied all the cygwin dlls to flexprop bin folder. It runs, but can't find any of my sources include files.

  • Not sure if Cygwin is even properly supported. I'm pretty sure only MinGW actually is.

    May also be a case of the case-sensitive file names. Cygwin might have issues if the case doesn't match.


    Eitherhow, you can get prebuilt windows compiler binaries from the Github CI. It's a bit clunky to get to and you need to be logged in, but saves the hassle of having to set up a working build env:


    Click the most recent run that has the green checkmark and that says master

    Scroll down to the artifacts section and get the flexptools-git.zip. If you aren't logged in to github, it isn't clickable!

  • RaymanRayman Posts: 14,553

    @Wuerfel_21 Thanks! That's awesome.

    @ersmith All fixed! Thanks!

  • @Wuerfel_21 : I'd forgotten about the CI build, that's great.

    @Rayman : Thanks for checking this!

  • RaymanRayman Posts: 14,553
    edited 2022-11-08 18:04

    @ersmith This kind of initialization now seems to work:

    static wiz_NetInfo g_net_info =
    {
        .mac = {0x00, 0x08, 0xDC, 0x12, 0x34, 0x56}, // MAC address
        .ip = {192, 168, 1, 249},                     // IP address  192.168.1.2
        .sn = {255, 255, 255, 0},                    // Subnet Mask
        .gw = {192, 168, 1, 1},                      // Gateway
        .dns = {192, 168, 1, 1},                     // DNS server
        .dhcp = NETINFO_STATIC  //NETINFO_DHCP //RJA                      // DHCP enable/disable
    };
    

    Is this something you just fixed?

    Looking back, I think you said this was working in your tests.
    Guess something else was messing it up...

  • RaymanRayman Posts: 14,553

    @ersmith
    This other kind of initialization also seems to work now, but not 100% sure because it would break things in strange ways...

    static uint8_t g_ethernet_buf[ETHERNET_BUF_MAX_SIZE] = { 0, };

    I guess the idea is to just set the first element of the array to zero, like for an empty string.
    Is this now fixed as well?

  • I think all of the initializations should be working now. The root cause of all the problems was that the initialization code wasn't inserting padding between structure elements that needed it, so the data in memory was too short compared to what the coder expected.

  • RaymanRayman Posts: 14,553

    @ersmith Thanks! It's great to see this rather complex code working with FlexC.

  • @ersmith I found a bit of mischief in FlexBASIC. This "error" may just be some unimplemented 64-bit stuff, and if so ignore.
    With the current version compiler (Version 5.9.19) this swapping works fine:

        dim a, b as ulong
        a, b = b, a
    

    ... but this generates an error:

        dim a, b as ulongint
        a, b = b, a
    

    ... and the error is:

    error: Cannot handle memref of size 8
    error: Cannot handle memref of size 8
    D:/Flex2Gui/flexgui/swapvartest.bas:3: error: Too many elements on right hand side of assignment
    child process exited abnormally
    
  • RaymanRayman Posts: 14,553

    @ersmith Sorry to keep doing this to you...
    I tried adding the Wiznet ftp code and the main function there won't compile...

    This is the error:
    1>ftpd.c:783: error: Expected multiple values
    1>ftpd.c:811: error: Expected multiple values

    But, I think the compiler might be choking on this pretty large function...

  • RaymanRayman Posts: 14,553

    Think I figured out the problem...
    FlexC doesn't like this:

    /* Command table */
    static char* commands[10];
    = {
        "user",
        "acct",
        "pass",
        "type",
        "list",
        "cwd",
        "dele",
        "name",
        "quit",
        "retr",
        "stor",
        "port",
        "nlst",
        "pwd",
        "xpwd",
        "mkd",
        "xmkd",
        "xrmd",
        "rmd ",
        "stru",
        "mode",
        "syst",
        "xmd5",
        "xcwd",
        "feat",
        "pasv",
        "size",
        "mlsd",
        "appe",
        NULL
    };
    

    Think I'm able to work around by manually setting each value with line of code.

  • RaymanRayman Posts: 14,553
    edited 2022-11-13 20:36

    Also didn't like this:

    switch(cmdp - commands)

    and I don't blame it, fixed like this:

    switch((int)((int)cmdp - (int)commands))
    actually, like this:
    switch ((int)(cmdp - commands))

  • @JRoark and @Rayman : thanks for your bug reports, I'll have to look into them.

  • roglohrogloh Posts: 5,750
    edited 2022-11-15 08:10

    @ersmith said:
    @JRoark and @Rayman : thanks for your bug reports, I'll have to look into them.

    In addition to those, I just found that flexspin would not compile this (simple?) attached code and would just crash flexspin completely. You might like to determine why. I tried with and without verbose output but it made no difference.

    RLs-MacBook-Pro:encoder roger$ f -2 --verbose c4.c
    Propeller Spin/PASM Compiler 'FlexSpin' (c) 2011-2022 Total Spectrum Software Inc.
    Version 5.9.19-HEAD-v5.9.19 Compiled on: Nov 13 2022
    c4.c
    Segmentation fault: 11

    EDIT: after messing about if I comment out the ++line; statement on line 65 it compiles (just the next() function in isolation) and segfault crashes without it. But why? Also replacing it with line++; instead compiles okay too.

    EDIT2: looks like flexspin can't handle assignments with pre-increment/pre-decrement operations, at least in non-pointer cases. When I removed all of them, I was able to compile without crashing - with some other strange issues related to argument mismatch in some called library functions which is still to be fixed. It'd be nice to at least not crash the compiler if it encounters this, although it would be far better to actually support these pre/post operations too.

    I've attached the workingc4.c code without the pre-increment/pre-decrement stuff, that flexspin now handles.

    EDIT3: Looks like this issue stems from the fact that the int type is being redefined as a long long in the source. If I change it to long instead, the crashes go away. So perhaps this is some 64 bit limitation internally in flexspin with no support for pre-inc/dec operations.

    c
    c
    20K
  • Hi Eric,

    the attached code immediately crashes the compiler (segmentation fault). It does this since I added the C code "B2M_axes.c" to the main module "B2M_main.spin2". B2M-axes is untested and surely contains lots of bugs but it shouldn't crash the compiler. If I comment out "axe.Init_Axes ()" it compiles and runs well.

  • Could it be that FlexC doesn't like this reference variable declaration?

    void PutPosDat (int32_t* data, int16_t ref)
    {
        while (bufGauge >= AXIS_BUFFER_SIZE) {};
        /*
        AxisBuffEntry& buf= AxisBuffer[wrIndex]; // neuer Puffereintrag
    
        memcpy (buf.pos, data, MAX_NUMAXES*4);
        buf.vNom= currVel;
        buf.vMax= maxVel;
        buf.ref = ref;
        */
    

    I've used "buf" as a shortcut to the indexed array field AxisBuffer[wrIndex]. If I comment it out the compiler no longer crashes. The docs say that C++ style reference parameters are supported but I guess this doesn't include local reference variables. However, the compiler should throw an error instead of crashing.

    If that's really the (only) cause I could use a pointer instead (which is used internally for &-style references, anyway).

  • @ManAtWork : yes, there's a bug (probably several) in local reference variables. The crash is fixed in github now, but I doubt local reference variables will work correctly yet.

  • @rogloh : The c4.c compiles now with the version of flexspin checked into github (built from source, that is).

  • @ersmith said:
    The crash is fixed in github now, but I doubt local reference variables will work correctly yet.

    Thanks for the fix. No problem, I can use pointers instead if I know it. I've just ported that code from an ARM environment (MinGW/GNU based I think) where it worked correctly.

  • @ersmith said:
    @rogloh : The c4.c compiles now with the version of flexspin checked into github (built from source, that is).

    Thanks for the fix so soon!
    Cheers,
    Roger.

  • RaymanRayman Posts: 14,553
    edited 2022-11-19 17:24

    @ersmith This Wiznet FTP server code uses FatFs to access the sd card like this:

    #if defined(F_FILESYSTEM)
    #include "ff.h"  
    #endif
    

    This isn't going to work with the built in SD card access, right?
    I'm thinking I either need to include all of FatFs myself and not use the built in SD card access, or rewrite all the SD card access code, is this right?

    Shoot, this code is based on FatFS version 0.10 instead of 0.14. Don't really want to go backwards... Guess need to rewrite anyway...

  • RaymanRayman Posts: 14,553
    edited 2022-11-19 17:10

    This AVR version of Micro-Max chess appears to now work with FlexC. Don't think it used to...

    Original version of Micro-Max may or may not be working... Works when you enter the moves, but just sits there if you hit enter for code to generate a move.
    But, I think this happened under Catalina too, it took a very long time to make a move...

  • @Rayman said:
    @ersmith This Wiznet FTP server code uses FatFs to access the sd card like this:

    #if defined(F_FILESYSTEM)
    #include "ff.h"  
    #endif
    

    This isn't going to work with the built in SD card access, right?
    I'm thinking I either need to include all of FatFs myself and not use the built in SD card access, or rewrite all the SD card access code, is this right?

    Why re-write it? Isn't there a version that will use the native file system (the built in one), e.g. for testing on linux or Windows?

    Or, you could just use the ff.h they provide. But do not try to use both the provided FatFS and the built in one, you'll run into big problems doing that.

  • RaymanRayman Posts: 14,553
    edited 2022-11-19 18:53

    @ersmith Is there still a "simple_ls.c" example? One I have doesn't work any more... Trying to figure out how to list a directory...

  • @Rayman : It depends on the language you're using. From context I'm guessing you want C: the "shell" sample that comes with FlexProp has examples of doing common file operations. Look at the function do_dir() in samples/shell/shell.c.

  • RaymanRayman Posts: 14,553

    @ersmith Thanks, that helped. Was able to implement "dir" in the Wiznet ftp server.
    But, going to have to rewrite a lot of code to get it all working...

Sign In or Register to comment.