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

ersmithersmith Posts: 3,640
edited 2019-11-25 - 01:14:00 in Propeller 2
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 micropython and ROM 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, 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

The original Spin language is supported, with some 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
FlexGUI, a GUI for programming the P1 and P2 in Spin, PASM, BASIC, and C.
Help support its development at Patreon or PayPal.
«134

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.
  • 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?
    Returning to Spin after two months of not coding micros at all, forgetting to use :=
  • JonnyMacJonnyMac Posts: 6,298
    edited 2019-11-09 - 19:20:10
    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!
    Jon McPhalen
    Hollywood, CA
    It's Jon or JonnyMac -- please do not call me Jonny.
  • Whoo!!

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

    Congratulations, ersmith on this! This is a very cool IDE!
    Returning to Spin after two months of not coding micros at all, forgetting to use :=
  • 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 :(
    My Prop boards: P8XBlade2 , RamBlade , CpuBlade , TriBlade
    P1 Prop OS (also see Sphinx, PropDos, PropCmd, Spinix)
    Website: www.clusos.com
    P1: Tools (Index) , Emulators (Index) , ZiCog (Z80)
    P2: Tools & Code , Tricks & Traps
  • 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//
    ◁ propeller-wiki ▷ ◁ FastSpin ▷ ◁ Help Spin at RosettaCode.org ▷ ◁ No Source – No Go! ▷ ◁ DK-E ▷ ◁ :-D ▷ ◁ Stay OmmmmmmPtimistic! ▷ ◁ Why Asimov's Laws of Robotics Don't Work ▷ ◁ DNA is a four letter word. ▷ ◁ Stop slavery! Free all mitochondria! ▷
  • 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
    FlexGUI, a GUI for programming the P1 and P2 in Spin, PASM, BASIC, and C.
    Help support its development at Patreon or PayPal.
  • 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".
    FlexGUI, a GUI for programming the P1 and P2 in Spin, PASM, BASIC, and C.
    Help support its development at Patreon or PayPal.
  • Ok thanks Eric, I'll have a try later.
  • dgatelydgately Posts: 1,137
    edited 2019-11-10 - 01:38:32
    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" 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
    Livermore, CA (50 miles SE of San Francisco)
  • AwesomeCronkAwesomeCronk Posts: 840
    edited 2019-11-10 - 02:43:42
    Can I connect to a non-P2 uPython device?

    Also: Where do I get propeller-loader.exe? Where do I install it?
    Returning to Spin after two months of not coding micros at all, forgetting to use :=
  • 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.


    FlexGUI, a GUI for programming the P1 and P2 in Spin, PASM, BASIC, and C.
    Help support its development at Patreon or PayPal.
  • 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.
    FlexGUI, a GUI for programming the P1 and P2 in Spin, PASM, BASIC, and C.
    Help support its development at Patreon or PayPal.
  • Thanks for the clarification!
    Returning to Spin after two months of not coding micros at all, forgetting to use :=
  • 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.
    FlexGUI, a GUI for programming the P1 and P2 in Spin, PASM, BASIC, and C.
    Help support its development at Patreon or PayPal.
  • 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.
    My Prop boards: P8XBlade2 , RamBlade , CpuBlade , TriBlade
    P1 Prop OS (also see Sphinx, PropDos, PropCmd, Spinix)
    Website: www.clusos.com
    P1: Tools (Index) , Emulators (Index) , ZiCog (Z80)
    P2: Tools & Code , Tricks & Traps
  • Any benchmarks to get an idea of the performance of the BASIC?
    Failure is not an option...it's bundled with the software.
  • 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.
    Failure is not an option...it's bundled with the software.
  • Surely uPython is no faster, though? It's been a bit of a dog in my limited experience.
    Failure is not an option...it's bundled with the software.
  • 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?
    Failure is not an option...it's bundled with the software.
  • JRoarkJRoark Posts: 194
    edited 2019-11-11 - 00:26:03
    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.
    FlexGUI, a GUI for programming the P1 and P2 in Spin, PASM, BASIC, and C.
    Help support its development at Patreon or PayPal.
  • 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.
    FlexGUI, a GUI for programming the P1 and P2 in Spin, PASM, BASIC, and C.
    Help support its development at Patreon or PayPal.
  • Outstanding work, Eric. You need some kind of award for this! :cool:
    Failure is not an option...it's bundled with the software.
Sign In or Register to comment.