Skip to content

Commit 777e36f

Browse files
committed
Tentatively add a way to re-parent a class to NQP's class meta-object, so we'll (hopefully) be able to get Perl 6's meta-objects to say they're ~~ Any.
1 parent 73ebd23 commit 777e36f

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/how/NQPClassHOW.pm

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,32 @@ knowhow NQPClassHOW {
126126
method set_default_parent($obj, $parent) {
127127
$!default_parent := $parent;
128128
}
129+
130+
# Changes the object's parent. Conditions: it has exactly one parent, and that
131+
# parent has no attributes, and nor does the new one.
132+
method reparent($obj, $new_parent) {
133+
if +@!parents != 1 {
134+
nqp::die("Can only re-parent a class with exactly one parent");
135+
}
136+
for @!parents[0].HOW.mro(@!parents[0]) {
137+
if +$_.HOW.attributes($_, :local) {
138+
nqp::die("Can only re-parent a class whose parent has no attributes");
139+
}
140+
}
141+
for $new_parent.HOW.mro($new_parent) {
142+
if +$_.HOW.attributes($_, :local) {
143+
nqp::die("Can only re-parent to a class with no attributes");
144+
}
145+
}
146+
@!parents[0] := $new_parent;
147+
@!mro := compute_c3_mro($obj);
148+
self.publish_type_cache($obj);
149+
self.publish_method_cache($obj);
150+
self.publish_boolification_spec($obj);
151+
self.publish_parrot_vtable_mapping($obj);
152+
self.publish_parrot_vtablee_handler_mapping($obj);
153+
1;
154+
}
129155

130156
method add_role($obj, $role) {
131157
for @!roles {

0 commit comments

Comments
 (0)