Skip to content

Commit

Permalink
Don't use integer in definite type parameterization
Browse files Browse the repository at this point in the history
It was working on MoarVM for a pure accidental reasons.
  • Loading branch information
vrurg committed Oct 20, 2022
1 parent 4d43bbf commit 07164fe
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions src/Perl6/Metamodel/DefiniteHOW.nqp
Expand Up @@ -2,14 +2,28 @@ class Perl6::Metamodel::DefiniteHOW
does Perl6::Metamodel::Documenting
does Perl6::Metamodel::Nominalizable
{
# Use coercive and generic flags as bits of a binary representation of the array index
my @archetypes := nqp::list(
Perl6::Metamodel::Archetypes.new(:definite, :nominalizable, :!coercive, :!generic),
Perl6::Metamodel::Archetypes.new(:definite, :nominalizable, :!coercive, :generic),
Perl6::Metamodel::Archetypes.new(:definite, :nominalizable, :coercive, :!generic),
Perl6::Metamodel::Archetypes.new(:definite, :nominalizable, :coercive, :generic));
# ATypeN are used as parameterization arguments to have a definite report correct archetypes.
my class AType0 {
my $type := Perl6::Metamodel::Archetypes.new(:definite, :nominalizable, :!coercive, :!generic);
method archetype() { $type }
}
my class AType1 {
my $type := Perl6::Metamodel::Archetypes.new(:definite, :nominalizable, :!coercive, :generic);
method archetype() { $type }
}
my class AType2 {
my $type := Perl6::Metamodel::Archetypes.new(:definite, :nominalizable, :coercive, :!generic);
method archetype() { $type }
}
my class AType3 {
my $type := Perl6::Metamodel::Archetypes.new(:definite, :nominalizable, :coercive, :generic);
method archetype() { $type }
}

method archetypes($definite_type = nqp::null()) {
@archetypes[ nqp::isnull($definite_type) ?? 0 !! nqp::typeparameterat(nqp::decont($definite_type), 2) ]
nqp::isnull($definite_type)
?? AType0.archetype()
!! nqp::typeparameterat(nqp::decont($definite_type), 2).archetype()
}

#~ has @!mro;
Expand All @@ -19,13 +33,14 @@ class Perl6::Metamodel::DefiniteHOW

method new_type(:$base_type!, :$definite!) {
my $base_archetypes := $base_type.HOW.archetypes($base_type);
# Use generic and coercive as positional bits in the @archetypes index value.
my $archetypes_idx :=
nqp::bitor_i(nqp::bitshiftl_i(nqp::istrue($base_archetypes.coercive), 1),
nqp::istrue($base_archetypes.generic));
# Use generic and coercive as positional bits to form a numeric suffix for 'ATypeN' names.
my $atype :=
nqp::getlexouter('AType' ~
nqp::bitor_i(nqp::bitshiftl_i(nqp::istrue($base_archetypes.coercive), 1),
nqp::istrue($base_archetypes.generic)));

my $root := nqp::parameterizetype((Perl6::Metamodel::DefiniteHOW.WHO)<root>,
[$base_type, $definite ?? Definite !! NotDefinite, $archetypes_idx]);
[$base_type, $definite ?? Definite !! NotDefinite, $atype]);
nqp::setdebugtypename($root, self.name($root));
}

Expand Down Expand Up @@ -77,7 +92,7 @@ class Perl6::Metamodel::DefiniteHOW
my $base_type := $definite_type.HOW.base_type($definite_type);
return $definite_type unless $base_type.HOW.archetypes($base_type).generic;
self.new_type(
base_type => $base_type.HOW.instantiate_generic($base_type, $type_env),
base_type => $base_type.HOW.instantiate_generic($base_type, $type_env),
definite => $definite_type.HOW.definite($definite_type))
}

Expand Down

0 comments on commit 07164fe

Please sign in to comment.