|A stack based X Machine in C++ email@example.com (2002-12-19)|
|Re: A stack based X Machine in C++ firstname.lastname@example.org (Joachim Durchholz) (2002-12-30)|
|Re: A stack based X Machine in C++ email@example.com (2003-01-12)|
|From:||Joachim Durchholz <firstname.lastname@example.org>|
|Date:||30 Dec 2002 23:58:02 -0500|
|Posted-Date:||30 Dec 2002 23:58:01 EST|
> [...] I need recommendations on:
> 1. Books
> 2. Online articles
> on how to write the above program. Any other help will be welcome.
You already did the hardest part: determining the components of your VM.
The interpreter is just an endless loop like this:
instruction := program_store [pc]
pc := pc + 1
executor := routine_to_execute (instruction)
for i := 1 to number_of_direct_operands_for_instruction loop
operands [i] := program_store [pc]
pc := pc + 1
executor(operands) // indirect jump
routine_to_execute (instruction: INTEGER)
-- Implement this as an array that maps instruction code
-- to the appropriate routine, that's fastest.
-- Maybe you want to mask out a few bits.
Alternatively, you could use vmgen, which will generate the above main
loop for you and optimize it (the above pseudocode is not very
efficient). What you still have to do is to write the various
instruction executor functions.
Return to the
Search the comp.compilers archives again.