Skip to content
Permalink
Browse files

Refactor METAOP_ASSIGN_NEW

It now takes the name and the op, making things simpler and allows it to
also be used for priming.
  • Loading branch information...
lizmat committed Nov 15, 2018
1 parent 32ab0d3 commit 90ac0940aa2d94464f0c27aca034ea9118de6dc4
Showing with 15 additions and 15 deletions.
  1. +15 −15 src/core/metaops.pm6
@@ -1,25 +1,25 @@

my $METAOP_ASSIGN := nqp::hash;
sub METAOP_ASSIGN_NEW(\name, \op) {
nqp::if(
name,
nqp::stmts(
nqp::bindkey($METAOP_ASSIGN,name,op),
op.set_name(name.substr(0,*-1) ~ "=>"),
)
);
op
}

sub METAOP_ASSIGN(\op) {
nqp::ifnull(
nqp::atkey($METAOP_ASSIGN,op.name),
METAOP_ASSIGN_NEW(op)
METAOP_ASSIGN_NEW(
op.name,
-> Mu \a, Mu \b { a = op.((a.DEFINITE ?? a !! op.()), b) }
)
)
}
sub METAOP_ASSIGN_NEW(\op) {
# Fast path the case where there is *no* name for the op. If we *do* have
# a name, then we'll only be here once for that op, so it doesn't matter
# that we call op.name multiple times.
op.name
?? nqp::bindkey($METAOP_ASSIGN,op.name,nqp::stmts(
(my \metaop :=
-> Mu \a, Mu \b { a = op.((a.DEFINITE ?? a !! op.()), b) }
),
metaop.set_name(op.name.substr(0,*-1) ~ "=>"),
metaop
))
!! -> Mu \a, Mu \b { a = op.((a.DEFINITE ?? a !! op.()), b) }
}

sub METAOP_TEST_ASSIGN:<//>(\lhs, $rhs) is raw { lhs // (lhs = $rhs()) }
sub METAOP_TEST_ASSIGN:<||>(\lhs, $rhs) is raw { lhs || (lhs = $rhs()) }

2 comments on commit 90ac094

@b2gills

This comment has been minimized.

Copy link
Contributor

replied Nov 16, 2018

Note that just appending => to the name doesn't always work.

If the infix operator contains < or >, then the name ends with »

&[>=].name.say; # infix:«>=»
@lizmat

This comment has been minimized.

Copy link
Contributor Author

replied Nov 16, 2018

Well, this whole approach is now moot anyway, because we don't want to add a lot of overhead for each time we want to get a meta-op.

Please sign in to comment.
You can’t perform that action at this time.