use nqp;
# for proper R5RS semantics, run this once wrapping your main function
sub run_main($f) {
nqp::continuationreset(nqp::null(), $f);
}
sub callcc($f) {
# first get the current continuation
nqp::continuationcontrol(1, nqp::null(), -> $dcont {
my $scheme_cont := -> $val {
# when the scheme continuation is invoked, we need to *replace*
# the current continuation with this one
nqp::continuationcontrol(1, nqp::null(), -> $c {
nqp::continuationinvoke($dcont, { $val })
});
};
nqp::continuationinvoke($dcont, { $f($scheme_cont) });
});
}
run_main {
say "hello";
}