Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!SUN.COM!wmb From: wmb@SUN.COM (Mitch Bradley) Newsgroups: comp.lang.forth Subject: Re: Forth Compilation (again) ? Message-ID: <8908020600.AA10095@jade.berkeley.edu> Date: 2 Aug 89 02:18:25 GMT Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: Forth Interest Group International List Organization: The Internet Lines: 38 How people do inline code expansion: a) First of all, the basic mechanism is to compile a "jsr" or "bsr" or "call" (or whatever) instruction for each Forth word called by a definition. In and of itself, this is usually a lose, because on most machines it takes up more space than threaded code, plus it is likely to be slower because most machines push a return address on the memory stack for each "jsr" and pop it on the return. However, it opens the door to in-line compilation, which can be a big win: b) Some words are marked with an "in-line" bit. When the compiler encounters those words, instead of compiling the "jsr", it copies the machine code for that word into the new definition. Often these in-line code sequences are only a few bytes long, so the code expansion is minimal. Longer words are usually not worth expanding in-line anyway, since their call/return overhead is amortized over a greater amount of actual work. c) The compiler can do peephole optimization as it compiles the in-line code. For instance, if one word ends with, e.g. PUSH A0 and the next word begins with, e.g. POP A0, the compiler could just erase both instructions. More sophisticated optimizations are of course possible. d) The "in-line" words generally have surrogate versions which can be "ticked" and executed in the normal interactive way. In-line compilation is actually quite easy to implement. I did an in-line version of my system several years ago. The basic work took a couple of evenings. I didn't pursue the effort much further, because I was unwilling to trade off the ability to decompile for extra speed, which I could always get by writing a few code words. Mitch