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

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

11617192122122

Comments

  • jmgjmg Posts: 15,173
    ozpropdev wrote: »
    004c4 031 030000FF
    004c8 032 D4EC07F6    | copyx		mov	pa,##_copy0		'start video buffer update
    
    In the above example "copyx" should be on the previous line, the AUGS line.
    Here the label "debug" is at the end of the data not the beginning.
    If every relevant line was tagged here, would that be ok for your extract debug data from fastspin .lst files ?
    That would make for a clearer file.
  • ersmithersmith Posts: 6,052
    edited 2019-08-09 23:48
    jmg wrote: »
    ersmith wrote: »
    If you can find out how to set higher clock speeds on the Mac I'd be delighted to put that into my version of loadp2.

    I presume you mean Baud settings ?

    Yes, I meant baud rate.
    DB: If I use both "-b 230400" and "-l 230400" everything seems to work
    On that topic, I hope loadp2 has no issues with this "-b 3" and "-l 3" ?
    For setting the serial baud rate loadp2 just passes the baud rate through to the OS. The loader baud rate also needs to be set in the P2 loader code, and that just uses the value after "-l" directly. So "-l 3" will probably set your download speed to 3 baud.

  • jmgjmg Posts: 15,173
    ersmith wrote: »
    For setting the serial baud rate loadp2 just passes the baud rate through to the OS. The loader baud rate also needs to be set in the P2 loader code, and that just uses the value after "-l" directly. So "-l 3" will probably set your download speed to 3 baud.

    That's all good then. The final actual baud depends on firmware, as mentioned above.
    I've used a dual plane to produce 24MHz/M, for M < 367, so that '3' yields 8MBd. That's done because some drivers block at the PC side, and refuse large numbers...

  • I tried this on the Mac and it also works. I haven't gotten it to work with 2000000 baud though. Maybe 921600 should be made the default on the Mac?
    loadp2 -t -b 230400 -l 921600 -p /dev/cu.usbserial-P2EEQXU test
    
  • jmgjmg Posts: 15,173
    David Betz wrote: »
    I tried this on the Mac and it also works. I haven't gotten it to work with 2000000 baud though. Maybe 921600 should be made the default on the Mac?
    loadp2 -t -b 230400 -l 921600 -p /dev/cu.usbserial-P2EEQXU test
    

    Yes, it makes sense to use a default that is reliable and portable :)
    What messages does 2Mbd give ? Does it try to download anything ?

    I see a cryptic [ -b baud ] use baud rate (default is 115200) in some docs, and digging I see that is actually applied to the terminal after boot, so maybe that should be called terminal baud rate or user terminal baud rate ?

    I do not see a Prop_Txt mode in loadp2 ? The DOCs say this mode is 2.25x faster :

    Prop_Txt ... This format is 2.25x denser than hex, and so minimizes transmission size and time.
  • dgatelydgately Posts: 1,630
    edited 2019-08-10 06:31
    David Betz wrote: »
    I'm not at home right now but I believe it was this:
    loadp2 -t -b 230400 -l 230400 -p /dev/cu.usbserial-P2EEQXU test
    
    I use several python scripts that call loadp2 with differing baud rates. Here's your C example compiling, loading and executing successfully on a P2ES from a MacBook Pro, running macOS Mojave 10.14.6:
    $ fastspin -2 test.c -L ~/source/spin2cpp/include -o test.binary
    $ loady3.py test.binary 
    Load my O2 Eval Board with a binary and setup a terminal.
    Note: Always uses -b 230400 & -l 230400.
    USAGE: loady.py [P2 binary filename]
    
    loading test.binary ...
    not an ELF file
    ( Entering terminal mode.  Press Ctrl-] to exit. )
    Hello, world!
    
    The loady3.py script contains (among other things) this:
    return_code = subprocess.call("loadp2 -p /dev/cu.usbserial-P2EEI8V -b 230400 -l 230400 -t -CHIP " + fn, shell=True)  
    

    dgately
  • roglohrogloh Posts: 5,786
    edited 2019-08-10 21:31
    David Betz wrote: »
    I tried this on the Mac and it also works. I haven't gotten it to work with 2000000 baud though. Maybe 921600 should be made the default on the Mac?
    loadp2 -t -b 230400 -l 921600 -p /dev/cu.usbserial-P2EEQXU test
    

    I have found that 2000000 can work on the MAC. I am using Yosemite 10.10.5 with some specific changes to loadp2 that I made a while back and discussed in the p2gcc thread. When I return from vacation I will try to collect them as a github request if Eric wants to get them integrated into loadp2. It also enabled the auto detect feature if I recall correctly.
  • rogloh wrote: »
    David Betz wrote: »
    I tried this on the Mac and it also works. I haven't gotten it to work with 2000000 baud though. Maybe 921600 should be made the default on the Mac?
    loadp2 -t -b 230400 -l 921600 -p /dev/cu.usbserial-P2EEQXU test
    

    I have found that 2000000 can work on the MAC. I am using Yosemite 10.10.5 with some specific changes to loadp2 that I made a while back and discussed in the p2gcc thread. When I return from vacation I will try to collect them as a github request if Eric wants to get them integrated into loadp2. It also enabled the auto detect feature if I recall correctly.
    That sounds great! I was just going to integrate the auto-detect code from propeller-load but I won't bother if you already have that done.
  • ersmithersmith Posts: 6,052
    edited 2019-08-14 20:14
    I've published new releases (3.9.29) of fastspin and spin2gui. @ozpropdev and @Cluso99, the listing files should work better in this version. I've also fixed some Spin compatibility issues that affected Numbers.spin.

    Most of the new features are in the BASIC language. Passing objects to functions works more smoothly now in BASIC, and there have been some other object cleanups. You can now declare classes inline like:
      class counter
        dim c as integer
        sub increment()
          c = c + 1
        end sub
        function get() as integer
          return c
        end function
      end class
    
      dim x as counter
    
    (The old "class using" syntax still works of course, and still supports including Spin or C files as classes).

    The C compiler also supports having methods inside structs, sort of a poor man's C++ class.

    BASIC also has a simple form of function template for polymorphic programming. You can specify a function that takes any kind of argument and that will be specialized at compile time:
    any(t) function twice(x as t) as t
      return x+x
    end function
    
    print twice(10) ' prints 20
    print twice(1.4) ' prints 2.8
    print twice("abc") ' prints "abcabc"
    

    These templates are BASIC only for now, but probably could be added to C as well (that's a low priority though... the compiler template support is actually there to support another language I'm thinking of adding as a longer term project).
  • ersmith wrote: »
    These templates are BASIC only for now, but probably could be added to C as well (that's a low priority though... the compiler template support is actually there to support another language I'm thinking of adding as a longer term project).
    Another language? Sounds intriguing. Is this an existing language you're planning to support or one you're designing yourself?
  • David Betz wrote: »
    ersmith wrote: »
    These templates are BASIC only for now, but probably could be added to C as well (that's a low priority though... the compiler template support is actually there to support another language I'm thinking of adding as a longer term project).
    Another language? Sounds intriguing. Is this an existing language you're planning to support or one you're designing yourself?

    I'd like to see if there's some subset of python that could be compiled. python in general is too dynamic to be efficiently compiled, but on the other hand many practical python programs don't rely on those dynamic features and could be compiled. So I was thinking that a python program like:
    def twice(x):
      return x+x
    
    could be compiled into something like the BASIC template I posted above, and then specialized based on the type of arguments actually passed to the "twice" function. That depends on being able to deduce the types at compile time, but in many cases that should be possible.
  • ersmith wrote: »
    David Betz wrote: »
    ersmith wrote: »
    These templates are BASIC only for now, but probably could be added to C as well (that's a low priority though... the compiler template support is actually there to support another language I'm thinking of adding as a longer term project).
    Another language? Sounds intriguing. Is this an existing language you're planning to support or one you're designing yourself?

    I'd like to see if there's some subset of python that could be compiled. python in general is too dynamic to be efficiently compiled, but on the other hand many practical python programs don't rely on those dynamic features and could be compiled. So I was thinking that a python program like:
    def twice(x):
      return x+x
    
    could be compiled into something like the BASIC template I posted above, and then specialized based on the type of arguments actually passed to the "twice" function. That depends on being able to deduce the types at compile time, but in many cases that should be possible.
    Sounds interesting.

  • jmgjmg Posts: 15,173
    ersmith wrote: »
    BASIC also has a simple form of function template for polymorphic programming. You can specify a function that takes any kind of argument and that will be specialized at compile time:
    any(t) function twice(x as t) as t
      return t+t
    end function
    
    print twice(10) ' prints 20
    print twice(1.4) ' prints 2.8
    print twice("abc") ' prints "abcabc"
    

    These templates are BASIC only for now, but probably could be added to C as well (that's a low priority though... the compiler template support is actually there to support another language I'm thinking of adding as a longer term project).

    That's impressively simple, and very student friendly. What is the code overhead cost of that flexibility ?

    ersmith wrote: »

    I'd like to see if there's some subset of python that could be compiled. python in general is too dynamic to be efficiently compiled, but on the other hand many practical python programs don't rely on those dynamic features and could be compiled. So I was thinking that a python program like:
    def twice(x):
      return x+x
    
    could be compiled into something like the BASIC template I posted above, and then specialized based on the type of arguments actually passed to the "twice" function. That depends on being able to deduce the types at compile time, but in many cases that should be possible.
    Sounds like a very appealing approach. Keep us posted.

  • ersmithersmith Posts: 6,052
    edited 2019-08-14 20:28
    jmg wrote: »
    ersmith wrote: »
    BASIC also has a simple form of function template for polymorphic programming. You can specify a function that takes any kind of argument and that will be specialized at compile time:
    any(t) function twice(x as t) as t
      return t+t
    end function
    
    Whoops! There was a typo in my original post, that should have read "return x+x". Sorry about that (I've edited the post now).
    That's impressively simple, and very student friendly. What is the code overhead cost of that flexibility ?
    Each different type passed to "twice" creates a new function. So if "twice" gets used in different places with an integer, float, and string argument (as in the example above) we end up with three functions:
    function twice__i4(x as integer) as integer
      return x+x
    end function
    function twice__f4(x as single) as single
      return x+x
    end function
    function twice__s(x as string) as string
      return x+x
    end function
    
    For this particular example the integer version is simple enough that it'll be inlined automatically, so there's really no code overhead for it. But we will get new functions created for the float ("single") and string versions.

    Once a specific version of the "twice" function is created (e.g. the "twice__s" version for strings) then it'll be re-used when further calls to "twice(string)" happen, so the overhead is only once per distinct type, not once per call.
  • Cluso99Cluso99 Posts: 18,069
    edited 2019-08-17 11:20
    Eric,
    I've been using spingui/fastspin for the past 3 weeks. What a great suite of programs!
    I really like the way the terminal program comes up automatically after downloading :)

    I have found that the find/search section in the editor doesn't seem to work. Perhaps I don't understand the metrics behind it, so can you enlighten me please,
    Thanks, Ray

    Postedit...
    Forgot to ask. How best to include a binary file (it has z80 instructions)?
    I've seen this example..
    framebuffer            file "rose.gray"
    
  • Cluso99 wrote: »
    I have found that the find/search section in the editor doesn't seem to work. Perhaps I don't understand the metrics behind it, so can you enlighten me please,
    Hi Ray. Glad you're finding spin2gui useful!

    It looks like there's a bug in the search menu command... it doesn't work unless you first click on the text window that you want to search in (that is, there's no default). If you load a file, click once on the window containing that file, and then do control-f (or select the menu entry) then it should bring up a dialog box asking what you want to search for, and it should work fine after that. (If you don't click on the window after loading the file it reports an error about missing tags).
    Forgot to ask. How best to include a binary file (it has z80 instructions)?
    I've seen this example..
    framebuffer            file "rose.gray"
    

    Yes, fastspin should support the standard Spin FILE command to include binary data. Are you finding that it doesn't work for you? It's certainly possible that there's a bug there, although it does seem to work in many cases.

    Regards,
    Eric
  • Cluso99Cluso99 Posts: 18,069
    Thanks Eric. I’ll try find again.

    Yes. I’ve since tried the file insert and it works works fine.
  • ersmith wrote: »
    I've published new releases (3.9.29) of fastspin and spin2gui. @ozpropdev and @Cluso99, the listing files should work better in this version.
    Thanks Eric!
    It's all good now except for RES cog addresses don't increment.
    00478 01e             | junk1		res	1
    00478 01e 
    00478 01e             | junk2		res	1
    00478 01e 
    00478 01e             | junk3		res	1
    00478 01e 
    


  • evanhevanh Posts: 15,915
    That'll be because those addresses in the .lst file are the file offset, not the symbol address. Well, except for the accompanying cog addresses that is.
  • ozpropdev wrote: »
    ersmith wrote: »
    I've published new releases (3.9.29) of fastspin and spin2gui. @ozpropdev and @Cluso99, the listing files should work better in this version.
    Thanks Eric!
    It's all good now except for RES cog addresses don't increment.
    00478 01e             | junk1		res	1
    00478 01e 
    00478 01e             | junk2		res	1
    00478 01e 
    00478 01e             | junk3		res	1
    00478 01e 
    

    Ah, I missed that one. Thanks for catching it!

    Here's a binary that should have that fixed, along with a few other minor fixes. It's not a complete release yet so it's still marked as "beta".

  • ersmith wrote: »
    ozpropdev wrote: »
    ersmith wrote: »
    I've published new releases (3.9.29) of fastspin and spin2gui. @ozpropdev and @Cluso99, the listing files should work better in this version.
    Thanks Eric!
    It's all good now except for RES cog addresses don't increment.
    00478 01e             | junk1		res	1
    00478 01e 
    00478 01e             | junk2		res	1
    00478 01e 
    00478 01e             | junk3		res	1
    00478 01e 
    

    Ah, I missed that one. Thanks for catching it!

    Here's a binary that should have that fixed, along with a few other minor fixes. It's not a complete release yet so it's still marked as "beta".
    Now it's:
    00dc8 046             | 	org	COG_BSS_START
    00dc8 046             | _main_i_0002
    00dc8 047             | 	res	1
    00dc8 047             | _main_pinmask_0001
    00dc8 048             | 	res	1
    00dc8 048             | _var01
    00dc8 049             | 	res	1
    
    I would think it should be:
    00dc8 046             | 	org	COG_BSS_START
    00dc8 046             | _main_i_0002
    00dc8 046             | 	res	1
    00dc8 047             | _main_pinmask_0001
    00dc8 047             | 	res	1
    00dc8 048             | _var01
    00dc8 048             | 	res	1
    

    Or am I wrong ?
  • jmgjmg Posts: 15,173
    dnalor wrote: »
    ...
    I would think it should be:
    00dc8 046             | 	org	COG_BSS_START
    00dc8 046             | _main_i_0002
    00dc8 046             | 	res	1
    00dc8 047             | _main_pinmask_0001
    00dc8 047             | 	res	1
    00dc8 048             | _var01
    00dc8 048             | 	res	1
    
    Or am I wrong ?

    I think you are right, here is another LST file which reports the start address / address of in the left most column, for reserved variables.
       994:    = A5                         T_THEN  EQU     T_LAST+1 
       995:    0233  A5                             DB      T_THEN
       996:    0234  54 48 45 4E                    DB      'THEN'
       997:                                         ;
       998:    = A6                         T_TO    EQU     T_LAST+2   
       999:    0238  A6                             DB      T_TO
    
  • Cluso99Cluso99 Posts: 18,069
    I'll wait until you have the next final version ready as I cannot seem to get find/search working.

    I'm just loving the compile/download/run/terminal as a single click :smiley:

    Meanwhile, I've noticed the "file save as" does not fill the box with the current filename. Is this an easy fix???

    Sometimes I forget to close the terminal window before the next compile/etc. This prevents the running so is there any reason not to close the current terminal window and proceed? If not, is that a possibility?

    BTW I am finding the editor a bit limited. Cannot tell you why. I just revert to using PropTool for anything but minor edits. Maybe it's just habit.
  • dnalor wrote: »
    [
    Now it's:
    00dc8 046             | 	org	COG_BSS_START
    00dc8 046             | _main_i_0002
    00dc8 047             | 	res	1
    00dc8 047             | _main_pinmask_0001
    00dc8 048             | 	res	1
    00dc8 048             | _var01
    00dc8 049             | 	res	1
    
    I would think it should be:
    00dc8 046             | 	org	COG_BSS_START
    00dc8 046             | _main_i_0002
    00dc8 046             | 	res	1
    00dc8 047             | _main_pinmask_0001
    00dc8 047             | 	res	1
    00dc8 048             | _var01
    00dc8 048             | 	res	1
    

    Or am I wrong ?

    That would be a better output, and I'll try to tweak it to look more like that. The main thing is that the labels should have the correct addresses for the debugger, which they do now.

    Thanks,
    Eric
  • ersmithersmith Posts: 6,052
    edited 2019-08-19 10:47
    Cluso99 wrote: »
    I'll wait until you have the next final version ready as I cannot seem to get find/search working.
    What symptoms are you seeing? Does pressing ctrl-F in the window bring up the search box?
    Meanwhile, I've noticed the "file save as" does not fill the box with the current filename. Is this an easy fix???

    Good idea. I think you can just make a small change to src/gui.tcl to do this. All of the .tcl files are directly interpreted, so you don't need to recompile or anything, just change the .tcl file and restart spin2gui.exe. Here's the diff (I had to edit it slightly because the forum messes up @ signs, but those are only in the diff header so don't affect the actual code):
    --- a/src/gui.tcl
    +++ b/src/gui.tcl
    @ @ -495,7 +495,15 @ @ proc saveFileAs {w} {
         global BINFILE
         global SpinTypes
         global config
    -    set filename [tk_getSaveFile -filetypes $SpinTypes -defaultextension $config(spinext) -initialdir $config(lastdir) ]
    +
    +    if { [string length $filenames($w)] == 0 } {
    +       set initdir $config(lastdir)
    +       set initfilename ""
    +    } else {
    +       set initdir [file dirname $filenames($w)]
    +       set initfilename [file tail $filenames($w)]
    +    }
    +    set filename [tk_getSaveFile -filetypes $SpinTypes -defaultextension $config(spinext) -initialdir $initdir -initialfile $initfilename ]
         if { [string length $filename] == 0 } {
            return
         }
    
    Sometimes I forget to close the terminal window before the next compile/etc. This prevents the running so is there any reason not to close the current terminal window and proceed? If not, is that a possibility?
    I'm not sure about this. Sometimes people might have more than one Prop and be running code in one that should stay open?
    BTW I am finding the editor a bit limited. Cannot tell you why. I just revert to using PropTool for anything but minor edits. Maybe it's just habit.

    Oh, the editor is definitely very limited. It should be possible to use an external editor and just use spin2gui for the compile/run portion -- spin2gui checks regularly for changes to external files. That is, it should work fine to leave both spin2gui and some other editor open with the same file, and any changes in the other editor should be noticed by spin2gui. (Whether any changes spin2gui makes are noticed by the other editor depends on that editor, of course, but if you only make changes in the other editor and only use spin2gui for compile/run then you should be fine.)

    spin2gui is really kind of a quick hack, and something like @Rayman's Spin tool or Visual Studio Code would probably be nicer as a GUI for fastspin.
  • Cluso99Cluso99 Posts: 18,069
    Thanks Eric.

    Ctl-F brings up the search box but after i enter something and click next, nothing happens. But i have a version about 3 weeks old.

    I’ll try editing the .tcl file.

    Didn’t think about more than one prop. I am happy as is.

    Yes, I’ve been keeping either PropTool or Notepad++ open and editing there. Don’t have VSCode on this laptop. I’ll be home at the end of the week so I’ll have my much faster pc with ssd :smiley:
  • Cluso99 wrote: »
    Ctl-F brings up the search box but after i enter something and click next, nothing happens. But i have a version about 3 weeks old.
    Odd. For me it highlights (in yellow) the next instance of the thing I searched for, and as I hit "next" it cycles through them.

    I did notice that if I search for something that's not in the file then nothing happens. Could that be what's hitting you? I'll add a "not found" dialog box, that should have been there from the beginning. (I used someone else's search and replace code and didn't notice that there was no message when the search term wasn't found.)

  • ersmith wrote: »

    That would be a better output, and I'll try to tweak it to look more like that. The main thing is that the labels should have the correct addresses for the debugger, which they do now.

    Thanks,
    Eric
    You're right. Actually, it's just a flaw.
  • ersmith wrote: »
    We could also provide a switch to explicitly dump labels (and any other debug information we can think of) into a file for the debugger. What format would be convenient for that?
    Your list file is now:
    HUB-address Cog-address hex |asm

    I would prefer a csv file (semicolon or tab as delimiter) for easy tokenization:
    HUB-address;Cog-address;hex;asm

    A user would want to set a breakpoint in the sourcefile. For that I would need sourcefile-name and sourcefile-line, that I can find the address for the breakpoints.
    sourcefile-name;sourcfile-line;HUB-address;Cog-address;hex;asm
    Would that be doable?

    Something like that:
    test1.c;25;0049c;;;_main
    test1.c;27;0049c;;00 80 00 FF 
    test1.c;27;004a0;;00 50 04 F6;mov	_main_pinmask_0001, ##16777216                         'unsigned int pinmask = 1<<(PIN-32);
    test1.c;28;004a4;;02 4E 04 F6;mov	_main_i_0002, #2                                                     'unsigned int i = 2;
    test1.c;33;004a8;;00 80 00 FF 
    test1.c;33;004ac;;00 F6 47 F5;or	dirb, ##16777216                                                    'DIRB |= pinmask;
    test1.c;35;004b0;;;'     for(;;) {
    test1.c;35;004b0;;;LR__0001
    test1.c;35;004b0;;28 FA 63 F5;xor	outb, _main_pinmask_0001                                       'OUTB ^= pinmask;
    [...]
    ;;004ec;027;;org	COG_BSS_START
    test1.c;28;004ec;027;;_main_i_0002
    ;;004ec;028;;res	1
    test1.c;27;004ec;028;;_main_pinmask_0001
    
    I'm still thinking about the labels...

  • Cluso99Cluso99 Posts: 18,069
    ersmith wrote: »
    Cluso99 wrote: »
    Ctl-F brings up the search box but after i enter something and click next, nothing happens. But i have a version about 3 weeks old.
    Odd. For me it highlights (in yellow) the next instance of the thing I searched for, and as I hit "next" it cycles through them.

    I did notice that if I search for something that's not in the file then nothing happens. Could that be what's hitting you? I'll add a "not found" dialog box, that should have been there from the beginning. (I used someone else's search and replace code and didn't notice that there was no message when the search term wasn't found.)
    Yes, the problem seems to be I didn't have ignore case selected and didn't realise it was not found because it is working now :smiley:
Sign In or Register to comment.