Re: A stack based X Machine in C++

Joachim Durchholz <joachim_d@gmx.de>
30 Dec 2002 23:58:02 -0500

          From comp.compilers

Related articles
A stack based X Machine in C++ tarun2701@msn.com (2002-12-19)
Re: A stack based X Machine in C++ joachim_d@gmx.de (Joachim Durchholz) (2002-12-30)
Re: A stack based X Machine in C++ anton@mips.complang.tuwien.ac.at (2003-01-12)
| List of all articles for this month |

From: Joachim Durchholz <joachim_d@gmx.de>
Newsgroups: comp.compilers
Date: 30 Dec 2002 23:58:02 -0500
Organization: Compilers Central
References: 02-12-086
Keywords: interpreter
Posted-Date: 30 Dec 2002 23:58:01 EST

TTA wrote:
  > [...] 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:
        loop forever
            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
            end
            executor(operands) // indirect jump
        end
        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.
        end


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.


HTH
Joachim


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.