[virtmach] first VM.

Thaddaeus Frogley thaddaeus.frogley@creaturelabs.com
Fri, 10 Nov 2000 09:52:05 -0000


Tom, everybody,

Congratulations Tom!  Isn't satisfying when a you new VM runs its first
program.  The next big step is a compiler... :)

> The main exicution routine is one big switch statement :)
> Is that an acceptable way to do it?

It depends on what your goals are.  If you intend to use the VM across
multiple projects, and may perhaps customise it then a less monolithic
approach might be advisable.  Consider function pointers.  This may work out
slightly more expensive per opcode, but the additional flexibility can make
it worth the sacrifice.

I got the impression from your message that high execution speed was a goal.
If this is a case consider the following:

Assuming your compiler is optimal, or near optimal, then switching on an
unsigned 8 bit value will compile down to a jump table.  If you are
switching on anything bigger it will probably compile down to something less
optimal.  

Now, if you intend to expand your VM past 255 instructions (sounds far
fetched now, but what about 6 months down the line) then creating your own
jump table, or using a table of functions pointers may be more efficient.

But, as I said, it depends on what your trying to achieve.

Thaddaeus Frogley
[ http://www.photo.net/users/Thad/ ]
Certified C/C++ Programmer
[ http://www.brainbench.com/transcript.jsp?pid=334344 ]
Beasts Team, 
Creature Labs Ltd
thaddaeus.frogley@creaturelabs.com