my MetaClass $dog_class = MetaClass.new(name => "Dog", repr => "p9opague");
####
sub add_attributes (MetaClass ^class, Int $defval) {
^class.meta.add_attribute(
name => "$.a" ,
type => Int,
default => $defval
);
^class.meta.add_attribute(
name => "$.c" ,
type => Str
);
}
class George {
has Int $.d;
add_attributes(?CLASS, 5);
}
####
my ^Class;
^Class = create_low_level_instance(
class => ^Class, # the instance has a ref to the metaobject
methods => {}, # some place to store the method refs
# ... now create the other
# fields in the class object
);
sub _add_method_bootstrapper ($class, $method_name, $method) {
low_level_instance_access($class, 'methods'){$method_name} = $method;
}
# first install the method dispatcher
_add_method_bootstrapper(
^Class,
'dispatch_method',
-> $obj, $method_name, @args {
# ... find the method, either in the
# the local class, or in an inherited
# class. Then call the method ref with
# the args.
}
);
# now add the add_method method ...
_add_method_bootstrapper(
^Class,
'add_method',
&_add_method_bootstrapper,
);
# whalla, you now have bootstrapped method dispatch
^Class.add_method('get_method' => -> $method_name {
low_level_instance_access($class, 'methods'){$method_name}
});
# go about building the rest of Class here