SiriusHardware
Posts: 500
Joined: Thu Aug 02, 2012 9:09 pm
Location: UK

BBC Basic compilable?

Fri Dec 28, 2012 1:37 pm

Sorry if this is a naive question, but can programs written in ARM variants of BBC BASIC be compiled to standalone executables which will run under Pi RISCOS like any other RISCOS utility?

My last exposure to BBC BASIC was on an authentic BBC model B - although it was a lovely implementation of the language it would never have won any awards for speed, and so if you wanted to write anything which ran fast you had to resort to using 6502 assembler (which was a nice feature built into that version).

-But I've never seen the ARM versions - is there an integral or standalone compiler for those versions?

User avatar
Burngate
Posts: 6005
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: BBC Basic compilable?

Fri Dec 28, 2012 5:20 pm

RISC OS on the Pi, as on any other platform, has the BBC BASIC interpreter built-in.
This means that anything written in BBC BASIC will run on any machine that has RISC OS.
Included in the interpreter is an Arm assembler, so if your BASIC program contains assembler code, that also works.

I have written programs on my RiscPC that run well on the Pi, as well as on my VirtualRPC (an emulator which runs on my Windows Laptop)

There are of course caveats - anything hardware-dependent will have problems. So a program written on the Pi that used the GPIOs would struggle when run on another computer
And screen resolutions being hardware-dependent, graphics could be difficult, depending on how it was written.
So that wonderfull program I wrote on my Archimedes (the successor to the BBC-B) works, but because it changes the screen-mode, the graphics are all to cock, and the Pi won't recover without a reboot!

There have been attempts to compile BASIC programs, but you gain almost nothing from doing so, because of the way the interpreter is integrated into RISC OS.
In part this is because the size of the interpreter means it fits inside the processor cache, meaning only your program has to be fetched from memory.
Also, although you write the program in text, it's stored in a condensed format, taking less space on disc. And when it's run, it gets squashed even more, meaning fewer memory transactions.

Steve Drain
Posts: 105
Joined: Tue Oct 30, 2012 2:08 pm
Location: Exeter UK

Re: BBC Basic compilable?

Fri Dec 28, 2012 5:40 pm

SiriusHardware wrote:Sorry if this is a naive question, but can programs written in ARM variants of BBC BASIC be compiled to standalone executables which will run under Pi RISCOS like any other RISCOS utility?
Although there are possible ways to compile ARM BBC BASIC, it is essentially an interpreted language. The interpreter module is already available on startup with all versions of RISC OS, including the Pi, and any programs can be run in the normal way.

There have been some changes in the versions of BASIC, but they are small and will not affect most programs. Because it is interpreted, BASIC itself is largely immune from changes in the underlying hardware and operating system and a program from a long time ago will be odds-on to run on the latest machine. However, most useful programs call OS routines so that is no guarantee, but you are unlikely to encounter the problems of programs written in C or assembler.
My last exposure to BBC BASIC was on an authentic BBC model B - although it was a lovely implementation of the language it would never have won any awards for speed, and so if you wanted to write anything which ran fast you had to resort to using 6502 assembler (which was a nice feature built into that version).
That BASIC was pretty zippy for that machine, even if the best speed had to come from machine code. Likewise, ARM BBC BASIC is fast, and hundreds of very useable desktop applications have been written with it. The built-in ARM assembler can be used for particular speed enhancement.
-But I've never seen the ARM versions - is there an integral or standalone compiler for those versions?
Do not think compiler. Just write programs and run them. You will not realise they are interpreted until you get into very intensive processing, and then you should probably be using C.

As an afterword, remember that there are other versions of BBC BASIC for many machines - do a search. Programs written with these will only be compatible at the very simplest level.

User avatar
RichardRussell
Posts: 578
Joined: Thu Jun 21, 2012 10:48 am

Re: BBC Basic compilable?

Sat Dec 29, 2012 9:44 am

Just as a clarification of terminology, 'compiling' in the sense that the OP uses it doesn't necessarily mean converting BASIC to machine code. He refers explicitly to being "compiled to standalone executables" and of course it's perfectly possible to create a 'standalone executable' whilst still being interpreted!

That's exactly what BBC BASIC for Windows does: the 'compile' feature combines a crunched version of the BASIC program with the interpreter ('run time engine') to create a standalone EXE file which behaves in every respect like any other 'compiled' program, but the code is nevertheless interpreted at run time.

Of course if running RISC OS - when the BBC BASIC interpreter is effectively built into the OS - there is little point in doing this (although there might be in the case of BASIC64) but when/if BBC BASIC becomes available for Linux on the RPi an option to create standalone executables could be useful.

Richard.

User avatar
RichardRussell
Posts: 578
Joined: Thu Jun 21, 2012 10:48 am

Re: BBC Basic compilable?

Sat Dec 29, 2012 9:55 am

Steve Drain wrote:As an afterword, remember that there are other versions of BBC BASIC for many machines - do a search. Programs written with these will only be compatible at the very simplest level.
If you run Jonathan Harston's BASICplus the compatibility with (in particular) BBC BASIC for Windows is greatly improved. Although there are some features he has not yet implemented (notably structures and long strings) many of the BB4W extensions are incorporated, so writing a program that will run on both a Windows PC and a RISC OS machine doesn't mean restricting yourself to "the very simplest level" of BBC BASIC code.

Richard.

SiriusHardware
Posts: 500
Joined: Thu Aug 02, 2012 9:09 pm
Location: UK

Re: BBC Basic compilable?

Sat Dec 29, 2012 12:47 pm

Hi gents, thanks for the interesting replies. My reasons for posing this question were twofold -

One, that code assembled or compiled to executable code should always run faster than the interpreted alternative - although of course that depends upon how it is done. In the old days the interpreter would work through every line of code working out what to do each time that line of code was encountered - a terrible waste of processor time. I suppose that on modern machines with memory to burn, the interpreter could do a single initial pass through the whole source code effectively assembling or compiling it to a ready-to run image in RAM, and then run it. Is that what modern interpreted languages (Like Python) actually do?

Secondly, I'd prefer any final application written in this (or any other language) to be a single, independently executable file which does not assume the presence of any other resource which may or may not be present on the host. (Obviously, if the compiler uses calls to OS system functions then the OS at least would always have to be present).

neilf
Posts: 72
Joined: Sun Nov 11, 2012 8:14 am

Re: BBC Basic compilable?

Sat Dec 29, 2012 1:04 pm

ARM BBC Basic is very quick as an interpreted language - being hand coded for speed of execution. There's no need for compilers (but one or two are available if you're determined to use one).

I write some quite complex full gui programs in ARM Basic and they more than hold their own on the desktop, plus of course, you still have the in-line assembler available for speed-critical sections. The world has moved on a long way since the days of the BBC Micro. 8-)

All ARM Basic code is completely free-standing - you can move a program it to any modern Risc OS machine and it will run straight away, because BBC Basic is built into the OS.

User avatar
RichardRussell
Posts: 578
Joined: Thu Jun 21, 2012 10:48 am

Re: BBC Basic compilable?

Sat Dec 29, 2012 3:16 pm

SiriusHardware wrote:code assembled or compiled to executable code should always run faster than the interpreted alternative
Of course that is (mostly) true, but it's comparatively rare for it to be important. Commonly the overall speed of a program is determined by its I/O, for example graphics rendering may be the limiting factor, or the speed with which data can be read from a disk. The great majority of the programs I write in BBC BASIC would show no noticeable speed benefit from being converted to machine code.

Incidentally the reason I added "mostly" there is that things are not always as clear cut as they might seem. Cache performance often impacts significantly on overall speed, so if an 'interpreted' program is much smaller than its machine-code equivalent (which it typically will be, if an efficient 'byte code' is used), and if the run-time engine is small enough to fit in the CPU's instruction cache, the much more efficient cache usage may go some way to claw back the speed penalty inherent in an interpreter.
the interpreter could do a single initial pass through the whole source code effectively assembling or compiling it to a ready-to run image in RAM, and then run it. Is that what modern interpreted languages (Like Python) actually do?
Not really, because what you describe is effectively what a compiled language does. More likely is that a Just In Time (dynamic translation) approach will be used: http://en.wikipedia.org/wiki/Just-in-time_compilation
I'd prefer any final application written in this (or any other language) to be a single, independently executable file which does not assume the presence of any other resource which may or may not be present on the host.
Absolutely, and as I said it's in that sense that BBC BASIC for WIndows 'compiles' its executables. They do run faster than when interpreted in the IDE, but not much.

Richard.

Steve Drain
Posts: 105
Joined: Tue Oct 30, 2012 2:08 pm
Location: Exeter UK

Re: BBC Basic compilable?

Sat Dec 29, 2012 5:06 pm

SiriusHardware wrote:I'd prefer any final application ... to be a single, independently executable file which does not assume the presence of any other resource ...
RISC OS is predicated on shared resources. If you ignore that you are just making trouble for yourself. Start simple, look at some applications, see how things are done. An application is not a single file, but it is, more or less, a self-contained entity. BASIC and C are the common languages to start with and either can do nearly everything you will need at first. Speed is very unlikely to be your main problem.

SiriusHardware
Posts: 500
Joined: Thu Aug 02, 2012 9:09 pm
Location: UK

Re: BBC Basic compilable?

Wed Jan 02, 2013 11:01 am

The more I read about RISCOS the more I think it's a pity that it was not adopted as the main OS for the Pi from the beginning, as it would have brought the machine much closer to having a single user interface and instantly available programming language right from switch-on.

I personally cannot understand the apparent loathing with which BASIC appears to be regarded in programming circles - I appreciate that Python is very BASIC-Like, and I've spent maybe 10-20 hours writing and debugging Python code, but I just don't feel as instantly comfortable with it as I do with BASIC.

I'm away from my Pi at the moment but I have now decided to give RISCOS and BBC basic a try.

I'd be grateful if you can suggest the most appropriate online tutorial or manual for the BASIC which is bundled with Pi RISCOS, and ditto for the ARM assembler variant / instruction set used by the Pi's processor?

User avatar
RichardRussell
Posts: 578
Joined: Thu Jun 21, 2012 10:48 am

Re: BBC Basic compilable?

Wed Jan 02, 2013 12:57 pm

SiriusHardware wrote:I personally cannot understand the apparent loathing with which BASIC appears to be regarded in programming circles
It depends on what you mean by "programming circles". As far as the teaching of programming is concerned, BBC BASIC is recommended by the OCR examining board for their GCSE qualification in computing: Unit A451 Computer Systems and Programming 'may contain questions in a generic pseudocode that looks a lot like BBC BASIC, e.g. BBC BASIC for WINDOWS, or PASCAL' and 'all tasks have been tested in VB.net and BBC BASIC for Windows to make sure they are suitable'.

Richard.


User avatar
MonitorMan
Posts: 22
Joined: Tue Jan 03, 2012 1:31 am
Contact: Website

Re: BBC Basic compilable?

Wed Jan 02, 2013 9:24 pm

SiriusHardware wrote:The more I read about RISCOS the more I think it's a pity that it was not adopted as the main OS for the Pi from the beginning, as it would have brought the machine much closer to having a single user interface and instantly available programming language right from switch-on.

I personally cannot understand the apparent loathing with which BASIC appears to be regarded in programming circles - I appreciate that Python is very BASIC-Like, and I've spent maybe 10-20 hours writing and debugging Python code, but I just don't feel as instantly comfortable with it as I do with BASIC.

I'm away from my Pi at the moment but I have now decided to give RISCOS and BBC basic a try.

I'd be grateful if you can suggest the most appropriate online tutorial or manual for the BASIC which is bundled with Pi RISCOS, and ditto for the ARM assembler variant / instruction set used by the Pi's processor?

You may want to check out my Assembly Language book for the Raspberry Pi at the link below.
Raspberry Pi Assembly Language now available in book and eBook formats.
For details, go to www.brucesmith.info - examples and programming hints and tips.
Check out the Raspberry Pi Resources page on the website for more information.

SiriusHardware
Posts: 500
Joined: Thu Aug 02, 2012 9:09 pm
Location: UK

Re: BBC Basic compilable?

Thu Jan 03, 2013 8:39 pm

MonitorMan wrote:
You may want to check out my Assembly Language book for the Raspberry Pi at the link below.
Thanks for that info - I wasn't aware it had been published. It looks ideal for me.

SiriusHardware
Posts: 500
Joined: Thu Aug 02, 2012 9:09 pm
Location: UK

Re: BBC Basic compilable?

Thu Jan 03, 2013 9:00 pm

RichardRussell wrote:
It depends on what you mean by "programming circles". Richard.
I think I meant that it appears to be a neglected language when it comes to commercial use, where 'C' and derivatives or developments seem to be much more heavily favoured.

The usual criticism is that it allows the user to write 'Spaghetti' code and so should be condemned to programming Hell. But it remains one of the most easily humanly readable of all programming languages, and consequently very easy to understand, debug and modify.

SiriusHardware
Posts: 500
Joined: Thu Aug 02, 2012 9:09 pm
Location: UK

Re: BBC Basic compilable?

Thu Jan 03, 2013 9:00 pm

Raeddie wrote:The BASIC manual as PDF: http://foundation.riscos.com/Private/manuals/BASIC/
Thanks for that!

User avatar
aTao
Posts: 1087
Joined: Wed Dec 12, 2012 10:41 am
Location: Howlin Eigg

Re: BBC Basic compilable?

Thu Jan 03, 2013 9:34 pm

SiriusHardware wrote:can programs written in
a computer language
be compiled to standalone executables
Yes
>)))'><'(((<

User avatar
RichardRussell
Posts: 578
Joined: Thu Jun 21, 2012 10:48 am

Re: BBC Basic compilable?

Thu Jan 03, 2013 10:34 pm

SiriusHardware wrote:The usual criticism is that it allows the user to write 'Spaghetti' code
But so does C (both C and BASIC have a GOTO statement), yet C doesn't tend to attract the same criticism! In both languages it's entirely up to the programmer whether he chooses to write structured code or not. In fact you can argue that C, in providing labels, actually encourages the use of GOTO more so than BBC BASIC, which provides only line numbers as the destination (apart from BBC BASIC for Windows, which does have labels).

If BBC BASIC programs tend to be less well structured than C programs it's not the fault of the language, it's the fault of the programmers!

Richard.

SiriusHardware
Posts: 500
Joined: Thu Aug 02, 2012 9:09 pm
Location: UK

Re: BBC Basic compilable?

Thu Jan 03, 2013 10:44 pm

RichardRussell wrote:
SiriusHardware wrote:The usual criticism is that it allows the user to write 'Spaghetti' code
But so does C (both C and BASIC have a GOTO statement), yet C doesn't tend to attract the same criticism! In both languages it's entirely up to the programmer whether he chooses to write structured code or not. In fact you can argue that C, in providing labels, actually encourages the use of GOTO more so than BBC BASIC, which provides only line numbers as the destination (apart from BBC BASIC for Windows, which does have labels).

If BBC BASIC programs tend to be less well structured than C programs it's not the fault of the language, it's the fault of the programmers!

Richard.
I did not say that it was MY criticism. :| Only that it was a criticism commonly used to dismiss BASIC as an 'unworthy' language. I love BASIC.

I've often described 'C' as a write-only language because it is so difficult to read. (And before anyone jumps unnecessarily to the defence of C, I have written thousands of lines of code for embedded projects in 'C'. It's just that 'C' looks a lot less like English than BASIC does).

User avatar
Grumpy Mike
Posts: 914
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: BBC Basic compilable?

Thu Jan 03, 2013 10:50 pm

If you want a true write only language then you should try looking at some Fourth.

User avatar
aTao
Posts: 1087
Joined: Wed Dec 12, 2012 10:41 am
Location: Howlin Eigg

Re: BBC Basic compilable?

Thu Jan 03, 2013 10:52 pm

Grumpy Mike wrote:If you want a true write only language then you should try looking at some Fourth.
Or a craddy language like Lithp
>)))'><'(((<

AMcS
Posts: 184
Joined: Sun Jan 06, 2013 11:23 am
Location: Dublin, Ireland

Re: BBC Basic compilable?

Sun Jan 06, 2013 11:41 am

can programs written in ARM variants of BBC BASIC be compiled to standalone executables which will run under Pi RISCOS like any other RISCOS utility?
Short answer is possibly but with some restrictions.

The question would be why would you want to as BBC BASIC V is pretty fast as is (and if you need even higher performance you can "interleave" it with ARM Assembly Code for the speed critical bits).

There is a compiler (ABC Compiler) that could take *most* BBC BASIC programs (it can't handle the EVAL() function and there are a few other minor differences) and compile them.

It was 32bitted and was available as part of the Software Development environment from RISC OS Open (http://www.riscosopen.org).

Don't know if this will work on R-PI though, has anyone tried this ?

It also requires that you distribute ABCLib with any application you release that are compiled with ABC (if the recipient doesn't already have that installed).

Regards
AMcS

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: BBC Basic compilable?

Sun Jan 06, 2013 3:08 pm

If you are already familiar with writing BBC-BASIC programs for RISC OS and with programming for the RISC OS WIMP, and you really need a compiler, there is one called Whiz (if I remember correctly).

It does not support the screen oriented statements, though you usually should not be using those in a WIMP program anyway. It does support enough to compile most WIMP programs. Also i think that it is missing support for assembly.

I do not know if it and the code it produces are completely 32-bit addressing clean or not (it may not run on the RPi).
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: BBC Basic compilable?

Tue Sep 17, 2013 3:46 pm

Ok I can now say that ABC is completely RPi compatable. I have compiled a few things with it.

Though I would reiterate what others have said in that for most applications there is no real benifit in Compiling as the BBC BASIC interpreter is quite fast, and it is part of RISC OS, so there are no special requirments in having an application written in BBC BASIC on RISC OS.

Some of the applications that you likely run in RISC OS are interpretted BBC BASIC, for example:
-The Screen Savers: DeskBall, Rain, Shred, Snow, and SprBounce.
-!CloseUp.
-!Maestro.
-!SciCalc.
-!Blocks.
-!Flasher.
-!Madness.
-!MemNow.
-!Patience.
-!Puzzle.
-!7backup.
-!Usage. (Partly)
-!WinMenu. (Partly)
-!Chars.
-!SDCreate.
Just to list a few that come with the RPi distrobution of RISC OS.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

AMcS
Posts: 184
Joined: Sun Jan 06, 2013 11:23 am
Location: Dublin, Ireland

Re: BBC Basic compilable?

Tue Sep 17, 2013 9:58 pm

DavidS wrote:Ok I can now say that ABC is completely RPi compatable. I have compiled a few things with it.
Thanks for confirming that David.

Return to “RISCOS”