diff --git a/src/main.c b/src/main.c index d234164c..30336bcb 100644 --- a/src/main.c +++ b/src/main.c @@ -4,6 +4,7 @@ #include "utils/utf.h" #include "utils/file.h" #include "utils/time.h" +#include "utils/interrupt.h" static B replPath; static Scope* gsc; diff --git a/src/utils/interrupt.h b/src/utils/interrupt.h new file mode 100644 index 00000000..0ddffa69 --- /dev/null +++ b/src/utils/interrupt.h @@ -0,0 +1,14 @@ +#pragma once +#if REPL_INTERRUPT && !__has_include() + #undef REPL_INTERRUPT +#endif + +bool cbqn_takeInterrupts(bool b); + +#if REPL_INTERRUPT +extern volatile int cbqn_interrupted; +NOINLINE NORETURN void cbqn_onInterrupt(); +#define CHECK_INTERRUPT ({ if (cbqn_interrupted) cbqn_onInterrupt(); }) +#else +#define CHECK_INTERRUPT +#endif \ No newline at end of file diff --git a/src/vm.c b/src/vm.c index feb59bb6..c7f1a473 100644 --- a/src/vm.c +++ b/src/vm.c @@ -5,6 +5,7 @@ #include "utils/utf.h" #include "utils/talloc.h" #include "utils/mut.h" +#include "utils/interrupt.h" #ifndef UNWIND_COMPILER // whether to hide stackframes of the compiler in compiling errors #define UNWIND_COMPILER 1 @@ -843,10 +844,9 @@ B mnvmExecBodyInline(Body* body, Scope* sc) { -#if __has_include() && REPL_INTERRUPT -volatile int cbqn_interrupted; +#if REPL_INTERRUPT #include -bool cbqn_takeInterrupts(bool b); +volatile int cbqn_interrupted; static void interrupt_sigHandler(int x) { if (cbqn_interrupted) abort(); // shouldn't happen cbqn_takeInterrupts(false); @@ -863,10 +863,8 @@ NOINLINE NORETURN void cbqn_onInterrupt() { cbqn_interrupted = 0; thrM("interrupted"); } -#define CHECK_INTERRUPT ({ if (cbqn_interrupted) cbqn_onInterrupt(); }) #else bool cbqn_takeInterrupts(bool b) { return false; } -#define CHECK_INTERRUPT #endif diff --git a/src/vm.h b/src/vm.h index 26eb979c..1f84d51f 100644 --- a/src/vm.h +++ b/src/vm.h @@ -236,7 +236,6 @@ NOINLINE B vm_fmtPoint(B src, B prepend, B path, usz cs, usz ce); // consumes pr NOINLINE void printErrMsg(B msg); NOINLINE void unwindEnv(Env* envNew); // envNew==envStart-1 for emptying the env stack NOINLINE void unwindCompiler(void); // unwind to the env of the invocation of the compiler; UB when not in compiler! -bool cbqn_takeInterrupts(bool b); usz getPageSize(void); diff --git a/test/moreCfgs.sh b/test/moreCfgs.sh index 9b78a6ef..088d34fb 100755 --- a/test/moreCfgs.sh +++ b/test/moreCfgs.sh @@ -25,3 +25,5 @@ make f='-DLOG_GC' c && ./BQN -p 2+2 || exit make f='-DWRITE_ASM' c && ./BQN -p 2+2 || exit make f='-DUSE_PERF' c && ./BQN -p 2+2 || exit make f='-DUSZ_64' c && ./BQN -p 2+2 || exit +make f='-DREPL_INTERRUPT=0' c && ./BQN -p 2+2 || exit +make f='-DREPL_INTERRUPT=1' c && ./BQN -p 2+2 || exit