Extending BBC Basic...
Pages: 1 2
Alex Farlie (144) 35 posts |
Hi. In other versions of BBC Basic, notably the Windows version by RT Russell some improvements have been made. It is STRONGLY suggested that someone from Castle or RISC OS Open liaise with them so that some of the BB4W improvements could at the very least be synced back into the ARM version. In particular I would like to request extension of ARM BBC Basic to allow use of the structure syntax present in the Windows version. In terms of a more radical extension, how easy would extension of BBC BASIC to cope with ‘Object’ techniques be, given that implementations of simple OO lanaguges (e.g !Squeak) already exist for RISC OS? |
Steve Revill (20) 1361 posts |
We’re quite happy to see that happen. The sources to BASIC have been released so interested parties (such as Steve Drain and RTR) can get in there and add features. |
Alex Farlie (144) 35 posts |
I don’t see commercial developers like RTR jumping into shared source, personally. However, perhaps ROOL/Castle could try to start a standardisation procedure between some of the disparate versions? (such as Basic V, Brandy , and BB4W) The aim of such standardisation might be to allow for the creation of a modern BBC Basic (say Basic 8) which had modern features like structures, objects and 3D (noting that Iyonix supports 3D). Structures would (for Windows style syntax at least) needs someone ‘offical’ to ask RTR extremely nicely for a specification. However this might not be needed if structures and objects are treated together. Objects are straightforward to implement (assuming knowledge of C/ARM code and how C++ compilers work) but time consuming to write parsers for. Some of my own thinking in regard to ‘objects’ is as follows : An object is declared in Basic 8 as follows.'DIM' 'CLASS' {identifier}'~[TO' {identifier}[,{identifier}]]' {block} 'END' 'CLASS' {block} can be any valid BBC Basic code with the exception of the END CLASS statement. An alternative method would be to declare a class by it’s constructor. Non local variables (i.e. those inside methods) created would have ‘object scope’ and would be created for the object by initialisation, or explicitly via LET. Assuming a CLASS already existed the DIM statement could be written shorthand as'DIM' {identifer1}~ 'CLASS' TO {identifer2}~ Which would create a class in memory In memory the location in the variable table for {var}~ would contain a pointer to a variable list and a pointer to a list of procedure/function names, both these pointer would be 32bit with an appropriate Hence the code sequence:DIM CLASS point~: x%=0 : REM field y%=0 : REM field DEF PROCplot PLOT 69,x%,y% ENDPROC END CLASS would create in memory: point~ entry in variable list Address of 'class' paramatter block. !(point~) Link to next object. (note this list need not be contiguous) Value would be dependent on what objects already declared. (point~!4) parent or prototype (this is relevant re inheritance) =NUL (point~!8) Method number or 0 =1 (point~!12) link to next method = NIL (point~!bb) Address of tokenised code to do procedure/function (point~!aa) 'p''l''o''t' [NUL] NB additonal NULS would be padded to ensure word alignment. (point~!zz) End of methods (FFFF EEEE) (point~!aa) Number of variables. (point~!aa+4) Address of datablock (point~!aa+8) Offset to Next entry = 8 ( see point~!bb) (point~!aa+12) Offsest from !bbb =0 (point~!aa+16) 'x''%'[NUL][NUL] (point~!bb Offset to Next entry= NIL (point~!bb+4) Offset from !bbb = 4 (point~!bb+8) 'y''%'[NUL][NUL] {point~!cc+4) end of object. Feel free to correct me if my understanding of variable layout on BASIC V is mistaken , I can swap fields around if needed. The use of ~ to refer to a 'class' pointer variable of course assumes ~ as a variable type CAN be distinguished from ~ used as an operator in PRINT statements in Basic 8. Feedback on the above is much appreicated, espically if you (or others actually want to put this syntax in BBC Basic :) ) |
Alex Farlie (144) 35 posts |
Apologies for the formatting mess… Will send the ASCII version to email if interested :) |
Andrew Hodgkinson (6) 465 posts |
Try wrapping what you intended to say in There’s a tests page in the Wiki which can be handy for playing about with Textile |
nemo (145) 2556 posts |
The whole OOBASIC thing was thrashed out between the two Steves, Richard and I years ago, and R went on to implement some of it in the Windows version. I did the whole lot including class methods and “templating” (which was actually a form of casting). Perhaps this would be a good outlet for some of that old stuff. |
Alex Farlie (144) 35 posts |
Nemo, Willing to share? :) If so I think you’ve kickstarted Basic 8 ( 8 looking like two stacked o’s) Did you have a technical paper you could put on something like the wiki here (or one of the other RISC OS) wiki’s? What where your thoughts on the ‘object’ layout I suggested BTW? |
nemo (145) 2556 posts |
Erm, didn’t like the syntax. We all decided on:
Do a search on Google Groups for all the torrid details. |
Alex Farlie (144) 35 posts |
Your syntax looks better… You also had some thoughts on how to tweak the interpreter it seems, with the sources now available perhaps you could make some tests, assuming the sources build. |
nemo (145) 2556 posts |
I’ve always had a source! |
Alan Robertson (52) 420 posts |
Nemo, It’s good to see you back (at least temporarily) on the RISC OS scene. Wish you’d come back. It would be good to have you working on the sources… Anyway, all the best. |
nemo (145) 2556 posts |
Too kind. |
Trevor Johnson (329) 1645 posts |
David Braben has mentioned BBC BASIC on the Raspberry Pi (thanks for pointing it out, Vince) so is it worth picking up the "Basic 8" discussion again? Also, this morning’s c.s.a.programmer thread on Running BASIC text files talks about renumbering 1,1. If we want to be able to diff BASIC sources here then is this important? (I’ve no idea what the largest BASIC RO source file is.) |
Trevor Johnson (329) 1645 posts |
Thanks… and to push it right to the limit, instead of |
Sprow (202) 1158 posts |
I thought about that, but I’m aware that some things prefix libraries to other BASIC programs where the library is (effectively) done with RENUMBER 0,0 – ie. every line is line 0 – using some combination of *LOAD and the value of TOP. I couldn’t think of a situation where your would interleave 9 lines of one program with 1 line of TEXTLOADed program, so for maximum compatibility just changing the step seemed safest. Frankly, if you’ve got 65279 lines of BASIC and those last 9 are important to you, you’re probably using the wrong language. |
Trevor Johnson (329) 1645 posts |
Sorry and thanks for the detailed explanation. |
Trevor Johnson (329) 1645 posts |
In case I forget to add this to the bug tracker (when it’s available again)… does faulting zero shifts (thanks John Kortink and Martin Wuerthner) mean anything? |
Sprow (202) 1158 posts |
Well yes, ASR and ROR can’t do shifts of 0 (LSL and its alias ASL can) because the instruction encoding forbids it (ASR is 1 to 32 encoded in 5 bits as 0 to 31, and ROR#0 encodes RRX). Typically, you’ll hit the problem as Martin says when you’re using BASIC to do run time code generation, and I think that’s probably also the time you do want the error since the code generator has output something probably isn’t what was wanted. An alternative is to go via a macro:
replaced with
and to deal with the shift of zero there. |
Andrew Rawnsley (492) 1445 posts |
Edit: Post was made on wrong thread, sorry. |
James Lampard (51) 120 posts |
I don’t quite understand this, if you want to add a library to a basic program you suffix it onto the end surely? I can’t think of any reason why you would want it to come before.
If you had a program which had a library added to it where every line was numbered 0, and you TEXTLOADed it as a text file, interleaving would be the least of your problems. You would only get the last line of the library (which would replace all the earlier ones numbered 0)
True. |
Jeffrey Lee (213) 6048 posts |
I suppose there could be scope for extending the “ON …” syntax to include “ON END” for defining exit handlers. |
Steve Drain (222) 1620 posts |
Not entirely relevant, but Basalt deals with open files this way. Files are opened with statement versions of The idea of a more general exit handler that works when the program ends prematurely is interesting. 1 Statements are used so that the original keywords are not changed. BASIC itself could be changed to do the same with its functions. |
nemo (145) 2556 posts |
Erm…
versus
Unless your code has a LOT of ENDs in it… I can’t see the point. ONERROR is important because there are a bazillion entry points. ONEND is not equivalent. I bet 99% of Wimp programs already have a single exit point – Wimp_CloseDown, MessageTrans_CloseFile, etc. |
nemo (145) 2556 posts |
Having said that, there’s something to be said for files being auto-closed when ANY app exits. That is to say, OS_File from app space, add resulting file handle to a per-app list. After app exits, close those files. The ‘app space’ bit is questionable… the only usage scenario where files ought to be left open after the task has quit is fonts… and FontManager copes magnificently with its handles being closed for it. Have I forgotten some other useful file-left-open scenario? |
Jeffrey Lee (213) 6048 posts |
Closing a task window will invoke the exit environment handler of whatever program is running inside that task window. Currently BASIC doesn’t allow any BASIC code to be invoked during as part of the exit handler; “ON END” was proposed as a solution for that (similar to how “ON ERROR” allows code to be run from the error environment handler) |
Pages: 1 2