Skip to content

Commit 361feca

Browse files
committed
Attribute ordering matters; don't use a hash.
1 parent 0968572 commit 361feca

File tree

3 files changed

+29
-23
lines changed

3 files changed

+29
-23
lines changed

src/how/NQPClassHOW.pm

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ knowhow NQPClassHOW {
1111
has $!name;
1212

1313
# Attributes, methods, parents and roles directly added.
14-
has %!attributes;
14+
has @!attributes;
1515
has %!methods;
1616
has @!method_order;
1717
has @!multi_methods_to_incorporate;
@@ -65,7 +65,7 @@ knowhow NQPClassHOW {
6565

6666
method BUILD(:$name = '<anon>') {
6767
$!name := $name;
68-
%!attributes := nqp::hash();
68+
@!attributes := nqp::list();
6969
%!methods := nqp::hash();
7070
@!method_order := nqp::list();
7171
@!multi_methods_to_incorporate := nqp::list();
@@ -119,10 +119,12 @@ knowhow NQPClassHOW {
119119

120120
method add_attribute($obj, $meta_attr) {
121121
my $name := $meta_attr.name;
122-
if nqp::existskey(%!attributes, $name) {
123-
nqp::die("This class already has an attribute named " ~ $name);
122+
for @!attributes {
123+
if $_.name eq $name {
124+
nqp::die("This class already has an attribute named " ~ $name);
125+
}
124126
}
125-
%!attributes{$name} := $meta_attr;
127+
nqp::push(@!attributes, $meta_attr);
126128
}
127129

128130
method add_parent($obj, $parent) {
@@ -630,8 +632,8 @@ knowhow NQPClassHOW {
630632
method attributes($obj, :$local = 0) {
631633
my @attrs;
632634
if $local {
633-
for %!attributes {
634-
nqp::push(@attrs, nqp::iterval($_));
635+
for @!attributes {
636+
nqp::push(@attrs, $_);
635637
}
636638
}
637639
else {

src/how/NQPConcreteRoleHOW.pm

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ knowhow NQPConcreteRoleHOW {
1212
has $!instance_of;
1313

1414
# Attributes and methods.
15-
has %!attributes;
15+
has @!attributes;
1616
has %!methods;
1717
has @!multi_methods_to_incorporate;
1818
has @!collisions;
@@ -45,7 +45,7 @@ knowhow NQPConcreteRoleHOW {
4545
method BUILD(:$name!, :$instance_of!) {
4646
$!name := $name;
4747
$!instance_of := $instance_of;
48-
%!attributes := nqp::hash();
48+
@!attributes := nqp::list();
4949
%!methods := nqp::hash();
5050
@!multi_methods_to_incorporate := nqp::list();
5151
@!collisions := nqp::list();
@@ -78,10 +78,12 @@ knowhow NQPConcreteRoleHOW {
7878

7979
method add_attribute($obj, $meta_attr) {
8080
my $name := $meta_attr.name;
81-
if nqp::existskey(%!attributes, $name) {
82-
nqp::die("This role already has an attribute named " ~ $name);
81+
for @!attributes {
82+
if $_.name eq $name {
83+
nqp::die("This role already has an attribute named " ~ $name);
84+
}
8385
}
84-
%!attributes{$name} := $meta_attr;
86+
nqp::push(@!attributes, $meta_attr);
8587
}
8688

8789
method add_parent($obj, $parent) {
@@ -143,8 +145,8 @@ knowhow NQPConcreteRoleHOW {
143145

144146
method attributes($obj, :$local) {
145147
my @attrs;
146-
for %!attributes {
147-
nqp::push(@attrs, nqp::iterval($_));
148+
for @!attributes {
149+
nqp::push(@attrs, $_);
148150
}
149151
@attrs
150152
}

src/how/NQPParametricRoleHOW.pm

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ knowhow NQPParametricRoleHOW {
1111
has $!name;
1212

1313
# Attributes and methods.
14-
has %!attributes;
14+
has @!attributes;
1515
has %!methods;
1616
has @!multi_methods_to_incorporate;
1717

@@ -44,7 +44,7 @@ knowhow NQPParametricRoleHOW {
4444

4545
method BUILD(:$name!) {
4646
$!name := $name;
47-
%!attributes := nqp::hash();
47+
@!attributes := nqp::list();
4848
%!methods := nqp::hash();
4949
@!multi_methods_to_incorporate := nqp::list();
5050
@!roles := nqp::list();
@@ -79,10 +79,12 @@ knowhow NQPParametricRoleHOW {
7979

8080
method add_attribute($obj, $meta_attr) {
8181
my $name := $meta_attr.name;
82-
if nqp::existskey(%!attributes, $name) {
83-
nqp::die("This role already has an attribute named " ~ $name);
82+
for @!attributes {
83+
if $_.name eq $name {
84+
nqp::die("This role already has an attribute named " ~ $name);
85+
}
8486
}
85-
%!attributes{$name} := $meta_attr;
87+
nqp::push(@!attributes, $meta_attr);
8688
}
8789

8890
method add_parent($obj, $parent) {
@@ -129,8 +131,8 @@ knowhow NQPParametricRoleHOW {
129131

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

136138
# Capture methods in the correct lexical context.
@@ -182,8 +184,8 @@ knowhow NQPParametricRoleHOW {
182184

183185
method attributes($obj, :$local) {
184186
my @attrs;
185-
for %!attributes {
186-
nqp::push(@attrs, nqp::iterval($_));
187+
for @!attributes {
188+
nqp::push(@attrs, $_);
187189
}
188190
@attrs
189191
}

0 commit comments

Comments
 (0)