From: Jeffrey Schwab Date: 2005-12-17T13:03:46+09:00 Subject: Re: Assigning a block to a variable in Ruby ajmayo@my-deja.com wrote: > Technically, Ruby is really an 'incremental compiler'. That there is no > final code generation step actually doesn't change this. > > Normally we make the following distinctions > > An INTERPRETER reads source code and processes each symbol in the code > each time it encounters the symbol. This is very inefficient, of > course. Thus a loop with an inner expression will require that the > inner expression be parsed and transformed into an evaluation stack > each time it is encountered. Early versions of BASIC were pure > interpreters, and performance was consequently far removed from native > code. > > An INCREMENTAL COMPILER (most scripting languages fall into this > category) transforms source into an internal structure with a symbol > table and expression stacks etc as it reads the source. Subsequently > this structure is modified, but not discarded, if the source is changed > or additional source code is fed into the system. (The first popular > example of an incremental compiler was Microsoft QuickBasic, as far as > I can recall. At the time, this was a miracle to behold). The internal > representation can then be 'executed', usually by what is in effect a > virtual machine within the system. > > A TRUE COMPILER normally operates as a batch process. All the tasks > that an incremental compiler performs are done once on the whole source > tree. Subsequently, the code generator emits code either for the native > hardware architecture or for a virtual machine. Source code changes > require that the entire batch process be repeated. > > There are also 'just in time' compilers for virtual machines which can, > at runtime, evaluate 'hotspots' in the code which would benefit from > further compilation - more technically, translation - into native > machine code. > > It is because modern scripting languages are incremental compilers and > not merely interpreters that their performance is so good. If they were > pure interpreters they would be hundreds of times slower. > > Possibly Wikipedia could benefit from some clarification in its > explanation. > Don't forget "dynamic translation," a la Smalltalk. Code is compiled for a virtual machine, but all VM instructions (not just hot spots) are translated into native instructions the first time they are encountered.