There are several classes that are involved in compiling a method (or expression), and given your interest in the subject, I am tempted to stimulate you even further in my study and understanding.
In general, the main classes are Scanner, Parser, Compiler, and Encoder. Depending on the dialect, they may have slightly different names and implementations, but the central idea remains the same.
The scanner analyzes the source code character stream and creates a stream of tokens. These tokens are then parsed, which converts them to AST nodes (abstract syntax tree). The compiler then visits the nodes of the AST to analyze them semantically. Here, all variable nodes are classified: method arguments, method temporary methods, general, blocking arguments, temporary locks, etc. It is during this analysis that all variables are bound in the corresponding area. At this stage, the AST is no longer "abstract" because it was annotated with the required information. Finally, the nodes are reviewed to generate the literal and bytecodes of the compiled method.
Of course, there are many things that I exclude from this summary (pragmas, blocking blocks, etc.), but with these basic ideas in mind, you should be prepared to debug a very simple example. For example, start with
Object compile: 'm ^3'
to internalize the process.
After a step back and forth, you will reach the first interesting piece of code, which is the OpalCompiler >> #compile . If we remove the error handling blocks, these methods speak for themselves:
compile | cm | ast := self parse. self doSemanticAnalysis. self callPlugins. cm := ast generate: self compilationContext compiledMethodTrailer ^cm
First, we have a #parse message where analysis nodes are created. Then we have the semantic analysis that I mentioned above, and finally #generate: creates the encoding. You must debug each of these methods to understand the compilation process in depth. Given that you are dealing with a tree, you will be ready to navigate through many visitors.
Once you get familiar with the basic ideas, you can try more elaborate simple examples to see other objects in the scene.