Skip to content

Commit

Permalink
Cope with ^method_table and ^submethod_table written in Perl 6
Browse files Browse the repository at this point in the history
When these meta model methods are written in Perl 6, they will return a Perl 6
map instead of a VMHash. Need to unwrap to be able to iterate in NQP.
  • Loading branch information
niner committed May 29, 2018
1 parent 091b752 commit 9684d1f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/Perl6/Metamodel/AttributeContainer.nqp
Expand Up @@ -25,6 +25,7 @@ role Perl6::Metamodel::AttributeContainer {
method compose_attributes($obj, :$compiler_services) {
my %seen_with_accessor;
my %meths := self.method_table($obj);
%meths := %meths.FLATTENABLE_HASH() unless nqp::ishash(%meths);
my %orig_meths;
for %meths {
%orig_meths{$_.key} := 1;
Expand Down
8 changes: 5 additions & 3 deletions src/Perl6/Metamodel/MROBasedMethodDispatch.nqp
Expand Up @@ -63,16 +63,18 @@ role Perl6::Metamodel::MROBasedMethodDispatch {
@mro_reversed.unshift($_);
}
for @mro_reversed {
for $_.HOW.method_table($_) {
%cache{$_.key} := $_.value;
my $method_table := $_.HOW.method_table($_);
for nqp::ishash($method_table) ?? $method_table !! $method_table.FLATTENABLE_HASH() {
%cache{$_.key} := nqp::decont($_.value);
}
if nqp::can($_.HOW, 'is_composed') && !$_.HOW.is_composed($_) {
$authable := 0;
}
}

# Also add submethods.
for $obj.HOW.submethod_table($obj) {
my $submethod_table := $obj.HOW.submethod_table($obj);
for nqp::ishash($submethod_table) ?? $submethod_table !! $submethod_table.FLATTENABLE_HASH() {
%cache{$_.key} := $_.value;
}

Expand Down
16 changes: 10 additions & 6 deletions src/Perl6/Metamodel/MethodContainer.nqp
Expand Up @@ -52,11 +52,13 @@ role Perl6::Metamodel::MethodContainer {
# If local flag was not passed, include those from parents.
unless $local {
for self.parents($obj, :all($all), :excl($excl)) {
for $_.HOW.method_table($_) {
@meths.push(nqp::hllizefor($_.value, 'perl6'));
my %method_table := $_.HOW.method_table($_);
for nqp::ishash(%method_table) ?? %method_table !! %method_table.FLATTENABLE_HASH {
@meths.push(nqp::hllizefor(nqp::decont($_.value), 'perl6'));
}
for $_.HOW.submethod_table($_) {
@meths.push(nqp::hllizefor($_.value, 'perl6'));
my %submethod_table := $_.HOW.submethod_table($_);
for nqp::ishash(%submethod_table) ?? %submethod_table !! %submethod_table.FLATTENABLE_HASH {
@meths.push(nqp::hllizefor(nqp::decont($_.value), 'perl6'));
}
}
}
Expand Down Expand Up @@ -86,13 +88,15 @@ role Perl6::Metamodel::MethodContainer {
method lookup($obj, $name) {
for self.mro($obj) {
my %meth := $_.HOW.method_table($obj);
%meth := %meth.FLATTENABLE_HASH unless nqp::ishash(%meth);
if nqp::existskey(%meth, $name) {
return %meth{$name};
return nqp::decont(%meth{$name});
}
if nqp::can($_.HOW, 'submethod_table') {
my %submeth := $_.HOW.submethod_table($obj);
%submeth := %submeth.FLATTENABLE_HASH unless nqp::ishash(%submeth);
if nqp::existskey(%submeth, $name) {
return %submeth{$name};
return nqp::decont(%submeth{$name});
}
}
}
Expand Down

0 comments on commit 9684d1f

Please sign in to comment.