1 / 16

OO in Parrot

OO in Parrot. Dan Sugalski Dan@sidhe.org. April 14, 2003. Goals of Parrot OO. Support perl 5’s “anything goes” style of objects Support perl 6’s “atrributes and compile-time fixednes” style of objects Support Ruby and Python objects All interchangeably. OO in four parts.

remy
Télécharger la présentation

OO in Parrot

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. OO in Parrot Dan Sugalski Dan@sidhe.org April 14, 2003

  2. Goals of Parrot OO • Support perl 5’s “anything goes” style of objects • Support perl 6’s “atrributes and compile-time fixednes” style of objects • Support Ruby and Python objects • All interchangeably

  3. OO in four parts • Outside code using objects • Code within parrot-style object classes • Class mutation • Inheritance

  4. Objects from the outside • Objects are opaque • They have properties • You can call methods on them • Other than that, don’t touch

  5. Calling a method Perl 6 $obj.foo();

  6. Calling a method Parrot Assembly clearall find_global P2, “$obj” set S0, “foo” callmeth

  7. Calling a method Parrot Assembly (Fast version) clearall find_global P2, “$obj” set S0, “foo” callmeth .foo_hashed

  8. Parrot class objects • Objects are arrays of attributes • One slot per attribute of the class and all compatible parent classes • Most metadata about objects is stored in the class for the object. • This includes slot directories and such

  9. Mutating classes • Adding attributes at runtime is possible • We’re building a full notification and event system into Parrot • Blows caches like mad, so try to avoid this

  10. Inheritance • You can inherit from any class • Inheriting from ‘foreign’ classes does transparent delegation • Delegated objects have parent properties for proper redispatch • Opaque classes are a bit of a dead-end

  11. New for Method Invocation • Prototypes enforced for methods • Method vs Sub invocation known • Multimethod dispatch • Guaranteed passed-in method names • Method tail calls

  12. Introspection • No promises in general • In practice, lots of opportunities • Base object type is completely inspectable

  13. Engine goodies • Full notification and event system • Method caching (lexically scoped!) • Core hash calculations • Multimethod dispatch handling • Everything can be overridden

  14. Property fetching Property storing Returned property hashes Attribute get Attribute set can does isa AUTOLOAD Method lookup Method dispatch Pre and post method calling Really, everything

  15. Both kinds of objects • Both reference and value types • Objects have full control over their vtables • Full control is yours if you want it • Wraps up tying, overloading, and magic • Oddly enough, all the object stuff is done as just a custom PMC class--no core changes were needed • We’re making some anyway, though

  16. Our plans for world domination • Perl 6, Python, and Ruby objects all use the new scheme • Transparent inheritance/delegation for perl 5 support

More Related