|parrotcode: PIR implementation for creating protoobjects|
|Contents | Libraries|
Protoobject.pir - PIR implementation for creating protoobjects
load_bytecode 'Protoobject.pbc' .local pmc protomaker, fooclass, fooproto # create a protoobject for class Foo protomaker = new 'Protomaker' fooclass = get_class 'Foo' fooproto = protoobj.'new_proto'(fooclass) # create a subclass 'NS::Bar' from 'Foo' with attributes .local pmc barclass, barproto protoobj = new 'Protomaker' fooclass = get_class 'Foo' (barclass, barproto) = protoobj.'new_subclass'(fooclass, 'NS::Bar', '$attr')
Objects of class
Protomaker are used to construct and initialize "protoobjects" for Parrot classes. The concept of protoobjects comes from Perl 6; protoobjects are "empty" instances of a class -- i.e., they are instances that are simply more undefined than a normal instance.
Newly created protoobjects are automatically added as symbols in a corresponding namespace -- for example, the protoobject for
Foo::Bar::Baz is automatically entered as the 'Baz' symbol in the
class. The newly created protoobject is placed as an entry in the appropriate namespace and returned.
baseclasswith the given
name, adds attributes
attr2, etc. to the subclass, and then creates a corresponding protoobject for the subclass.
nameparameter is either an array of strings or a string with namespace identifiers separated by double colons (