Is there a program to convert BASIC programs to machine language?
The easiest way to speed up BASIC programs is to use a sophisticated utility program called a compiler. Generally speaking, a compiler converts a program written in a high-level language like BASIC or Pascal into a form which is similar to regular machine language. There are two main types of compilers: native-code compilers and p-code (pseudo-code) compilers. The output of a native-code compiler closely resembles ML object code; a P-code compiler produces output which is not quite ML, but nevertheless much faster than the original source code.
However, using a compiler is rarely as simple as just loading up your BASIC program and running it through the compiler. Most compilers work only with a subset of BASIC (that is, certain BASIC commands cannot be compiled). There are other restrictions, too. Sometimes a compiler requires your BASIC source code to be structured in a certain way. For instance, any DATA statements may have to be grouped together at the end of the program.
Like other software, compiler programs vary in efficiency. Some compilers shrink your programs in addition to speeding them up, while others actually expand the amount of code. Still others let you choose whether you prefer compacted code or speedy execution. Compilers usually claim to speed up BASIC programs by a factor of 10 to 50 times. In practice, the lower figure is more common. Compilers can't make your BASIC programs run as fast as a program written in machine language in the first place, but they can yield significant gains.
Because the compiled object code is much more difficult to interpret and modify than BASIC (or regular ML), compiled code can give some measure of program protection.
Some compilers produce code that will run on any compatible computer, even if the other user doesn't own the compiler. But many compilers require a runtime package to run the compiled code. Sometimes the runtime package is appended to the compiled program automatically, while other times the only way a user can obtain the runtime package is to buy the compiler. You should be aware of these differences if you intend to give or sell your compiled programs to others. In addition, many companies which make compilers require you to obtain a license or include a notice if you sell compiled programs to other people.
Compilers usually require a fair amount of memory and at least one disk drive to operate. For that reason, there are no compilers for the Commodore VIC-20 that we are aware of. However, there are several fine compilers available for the Commodore PET, 64, Atari, Apple, and IBM computers. Check with your local dealers or the advertisements in computer magazines.
COMPUTE! is working on a Tiny BASIC Compiler that will work with a subset of BASIC on various computers. Watch for it in future issues.