Reorganize error functions and includes

These functions are complicated because they need to be marked
"noreturn" for the compiler. There are several fundamentally
incompatible ways of doing that. Since we have only a few "noreturn"
functions, let's just list all of those in one header file of which
there is a completely different version for each compiler.
This commit is contained in:
Lassi Kortela 2019-08-21 22:06:13 +03:00
parent debbcdf857
commit 60ff06fb6d
20 changed files with 99 additions and 28 deletions

View File

@ -28,6 +28,8 @@
#include "flisp.h" #include "flisp.h"
#include "error.h"
#include "argcount.h" #include "argcount.h"
#include "builtins.h" #include "builtins.h"

View File

@ -29,6 +29,8 @@
#include "flisp.h" #include "flisp.h"
#include "error.h"
#include "argcount.h" #include "argcount.h"
#include "libraries.h" #include "libraries.h"

View File

@ -1363,13 +1363,6 @@ int numeric_compare(value_t a, value_t b, int eq, int eqnans, char *fname)
return 1; return 1;
} }
STATIC_NORETURN(void, DivideByZeroError());
static void DivideByZeroError(void)
{
lerror(DivideError, "/: division by zero");
}
static value_t fl_div2(value_t a, value_t b) static value_t fl_div2(value_t a, value_t b)
{ {
double da, db; double da, db;

View File

@ -29,22 +29,6 @@ typedef double double_t;
#define BITS64 #define BITS64
#endif #endif
#ifdef __GNUC__
#define EXTERN_NORETURN(ret, args) extern ret args __attribute__((__noreturn__))
#define STATIC_NORETURN(ret, args) static ret args __attribute__((__noreturn__))
#endif
#ifdef _MSC_VER
#define EXTERN_NORETURN(ret, args) __declspec(noreturn) extern ret args
#define STATIC_NORETURN(ret, args) __declspec(noreturn) static ret args
#endif
#ifdef __WATCOMC__
#pragma aux noreturn aborts;
#define EXTERN_NORETURN(ret, args) extern ret __pragma("noreturn") args
#define STATIC_NORETURN(ret, args) static ret __pragma("noreturn") args
#endif
#define LLT_ALLOC(n) malloc(n) #define LLT_ALLOC(n) malloc(n)
#define LLT_REALLOC(p, n) realloc((p), (n)) #define LLT_REALLOC(p, n) realloc((p), (n))
#define LLT_FREE(x) free(x) #define LLT_FREE(x) free(x)

View File

@ -32,6 +32,8 @@
#include "flisp.h" #include "flisp.h"
#include "error.h"
#include "argcount.h" #include "argcount.h"
static const struct utsname *get_global_uname(void) static const struct utsname *get_global_uname(void)

15
c/error.h Normal file
View File

@ -0,0 +1,15 @@
#ifdef __DMC__
#include "error_dmc.h"
#endif
#ifdef __GNUC__
#include "error_gnuc.h"
#endif
#ifdef _MSC_VER
#include "error_msc.h"
#endif
#ifdef __WATCOMC__
#include "error_watcomc.h"
#endif

17
c/error_dmc.h Normal file
View File

@ -0,0 +1,17 @@
extern void DivideByZeroError(void);
#pragma noreturn(DivideByZeroError)
extern void lerrorf(value_t e, char *format, ...);
#pragma noreturn(lerrorf)
extern void lerror(value_t e, const char *msg);
#pragma noreturn(lerror)
extern void fl_raise(value_t e);
#pragma noreturn(fl_raise)
extern void type_error(char *fname, char *expected, value_t got);
#pragma noreturn(type_error)
extern void bounds_error(char *fname, value_t arr, value_t ind);
#pragma noreturn(bounds_error)

13
c/error_gnuc.h Normal file
View File

@ -0,0 +1,13 @@
void DivideByZeroError(void) __attribute__((__noreturn__));
void lerrorf(value_t e, char *format, ...) __attribute__((__noreturn__));
void lerror(value_t e, const char *msg) __attribute__((__noreturn__));
void fl_raise(value_t e) __attribute__((__noreturn__));
void type_error(char *fname, char *expected, value_t got)
__attribute__((__noreturn__));
void bounds_error(char *fname, value_t arr, value_t ind)
__attribute__((__noreturn__));

13
c/error_msc.h Normal file
View File

@ -0,0 +1,13 @@
__declspec(noreturn) extern void DivideByZeroError(void);
__declspec(noreturn) extern void lerrorf(value_t e, char *format, ...);
__declspec(noreturn) extern void lerror(value_t e, const char *msg);
__declspec(noreturn) extern void fl_raise(value_t e);
__declspec(noreturn) extern void type_error(char *fname, char *expected,
value_t got);
__declspec(noreturn) extern void bounds_error(char *fname, value_t arr,
value_t ind);

17
c/error_watcomc.h Normal file
View File

@ -0,0 +1,17 @@
#pragma aux DivideByZeroError aborts;
extern void DivideByZeroError(void);
#pragma aux lerrorf aborts;
extern void lerrorf(value_t e, char *format, ...);
#pragma aux lerror aborts;
extern void lerror(value_t e, const char *msg);
#pragma aux fl_raise aborts;
extern void fl_raise(value_t e);
#pragma aux type_error aborts;
extern void type_error(char *fname, char *expected, value_t got);
#pragma aux bounds_error aborts;
extern void bounds_error(char *fname, value_t arr, value_t ind);

View File

@ -63,6 +63,8 @@
#include "flisp.h" #include "flisp.h"
#include "error.h"
#include "argcount.h" #include "argcount.h"
#include "env.h" #include "env.h"
#include "opcodes.h" #include "opcodes.h"
@ -247,6 +249,8 @@ void bounds_error(char *fname, value_t arr, value_t ind)
fl_raise(fl_listn(4, BoundsError, symbol(fname), arr, ind)); fl_raise(fl_listn(4, BoundsError, symbol(fname), arr, ind));
} }
void DivideByZeroError(void) { lerror(DivideError, "/: division by zero"); }
// safe cast operators // safe cast operators
// -------------------------------------------------------- // --------------------------------------------------------

View File

@ -190,13 +190,8 @@ extern value_t fl_lasterror;
#define FL_CATCH_EXTERN \ #define FL_CATCH_EXTERN \
else for (l__ca = 1; l__ca; l__ca = 0, fl_restorestate(&_ctx)) else for (l__ca = 1; l__ca; l__ca = 0, fl_restorestate(&_ctx))
EXTERN_NORETURN(void, lerrorf(value_t e, char *format, ...));
EXTERN_NORETURN(void, lerror(value_t e, const char *msg));
void fl_savestate(struct fl_exception_context *_ctx); void fl_savestate(struct fl_exception_context *_ctx);
void fl_restorestate(struct fl_exception_context *_ctx); void fl_restorestate(struct fl_exception_context *_ctx);
EXTERN_NORETURN(void, fl_raise(value_t e));
EXTERN_NORETURN(void, type_error(char *fname, char *expected, value_t got));
EXTERN_NORETURN(void, bounds_error(char *fname, value_t arr, value_t ind));
extern value_t ArgError, IOError, KeyError, MemoryError, EnumerationError; extern value_t ArgError, IOError, KeyError, MemoryError, EnumerationError;
extern value_t UnboundError; extern value_t UnboundError;

View File

@ -25,6 +25,8 @@
#include "flisp.h" #include "flisp.h"
#include "error.h"
#include "argcount.h" #include "argcount.h"
static value_t iostreamsym, rdsym, wrsym, apsym, crsym, truncsym; static value_t iostreamsym, rdsym, wrsym, apsym, crsym, truncsym;

View File

@ -37,6 +37,7 @@
#include "buf.h" #include "buf.h"
#include "env.h" #include "env.h"
#include "error.h"
#include "opcodes.h" #include "opcodes.h"
#include "builtins.h" #include "builtins.h"

View File

@ -31,6 +31,8 @@
#include "flisp.h" #include "flisp.h"
#include "error.h"
#include "argcount.h" #include "argcount.h"
#include "os.h" #include "os.h"

View File

@ -32,6 +32,8 @@
#include "flisp.h" #include "flisp.h"
#include "error.h"
#include "argcount.h" #include "argcount.h"
#include "os.h" #include "os.h"

View File

@ -31,6 +31,7 @@
#include "flisp.h" #include "flisp.h"
#include "error.h"
#include "os.h" #include "os.h"
void path_to_dirname(char *path) void path_to_dirname(char *path)

View File

@ -32,6 +32,8 @@
#include "flisp.h" #include "flisp.h"
#include "error.h"
#include "argcount.h" #include "argcount.h"
value_t fl_stringp(value_t *args, uint32_t nargs) value_t fl_stringp(value_t *args, uint32_t nargs)

View File

@ -25,6 +25,8 @@
#include "flisp.h" #include "flisp.h"
#include "error.h"
#include "argcount.h" #include "argcount.h"
#include "equalhash.h" #include "equalhash.h"

View File

@ -28,6 +28,8 @@
#include "flisp.h" #include "flisp.h"
#include "error.h"
#include "argcount.h" #include "argcount.h"
#include "buf.h" #include "buf.h"