Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 14:36 08 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Crunch to reduce program size

Author Message
shoebuckle
Senior Member

Joined: 21/01/2012
Location: Australia
Posts: 189
Posted: 07:37pm 11 May 2013
Copy link to clipboard 
Print this post

It has been a while and quite a challenge, but version 1.0 of Crunch, a program to reduce the size of a source MMBasic program and speed up its execution, is available at last here. I have tested it under DOS MMBasic v4.3A and on a mono MM using MMBasic v4.3A, but not on a Colour MM because I don't have one.

Briefly, Crunch removes all comments and blank lines from a program and replaces all variable names, labels, user defined Function names and Subroutine names with 1 and 2 character names. Optionally, the replacement of label names and Function/Sub names can be suppressed. There are 3 programs in the suite:

- RWSRTMRG.BAS (Reserved word sort/merge) which creates a list of reserved words.
- CRUNCH.BAS which identifies all variables, labels, Functions and Subroutines.
- CRUNCHa.BAS which replaces them with 1 & 2 character short names.

You only need to run RWSRTMRG when MMBasic is updated with new commands.

CRUNCH and CRUNCHa are designed to work together. CRUNCHa is automatically run by CRUNCH and became necessary when CRUNCH ran out of memory.

CRUNCH can get its parameters either from the implied RUN command or from CRUNCH.DAT. The implied RUN command is:

CRUNCH InputFileName<.BAS> OutputFileName<.BAS> </L> </F> </P>


CRUNCH.DAT format is similar:

InputFileName<.BAS> OutputFileName<.BAS> </L> </F> </P>


- .BAS is assumed if an extension isn't provided.
- InputFileName and OutputFileName must be different so you cannot accidentally overwrite the source.
- By default, CRUNCH replaces all variables, labels, function names and subroutine names with 1 or 2 character names. You can prevent labels from being replaced by adding the /L switch. /F switch prevents both function names and subroutine names from being replaced and the /P switch adds some debugging messages as the job progresses. Switches can be supplied in any order.
- Parameters can be separated either with spaces or a comma.

More details can be found in the ReadMe file in the package.

I would appreciate any comments and bug reports. Although I have tested it extensively, I am sure it isn't perfect, oh and PLEASE TEST the crunched version of your program very carefully before committing to it. There is no guarantee that it will work, even though I am confident that it will.

Cheers,
Hugh
p.s. Woops! Just found a problem with the second Crunch program, CrunchA. It runs out of memory when the program being crunched has a lot of variables, labels, function names and subroutine names. My Hearts and Bones game is one such with just over 100. I will need to use a less memory hungry way of sorting the list. H

BTW, Crunch doesn't support programs with line numbers. You need to run NONUMBER, which is in MMLib, first.




Edited by shoebuckle 2013-05-15
 
shoebuckle
Senior Member

Joined: 21/01/2012
Location: Australia
Posts: 189
Posted: 01:46pm 15 May 2013
Copy link to clipboard 
Print this post

Hi,
I have just loaded Crunch v1.01 onto my web site and it can be downloaded here.

The out of memory problem in CRUNCHA is now fixed by using a different method to copy the list of sorted variables. It will allow for programs with many more variables.

The reduction in size of the source program and its increase in speed depends very much on the nature of the program. Size will be reduced considerably if the source has lots of comments and uses long names for variables, labels, functions and subroutines. Getting rid of long names and lots of comments will also increase speed. Processor-bound programs will tend to gain more speed than I/O bound programs.
A couple of examples:
Program Size Speed (secs) on Mono MM
Original Crunched Reduction Original Crunched Reduction
Alphanum 14KB 5KB 65% 76 56 26%
Hearts 19KB 11KB 42% n/a as Hearts is a game


Comments, suggestions and bug reports are always welcome.
Cheers,
Hugh
 
shoebuckle
Senior Member

Joined: 21/01/2012
Location: Australia
Posts: 189
Posted: 05:10pm 17 May 2013
Copy link to clipboard 
Print this post

I have just uploaded Crunch v2.0. This now removes all unnecessary blanks and tabs from the source. It is available here.

My thanks to Geoff G for advice on what can and cannot be removed.

The next task is to get it to combine lines of code into multi-statement lines where possible.

Comments, suggestions and bug reports are always welcome.
Cheers,
Hugh
 
shoebuckle
Senior Member

Joined: 21/01/2012
Location: Australia
Posts: 189
Posted: 09:44pm 06 Jun 2013
Copy link to clipboard 
Print this post

Crunch v2.2 will be in the 7-June-2013 version MMLib which should be available soon from Geoff's web site.

Crunch removes comments and unnecessary characters from MMBasic source code, replaces variable, label, function and subroutine names with 1 or 2 character names and compresses the code into records with a maximum line length of 255 characters.

Its uses include:
- speeding up program execution
- reducing source size for imbedded applications
- disguising program logic.

I have tested it under DOS MMBasic v4.3A and on a Mono Maximite under v4.3A but not in any other environment as I don't have any other.

Full details are contained in the ReadMe pdf in the Crunch folder.

Comments, suggestions and bug reports are very welcome.
Cheers,
Hugh

p.s. The RANDOM command isn't in the list of commands it recognises. Just add it to either RWORD1.txt or RWORD2.txt and run RWSRTMRG.BAS before running CRUNCH if your program has a RANDOM command in it.
p.p.s. MODULE isn't there either. Add it too if you are using it.Edited by shoebuckle 2013-06-08
 
shoebuckle
Senior Member

Joined: 21/01/2012
Location: Australia
Posts: 189
Posted: 01:11am 11 Jun 2013
Copy link to clipboard 
Print this post

I have added:
- an option to set the output file length up to 255 characters (default 255). Just add the switch /nnn (where nnn is the record length) to the command line or to Crunch.dat.
- progress dots to show that the program is working.
- some compression statistics.

I have also fixed a couple of problems.

Version 2.3 is available here or in the next update to MMLib.

Cheers,
HughEdited by shoebuckle 2013-06-12
 
James_From_Canb

Senior Member

Joined: 19/06/2011
Location: Australia
Posts: 265
Posted: 02:54pm 11 Jun 2013
Copy link to clipboard 
Print this post

Hi Hugh.

Would you please expand on what you mean by setting the output file length up to 255 characters (default 255)?

James
My mind is aglow with whirling, transient nodes of thought careening through a cosmic vapor of invention.

Hedley Lamarr, Blazing Saddles (1974)
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1328
Posted: 10:03pm 11 Jun 2013
Copy link to clipboard 
Print this post

I was wondering the same thing - it'd be a pretty short file
Greg
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 10:46pm 11 Jun 2013
Copy link to clipboard 
Print this post

That should be LINE LENGTH. :)
255 is the default, but if you ever need to print it out or read it on a monitor you can lower it to make it easier to read.

Microblocks. Build with logic.
 
shoebuckle
Senior Member

Joined: 21/01/2012
Location: Australia
Posts: 189
Posted: 12:26pm 12 Jun 2013
Copy link to clipboard 
Print this post

  James_From_Canb said   Hi Hugh.

Would you please expand on what you mean by setting the output file length up to 255 characters (default 255)?

James


Yes, sorry, I did mean line length and, as TZ says, it is mainly so that you can limit the output lines to the width of the screen but you can make it any size you like, up to 255 characters. Without the /nnn switch, lines are filled as near to 255 characters as possible. The /nnn spec is ignored if a statement is longer so, for instance, a single-line IF statement won't be split if it is longer than the specified line length because that would alter the logic. Another example which is likely to exceed the specified length is a print statement with 80 characters of quoted text.

Should you wish to check the output against the original source code, there is an undocumented switch, /T for testing, which you can add to the command or CRUNCH.DAT file that will leave all of the intermediate files in tact. One of these files, CRUNCHSV1.tmp, contains a sorted list of new vs. old variable, label, subroutine and function names. Its only purpose is for debugging.

Cheers,
Hugh
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024