Design of the Parrot Virtual Machine The OO-ish bits Dan Sugalski dan@sidhe.org
Important notes The OO parts of the design aren’t complete This is not a pure OO system I am not an OO guy We care about speed We don’t care about theoretical purity July 22, 2019 Design of the Parrot VM
Quick parrot design recap Register based Bytecode driven Mostly language neutral July 22, 2019 Design of the Parrot VM
Multiple language support Perl 6 Perl 5 Ruby Python JVM .NET Z-Machine July 22, 2019 Design of the Parrot VM
Challenges of the design Several conflicting object systems Runtime instantiation of much of the system Dynamic redefinition of classes, methods, and types of objects Dynamic redefinition of inheritance hierarchies Object system differences must be invisible to user code July 22, 2019 Design of the Parrot VM
Programmer view of objects Programmer shouldn’t care about the source of an object Programmer shouldn’t have to make any allowances for the source of an object when calling its methods It all ought to just work July 22, 2019 Design of the Parrot VM
Required end-user functionality Check for Class parentage Method existence Call method Get property Set property July 22, 2019 Design of the Parrot VM
Implementation of objects Objects are an opaque and fundamental variable type All variables have a core set of vtable functions Call method and the other minimal functionality is shared across all variables Since it all looks the same at this level, usage is consistent regardless of object type July 22, 2019 Design of the Parrot VM
Usage example my $foo; $foo = Some::Class.new(); $foo.a_method(12, 15); July 22, 2019 Design of the Parrot VM
Advantages of this scheme Programs are isolated from the implementation details Doesn’t place many real restrictions on the implementation of objects Offers class authors plenty of flexibility July 22, 2019 Design of the Parrot VM
Disadvantages of this scheme Programs are isolated from the implementation details Doesn’t place many real restrictions on the implementation of objects Offers class authors plenty of flexibility July 22, 2019 Design of the Parrot VM
Parrot’s object model requirements Support at least two wildly different implementation models Be more efficient than perl 5’s object system July 22, 2019 Design of the Parrot VM
Required functionality Untyped variables Runtime class changes on objects Runtime class mutation Runtime inheritance hierarchy changes Multiple inheritance Signature-based dispatch Cross-class-scheme inheritance July 22, 2019 Design of the Parrot VM
Requirements for classes More stringent Need: List of methods in class List of immediate parent classes Parent class method search list Duplication capabilities Parent class method search scheme Redispatch scheme Attribute count Duplication capabilities mean whether the class can be really in the class hierarchy twice, or if multiple occurrences are thrown away so only one is in there July 22, 2019 Design of the Parrot VM
Easy Answer Do all inheritance with delegation At least conceptually Does allow for inheritance from disparate object systems Performance is potentially an issue Shortcuts are definitely in order July 22, 2019 Design of the Parrot VM
Calling convention provides Real self Current self Class offset Attribute start offset July 22, 2019 Design of the Parrot VM