Skip to content

Instantly share code, notes, and snippets.

@zoffixznet

zoffixznet/p6.p6 Secret

Last active Aug 1, 2018
Embed
What would you like to do?
multi sub trait_mod:<is>(Method:D $m, :$strict) is export {
use nqp;
use QAST:from<NQP>;
nqp::pop(nqp::getattr($m.signature,Signature,'@!params'));
my $pad := nqp::atpos($*W.cur_lexpad, 0);
my int $els = nqp::elems($pad);
my int $i = -1;
nqp::while(
++$i < $els,
nqp::stmts(
(my $val := nqp::atpos($pad, $i)),
nqp::if(
nqp::istype($val, QAST::Block)
&& ! $val.has_ann('is-strict'),
nqp::stmts(
($i = $els),
$val.annotate('is-strict', 0),
remove-slurpy(nqp::atpos($val,0))))));
sub remove-slurpy(Mu $pad is raw) {
my int $els = nqp::elems($pad);
my int $i = -1;
nqp::while(
++$i < $els,
nqp::stmts(
(my $val := nqp::atpos($pad, $i)),
nqp::if(
nqp::istype($val, QAST::Var)
&& $val.name && $val.name eq '%_',
nqp::stmts(
nqp::bindpos($pad, $i, QAST::Op.new: :op<null>),
($i = $els)))));
}
}
class Foo {
method z()
is strict
{
say MY::.keys
}
method y()
is strict
{
say MY::.keys
}
}.new.z
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment