Re: Absolute beginner - Need some pointers

anton@mips.complang.tuwien.ac.at (Anton Ertl)
Tue, 04 Mar 2008 15:32:44 GMT

          From comp.compilers

Related articles
Absolute beginner - Need some pointers nacarlson@gmail.com (NickCarlson) (2008-02-27)
Re: Absolute beginner - Need some pointers DrDiettrich1@aol.com (Hans-Peter Diettrich) (2008-02-28)
Re: Absolute beginner - Need some pointers bc@freeuk.com (Bartc) (2008-02-29)
Re: Absolute beginner - Need some pointers anton@mips.complang.tuwien.ac.at (2008-03-02)
Re: Absolute beginner - Need some pointers anton@mips.complang.tuwien.ac.at (2008-03-03)
Re: Absolute beginner - Need some pointers anton@mips.complang.tuwien.ac.at (2008-03-04)
Re: Absolute beginner - Need some pointers gah@ugcs.caltech.edu (glen herrmannsfeldt) (2008-03-05)
Re: Absolute beginner - Need some pointers sandmann@daimi.au.dk (Soeren Sandmann) (2008-03-07)
| List of all articles for this month |

From: anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.compilers
Date: Tue, 04 Mar 2008 15:32:44 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
References: 08-02-091 08-03-008 08-03-013
Keywords: interpreter
Posted-Date: 04 Mar 2008 10:58:39 EST

The moderator natters
>[Not the block structure of the source language, the loops in the
>object code. When you get to the bottom of the loop, you need
>something that tells the interpreter to go back to the top of the
>loop. I've done it with assembler style gotos that require some sort
>of symbol table and backpatching, which is doable but unpleasant.


Yes, most VMs implement control flow using assembler-style VM branch
instructions. You don't need backpatching for backward branches
(e.g., the loop-back branch you mentioned), because in that case you
know where you want to branch to when you generate the branch.


However, when you generate a forward branch (e.g., in an
IF-statement), you usually don't know the target of the branch at that
time, and the simplest approach to deal with this is usually
backpatching. Normally, the backpatching itself takes one line of
code and is not at all unpleasant. If your VM design has some
additional complications (e.g., moving the code around after code
generation while avoiding relative VM branch instructions), this can
become more complex and less pleasant, but one usually can avoid such
complications.


Concerning structured VM instructions, one can use them for backward
branches (keeping the target address on a stack or in a register at
run-time), but using them for forward branches at run-time is going to
be inefficient. However, you could use the additional information
such instructions provide in a separate pass that runs after all
relocation (or whatever complication the VM has) and generates and
patches the target addresses at that time.


- anton
--
M. Anton Ertl
anton@mips.complang.tuwien.ac.at
http://www.complang.tuwien.ac.at/anton/


Post a followup to this message

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