Presentation is loading. Please wait.

Presentation is loading. Please wait.

OO in Parrot Dan Sugalski April 14, 2003.

Similar presentations

Presentation on theme: "OO in Parrot Dan Sugalski April 14, 2003."— Presentation transcript:

1 OO in Parrot Dan Sugalski 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 $;

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 Really, everything Property fetching Property storing Returned property hashes Attribute get Attribute set can does isa AUTOLOAD Method lookup Method dispatch Pre and post method calling

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

Download ppt "OO in Parrot Dan Sugalski April 14, 2003."

Similar presentations

Ads by Google