Shop OBEX P1 Docs P2 Docs Learn Events
FlexProp: a complete programming system for P2 (and P1) — Parallax Forums

FlexProp: a complete programming system for P2 (and P1)

ersmithersmith Posts: 6,066
edited 2023-12-30 17:18 in Propeller 2
Summary: FlexProp is a GUI and compiler that lets you develop programs in Spin 1, Spin 2, BASIC, and C for the Prop 1 and Prop 2. You can mix objects written in the different languages, and it produces fast assembly code as output. Any combination of languages and processors is OK, e.g. you can compile Spin 1 code for P2 (as long as any assembly in DAT sections is P2 compatible) and Spin 2 code for P1 (again, any user provided assembly language has to be P1 compatible in this case).

The latest version may be found at my patreon page ( https://patreon.com/totalspectrum ) or from github ( https://github.com/totalspectrum/flexprop/releases ). Binaries are provided for both Windows and Mac -- the zip file has both. The program runs on Linux too, but you'll have to build it from source there.

Update December 2023:

The most recent release is 6.8.x, which brings the Spin2 language features up to par with PNut v43. It also has a large number of bug fixes and optimization improvements, some new builtin BASIC functions for date and time, support for the Parallax flash file system, ARGv parameters for loadp2 and CHAIN, and support for more C standard library functions.

Update May 2023:

The most recent release is 6.1.x, which has P1 and P2 bytecode output, improved Spin2 compatibility, support for project files, and support for creating .zip files of the source code.

Update September 2021:

FlexProp is now in the 5.9.x series, which is in some sense a "preview" for version 6.0 which will have support for P1 bytecode and a new P2 bytecode output. That is, you can now compile Spin, C, and BASIC programs to bytecode as well as to assembly. The bytecode binaries will be smaller, but slower, than the default assembly language. Bytecode support isn't complete in 5.9.x, but there are a lot of other new features (such as Spin2 floating point support, and support for P2 BRK debugging) which make it worth upgrading. Many thanks to @Wuerfel_21 for her contributions of BRK debugging and P1 bytecode support!

Update May 2021:

The latest version is 5.5.0, which has a lot of bug fixes and improvements.

Update October 2020:

FlexGUI has been renamed to FlexProp to avoid conflict with another product. The functionality is still the same: it is a simple GUI for programming the P1 and P2 in Spin1, Spin2, PASM, BASIC, and C. The languages may be mixed together, so for example you can call a Spin driver from a C program. Output is fast PASM code.

The latest release is available from https://github.com/totalspectrum/flexprop/releases : download the "flexprop.zip", unzip it in some convenient location (e.g. your desktop), and run the "flexprop.exe" program.

Older information

There is a new release of flexgui, a GUI providing a complete programming system for P2 including PASM, Spin, BASIC, and C, and now including a version of micropython and a simple terminal interface for the P2 ROM. It may be downloaded from https://github.com/totalspectrum/flexgui/releases/latest; look for the "flexgui.zip" file for the Windows binary release.

New in this release are menu options for the ROM monitor and TAQOZ, improved C support, and many bug fixes.

If you haven't used FlexGUI yet, or haven't tried it in a while, here are some of its features:

General
* Both Propeller1 and Propeller2 are supported
* Supports PASM, Spin 1, Spin 2, BASIC, and C
* View output PASM code
* Built in terminal emulator
* GUI checks files for external changes, so you may use any editor and compile in FlexGUI
* Options for interacting directly with P2 ROM monitor and ROM TAQOZ
* Micropython for P2 sample included

PASM Support
* Both P1 and P2 assembly language supported
* Preprocessor supporting `#define`, `#ifdef`, and `#include`
* Absolute address operator `@ @ @`
* Warnings for common mistakes like forgetting `#` in a jump
* Can compile assembly-only files (no Spin methods required)

Spin support

Both the original Spin 1 and new Spin 2 languages are supported. The Spin 1 support has a number of enhancements:
* Generates optimized PASM instead of bytecode
* `case_fast` to force `case` to produce a jump table
* Conditional expressions like `(x < y) ? x : y`
* Inline assembly inside PUB and PRI functions
* Object pointers
* `pub file` and `pri file` to include functions from other languages (C, BASIC)
* Multiple return values and assignments, e.g. `x,y := y,x`
* Default parameter values for functions
* Optional type specifiers for function parameters and return values
* Automatic passing of strings as pointers in some cases
* Unsigned operators `+/`, `+//`, `+<`, `+=<`, `+>`, `+=>`
* Spin2 operators `\`, `<=>`


BASIC Support

fastspin supports a fairly complete version of BASIC, based on traditional Microsoft BASICs. Please see `doc/basic.md` for details. Notable features are:
* Structured programming features
* Line numbers are optional
* Garbage collected memory allocation
* Support for classes, and importing Spin objects as classes
* Function closures and immediate functions
* `try` / `catch`
* Inline assembly
* Generic functions and templates

C Language Support

fastspin supports a C dialect called FlexC, which is intended to be C99 compatible with some C++ extensions. It is not yet complete. Notable enhancements are:
* Inline assembly (similar to MSVC)
* Simple classes, including using Spin and BASIC objects as C classes
* Reference parameters using `&`
* GCC style statement expressions
* Header files may specify linking information for libraries
* Several useful builtin functions
«13456755

Comments

  • Windows installed without a snag. Ran @localroger "Game of Life" on LED Matrix on P2EVAL.

    Good job!
  • My version (Windows) defaulted to P1, but it was easy enough to change.
  • Attention BASIC programmers: FlexBASIC is the *bomb*! You owe it to yourself to play with this. It is stable and quite fast. Quick and painless install. The ability to drop down into assembly language is a really nice touch. I now have several projects that are over 2000 lines of code and it just flat works.

    Cant wait to see how it does with the incoming P2 boards!

    @ersmith You have done an amazing job with the Flex suite.
  • cgraceycgracey Posts: 14,204
    JRoark wrote: »
    Attention BASIC programmers: FlexBASIC is the *bomb*! You owe it to yourself to play with this. It is stable and quite fast. Quick and painless install. The ability to drop down into assembly language is a really nice touch. I now have several projects that are over 2000 lines of code and it just flat works.

    Cant wait to see how it does with the incoming P2 boards!

    @ersmith You have done an amazing job with the Flex suite.

    That's great news! Good job, JRoark and Ersmith.
  • I see a mention of MicroPython. Can I use this new version as a replacement for tools like Thonny IDE?
  • JonnyMacJonnyMac Posts: 9,144
    edited 2019-11-09 19:20
    I just tried it -- a terminal window comes up with the uPython prompt. Pretty cool.

    The default terminal doesn't handle Backspace, nor Ctrl+C like a typical Python terminal (e.g., Idle). Still, it's really cool to have Python on a Propeller!
  • Whoo!!

    The availability of uPython for P2 May be what gets me into it!

    Congratulations, ersmith on this! This is a very cool IDE!
  • Cluso99Cluso99 Posts: 18,069
    WOW!!!
    Thanks Eric. You're doing an amazing job here :smiley:

    I just installed flexgui on my PC under W10. I unzipped and renamed the directory flexgui 4.0.3 and then moved to C:\P2\ where I also have older versions of flexgui similarly named with their versions. When I opened flexgui and looked at the options, I note that when I looked at Commands|Configure Commands and then used the Cancel option, it did in fact create and save a default configuration in the same directory (C:\P2\flexgui 4.0.3) called ".flexgui.config". The config looks fine but I was not expecting the cancel option to do anything. Is this normal?

    Of course , now I need to find time to try flexgui. I've been using fastspin from the command line previously, and PropTool to edit P2ASM. I should move to VSCode especially since I did a P1/P2 addon a year ago but don't use it :(
  • cgracey wrote: »
    That's great news! Good job, JRoark and Ersmith.

    For the record, I'm just some goober who is using it and loving it. Didn't write a single line of code and I have zero comprehension about the internals. Eric is the guy who gets all the credit.

    (I just have a talent for blowing things up). :blush:

  • JRoark wrote: »
    Attention BASIC programmers: FlexBASIC is the *bomb*!
    JRoark wrote: »
    (I just have a talent for blowing things up). :blush:
    \\o   o//   \o/   A perfect fit!   \o/   \\o   o//
  • Hi @ersmith , does your flexgui work on Linux/Mac OS X with fastspin? I downloaded your latest 4.0.3 version and can start flexgui using Wish TCL/TK on the Mac but fastspin doesn't seem to be supplied. I didn't find a way to make it from source yet either unless it comes from elsewhere, as the spin2cpp folder is missing its files. What pieces/steps am I missing here? Is fastspin usable on non-Windows platforms?

    Thanks,
    Roger.


    "/Users/roger/Downloads/flexgui-4.0.3/bin/fastspin" -2b -l -O1 -I "/Users/roger/Downloads/flexgui-4.0.3/include" "/Users/roger/Downloads/flexgui-4.0.3/samples/hello.spin"
    couldn't execute "/Users/roger/Downloads/flexgui-4.0.3/bin/fastspin": no such file or directory
    Finished at Sun Nov 10 09:09:27 2019
  • Publison wrote: »
    My version (Windows) defaulted to P1, but it was easy enough to change.

    Odd, I haven't seen that before. Glad you were able to sort it out though.
    JonnyMac wrote: »
    I just tried it -- a terminal window comes up with the uPython prompt. Pretty cool.

    The default terminal doesn't handle Backspace, nor Ctrl+C like a typical Python terminal (e.g., Idle). Still, it's really cool to have Python on a Propeller!

    Ah, I forgot that I have my cmd.exe set to default to ANSI mode. To do that create a registry key HKEY_CURRENT_USER\Console\VirtualTerminalLevel of type DWORD and value 1.

    I'll try to figure out some way to automate that in the next FlexGUI release.

    Thanks,
    Eric
  • rogloh wrote: »
    Hi @ersmith , does your flexgui work on Linux/Mac OS X with fastspin? I downloaded your latest 4.0.3 version and can start flexgui using Wish TCL/TK on the Mac but fastspin doesn't seem to be supplied. I didn't find a way to make it from source yet either unless it comes from elsewhere, as the spin2cpp folder is missing its files. What pieces/steps am I missing here? Is fastspin usable on non-Windows platforms?

    You'll need to do a "git submodule update --recursive" to grab the spin2cpp and loadp2 subdirectories. I cannot build on Mac myself, not having a Mac machine, but someone supplied a "Makefile.mac" which might do the trick (it may have bit rotted so it may need a bit of tweaking).

    I develop flexgui on Linux, so it definitely works there :) although I build loadp2 and fastspin "by hand".
  • Ok thanks Eric, I'll have a try later.
  • dgatelydgately Posts: 1,630
    edited 2019-11-10 01:38
    ersmith wrote: »
    rogloh wrote: »
    Hi @ersmith , does your flexgui work on Linux/Mac OS X with fastspin? I downloaded your latest 4.0.3 version and can start flexgui using Wish TCL/TK on the Mac but fastspin doesn't seem to be supplied. I didn't find a way to make it from source yet either unless it comes from elsewhere, as the spin2cpp folder is missing its files. What pieces/steps am I missing here? Is fastspin usable on non-Windows platforms?

    You'll need to do a "git submodule update --recursive" to grab the spin2cpp and loadp2 subdirectories. I cannot build on Mac myself, not having a Mac machine, but someone supplied a "Makefile.mac" which might do the trick (it may have bit rotted so it may need a bit of tweaking).

    I develop flexgui on Linux, so it definitely works there :) although I build loadp2 and fastspin "by hand".
    I initially use "git clone --recursive https://github.com/totalspectrum/flexgui.git&quot; to get flexgui sources as well as sources from sub-modules. Then, use "git submodule update --recursive" to update when ersmith has made changes. Then:
    to build for macOS:
    $ make -f Makefile.mac 
    make: *** No rule to make target `spin2gui.tcl', needed by `spin2gui.zip'.  Stop.
    
    ignore this error as you probably don't need to build the .zip file, for macOS (it builds a WIN .exe app version)
    
    Then to execute flexgui.tcl, use the XQuartz, X11 runtime environment (get it from: https://www.xquartz.org). Launch the XQuartz app... This allows flexgui to use xterm, since flexgui's config is not really set up for macOS's Terminal app and wants to use xterm to communicate with the P2.
    Within XQuartz, choose 'xterm' from the Applications menu (or type a Command-T )...
    In the xterm terminal window:
    $ cd PATH-TO-flaxgui-DIRECTORY   <== the PATH to where you downloaded flexgui with "git clone"
    $ wish flexgui.tcl
    
    That will give you a new Wish-app based execution of flexgui that allows building and running an xterm within flexgui.

    I actually git clone Spin2Cpp and Loadp2 seperately and put their binaries in a common Propeller tools directory (/opt/parallax/bin). Then I set my $PATH environment in the .profile file within my home directory. Like this:
    export PATH=/opt/parallax:/opt/parallax/bin:/opt/parallax/lib:$PATH
    
    When I launch any terminal (Terminal app or xterm within XQuartz), macOS will look in those directories for tools like: loadp2, fastspin, spin2cpp, propeller-elf-gcc, etc... I set up flexgui's "Configure Commands" Compile command to just exec "fastspin" & the Run command to exec loadp2. It finds them in /opt/parallax/bin (which I copy the tools to whenever they are updated).
    flexgui-config.png
    dgately

    490 x 498 - 143K
  • AwesomeCronkAwesomeCronk Posts: 1,055
    edited 2019-11-10 02:43
    Can I connect to a non-P2 uPython device?

    Also: Where do I get propeller-loader.exe? Where do I install it?
  • Can I connect to a non-P2 uPython device?

    No. I'm sorry if I gave the wrong impression -- FlexGUI isn't a uPython IDE. It's an IDE for developing PASM, Spin, BASIC, and C programs on the P2. It's also able to *run* uPython on the P2, and Forth (via the built-in TAQOZ in the ROM) and Lisp (via the proplisp program in the sample directory). But it doesn't really provide any tools to help you develop python, forth, or lisp programs, just the basic ability to run them on the P2.
    Also: Where do I get propeller-loader.exe? Where do I install it?

    Sounds like there's something out of date in the documentation. You don't need propeller-loader.exe, you can use the proploader.exe that's already in the bin folder to run programs on P1. Just go to "Commands > Configure Commands..." and press the "P1 defaults" button and you should be all set.


  • JonnyMac wrote: »
    I just tried it -- a terminal window comes up with the uPython prompt. Pretty cool.

    The default terminal doesn't handle Backspace, nor Ctrl+C like a typical Python terminal (e.g., Idle). Still, it's really cool to have Python on a Propeller!

    If you have the P2-ES accessory set then there's an alternative to editing the Windows registry to force ANSI support in cmd.exe. Plug the "Serial Host" board in to pin group 16 and the "A/V" board in to pin group 48, hook up a USB keyboard and VGA monitor, and do your typing and display that way. You can also put in an SD card with the pye.py program from samples/upython and use pye as an editor for Python code on the SD card.
  • Thanks for the clarification!
  • Cluso99 wrote: »
    I just installed flexgui on my PC under W10. I unzipped and renamed the directory flexgui 4.0.3 and then moved to C:\P2\ where I also have older versions of flexgui similarly named with their versions. When I opened flexgui and looked at the options, I note that when I looked at Commands|Configure Commands and then used the Cancel option, it did in fact create and save a default configuration in the same directory (C:\P2\flexgui 4.0.3) called ".flexgui.config". The config looks fine but I was not expecting the cancel option to do anything. Is this normal?
    Sorry, I forgot to reply to this one. ".flexgui.config" is always created when flexgui.exe exits, because it contains things like the last directory visted, font selected, and window positions as well as the command configurations.
  • Cluso99Cluso99 Posts: 18,069
    ersmith wrote: »
    Cluso99 wrote: »
    I just installed flexgui on my PC under W10. I unzipped and renamed the directory flexgui 4.0.3 and then moved to C:\P2\ where I also have older versions of flexgui similarly named with their versions. When I opened flexgui and looked at the options, I note that when I looked at Commands|Configure Commands and then used the Cancel option, it did in fact create and save a default configuration in the same directory (C:\P2\flexgui 4.0.3) called ".flexgui.config". The config looks fine but I was not expecting the cancel option to do anything. Is this normal?
    Sorry, I forgot to reply to this one. ".flexgui.config" is always created when flexgui.exe exits, because it contains things like the last directory visted, font selected, and window positions as well as the command configurations.
    Thanks Eric. Good to know.
  • Any benchmarks to get an idea of the performance of the BASIC?
  • Mickster wrote: »
    Any benchmarks to get an idea of the performance of the BASIC?

    I’m not aware of any BASIC-specific benchmarks per se, but I can tell you from personal experience it is entirely possible to toggle an output pin on the FLiP module at 5 mhz without breaking a sweat. Not too shabby!

    The BASIC code gets compiled down to PASM. Its pretty efficient. I’ll grant you that its slower than pure assembly, and to some extent C, but the deployment/debug time is so much faster.

    You might download this critter and wiggle some bits. I think you’ll be impressed. And if not, change gears and play with PASM, Spin, C or uPython.... without ever leaving the FlexGui editor/compiler/suite. Thats just darned-Skippy impressive... at least to me. :)



  • Yup, that is PDQ...I think that would be like PropBasic LMM code.
  • Surely uPython is no faster, though? It's been a bit of a dog in my limited experience.
  • So let's say I need to do some SPI stuff. I can utilise an existing PASM object, right or is it supported directly by FastBasic?
  • JRoarkJRoark Posts: 1,215
    edited 2019-11-11 00:26
    Write it in Spin, call it as a class from Flex. Done. :)

    Edited to add: I have not personally called PASM from FlexBASIC, but I’ve got a fiver that says it can be done. And indeed you can put PASM code inline with FlexBASIC. Lets get @ersmith to weigh-in here for a non-fanboy answer.
  • Mickster wrote: »
    Any benchmarks to get an idea of the performance of the BASIC?

    Here's a bit-banging benchmark; it streams 32 bit words out a pin from HUB memory as quickly as it can. I've provided fastspin basic and generic C versions. I'll also have to confess that this is a benchmark that fastspin is particularly good at, because bit-banging is something I've tried to optimize. If you have some more generic benchmarks I'd be interested in trying those.

    The P1 numbers are all in LMM mode; P2 are all in native mode. The command lines used for P2 are:
    fastspin -2 -O2 bitbang.c
    fastspin -2 -O2 bitbang.bas
    p2gcc bitbang.c
    riscv-none-embed-gcc -Triscvp2.ld -D__propeller2__ -Os bitbang.c
    catalina -p2 -O3 -C NATIVE -D __propeller2__ -lci bitbang.c
    

    I haven't got a PropBASIC version of the benchmark. My expectation would be that PropBASIC LMM mode would come in about a third to a quarter of the speed of fastspin LMM (so around 400K cycles). fastspin has FCACHE (and hence avoids LMM overhead completely in the inner loop) and has an optimizer, both of which will improve its performance over PropBASIC, although carefully written code can mitigate the missing optimizer.

    P2 results (cycles to send 256 longs, lower is better):
    fastspin (C):    51813 cycles
    fastspin (BAS):  86015 cycles
    p2gcc:          277382 cycles
    riscvp2:        308260 cycles
    Catalina:       471283 cycles
    

    P1 results:
    fastspin (C):   139648 cycles
    fastspin (BAS): 106928 cycles
    PropGCC:        287392 cycles
    Catalina:      2144688 cycles
    

    You'll notice that the compilers are much closer together on P2, because hubexec presents a more even target for the compiler (on P1 the performance of the LMM interpreter pretty much dominates things). If you leave the -O2 flag off of fastspin for P2 the performance gets even closer, since it removes the LUT caching that fastspin does in -O2.

    The fastspin C version on P2 benefits from the built-in dirh/dirl instructions, which the BASIC version does not, which explains why C is faster there. Conversely, on P1 the BASIC language output() array provides the optimizer with more information than the C based OUTA, so on P1 the BASIC code is a bit faster than C.
  • JRoark wrote: »
    Write it in Spin, call it as a class from Flex. Done. :)

    Edited to add: I have not personally called PASM from FlexBASIC, but I’ve got a fiver that says it can be done. And indeed you can put PASM code inline with FlexBASIC. Lets get @ersmith to weigh-in here for a non-fanboy answer.

    It depends on what you mean by calling PASM from FlexBASIC, exactly, but I think that for all practical purposes it can be done. Certainly you can take an existing (or new) Spin+PASM object and call it directly from BASIC. You can also write a BASIC function whose contents are almost entirely PASM, although often it's useful to include some variable declarations and perhaps a return statement outside of the asm block.
  • Outstanding work, Eric. You need some kind of award for this! :cool:
Sign In or Register to comment.