Replace fl_exception_context_t with struct

This commit is contained in:
Lassi Kortela 2019-08-09 19:18:27 +03:00
parent 262ace1efd
commit e54797e4eb
2 changed files with 26 additions and 26 deletions

View File

@ -146,20 +146,20 @@ static uint32_t *consflags;
// ------------------------------------------------------------ // ------------------------------------------------------------
// saved execution state for an unwind target // saved execution state for an unwind target
fl_exception_context_t *fl_ctx = NULL; struct fl_exception_context *fl_ctx = NULL;
uint32_t fl_throwing_frame = 0; // active frame when exception was thrown uint32_t fl_throwing_frame = 0; // active frame when exception was thrown
value_t fl_lasterror; value_t fl_lasterror;
#define FL_TRY \ #define FL_TRY \
fl_exception_context_t _ctx; \ struct fl_exception_context _ctx; \
int l__tr, l__ca; \ int l__tr, l__ca; \
_ctx.sp = SP; \ _ctx.sp = SP; \
_ctx.frame = curr_frame; \ _ctx.frame = curr_frame; \
_ctx.rdst = readstate; \ _ctx.rdst = readstate; \
_ctx.prev = fl_ctx; \ _ctx.prev = fl_ctx; \
_ctx.ngchnd = N_GCHND; \ _ctx.ngchnd = N_GCHND; \
fl_ctx = &_ctx; \ fl_ctx = &_ctx; \
if (!setjmp(_ctx.buf)) \ if (!setjmp(_ctx.buf)) \
for (l__tr = 1; l__tr; l__tr = 0, (void)(fl_ctx = fl_ctx->prev)) for (l__tr = 1; l__tr; l__tr = 0, (void)(fl_ctx = fl_ctx->prev))
#define FL_CATCH \ #define FL_CATCH \
@ -167,7 +167,7 @@ value_t fl_lasterror;
fl_throwing_frame = 0, SP = _ctx.sp, \ fl_throwing_frame = 0, SP = _ctx.sp, \
curr_frame = _ctx.frame) curr_frame = _ctx.frame)
void fl_savestate(fl_exception_context_t *_ctx) void fl_savestate(struct fl_exception_context *_ctx)
{ {
_ctx->sp = SP; _ctx->sp = SP;
_ctx->frame = curr_frame; _ctx->frame = curr_frame;
@ -176,7 +176,7 @@ void fl_savestate(fl_exception_context_t *_ctx)
_ctx->ngchnd = N_GCHND; _ctx->ngchnd = N_GCHND;
} }
void fl_restorestate(fl_exception_context_t *_ctx) void fl_restorestate(struct fl_exception_context *_ctx)
{ {
fl_lasterror = FL_NIL; fl_lasterror = FL_NIL;
fl_throwing_frame = 0; fl_throwing_frame = 0;
@ -195,7 +195,7 @@ void fl_raise(value_t e)
if (fl_throwing_frame == 0) if (fl_throwing_frame == 0)
fl_throwing_frame = curr_frame; fl_throwing_frame = curr_frame;
N_GCHND = fl_ctx->ngchnd; N_GCHND = fl_ctx->ngchnd;
fl_exception_context_t *thisctx = fl_ctx; struct fl_exception_context *thisctx = fl_ctx;
if (fl_ctx->prev) // don't throw past toplevel if (fl_ctx->prev) // don't throw past toplevel
fl_ctx = fl_ctx->prev; fl_ctx = fl_ctx->prev;
longjmp(thisctx->buf, 1); longjmp(thisctx->buf, 1);

View File

@ -169,25 +169,25 @@ struct fl_readstate {
struct fl_readstate *prev; struct fl_readstate *prev;
}; };
typedef struct _ectx_t { struct fl_exception_context {
jmp_buf buf; jmp_buf buf;
uint32_t sp; uint32_t sp;
uint32_t frame; uint32_t frame;
uint32_t ngchnd; uint32_t ngchnd;
struct fl_readstate *rdst; struct fl_readstate *rdst;
struct _ectx_t *prev; struct fl_exception_context *prev;
} fl_exception_context_t; };
extern fl_exception_context_t *fl_ctx; extern struct fl_exception_context *fl_ctx;
extern uint32_t fl_throwing_frame; extern uint32_t fl_throwing_frame;
extern value_t fl_lasterror; extern value_t fl_lasterror;
#define FL_TRY_EXTERN \ #define FL_TRY_EXTERN \
fl_exception_context_t _ctx; \ struct fl_exception_context _ctx; \
int l__tr, l__ca; \ int l__tr, l__ca; \
fl_savestate(&_ctx); \ fl_savestate(&_ctx); \
fl_ctx = &_ctx; \ fl_ctx = &_ctx; \
if (!setjmp(_ctx.buf)) \ if (!setjmp(_ctx.buf)) \
for (l__tr = 1; l__tr; l__tr = 0, (void)(fl_ctx = fl_ctx->prev)) for (l__tr = 1; l__tr; l__tr = 0, (void)(fl_ctx = fl_ctx->prev))
#define FL_CATCH_EXTERN \ #define FL_CATCH_EXTERN \
@ -195,8 +195,8 @@ extern value_t fl_lasterror;
void lerrorf(value_t e, char *format, ...) __attribute__((__noreturn__)); void lerrorf(value_t e, char *format, ...) __attribute__((__noreturn__));
void lerror(value_t e, const char *msg) __attribute__((__noreturn__)); void lerror(value_t e, const char *msg) __attribute__((__noreturn__));
void fl_savestate(fl_exception_context_t *_ctx); void fl_savestate(struct fl_exception_context *_ctx);
void fl_restorestate(fl_exception_context_t *_ctx); void fl_restorestate(struct fl_exception_context *_ctx);
void fl_raise(value_t e) __attribute__((__noreturn__)); void fl_raise(value_t e) __attribute__((__noreturn__));
void type_error(char *fname, char *expected, value_t got) void type_error(char *fname, char *expected, value_t got)
__attribute__((__noreturn__)); __attribute__((__noreturn__));