Shop OBEX P1 Docs P2 Docs Learn Events
NEW: xBasic IDE and Compiler for Propeller — Parallax Forums

NEW: xBasic IDE and Compiler for Propeller

jazzedjazzed Posts: 11,803
edited 2011-08-27 12:46 in Propeller 1
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.

image012.jpg
«13456

Comments

  • David BetzDavid Betz Posts: 14,516
    edited 2011-08-22 14:08
    Thanks for posting this Steve! Anyone who downloads this and tries it should feel free to make suggestions for improvements. For instance, changing the syntax to match JavaScript or Lisp would be seriously considered. :-)
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-08-22 15:45
    Very nice little IDE. I have it hooked up to an EFX-TEK HC-8+ (new product) with a 6.25MHz crystal and it doesn't seem to like me changing 80000000 to 100000000.
  • David BetzDavid Betz Posts: 14,516
    edited 2011-08-22 16:05
    JonnyMac wrote: »
    Very nice little IDE. I have it hooked up to an EFX-TEK HC-8+ (new product) with a 6.25MHz crystal and it doesn't seem to like me changing 80000000 to 100000000.

    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?
  • Cluso99Cluso99 Posts: 18,069
    edited 2011-08-22 16:34
    Looks great guys!

    However, why yet another construct for PUB/PRI using DEF ?
  • David BetzDavid Betz Posts: 14,516
    edited 2011-08-22 16:39
    This isn't supposed to be a Spin clone. We already have Spin. This is a version of Basic. The DEF replaces SUB in regular Basic because it defines both subroutines and functions.
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-08-22 16:39
    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?

    I can enter 100000000 and click Save, but when I re-open that dialog it's back to 80000000.
  • David BetzDavid Betz Posts: 14,516
    edited 2011-08-22 16:50
    JonnyMac wrote: »
    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.
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-08-22 16:52
    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.
  • jazzedjazzed Posts: 11,803
    edited 2011-08-22 16:55
    JonnyMac wrote: »
    I can enter 100000000 and click Save, but when I re-open that dialog it's back to 80000000.
    Thanks for looking at this Jon. Do you get any dialog box errors?
    I'm investigating other aspects of your problem now.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2011-08-22 17:11
    Wow, this is great!
    Over the last several months David Betz and I have been working on xBasic.

    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
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-08-22 17:19
    Thanks for looking at this Jon. Do you get any dialog box errors?

    No, everything seems fine; re-opening the dialog shows that it isn't.
  • jazzedjazzed Posts: 11,803
    edited 2011-08-22 17:19
    Hi Jon.
    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.
    JonnyMac wrote: »
    I can enter 100000000 and click Save, but when I re-open that dialog it's back to 80000000.
  • RossHRossH Posts: 5,519
    edited 2011-08-22 17:20
    Looks good, guys. Well done!

    Ross.
  • jazzedjazzed Posts: 11,803
    edited 2011-08-22 17:47
    RossH wrote: »
    Looks good, guys. Well done!

    Ross.

    Thanks Ross, Dr_Acula, and Cluso99.
    Dr_Acula wrote: »
    Wow, this is great!



    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

    There is no string concatenation support in xBasic.

    From the xBasic IDE User Guide:
    What is xBasic?
    The xBasic programming language was developed for Propeller by David Betz. It uses many language constructs found in other BASIC language variations. The language does not use line numbers. It does not provide dynamic string concatenation support. It def’s constants and functions, dim’s variables, and allows labels for goto statements where necessary. xBasic allows for in-lined xBasic VM assembly and Propeller instructions. The feel of xBasic is similar to the older non-object oriented Visual Basic versions.

    Here is a brief xBasic Language Syntax Summary:
    Language syntax:
    
    REM comment
    
    INCLUDE filename-string
    
    OPTION
    
    DEF var = constant_expr
    
    DEF function-name
    DEF function-name ( arg [ , arg ]... )
    
    END DEF
    
    arg:
    
        var
        var variable-type
        var()
        var() variable-type
        
    RETURN expr
    
    dim-statement:
    
        DIM variable-def [ , variable-def ]...
        
    variable-def:
    
        var [ variable-type ] [ section-placement ] [ scalar-initializer ]
        var ( size ) [ variable-type ] [ section-placement ] [ array-initializer ]
        
    variable-type:
    
        AS INTEGER
        AS BYTE
    
    section-placement:
    
        IN section-name-string
        
    scalar-initializer:
    
        = constant-expr
        
    array-initializer:
    
        = { constant-expr [ , constant-expr ]... }
    
    var = expr
    
    IF expr
    
    ELSE IF expr
    
    ELSE
    
    END IF
    
    SELECT expr
    
    CASE expr [ , expr ]...
    
    CASE expr TO expr
    
    CASE ELSE
    
    END SELECT
    
    STOP
    
    END
    
    FOR var = start TO end [ STEP inc ]
    
    NEXT var
    
    DO
    DO WHILE expr
    DO UNTIL expr
    
    LOOP
    LOOP WHILE expr
    LOOP UNTIL expr
    
    label:
    
    GOTO label
    
    PRINT expr [ ;|, expr ]... [ ; ]
    
    expr AND expr
    expr OR expr
    
    expr ^ expr
    expr | expr
    expr & expr
    
    expr = expr
    expr <> expr
    
    expr < expr
    expr <= expr
    expr >= expr
    expr > expr
    
    expr << expr
    expr >> expr
    
    expr + expr
    expr - expr
    expr * expr
    expr / expr
    expr MOD expr
    
    - expr
    ~ expr
    NOT expr
    
    function ( arg [, arg ]... )
    array ( index )
    
    (expr)
    var
    integer
    "string"
    
    Registers:
    
    PAR
    CNT
    INA
    INB
    OUTA
    OUTB
    DIRA
    DIRB
    CTRA
    CTRB
    FRQA
    FRQB
    PHSA
    PHSB
    VCFG
    VSCL
    CLKFREQ
    
  • RonPRonP Posts: 384
    edited 2011-08-22 17:48
    Is it Christmas? Awesome guys.!

    Thanks Ron
  • David BetzDavid Betz Posts: 14,516
    edited 2011-08-22 18:08
    Dr_Acula wrote: »
    Wow, this is great!



    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

    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?
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2011-08-22 18:15
    Good point. Actually, dynamic strings in the original MBASIC were never all that good, because every now and then the program would hang (sometimes for a minute) while it sorted out the strings.

    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?
  • David BetzDavid Betz Posts: 14,516
    edited 2011-08-22 18:19
    Dr_Acula wrote: »
    Good point. Actually, dynamic strings in the original MBASIC were never all that good, because every now and then the program would hang (sometimes for a minute) while it sorted out the strings.

    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.
  • TubularTubular Posts: 4,717
    edited 2011-08-22 18:29
    David,

    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...
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2011-08-22 18:35
    Ok, well if strings are just byte arrays like in C with a NUL on the end then strings will end up similar to C.

    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.
  • David BetzDavid Betz Posts: 14,516
    edited 2011-08-22 18:37
    Tubular wrote: »
    I don't think we look to basic for any kind of speed... but no strings really limits things.

    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.
  • David BetzDavid Betz Posts: 14,516
    edited 2011-08-22 18:40
    Dr_Acula wrote: »
    left(b,a,5)

    and then everything is passed to the function within the brackets.

    That should avoid the need for a string stack.

    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.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2011-08-22 18:55
    Well I guess everyone has a reason for their favourite language, and I've moved away from spin because there isn't enough program space, and all the Basic languages for the prop don't have strings so I've gone over to C.

    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
    mid$(a$, 1, 2) + " " + left$(b$, 4)

    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?
  • jazzedjazzed Posts: 11,803
    edited 2011-08-22 18:56
    @JonnyMac, did the .exe in that zip file fix your clock setting problem?
    I'll have to do last visited directory stuff later. Will post an update to the web-site tonight or tomorrow.


    David Betz wrote: »
    Remember, this isn't Visual Basic on a PC.
    No. But it has that VB feel to me.



    Thanks Tubular and RonP :)
  • David BetzDavid Betz Posts: 14,516
    edited 2011-08-22 19:04
    Dr_Acula wrote: »
    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?

    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.
  • David BetzDavid Betz Posts: 14,516
    edited 2011-08-22 19:07
    Dr_Acula wrote: »
    Well I guess everyone has a reason for their favourite language, and I've moved away from spin because there isn't enough program space, and all the Basic languages for the prop don't have strings so I've gone over to C.

    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.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2011-08-22 19:09
    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.

    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.
  • David BetzDavid Betz Posts: 14,516
    edited 2011-08-22 19:15
    Dr_Acula wrote: »
    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.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2011-08-22 20:04
    Unfortunately, xbasic doesn't currently support local arrays. It does support local variables though.

    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.
    Now that I think about it, fixed-maximum length strings might not be very hard to implement after all.

    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.
    dim a(10) as byte in "hub"

    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?
  • ercoerco Posts: 20,259
    edited 2011-08-22 20:15
    Nice job guys. Now Humanoido must update his list of 150+ languages that the Prop can be programmed in.
Sign In or Register to comment.