Shop OBEX P1 Docs P2 Docs Learn Events
Writing spin editor versus integrating C — Parallax Forums

Writing spin editor versus integrating C

RaymanRayman Posts: 14,826
edited 2012-08-15 18:24 in Propeller 1
Facing a bit of a tough choice...
I'd like to upgrade VisualSpin to work with graphical displays.
At the same time, I'd like to include a native compiler and spin editor in Visual C++...

But, writing a Spin editor is a nightmare because of all the different colors, fonts, and indentation.
On the other hand Roy has posted a Spin compiler that should be easy to integrate.

Was just thinking today about switching to C, but here's the problem with that (please tell me if I'm wrong):
Catalina is closed source and GCC is GNU licensed and also written in GCC, so there's no way to integrate into my own closed source project.
«1

Comments

  • jmgjmg Posts: 15,183
    edited 2012-08-13 16:31
    Rayman wrote: »
    Catalina is closed source and GCC is GNU licensed and also written in GCC, so there's no way to integrate into my own closed source project.

    I'm not sure I follow ?

    Those tools are usually simply called, they are not changed or renamed, or claimed as your own.

    Other vendors include GCC/SDCC et al, with their Eval boards, and usually there is some part of this, that is closed source.
  • RaymanRayman Posts: 14,826
    edited 2012-08-13 16:43
    Yes, I could call it as an external executable with a shell command, but I'd rather have the compiler as integral part of the program...
    I think I can do that for Spin now since Roy posted his port of Chip's original source.
  • jazzedjazzed Posts: 11,803
    edited 2012-08-13 16:51
    Roy's SPIN can be used as a library or a separate program. I use it as a separate program now mainly to give users the choice of BSTC and SPIN. BSTC can optimize where SPIN can not.
  • RaymanRayman Posts: 14,826
    edited 2012-08-13 16:54
    Did notice that BSTC is part of GCC. I might check the licensing terms, but I have a feeling it'd exclude me using it in my own closed source app....
  • RaymanRayman Posts: 14,826
    edited 2012-08-13 16:58
    Does anybody know if a program can use GCC or Catalina without having either installed?

    What I mean is... Can I include Catalina.exe or gcc.exe files into the install folder of my program and have it compile C code?
  • jazzedjazzed Posts: 11,803
    edited 2012-08-13 17:56
    Rayman wrote: »
    Did notice that BSTC is part of GCC. I might check the licensing terms, but I have a feeling it'd exclude me using it in my own closed source app....

    Parallax has explicit permission from Brad as well as his open-source statement on the forums.
    Rayman wrote: »
    Does anybody know if a program can use GCC or Catalina without having either installed?

    What I mean is... Can I include Catalina.exe or gcc.exe files into the install folder of my program and have it compile C code?

    GCC has a directory structure. Propeller-GCC is prepackaged for use. As long as the windows Path is set to the bin directory it will work. MinGW would work the same.
  • RaymanRayman Posts: 14,826
    edited 2012-08-13 18:07
    Thanks jazzed. That's kinda what I expected. It sounds like you really need to have gcc installed in order to use it...
    I'd really rather just be able to put all the required files in one folder and compile though...
  • jazzedjazzed Posts: 11,803
    edited 2012-08-13 18:18
    Rayman wrote: »
    Thanks jazzed. That's kinda what I expected. It sounds like you really need to have gcc installed in order to use it...
    I'd really rather just be able to put all the required files in one folder and compile though...

    You're welcome. Yes, copying the directory and then doing that extra step for setting the path in windows is kind of painful. The InnoIDE installer does it all for us.
  • jmgjmg Posts: 15,183
    edited 2012-08-13 18:22
    Rayman wrote: »
    Yes, I could call it as an external executable with a shell command, but I'd rather have the compiler as integral part of the program...
    I think I can do that for Spin now since Roy posted his port of Chip's original source.

    The serious down-side of doing this though, is users cannot follow updates to the Spin compiler, or run it in batch mode.
    I'm not clear on what you gain ?
  • RaymanRayman Posts: 14,826
    edited 2012-08-13 18:33
    Haven't seen any substantial changes in the Prop Tool compiler for years... I think that's pretty etched in stone now...
    What I'm trying to do is create an environment where all the dirty laundry is hidden...
  • jmgjmg Posts: 15,183
    edited 2012-08-13 18:39
    Rayman wrote: »
    Haven't seen any substantial changes in the Prop Tool compiler for years... I think that's pretty etched in stone now...

    I think that is because they are coded in ASM ? - the new C based Spin compiler, should allow steady fixes to be made.

    Rayman wrote:
    What I'm trying to do is create an environment where all the dirty laundry is hidden...

    You should be able to run from a tree you supply ?

    We've bumped into this a couple of times, (path/set directives) with other tools
    - one we avoided with an additional command line param, and the other we included a SET command in the calling wrapper.

    Both tool flows can now run on a Flash Drive.
  • jazzedjazzed Posts: 11,803
    edited 2012-08-13 18:42
    Make sure to duplicate Propeller Tool perfectly otherwise you'll take flack from the SPIN faithful.
  • RaymanRayman Posts: 14,826
    edited 2012-08-13 18:46
    My dilemma exactly... I really do not want to write a Spin editor...
    A C editor is much simpler, really just plain text...
    But, how can I encapsulate a C compiler for the Prop?
  • jazzedjazzed Posts: 11,803
    edited 2012-08-13 19:00
    Rayman wrote: »
    My dilemma exactly... I really do not want to write a Spin editor...
    A C editor is much simpler, really just plain text...
    But, how can I encapsulate a C compiler for the Prop?

    Maybe Ross can make a "compiler" dll for you ? All the spin code will still be visible though.
  • David BetzDavid Betz Posts: 14,516
    edited 2012-08-13 20:19
    Rayman wrote: »
    Catalina is closed source and GCC is GNU licensed and also written in GCC, so there's no way to integrate into my own closed source project.
    I don't believe that Catalina is closed source. I think it's GPL. Only the optimizer is closed source.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2012-08-13 21:24
    This thread has my head going in circles with possibilities, but fundamentally I think I want to do the same thing with a "visual" programming language. Instead of starting with "main", start with a blank form on a PC screen. Drop in a button and a text box. Double click the button and enter one line of code textbox1.text = "Hello World" and then hit the run button. That compiles to a propeller board and it replicates what was on the PC screen.

    I'm not sure if the language could be called spin
    textbox1.text := "Hello World"
    
    or C
    textbox1.text = "Hello World";
    
    or Basic
    textbox1.text = "Hello World"
    
    or another language. They all look pretty similar.

    What would be good though is to have buttons and textboxes that work on TV, VGA and touchscreens and the program is portable between all these types of displays. Only the resolution and color depth might be different.

    So in a way this sidesteps the language wars. Realistically though, it will probably be in cached XMM C.

    What I am not sure about is what language to write this in. I think rayman is looking for the source code for a compiler to drop into an existing program and I agree that would be great. Next best thing is a self contained program and you make multiple copies of the IDE and just drop them into the working folder. I've done that many times with Brads Spin Tool.

    I suppose the next best thing is you write your own IDE and shell out to command line programs for compiling. I went off on a tangent over the last few days trying to work out if .net micro could be run on the propeller as that has a nice GUI front end. I don't know the answer yet but maybe it can.

    Shelling Catalina, PropGCC or BST from a custom IDE is probably the quickest solution and I've done it for all three with an IDE. But my IDE is in vb.net which is about as far away from a single .exe program as you can get.

    Visual spin with a single .exe IDE and compiler as part of the internal code. I'm hopelessly confused about it all!
  • jazzedjazzed Posts: 11,803
    edited 2012-08-13 21:38
    You know what? If the idea is just to get an open-source language into an IDE it can be done. David Betz wrote xbasic and it will do xmm code. And it's pretty tight without xmm (half the size of the same C app). Some of the code is SPIN-like, but it's mostly BASIC syntax.

    Here's a main file example to think about. Attached is a picture of one example, though not this code.

    Bonus? VisualC# IDE code is already available for programming with it (as an application).
    rem =================================================
    rem include files
    rem
    include "GbLCD.bas"
    include "GbI2C.bas"
    include "GbGUI.bas"
    include "lastcog.bas"
    include "GbBattery.bas"
    include "print.bas"
    include "propeller.bas"
    include "string.bas"
    
     rem =================================================
    rem main program code here
    rem =================================================
    
    def startup
    
        dim x,y,m,n
        dim buttons
    
        REM ---------------------------------------------
        REM send user startup message and show our cogid
        REM
    
        print "Starting Gamebaby... ";
        cog = cogid
        print "COGID "; cog
    
        REM ---------------------------------------------
        REM startup the LCD and clear screen to background color.
        REM
    
        GbLCD_start
        GbLCD_clear(GbLCD_BLUE)
    
        REM ---------------------------------------------
        REM startup the I2C devices including the button monitor.
        REM
    
        GbI2C_start
    
        REM ---------------------------------------------
        REM show last available cog number
        REM
    
        print "LastCog "; lastcog
    
        REM ---------------------------------------------
        REM Make a panel
        REM
    
        GbGUI_panel_parms(GbLCD_WHITEST_GRAY,3,15,GbLCD_MAXX-8,GbLCD_MAXY-21,0)
    
        REM ---------------------------------------------
        REM Make a title and show battery
        REM
    
        GbLCD_setBgColor(GbLCD_BLUE)
        GbGUI_textColor(GbLCD_YELLOW)
        //GbGUI_Label("GameBaby",5,4)
    
        GbGUI_3Dbutton("OK",GbLCD_MAXX-40,GbLCD_MAXY-35)
    
        do
            GbBattery_show(GbLCD_MAXX-20,3,GbLCD_YELLOW, GbLCD_BLUE)
              waitcnt(clkfreq/4+cnt)
    
            GbLCD_setBgColor(GbLCD_BLUE)
            GbLCD_setFgColor(GbLCD_YELLOW)
            GbLCD_printXY(" GameBaby! ",0,0)
    
            x = 4 //GbLCD_getx
            y = 2 //GbLCD_gety
    
            buttons = GbButtons_buttons
            if oldbut <> buttons then
                oldbut = buttons
                GbLCD_setTextXY(x,y)
                GbLCD_bin(buttons,9)
            end if
    
            //GbBattery_showVoltage
    
            GbLCD_setTextXY(28,32)
            for n = 0 to 4
                GbLCD_hex(GbI2C_accel_readReg(n),2)
            next n
    
             GbLCD_setTextXY(28,33)
            for n = 0 to 8
                GbLCD_hex(GbI2C_ee_readByte(n),2)
            next n
    
            GbLCD_setTextXY(28,34)
            GbI2C_rtc_readRegs
            for n = 0 to 4
                GbLCD_hex(GbI2C_rtc_getReg(n),2)
            next n
    
          waitcnt(clkfreq/10+cnt)
    
        loop
    
    
    end def
    
    
    rem =================================================
    rem call startup here
    rem =================================================
    startup
    
    
    rem =================================================
    rem end of file
    rem =================================================
    
    391 x 268 - 188K
  • jmgjmg Posts: 15,183
    edited 2012-08-13 21:38
    Dr_Acula wrote: »
    I went off on a tangent over the last few days trying to work out if .net micro could be run on the propeller as that has a nice GUI front end. I don't know the answer yet but maybe it can.

    Have you seen this ? -

    https://www.sparkfun.com/products/10749

    ["Description: The 72Mhz FEZ Panda II runs .NET Micro Framework, allowing users to program and debug FEZ Panda using Microsoft's free Visual C# Express. Applications are loaded over USB cable (or serial) with full featured debugging capabilities, such as stepping in code or inspecting variables."]
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2012-08-13 22:37
    jmg, that sort of thing is extremely clever. It kind of freaks me out a bit because this is what the propeller is up against and we need to keep up! And what is more, I believe the propeller can do this. Not the P2, the current propeller. It can run a visual language, with drag and drop icons, a web browser, java, games etc.

    in fact I think the prop would go superbly with a multi threading language like .net, as you can devote cogs to serial, clocks etc and have all these things running in parallel instead of a 'simulated parallel' on a PC.

    Brainstorming .net maybe is for another thread, but as a start, one could build a simulator for their common language interface a bit like Zog or the Z80 emulators. Or one could write all the low end drivers in C and splice it into existing C# in .net.

    With the raspberry pi and now this panda II, the world is changing. $40 computers are becoming commonplace and that is cheaper than I can build a propeller board for.

    @jazzed, that looks interesting. Can xbasic be run cached, ie a megabyte program cached from an SD card?

    I don't want to take over this thread too much, but it is interesting brainstorming what is out there as there could be other solutions to writing a spin editor from scratch.
  • jazzedjazzed Posts: 11,803
    edited 2012-08-13 23:19
    Dr_Acula wrote: »
    @jazzed, that looks interesting. Can xbasic be run cached, ie a megabyte program cached from an SD card?

    The xbasic XMM runs cached. SD card XMM support is not available at the moment.
  • David BetzDavid Betz Posts: 14,516
    edited 2012-08-14 18:46
    jazzed wrote: »
    The xbasic XMM runs cached. SD card XMM support is not available at the moment.
    Actually, xbasic uses exactly the same cache drivers as PropGCC so it should work with the SD card cache driver. I haven't tried it though.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-08-14 19:04
    I don't get why invoking a compiler from the command line is a problem. I've done it from Perl with Propellent and Roy's compiler and, to the user, it looks completely integrated. You just have to make sure that you can invoke the compiler in a mode that doesn't produce any dialog boxes. Both Propellent and Roy's compiler have versions or command-line switches that inhibit such interruptions. To use them from a program, you just invoke the .exe and capture its output from STDOUT. In case of errors, most compilers give you the line and column where the error occurred, which you can use for highlighting in the edit window. IMO, using an API instead just adds an unnecessary level of complexity and could restrict your choice of application languages.

    -Phil
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2012-08-14 20:11
    Re xbasic, great to hear it works with the SD cache driver. WRT the boards averagejoe and I have made, I need to apologise for asking so many C questions and then not following through with code, but we still have some hardware issues to solve. I think there is a solution though and it involves moving multiple bits of spin into pasm. So we are going to work on that and then can get on with building graphics libraries in C.

    I agree with PhiPi about command line compilers. A GUI IDE is a graphical sort of thing, but compilation is taking ascii characters and turning them into other ascii characters and that (IMHO) works better as a command line program.

    Re GUI code, what we have now are some great tools for writing and building text based programs. Everything is text ultimately, even the code in C# and vb.net that describes where a button is, but it is easier to work in a more graphical environment. Drag a button onto a form.

    Thinking tangentially, I went on a search for a GUI IDE where the source code is available - not just the source for the compiler, but the source for the graphical part of the IDE and the source for the syntax highlighter and all the other bits you need to develop graphical code more easily. This led me to this interesting project http://www.icsharpcode.net/OpenSource/SD/

    I haven't managed to pull it to bits yet but the source code is all available and it works with multiple languages. Maybe this could lead somewhere?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-08-14 20:35
    Dr_Acula wrote:
    Everything is text ultimately, even the code in C# and vb.net that describes where a button is, but it is easier to work in a more graphical environment. Drag a button onto a form.
    I've done it both ways (Visual BASIC and Perl/Tk). I actually prefer specifying widget features and locations with text, rather than from a GUI. I find that I have much finer control over the appearance of my windows that way. Fortunately, Tk's pack method, which I use almost exclusively, makes it easy.

    -Phil
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-08-15 00:10
    jazzed wrote:
    Make sure to duplicate Propeller Tool perfectly otherwise you'll take flack from the SPIN faithful.
    Good advice. :)

    The duplication does not have to be isomorphic, however, as long as the spirit of simplicity and rapid application development are hewn to.

    -Phil
  • SRLMSRLM Posts: 5,045
    edited 2012-08-15 00:35
    I don't get why invoking a compiler from the command line is a problem. I've done it from Perl with Propellent and Roy's compiler and, to the user, it looks completely integrated. You just have to make sure that you can invoke the compiler in a mode that doesn't produce any dialog boxes. Both Propellent and Roy's compiler have versions or command-line switches that inhibit such interruptions. To use them from a program, you just invoke the .exe and capture its output from STDOUT. In case of errors, most compilers give you the line and column where the error occurred, which you can use for highlighting in the edit window. IMO, using an API instead just adds an unnecessary level of complexity and could restrict your choice of application languages.

    -Phil

    Adding to the above, BST is a poor compiler to integrate into a larger tool: it doesn't have very many unique strings in it's output so it's difficult to parse. It does have a very useful (but equally un-parseable) .list feature that gives the breakdown of the code.
  • RossHRossH Posts: 5,511
    edited 2012-08-15 02:43
    Rayman wrote: »
    Was just thinking today about switching to C, but here's the problem with that (please tell me if I'm wrong):
    Catalina is closed source and GCC is GNU licensed and also written in GCC, so there's no way to integrate into my own closed source project.

    Hi Rayman,

    Perhaps this has already been answered - but I'll answer anyway ...

    Catalina - or perhaps I should say LCC - is 100% "open source", like GCC. But (also like GCC) that does NOT mean "open slather". It all depends on what you want to do with it ...

    If you want to sell a "closed source" product based on a modified version of either Catalina or GCC, then I'm afraid you're out of luck. Even if you offered to pay, Parallax can't sell you a license to resell GCC as a "closed" product, and I can't sell you a license to resell LCC.

    However, you can distribute your own modified version of either one - provided you distribute it as "open source". You can't charge for it directly, but you can charge to support it!

    On the other hand ... if you want to sell a closed source product that can integrate with Catalina or GCC, go right ahead - that's easy. Code::Blocks provides a good model here (forget for a moment that it is also an open source product - it could just as easily be closed). You don't need to modify either Catalina or GCC to use them with Code::Blocks.

    Ross.
  • RossHRossH Posts: 5,511
    edited 2012-08-15 02:53
    David Betz wrote: »
    I don't believe that Catalina is closed source. I think it's GPL. Only the optimizer is closed source.

    Correct - I now include the CMM version of the Optimizer for free as part of the new Catalina 3.7, but it's still closed source. I'm loath to release the source ... because it's just soooo ugly! However, you don't really need the optimizer to produce good code - especially with CMM.

    There is also the fact that Catalina currently uses HomeSpun as it's Spin compiler. It is easy enough to switch back to BST (I originally supported BST, HomeSpun and the Parallax Propeller tool, but I decided to stick to just one - and HomeSpun won out because it was far and away the most flexible. I kept hoping Parallax would fix the problems in the Propeller tool and I could switch back to that instead ... glad I didn't wait for that to happen!)

    Ross.
  • RossHRossH Posts: 5,511
    edited 2012-08-15 03:05
    Rayman wrote: »
    Does anybody know if a program can use GCC or Catalina without having either installed?

    What I mean is... Can I include Catalina.exe or gcc.exe files into the install folder of my program and have it compile C code?

    Can't speak for GCC, but with Catalina, the answer is "yes". Catalina doesn't really need an "installer" at all - I just provided one to simplify things for Windows users. I copy versions of Catalina around all the time, and often have many different versions installed (and in use simultaneously) - each one living in a different directory.

    Ross.
  • RaymanRayman Posts: 14,826
    edited 2012-08-15 03:33
    Ross, this is sounding good...

    Let me try to be more specific about what I'd like...
    My preference is usually to have a program to be a single .exe executable with no external dependencies.
    For Visual Spin, I did this by including propellent as a resource and then spitting it out to a file when needed...

    Anyway, what I'd like from Catalina or GCC is to be able to put all the relavant files into one folder and be able to run it.

    What I'd like not to be required is that Catalina or GCC are installed by the user as a seperate step prior to be able to use my program.

    BTW: Spent about an hour yesterday looking at how to do a Spin editor. It really is difficult...
Sign In or Register to comment.