Permalink
Browse files

struct pic_data * -> pic_value

  • Loading branch information...
nyuichi committed Feb 19, 2016
1 parent 064eaff commit 0d8a45191aa449db73d52be4ef5b202e59f8c958
@@ -252,7 +252,7 @@ pic_callcc(pic_state *pic, struct pic_proc *proc)
pic_value args[1];
/* save the continuation object in proc */
c = pic_lambda(pic, cont_call, 1, pic_obj_value(pic_data_value(pic, cont, &cont_type)));
c = pic_lambda(pic, cont_call, 1, pic_data_value(pic, cont, &cont_type));
args[0] = pic_obj_value(c);
return pic_applyk(pic, proc, 1, args);
@@ -62,7 +62,7 @@ pic_regexp_regexp(pic_state *pic)
pic_errorf(pic, "regexp compilation error: %s", errbuf);
}
return pic_obj_value(pic_data_value(pic, reg, &regexp_type));
return pic_data_value(pic, reg, &regexp_type);
}
static pic_value
@@ -141,7 +141,7 @@ pic_socket_make_socket(pic_state *pic)
pic_errorf(pic, "%s", strerror(errno));
}
return pic_obj_value(pic_data_value(pic, sock, &socket_type));
return pic_data_value(pic, sock, &socket_type);
}
static pic_value
@@ -179,7 +179,7 @@ pic_socket_socket_accept(pic_state *pic)
new_sock = pic_malloc(pic, sizeof(struct pic_socket_t));
new_sock->fd = fd;
return pic_obj_value(pic_data_value(pic, new_sock, &socket_type));
return pic_data_value(pic, new_sock, &socket_type);
}
static pic_value
View
@@ -83,15 +83,12 @@ When you use dynamic memory allocation inside C APIs, you must be caseful about
pic_create_foo(pic_state *pic)
{
struct foo *f;
struct pic_data *dat;
pic_get_args(pic, ""); // no args here
f = create_foo();
data = pic_data_value(pic, md, &foo_type);
return pic_obj_value(data);
return pic_data_value(pic, md, &foo_type);
}
void
View
@@ -172,7 +172,7 @@ internal_equal_p(pic_state *pic, pic_value x, pic_value y, int depth, khash_t(m)
return true;
}
case PIC_TYPE_DATA: {
return pic_data_ptr(x)->data == pic_data_ptr(y)->data;
return pic_data(pic, x) == pic_data(pic, y);
}
default:
return false;
View
@@ -109,7 +109,7 @@ cont_call(pic_state *pic)
pic_errorf(pic, "calling dead escape continuation");
}
cont = pic_data_ptr(pic_closure_ref(pic, CV_ESCAPE))->data;
cont = pic_data(pic, pic_closure_ref(pic, CV_ESCAPE));
cont->retc = argc;
cont->retv = argv;
@@ -127,7 +127,7 @@ pic_make_cont(pic_state *pic, struct pic_cont *cont)
struct pic_proc *c;
/* save the escape continuation in proc */
c = pic_lambda(pic, cont_call, 2, pic_int_value(pic, cont->id), pic_obj_value(pic_data_value(pic, cont, &cont_type)));
c = pic_lambda(pic, cont_call, 2, pic_int_value(pic, cont->id), pic_data_value(pic, cont, &cont_type));
return c;
}
View
@@ -4,18 +4,16 @@
bool
pic_data_type_p(pic_state *pic, pic_value obj, const pic_data_type *type)
{
return pic_data_p(pic, obj) && pic_data_ptr(obj)->type == type;
return pic_data_p(pic, obj) && pic_data_ptr(pic, obj)->type == type;
}
void *
pic_data(pic_state *pic, pic_value data)
pic_data(pic_state PIC_UNUSED(*pic), pic_value data)
{
pic_assert_type(pic, data, data);
return pic_data_ptr(data)->data;
return pic_data_ptr(pic, data)->data;
}
struct pic_data *
pic_value
pic_data_value(pic_state *pic, void *userdata, const pic_data_type *type)
{
struct pic_data *data;
@@ -24,5 +22,5 @@ pic_data_value(pic_state *pic, void *userdata, const pic_data_type *type)
data->type = type;
data->data = userdata;
return data;
return pic_obj_value(data);
}
View
@@ -704,7 +704,7 @@ pic_alloca(pic_state *pic, size_t n)
static const pic_data_type t = { "pic_alloca", pic_free, 0 };
/* TODO: optimize */
return pic_data_value(pic, pic_malloc(pic, n), &t)->data;
return pic_data(pic, pic_data_value(pic, pic_malloc(pic, n), &t));
}
struct pic_object *
@@ -58,7 +58,6 @@ struct pic_proc;
struct pic_port;
struct pic_error;
struct pic_env;
struct pic_data;
typedef struct pic_symbol pic_sym;
typedef struct pic_id pic_id;
@@ -125,7 +124,7 @@ PIC_INLINE char pic_char(pic_state *, pic_value c);
#define pic_bool(pic,b) (! pic_false_p(pic, b))
const char *pic_str(pic_state *, struct pic_string *);
unsigned char *pic_blob(pic_state *, pic_value blob, int *len);
void *pic_data(pic_state *, pic_value str);
void *pic_data(pic_state *, pic_value data);
typedef struct {
const char *type_name;
@@ -147,7 +146,7 @@ struct pic_string *pic_str_value(pic_state *, const char *str, int len);
struct pic_string *pic_strf_value(pic_state *, const char *fmt, ...);
struct pic_string *pic_vstrf_value(pic_state *, const char *fmt, va_list ap);
pic_value pic_blob_value(pic_state *, const unsigned char *buf, int len);
struct pic_data *pic_data_value(pic_state *, void *ptr, const pic_data_type *type);
pic_value pic_data_value(pic_state *, void *ptr, const pic_data_type *type);
enum {
PIC_TYPE_INVALID = 1,
@@ -123,12 +123,12 @@ struct pic_port {
#define pic_pair_ptr(pic, o) ((struct pic_pair *)pic_obj_ptr(o))
#define pic_blob_ptr(pic, v) ((struct pic_blob *)pic_obj_ptr(v))
#define pic_vec_ptr(pic, o) ((struct pic_vector *)pic_obj_ptr(o))
#define pic_dict_ptr(pic, v) ((struct pic_dict *)pic_obj_ptr(v))
#define pic_dict_ptr(pic, o) ((struct pic_dict *)pic_obj_ptr(o))
#define pic_data_ptr(pic, o) ((struct pic_data *)pic_obj_ptr(o))
#define pic_sym_ptr(v) ((pic_sym *)pic_obj_ptr(v))
#define pic_id_ptr(v) ((pic_id *)pic_obj_ptr(v))
#define pic_str_ptr(o) ((struct pic_string *)pic_obj_ptr(o))
#define pic_weak_ptr(v) ((struct pic_weak *)pic_obj_ptr(v))
#define pic_data_ptr(o) ((struct pic_data *)pic_obj_ptr(o))
#define pic_context_ptr(o) ((struct pic_context *)pic_obj_ptr(o))
#define pic_proc_ptr(o) ((struct pic_proc *)pic_obj_ptr(o))
#define pic_rec_ptr(v) ((struct pic_record *)pic_obj_ptr(v))

0 comments on commit 0d8a451

Please sign in to comment.