Compiling and evaluating code
Although the Blue Book describes the Smalltalk compiler, it does not actually specify any of the messages that it should support. The various Smalltalk dialects are not consistent on whether to access the compiler through Compiler class methods, or to create a compiler instance and access compilation facilities through instance methods. VA Smalltalk takes the first approach, but the choice is completely arbitrary.
A key question is how to handle compile errors. CLIM defines an object that encapsulates all of the error information that a compiler might return. A CompilerError is required to support the following accessor messages, each of which returns one of the attributes of the error object:
context
Answers the class in whose context the source code was compiled
message
Answers the compiler error or warning message
sourceString
Answers the source code string that was compiled
startPosition
Answers the position in the source code string of the first character of the token at which the error or warning was detected
stopPosition
Answers the position in the source code string of the last character of the token at which the error or warning was detected
Compiler error handling in CLIM works as follows:
1. Several of the class messages defined for Compiler accept as a parameter a one-argument block, called the fail block.
2. If the compilation is successful, these messages return an instance of CompiledMethod, described in the next section.
3. However, if a compiler warning or error occurs, a CompilerError describing the error is created.
4. It is then passed as an argument to the fail block, which is evaluated.
5. The result of evaluating the fail block is returned.
Note that CLIM does not define how the CompilerError is created, or how its attributes are set. These are assumed to be platform-specific operations. This mechanism was chosen because it provides a fairly general way to handle warnings and errors, but does not require a complex runtime infrastructure.
The compilation facilities provided in CLIM support two distinct activities: compiling and evaluating.
Last modified date: 01/29/2015