move the definiton of pic_checkpoint to object.h
This commit is contained in:
parent
d91ec28474
commit
45879deafd
|
@ -1,11 +1,12 @@
|
||||||
#include "picrin.h"
|
#include "picrin.h"
|
||||||
|
#include "picrin/object.h"
|
||||||
|
|
||||||
struct pic_fullcont {
|
struct pic_fullcont {
|
||||||
jmp_buf jmp;
|
jmp_buf jmp;
|
||||||
|
|
||||||
struct pic_cont *prev_jmp;
|
struct pic_cont *prev_jmp;
|
||||||
|
|
||||||
pic_checkpoint *cp;
|
struct pic_checkpoint *cp;
|
||||||
|
|
||||||
char *stk_pos, *stk_ptr;
|
char *stk_pos, *stk_ptr;
|
||||||
ptrdiff_t stk_len;
|
ptrdiff_t stk_len;
|
||||||
|
@ -50,7 +51,7 @@ static void
|
||||||
cont_mark(pic_state *pic, void *data, void (*mark)(pic_state *, pic_value))
|
cont_mark(pic_state *pic, void *data, void (*mark)(pic_state *, pic_value))
|
||||||
{
|
{
|
||||||
struct pic_fullcont *cont = data;
|
struct pic_fullcont *cont = data;
|
||||||
pic_checkpoint *cp;
|
struct pic_checkpoint *cp;
|
||||||
pic_value *stack;
|
pic_value *stack;
|
||||||
pic_callinfo *ci;
|
pic_callinfo *ci;
|
||||||
struct pic_proc **xp;
|
struct pic_proc **xp;
|
||||||
|
|
|
@ -41,7 +41,7 @@ pic_load_point(pic_state *pic, struct pic_cont *cont)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
pic_wind(pic_state *pic, pic_checkpoint *here, pic_checkpoint *there)
|
pic_wind(pic_state *pic, struct pic_checkpoint *here, struct pic_checkpoint *there)
|
||||||
{
|
{
|
||||||
if (here == there)
|
if (here == there)
|
||||||
return;
|
return;
|
||||||
|
@ -59,13 +59,13 @@ pic_wind(pic_state *pic, pic_checkpoint *here, pic_checkpoint *there)
|
||||||
static pic_value
|
static pic_value
|
||||||
pic_dynamic_wind(pic_state *pic, pic_value in, pic_value thunk, pic_value out)
|
pic_dynamic_wind(pic_state *pic, pic_value in, pic_value thunk, pic_value out)
|
||||||
{
|
{
|
||||||
pic_checkpoint *here;
|
struct pic_checkpoint *here;
|
||||||
pic_value val;
|
pic_value val;
|
||||||
|
|
||||||
pic_call(pic, in, 0); /* enter */
|
pic_call(pic, in, 0); /* enter */
|
||||||
|
|
||||||
here = pic->cp;
|
here = pic->cp;
|
||||||
pic->cp = (pic_checkpoint *)pic_obj_alloc(pic, sizeof(pic_checkpoint), PIC_TYPE_CP);
|
pic->cp = (struct pic_checkpoint *)pic_obj_alloc(pic, sizeof(struct pic_checkpoint), PIC_TYPE_CP);
|
||||||
pic->cp->prev = here;
|
pic->cp->prev = here;
|
||||||
pic->cp->depth = here->depth + 1;
|
pic->cp->depth = here->depth + 1;
|
||||||
pic->cp->in = pic_proc_ptr(pic, in);
|
pic->cp->in = pic_proc_ptr(pic, in);
|
||||||
|
|
|
@ -56,9 +56,6 @@ struct pic_port;
|
||||||
struct pic_error;
|
struct pic_error;
|
||||||
struct pic_env;
|
struct pic_env;
|
||||||
|
|
||||||
typedef struct pic_identifier pic_id;
|
|
||||||
typedef pic_id pic_sym;
|
|
||||||
|
|
||||||
typedef void *(*pic_allocf)(void *userdata, void *ptr, size_t n);
|
typedef void *(*pic_allocf)(void *userdata, void *ptr, size_t n);
|
||||||
|
|
||||||
pic_state *pic_open(pic_allocf f, void *userdata);
|
pic_state *pic_open(pic_allocf f, void *userdata);
|
||||||
|
@ -266,6 +263,9 @@ int pic_str_hash(pic_state *, pic_value str);
|
||||||
/* extra stuff */
|
/* extra stuff */
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct pic_identifier pic_id;
|
||||||
|
typedef pic_id pic_sym;
|
||||||
|
|
||||||
#include "picrin/type.h"
|
#include "picrin/type.h"
|
||||||
#include "picrin/state.h"
|
#include "picrin/state.h"
|
||||||
#include "picrin/cont.h"
|
#include "picrin/cont.h"
|
||||||
|
|
|
@ -14,7 +14,7 @@ struct pic_cont {
|
||||||
|
|
||||||
int id;
|
int id;
|
||||||
|
|
||||||
pic_checkpoint *cp;
|
struct pic_checkpoint *cp;
|
||||||
ptrdiff_t sp_offset;
|
ptrdiff_t sp_offset;
|
||||||
ptrdiff_t ci_offset;
|
ptrdiff_t ci_offset;
|
||||||
ptrdiff_t xp_offset;
|
ptrdiff_t xp_offset;
|
||||||
|
@ -33,7 +33,7 @@ void pic_load_point(pic_state *, struct pic_cont *);
|
||||||
|
|
||||||
pic_value pic_make_cont(pic_state *, struct pic_cont *);
|
pic_value pic_make_cont(pic_state *, struct pic_cont *);
|
||||||
|
|
||||||
void pic_wind(pic_state *, pic_checkpoint *, pic_checkpoint *);
|
void pic_wind(pic_state *, struct pic_checkpoint *, struct pic_checkpoint *);
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,14 @@ KHASH_DECLARE(env, pic_id *, pic_sym *)
|
||||||
KHASH_DECLARE(dict, pic_sym *, pic_value)
|
KHASH_DECLARE(dict, pic_sym *, pic_value)
|
||||||
KHASH_DECLARE(weak, struct pic_object *, pic_value)
|
KHASH_DECLARE(weak, struct pic_object *, pic_value)
|
||||||
|
|
||||||
|
#define PIC_OBJECT_HEADER \
|
||||||
|
unsigned char tt; \
|
||||||
|
char gc_mark;
|
||||||
|
|
||||||
|
struct pic_basic {
|
||||||
|
PIC_OBJECT_HEADER
|
||||||
|
};
|
||||||
|
|
||||||
struct pic_identifier {
|
struct pic_identifier {
|
||||||
PIC_OBJECT_HEADER
|
PIC_OBJECT_HEADER
|
||||||
union {
|
union {
|
||||||
|
@ -115,6 +123,14 @@ struct pic_port {
|
||||||
xFILE *file;
|
xFILE *file;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct pic_checkpoint {
|
||||||
|
PIC_OBJECT_HEADER
|
||||||
|
struct pic_proc *in;
|
||||||
|
struct pic_proc *out;
|
||||||
|
int depth;
|
||||||
|
struct pic_checkpoint *prev;
|
||||||
|
};
|
||||||
|
|
||||||
#define pic_id_ptr(pic, o) ((pic_id *)pic_obj_ptr(o))
|
#define pic_id_ptr(pic, o) ((pic_id *)pic_obj_ptr(o))
|
||||||
#define pic_sym_ptr(pic, o) ((pic_sym *)pic_obj_ptr(o))
|
#define pic_sym_ptr(pic, o) ((pic_sym *)pic_obj_ptr(o))
|
||||||
#define pic_str_ptr(pic, o) ((struct pic_string *)pic_obj_ptr(o))
|
#define pic_str_ptr(pic, o) ((struct pic_string *)pic_obj_ptr(o))
|
||||||
|
@ -131,6 +147,7 @@ struct pic_port {
|
||||||
#define pic_port_ptr(v) ((struct pic_port *)pic_obj_ptr(v))
|
#define pic_port_ptr(v) ((struct pic_port *)pic_obj_ptr(v))
|
||||||
#define pic_env_ptr(v) ((struct pic_env *)pic_obj_ptr(v))
|
#define pic_env_ptr(v) ((struct pic_env *)pic_obj_ptr(v))
|
||||||
|
|
||||||
|
#define pic_obj_p(pic,v) (pic_vtype(pic,v) == PIC_IVAL_END)
|
||||||
#define pic_env_p(pic, v) (pic_type(pic, v) == PIC_TYPE_ENV)
|
#define pic_env_p(pic, v) (pic_type(pic, v) == PIC_TYPE_ENV)
|
||||||
#define pic_error_p(pic, v) (pic_type(pic, v) == PIC_TYPE_ERROR)
|
#define pic_error_p(pic, v) (pic_type(pic, v) == PIC_TYPE_ERROR)
|
||||||
#define pic_rec_p(pic, v) (pic_type(pic, v) == PIC_TYPE_RECORD)
|
#define pic_rec_p(pic, v) (pic_type(pic, v) == PIC_TYPE_RECORD)
|
||||||
|
|
|
@ -22,14 +22,6 @@ struct pic_lib {
|
||||||
struct pic_dict *exports;
|
struct pic_dict *exports;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct pic_checkpoint {
|
|
||||||
PIC_OBJECT_HEADER
|
|
||||||
struct pic_proc *in;
|
|
||||||
struct pic_proc *out;
|
|
||||||
int depth;
|
|
||||||
struct pic_checkpoint *prev;
|
|
||||||
} pic_checkpoint;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int argc, retc;
|
int argc, retc;
|
||||||
pic_code *ip;
|
pic_code *ip;
|
||||||
|
@ -48,7 +40,7 @@ struct pic_state {
|
||||||
pic_allocf allocf;
|
pic_allocf allocf;
|
||||||
void *userdata;
|
void *userdata;
|
||||||
|
|
||||||
pic_checkpoint *cp;
|
struct pic_checkpoint *cp;
|
||||||
struct pic_cont *cc;
|
struct pic_cont *cc;
|
||||||
int ccnt;
|
int ccnt;
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,8 @@ extern "C" {
|
||||||
* it is only used for repsenting internal special state
|
* it is only used for repsenting internal special state
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define pic_invalid_p(pic, v) (pic_vtype(pic, v) == PIC_TYPE_INVALID)
|
||||||
|
|
||||||
#if PIC_NAN_BOXING
|
#if PIC_NAN_BOXING
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -96,19 +98,6 @@ pic_obj_ptr(pic_value v)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define PIC_OBJECT_HEADER \
|
|
||||||
unsigned char tt; \
|
|
||||||
char gc_mark;
|
|
||||||
|
|
||||||
struct pic_basic {
|
|
||||||
PIC_OBJECT_HEADER
|
|
||||||
};
|
|
||||||
|
|
||||||
#define pic_obj_p(pic,v) (pic_vtype(pic,v) == PIC_IVAL_END)
|
|
||||||
#define pic_invalid_p(pic, v) (pic_vtype(pic, v) == PIC_TYPE_INVALID)
|
|
||||||
|
|
||||||
#define pic_test(pic, v) (! pic_false_p(pic, v))
|
|
||||||
|
|
||||||
PIC_INLINE bool
|
PIC_INLINE bool
|
||||||
pic_valid_int(double v)
|
pic_valid_int(double v)
|
||||||
{
|
{
|
||||||
|
|
|
@ -571,7 +571,7 @@ pic_pair_member(pic_state *pic)
|
||||||
if (pic_equal_p(pic, key, pic_car(pic, list)))
|
if (pic_equal_p(pic, key, pic_car(pic, list)))
|
||||||
return list;
|
return list;
|
||||||
} else {
|
} else {
|
||||||
if (pic_test(pic, pic_call(pic, proc, 2, key, pic_car(pic, list))))
|
if (! pic_false_p(pic, pic_call(pic, proc, 2, key, pic_car(pic, list))))
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
list = pic_cdr(pic, list);
|
list = pic_cdr(pic, list);
|
||||||
|
@ -627,7 +627,7 @@ pic_pair_assoc(pic_state *pic)
|
||||||
if (pic_equal_p(pic, key, pic_car(pic, cell)))
|
if (pic_equal_p(pic, key, pic_car(pic, cell)))
|
||||||
return cell;
|
return cell;
|
||||||
} else {
|
} else {
|
||||||
if (pic_test(pic, pic_call(pic, proc, 2, key, pic_car(pic, cell))))
|
if (! pic_false_p(pic, pic_call(pic, proc, 2, key, pic_car(pic, cell))))
|
||||||
return cell;
|
return cell;
|
||||||
}
|
}
|
||||||
alist = pic_cdr(pic, alist);
|
alist = pic_cdr(pic, alist);
|
||||||
|
|
|
@ -344,7 +344,7 @@ pic_open(pic_allocf allocf, void *userdata)
|
||||||
pic->macros = pic_make_weak(pic);
|
pic->macros = pic_make_weak(pic);
|
||||||
|
|
||||||
/* root block */
|
/* root block */
|
||||||
pic->cp = (pic_checkpoint *)pic_obj_alloc(pic, sizeof(pic_checkpoint), PIC_TYPE_CP);
|
pic->cp = (struct pic_checkpoint *)pic_obj_alloc(pic, sizeof(struct pic_checkpoint), PIC_TYPE_CP);
|
||||||
pic->cp->prev = NULL;
|
pic->cp->prev = NULL;
|
||||||
pic->cp->depth = 0;
|
pic->cp->depth = 0;
|
||||||
pic->cp->in = pic->cp->out = NULL;
|
pic->cp->in = pic->cp->out = NULL;
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "picrin.h"
|
#include "picrin.h"
|
||||||
|
#include "picrin/object.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
pic_type(pic_state PIC_UNUSED(*pic), pic_value v)
|
pic_type(pic_state PIC_UNUSED(*pic), pic_value v)
|
||||||
|
|
Loading…
Reference in New Issue