Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
A further round of MOP code simplifications.
We've relied in various places on methods that Parrot's PMCs provide,
but that it's not reasonable to expect a ground-up 6model runtime to
offer. In general, the only things that define internal methods are
the KnowHOW and KnowHOWAttribute, from which everything else is built.
By keeping the MOP simpler, it means we can keep the runtime leaner
and write more of NQP in NQP. This isn't the entire set of changes we
need, but many of them.
  • Loading branch information
jnthn committed Jan 14, 2013
1 parent 8319c39 commit 4084b68
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
38 changes: 21 additions & 17 deletions src/how/NQPClassHOW.pm
Expand Up @@ -156,12 +156,12 @@ knowhow NQPClassHOW {
nqp::die("Can only re-parent a class with exactly one parent");
}
for @!parents[0].HOW.mro(@!parents[0]) {
if +$_.HOW.attributes($_, :local) {
if nqp::elems($_.HOW.attributes($_, :local)) {
nqp::die("Can only re-parent a class whose parent has no attributes");
}
}
for $new_parent.HOW.mro($new_parent) {
if +$_.HOW.attributes($_, :local) {
if nqp::elems($_.HOW.attributes($_, :local)) {
nqp::die("Can only re-parent to a class with no attributes");
}
}
Expand Down Expand Up @@ -210,7 +210,7 @@ knowhow NQPClassHOW {
my @specialized_roles;
for @!roles {
my $ins := $_.HOW.specialize($_, $obj);
@specialized_roles.push($ins);
nqp::push(@specialized_roles, $ins);
nqp::push(@!done, $_);
nqp::push(@!done, $ins);
}
Expand Down Expand Up @@ -316,15 +316,15 @@ knowhow NQPClassHOW {
# immediate parents and merge.
my @merge_list;
for @immediate_parents {
@merge_list.push(compute_c3_mro($_));
nqp::push(@merge_list, compute_c3_mro($_));
}
@merge_list.push(@immediate_parents);
nqp::push(@merge_list, @immediate_parents);
@result := c3_merge(@merge_list);
}
}

# Put this class on the start of the list, and we're done.
@result.unshift($class);
nqp::unshift(@result, $class);
return @result;
}

Expand Down Expand Up @@ -381,7 +381,7 @@ knowhow NQPClassHOW {
my @new_list;
for @merge_list[$i] {
unless $_ =:= $accepted {
@new_list.push($_);
nqp::push(@new_list, $_);
}
}
@merge_list[$i] := @new_list;
Expand All @@ -391,23 +391,28 @@ knowhow NQPClassHOW {
# Need to merge what remains of the list, then put what was accepted on
# the start of the list, and we're done.
@result := c3_merge(@merge_list);
@result.unshift($accepted);
nqp::unshift(@result, $accepted);
return @result;
}

method publish_type_cache($obj) {
my @tc;
for @!mro { @tc.push($_); }
for @!done { @tc.push($_); }
for @!mro { nqp::push(@tc, $_); }
for @!done { nqp::push(@tc, $_); }
nqp::settypecache($obj, @tc)
}

sub reverse(@in) {
my @out;
for @in { nqp::unshift(@out, $_) }
@out
}

method publish_method_cache($obj) {
# Walk MRO and add methods to cache, unless another method
# lower in the class hierarchy "shadowed" it.
my %cache;
my @mro_reversed := nqp::clone(@!mro);
@mro_reversed.reverse();
my @mro_reversed := reverse(@!mro);
for @mro_reversed {
for $_.HOW.method_table($_) {
%cache{$_.key} := $_.value;
Expand Down Expand Up @@ -448,8 +453,7 @@ knowhow NQPClassHOW {

method publish_parrot_vtablee_handler_mapping($obj) {
my %mapping;
my @mro_reversed := nqp::clone(@!mro);
@mro_reversed.reverse();
my @mro_reversed := reverse(@!mro);
for @mro_reversed {
for $_.HOW.parrot_vtable_handler_mappings($_, :local(1)) {
%mapping{$_.key} := $_.value;
Expand Down Expand Up @@ -554,7 +558,7 @@ knowhow NQPClassHOW {
my @meths;
for @!mro {
for $_.HOW.methods($_, :local) {
@meths.push($_)
nqp::push(@meths, $_)
}
}
@meths
Expand All @@ -581,13 +585,13 @@ knowhow NQPClassHOW {
my @attrs;
if $local {
for %!attributes {
@attrs.push($_.value);
nqp::push(@attrs, $_.value);
}
}
else {
for @!mro {
for $_.HOW.attributes($_, :local) {
@attrs.push($_);
nqp::push(@attrs, $_);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/how/NQPConcreteRoleHOW.pm
Expand Up @@ -121,7 +121,7 @@ knowhow NQPConcreteRoleHOW {
method methods($obj, :$local) {
my @meths;
for %!methods {
@meths.push($_.value);
nqp::push(@meths, $_.value);
}
@meths
}
Expand All @@ -141,7 +141,7 @@ knowhow NQPConcreteRoleHOW {
method attributes($obj, :$local) {
my @attrs;
for %!attributes {
@attrs.push($_.value);
nqp::push(@attrs, $_.value);
}
@attrs
}
Expand Down
4 changes: 2 additions & 2 deletions src/how/NQPParametricRoleHOW.pm
Expand Up @@ -164,7 +164,7 @@ knowhow NQPParametricRoleHOW {
method methods($obj, :$local) {
my @meths;
for %!methods {
@meths.push($_.value);
nqp::push(@meths, $_.value);
}
@meths
}
Expand All @@ -180,7 +180,7 @@ knowhow NQPParametricRoleHOW {
method attributes($obj, :$local) {
my @attrs;
for %!attributes {
@attrs.push($_.value);
nqp::push(@attrs, $_.value);
}
@attrs
}
Expand Down
4 changes: 2 additions & 2 deletions src/how/RoleToRoleApplier.pm
Expand Up @@ -21,7 +21,7 @@ knowhow RoleToRoleApplier {
}
}
unless $found {
@meth_list.push($meth);
nqp::push(@meth_list, $meth);
}
}
}
Expand Down Expand Up @@ -80,7 +80,7 @@ knowhow RoleToRoleApplier {

# Build up full list.
# XXX Not really right yet...
@all_roles.push($_);
nqp::push(@all_roles, $_);
}

return @all_roles;
Expand Down

0 comments on commit 4084b68

Please sign in to comment.