NEW: xBasic IDE and Compiler for Propeller
jazzed
Posts: 11,803
Over the last several months David Betz and I have been working on xBasic.
Why another BASIC?
xBasic is designed to run programs from HUB, C3 Flash, or SpinSocket Flash .
xBasic syntax is similar to the older Visual Basic languages but is simpler.
xBasic can start PASM programs in COGs like other languages.
The xBasic IDE and the xBasic tools are multi-platform and open source.
Several demo programs are available including a TV demo.
A Windows installer is available today for Windows XP, Vista, and Windows 7 (x86).
Linux and Mac OSX distributions are coming.
The xBasic IDE overview page is here: http://www.microcsource.com/software.htm
The xBasic support page is here: http://www.microcsource.com/xbasic/help.htm
Please take a little time to try the xBasic IDE. We would appreciate your feedback.
Here is an xBasic IDE screen-shot.
Why another BASIC?
xBasic is designed to run programs from HUB, C3 Flash, or SpinSocket Flash .
xBasic syntax is similar to the older Visual Basic languages but is simpler.
xBasic can start PASM programs in COGs like other languages.
The xBasic IDE and the xBasic tools are multi-platform and open source.
Several demo programs are available including a TV demo.
A Windows installer is available today for Windows XP, Vista, and Windows 7 (x86).
Linux and Mac OSX distributions are coming.
The xBasic IDE overview page is here: http://www.microcsource.com/software.htm
The xBasic support page is here: http://www.microcsource.com/xbasic/help.htm
Please take a little time to try the xBasic IDE. We would appreciate your feedback.
Here is an xBasic IDE screen-shot.
Comments
Do you mean that the IDE won't let you enter 10000000 or that xbasic doesn't work when you set the clock rate to that value?
However, why yet another construct for PUB/PRI using DEF ?
I can enter 100000000 and click Save, but when I re-open that dialog it's back to 80000000.
Well, Steve wrote the IDE. I only wrote the simple compiler underneath. I guess we'll have to wait until he logs in again to get an answer as to why that isn't working. You could try just editing the xbasic.cfg file directly.
That's what I did.
Would also be nice if the Open dialog would remember the last place I opened from; always wants to open from \bin folder.
I'm investigating other aspects of your problem now.
How do you find time for all these projects??!
Do you have some program examples for strings? eg
dim a,b,c as string
a="Hello "
b="World"
c=a + b
print c
No, everything seems fine; re-opening the dialog shows that it isn't.
Please take xbasic-qt.exe from the attached .zip and put in your xBasic IDE bin directory.
Exit and restart the IDE. Try your change test again.
Thanks.
Ross.
Thanks Ross, Dr_Acula, and Cluso99.
There is no string concatenation support in xBasic.
From the xBasic IDE User Guide:
Here is a brief xBasic Language Syntax Summary:
Thanks Ron
I was afraid people would ask for strings. Is it really important to have dynamic string support in an embedded language? Spin and Basic Stamp don't have them but people seem to get a lot done anyway. If you think dynamic strings are an important part of Basic, how much performance would you be willing to sacrifice to have them?
I quite liked the approach SBASIC used where you could dimension a string with a fixed amount of memory. The default was 80 bytes but you could make it smaller for strings that you knew would always be small. So in practice, a string array ended up the same as a byte array in C. I don't know if this would be possible in xbasic?
Yes, that is possible in xbasic. Literal strings are just arrays of bytes with a NUL at the end just like in C. There is even a strcpy function in the runtime library and more C-like string functions could be added. Unfortunately, the code generator can't handle "a + b" as string concatenation. To have more general string support I'd have to implement a string stack and that would slow down function/subroutine calls.
What would make it easier for the code generator to support basic strings? Dimensioning fixed length strings with DIM at the start? Using $ signs on the end to identify string concatenation as opposed to math functions?
I don't think we look to basic for any kind of speed... but no strings really limits things
Great work you two...
strcpy vs +, well it probably does not matter.
what about other string functions, left(), mid(), right(), instr(), str(), chr(), hex()
I have sort-of replicated these in C as C has the flexibility to create new functions that look the same as functions that are part of the language. But not quite. Then inside the function, you do your manipulation on the byte level.
So
dim a,b as string
a = "Hello World"
b = left(a,5)
So you need to pass the location of string a and string b. The above is the BASIC syntax. The workaround in C, and maybe xbasic, is to replace
b=left(a,5)
with
left(b,a,5)
and then everything is passed to the function within the brackets.
That should avoid the need for a string stack.
Strings are easy with traditional Basic because all variables are global. It's a bit harder when you allow functions with arguments and local variables. Then you need to know which values on the stack are dynamic strings and which are just numbers. This means you either have to keep some sort of type tag along with the value or you have to have two separate stacks, one for dynamically allocated objects and one for numbers. Either will slow things down some. Also, the xbasic virtual machine is written in PASM like the Spin VM. I'm not sure I have enough space in the COG for a dynamic memory manager. The fixed-length strings certainly make things a bit easier but it's still difficult to figure out a way to handle complex string expressions like mid$(a$, 1, 2) + " " + left$(b$, 4). You need a string stack for intermediate results.
Is lack of strings why FemtoBasic doesn't get used much? What about PropBasic? I don't think it has strings either. Tiny Basic got used a lot and it didn't support string expressions. What I'm trying to figure out is what they would actually get used for. Don't think that I object to doing the work to implement them. I just want to know that it will be worth the effort because it makes the language more useful on the Propeller. Remember, this isn't Visual Basic on a PC.
That is already possible to define in xbasic. As I said in another post, there is a strcpy function in the existing library. The left function you describe could be written in the same way.
Kye's string driver has most of the string drivers written in spin to do all the common string manipulation and I wrote some more code to do even more. It is part of the kyedos package and if it is helpful to have something in Spin I'll dig that up.
I've got some of this in C as well.
Essentially, with some minor syntax changes to basic (ie everything is passed within a function call) you can do all the string things without needing a stack.
eg, in oldschool basic
a$=hex$(b)
becomes
hex(a,b)
where a is a byte array, and b is a number variable
The function writes some new bytes to the a array.
You can do everything without a stack.
I've written almost all the drivers but there are one or two that look deceptively simple but are a bit more complex. The sneaky one is "str" which returns the string representation of a number.
That is fine for integers, but it is a little more complex for floating point numbers. I think there is code in Spin for that. The problem I haven't quite worked out is how the function "knows" what sort of number it has been passed. Is it an integer like 25 (in which case the string would be "25"), or is it a floating point number (in which case the string would be "25.0000000")
re
I guess I'd chop that up into separate lines of code
mid(a,c,1,2)
strcpy(a," ")
left(d,b,2)
strcpy(a,d)
Messy maybe?
I'll have to do last visited directory stuff later. Will post an update to the web-site tonight or tomorrow.
No. But it has that VB feel to me.
Thanks Tubular and RonP
Those functions could easily be written for xbasic without any changes to the language. Just look at the way strcpy is implemented in the code in the "include" directory and do something similar. I can write those functions if it will help.
Well, xbasic can certainly address more memory than Spin since it can run code from external memory with the appropriate cache driver. I'll have to dust off my DracBlade and get that working with xbasic! Almost the same cache driver as I used for ZOG should work.
Thinking about this some more, I guess
1) Can an interpreter convert that into separate instructions?
2) How does it work with a stack.
Re 1, well lots of interpreters do, the spin compiler is one of them. Is this the done with a railway carriage shuffling algorithim?
Re 2, you could have a stack of maybe 10x80 bytes?
Come to think of it, do you have global and local arrays, like in C? (define global arrays at the beginning, define local arrays in each function, including "main"). Ross used this technique to determine where the data ended up - global arrays (I think) end up in external memory and local arrays are in hub memory.
With xbasic you can place variables wherever you want using the "IN" construction. For instance:
dim a(10) as byte in "hub"
Unfortunately, xbasic doesn't currently support local arrays. It does support local variables though.
Now that I think about it, fixed-maximum length strings might not be very hard to implement after all. I'll think about it more and get back to you. Thanks for the suggestions.
That may or may not be an issue. My programming style is a bit quirky, but I tend to end up with arrays as global and variables as local. So that would be fine for me.
I played around with these in Z80 assembly and also Spin and in C, and found that you can do a lot with ten general purpose string arrays. 80 bytes seemed to work well.
How does that work for external memory? And can you fill the array with data like in C - eg in catalina I have a global array, which ends up in external ram, with a font bitmap
dim myfont(1280) as byte in "external" {1,2,3,4... etc}
or even better, as binary values which C can't do, and then you could see the characters if you lined up the lines right
{ %00101111,%11110000,11111111 }
Re running on a dracblade (or C3, Hydra etc), is the external memory defined as an IDE setting or as a line of code in the program?