New BASIC compiler for Prop1 and Prop2

1246714

Comments

  • David Betz wrote: »
    How do you handle the "main" program? It looks like it consists of anything outside of a function definition but does it have to be all together or can you have it interspersed between function definitions?

    It can have functions interspersed or whatever. All the top level statements are gathered up together to make a main program. That's callable from Spin as "foo.program". So for example:
    ' bar.bas
    print "hello"
    
    ' foo.spin
    obj
      b: "bar.bas"
    PUB demo
      b.program
      b.program
    
    Then foo.binary prints "hello" twice.
  • ersmith wrote: »
    David Betz wrote: »
    How do you handle the "main" program? It looks like it consists of anything outside of a function definition but does it have to be all together or can you have it interspersed between function definitions?

    It can have functions interspersed or whatever. All the top level statements are gathered up together to make a main program. That's callable from Spin as "foo.program". So for example:
    ' bar.bas
    print "hello"
    
    ' foo.spin
    obj
      b: "bar.bas"
    PUB demo
      b.program
      b.program
    
    Then foo.binary prints "hello" twice.
    That sounds like a good idea. I may do that with my language as well. It's a bit friendlier than requiring an explicit main function definition.

  • ersmithersmith Posts: 2,479
    edited October 7 Vote Up1Vote Down
    [Edited to remove the attachment, that will go in the first message to this thread]

    I've updated the compiler quite a bit, and I think the BASIC is usable for some purposes now. I still need to get the I/O routines hooked up so that you can do OPEN/PRINT #, but otherwise I think the main features are there (and for now you can use Spin classes directly for I/O).

    Documentation for the BASIC is in docs/basic.md. The main compiler is "fastspin", and to run it you just do something like:
    # compile a .spin file, produces mydemo.binary
    fastspin mydemo.spin
    # compile a BASIC file, produces basdemo.binary
    fastspin basdemo.bas
    # compile the BASIC file for Prop2, produces basdemo.binary that is for Prop2
    fastspin -2 basdemo.bas
    

    Any feedback would be very welcome, e.g. what isn't clear in the docs, what missing features are most important, what unexpected problems did you run into...

  • Taking shape very nicely :cool: :-D
    Failure is not an option...it's bundled with the software.
  • I've updated the first message in this thread with the most recent beta. This now has support for inline assembly, and for OPEN #/PRINT # and PRINT USING (although the PRINT USING support is still very incomplete). So for example a simple program to print to a VGA monitor, using an existing Spin object, would look like:
    dim v as class using "vga_text_010.spin"
    
    '' start up the VGA
    pausems(1000)
    v.start(16 + 7)
    pausems(1000)
    
    ' needed for C3: enable VGA by driving pin 15 low
    direction(15) = output
    output(15) = 0
    
    ' open BASIC I/O handle
    open SendRecvDevice(@v.out, nil, @v.stop) as #2
    
    ' print messages
    ' note: the VGA out routine does not use standard CR/LF,
    ' so we have to send an explicit CR (\13) and skip the line feed
    ' by ending the print in ;
    '
    for i = 1 to 100
      print #2, using "hello ###, vga world  "; i, \13;
      pausems(100)
    next
    
    ' loop forever
    do
    loop
    
  • RaymanRayman Posts: 8,907
    edited October 10 Vote Up0Vote Down
    Is this fastspin.exe the same one that can also generate P2 code?
    Is there command line usage info somewhere?

    Never mind... Figured out what a .md file is...
    Prop Info and Apps: http://www.rayslogic.com/
  • Rayman wrote: »
    Is this fastspin.exe the same one that can also generate P2 code?
    Is there command line usage info somewhere?
    Yes, all versions of fastspin for the past few years have had a -2 switch to generate P2 code. I mainly develop on a P1 machine, so some of the libary functions may be missing P2 versions, but the basic compiler itself should be fine.

    You've already figured out that the README.md is a plain text file (maybe I should rename it README.txt, but then github wouldn't parse the markdown in it). fastspin also prints a usage message if you run it with no arguments.

    I guess I should also make it clear that in P2 mode (when -2 is given on the command line) the PASM that fastspin accepts is P2 assembler rather than P1, and it's able to assemble any P2 program. The Spin and BASIC compilers should work fine for P2 output (although as I mentioned the BASIC libraries haven't been tested as thoroughly on P2). The default is to produce a .binary file containing the executable code, so just:
      fastspin myspin.spin
    
    produces a P1 executable "myspin.binary", and
      fastspin -2 myspin.spin
    
    produces a P2 executable "myspiin.binary". Replace "myspin.spin" with "myprog.bas" to compile a BASIC program. BASIC and Spin programs can include each other as objects and interoperate freely.
  • I have to say that fastspin is amazing work! One tool gives us Spin, PASM, and BASIC for the P1 and P2. Thanks, Eric!

    P.S. When are you going to add C and C++? :smile:
  • David Betz wrote: »
    P.S. When are you going to add C and C++? :smile:
    ...and XMM? :wink:

    ◁ FastSpin ▷ ◁ Stay OmmmmmmPtimistic! ▷ ◁ No Source – No Go! ▷ ◁ Please help: http://rosettacode.org/wiki/Category:Spin ▷ ◁ Why Asimov's Laws of Robotics Don't Work - Computerphile ▷ ◁ DNA is a four letter word. ▷
  • yeti wrote: »
    David Betz wrote: »
    P.S. When are you going to add C and C++? :smile:
    ...and XMM? :wink:
    I assume you mean XMM on P1 since it won't really be needed on P2. Unfortunately, XMM is pretty much dead. Parallax ended up deciding not to use it. It's still there in the compiler but not supported by SimpleIDE or BlocklyProp.
  • David Betz wrote: »
    I have to say that fastspin is amazing work! One tool gives us Spin, PASM, and BASIC for the P1 and P2.
    Thanks, David. I hope some people find it useful :)
    P.S. When are you going to add C and C++? :smile:

    C++, probably never -- it's a huge and very complicated language, as you know! But C isn't really that much different from FreeBasic, under the hood, so once I have the BASIC code stable... who knows? I guess in part it depends on whether there's interest in the whole thing. I'm not sure how many people actually use it.
  • Yeah, C++ is an ugly bear. I've been using it lately and I now remember why I don't really like it. It's overly complicated. I suppose it has to be to address the real-world problems it's trying to address but it's pretty ugly to read and hard to learn. I still prefer C or Lisp or maybe even Python.

    I sure hope fastspin gets a lot of use. It seems like there are many people here who prefer to use either Spin or BASIC and it is an excellent implementation of both.
  • I thought I would give this fastspin a try, especially the BASIC.

    Just for the some of the new forum members, fastspin is a command line program, no GUI IDE. I gave the BASIC a quick try, and it gets compiled to a binary file. The missing part is a method of loading and running the binary file on the Propeller; which I guess, the normal sequence would be is to have the Propeller Tool do that part. Is there any other program out there that would do load and run of the binary file at the command line?

    I am trying to implement the use of the Geany IDE to work with fastspin. Just as an fyi, Geany recognizes the .bas as a FreeBasic file, Geany has a default plugin for FreeBasic.

    With this setup, I guess, it is a little messy going between fastspin at the command line and then having to start up Propeller Tool to get the program to load and run. I guess you really want to use this tool in the way it is used at the moment. Not sure if I want to try some sort of batch file script, in order to automate this whole process.

    I will concentrate on the BASIC part, in order to get a feel for its future use with the Propeller. Have quite a bit to read, in the docs, but if it follows a FreeBasic format, it should go fairly easily, since I am familiar with FreeBasic, we shall see.

    Ray
  • Rsadeika wrote: »
    I thought I would give this fastspin a try, especially the BASIC.

    Just for the some of the new forum members, fastspin is a command line program, no GUI IDE. I gave the BASIC a quick try, and it gets compiled to a binary file. The missing part is a method of loading and running the binary file on the Propeller; which I guess, the normal sequence would be is to have the Propeller Tool do that part. Is there any other program out there that would do load and run of the binary file at the command line?
    Thank you for trying this, Ray! I'm looking forward to any feedback you have.

    For loading and running the binary file on the Propeller, I use David Betz's propeller-load tool for P1, and Dave Hein's loadp2 for P2. Both of those are bundled with fastspin in my spin2gui program (https://github.com/totalspectrum/spin2gui/releases/), which is a really simple IDE for doing P1/P2 development. My typical workflow is to use a command line and do:
    fastspin foo.bas
    propeller-load foo.binary -r -t
    
    I am trying to implement the use of the Geany IDE to work with fastspin. Just as an fyi, Geany recognizes the .bas as a FreeBasic file, Geany has a default plugin for FreeBasic.
    Geany would be really cool to have running. I think it should be possible to have it compile the program with fastspin and then load & run it with propeller-load.

    Cheers,
    Eric
  • I've updated spin2gui to version 1.1.5, which has the latest fastspin compiler (the 1.1.4 release had a fastspin which was several weeks old, and hence missing some of the later improvements to BASIC).
  • Thanks, great Job.


    BTW I just used Geany to write a trivial typewriter program.


    Ron
    Gathemo, france
  • I'm thinking about adding this basic (and maybe the other one too) to SpinEdit. Then, we'd have an all in one tool for P1 and P2...
    Prop Info and Apps: http://www.rayslogic.com/
  • rsut wrote: »
    BTW I just used Geany to write a trivial typewriter program.

    Cool! Was it difficult to get Geany to use fastspin? Were you able to run the output directly from Geany, or did you have to run it separately?

    Cheers,
    Eric
  • Rayman wrote: »
    I'm thinking about adding this basic (and maybe the other one too) to SpinEdit. Then, we'd have an all in one tool for P1 and P2...

    That sounds very nice! Let me know if there are any changes to fastspin that would make this easier for you. I've tried to make it fairly compatible with openspin (for the Spin part, at least) but there may be something I've overlooked.


  • RaymanRayman Posts: 8,907
    edited October 11 Vote Up0Vote Down
    I'm trying to decide if I should color the background or not... I might try it and see what it looks like... Could color subs and/or inline assembly differently...
    Prop Info and Apps: http://www.rayslogic.com/
  • @ersmith

    I am a first time user of Geany so I just created newbasic.bat below

    del %1.err
    newbasic %1.bas /p
    'if not exist %1.err (
    fastspin -e %1.bas
    propeller-load -e %1.eeprom -r -t

    I put the following in the execute box
    newbasic.bat,/%e%f


    It's far from Ideal but works, I need to do something with the batch file to invoke Tera Term.
    No doubt if I wait, you will end up doing it for me and others (: (:


    thanks again
    Ron
    Gathemo, France


  • I just tried the spin2GUI program, and I am not sure if I understand what the Run Binary and Compile & Run commands are supposed to do.

    I have my FLiP module plugged into the USB, and it is using COM3. Now, when I do a Compile & Run, does the spin2GUI program associate with COM3 and load the program and run it.

    I have not tried a print command, will that open up a terminal and display the print statement?

    Ray
  • Rsadeika wrote: »
    I just tried the spin2GUI program, and I am not sure if I understand what the Run Binary and Compile & Run commands are supposed to do.

    I have my FLiP module plugged into the USB, and it is using COM3. Now, when I do a Compile & Run, does the spin2GUI program associate with COM3 and load the program and run it.
    That's what it should do. In fact it should open up a terminal and display something like "Propeller Version 1 on COM3", then some messages about downloading to hub memory and then "[ Entering terminal mode. Type ESC or Control-C to exit. ]"

    "Run binary" lets you select what binary you want to download. "Compile & Run" compiles the current Spin (or BASIC) program and downloads that.

    Have you tried it? Is it not working for you?

    I did just notice that there's a bug where if there's a space in the directory name then the compiler can't find some files. Perhaps you've run into that?
  • I am using your example program to flash the LED. I changed the pin number to 26, since that is where the LED is on the FLiP module.

    When I do the Compile & Run, it opens up a terminal, momentarily, and then the bottom of spin2GUI program, the Compiler Output section, is kind like flashing, it is doing something weird. But the LED on pin 26 is not flashing, so something went wrong.

    I am running Windows 10 Pro, with the latest upgrade of 1809.

    Ray

    Compiler Output
    G:/fastspin/spin2gui/bin/fastspin -l -O1 -L ./lib G:/fastspin/programs/test1.bas
    Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2018 Total Spectrum Software Inc.
    Version 3.9.5-beta Compiled on: Oct 11 2018
    test1.bas
    test1.pasm
    Done.
    Program size is 576 bytes
    cmd.exe /c start G:/fastspin/spin2gui/bin/propeller-load G:/fastspin/programs/test1.binary -r -t
  • It looks like your test1 program compiled fine ("Program size is 576 bytes.") but it isn't loading to the propeller. Unfortunately spin2gui doesn't have very good error feedback when something goes wrong with its loaded commands (like propeller-load). I would suggest starting a command line and trying the command:
    G:/fastspin/spin2gui/bin/propeller-load G:/fastspin/programs/test1.binary -r -t
    
    Hopefully this will print some error messages. Are you able to run binaries using other Propeller tools?
  • Since I am using Windows 10 Pro, and the command line terminal, I noticed that your command path uses forward slashes. For the DOS isn't it suppose to use the backslash in the path.

    Anyway, I tried running the test1.binary, and it did not work. Using the forward slash path, the system complained, cannot find path.

    Ray
  • Rsadeika wrote: »
    Since I am using Windows 10 Pro, and the command line terminal, I noticed that your command path uses forward slashes. For the DOS isn't it suppose to use the backslash in the path.
    Generally DOS will accept either forward or backwards slashes. But probably it's worth trying to replace / with \. Did you try that? Is the test1.binary program in the right place? (You can check the last one by browsing with the desktop to G:\fastspin\programs and looking for test1.binary.)

  • Something weird is going on, I have to be in the spin2gui in order to run the load program. I guess the propeller-load program is not able to find the port. I guess I will have to test this with my Activity Board.

    Ray
    G:\fastspin\spin2gui\bin>propeller-load g:\fastspin\programs\test1.binary -r -t
    error: can't find a port with a propeller chip
  • I tried it with the Activity Board, and it worked. I will have to see if I can figure out what is going on with the FLiP module.

    Ray
  • Yep, just figured it out, for the FLiP module. I had the WX WiFi module on, once I turned off the WiFi module, than the load program found the port and loaded the test1.binary file.

    I just tried it with another Activity Board that had the WiFi on, and the propeller-load could not find the port. So, I guess the WiFi module is messing up the spin2gui propeller-load process.

    Ray
Sign In or Register to comment.