From 500508664f787f8995ecd428a25b9f1a70314385 Mon Sep 17 00:00:00 2001 From: Elizabeth Mattijsen Date: Tue, 31 Jan 2023 13:26:25 +0100 Subject: [PATCH] Introduce $*EXIT / $*EXCEPTION dynamic vars Basically the implementation of https://github.com/rakudo/rakudo/pull/5014 without a commit with a lot of noise. --- src/core.c/Exception.pm6 | 2 ++ src/core.c/Rakudo/Internals.pm6 | 3 +++ t/08-performance/05-processkeys.t | 2 ++ 3 files changed, 7 insertions(+) diff --git a/src/core.c/Exception.pm6 b/src/core.c/Exception.pm6 index cf031aed5e7..76cc02d9886 100644 --- a/src/core.c/Exception.pm6 +++ b/src/core.c/Exception.pm6 @@ -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 -> $handler { my $class := ::("Exceptions::$handler"); diff --git a/src/core.c/Rakudo/Internals.pm6 b/src/core.c/Rakudo/Internals.pm6 index 932958bfe49..124af2897d9 100644 --- a/src/core.c/Rakudo/Internals.pm6 +++ b/src/core.c/Rakudo/Internals.pm6 @@ -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)) diff --git a/t/08-performance/05-processkeys.t b/t/08-performance/05-processkeys.t index 2774659b771..c8cbd64dca3 100644 --- a/t/08-performance/05-processkeys.t +++ b/t/08-performance/05-processkeys.t @@ -14,6 +14,8 @@ my $allowed = ( Q{$CORE-SETTING-REV}, Q{$DISTRO}, Q{$ERR}, + Q{$EXCEPTION}, + Q{$EXIT}, Q{$IN}, Q{$OUT}, Q{$PID},