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 ['Foo';'Bar'] namespace.

Methods ^


Create and initialize a new protoobject for class. The newly created protoobject is placed as an entry in the appropriate namespace and returned.

new_subclass(baseclass, name [, attr1, attr2, ...] )

Helper method to create subclasses and their corresponding protoobjects as a single method call. This method creates a subclass of baseclass with the given name, adds attributes attr1, attr2, etc. to the subclass, and then creates a corresponding protoobject for the subclass.

The name parameter is either an array of strings or a string with namespace identifiers separated by double colons (::).

The method returns the subclass object and its corresponding protoobject.