[ANN] Closure Compiler

Anthony Hannan ajh18 at cornell.edu
Tue Mar 25 08:32:42 UTC 2003


Hello All,

A new version of my closure compiler is ready at
http://minnow.cc.gatech.edu/squeak/ClosureCompiler (also linked from
SqueakMap).  The runtime has not changed (closures, context
enhancements, continuations, three new primitives, etc.), but the
compiler itself has been refactored (once again).  This time it uses the
SmaCC parser generator and the Refactory abstract syntax tree.  Also, the
back-end has been refactored a bit and the decompiler has been totally
rewritten.  A special thanks goes to John Brant and Don Roberts for
creating both Smacc and the Refactory Browser, and to Markus Gaelli
and Daniel Vainsencher for porting them, respectively, to Squeak.
Below is a short description of the closure compiler copied from the
Compiler class comment.

Cheers,
Anthony

The Compiler class (like before) serves as the interface to the
compiler.  If Preferences compileBlocksAsClosures is true it will run
the new closure compiler.  The closure compiler classes reside in their
own system category called 'Compiler-*', which is broken down into four
minor categories: 'Compiler-Syntax', 'Compiler-Semantics',
'Compiler-IR', and 'Compiler-Bytecodes'.  The closure compiler also uses
classes in 'SmaCC-Runtime' and the Refactory abstract syntax tree in
'Refactory-Parser'.

Like most compilers, the closure compiler translates source text into
bytecodes using a sequence of phases or transformations.

Phase 1 - Scan and parse text into abstract syntax tree (AST)

SqueakScanner and SqueakParser in 'Compiler-Syntax' transform a method
or do-it text into a Refactory abstract syntax tree.  The SqueakScanner
and SqueakParser classes were automatically generated using SmaCC from a
token and grammar specification derived from the StScanner and StParser
specifications that comes with SmaCC.

Phase 2 - Verify and annotate AST (semantic analysis)

SemanticChecker in 'Compiler-Semantics' binds RBVariableNodes in the AST
to temp, instance, or pool (class, pool, or global) SemVars, raising a
notifier if no match is found.  The lookup is performed on a chain of
SemScopes, one for the class, method and each nested closure.  Var usage
(read/write/capture-in-closure) is tracked using a FiniteAutomaton.  The
final usage state is used to determine unused temps and escaping temps
(temps whose storage need to reside independent of the context since a
block may assign to it after the context is gone).

Phase 3 - Translate AST to intermediate representation (IR)

SemanticTranslator in 'Compiler-Semantics' visits each node in the AST
and invokes the appropriate instruction message on IRBuilder in
'Compiler-IR' resulting in an IRMethod.  An IRMethod consists of
IRInstructions grouped by IRSequence (basic block).  Each IRInstruction
represents a simple stack instruction like pushTemp: or send:.

Phase 4 - Optimize IR

Two simple optimization are applied to the IRMethod:
absorbJumpsToSingleInstrs and absorbConstantConditionalJumps. The first
eliminates jumps to returns and returns directly.  The second converts
chained constant jumps created by and:/or: to single jumps directly to
the target code.

Phase 5 - Translate IR to bytecodes (CompiledMethod)

IRTranslator in 'Compiler-IR' visits each IR instruction and invokes the
appropriate bytecode message on BytecodeGenerator in
'Compiler-Bytecodes'.  Certain combinations of IR instructions (like
storeTemp: and popTop) are mapped to a single bytecode instructions.



More information about the Squeak-dev mailing list