Skip to content

Commit

Permalink
Introduce $*EXIT / $*EXCEPTION dynamic vars
Browse files Browse the repository at this point in the history
Basically the implementation of #5014
without a commit with a lot of noise.
  • Loading branch information
lizmat committed Jan 31, 2023
1 parent b21cd61 commit 5005086
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/core.c/Exception.pm6
Expand Up @@ -522,6 +522,8 @@ do {
sub print_exception(|) {
my Mu $ex := nqp::atpos(nqp::p6argvmarray(), 0);
my $e := EXCEPTION($ex);
$*EXIT = 1;
$*EXCEPTION = $e;

if %*ENV<PERL6_EXCEPTIONS_HANDLER> -> $handler {
my $class := ::("Exceptions::$handler");
Expand Down
3 changes: 3 additions & 0 deletions src/core.c/Rakudo/Internals.pm6
Expand Up @@ -1835,10 +1835,13 @@ my constant $?BITS = nqp::isgt_i(nqp::add_i(2147483648, 1), 0) ?? 64 !! 32;
}

# we need this to run *after* the mainline of Rakudo::Internals has run
PROCESS::<$EXIT> = 0;
PROCESS::<$EXCEPTION> = Exception;
Rakudo::Internals.REGISTER-DYNAMIC: '&*EXIT', {
PROCESS::<&EXIT> := sub exit($status) {
state $exit = $status; # first call to exit sets value

$*EXIT = $exit;
nqp::getcurhllsym('&THE_END')()
?? $exit
!! nqp::exit(nqp::unbox_i($exit.Int))
Expand Down
2 changes: 2 additions & 0 deletions t/08-performance/05-processkeys.t
Expand Up @@ -14,6 +14,8 @@ my $allowed = (
Q{$CORE-SETTING-REV},
Q{$DISTRO},
Q{$ERR},
Q{$EXCEPTION},
Q{$EXIT},
Q{$IN},
Q{$OUT},
Q{$PID},
Expand Down

0 comments on commit 5005086

Please sign in to comment.