1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-27 17:00:27 +00:00

Use _setjmp/_longjmp on BSDs.

This doesn't save the signal mask so should be a bit faster.
This commit is contained in:
Calvin Rose 2019-12-18 12:11:18 -05:00
parent 8cc43ad2d1
commit 4238379552
3 changed files with 23 additions and 3 deletions

View File

@ -173,17 +173,25 @@ static void janet_asm_deinit(JanetAssembler *a) {
janet_table_deinit(&a->defs);
}
static void janet_asm_longjmp(JanetAssembler *a) {
#if defined(JANET_BSD) || defined(JANET_APPLE)
_longjmp(a->on_error, 1);
#else
longjmp(a->on_error, 1);
#endif
}
/* Throw some kind of assembly error */
static void janet_asm_error(JanetAssembler *a, const char *message) {
a->errmessage = janet_formatc("%s, instruction %d", message, a->errindex);
longjmp(a->on_error, 1);
janet_asm_longjmp(a);
}
#define janet_asm_assert(a, c, m) do { if (!(c)) janet_asm_error((a), (m)); } while (0)
/* Throw some kind of assembly error */
static void janet_asm_errorv(JanetAssembler *a, const uint8_t *m) {
a->errmessage = m;
longjmp(a->on_error, 1);
janet_asm_longjmp(a);
}
/* Add a closure environment to the assembler. Sub funcdefs may need
@ -501,10 +509,14 @@ static JanetAssembleResult janet_asm1(JanetAssembler *parent, Janet source, int
janet_table_init(&a.defs, 0);
/* Set error jump */
#if defined(JANET_BSD) || defined(JANET_APPLE)
if (_setjmp(a.on_error)) {
#else
if (setjmp(a.on_error)) {
#endif
if (NULL != a.parent) {
janet_asm_deinit(&a);
longjmp(a.parent->on_error, 1);
janet_asm_longjmp(a.parent);
}
result.funcdef = NULL;
result.error = a.errmessage;

View File

@ -29,7 +29,11 @@
void janet_panicv(Janet message) {
if (janet_vm_return_reg != NULL) {
*janet_vm_return_reg = message;
#if defined(JANET_BSD) || defined(JANET_APPLE)
_longjmp(*janet_vm_jmp_buf, 1);
#else
longjmp(*janet_vm_jmp_buf, 1);
#endif
} else {
fputs((const char *)janet_formatc("janet top level panic - %v\n", message), stdout);
exit(1);

View File

@ -1153,7 +1153,11 @@ JanetSignal janet_continue(JanetFiber *fiber, Janet in, Janet *out) {
/* Run loop */
JanetSignal signal;
#if defined(JANET_BSD) || defined(JANET_APPLE)
if (_setjmp(buf)) {
#else
if (setjmp(buf)) {
#endif
signal = JANET_SIGNAL_ERROR;
} else {
signal = run_vm(fiber, in, old_status);