Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Attribute ordering matters; don't use a hash.
  • Loading branch information
jnthn committed Feb 27, 2013
1 parent 0968572 commit 361feca
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
16 changes: 9 additions & 7 deletions src/how/NQPClassHOW.pm
Expand Up @@ -11,7 +11,7 @@ knowhow NQPClassHOW {
has $!name;

# Attributes, methods, parents and roles directly added.
has %!attributes;
has @!attributes;
has %!methods;
has @!method_order;
has @!multi_methods_to_incorporate;
Expand Down Expand Up @@ -65,7 +65,7 @@ knowhow NQPClassHOW {

method BUILD(:$name = '<anon>') {
$!name := $name;
%!attributes := nqp::hash();
@!attributes := nqp::list();
%!methods := nqp::hash();
@!method_order := nqp::list();
@!multi_methods_to_incorporate := nqp::list();
Expand Down Expand Up @@ -119,10 +119,12 @@ knowhow NQPClassHOW {

method add_attribute($obj, $meta_attr) {
my $name := $meta_attr.name;
if nqp::existskey(%!attributes, $name) {
nqp::die("This class already has an attribute named " ~ $name);
for @!attributes {
if $_.name eq $name {
nqp::die("This class already has an attribute named " ~ $name);
}
}
%!attributes{$name} := $meta_attr;
nqp::push(@!attributes, $meta_attr);
}

method add_parent($obj, $parent) {
Expand Down Expand Up @@ -630,8 +632,8 @@ knowhow NQPClassHOW {
method attributes($obj, :$local = 0) {
my @attrs;
if $local {
for %!attributes {
nqp::push(@attrs, nqp::iterval($_));
for @!attributes {
nqp::push(@attrs, $_);
}
}
else {
Expand Down
16 changes: 9 additions & 7 deletions src/how/NQPConcreteRoleHOW.pm
Expand Up @@ -12,7 +12,7 @@ knowhow NQPConcreteRoleHOW {
has $!instance_of;

# Attributes and methods.
has %!attributes;
has @!attributes;
has %!methods;
has @!multi_methods_to_incorporate;
has @!collisions;
Expand Down Expand Up @@ -45,7 +45,7 @@ knowhow NQPConcreteRoleHOW {
method BUILD(:$name!, :$instance_of!) {
$!name := $name;
$!instance_of := $instance_of;
%!attributes := nqp::hash();
@!attributes := nqp::list();
%!methods := nqp::hash();
@!multi_methods_to_incorporate := nqp::list();
@!collisions := nqp::list();
Expand Down Expand Up @@ -78,10 +78,12 @@ knowhow NQPConcreteRoleHOW {

method add_attribute($obj, $meta_attr) {
my $name := $meta_attr.name;
if nqp::existskey(%!attributes, $name) {
nqp::die("This role already has an attribute named " ~ $name);
for @!attributes {
if $_.name eq $name {
nqp::die("This role already has an attribute named " ~ $name);
}
}
%!attributes{$name} := $meta_attr;
nqp::push(@!attributes, $meta_attr);
}

method add_parent($obj, $parent) {
Expand Down Expand Up @@ -143,8 +145,8 @@ knowhow NQPConcreteRoleHOW {

method attributes($obj, :$local) {
my @attrs;
for %!attributes {
nqp::push(@attrs, nqp::iterval($_));
for @!attributes {
nqp::push(@attrs, $_);
}
@attrs
}
Expand Down
20 changes: 11 additions & 9 deletions src/how/NQPParametricRoleHOW.pm
Expand Up @@ -11,7 +11,7 @@ knowhow NQPParametricRoleHOW {
has $!name;

# Attributes and methods.
has %!attributes;
has @!attributes;
has %!methods;
has @!multi_methods_to_incorporate;

Expand Down Expand Up @@ -44,7 +44,7 @@ knowhow NQPParametricRoleHOW {

method BUILD(:$name!) {
$!name := $name;
%!attributes := nqp::hash();
@!attributes := nqp::list();
%!methods := nqp::hash();
@!multi_methods_to_incorporate := nqp::list();
@!roles := nqp::list();
Expand Down Expand Up @@ -79,10 +79,12 @@ knowhow NQPParametricRoleHOW {

method add_attribute($obj, $meta_attr) {
my $name := $meta_attr.name;
if nqp::existskey(%!attributes, $name) {
nqp::die("This role already has an attribute named " ~ $name);
for @!attributes {
if $_.name eq $name {
nqp::die("This role already has an attribute named " ~ $name);
}
}
%!attributes{$name} := $meta_attr;
nqp::push(@!attributes, $meta_attr);
}

method add_parent($obj, $parent) {
Expand Down Expand Up @@ -129,8 +131,8 @@ knowhow NQPParametricRoleHOW {

# Copy attributes. (Nothing to reify in NQP as we don't currently
# have parametric types that may end up in the signature.)
for %!attributes {
$irole.HOW.add_attribute($irole, nqp::iterval($_));
for @!attributes {
$irole.HOW.add_attribute($irole, $_);
}

# Capture methods in the correct lexical context.
Expand Down Expand Up @@ -182,8 +184,8 @@ knowhow NQPParametricRoleHOW {

method attributes($obj, :$local) {
my @attrs;
for %!attributes {
nqp::push(@attrs, nqp::iterval($_));
for @!attributes {
nqp::push(@attrs, $_);
}
@attrs
}
Expand Down

0 comments on commit 361feca

Please sign in to comment.