[comp.lang.smalltalk] How does the Smalltalk compiler wor

johnson@p.cs.uiuc.edu (01/11/90)

I am very familiar with the Smalltalk-80 version 2.3 compiler, and I assume
that 2.4 is basically the same, though I know that they made lots of changes.

The parser is recursive descent, and very easy to read and modify.  It
produces a parse tree from which code is produced.  A statement of the
form 
	x<y ifTrue: [z <- y]
forms a tree
		message ifTrue:
		/	  |
	message <	block
	 |	 |	  |
	var x	var y	assignment
			|	|	
			var z	var y


The compiler performs some very basic optimizations on the tree, so that
when code is produced the ifTrue: is not implemented as a message, but
jump instructions are inserted directly.  Thus, if you change the definition
of ifTrue: in True or False then it will make no difference in the compiled
code.  Other messages for which this is done are whileTrue:, and:, etc.

My understanding is that the compiler is hidden in the Digitalk Smalltalks,
though it is still written in Smalltalk.  It's nice to be able to read the
source, if you are interested in compilers, though the code is not always
as well written as one would like.  My guess is that the authors didn't
realize so many people would read their code.

Ralph Johnson