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

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

12627293132123

Comments

  • JRoarkJRoark Posts: 1,215
    edited 2019-10-18 16:47
    When using FlexGUI 4.0.0 beta, under Win10 and coding in BASIC:

    I boiled-down the "Out Of Memory" code to an uber-thin test case. If you copy and run this with the debug window open, after 3-4 loops, you'll get an "Out of Memory" message up the serial channel and the FLIP sort of wanders-off somewhere.
    OPTION EXPLICIT
    CONST HEAPSIZE = 4096
    
    	dim tmp$ as string
    	dim idx as integer
    
    	for idx = 1 to 15
    		tmp$ = str$(idx) + " :The quick brown fox jumps over the lazy hedgehog"
                    '_gc_free(tmp$)
                    '_gc_collect()
                    'tmp$ = ""
    	next idx
    

    You can uncomment the _gc_free() and _gc_collect() in any combination and the error still persists. Same goes for setting TMP$="". Putting this code into a SUB doesn't seem to have much effect either.

    I'm stumped. @ersmith, your garbage collector just doesn't seem to like me... :smile:
  • yetiyeti Posts: 818
    edited 2019-10-18 17:40
    @JRoark ... the GC doesn't like me too.

    Testing on Propeller1/SpinSim...
    Maybe "str$()" is the problem?
    Even this fails:
    let s$=str$(1)
    let s$=str$(1)
    let s$=str$(1)
    let s$=str$(1)
    

    A byte later:
    OPTION EXPLICIT
    CONST HEAPSIZE = 4096
    
    dim tmp$ as string
    dim idx as integer
    
    function itos$(n as integer) as string
      if n<0 return "-"+itos$(-n)
      if n<10 return chr$(48+n)
      return itos$(n/10)+itos$(n mod 10)
    end function
    
    for idx = 1 to 15
      tmp$ = itos$(idx) + " :The quick brown fox jumps over the lazy hedgehog"
      '_gc_free(tmp$)
      '_gc_collect()
      'tmp$ = ""
      print tmp$
    next idx
    
    $ fastspin -q cvbbv.bas ; spinsim -b cvbbv.binary 
    1 :The quick brown fox jumps over the lazy hedgehog
    2 :The quick brown fox jumps over the lazy hedgehog
    3 :The quick brown fox jumps over the lazy hedgehog
    4 :The quick brown fox jumps over the lazy hedgehog
    5 :The quick brown fox jumps over the lazy hedgehog
    6 :The quick brown fox jumps over the lazy hedgehog
    7 :The quick brown fox jumps over the lazy hedgehog
    8 :The quick brown fox jumps over the lazy hedgehog
    9 :The quick brown fox jumps over the lazy hedgehog
    10 :The quick brown fox jumps over the lazy hedgehog
    11 :The quick brown fox jumps over the lazy hedgehog
    12 :The quick brown fox jumps over the lazy hedgehog
    13 :The quick brown fox jumps over the lazy hedgehog
    14 :The quick brown fox jumps over the lazy hedgehog
    15 :The quick brown fox jumps over the lazy hedgehog
    
    No comment!
    ;-)
  • Looks like Ol' @yeti got the best of Mr. Hedgehog! It's starting to look like STR$() is the guilty party...
  • @evanh:

    Thank you! I'll give those changes a try here.

    @JRoark and @yeti:

    Yes, str$ is broken :(. It appears that creating a temporary function inside another function can create an infinite loop that prevents garbage collection from happening. I'll have to think about the right solution for that, but for now you can replace the fastspin file include/libsys/strings.bas with the one attached to this message to get str$ working properly again.

    Thanks for your help finding this!
  • JRoarkJRoark Posts: 1,215
    edited 2019-10-19 12:40
    When using FlexGUI 4.0.0 beta, under Win10 and coding in BASIC:

    @ersmith added the VAL() function when I wasnt looking. Sneaky devil! On the next doc cycle, you might add that to the keywords along with a brief description.

    Edited to add: VAL() has some bugs. VAL() doesnt handle anything to the right of the decimal point and it also does not like the presence of a sign at all.
    val("1234")    'returns 1234
    val("+1234")   'returns 0
    val("-1234")   'returns 0
    val("1234.56") 'returns 1234
    
    But the basic "VAL()" for unsigned integers works nicely. So it may be that I've stumbled onto one of those "I wasn't actually ready to release that" sort of things... which explains why it's not in the manual yet. :blush:
  • JRoark wrote: »
    BTW: VAL() doesnt handle anything to the right of the decimal point (ie, val("1234.56") returns 1234), but for integers it works nicely.
    How do floats in DATA blocks behave?
    I thought "VAL()", reading input and reading "DATA ..." might be related.
    Then I stumbled over:
    $ cat data.bas 
    data 3.13
    
    dim as single s
    
    read s
    print s
    
    $ fastspin data.bas 
    Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
    Version 4.0.0 Compiled on: Oct 19 2019
    data.bas
    readdata.spin
    fmt.c
    strcpy.c
    strlen.c
    warning: : Internal error, unexpected COG label
    data.pasm
    Done.
    Program size is 9376 bytes
    
    $ spinsim -b data.binary 
    3.1300
    
    ...where the result looks ok but what tries fastspin to tell my by "warning: : Internal error, unexpected COG label"?
  • JRoark wrote: »
    Edited to add: VAL() has some bugs. VAL() doesnt handle anything to the right of the decimal point and it also does not like the presence of a sign at all.
    val("1234")    'returns 1234
    val("+1234")   'returns 0
    val("-1234")   'returns 0
    val("1234.56") 'returns 1234
    
    But the basic "VAL()" for unsigned integers works nicely. So it may be that I've stumbled onto one of those "I wasn't actually ready to release that" sort of things... which explains why it's not in the manual yet. :blush:

    VAL is kind of half-baked so far, yes, although the sign bug is not supposed to happen. I'll fix that.

    I'm not sure we want to pull in all of the floating point code for every use of VAL, but on the other hand it would be nice to have val("1234.56") return the correct value. Maybe we need both VAL# and VAL%, and make plain VAL the same as VAL#?
  • @yeti: the "unexpected COG label" warning seems to be harmless, but it indicates that for some reason the label starting the BASIC data block hasn't been flagged as a HUB label. It should be, so I'll look into it.

    Thanks,
    Eric
  • JRoarkJRoark Posts: 1,215
    edited 2019-10-21 00:36
    When using FlexGUI 4.0.0 beta, under Win10 and coding in BASIC for the FLiP:

    @ersmith I haz an error, bigly. This only happens when Options -> Full Optimization is selected, but I thought I'd pass it along just the same. It never happens when Options -> Default Optimization is selected. When I select Options -> No Optimization it doesn't error-out, but the resulting file size exceeds the Prop1's memory so I'm not sure it's relevant.

    I'd post the code, but I'm somewhere north of 2000 lines of BASIC and some non-trivial amount of Spin with embedded assembly, so it'd be a slog. That being said, if I must, I'll do a binary divide and conquer to see if I can isolate the offending chunk.
    Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
    Version 4.0.0-beta-317bfbe5 Compiled on: Oct  4 2019
    GenTest1.bas
    |-vga_hires_textLEAN.spin   '<- highly modified version of Chip's vga_hires_text but for 640x480 and 256 char font
    |-DS1307RTC.spin            '<- modifed version of file of same name from obex but for DS3231 chip
    fmt.c
    strings.bas                 '<- ERSmith's temp replacement for the misbehaving distro file
    gcptrs.spin
    strcpy.c
    strlen.c
    GenTest1.pasm               '<- Generator control w/user interface - top-level module in FlexBASIC
    Done.
    d:/Flex2Gui/flexgui/GenTest1.pasm:6985: error: fit 496 failed: pc is 535
    child process exited abnormally
    Finished at Sun Oct 20 19:14:40 2019
    
  • I've been away on vacation and am just getting up to speed again. What is the current status of the FastSpin C compiler? It sounds like the entire suite of languages has made great progress in the past few weeks!
  • David Betz wrote: »
    I've been away on vacation and am just getting up to speed again. What is the current status of the FastSpin C compiler? It sounds like the entire suite of languages has made great progress in the past few weeks!

    Welcome back, David! FastSpin C is in much better shape than it was, but there are still plenty of things that need improvement. My goal for 4.0.0 was to get BASIC stable (which I think has been achieved) and I'm turning to C next. There's a c-testsuite on github that I've started working with and it's already turned up some interesting bugs in the C support.
  • Sounds good! I'll try some of my code again to see if I run into any problems. I'd still like to get my BASIC interpreter working on P2. It is nothing compared with your BASIC but it does run directly on the P2.
  • @JRoark : the "fit 496 failed" error when compiling with -O2 is an out of memory problem. The optimizer puts more things into registers, and we've run out of registers. There's no easy fix for this, although one potential work-around on P1 is to eliminate the fcache by adding "--fcache=0" to the command line. That hurts performance though and probably defeats the purpose of using -O2.
  • I've released the "final" version of fastspin 4.0.0 and flexgui 4.0.0. They're at:

    https://github.com/totalspectrum/flexgui/releases/latest
    https://github.com/totalspectrum/spin2cpp/releases/latest

    FlexGUI contains fastspin, so that's the one you probably want unless you're just looking for command line tools.

    This release has many bug fixes. The GUI is mostly unchanged, except I did change the Library Directories... dialog box to allow for multiple library directories to be selected.

  • Sweet! @ersmith you ever actually sleep?

    The BASIC-side of the Flex house is impressively stable and for the most part well-behaved. The ability to drop-down into assembler, or to call Spin routines from BASIC so simply is a huge benefit to me. If anyone lurking has been “on-the-fence” about trying this, you owe it to yourself to try it.

    Well done, Eric!
  • Thanks, @JRoark. Someone noticed a bug in the dialog that switches between P1 and P2, so I've uploaded a slightly revised version 4.0.0b that fixes it. If you're not switching between the platforms you won't need to re-download.
  • \o/ 4.0 \o/
    JRoark wrote: »
    Sweet! @ersmith you ever actually sleep?
    ***cough*** ...commit time stamps... ***cough***
    JRoark wrote: »
    The BASIC-side of the Flex house is impressively stable and for the most part well-behaved. The ability to drop-down into assembler,
    Inline LMM-PASM may lower the hurdle to start looking at PASM a lot.
    JRoark wrote: »
    or to call Spin routines from BASIC so simply is a huge benefit to me.
    Using "stdio" or "stdlib" stuff in Spin and BASIC is fun too!

    And not to forget: You can include "fastspin -w" compiled and "wrapped" cog objects in bytecode Spin programs.
    JRoark wrote: »
    If anyone lurking has been “on-the-fence” about trying this, you owe it to yourself to try it.
    !!!
    JRoark wrote: »
    Well done, Eric!
    I 2nd this!
    👏👏👏 Thanks, Eric! 👏👏👏
  • I've released version 4.0.1, which has several bug fixes. As always, the binaries may be obtained at:

    https://github.com/totalspectrum/flexgui/releases/latest
    https://github.com/totalspectrum/spin2cpp/releases/latest

    "flexgui.zip" is the GUI and has everything you need to develop programs for P1 or P2. If you want just the command line tools you can download spin2cpp.zip and/or fastspin.zip. Spin2cpp is the general tool for converting Spin, BASIC, and C to C++ or PASM. fastspin is a simplified command line tool for compiling executable binaries.
  • When using FlexGUI 4.0.1, under Win10 and coding in BASIC for the FLiP:

    I was reading the doc for the command line switches for PropLoader here: https://github.com/parallaxinc/PropLoader, and it seems that FlexGUI uses a "-k" option when calling PropLoader that isn't defined. What does "-k" do? Here is what the doc says:
    PropLoader v1.0-43 (2018-12-01 13:55:21 g7445ae2)
    
    usage: proploader [options] [<file>]
    
    options:
        -b <type>       select target board and subtype (default is 'default:default')
        -c              display numeric message codes
        -D var=value    define a board configuration variable
        -e              program eeprom (and halt, unless combined with -r)
        -f <file>       write a file to the SD card
        -i <ip-addr>    IP address of the Parallax Wi-Fi module
        -I <path>       add a directory to the include path
        -n <name>       set the name of a Parallax Wi-Fi module
        -p <port>       serial port
        -P              show all serial ports
        -r              run program after downloading (useful with -e)
        -R              reset the Propeller
        -s              do a serial download
        -t              enter terminal mode after the load is complete
        -T              enter pst-compatible terminal mode after the load is complete
        -v              enable verbose debugging output
        -W              show all discovered wifi modules
        -?              display a usage message and exit
    file:               binary file to load (.elf or .binary)
    
  • -k means to prompt the user before exiting; it acts to "k"eep the terminal window open so error messages don't flash by too fast to read. It's something I added to proploader, and I guess I forgot to update the usage() message for it.
  • yetiyeti Posts: 818
    edited 2019-10-26 10:48
    @ersmith ... nono ... your version (totalspectrum/PropLoader) has "-k" and "-q" and I think "upstream" (parallaxinc/PropLoader) should adopt both too. The versions have diverged a bit. Both now have commits the other one does not have.
    $ git pull
    Already up to date.
    $ git log --max-count=1
    commit 91922307854c6de4ea2774ab4383a2588dc9b822 (HEAD -> master, origin/master, origin/HEAD)
    Author: Eric Smith <ersmith@totalspectrum.ca>
    Date:   Mon Oct 15 13:52:17 2018 -0300
    
        added -k flag to prompt before exit
    $ proploader -? | awk 'NR==1 || /-[kq]/'
    PropLoader v1.0-41 (2019-07-15 17:52:52 g9192230)
        -k              prompt before exiting due to an error
        -q              during terminal display check for exit status from Propeller
    
  • How does the -q option work? Does the prop send a character string that causes the terminal emulator to exit?
  • Dave Hein wrote: »
    How does the -q option work? Does the prop send a character string that causes the terminal emulator to exit?

    Yes, the sequence $FF $00 $xx indicates that the terminal emulator should exit with code $xx. That particular sequence is not a legal UTF-8 character, so it should generally be safe in text output. But obviously there are binary applications for which we don't want to treat any sequences specially, so "-q" is not the default.
  • yetiyeti Posts: 818
    edited 2019-10-26 16:08
    @"Dave Hein" .. yes.

    I think "-q" started to show up in PropGCC's "propeller-load" and turned out to be useful for automating test snippets by the propeller program being able to actively close the terminal routines and is available in "propeller-load", Eric's "PropLoader" version and a not yet accepted PR for "p1load" (it only lacks the "-q" option detection, the terminal stuff already has code for handling that exit). Maybe SpinSim would benefit from it too? Just for compatibility with other loaders? Currently it terminates cleanly when the last cog is shut down which often is [good enough]™.

    "propeller-load -?" explains it:
             [ -q ]            quit on the exit sequence (0xff, 0x00, status)
    
    Sending "255, 0, status" will terminate the terminal and "status" shall be the exit code of the loader.
  • JRoarkJRoark Posts: 1,215
    edited 2019-10-26 17:11
    All: Good input on the -k option. Makes sense! Thank you one and all.

    @ersmith This is getting awfully close to being nitpicking, but would you consider adding a "Select All" function to the "Edit" menu in FlexGui? I'm working with some decent size files and it would make things smoother sometimes. And, since you've got the FlexGUI code open anyway, (cough-cough), is there any chance you could also add that same feature to the right mouse button menu as well?

    Fair warning: I'm also fixin' to ask you for a pop-up ASCII character chart as well, (and likely in two flavors: Propeller, and traditional ASCII) but I sort of wanted to wait until you were done cussin' me for the first feature request. :smiley:

    I should note that bribes for said modifications may be available. If you'll PM me an address and the name of your favorite imbibement, I'll have a discussion with a certain "jolly old elf" shortly...
  • When using FlexGUI 4.0.1, under Win10 and coding in BASIC for the FLiP:

    @ersmith There seems to be a bug in the floating point comparisons. It appears that the comparison operators are not handling the sign of a floating point number properly. The code:
    OPTION EXPLICIT
    CONST HEAPSIZE = 4092
    
    	dim cnt as single
    	dim cnt_Min as single
    	dim cnt_Max as single
    
    	cnt = 0.0
    	cnt_MAX = -999.0   'set our MAX to a very low number initially
    	cnt_MIN = 999.0    'set our MIN to a very high number initially
    
    	for cnt = -20.0 to +20.0 step 2.0
    		if cnt > cnt_MAX then 
    			cnt_MAX = cnt   'save new maximum value
    		end if
    
    		if cnt < cnt_MIN then 
    			cnt_MIN = cnt   'save new minimum value
    		end if
    		print "Cnt: ";cnt, "  Min: "; cnt_MIN, "  Max: "; cnt_Max
    	next cnt
    

    The result:
    Cnt: -20.000      Min: -20.000    Max: -999.00
    Cnt: -18.000      Min: -18.000    Max: -999.00
    Cnt: -16.000      Min: -16.000    Max: -999.00
    Cnt: -14.000      Min: -14.000    Max: -999.00
    Cnt: -12.000      Min: -12.000    Max: -999.00
    Cnt: -10.000      Min: -10.000    Max: -999.00
    Cnt: -8.0000      Min: -8.0000    Max: -999.00
    Cnt: -6.0000      Min: -6.0000    Max: -999.00
    Cnt: -4.0000      Min: -4.0000    Max: -999.00
    Cnt: -2.0000      Min: -2.0000    Max: -999.00
    Cnt: 0.0000       Min: -2.0000    Max: 0.0000
    Cnt: 2.0000       Min: -2.0000    Max: 2.0000
    Cnt: 4.0000       Min: -2.0000    Max: 4.0000
    Cnt: 6.0000       Min: -2.0000    Max: 6.0000
    Cnt: 8.0000       Min: -2.0000    Max: 8.0000
    Cnt: 10.000       Min: -2.0000    Max: 10.000
    Cnt: 12.000       Min: -2.0000    Max: 12.000
    Cnt: 14.000       Min: -2.0000    Max: 14.000
    Cnt: 16.000       Min: -2.0000    Max: 16.000
    Cnt: 18.000       Min: -2.0000    Max: 18.000
    Cnt: 20.000       Min: -2.0000    Max: 20.000
    
  • @JRoark ... nice! \o/
    I'm really surprised that this wasn't found earlier!
  • Wow, that was a nasty bug @JRoark. Thanks for finding it. The root cause was a typo in the floating point comparison function, which should be fixed now.

    I've uploaded version 4.0.2 to the usual places.

    As for your GUI changes, I may be able to do a "select all" (I haven't had a chance to look at it yet). An ASCII table seems more like the kind of thing that belongs in an external tool.
  • JRoarkJRoark Posts: 1,215
    edited 2019-10-27 01:52
    FlexGUI version 4.0.2 fixes the floating point comparison issue nicely! Cool!
  • JRoarkJRoark Posts: 1,215
    edited 2019-10-27 02:16
    When using FlexGUI 4.0.2, under Win10 and coding in BASIC for the FLiP:

    @ersmith The "Edit -> Search" feature in FlexGUI seems to have broken. The search dialog comes up normally, and it allows you to specify the text to search, but when you click "Next", it all goes kablooey. This is the error that pops up:
    bad command "tag": must be configure, cget, invoke, instate, state, or identify
    bad command "tag": must be configure, cget, invoke, instate, state, or identify
        while executing
    "$w tag ranges hilite"
        (procedure "searchrep'next" line 3)
        invoked from within
    "searchrep'next .toolbar.compileRun"
        invoked from within
    ".sr.bn invoke "
        invoked from within
    ".sr.bn instate !disabled { .sr.bn invoke } "
        invoked from within
    ".sr.bn instate pressed { .sr.bn state !pressed; .sr.bn instate !disabled { .sr.bn invoke } } "
        (command bound to event)
    
    That isn't remotely a show stopper, but when you roll-out the next version it would be nice to have the search feature again.

    Edited to add:
    There also seems to be a "turnaround" bug on the USB port. If, after downloading code, you immediately issue a "PRINT" statement, the first dozen (or more) characters displayed will be garbage. If however, you put a short delay before the PRINT statement (50 mS seems to work really well for me), then it's fine.

    This code causes garbage on the USB terminal:
    	' pauseMS(50)   '<- delay is commented out
    	print "The quick brown fox... (aw phooey... stop me if you've heard this one)"
    
    gives:
    
    Opening file 'D:/Flex2Gui/flexgui/test.binary'
    Downloading file to port COM4
    1908 bytes sent
    Verifying RAM
    Download successful!
    [ Entering terminal mode. Type ESC or Control-C to exit. ]
     ÇÇÇ ÇÇÇÇ Ç  Ç ÇÇÇÇÇÇ Ç╪∞φÉbrown fox... (stop me if you've heard this one)
    
    This code works fine every time:
    	pauseMS(50)  '<- 50 mS delay
    	print "The quick brown fox... (aw phooey... stop me if you've heard this one)"
    
    gives:
    
    Opening file 'D:/Flex2Gui/flexgui/test.binary'
    Downloading file to port COM4
    2128 bytes sent
    Verifying RAM
    Download successful!
    [ Entering terminal mode. Type ESC or Control-C to exit. ]
    The quick brown fox... (stop me if you've heard this one)
    

    The "turnaround" bug is machine-speed dependent. On a very fast machine, it's very evident. On an old clunker-box, I cant replicate it at all.
Sign In or Register to comment.