2014-09-21 23:32:14 +08:00
|
|
|
#include "exceptions.h"
|
2014-09-23 22:09:08 +08:00
|
|
|
#include "corecom.h"
|
2014-09-21 23:32:14 +08:00
|
|
|
|
2014-09-22 13:18:48 +08:00
|
|
|
#define MAX_EXCEPTION_CONTEXTS 64
|
|
|
|
|
|
|
|
struct exception_context {
|
2014-09-23 22:09:08 +08:00
|
|
|
void *jb[13];
|
2014-09-22 13:18:48 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct exception_context exception_contexts[MAX_EXCEPTION_CONTEXTS];
|
|
|
|
static int ec_top;
|
2014-09-21 23:32:14 +08:00
|
|
|
static int stored_id;
|
|
|
|
|
2014-09-22 13:18:48 +08:00
|
|
|
void *exception_push(void)
|
2014-09-21 23:32:14 +08:00
|
|
|
{
|
2014-09-22 13:18:48 +08:00
|
|
|
if(ec_top >= MAX_EXCEPTION_CONTEXTS)
|
|
|
|
exception_raise(EID_NOMEM);
|
|
|
|
return exception_contexts[ec_top++].jb;
|
2014-09-21 23:32:14 +08:00
|
|
|
}
|
|
|
|
|
2014-09-23 16:22:32 +08:00
|
|
|
void exception_pop(int levels)
|
2014-09-21 23:32:14 +08:00
|
|
|
{
|
2014-09-23 16:22:32 +08:00
|
|
|
ec_top -= levels;
|
2014-09-21 23:32:14 +08:00
|
|
|
}
|
|
|
|
|
2014-09-22 13:18:48 +08:00
|
|
|
int exception_getid(void)
|
2014-09-21 23:32:14 +08:00
|
|
|
{
|
2014-09-22 13:18:48 +08:00
|
|
|
return stored_id;
|
|
|
|
}
|
2014-09-21 23:32:14 +08:00
|
|
|
|
2014-09-22 13:18:48 +08:00
|
|
|
void exception_raise(int id)
|
|
|
|
{
|
2014-09-25 12:55:22 +08:00
|
|
|
stored_id = id;
|
2014-09-24 00:00:10 +08:00
|
|
|
exception_longjmp(exception_contexts[--ec_top].jb);
|
2014-09-21 23:32:14 +08:00
|
|
|
}
|