Skip to content

Instantly share code, notes, and snippets.

@jnthn

jnthn/x.raku Secret

Created February 12, 2021 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnthn/b0e6a33f431ab177e971ae0869810584 to your computer and use it in GitHub Desktop.
Save jnthn/b0e6a33f431ab177e971ae0869810584 to your computer and use it in GitHub Desktop.
use nqp;
say "# Methods";
class C1 {
method m() { 'c1' }
method m2() { new-disp-callsame() }
}
class C2 is C1 {
method m() { 'c2' ~ new-disp-callsame() }
}
class C3 is C2 {
method m() { 'c3' ~ new-disp-callsame() }
}
class C4 is C3 {
method m() { 'c4' ~ new-disp-callsame() }
}
say nqp::dispatch('raku-meth-call', C1, 'm', C1);
say nqp::dispatch('raku-meth-call', C2, 'm', C2);
say nqp::dispatch('raku-meth-call', C3, 'm', C3);
say nqp::dispatch('raku-meth-call', C4, 'm', C4);
say nqp::dispatch('raku-meth-call', C1, 'm2', C1);
class C5 is C4 {
method m() { 'nc5' ~ new-disp-nextcallee()(self) }
}
class C6 is C5 {
method m() { 'nc6' ~ new-disp-nextcallee()(self) }
}
say nqp::dispatch('raku-meth-call', C5, 'm', C5);
say nqp::dispatch('raku-meth-call', C6, 'm', C6);
class C7 is C6 {
method m() { new-disp-lastcall(); new-disp-callsame() }
}
class C8 is C7 {
method m() { new-disp-callsame() }
}
say nqp::dispatch('raku-meth-call', C7, 'm', C7);
say nqp::dispatch('raku-meth-call', C8, 'm', C8);
say "# Wrapped subs";
sub inner() { 'i' }
say nqp::dispatch('raku-invoke', &inner);
my $w1 = &inner.new-disp-wrap({ 'w1' ~ new-disp-callsame() });
say nqp::dispatch('raku-invoke', &inner);
my $w2 = &inner.new-disp-wrap({ 'w2' ~ new-disp-nextcallee()() });
say nqp::dispatch('raku-invoke', &inner);
$w1.restore();
say nqp::dispatch('raku-invoke', &inner);
$w2.restore();
say nqp::dispatch('raku-invoke', &inner);
say "# Wrapped methods";
class WC0 {
method m() { 'm0' }
}
class WC1 is WC0 {
method m() { 'm1' ~ new-disp-callsame }
}
class WC2 is WC1 {
method m() { 'm2' ~ new-disp-callsame }
}
class WC3 is WC2 {
method m() { 'm3' ~ new-disp-callsame }
}
class WC4 is WC3 {
method m() { 'm4' ~ new-disp-callsame }
}
WC1.^lookup('m').new-disp-wrap({ 'wi1' ~ new-disp-callsame });
WC1.^lookup('m').new-disp-wrap({ 'wo1' ~ new-disp-callsame });
WC2.^lookup('m').new-disp-wrap({ 'wi2' ~ new-disp-callsame });
WC2.^lookup('m').new-disp-wrap({ 'wo2' ~ new-disp-callsame });
WC3.^lookup('m').new-disp-wrap({ 'wi3' ~ new-disp-callsame });
WC3.^lookup('m').new-disp-wrap({ 'wo3' ~ new-disp-callsame });
WC4.^lookup('m').new-disp-wrap({ 'wi4' ~ new-disp-callsame });
WC4.^lookup('m').new-disp-wrap({ 'wo4' ~ new-disp-callsame });
say nqp::dispatch('raku-meth-call', WC1, 'm', WC1);
say nqp::dispatch('raku-meth-call', WC2, 'm', WC2);
say nqp::dispatch('raku-meth-call', WC3, 'm', WC3);
say nqp::dispatch('raku-meth-call', WC4, 'm', WC4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment