Skip to content
Permalink
Browse files

Cache METAOP_ASSIGN ops

Not to specifically to make it faster, but to be able to assign a name
to the generated block without incurring a runtime penalty for that.
The name will allow metaoperators to introspect and optimize >>+=>> with
about a factor of 2.

Pushed as a separate commit for bisecting.
  • Loading branch information...
lizmat committed Nov 15, 2018
1 parent c3f03e6 commit 1ed2b098ebba2c825fd973500f4b830e65e4f2ac
Showing with 14 additions and 1 deletion.
  1. +14 −1 src/core/metaops.pm6
@@ -1,6 +1,19 @@

my $METAOP_ASSIGN := nqp::hash;
sub METAOP_ASSIGN(\op) {
-> Mu \a, Mu \b { a = op.( ( a.DEFINITE ?? a !! op.() ), b) }
nqp::ifnull(
nqp::atkey($METAOP_ASSIGN,op.name),
METAOP_ASSIGN_NEW(op)
)
}
sub METAOP_ASSIGN_NEW(\op) {
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
))
}

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

0 comments on commit 1ed2b09

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