Instantly share code, notes, and snippets.

What would you like to do?
Index: runtime/parrot/library/P6object.pir
--- runtime/parrot/library/P6object.pir (revision 40185)
+++ runtime/parrot/library/P6object.pir (working copy)
@@ -441,16 +441,19 @@
ns = split '::', name
- ## get the metaclass (how) from :protoobject, or create one
+ ## get the metaclass (how) from :how, or :protoobject, or create one
.local pmc how
+ how = options['how']
+ unless null how goto have_how
$P0 = options['protoobject']
if null $P0 goto make_how
how = $P0.'HOW'()
- goto have_how
+ goto how_setup
## create a metaclass for parrotclass
how = new 'P6metaclass'
setattribute how, 'parrotclass', parrotclass
+ have_how:
## create an anonymous class for the protoobject
.local pmc protoclass, protoobject
@@ -506,7 +509,7 @@
push ns, 'EXPORT'
push ns, 'ALL'
set_root_global ns, $S0, protoobject
- goto have_how
+ goto how_setup
## anonymous classes have empty strings for shortname and longname
@@ -515,7 +518,7 @@
setattribute how, 'longname', longname
setattribute how, 'shortname', shortname
- have_how:
+ how_setup:
## attach the metaclass object to the parrotclass
setprop parrotclass, 'metaclass', how
@@ -524,14 +527,15 @@
-=item new_class(name [, 'parent'=>parentclass] [, 'attr'=>attr] [, 'hll'=>hll])
+=item new_class(name [, 'parent'=>parentclass] [, 'attr'=>attr] [, 'hll'=>hll] [, 'how'=>howclass)
Create a new class called C<name> as a subclass of C<parentclass>.
When C<name> is a string, then double-colons will be treated as separators.
If C<parentclass> isn't supplied, defaults to using C<P6object>
as the parent. The C<attr> parameter is a list of attribute names
to be added to the class, specified as either an array or a string
-of names separated by spaces.
+of names separated by spaces. The C<how> parameter allows you to
+specify the meta-class for this class.
@@ -593,6 +597,16 @@
goto iter_loop
+ .local pmc how
+ how = options['how']
+ if null how goto how_done
+ how = self.'get_parrotclass'(how)
+ how = new how
+ setattribute how, 'parrotclass', parrotclass
+ options['how'] = how
+ how_done:
.tailcall self.'register'(parrotclass, options :named :flat)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment