Hong Zhang writes:
|> I've looked, a little, (and months ago at that) at the LibREP (ala
|> "sawfish") virtual machine. It's a pretty good indirect threaded VM
|> that uses techniques pioneered by Forth engines. It utilizes the GCC
|> ability to take the address of a label to build a jump table indexed
|> by opcode. Very efficient.
|
|It is not very portable. I don't believe it will be any faster than
|switch case.
IIRC it was at least 10% faster; portability is maintained by falling
back to switch on non-gcc systems
One of the problems with switch is that it checks that the switched
value is within the range of the jump table (even if you switch on an
eight bit value, and have exactly 256 cases)
See this paper for more details:
@InProceedings{ertl93,
author = "M. Anton Ertl",
title = "A Portable {Forth} Engine",
booktitle = "EuroFORTH '93 conference proceedings",
year = "1993",
address = "Mari\'ansk\'e L\'azn\`e (Marienbad)",
url = "http://www.complang.tuwien.ac.at/papers/ertl93.ps.Z",
}
John