BASIC compiler
Rick Murray (539) 13840 posts |
Of course, but “they” have to accept that it is way down on the list of priorities. I mean, let’s take a vote – better USB and a newer network stack…or some tarting up of BASIC? ;-)
Hmm, what’s the deal with the postbox red lipstick?
A function that takes and/or returns functions in its arguments. I’ve seen that done in C – one of the Inform adventure interpreters does that. It is clever and horrible. Oh look, we’re back to “nasty pointer abuse in C” again.
That’s a perfectly fair approach, however it is worth noting that when you give up maintaining a package, that doesn’t necessarily mean all of the people using it have given up and moved on. I could name dozens of programs where the author has moved on, forgotten their program, and…it’s still in use some place.
One of my first C projects was a module to maintain a big array of data. When bits of data were removed, the rest would be shuffled around to fill in the gap. It was a linear block, nothing fancy like a linked list. So, deleting the first bit of data meant shuffling around everything (another 220 blocks) after. The code in BASIC took about forty seconds. A revised bit of code in BASIC trimmed this to 20 seconds by writing the data out to file (skipping the bit we wanted to delete) and loading it back in again. Obviously if your program does little bursts of processing in response to user input, there won’t be much difference. For computationally heavy programs, there should be a big difference.
You got that far? When I tried it choked on GCOL 255,255,255 though I do wonder how well it would cope with the first three DIMs of the program. For those who don’t know, it is 10000000, 10000000, and 2000000 – or ~22MiB in three DIM statements.
I’m just interested in how it works, plus want to support some of the later changes to BASIC (such as the GCOL example) while I’m at it. It looks (at a brief examination of the program) as if ABC was itself built using ABC. Cool. ;-) Another thing I noticed is that compiling “e = e% / n%” (don’t worry about what e% and n% are) gives us:
In this day and age, there really ought to be an option to use VFP or NEON in the FP maths, instead of an ancient emulated floating point system. We’ve already done the tests (last year), the differences between FPE and VFP were phenomenal. And yes, I could lay the exact same blame on the C compiler, as it does the exact same thing. :-/
;-) That’s a mindset from a previous generation. Now we all know that we don’t have any rights over our creations. But that’s an argument for another day.
Indeed, which is why I would encourage open sourcing projects when you no longer want to maintain them. And preferably using a true open licence instead of GPL.
Now you’re being ridiculous. It would be nice to have these sorts of things (I still haven’t figured out the Ovation file format yet, though I’ve not tried much due to lack of time), the reality is that most projects around don’t have this sort of documentation. The mechanism is expressed in the code and in the head of the programmer. Where this does exist, any competent programmer would be inclined to distrust it until such documentation can be shown to be correct. Examples? The RISC OS sources are littered with documents that were correct when RISC OS 3.10 was released…
It can be quite galling to see your work that you spent the time creating lifted, pasted somewhere else, and passed off as somebody else’s work. And, worse, when idiots then think YOU are the one plagarising.
I did, once. I think I made about twenty quid, which in no way even slightly re-compensated the time it took. So now I just don’t bother. I write programs that I want, when I want. If this benefits others, good. If not, no big deal.
??? I read that as “money paid should be for fancy packaging”. Please tell me I’m misreading.
Oh, now I know you’re an optimist.
“Goddammit man, it’s 2016 and you’re using a bubble sort???” |
Chris Johnson (125) 825 posts |
I think this was actually somewhere in the original documentation for ABC. |
Steve Fryatt (216) 2105 posts |
In BASIC, AppBASIC did pretty much exactly that: unfortunately, as noted in this thread, it’s now abandonware… Also, a large amount of C code is written like that, albeit not with the pointy-clicky-GUI-builder bit: most core C libraries in use today are event-based, so that the developer registers functions with the Wimp event handler (or even pseudo-event handler if the library is more high-level) for bits of their GUI and then lets the event dispatcher call those handler functions as required. |
Steve Fryatt (216) 2105 posts |
I’m not sure that I completely follow this. It’s true that not all software can be Open Source, but being realistic there’s little reason why RISC OS stuff that’s available to download for free from the internet shouldn’t be. If users can get it for free, why shouldn’t they also be able to fix bugs if you can’t or won’t? Sometimes the developer will be legitimately using code that’s it’s not possible to licence in a suitable way, but otherwise what’s to lose? It would be nice to think that every developer has an “exit strategy”, but often they won’t bring that into action if there’s a chance that they might pick the code up again. And in the event that a developer dies, we’ve seen time and time again that next of kin often have no idea what was on “the strange computer” or that it might be of interest or importance to others.
Finding bits of my software (in the days when it was covered by my “don’t distribute without my permission” licence) in ROOL’s early Raspberry Pi disc image via support posts on this forum springs to mind… On the other hand, sorting that mess out with ROOL was what finally made me start the (very long, and still ongoing) process of re-licensing my code under an Open licence. |
Steve Fryatt (216) 2105 posts |
String handling in C is a pain, agreed.
That’s a library issue…
Platform independence is a myth for most projects, unless you keep it very simple, build conditionally, or take the approach that NetSurf uses and decouple the core code from the platform-specific stuff.
Pointers in BASIC are OK, but pointers in C aren’t? At least in C, you get some sanity checking thrown in by the compiler.
vs
What’s the difference (except that the C version is clearer as to what’s at block + 8 and block + 12)?
Stuff written for the RISC OS desktop should really be using C99 facilities like snprintf nowadays, so you’ve got bounds checking. Any libraries that you use or write should also take buffer lengths in a similar way when applicable.
On RISC OS, you’ll generally call X versions of SWIs and handle the results yourself. In BASIC, you’ll generally call the X versions of SWIs and handle the results… oh. ETA: I’ll agree that having a top-level ON ERROR is useful in BASIC, but you can do very similar in C. |
Steve Fryatt (216) 2105 posts |
It’s an extremely useful facility, that’s pretty crucial to one of the major advantages that C has over BASIC. In a structured, event-driven C application, it’s quite common to see something like
and then somewhere else in the same source file, a line to register that handler with an event dispatcher:
The ability for C to hold pointers to handler functions along with window and icon handles makes it easy to dispense with the cumbersome nested CASE .. OF statements that plague big Wimp applications in BASIC: the dispatcher can simply look up the window handle in its list, check the event type, then call the associated handler function via the pointer that it’s been given. It also aids modularity, as nothing outside of the one source file above needs to know anything about how the iconbar menu is implemented. ETA: Oh, and did anyone mention that BBC BASIC for Windows has pointers to FNs and PROCs…? They’re useful for very much the same reasons. |
Malcolm Hussain-Gambles (1596) 811 posts |
@Rick, yeah when I was trying to compile Xeroid, the error on the GCOL was the furthest I got… the other errors were before that. In the case of my application NewsUK, to be honest it’s embarrassment. If someone asks for it, they can have it – the “design” is nice, but the code is frankly shocking as I didn’t know where I was going most of the time. |
Steve Fryatt (216) 2105 posts |
That was true of CashBook, and still is in a lot of areas. It was where I learned how to structure a Wimp application in C, having always used BASIC before, and it shows. It’s still more use if people can work on the code if they wish to, though. Open Sourcing SFLib was a major driver to fixing a lot of the nasty things that were in there. A lot of stuff like unchecked bounds have been fixed since the code was made public, simply because I’ve gone through it all critically with the benefit of 15 years’ more experience1 and thought “that’s nasty”. If I hadn’t open sourced it all and started documenting how to use it, I probably wouldn’t have found some of the really exciting bits. 1 Ouch. |
Chris Evans (457) 1614 posts |
Crunching is almost as bad as compiled code for editing without original sources. |
Chris Mahoney (1684) 2165 posts |
In my case I have Seasonal and DCSHelper. Both are currently closed source, although I do intend to release the source at some point. My biggest concern with Seasonal is that being my first “real” RISC OS app, the code is a bit of a mess, and it’s the sort of thing that I’d like to tidy up before releasing. As for DCSHelper, the code is a lot tidier but I’m worried that releasing the source too early would result in “private” bug fixes. If someone finds a bug, then I’d like to be able to fix it in my official release. On the other hand, I suspect that I’m the only person actually using it… perhaps I should actually announce the thing instead of just mentioning it in passing… |
Vince M Hudd (116) 534 posts |
It was only four months ago that I said this :) Joking, obviously. When I’m dead and buried, rotting an putrefying in the dark of my grave, being consumed by things that crawl or squirm, what does it matter? No point being prepared for the embarrassment that I’m not going to be around to actually feel. The real problem is those left behind actually knowing what to do with this stuff, as Steve said – even with instructions1, I think my family would still struggle to know what’s what and what to do with it. 1 Cue someone like Ron popping up to comment about me not writing instructions. ;) |
Steve Pampling (1551) 8170 posts |
Sometimes, instructions, clues1 or encouragement short of a hot poker up the nostril, will fail. 1 You know, like you write a GUI front-end for a FreeRADIUS install so people can enter new MAC entries for the non-dot1x capable stuff and have the text “MAC in the form 88-9F-FA-69-11-CF” right at the side of the input panel knowing that IPCONFIG gives the MAC in that form and cut and paste isn’t intellectually challenging. You know that can’t fail to be understood, right? Ah, but it can… 2 In some cases you can only conclude that pulling the trigger would fail to find a braincell to hit, but that’s another story. |
Rick Murray (539) 13840 posts |
When it is part of the standard C library, I call it a language issue.
I said that structures with named elements would be useful in BASIC. However you aren’t comparing like with like;
Some of my code sucks. I try to write clear logical code, having experienced the shock of returning to a forgotten project and learning that obscurity and coding like it was a Beeb really isn’t useful. So I favour legible over clever.
It is all to easy to judge other people’s code without understanding any of the historical aspects. A case in point is that Ovation can be….peculiar. Which seems a bit WTF? until you realise when it was written, 4MiB machines were the cutting edge, 1MiB machines were commonplace (and the program was expected to run on such a machine). The only library around was an early (quite broken) version of RISC_OSLib, and the development machine probably chugged along at a mere 8MHz. With all that in mind, things make much more sense. We’re seeing late ‘80s code in 2015, it simply can’t be judged by today’s standards. People would have laughed in your face if you said then that we’d be using gigahertz speed ARM processors with a gigabyte of RAM on board, in a circuit that could fit inside a cigarette pack. Domestic harddiscs weren’t even that large, and given how much a RAM upgrade cost, a gigabyte would have been unthinkable.
During an argument with my mother (reason long since forgotten), she referred to all of you as “my imaginary friends”. So, what was that you were saying about not understanding? |
Steve Fryatt (216) 2105 posts |
I’m not sure what you’re saying there? → is a pointer dereference, and so pretty much equivalent to ! or ? in BASIC. The . operator applies to actual structures, as opposed to pointers to them. If you’re after complete equivalents, then
is going to be somewhat akin to
assuming that we’ve previously defined block to be a pointer to something that occupies four bytes. However, I don’t think I’ve ever had to write anything like the C version there in a RISC OS desktop application1, and if you’re doing so then you’re almost certainly doing it wrong. The pointer examples from C which seem to give people the heebie jeebies tend to be the kind of thing that one never sees in modern code… 1 OK, I have. Once. It was one of the first bits of C that I wrote for RISC OS, while I was still in “BASIC Mode”, and you can find it in SFLib if you go hunting. And the conclusion that I drew in the referenced sentence applied to that implementation, to the extent that re-writing it with no functional improvements is high on my to-do list… |
Clive Semmens (2335) 3276 posts |
Good to read Rick’s #539. I haven’t done much programming since the mid 90s, and my code (mostly in BASIC with a bit of Assembler for critical bits) probably sucks big time. But it works, and I’m extremely glad that there’s a nice little machine on which it still works, and on which it’s nice and quick even when it’s handling files a hundred times bigger than I wrote it for. Coming back to some of it 20 years later it takes me a little while to understand what I was doing, but I find I still can without too much difficulty. I’m even writing new programs to do things my Mac can’t do – sometimes that it could do if I could afford the software, sometimes that I’d have to write a program on the Mac to do. But writing programs for the Pi is easy for me, and writing programs for the Mac is impossible for me. Some of my programs might even be useful for other people – but sorry, they’re in BASIC and Assembler, because those are the languages I’m familiar with. And they work. And no, I’m not remotely interested in compiling them. Yes, I did do an Oaktree C++ course, and got 100% in the final test. And have never used it in anger, and doubt if I ever will. So much for ARM’s expenditure on that course! (I could probably still code in Fortran or Cobol or Algol or Pascal or PDP8 assembler or IBM3790 Assembler if I had to but I’m very sure I never will!) |
Paul Sprangers (346) 524 posts |
Is that compiled BASIC? |
Rick Murray (539) 13840 posts |
That’s probably about what you can expect when you remove the overheads of interpreting and just have the raw ARM code doing the job. |
Steve Drain (222) 1620 posts |
Wow! You go away for a weekend, someone mentions “BASIC” and “compiler” in the same breath, and the merry-go-round rolls into action yet again. ;-) I enjoy these discussions, which go back decades. They do generate plenty of light and rarely any heat, but they never seem to get anywhere. Sticking strictly to the topic, for me, the question to ask is why anyone wants a BBC BASIC compiler? Here are some answers that have been mentioned: speed, compactness, obscurity. Are there others? For each of those there is probably a good enough solution that does not imply compiling. I get the impression that these days a BASIC compiler is an end in itself, regardless of benefits or limitations. The supplementary subject that inevitably arises is the suitability of BBC BASIC for programming in general. This really should be put to one side until the compiler question has been settled, or opened in a separate topic, where I would leap in with much joy. ;-) |
Clive Semmens (2335) 3276 posts |
I’m sure that’s it exactly. Which is why I’m perfectly happy with uncompiled BASIC doing all the stuff that only happens once or a few times, and switch to assembler as soon as I get to anything that’s going to happen a zillion times. |
Steffen Huber (91) 1953 posts |
My opinion is that it is not a good idea to try to emulate BBC BASIC as faithfully as possible, so in my world the lack of formal definition is not really a problem. To produce a compiler, you have to come up with a formalized syntax anyway (hopefully nobody would start writing a scanner/lexer/parser by hand!). Have a look at BBC BASIC, extract the good things, then look at BlitzMax, freeBASIC, PowerBASIC, VB, and possibly some other modern languages like Kotlin, Groovy, Scala, Python, Go and Swift for inspiration. What the ABC compiler demonstrates is (IMHO) two things. 1: producing a high quality compiler is hard and – if you try to do it completely on your own – very time consuming, and the necessary time to implement everything from front to back end is just not possible in a market as small as RISC OS. 2: if you aim to faithfully implement all of the BBC BASIC interpreter’s functionality, it will end in tears. |
Steffen Huber (91) 1953 posts |
Correctness. Extendability. Easy reuse of existing libraries written in other compiled languages. |
Rick Murray (539) 13840 posts |
Is there any BASIC compiler that interfaces with AOF?
That’s why we should push to update ABC – it mostly works, it is available, and as everybody says, it is madness to try rolling “yet another compiler” by hand. |
Steffen Huber (91) 1953 posts |
It is not available as source code, so we don’t really know if it is suitable for any of the things discussed in this thread. We know nothing about its level of maintainability, for example.
I have only said that it is madness to implement your own compiler from frontend to backend. On the other hand, it is well possible that creating a new frontend for GCC or LLVM “from scratch” is a much easier and future proof option compared to updating ABC. |
Clive Semmens (2335) 3276 posts |
Some of us have never been on this particular merry-go-round before! Let us have our fun! |
Steve Drain (222) 1620 posts |
I think the matter of speed, whether from a compiler or otherwise, is the crux of the matter, and I might comment on that seperately. However, compactness and obscurity are not exclusive to compilation and can be the result of crunching, so best to put those to one side.
I take that to mean syntax checking and consistency in use of variables etc, which are definitely benefits of compiling a program. That BBC BASIC does not check syntax is an omission; many dialects do, or have done. Writing a syntax checker might be a drag, but I reckon that programs such as StrongBS must have had most of the elements in place. Whether it holds back the development of BASIC programs I doubt very much and history suggests otherwise.
I am not sure what you intend by this. BBC BASIC is infinitely extendable through libraries and in some respects that has been a curse. Everone who wanted to has been able to reinvent the wheel – myself, too. In contrast, Richard Russell has kept a tight control over BB4W, and only approved libraries are used, in general.
That seems to be an advantage that compiled languages share, but how would it integrate with BASIC? If another language can be used to produce a stand-alone piece of code, that might be called by BASIC, or such code might be included in a module to be called with a SWI, which I think is the RISC OS way of doing things. You can use the routines from the SCL that way from BASIC, but I have failed to see the advantage.
The way ARM BBC BASIC was written was a product of its times. First, it derived from the BBC B version and second, it was in an era of comparatively limited memory and slow processors. The choices taken then would not be taken now and many of those allowed shortcuts make the language difficult to analyse. If I had any mind to write a compiler I would limit the possibilties to regular syntax, a subset of the whole possibilities of BASIC. Trying to cope with everything already written would be courting disaster. |