move interrupt check to its own header

This commit is contained in:
dzaima 2022-06-03 16:02:02 +03:00
parent 7a21f9ef73
commit 572bc04459
5 changed files with 20 additions and 6 deletions

View File

@ -4,6 +4,7 @@
#include "utils/utf.h" #include "utils/utf.h"
#include "utils/file.h" #include "utils/file.h"
#include "utils/time.h" #include "utils/time.h"
#include "utils/interrupt.h"
static B replPath; static B replPath;
static Scope* gsc; static Scope* gsc;

14
src/utils/interrupt.h Normal file
View File

@ -0,0 +1,14 @@
#pragma once
#if REPL_INTERRUPT && !__has_include(<signal.h>)
#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

View File

@ -5,6 +5,7 @@
#include "utils/utf.h" #include "utils/utf.h"
#include "utils/talloc.h" #include "utils/talloc.h"
#include "utils/mut.h" #include "utils/mut.h"
#include "utils/interrupt.h"
#ifndef UNWIND_COMPILER // whether to hide stackframes of the compiler in compiling errors #ifndef UNWIND_COMPILER // whether to hide stackframes of the compiler in compiling errors
#define UNWIND_COMPILER 1 #define UNWIND_COMPILER 1
@ -843,10 +844,9 @@ B mnvmExecBodyInline(Body* body, Scope* sc) {
#if __has_include(<signal.h>) && REPL_INTERRUPT #if REPL_INTERRUPT
volatile int cbqn_interrupted;
#include <signal.h> #include <signal.h>
bool cbqn_takeInterrupts(bool b); volatile int cbqn_interrupted;
static void interrupt_sigHandler(int x) { static void interrupt_sigHandler(int x) {
if (cbqn_interrupted) abort(); // shouldn't happen if (cbqn_interrupted) abort(); // shouldn't happen
cbqn_takeInterrupts(false); cbqn_takeInterrupts(false);
@ -863,10 +863,8 @@ NOINLINE NORETURN void cbqn_onInterrupt() {
cbqn_interrupted = 0; cbqn_interrupted = 0;
thrM("interrupted"); thrM("interrupted");
} }
#define CHECK_INTERRUPT ({ if (cbqn_interrupted) cbqn_onInterrupt(); })
#else #else
bool cbqn_takeInterrupts(bool b) { return false; } bool cbqn_takeInterrupts(bool b) { return false; }
#define CHECK_INTERRUPT
#endif #endif

View File

@ -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 printErrMsg(B msg);
NOINLINE void unwindEnv(Env* envNew); // envNew==envStart-1 for emptying the env stack 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! 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); usz getPageSize(void);

View File

@ -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='-DWRITE_ASM' c && ./BQN -p 2+2 || exit
make f='-DUSE_PERF' 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='-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