move the definiton of pic_checkpoint to object.h

This commit is contained in:
Yuichi Nishiwaki 2016-02-20 16:12:21 +09:00
parent d91ec28474
commit 45879deafd
10 changed files with 35 additions and 35 deletions

View File

@ -1,11 +1,12 @@
#include "picrin.h"
#include "picrin/object.h"
struct pic_fullcont {
jmp_buf jmp;
struct pic_cont *prev_jmp;
pic_checkpoint *cp;
struct pic_checkpoint *cp;
char *stk_pos, *stk_ptr;
ptrdiff_t stk_len;
@ -50,7 +51,7 @@ static void
cont_mark(pic_state *pic, void *data, void (*mark)(pic_state *, pic_value))
{
struct pic_fullcont *cont = data;
pic_checkpoint *cp;
struct pic_checkpoint *cp;
pic_value *stack;
pic_callinfo *ci;
struct pic_proc **xp;

View File

@ -41,7 +41,7 @@ pic_load_point(pic_state *pic, struct pic_cont *cont)
}
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)
return;
@ -59,13 +59,13 @@ pic_wind(pic_state *pic, pic_checkpoint *here, pic_checkpoint *there)
static pic_value
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_call(pic, in, 0); /* enter */
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->depth = here->depth + 1;
pic->cp->in = pic_proc_ptr(pic, in);

View File

@ -56,9 +56,6 @@ struct pic_port;
struct pic_error;
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);
pic_state *pic_open(pic_allocf f, void *userdata);
@ -266,6 +263,9 @@ int pic_str_hash(pic_state *, pic_value str);
/* extra stuff */
typedef struct pic_identifier pic_id;
typedef pic_id pic_sym;
#include "picrin/type.h"
#include "picrin/state.h"
#include "picrin/cont.h"

View File

@ -14,7 +14,7 @@ struct pic_cont {
int id;
pic_checkpoint *cp;
struct pic_checkpoint *cp;
ptrdiff_t sp_offset;
ptrdiff_t ci_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 *);
void pic_wind(pic_state *, pic_checkpoint *, pic_checkpoint *);
void pic_wind(pic_state *, struct pic_checkpoint *, struct pic_checkpoint *);
#if defined(__cplusplus)
}

View File

@ -13,6 +13,14 @@ KHASH_DECLARE(env, pic_id *, pic_sym *)
KHASH_DECLARE(dict, pic_sym *, 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 {
PIC_OBJECT_HEADER
union {
@ -115,6 +123,14 @@ struct pic_port {
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_sym_ptr(pic, o) ((pic_sym *)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_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_error_p(pic, v) (pic_type(pic, v) == PIC_TYPE_ERROR)
#define pic_rec_p(pic, v) (pic_type(pic, v) == PIC_TYPE_RECORD)

View File

@ -22,14 +22,6 @@ struct pic_lib {
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 {
int argc, retc;
pic_code *ip;
@ -48,7 +40,7 @@ struct pic_state {
pic_allocf allocf;
void *userdata;
pic_checkpoint *cp;
struct pic_checkpoint *cp;
struct pic_cont *cc;
int ccnt;

View File

@ -14,6 +14,8 @@ extern "C" {
* 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
/**
@ -96,19 +98,6 @@ pic_obj_ptr(pic_value v)
#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_valid_int(double v)
{

View File

@ -571,7 +571,7 @@ pic_pair_member(pic_state *pic)
if (pic_equal_p(pic, key, pic_car(pic, list)))
return list;
} 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;
}
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)))
return cell;
} 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;
}
alist = pic_cdr(pic, alist);

View File

@ -344,7 +344,7 @@ pic_open(pic_allocf allocf, void *userdata)
pic->macros = pic_make_weak(pic);
/* 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->depth = 0;
pic->cp->in = pic->cp->out = NULL;

View File

@ -3,6 +3,7 @@
*/
#include "picrin.h"
#include "picrin/object.h"
int
pic_type(pic_state PIC_UNUSED(*pic), pic_value v)