TITLE
Object and Class semantics for Parrot
VERSION
CURRENT
Maintainer: Dan Sugalski
Class: Internals
PDD Number: 15
Version: 1.1
Status: Developing
Last Modified: March 11, 2003
PDD Format: 1
Language: English
HISTORY
CHANGES
- Version 1.1
-
Removed attributes from the object interface and put them in the class interface section, where they belong.
- Version 1.0
-
None. First version
ABSTRACT
This PDD describes the semantics of Parrot's object and class systems. The PDD is divided into two parts, the semantics expressed to user programs through PMCs, and the default back-end class scheme.
Note that the class system is not the single mandated class scheme, merely the one designed to express the semantics needed for perl 6, ruby, and python. Alternate class systems are certainly possible, and direct compatibility with the system as described here isn't strictly necessary.
DESCRIPTION
This PDD lays out two separate things.
The first is the object semantics, as presented to user programs. This means that code has an object PMC, and wants to do Object Things with it. Object semantics are reasonably simple, and will be defined in a bit.
The second is class semantics. Class semantics are rather more complex, and can't really be dealt with in a generic way, such that all classes are compatible. As such this PDD lays out Parrot's default class semantics, and it is assumed that languages that need different semantics will then do whatever they need to, provided that the objects they create are generically usable.
Please see the glossary for definitions of the various terms.
IMPLEMENTATION
Objects
Objects must do the following things. Note that these are required of PMCs in general, but objects are presumed to actually do something useful with these things rather than just (potentially) throwing an exception.
Any PMC that meets these criteria can be considered an object. Objects do not have to have corresponding classes, though it's a fairly common occurrence.
- Get and set properties
-
Strictly speaking, getting and setting properties is a PMC thing rather than an object thing, as PMCs are
- Get a property hash
- Call a method
- Get a method PMC
- Check if a PMC can perform a method
- Check if a PMC implements an interface
- Check if a PMC is a member of or child of a class
Classes
TRANSLATION AND GLOSSARY
Since every object system on the planet shares a common set of terms but uses them completely differently, this section defines
Glossary
- Property
-
A name and value pair attached to a PMC. Properties may be attached to the PMC in its role as a container or the PMC in its role as a value.
Properties are global to the PMC. That is there can only be one property named "FOO" attached to a PMC, and it is globally visible to all inspectors of the PMCs properties. They are not restricted by class.
Properties are generally assigned at runtime, and a particular property may or may not exist on a PMC at any particular time. Properties are not restricted to objects as such, and any PMC may have a property attached to it.
- Attribute
-
An attribute is a slot in an object that contains a value, generally a PMC. (Containing non-PMCs leads to interesting garbage collection issues at the moment) Attributes are referenced either by slot number or by class name/attribute name pairs. (At least conceptually)
Attributes are set on a class-wide basis, and all the objects of a class will have the same set of attributes. Generally attributes aren't added or removed from classes at runtime, as this would require resizing and moving the elements of the attribute arrays of existing objects, and potentially recompiling code with fixed attribute offsets embedded in it. Most OO languages don't allow attribute changes to existing classes, though parrot's base attribute system does allow this.
- Method
-
In its strictest sense, a method is a chunk of code that you call with an object in the object slot of the calling conventions.
More generally, a method is some piece of code that you invoke by name through an object. You call the object's "Invoke a method" vtable entry, passing in the method name (Assuming we don't just get it from the sub name register, per calling conventions). The object is then responsible for doing something with the method being requested. Presumably it calls the method, though this isn't strictly required.
- Delegate
-
An object that is transparently (to the user) embedded in another object. Delegate objects are used in those cases where we can't inherit from a class because the class is from a different object universe.
As an example, assume you have a class A, which inherits from class B. The classes are incompatible, so Parrot can't automatically meld B into A, as it might if they were. When instantiating an object of class A, Parrot will automatically instantiate an object of class B and embed it in the object of class A. The object of class B is class A's delegate--when a method call comes in that A can't handle, that method call is delegated to B.
- Parent class
-
Also called the super-class. The parent class is, in an inheritance situation, the class being derived from. If A derives from B, B is the parent class of A.
- Child class
-
Also called the sub-class. The child class is, in an inheritance situation, the class doing the deriving. If A derives from B, A is the child class.
Translation
The following list a set of languages, then within each language what the parrot term translates to.
- Python
-
- Attribute
-
A Python attribute maps to a parrot property
- .NET
-
- Attribute
-
What .NET calls an attribute parrot calls a property
- Property
-
What .NET calls a property we call an attribute
- Generic Terminology
ATTACHMENTS
None