at:tutorial:reflection
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
at:tutorial:reflection [2008/11/06 15:36] – elisag | at:tutorial:reflection [2010/11/16 15:59] – fixed tvcutsem | ||
---|---|---|---|
Line 85: | Line 85: | ||
===== Mirages ===== | ===== Mirages ===== | ||
- | Extending the AmbientTalk core language | + | Extending the AmbientTalk core language |
As a simple example, we show how to trace all method calls made on an object. The first step is to define a //mirror// object that encapsulates this logging behaviour. A mirror object must implement the complete AmbientTalk MOP. To make it convenient to make small changes to the MOP, AmbientTalk provides the '' | As a simple example, we show how to trace all method calls made on an object. The first step is to define a //mirror// object that encapsulates this logging behaviour. A mirror object must implement the complete AmbientTalk MOP. To make it convenient to make small changes to the MOP, AmbientTalk provides the '' | ||
Line 91: | Line 91: | ||
< | < | ||
def createTracingMirror(baseObject) { | def createTracingMirror(baseObject) { | ||
- | extend: defaultMirror with: { | + | extend: defaultMirror.new(baseObject) |
def invoke(slf, invocation) { | def invoke(slf, invocation) { | ||
system.println(" | system.println(" | ||
Line 100: | Line 100: | ||
</ | </ | ||
- | The primitive '' | + | The primitive '' |
< | < | ||
- | def createTracingMirror(baseObject) { | + | def TracingMirror := mirror: { |
- | | + | def invoke(slf, invocation) { |
- | def invoke(slf, invocation) { | + | system.println(" |
- | system.println(" | + | super^invoke(slf, |
- | super^invoke(slf, | + | |
- | } | + | |
} | } | ||
} | } | ||
Line 121: | Line 119: | ||
</ | </ | ||
- | In the code above, the closure passed to '' | + | In the code above, the closure passed to '' |
- | {{:at:tutorial:meta-2.jpg|: | + | Another alternative is to just pass a mirror prototype to '' |
+ | < | ||
+ | def mirage := object: { | ||
+ | def foo() { 42 }; | ||
+ | } mirroredBy: TracingMirror; | ||
+ | </ | ||
- | When invoking the method '' | + | The AmbientTalk VM will then call '' |
+ | |||
+ | When invoking the method '' | ||
< | < | ||
- | > mirage.m(); | + | > mirage.foo(); |
- | invoked | + | invoked |
>> 42 | >> 42 | ||
</ | </ | ||
+ | |||
+ | The picture below gives an overview of the different objects involved in the actor. | ||
+ | |||
+ | {{: | ||
Whereas the example provided above may seem a little contrived, the reflective capabilities of AmbientTalk allow it to be extended with many abstraction relating to distributed computing for mobile ad hoc networks (AmbientTalk' | Whereas the example provided above may seem a little contrived, the reflective capabilities of AmbientTalk allow it to be extended with many abstraction relating to distributed computing for mobile ad hoc networks (AmbientTalk' | ||
Line 138: | Line 147: | ||
===== The Metaobject Protocol ===== | ===== The Metaobject Protocol ===== | ||
- | The Meta-Object Protocol of AmbientTalk can be divided into a series of independent protocols. Whereas the full semantics and signature of the meta-methods can be found in the [[http://prog.vub.ac.be/ | + | The Meta-Object Protocol of AmbientTalk can be divided into a series of independent protocols. Whereas the full semantics and signature of the meta-methods can be found in the [[http://soft.vub.ac.be/ |
+ | |||
+ | The **Message Invocation Protocol** consists of methods to deal with both synchronous and asynchronous method invocation. It provides necessary hooks to intercept both the reception of asynchronous messages and the invocation of synchronous messages. Moreover, it provides a hook to intercept asynchronous messages being sent by the object, allowing the object to add additional metadata to the message. The '' | ||
- | The **Message Passing Protocol** consists of methods to deal with both synchronous and asynchronous message sending. It provides necessary hooks to intercept both the reception of asynchronous messages and the invocation of synchronous messages. Moreover, it provides a hook to intercept asynchronous messages being sent by the object, allowing the object to add additional metadata to the message. The '' | + | {{: |
- | The **Object | + | The **Object |
The **Slot Access and Modification Protocol** consists of operations which allow trapping both dynamic access and modification to slots. For instance, '' | The **Slot Access and Modification Protocol** consists of operations which allow trapping both dynamic access and modification to slots. For instance, '' | ||
- | The **Structural Access Protocol** consists of operations used list all available slots, get access to a first-class slot representation and to add new slots to an existing object. The '' | + | The **Structural Access Protocol** |
- | The **Instantiation Protocol** consists of the '' | + | The **Object |
The **Relational Testing Protocol** consists of the methods '' | The **Relational Testing Protocol** consists of the methods '' | ||
- | The **Type | + | The **Type |
The **Evaluation Protocol** ensures that any AmbientTalk object can be part of a parse tree, and therefore every object provides meaningful implementations of the '' | The **Evaluation Protocol** ensures that any AmbientTalk object can be part of a parse tree, and therefore every object provides meaningful implementations of the '' |
at/tutorial/reflection.txt · Last modified: 2010/11/16 16:32 by tvcutsem