Mario Latendresse. Automatic Generation of Compact Programs and Virtual Machines for Scheme, in Scheme Workshop, Principles, Logics and Implementations of high-level programming Languages (PLI), Montréal, Canada , September 2000.
Compact programs are not particularly needed on large workstations, but they become a necessity on small embedded systems. For example, smart cards have on the order of 1K of RAM, 16K of non-volatile memory, and 24K of ROM. This is an extreme situation, but many embedded systems also have memory constraints requiring compact code. Virtual machine can be an effective approach to obtain com- pact programs and byte code is a common technique for encoding virtual instructions. If the instructions are tailored for a particular language, the resulting virtual programs are compact. We use a combination of techniques to automatically generate new instructions and new compact encodings for virtual instructions. The common byte code encodings align instructions on byte boundaries. Our encoding does not align instructions, operational codes for instructions are Huffman encoded, and argument lengths are not necessarily a multiple of eight bits. New instructions are generated to replace repetitive sequences of instructions in programs. This process is done using axed basic set of instructions and a sample of programs. The virtual machines are automatically generated in C. The resulting compressed programs are interpreted without decompression. This approach is general enough to be applied to C, Java and many other languages. We demonstrate it on the Scheme language using several benchmarks. The resulting Scheme virtual machines and programs run efficiently and are compact enough to be ported on small embedded systems.