The term metaprogramming refers to programming at the level of program interpretation, or in other words, to extending the interpreter of a given pro_ gramming language in an application_specific way. Traditionally, this concept is available only in dynamically typed and interpreted languages such as Smalltalk or Lisp. This thesis investigates the possibilities of metaprogramming in a statically typed and efficiently compiled programming language. In the course of a case study, we introduce metaprogramming facilities for the Oberon programming language and system.
The result is a variant of the Oberon operating environment which allows a seamless integration of useful meta_level facilities. The key to this integration is a generalized notion of persistent objects and object libraries and its application to components of Oberon programs. Types and procedures are considered to be persistent objects collected in a special kind of library, namely a module. We introduce a metaprogramming protocol which allows to manipulate arbitrary data structures based on the notion of object riders. An object rider is an iterator which can be used to scan the components of an object and which can be hierarchically refined to structured components down to an arbitrary nesting level. We introduce also facilities for controlling procedure activations based on the notion of active procedures. An active procedure is a procedure object which has its own instance specific behavior expressed by a message handler. Active procedures can individually respond to invocation messages and perform any computation as response.
We investigate the implications of this approach with respect to the overall system structure and to the implementation of critical components of the run_time system, such as the library loader and the garbage collector. A new approach to safe library loading and unloading is introduced as well as a simple finalization technique and a way for optimizing libraries with a large number of objects. We show that the integration of metaprogramming facilities does not introduce undue static or dynamic complexity into the Oberon system. A number of realistic applications serve as proof_by_example of the feasibility of the metaprogramming approach. »