Shop OBEX P1 Docs P2 Docs Learn Events
Propeller BASIC compiler ideas... — Parallax Forums

Propeller BASIC compiler ideas...

BeanBean Posts: 8,129
edited 2011-11-10 12:06 in Propeller 1
I was thinking about just messing around with a BASIC compiler for the Propeller. Which to do you think would be most useful:

A) BASIC to Propeller Assembly
······ Could use to make video/hardware drivers
······ Limited to 497 assembly instructions


B) BASIC to Spin Tokens
······ Large programs possible
······ Same speed as spin code
·······Easiest to implement compiler


C) BASIC to LMM Assembly
········Not as fast as PASM
······· Large programs possible
······· Hardest to implement compiler

Which option do you think would be the most useful. And why.

Bean.


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Does that byte of memory hold "A", 65, $41 or %01000001 ?
Yes it does...


·
«13

Comments

  • BradCBradC Posts: 2,601
    edited 2009-07-16 13:33
    This is a really tough one. I figure if Parallax could have made BASIC do what they wanted to get out of the chip they would have used that rather than creating SPIN.

    A) is limited by code size but would go like a bat out of hell. B) is just re-packaging SPIN for those who won't learn another language. C) has the disadvantages of C (lower code density than SPIN and less speed than PASM) plus the extra complexity of the compiler without the global compatibility that actually makes the language attractive.

    Personally I'd be targeting B to start with. It's much easier to implement and will likely attract people that currently use the stamps and their clones who are looking for more horsepower. You could then offer a variant back end later that had an LMM target as a bit of a challenge if you were bored [noparse];)[/noparse]

    Having said that, I'm also not a likely target, nor am I developing it.. so I probably need to give a huge discount on my .2c worth.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Release the hounds!
  • trodosstrodoss Posts: 577
    edited 2009-07-16 13:40
    I would opt for option 'B' for a BASIC compiler, since it would be easier to implement, and should perform well for most BASIC apps. Are you planning on writing a PBASIC-like compiler, or are you going for a basic variant like PowerBasic/FreeBasic?
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-07-16 13:53
    Why not support all possibilities? You could have a compile directive which tells the compiler which block to compile in which way.

    I think there is no big difference in BASIC to PASM compared to BASIC to LMM. My understanding is that the jumps and calls have to be treated different whereas the rest is pretty much the same.

    And as you say BASIC to SPIN is the easiest you can add this as well ;o)

    Or what about having BASIC to SPIN plus inline PASM? So you don't have to switch development environment if you want to do some stuff in PASM.

    Just my half a cent ...
  • BradCBradC Posts: 2,601
    edited 2009-07-16 14:05
    MagIO2 said...

    Or what about having BASIC to SPIN plus inline PASM? So you don't have to switch development environment if you want to do some stuff in PASM.

    You can't do that. If you are working in the SPIN interpreter, the only real way to run some PASM is to launch another cog. Nobody has come up with a modified interpreter that will allow you to inline PASM. Cluso99 was probably the closest to being able to do that with his modified interpreter, but I'm not sure it was even on his radar. I recall hippy talking about it at one point (where is he lately?)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Release the hounds!
  • MagIO2MagIO2 Posts: 2,243
    edited 2009-07-16 14:20
    ?????

    He want's to create a BASIC to SPIN bytecode compiler ... So, the output is a EEPROM-file which of course can include DAT-sections that hold the also compiled PASM code. Of course the BASIC compiler needs some kind of cognew instruction which starts another SPIN bytecode or an assembler section.

    Ah ... Ok ... understood what the missunderstanding was:
    With INLINE PASM I don't mean to mix PASM and BASIC instructions. Just the same as in SPIN ... a DAT section can contain PASM code. In BASIC -> a function (forced to have only one parameter) can contain only PASM code and the call of this function is compiled to a cognew.
  • RaymanRayman Posts: 14,854
    edited 2009-07-16 15:43
    If only I had time... I'd like to do a version of Femtobasic that compiles a bit to make it faster... I'd also like to do a Windows program for coding and hooks for debugging...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My Prop Info&Apps: ·http://www.rayslogic.com/propeller/propeller.htm
  • Bill HenningBill Henning Posts: 6,445
    edited 2009-07-16 15:57
    My vote is for B - since it should be possible to call Spin objects from that Basic, and Basic functions from Spin.

    Adding the special Stamp basic commands would help bring a lot of Stamp users over...
    Bean (Hitt Consulting) said...
    I was thinking about just messing around with a BASIC compiler for the Propeller. Which to do you think would be most useful:


    A) BASIC to Propeller Assembly

    Could use to make video/hardware drivers

    Limited to 497 assembly instructions





    B) BASIC to Spin Tokens

    Large programs possible

    Same speed as spin code

    Easiest to implement compiler





    C) BASIC to LMM Assembly

    Not as fast as PASM

    Large programs possible

    Hardest to implement compiler



    Which option do you think would be the most useful. And why.



    Bean.
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.mikronauts.com - my site 6.250MHz custom Crystals for running Propellers at 100MHz
    Las - Large model assembler for the Propeller Largos - a feature full nano operating system for the Propeller
    Morpheus & Mem+ Advanced dual Propeller SBC with XMM and 256 Color VGA
    Please use mikronauts _at_ gmail _dot_ com to contact me off-forum, my PM is almost totally full
  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-16 16:10
    I had started down this path with a Basic compiler for a LMM·called Ouroboros.· I stopped when I ran out of room in a single Spin program.· It could parse and process declarations, simple statements, and generate code (including fixups) for some expression operators and simple statements like IF / THEN and GOTO.· There's a thread somewhere with the last source code.· I meant to start to split the parser and code generator apart into separate phases, but got involved in other projects.

    I think a Basic to Spin byte code compiler would be more useful, but I had a better understanding at the time of LMM instructions than Spin byte codes.

    By mistake, I included the source code for Ouroboros and Ouroboros1 in the archive I posted for the Winbond/SRAM driver here: [noparse][[/noparse]url]http://forums.parallax.com/forums/default.aspx?f=25&m=349616&p=2[noparse][[/noparse]/url].




    Post Edited (Mike Green) : 7/16/2009 4:21:12 PM GMT
  • Ken GraceyKen Gracey Posts: 7,401
    edited 2009-07-16 16:19
    Option B is my preference, even though it may not be efficient. It would give a newbie a simple bridge from the BS2 to the Prop, plus the ability to see the Spin code generated by the compiler. This brought many benefits in your SX/B program. Even Peter Vanderzee finally dove into SX/B and we know he's a tough critic to please.

    Efficiency, speed and various benchmarks aside, I feel it would be most productive to provide a simple bridge from PBASIC to Spin. I wish all of you could participate in the language debates inside of Parallax. Whether or not we need BASIC for the Prop has been a common discussion. Many customers would benefit, instantly, but their lives could be made easier if they'd just give Spin a try. From my perspective a PropBASIC would be most valuable if it simply improved access.

    Keep in mind I haven't worked with Femto yet, and that I've been happy with Spin especially since PST was made available.

    Ken Gracey
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2009-07-16 16:26
    Option B is the one that makes the most sense..

    It would allow for fewer limits in regard to code.

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Visit the: The Propeller Pages @ Warranty Void.
  • BeanBean Posts: 8,129
    edited 2009-07-16 16:32
    Thanks for all the input guys.
    Just to be clear this is a PC compiler, not an imbedded Propeller compiler.

    I know the spin tokens are documented somewhere, but I couldn't find the document. Can anyone direct me to it ?

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Does that byte of memory hold "A", 65, $41 or %01000001 ?
    Yes it does...


    ·
  • rokickirokicki Posts: 1,000
    edited 2009-07-16 16:47
    Spin bytecodes would *seem* to be a good target.

    The only problem is that there's no good way in the Spin bytecode to do a goto,
    and normal line-number-based BASIC really wants a goto.

    Of course you can hack it (by doing a call and then munging the return
    address) but that borders on evil.

    Anyway, I'd start by targetting bytecodes, and then after that works reasonably
    well add in options for assembly output.
  • localrogerlocalroger Posts: 3,452
    edited 2009-07-16 16:56
    @rokicki -- there is in fact a Spin bytecode for GOTO; it's code $0C. The Spin compiler just doesn't provide a way to use it directly; it's used to implement Spin control structures like REPEAT and IF though.

    I add my vote for structured (not line numbered) BASIC to bytecode; with appropriate Spin functions added to the BASIC language.
  • rokickirokicki Posts: 1,000
    edited 2009-07-16 18:35
    Oh! How did I miss that! Sorry for the bad information.
  • WBA ConsultingWBA Consulting Posts: 2,935
    edited 2009-07-16 22:19
    I am too new at the propeller/SPIN to give a solid vote, but option B would seal the deal on my transition to the propeller from the Basic Stamp. Being able to see the compiled propeller code created from a language I know would be very beneficial. This is how I learned Macro programming in Excel (which is essentially Visual Basic). I would create Macros with the Macro Recorder, go in a change things here and there, and see what happened. Next time around, I would just code what I wanted from the start.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andrew Williams
    WBA Consulting
    IT / Web / PCB / Audio
  • heaterheater Posts: 3,370
    edited 2009-07-16 22:51
    Why do this?

    Yes I'm sure you can make a BASIC that everyone knows and loves, from their BASIC Stamp or back to their Altair days. But when it comes to doing anything useful, then what?

    OK you can ask me about ZiCog etc... I don't know....

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • JonnyMacJonnyMac Posts: 9,198
    edited 2009-07-16 23:02
    Exactly; there are a number of projects that any number of us have created that others will question -- the real question is: Why not? And... why judge? It seems like any Propeller oriented project would be helpful -- at least in small part -- to the Propeller user base.

    And in the FWIW category, I believe a BASIC compiler would be far cleaner way to to port BASIC Stamp programs than the BS2-type object modules that have been previously submitted.

    Code away, Terry!
  • BradCBradC Posts: 2,601
    edited 2009-07-16 23:23
    Bean (Hitt Consulting) said...

    I know the spin tokens are documented somewhere, but I couldn't find the document. Can anyone direct me to it ?

    The best reference is the interpreter source.
    If you want a hacky way of testing stuff, bst[noparse][[/noparse]c] has an extra command that allows you to inject raw bytecode into SPIN methods
    Bytecode($01,$02,$03) and so on. It's easier than building binaries for simple tests.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Release the hounds!
  • QuattroRS4QuattroRS4 Posts: 916
    edited 2009-07-16 23:42
    Bean said...
    I was thinking about just messing around with a BASIC compiler for the Propeller.

    Initially I thought of opting for option B ... then I thought why? I'm not sure why - 'Just Learn Spin it's not that difficult' I then thought 'Hey - A Basic compiler for LMM is the way to go' - just read Mike Greens post and that killed that .. Is there a reason that you have started down this path ?

    Regards,
    John

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Necessity is the mother of invention'

    'Those who can, do.Those who can’t, teach.'
    'Convince a man against his will, he's of the same opinion still.'

    ·
  • RossHRossH Posts: 5,514
    edited 2009-07-17 01:43
    @Bean,

    Definitely go with (B). The only problem you have here is floating point - but if you're willing to live without that, this would be your best option.

    As to the other options ...

    Option (A) is too limited as to code size to be much more than a gimmick - it would be hard to get a compiler optimized enough to write useful drivers.

    Option (C) Is already available. Just use b2c (or another Basic to C translator - there are several available) with Catalina. Okay, I haven't actually tried this - but I think you'll find this would give you a working basic compiler for the Prop in far less time than it would take to write one.

    Ross.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Catalina - a FREE C compiler for the Propeller - see Catalina
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2009-07-17 02:21
    I vote A, but because of space I vote B

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Toys are microcontroled.
    Robots are microcontroled.
    I am microcontroled.



    If it's not Parallax then don't even bother. :-)
    ·

    Mini-Din/PS2 connectors are for sale! 5 for $1! PM me if you wish to make an order.
    Cheap·shipping unless specified!··········150 left!!··


  • Peter NachtweyPeter Nachtwey Posts: 9
    edited 2009-07-17 02:52
    I would go for A but with a twist. I can't see where basic is any better than SPIN. If you want interpreted code use SPIN as it is. I would not even consider making a basic to assembly compiler. It would be yet another language/compiler/tool to learn.
    I think the best answer is to write a SPIN to PASM compiler or better yet, SPIN code to machine code compiler. This way one can write ALL their code in SPIN only and chose between speed and memory. One language, one code base, speed or memory efficient, your choice.
  • Ken GraceyKen Gracey Posts: 7,401
    edited 2009-07-17 14:30
    I agree that BASIC is no better than Spin for the Propeller, particularly if some of the BASIC Stamp's architecture-specific use of BASIC show their limits in the Propeller. I'm guessing that many comments from people above are from those who came into Parallax for the Propeller. Most of us on this forum don't have a 15-year BASIC Stamp history behind us.

    PropBASIC is of interest when you look at our company's history and customer base. It's reasonable to say that Parallax was built upon the BASIC Stamp with many useful educational programs, creative people inside Parallax, accessories, and books that go with that product. These BASIC Stamp customers would benefit tremendously to have some kind of bridge between PBASIC to at least try the Propeller. Even if a PropBASIC compiler executed Spin code the same speed as a BASIC Stamp 2 ran PBASIC and made only minimal use of concurrent processing it would be a tremendous boost for millions of BASIC Stamp developers. They simply need any barrier (perceived, real, architectural or hardware) reduced enough to step in and run a few programs in the Propeller from their favorite Stamps in Class book. That's all. It isn't necessary to have a full-blown PropBASIC environment. It needn't even use PBASIC structures, commands, etc.

    As BASIC Stamp customers continue to gain experience with our products it would be a shame to loose them to "more capable' Stamp-like devices instead of showing them the Propeller. I can hear many of you now say "but Spin is so easy!". If you've been raised on a single programming language and you've made your way successfully with a business and hobby around that language/product it can be difficult to justify forward motion. . . especially if all is going well already.

    One other solution is a side-by-side tutorial comparing Spin and PBASIC, showing the same program in both languages. This approach would only be useful for a limited number of examples until the architectures diverged in the second chapter.

    The concept of a BASIC compiler for the Propeller has been discussed a whole bunch at Parallax. We know it's a year-long project for us to undertake, and I've encouraged that we don't do it internally. While it helps our BASIC Stamp user try the Propeller as I've advocated above, it redirects our internal resources away from engineering efforts that we need to apply to make the Propeller sell in volume. Parallax's future business with the Propeller must include commercial applications produced in higher volume, and the efforts we need to apply towards those customers command the attention of our internal resource base. This includes specific customer support, improved datasheets and objects, IDE support, and Propeller 2. Once we take care of those engineering efforts we have no time to do anything as Bean has proposed.

    It is our hope that such a compiler could be produced by our customers or friends. Just as Bean has done with SX/B and the SX-Key IDE, we could envision a PropBASIC being integrated with our Propeller IDE. I believe it is a matter of time before this happens. The longer we delay the internal efforts the more room exists for us to partner with somebody outside of Parallax.

    Ken Gracey
    Parallax Inc.

    P.S. to BASIC Stamp users: we have new products in the plans for you over the next year. This includes WiFi BOE hardware for wireless programming/internet connectivity, renewable energy Stamps in Class programs, etc. The BASIC Stamp product line will continue to improve.
  • Cluso99Cluso99 Posts: 18,069
    edited 2009-07-17 15:18
    Option B because as Ken has said, it provides the simplest way for Stamp enthusiasts to move to the prop.

    Maybe the compiler could just convert the PBasic to Spin and then feed to the normal spin compilers. Not sure if this is feasible or not. It would provide a good feature for learning spin, but it would add another step.

    As for embedded pasm, this "could" be done using an LMM model...
    HOWEVER, I see 2 problems. One is the obvious jump problem, and the other is where are the variables? There is no room in the standard Spin Interpreter. I have some space in my faster version and I can (have already done it for for debugging in my interpreter) place the LMM interpreter in the shaddow ram for zero footprint. The interpreter could be extended to do floating point, either by LMM or overlays. My spin interpreter was giving 20-25% speed improvement before I optimised a couple of routines and broke it. Been busy with other things since.

    BTW - I would not use PBasic now, although when I first started it would have helped me. I was not a Stamp user.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Home of the MultiBladeProps: TriBladeProp, RamBlade, TwinBlade,·SixBlade, website
    · Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
    · Prop Tools under Development or Completed (Index)
    · Emulators: Micros eg Altair, and Terminals eg VT100 (Index) ZiCog (Z80), MoCog (6809)
    · Search the Propeller forums (via Google)
    My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
  • Ken GraceyKen Gracey Posts: 7,401
    edited 2009-07-17 15:30
    @Cluso99: You came in as a Prop user, too, so you would also not be a user of a PropBASIC compiler as you noted. It would be really interesting to ask this question on the BASIC Stamp forum. It helps to define the specific audience and need before starting such a project. Though floating point could be a great addition to PropBASIC, on the other hand it might be the reason for somebody to finally take the leap from PropBASIC to Spin/ASM after getting beyond the initial "hey, I CAN program this thing after all!" excitement. The Float32 library is easy to use in Spin and I cringe at trying to see some of this stuff accomplished in a PropBASIC compiler. This project has such daunting potential that it could be impossible to start if scoped out to the satisfaction of an engineer vs. the needs of a seasoned BASIC developer who just needs to try something new.

    Once a simple PropBASIC compiler is available, we'd likely see the King of Stamps (Jon McPhalen) make many simple requests to improve the tool. I'm suggesting that we need to have some kind of Option B solution just to get started. Just like BST, a starting point allows for much improvement.

    Very excited about this possibility,

    Ken Gracey
    Parallax Inc.
  • hippyhippy Posts: 1,981
    edited 2009-07-17 16:06
    BradC said...
    Nobody has come up with a modified interpreter that will allow you to inline PASM. Cluso99 was probably the closest to being able to do that with his modified interpreter, but I'm not sure it was even on his radar. I recall hippy talking about it at one point (where is he lately?)

    Still here, still lurking, still not active in the Propeller world at the moment.

    A modified Spin Interpreter can run LMM PASM or even load in and execute native PASM. My idea was to subvert CogNew/CogInit with start address of $0000..$000F ( which wouldn't make sense for real Spin ) as an 'escape' to non-standard and the argument the adress of what to run ( or sumething like that ).

    There's also option D ... convert Basic source to Spin source.

    And option E ... code up a Basic Stamp interpreter so the Propeller looks to the end user like a Basic Stamp with extra goodies.
  • jazzedjazzed Posts: 11,803
    edited 2009-07-17 16:10
    I was just wondering a few minutes ago how long it would take hippy to finish one of these year long projects given proper motivation [noparse]:)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve


    Propalyzer: Propeller PC Logic Analyzer
    http://forums.parallax.com/showthread.php?p=788230
  • mparkmpark Posts: 1,305
    edited 2009-07-17 17:06
    I thought Bean was already working on option E. Focus, Bean, focus!
  • rokickirokicki Posts: 1,000
    edited 2009-07-17 17:10
    That's an idea that's intriguing---allow LMM-style assembly callouts from Spin! Someone should push on this idea.
  • RaymanRayman Posts: 14,854
    edited 2009-07-17 18:37
    Personally, I think compiling to SPIN would be great, but overkill... Besides, I think the main thing people would be interested in is debugging their code from a Windows App with breakpoints and watches and so forth... I'm not sure speed would be a driving force. But, I guess it depends on the target audience. You'll never get me going back to BASIC!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My Prop Info&Apps: ·http://www.rayslogic.com/propeller/propeller.htm
Sign In or Register to comment.