[virtmach] first VM.

Tom Fjellstrom tfjellstrom@home.com
Fri, 10 Nov 2000 13:15:27 -0700


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

Thats funny.. Because It already comes with one. :)

> > 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:

It would be nice... but right now It takes an hour to do something that
would
take something done in C a couple minutes... :(

> 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.

Right now the compiler is just a translater. It takes the inputed code
translates it to CHIP's machine code and hands it off to CHIP.
So its more of a script language right now but It wasn't intended to be.

> 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.

Really? So a big switch/case is slower than a huge amount of function
calls?
by the way, what is a jump table? Or better yet, how is one implemented?
(I learn better by example, theory usually just seeps back out of my
head.)

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

Originally I was writing CHIP to see if i could. but when I realized
I could I decided to see if my other project a c++/java/perl hybred
compiler/scriptengine could efficiently compile to CHIP.

> 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

Thank you for your insight.

-- 
Tom Fjellstrom
tfjellstrom@home.com
http://strangesoft.net/