From 4a316c9398135127632842316786e38f1b67d66d Mon Sep 17 00:00:00 2001 From: dzaima Date: Wed, 6 Apr 2022 18:52:09 +0300 Subject: [PATCH] don't include setjmp.h when CATCH_ERRORS=0 --- src/builtins/sysfn.c | 5 +++-- src/h.h | 4 +++- src/singeli/src/dyarith.singeli | 2 ++ src/vm.c | 12 ++++++++++-- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/builtins/sysfn.c b/src/builtins/sysfn.c index c02c8adf..89698f46 100644 --- a/src/builtins/sysfn.c +++ b/src/builtins/sysfn.c @@ -1,7 +1,7 @@ #include #include #include -#include + #include "../core.h" #include "../utils/hash.h" @@ -758,9 +758,10 @@ B fromUtf8_c1(B t, B x) { extern char** environ; -#if __has_include() +#if __has_include() && __has_include() #include #include +#include typedef struct pollfd pollfd; void shClose(int fd) { if (close(fd)) err("bad file descriptor close"); } diff --git a/src/h.h b/src/h.h index 95a1fba7..f792ff8b 100644 --- a/src/h.h +++ b/src/h.h @@ -70,7 +70,9 @@ #include #include #include +#if CATCH_ERRORS #include +#endif #ifdef HEAP_VERIFY #undef CATCH_ERRORS #define CATCH_ERRORS 0 @@ -342,8 +344,8 @@ NOINLINE NORETURN void rethrow(); NOINLINE NORETURN void thrM(char* s); NOINLINE NORETURN void thrF(char* s, ...); NOINLINE NORETURN void thrOOM(void); -jmp_buf* prepareCatch(void); #if CATCH_ERRORS +jmp_buf* prepareCatch(void); #define CATCH setjmp(*prepareCatch()) // use as `if (CATCH) { /*handle error*/ freeThrown(); return; } /*potentially erroring thing*/ popCatch(); /*no errors yay*/` #else // note: popCatch() must always be called if no error was caught, so no returns before it! #define CATCH false diff --git a/src/singeli/src/dyarith.singeli b/src/singeli/src/dyarith.singeli index 1c1d3514..84bf26e6 100644 --- a/src/singeli/src/dyarith.singeli +++ b/src/singeli/src/dyarith.singeli @@ -1,6 +1,7 @@ include './base' include './f64' include './cbqnDefs' +include './sse3' include './avx' include './avx2' include './bitops' @@ -59,6 +60,7 @@ def arithChk2{F, M, w:T, x:T, i & match{F,__mul} & isvec{T} & i32==eltype{T}} = f32mul:= cf32{w} * cf32{x} tup{w*x, any{M{cast_v{[8]u32, emit{[8]f32, '_mm256_cmp_ps', abs{f32mul}, max, 29}}}}} # TODO fallback to the below if the above fails + # TODO don't do this, but instead shuffle one half, do math, unshuffle that half # def wp = unpackQ{w, broadcast{T, 0}} # def xp = unpackQ{x, broadcast{T, 0}} # def rp = each{__mul32, wp, xp} diff --git a/src/vm.c b/src/vm.c index 356b558d..85097c52 100644 --- a/src/vm.c +++ b/src/vm.c @@ -1076,9 +1076,10 @@ void comp_init() { - typedef struct CatchFrame { - jmp_buf jmp; + #if CATCH_ERRORS + jmp_buf jmp; + #endif u64 gsDepth; u64 envDepth; u64 cfDepth; @@ -1087,6 +1088,7 @@ CatchFrame* cf; // points to after end CatchFrame* cfStart; CatchFrame* cfEnd; +#if CATCH_ERRORS jmp_buf* prepareCatch() { // in the case of returning false, must call popCatch(); if (cf==cfEnd) { u64 n = cfEnd-cfStart; @@ -1101,6 +1103,8 @@ jmp_buf* prepareCatch() { // in the case of returning false, must call popCatch( cf->envDepth = (envCurr+1)-envStart; return &(cf++)->jmp; } +#endif + void popCatch() { #if CATCH_ERRORS assert(cf>cfStart); @@ -1225,6 +1229,7 @@ NOINLINE NORETURN void throwImpl(bool rethrow) { // printf("gStack %p-%p:\n", gStackStart, gStack); B* c = gStack; // while (c>gStackStart) { print(*--c); putchar('\n'); } printf("gStack printed\n"); +#if CATCH_ERRORS if (cf>cfStart) { // something wants to catch errors cf--; @@ -1239,6 +1244,7 @@ NOINLINE NORETURN void throwImpl(bool rethrow) { cf = cfStart+cf->cfDepth; longjmp(cf->jmp, 1); } else { // uncaught error +#endif assert(cf==cfStart); fprintf(stderr, "Error: "); printErrMsg(thrownMsg); fputc('\n',stderr); fflush(stderr); Env* envEnd = envCurr+1; @@ -1249,7 +1255,9 @@ NOINLINE NORETURN void throwImpl(bool rethrow) { #else exit(1); #endif +#if CATCH_ERRORS } +#endif } NOINLINE NORETURN void thr(B msg) {