Skip to content

Commit

Permalink
Refactor METAOP_ASSIGN_NEW
Browse files Browse the repository at this point in the history
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 90ac094
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions 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()) }
Expand Down

2 comments on commit 90ac094

@b2gills
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor Author

@lizmat lizmat commented on 90ac094 Nov 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.