allow custom setjmp/longjmp
This commit is contained in:
parent
bb55bbfdde
commit
b9dde91123
|
@ -103,7 +103,9 @@ escape_call(pic_state *pic)
|
|||
|
||||
pic_load_point(pic, e->data);
|
||||
|
||||
longjmp(((struct pic_escape *)e->data)->jmp, 1);
|
||||
PIC_LONGJMP(pic, (void *)((struct pic_escape *)e->data)->jmp, 1);
|
||||
|
||||
PIC_UNREACHABLE();
|
||||
}
|
||||
|
||||
struct pic_proc *
|
||||
|
@ -130,7 +132,7 @@ pic_escape(pic_state *pic, struct pic_proc *proc)
|
|||
|
||||
pic_save_point(pic, escape);
|
||||
|
||||
if (setjmp(escape->jmp)) {
|
||||
if (PIC_SETJMP(pic, (void *)escape->jmp)) {
|
||||
return pic_values_by_list(pic, escape->results);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -35,7 +35,6 @@ extern "C" {
|
|||
#include <stdarg.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <setjmp.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
|
|
@ -11,6 +11,11 @@
|
|||
/** treat false value as none */
|
||||
/* #define PIC_NONE_IS_FALSE 1 */
|
||||
|
||||
/** custom setjmp/longjmp */
|
||||
/* #define PIC_JMPBUF_SIZE sizeof(jmp_buf) */
|
||||
/* #define PIC_SETJMP(pic, buf) setjmp(buf) */
|
||||
/* #define PIC_LONGJMP(pic, buf, val) longjmp((buf), (val)) */
|
||||
|
||||
/** initial memory size (to be dynamically extended if necessary) */
|
||||
/* #define PIC_ARENA_SIZE 1000 */
|
||||
|
||||
|
@ -55,6 +60,21 @@
|
|||
# define PIC_NONE_IS_FALSE 1
|
||||
#endif
|
||||
|
||||
#ifndef PIC_JMPBUF_SIZE
|
||||
# include <setjmp.h>
|
||||
# define PIC_JMPBUF_SIZE sizeof(jmp_buf)
|
||||
#endif
|
||||
|
||||
#ifndef PIC_SETJMP
|
||||
# include <setjmp.h>
|
||||
# define PIC_SETJMP(pic, buf) setjmp(buf)
|
||||
#endif
|
||||
|
||||
#ifndef PIC_LONGJMP
|
||||
# include <setjmp.h>
|
||||
# define PIC_LONGJMP(pic, buf, val) longjmp((buf), (val))
|
||||
#endif
|
||||
|
||||
#ifndef PIC_ARENA_SIZE
|
||||
# define PIC_ARENA_SIZE (8 * 1024)
|
||||
#endif
|
||||
|
|
|
@ -10,7 +10,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
struct pic_escape {
|
||||
jmp_buf jmp;
|
||||
char jmp[PIC_JMPBUF_SIZE];
|
||||
|
||||
bool valid;
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ struct pic_error *pic_make_error(pic_state *, pic_sym *, const char *, pic_list)
|
|||
do { \
|
||||
struct pic_escape *escape = pic_alloc(pic, sizeof(struct pic_escape)); \
|
||||
pic_save_point(pic, escape); \
|
||||
if (setjmp(escape->jmp) == 0) { \
|
||||
if (PIC_SETJMP(pic, (void *)escape->jmp) == 0) { \
|
||||
pic_push_try(pic, escape); \
|
||||
do
|
||||
#define pic_catch_(label) \
|
||||
|
|
Loading…
Reference in New Issue