Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Switch Array/Hash to use method ^parameterize.
  • Loading branch information
jnthn committed Mar 12, 2015
1 parent 699f9b0 commit 976eeaf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
9 changes: 4 additions & 5 deletions src/core/Array.pm
Expand Up @@ -230,16 +230,15 @@ class Array { # declared in BOOTSTRAP
}
# XXX some methods to come here...
}
method PARAMETERIZE_TYPE(Mu $t, |c) {
method ^parameterize(Mu \arr, Mu \t, |c) {
if c.elems == 0 {
# my $what := self but TypedArray[$t.WHAT]; # too early in bootstrap
my $what := self.HOW.mixin(self.WHAT, TypedArray[$t.WHAT]);
my $what := arr.HOW.mixin(arr.WHAT, TypedArray[t.WHAT]);
# needs to be done in COMPOSE phaser when that works
$what.HOW.set_name(self,"{self.HOW.name(self)}[{$t.HOW.name($t)}]");
$what.HOW.set_name(arr, "{arr.HOW.name(arr)}[{t.HOW.name(t)}]");
$what;
}
else {
die "Can only type-constraint Array with [ValueType]"
die "Can only type-constrain Array with [ValueType]"
}
}
multi method ACCEPTS(Array:D: $topic) {
Expand Down
14 changes: 6 additions & 8 deletions src/core/Hash.pm
Expand Up @@ -423,23 +423,21 @@ my class Hash { # declared in BOOTSTRAP
}

}
method PARAMETERIZE_TYPE(Mu $t, |c) {
method ^parameterize(Mu \hash, Mu \t, |c) {
if c.elems == 0 {
# my $what := self but TypedHash[$t.WHAT]; # too early in bootstrap
my $what := self.HOW.mixin(self.WHAT, TypedHash[$t.WHAT]);
my $what := hash.HOW.mixin(hash.WHAT, TypedHash[t.WHAT]);
# needs to be done in COMPOSE phaser when that works
$what.HOW.set_name(self,"{self.HOW.name(self)}[{$t.HOW.name($t)}]");
$what.HOW.set_name(self, "{hash.HOW.name(hash)}[{t.HOW.name(t)}]");
$what;
}
elsif c.elems == 1 {
my $what := self.HOW.mixin(self.WHAT, TypedHash[$t.WHAT,c[0]]);
# my $what := self but TypedHash[$t.WHAT, c[0]]; # too early in bootstrap
my $what := hash.HOW.mixin(hash.WHAT, TypedHash[t.WHAT, c[0]]);
# needs to be done in COMPOSE phaser when that works
$what.HOW.set_name(self,"{self.HOW.name(self)}[{$t.HOW.name($t)},{c[0].HOW.name(c[0])}]");
$what.HOW.set_name(hash, "{hash.HOW.name(hash)}[{t.HOW.name(t)},{c[0].HOW.name(c[0])}]");
$what;
}
else {
die "Can only type-constraint Hash with [ValueType] or [ValueType,KeyType]";
die "Can only type-constrain Hash with [ValueType] or [ValueType,KeyType]";
}
}
}
Expand Down

0 comments on commit 976eeaf

Please sign in to comment.