Login  Register

Re: [Ann] New version of Ghost

Posted by Mariano Martinez Peck on Mar 24, 2016; 5:54pm
URL: https://forum.world.st/Ann-New-version-of-Ghost-tp4886357p4886368.html



On Thu, Mar 24, 2016 at 1:48 PM, Denis Kudriashov <[hidden email]> wrote:
Hello.

I finished new version of Ghost:


That's very nice to hear!! I love to see someone took it and improve it :)
 
  • DNU approach for basic proxies instead of #cannotInterpret: trick (trick used only for class proxies)
Excellent. Yes, I remember the discussion we had weeks ago. 
  • Abstract proxy classes uses Ghost name instead of Proxy: there are GHObjectGhost and GHClassGhost.
  • GHProxyHandler renamed to GHGhostBehaviour. Concrete ghosts should implement #ghostBehaviour instead of #proxyHandler.
  • GHGhostBehaviour should define #currentMetaLevel to specify set of messages which should not be intercepted. Such meta messages will be executed under ghost instance by subclass of GHMetaMessages.
In previous version there was dictionary which maps meta message selector to implementation selector. It was not suitable. Now meta messages should be directly implemented on particular GHMetaMessages subclass and all it methods are considered meta.
So GhostBehaviour should return instance of GHMetaLevel with meta messages implementation class:
    • GHMetaLevel with: GHEmptyMetaMessages "when all possible messages should intercepted"
    • GHMetaLevel with: GHStandartMetaMessages "when tools specific messages should not be intercepted"
For example standard meta messages implements #inspect:

GHStandartMetaMessages>>inspect
"Create and schedule an Inspector in which the user can examine the receiver's variables."
^ Smalltalk tools inspector inspect: ghost



Nice. Yes, this is much better than my original dictionary-based solution 
 
  • Traits for methods explicitly defined on ghosts: TMinimalProxy, TNotNilProxy, TIdentifiedProxy (with #=, #hash, #class). Concrete proxies can add this traits to itself independently from meta level. For example traits supply convenient methods to retrieve ghost information in polymorphic way with objects:
    • ghost isGhost
    • ghost ghostClass "returns actual class of receiver"
    • ghost ghostPrintString "returns string which represents ghost from meta level point of view"
This traits are suitable and they provide some kind of optimisation for proxies (methods from traits are executed directly instead of complex meta messages mechanizm). But maybe they are superfluous. For example they can't be reused for class proxies which substitute real object classes (to intercept all instance messages).


Good idea as well. Just as yet another useful example of this, I recommend watching the proxies I defined for Marea as you will have interesting proxies for classes and metaclasses. Basically, I defined quite some methods in those proxies so that to avoid intercepting and faulting my objects. See Marea code and watch for it's proxies! Let me know if you found the methods I am talking about. 
 
  • GHClassGhost able to replace class of real objects. It implements cannotInterpret: trick to intercept all instance messages. Subclasses should define two behaviours: #ghostBehaviour (as any other ghost) and #instancesBehaviour which will process instance messages. In previous version it was different message to same #ghostBehaviour.
  • New kind of proxies:
    • GHObjectVirus. It is special kind of GHClassProxy. It infects real object to intercept it messages. From meta level infected object looks like healthy object which means that meta messages are executed by infected object itself. As class virus looks like real victim class. So in case when virus is created with standard meta level tools will not differ him from health object. There are special messages which allow ask object about viruses:
      • infectedObject isInfectedByVirus
      • infectedObject virus
      • infectedObject recoverFromVirus

Sorry I did not get this one. 
 
    • GHLearningObject. It is suitable proxy which retrieves all unknown methods from teacher class. Thank's Stephan for this idea.
This kind of proxy allows me easily find required set of messages to support inspectors and debuggers. You can create instance of learning object by:
GHLearningObject withTeacher: Object.
And any operation with it will fill studiedMessages dictionary. In my case I opened GTInspector on it and got all messages which was needed for him. 

Great idea too. I had to come with the set of mapped selectors (the dictionary) by poor man human try and error hahaha. 
 
  • Ghosts works correctly with latest Pharo 5 tools (basic inspector, GTInspector, SpecDebugger, GTDebugger). Required methods for tools are extracted to 'Ghost-GTSupport' package. 
  • Repackaging:
    • Ghost-ObjectProxies. It contains all core classes and abstract GHObjectGhost which is based on DNU
    • Ghost-ClassProxies. It contains code for proxy which can substitute class of real object. GHClassGhost implements cannotInterpret: trick to intercept all instance messages. And it implement support for debugging such methods.
    • Ghost-LearningObject
    • Ghost-ObjectVirus
    • Ghost-GTSupport
    • test packages
  • All code moved to Pharo repository http://smalltalkhub.com/#!/~Pharo/Ghost (in includes packages from CAR repo too) 


Excellent. 

 
Thanks Denis for pushing Ghost further!


--