
Computational. Reflection Class based Objectkented Languages JacquesFERBER LAFORIA Universite Paris 6, T 45-46 4 place Jussieu 75252 Paris Cedex 5 France Email: [email protected] Abstract 1 Introduction This paper describes various models of computational After having been considered as a fascinating but rather reflection in class based object oriented language. Two sophisticated feature, reflection has become an important different approaches are covered: the meta-object approach issue in the field of computing architecture and language which supposes that every object can have a meta-object design [Smith 821 Ferber 861 p.Maes 87.b] Ferber 881 describing and monitoring its behavior, and the message [Watanabe & Yonezawa 881. Reflective systems have reification approach which describes a messageas an object. shown their practical interest for implementing systems, The me&object approach is discussed more fully showing because of their ability to represent the system, i.e. its that it is important to differentiate between structural functionalities and its implementation, within the system reflection and computational reflection. We will see that, itself. Some of the key features of such systems are their whereas classes and me&asses are very important for the capacity for: former, they cannot cope adequately with the later. Therefore we introduce a model of computational reflection - implementation description: allocation of where me&objects are instances of a class META-OBJECT entities, garbage collection, incremental extension or of one of its subclasses. and re-implementation of the whole system; Permission to copy without fee all or part of this material is granted provided that the copies are not made or distributed for direct commercial advantage, - monitoring entities of the language: the ACM copyright notice and the title of the publication and its date appear, inspection, analysis, and dynamic modification of and notice is given that copying is by permission of the Association for Computing Machinery. To copy otherwise, or to republish, requires a fee the code within the language itself; and/or specific permission. 0 1989 ACM 089791-333-7/89/0010/0317 $1.50 October 1-6, 1989 OOPSLA ‘89 Proceedings 317 - interfacing and debugging: implementation of 1.’ what is the nature of met&objects and/or of meta- programming tools within the language; communications, and what is their structure and behavior, - self-reorganization: learning abilities of the ii’ how is the handling of messages and lookup of system’s behavior, for an increase in consistency and methods described at the meta-level related to basic efficiency. messagepassing, iii’ when does the system uses meta-object and/or Object oriented languages (OOL) seem to be a major meta-communications. domain where reflection can easily be implemented, because of the distributed nature of data and procedure in objects. This paper introduces three models of computational However there have been just a few works on that subject, reflection in class based object oriented languages. It shows leading to two different model of reflection: that the so-called metackzsses which are very useful for structural reflection cannot deal correctly with 1 the first model advocated by P.Cointe [Cointe 883, computational reflection, i.e. they are not used at the concerns the reflective use of classes and metaclasses for computational meta level. implementing objects. In a pure class model, like OBJVLISP [Briot & Cointe 871, each entity is an instance The three models are: of a single class. Classes are instances of other classes, called metaclasses. This model allows for extension of the l the metaclass model which is based on an static part of OOL, i.e. the structural aspects of objects equivalence between the meta-object and the class of considered as implementation of abstract data types. an object. 2 the second model, introduced by P.Maes [Maes 87.a], l the specific metu-object model where meta-objects following Smiths work [Smith 821, is directed towards the are instances of a class META-OBJECT or of one of use of computational reflection within the object oriented its subclasses. programming (OOP) paradigm. This model is based on the fact that each object has its own me&object that represents l the meta-communication model which is based on all its otherwise implicit informations: its structure and its the reification of the message. way of handling messages. It has been shown that the use of meta-objects for buildind reflection in OOL allows for This paper describes the three models. All implementations the definition of new features not initially present in the are given in the OBJVLISP model of OOL. However, the system: multi-inheritance, daemons on accessof attributes, implementation is not specific and can be adapted to any interface programming, debugging tools, etc... [Maes 87.b] object oriented language using messagepassing as the basic However, this model has been defined in the context of the control structure. language KRS [Van Marcke 881, which does not support the class/instance model of traditionnal OOL such as SMALLTALK, CL0s [Michiel & Gabriel] or OBJVLISP. 2 Aspects of reflection When defining an reflective architecture, one has to answer 2.1 Domains and reflective equations three basic questions: Creating a reflective architectures is a way of effectively i what entities should be reified, i.e. transformed into relating the implicit entities of a computation domain Dn, something which can be manipulated at the meta called the basic level, into another computation domain level? Dn+I, called the meta-level. Each domain can serve both as ii how is the causal link (i.e. the relationship between a basic domain for an upper level, or as a meta-domain for a a lower and an upper level) implemented? . lower level, except the domain Do, made of referents, which 111 when does the system shifts up to a meta-level? can be used only as a basic level. In the domain of object oriented languages, where the only Models of reflection can easily be defined by ways of entities are objects and messages, these questions can be reflection equations, which express how entities and reformulated as follows: expressions of the basic level, are described at the meta- level. Thus, reflective equations act as semantic equations, i.e. they give the semantics of the lower levels in terms of 318 OOPSLA ‘89 Proceedings October 1-6, 1989 upper levels. For instance, in LISP, one can give the main 2.2 Reflection in Object reflection equation for expression evaluation: oriented languages mge]pK Dn= Ml[ (eval 'e B!l[pB M [K]) 1 Dn+l In 3-KRS [Maes 87.a], when an object 0 receives a message, it delegates the message to its me&object M-O. where p and K represent respectively the environment and This process is applied again until the system finds a meta- the continuation of the evaluation of the expression e, M is object called DEFAULT-META-OBJECT,which uses a basic a semantic function from Dn to Dn+l, and where ‘e, is the interpreter of messageswritten directly in LISP. data structure that representse. The traditional model of reflection is based on However, 3-KRS is not a class based OOL. When adapting interpretation. The domain Dn is made of a set of entities the 3-KRS style of reflection in the class/instance paradigm, and expressions, written in a language Ln, and of an one has to choose between different solutions: the meta- interpreter In which interprets those expressions. The object can be either the receiver’s class, as in the structural interpreter is written in a language Ln+l and is interpreted model of reflection advocated by P.Cointe ICointe.871, or by an In+1 interpreter. When the system is not reflective, an instance of a specific class, META-OBJECT (or an the language Ln+ I is radically different from Ln. For instance of one of its subclasses). In chapter 4 the two instance, if Ll is LISP, L2 could be a compiled language models will be presentedand discussed in details. like C or Pascal, L3 the machine language instruction set, Using a meta-object for reflection is not the only way for etc... implementing computational reflection: it is also possible In reflective architectures, there is a virtually infinite chain to reify the communication process. This leads to a of identical languages Li, the so-called reflective tower. somehow different view of reflection in OOL, which can This can be achieved because there is one interpreter, call it also be used for debugging and implementation purposes. In I’, written in a language L’ different from Li, which is used chapter 5, this model will be presented and compared to the to close the regression and replace the interpreter In at the preceding. highest level of computation needed. For instance, in 3-LISP [DesRivikes & Smith 841 , when the system encounters a reflective function at the level Dn, 3 ObjVlisp: the demonstration it shift up one level to Dn+l . There it starts a computation. language If there is a call to a reflective function, it goes one level higher, at level Dn+2, etc... until it finds a reflective In order to develop the three basic reflection models in class function which does not use any reflective functions. All based OOL, we will use OBJVLISP, a Ianguage whose non-reflective functions are interpreted by the interpreter I’, organization is based on structural reflection [Cointe 871. written in another language. Thus reflection can be Actually this language is not important in itself and will be implemented because there is no loop in the definition of used only for demonstration purposes. Many papers have reflective function. introduced the OBJVLISP syntax.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages10 Page
-
File Size-