Skip to content

Commit

Permalink
Streamline Metamodel::Trusting
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Feb 27, 2024
1 parent 192d7d0 commit 3271329
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/Perl6/Metamodel/Trusting.nqp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#- Metamodel::Trusting ---------------------------------------------------------
# Implements managing trust relationships between types.
role Perl6::Metamodel::Trusting {
# Who do we trust?
has @!trustees;

# Adds a type that we trust.
method add_trustee($XXX, $trustee) {
@!trustees[+@!trustees] := $trustee;
nqp::push(@!trustees, $trustee);
}

# Introspect the types that we trust.
Expand All @@ -14,15 +15,21 @@ role Perl6::Metamodel::Trusting {
# Checks if we trust a certain type. Can be used by the compiler
# to check if a private call is allowable.
method is_trusted($target, $claimant) {
my $WHAT := $claimant.WHAT;

# Always trust ourself.
if $claimant.WHAT =:= $target.WHAT {
return 1;
}
return 1 if nqp::eqaddr($target.WHAT, $WHAT);

# Otherwise, look through our trustee list.
for @!trustees {
if $_.WHAT =:= $claimant.WHAT {
return 1;
if nqp::elems(@!trustees) {
my @trustees := @!trustees;

my int $m := nqp::elems(@trustees);
my int $i;
while $i < $m {
nqp::eqaddr(nqp::atpos(@trustees, $i).WHAT, $WHAT)
?? (return 1)
!! ++$i;
}
}

Expand Down

0 comments on commit 3271329

Please sign in to comment.