EgonOlsen71 / basicv2

A Commodore (CBM) BASIC V2 interpreter/compiler written in Java
https://egonolsen71.github.io/basicv2/
The Unlicense
84 stars 15 forks source link

compiled code longer then source #39

Closed rzo42 closed 1 year ago

rzo42 commented 2 years ago

I have a file for the vic 20 that is 8k pre compiled and 21k post. The code works and I am happy as long as it functions. I just thought it was odd that the compiled code was over doubled in size. Here is the repository for the code. https://github.com/rzo42/Vic-20-Mini-Synth Thank you

EgonOlsen71 commented 2 years ago

Opps, I've somehow overlooked this one...to answer your question:

Yes, that's common. If you have to, you can work against it by using the /compactlevel directive when compiling. It will decrease the size at the expense of some performance (usually not much).

There are two main contributers to the size (apart from the fact that some things are simply more condensed in BASIC than they are in machine language): The runtime itself, which also includes a replacement for the floating point routines in ROM, which add some size (you can omit them by using the /xfloatopt directive, but the compiled code will be slower, of course). And the fact that Mospeed includes the space needed for variables and arrays in the binary as well. This isn't strictly needed in some cases but I left it in, because I need it to be there in some cases and instead of implementing some confusing logic that decides if it's needed or not, I simply include it anyway.