parrotcode: Core structure of a class | |
Contents | Compilers |
Class - Core structure of a class
Classes are instances of the Class
PMC.
Currently implemented in PIR,
but ultimately implemented as low-level .pmc.
.local pmc class, init_args, obj
init_args = new Hash
init_args['name'] = 'MyClass'
class = new 'Class', init_args
# class = newclass 'MyClass'
class.add_attribute('myattribute')
obj = class.'new'( 'myattribute' => "Foo" )
This subroutine prototypes the find_class
opcode. It looks up a class by name and returns a class object.
The accessor for the name attribute. With no argument, it simply returns the current value for name. When passed an argument, it sets the name of the class, and also sets the association with a namespace.
obj = class.'new'( 'myattrib' => "Foo" )
Create a new instance object from the class object. It takes an optional slurpy, named list of attributes and values to initialize the object.
An accessor for the attributes attribute of the class. It returns the a Hash of all attributes, with a key of the attribute name, and a value of the Attribute object. The accessor is set by a hash of attributes, with a key name and a value type.
Adds a single attribute to the class. It takes a simple string name, and a simple string value for type.
|