Skip to content

Commit

Permalink
Merge pull request #4769 from vrurg/problem-solving-311
Browse files Browse the repository at this point in the history
Turn junctions into value objects
  • Loading branch information
vrurg committed Feb 13, 2022
2 parents 771655b + cc3ed94 commit b67d38c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Perl6/bootstrap.c/BOOTSTRAP.nqp
Expand Up @@ -3775,6 +3775,7 @@ BEGIN {
Junction.HOW.add_parent(Junction, Mu);
Junction.HOW.add_attribute(Junction, scalar_attr('$!eigenstates', Mu, Junction));
Junction.HOW.add_attribute(Junction, scalar_attr('$!type', str, Junction));
Junction.HOW.add_attribute(Junction, Attribute.new(:name<$!WHICH>, :type(ValueObjAt), :package(Junction)));
Junction.HOW.compose_repr(Junction);

# class Bool is Int {
Expand Down
16 changes: 16 additions & 0 deletions src/core.c/Junction.pm6
Expand Up @@ -176,6 +176,22 @@ my class Junction { # declared in BOOTSTRAP
)
}

multi method WHICH(Junction:D: --> ValueObjAt:D) {
nqp::if(
nqp::defined($!WHICH),
$!WHICH,
($!WHICH := nqp::box_s(
nqp::concat(
nqp::if(
nqp::eqaddr(self.WHAT, Junction),
'Junction|',
nqp::concat(nqp::unbox_s(self.^name), '|')
),
nqp::sha1(self.gist)
),
ValueObjAt )));
}

multi method ACCEPTS(Junction:U: Junction:D --> True) { }
multi method ACCEPTS(Junction:D \SELF: Junction:D \topic) {
topic.BOOLIFY-ACCEPTS(self)
Expand Down

0 comments on commit b67d38c

Please sign in to comment.