Node:Example overview, Next:, Previous:Example, Up:Example



Example overview

There are two versions of the same example for using Vmgen: vmgen-ex and vmgen-ex2 (you can also see Gforth as example, but it uses additional (undocumented) features, and also differs in some other respects). The example implements mini, a tiny Modula-2-like language with a small JavaVM-like virtual machine.

The difference between the examples is that vmgen-ex uses many casts, and vmgen-ex2 tries to avoids most casts and uses unions instead. In the rest of this manual we usually mention just files in vmgen-ex; if you want to use unions, use the equivalent file in vmgen-ex2.

The files provided with each example are:

Makefile
README
disasm.c           wrapper file
engine.c           wrapper file
peephole.c         wrapper file
profile.c          wrapper file
mini-inst.vmg      simple VM instructions
mini-super.vmg     superinstructions (empty at first)
mini.h             common declarations
mini.l             scanner
mini.y             front end (parser, VM code generator)
support.c          main() and other support functions
fib.mini           example mini program
simple.mini        example mini program
test.mini          example mini program (tests everything)
test.out           test.mini output
stat.awk           script for aggregating profile information
peephole-blacklist list of instructions not allowed in superinstructions
seq2rule.awk       script for creating superinstructions

For your own interpreter, you would typically copy the following files and change little, if anything:

disasm.c           wrapper file
engine.c           wrapper file
peephole.c         wrapper file
profile.c          wrapper file
stat.awk           script for aggregating profile information
seq2rule.awk       script for creating superinstructions

You would typically change much in or replace the following files:

Makefile
mini-inst.vmg      simple VM instructions
mini.h             common declarations
mini.l             scanner
mini.y             front end (parser, VM code generator)
support.c          main() and other support functions
peephole-blacklist list of instructions not allowed in superinstructions

You can build the example by cding into the example's directory, and then typing make; you can check that it works with make check. You can run run mini programs like this:

./mini fib.mini

To learn about the options, type ./mini -h.