Crunchie for crunching BASIC
Steve Drain (222) 1620 posts |
Hang on. All in good time. Tomorrow probably. ;-)
Sorry, but Textile and pling do not mix. Could you make that a code block. |
Steve Pampling (1551) 8155 posts |
+1
Wasn’t there something, possibly ancient history1, that required higher numbers than single digits to kick in support for newer instructions like MSR and MRS. 1 Yup, history. MRS etc are fine in the raw BASIC assembler. There will be some antique change in CVS… |
Steve Drain (222) 1620 posts |
I am flattered that you should think of it in those terms, but yes, an element of throwback could be useful. My preference is to do it through *ReportError T.
That was a good summary of the problems of attempting to edit crunched code.
Of course. I have developed a fairly comprehensive set of macros, building on some I found on your site a good while ago. ;-)
Of course. Although it is a bit garbled by Textile, the crunched version does obey the rules, I think. |
John Sandgrounder (1650) 574 posts |
I have fixed all of my offending GOTOs and a 154K BASIC program now seems to work … or, is there a work around? |
Steve Drain (222) 1620 posts |
Standby for an update. This is a bug I have fixed. See my earlier post. If you urgently need a work around I think CHR$(+13) would defeat the current crunch logic. |
John Sandgrounder (1650) 574 posts |
That causes an error at cruch time, but cr%=13: CHR$(cr%) is OK. I now have a 154K BASIC program running. The full test will start at 7am tomorrow morning, but it looks good so far. Many thanks. |
Andrew Rawnsley (492) 1443 posts |
In terms of benefits that this could bring, replacing SWI names with numbers can yield some pretty significant benefits. I recall on an A3000 (OK, several orders of magnitude slower) I was using a few SYS calls by name to plot a (20×20 tile?) map on the screen. You could see it drawing the tiles – it was unusable. Changing to numbers (thus removing all the look-ups) made the map plotting seemingly instant. Of course, a programmer will naturally optimise such loops as best the can without the tool, but being able to use longer variable names, and full-name SYS calls makes the code far more readable. A cruncher can then optimise for speed before release. I recall Andrew Pullan had a custom tool for Webster, which (if memory serves) pulled together various smaller libraries (which were more extensively annotated for ease of development) then crunch and merge for speed. This made development far more practical. |
Steve Fryatt (216) 2103 posts |
There’s also Tokenize which in-lines libraries, converts SWI names to numbers, and applies a CRUNCH to the code (plus checking stuff like variable and FN/PROC names, if you wish).
Tokenize’s main purpose was to allow BASIC programs to be held in a text-based revision control system (eg. SVN or Git) with the benefits of diff and merge, which falls very firmly into the same category. It doesn’t have to be used for that, however. There is a native RISC OS version on the site above, alongside the Linux one. |
Steve Drain (222) 1620 posts |
Good. Could you say how you fixed the GOTOs? |
Steve Drain (222) 1620 posts |
I have uploaded version 0.72, which has a fix for the CHR13 bug and also allows lowercase assembly opcodes. This can be downloaded from the bottom of my Downloads page , where any other updates will appear from time to time without further announcement, unless there is a major change. |
Steve Drain (222) 1620 posts |
It has been encouraging to see the hunger with which Crunchie has been greeted, both here and privately. It clearly fits a need, despite some who see crunching as the work of the Devil. ;-) Clearly there is quite a lot to do still and most of the problems seem to be with assembler. I was not going to include this at first, but when I did I may have been over-ambitious. A simpler approach that does not attempt to crunch data directives and register names might be better and I will revisit this. Remember, please, that Crunchie is not a replacement for StrongBS. ;-) |
Steve Drain (222) 1620 posts |
Indeed it can. Although this is done by Crunchie, there are still some old applications written in BASIc that can do only this.
For me, that is the primary reason for crunching.
At the moment Crunchie can crunch a list of libraries to the same names as the main program, but it still expects those libraries to be loaded with LIBRARY 1. That is the way I work, but in discussion with Martin and others it is clear that there is a desire for merging and I will eventually implement that. 1 Judicious use of a path vath variable can ensure that a program can use crunched libaries if available, or fall back to the source. |
John Sandgrounder (1650) 574 posts |
Using a mixture of:- Unfortunately some of the logic does not work now. :( |
John Sandgrounder (1650) 574 posts |
Having thought about the meaning of your question, I have now fixed the GOTOS rather than by trying to re-code to remove them. Each GOTO linenumber has been replaced with line_number%=linenumber: GOTO line_number%
All except one, that is, to stop !Edit discarding all of my line numbers. The code uses blocks of line numbers for each PROC and FN. My 154K BASIC GPS Tracking server is now running with 24 live GPS trackers talking to it (with TCP/IP HTTP) every 30 seconds. And the server is sending 30 second live updates to !RiscOSM for my car. The location of the rest of the trackers can be seen on a Google map. The Google map web page being produced by the same crunchied server. !Crunchie is magic :) |
Steve Drain (222) 1620 posts |
This bug is a result of not accounting for the way BASIC codes line numbers in these cases, using the token &8D and 3 bytes. These bytes are always non-top-bit-set and Crunchie was seeing them as variables and crunching them, hence the weird decoded line numbers. A fixed version is now available. I hope it works. ;-) |
John Sandgrounder (1650) 574 posts |
GOTO linenumber and CHR$(13) now both Crunch OK for me with version 0.73 (03 Jan 2019) Thank you. |
Raik (463) 2059 posts |
I agree. I not know why, but my “problem childs” are working. Thanks a lot. |
Rick Murray (539) 13806 posts |
I think some moderate crunching might be a trade-off between programmer friendliness (can use SWI names) and efficiency (can use SWI numbers), however I think enough time has passed that most of us who are left are aware of the…issues…involved in dealing with heavily crunched code. Plus, as any one of the AmCog games amply demonstrates, it isn’t exactly as if crunching BASIC is an absolute necessity for speed.
Yet. :-) |
Andrew Rawnsley (492) 1443 posts |
I haven’t had a chance to look at Crunchie “live” yet (due to being ill since Christmas eve), so this may already be present… It sounds like a version with a nice options window to choose what degree of crunching is required would be nice. For example, whatever SWI numbers rather than names doesn’t make the code too hard to edit later, but yields performance and minor space savings. Other compression options that allow the code to be re-edited later (ie. doesn’t break Edit/StrongEd basic<→text system) would be useful, so that it is possible to crunch code without making it effectively “broken” for re-editing. It seems like Crunchie may already offer all this, but if it doesn’t, this kind of control (so that you can choose between gentle, medium or heavy crunching) would seem the obvious way to go. |
Dominic Plunkett (2556) 34 posts |
As SWI names appear popular. What about “de-crunchie” which turns SWI numbers to text. It could even be a load option for something like StrongED. You could also think about about splitting multi statement lines. Renaming variables/procedures where sensible to say “global_a_isused5times” so when looking at the source you have a clue about the importance. The strongBS release notes gives a good list of things that are possible to compress in BBC basic. |
Steve Drain (222) 1620 posts |
Of course, but I have reports that even this flawed version of Crunchie has increased the speed of some programs to a useful extent. The gains are marginal and crunching should not be a compensation for poorly constructed algorithms. If you want faster BASIC then for many operations the specialist keywords of Basalt provide it – in spades. If only Basalt itself was not a problem at the moment. ;-(
Never. The methods employed a quite different. |
Steve Drain (222) 1620 posts |
I have a ‘nice’ desktop front-end for Crunchie, but it relies on Basalt, so I will not release it for a while.
The first thing Crunchie does is to use BASIC’s CRUNCH %1111. To quote the manual: “CRUNCH %10 may make a program uneditable”. So no joy there.
If you want SWI name replacement there are applications from way back that probably still do that. On the other hand I question the notion of partly crunching a program and then editing it. Why would you do that? |
Steve Pampling (1551) 8155 posts |
Which is indeed so – !SpeedySWI APDL b172 does run under RO5 in RPCEmu, not tested on ARMv7+
To quote Andrew Rawnsley earlier:
i.e. Speed benefits (Faster machine than in the days of the author, so I added three zeros to the number of iterations) 26.62 seconds vs. 12.24 seconds, small memory benefits without leaving the program cryptic and uneditable. |
John Sandgrounder (1650) 574 posts |
Add another report to the list. A very useful speed increase. |
Steve Drain (222) 1620 posts |
If there are plenty of SWIs, then SWI conversion plus the setting of Basic$Crunch to ensure CRUNCH %1111, will give much of the benefits, but have you tried editing a program with only numebers after SYS? ;-) Once upon a time I experimented with including a routine in a program that did the SWI conversion at runtime, but that was before Basalt, which does it anyway. |