Crunchie for crunching BASIC
Steve Drain (222) 1620 posts |
Crunchie is a crunching utility for BASIC files written in BASIC. It can be downloaded from: http://kappa.me.uk/Miscellaneous/swCrunchie071.zipAs far as I know, there is currently no reliable BASIC cruncher that runs on RISC OS 5. About a year ago I started to play around with ideas for crunching, prompted by the possibility of including this in Basalt. As time went by, this just grew from an amusement into to a practical program. Recently it has been put through its paces by Martin Avison to crunch the Organizer application, which is large and complex, with many libraries. With several bugs and corner cases ironed out I think the New Year is a time to release a beta version for further testing. Crunchie is an on-going project, so comments are welcome, as well as bug reports. There are several features waiting to be included. Crunchie is a single-pass program and does:
Crunchie is intended to crunch a program that runs and has been tested, although there are a number of controls to cater for particular requirements, such as included assembler. If selected, Crunchie reports progress in a Reporter window, from which a file can be saved and then analysed. This will be improved. In addition to straight crunching, Crunchie can be set to translate a program that includes features that would prevent it running directly, into a running program. If selected, translation does:
Some of these are experimental. |
Clive Semmens (2335) 3276 posts |
Excellent, Steve! Will download and see how it goes. My BASIC programs probably won’t stress it much though – they’re all stand-alone, with no libraries, and none of my recent (still in use) programs include any assembler even. All being well I’ll crunch !Run in all my publicly offered apps – but leave the uncrunched version alongside for people to inspect or edit to their heart’s content. |
Steve Pampling (1551) 8170 posts |
Excellent spirit, making code properly visible with comments for the eddificashun of lesser mortals. With current processor speeds I do wonder how much benefit such crunching produces though. |
Clive Semmens (2335) 3276 posts |
Indeed. That’s why I don’t write assembler any more, too. But I’m very willing to give Steve’s Crunchie a whirl, as much for interest as anything else. Processor speeds and memory sizes both. |
Colin Ferris (399) 1814 posts |
I wonder if the name of the PROC’s – FN’s could be left in – ie the line before the PROC/FN Just in case the full source is lost!! REM PROC_Org_name |
Clive Semmens (2335) 3276 posts |
Personally, I’d rather not. If the full source is lost, you’re on a hiding to nothing trying to make sense of a program of any significance with just the PROC and FN names. Just make sure you don’t lose the source! |
Steve Drain (222) 1620 posts |
Some speed, but not a huge amount. The memory savings are probably not worth anything. It is the principle of making small gains more than anything.
That is something that makes many crunched 90s programs a lost cause, but we would not leave out the source for public programs now, would we? ;-) Private programs benefit from the obsurity, even if it just prevents customers fiddling with the code and creating problems for the maintainer to fix. |
Clive Semmens (2335) 3276 posts |
Sad to say, I’m not the best commenter ever 😞 nor am I the prettiest coder ever. Eddification is liable to be as much about how crap you can be and get away with it as anything else. |
John Sandgrounder (1650) 574 posts |
Quote from the manual:-
It may be better to set the defaults the same as BASIC’s CRUNCH. This would give a higher confidence that programs which run with BASIC’s CRUNCH would run after being crunchied. All of my programs with GOTOs fail after being cruchied. The targets for the GOTOs are not empty lines, although some have REM COMEFROM comments and some are ENDPROCs Using -emptyoff, still produces incorrect output for some GOTOs with output like GOTO484372.INPUTS with the following line joined even with -joinoff |
Raik (463) 2061 posts |
Thanks a lot. The tool is what I’m searching for, but I’m to stupid to get a usable result. The produced code will not work. A lot of errors (e.g. missing "" or “no such mnemonic” and other). Have play around with any of the arguments, but no success. I not use GOTO, GOSUB etc. in my code. *RAM (Basicfile is placed in RAMDisc) … the crunchfile is working like the basicfile. What are comparable settigs in Crunchie? What should I try? |
GavinWraith (26) 1563 posts |
Joe Taylor wanted to incorporate a BASIC compacter within AppBasic, especially one that loads in libraries and cuts out orphan FN/PROCs that are not in the dependency graph. He had some problems over this as the author of StrongBS, his first choice, had left the RISC OS scene and could not at that time be contacted (I believe he returned later). There were also Shrink and BASCompress. But StrongBS and BASCompress did not work on the Iyonix. Some of the issues over updating were because the compression programs written in BASIC had themselves been compressed, which also caused problems in RISC OS 5. Joe thought he could achieve his purpose with the ABC compiler, but that did not work with the A9. The moral, as I see it, is do not try to hide your source code. It is a sure path to obsolescence. It is ironic that one of Joe’s ambitions with AppBasic was to have it all in BASIC so that it would work without change on future versions of RISC OS. |
John Sandgrounder (1650) 574 posts |
Should the crunchied program be: |
Martin Avison (27) 1494 posts |
Certainly none of the thousands of lines of code I helped Steve to test with included any GOTOs, so that may have been overlooked.
I never saw
Unfortunately, there are some vital core parts that are in compiled Basic, and the source is not available. So if/when something affects those programs they cannot be recompiled.
As the Manual says, “Crunched programs may be impossible to edit” |
Steve Drain (222) 1620 posts |
GOTOs? ;-)
Without the source I cannot comment, but do all your IF statements have a THEN before the GOTO? Crunchie needs THEN to follow the syntax – it is not really very clever, but it will remove the THEN for you. |
Steve Drain (222) 1620 posts |
The assembler is a minefield for Crunchie. It was never included at the beginning. As it stands it requires opcodes in uppercase, because that is how I do it. However, I have now allowed lowercase, but not mixed case. It does not do any syntax checking. I have just fixed a bug with CHR$ that could result in Missing ". It allowed CHR$&0D, a CR, to be inserted as a literal string, but BASIC always interprets a CR as the end of a line, even when in a string. This leaves a hanging endless literal string. More problems with the source, at least the line of code, are welcome. |
Steve Drain (222) 1620 posts |
Possibly. It could help to identify problems, but it is largely unreadable.
No. There is no point. Edit the source. |
Steve Drain (222) 1620 posts |
I echo the other comments you made about unusable crunchers from the past, but that point strikes a particular chord. I am caught in a quandry. Basalt does not work reliably on the latest versions of RO5, although it does on my mini.m. All my source uses the ExtededBASICAssembler module, which only runs on 26-bit systems and requires the BASIC 1.20 module to be loaded. I have recently swapped everything else onto the mini.m and I am left with the orphan code on VRPC. It is possible to use Aemulor, but it limits some things I like and it is still not very convenient. I have started on converting the source, but it is huge. There is lesson here about assembler versus high-level languages. ;-( |
GavinWraith (26) 1563 posts |
One can do quite a bit with StrongED’s Search and Replace. When the contexts play an important role I like to try a scripted solution to large scale conversions. It usually takes me multiple attempts before I get it right, but even so, for large sources it is quicker and less error prone than wading through and correcting by hand. |
John Sandgrounder (1650) 574 posts |
Yeah, Yeah! I am working on it.
Yes, but the ones that fail have lots of other code in between the THEN and the GOTO EDIT: some hours later Changing the code to IF condition THEN does not help Neither does IF Condition THEN bla: bla: bla: |
Steve Drain (222) 1620 posts |
I will have another look at that. It was not one of my priorities. Maybe it is something to do with the line number coding. |
Steve Drain (222) 1620 posts |
A lot of that, but over multiple files (hundreds) it is difficult to undo and the question is how often to backup. I have it assembled, but there are inevitable new bugs. |
Steve Fryatt (216) 2105 posts |
Revision (version) control? That gives you as many backups as you want, without any of the hassle of taking copies yourself. |
Raik (463) 2061 posts |
I not use assembler. I am happy if I get something to work in basic. ;-)
Is the download changed? Looks like the same I have.
Have search the line with the “mnemonic error”. The “problematic line” is the third in the crunched part, beginning with ELSE… WHEN “file_” WHEN"file_":SYS&400E9,&28,,P2$CHR$(0)TO,,,w%,h%,,W2%:SYS&35,W2%,4TO,,X2%:SYS&35,W2%,5TO,,Y2%:h%=h%<<Y2%:w%=w%<<X2%:IFo1$=""THEN |
Rick Murray (539) 13840 posts |
To have an option to use Throwback like the rest of the DDE tools? You may have issues with using Edit to deal with crunched code. Maybe StrongEd as well. This is because these editors convert the BASIC to text for editing, and from text back to BASIC when saving. Some crunched sequences may trick the conversion into using the wrong tokens and…broken program. Some crunched tokenised sequences may also expand to be longer than the line limit when expressed as text and…broken program.
That’s why I won’t be using Crunchie. I am very happy to see it available for RISC OS 5, because I used to use StrongBS back in the day, but these days I don’t bother squishing stuff written in BASIC. It’s just too much of a PITA later on. Especially if the squished version is the one you have and the source is MIA.
Maybe what we need is something that added the extra assembler stuff to RISC OS 5’s BASIC? ;-) I know what you mean though – ExtBasAsm was lovely. When it came time to ditch it, I went one of two ways – I either rewrote the code in C, or I ported the code to ObjAsm. It’s been so long since I’ve used BASIC’s assembler that I don’t remember the default OPT settings. 0 TO 3 STEP 3? Or was it 0-2?
Remember this? Very clever. Very insane. Pain in the backside to deal with. |
John Sandgrounder (1650) 574 posts |
It is only 5 figure line numbers which are failing for me. (but not all of those) |