remove data.h
This commit is contained in:
parent
0243c52b14
commit
8979b65b0c
|
@ -224,7 +224,7 @@ cont_call(pic_state *pic)
|
||||||
|
|
||||||
pic_get_args(pic, "*", &argc, &argv);
|
pic_get_args(pic, "*", &argc, &argv);
|
||||||
|
|
||||||
cont = pic_data_ptr(pic_closure_ref(pic, 0))->data;
|
cont = pic_data(pic, pic_closure_ref(pic, 0));
|
||||||
cont->results = pic_list_by_array(pic, argc, argv);
|
cont->results = pic_list_by_array(pic, argc, argv);
|
||||||
|
|
||||||
/* execute guard handlers */
|
/* execute guard handlers */
|
||||||
|
|
|
@ -20,7 +20,7 @@ regexp_dtor(pic_state *pic, void *data)
|
||||||
static const pic_data_type regexp_type = { "regexp", regexp_dtor, NULL };
|
static const pic_data_type regexp_type = { "regexp", regexp_dtor, NULL };
|
||||||
|
|
||||||
#define pic_regexp_p(pic, o) (pic_data_type_p(pic, (o), ®exp_type))
|
#define pic_regexp_p(pic, o) (pic_data_type_p(pic, (o), ®exp_type))
|
||||||
#define pic_regexp_data_ptr(o) ((struct pic_regexp_t *)pic_data_ptr(o)->data)
|
#define pic_regexp_data(pic, v) ((struct pic_regexp_t *)pic_data(pic, v))
|
||||||
|
|
||||||
static pic_value
|
static pic_value
|
||||||
pic_regexp_regexp(pic_state *pic)
|
pic_regexp_regexp(pic_state *pic)
|
||||||
|
@ -92,11 +92,11 @@ pic_regexp_regexp_match(pic_state *pic)
|
||||||
matches = pic_nil_value(pic);
|
matches = pic_nil_value(pic);
|
||||||
positions = pic_nil_value(pic);
|
positions = pic_nil_value(pic);
|
||||||
|
|
||||||
if (strchr(pic_regexp_data_ptr(reg)->flags, 'g') != NULL) {
|
if (strchr(pic_regexp_data(pic, reg)->flags, 'g') != NULL) {
|
||||||
/* global search */
|
/* global search */
|
||||||
|
|
||||||
offset = 0;
|
offset = 0;
|
||||||
while (regexec(&pic_regexp_data_ptr(reg)->reg, input, 1, match, 0) != REG_NOMATCH) {
|
while (regexec(&pic_regexp_data(pic, reg)->reg, input, 1, match, 0) != REG_NOMATCH) {
|
||||||
pic_push(pic, pic_obj_value(pic_str_value(pic, input, match[0].rm_eo - match[0].rm_so)), matches);
|
pic_push(pic, pic_obj_value(pic_str_value(pic, input, match[0].rm_eo - match[0].rm_so)), matches);
|
||||||
pic_push(pic, pic_int_value(pic, offset), positions);
|
pic_push(pic, pic_int_value(pic, offset), positions);
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ pic_regexp_regexp_match(pic_state *pic)
|
||||||
} else {
|
} else {
|
||||||
/* local search */
|
/* local search */
|
||||||
|
|
||||||
if (regexec(&pic_regexp_data_ptr(reg)->reg, input, 100, match, 0) == 0) {
|
if (regexec(&pic_regexp_data(pic, reg)->reg, input, 100, match, 0) == 0) {
|
||||||
for (i = 0; i < 100; ++i) {
|
for (i = 0; i < 100; ++i) {
|
||||||
if (match[i].rm_so == -1) {
|
if (match[i].rm_so == -1) {
|
||||||
break;
|
break;
|
||||||
|
@ -140,7 +140,7 @@ pic_regexp_regexp_split(pic_state *pic)
|
||||||
|
|
||||||
pic_assert_type(pic, reg, regexp);
|
pic_assert_type(pic, reg, regexp);
|
||||||
|
|
||||||
while (regexec(&pic_regexp_data_ptr(reg)->reg, input, 1, &match, 0) != REG_NOMATCH) {
|
while (regexec(&pic_regexp_data(pic, reg)->reg, input, 1, &match, 0) != REG_NOMATCH) {
|
||||||
pic_push(pic, pic_obj_value(pic_str_value(pic, input, match.rm_so)), output);
|
pic_push(pic, pic_obj_value(pic_str_value(pic, input, match.rm_so)), output);
|
||||||
|
|
||||||
input += match.rm_eo;
|
input += match.rm_eo;
|
||||||
|
@ -163,7 +163,7 @@ pic_regexp_regexp_replace(pic_state *pic)
|
||||||
|
|
||||||
pic_assert_type(pic, reg, regexp);
|
pic_assert_type(pic, reg, regexp);
|
||||||
|
|
||||||
while (regexec(&pic_regexp_data_ptr(reg)->reg, input, 1, &match, 0) != REG_NOMATCH) {
|
while (regexec(&pic_regexp_data(pic, reg)->reg, input, 1, &match, 0) != REG_NOMATCH) {
|
||||||
output = pic_str_cat(pic, output, pic_str_value(pic, input, match.rm_so));
|
output = pic_str_cat(pic, output, pic_str_value(pic, input, match.rm_so));
|
||||||
output = pic_str_cat(pic, output, txt);
|
output = pic_str_cat(pic, output, txt);
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ socket_dtor(pic_state *pic, void *data)
|
||||||
static const pic_data_type socket_type = { "socket", socket_dtor, NULL };
|
static const pic_data_type socket_type = { "socket", socket_dtor, NULL };
|
||||||
|
|
||||||
#define pic_socket_p(pic, o) (pic_data_type_p(pic, (o), &socket_type))
|
#define pic_socket_p(pic, o) (pic_data_type_p(pic, (o), &socket_type))
|
||||||
#define pic_socket_data_ptr(o) ((struct pic_socket_t *)pic_data_ptr(o)->data)
|
#define pic_socket_data(pic, o) ((struct pic_socket_t *)pic_data(pic, o))
|
||||||
|
|
||||||
PIC_INLINE void
|
PIC_INLINE void
|
||||||
validate_socket_object(pic_state *pic, pic_value v)
|
validate_socket_object(pic_state *pic, pic_value v)
|
||||||
|
@ -154,7 +154,7 @@ pic_socket_socket_accept(pic_state *pic)
|
||||||
pic_get_args(pic, "o", &obj);
|
pic_get_args(pic, "o", &obj);
|
||||||
validate_socket_object(pic, obj);
|
validate_socket_object(pic, obj);
|
||||||
|
|
||||||
sock = pic_socket_data_ptr(obj);
|
sock = pic_socket_data(pic, obj);
|
||||||
ensure_socket_is_open(pic, sock);
|
ensure_socket_is_open(pic, sock);
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
@ -194,7 +194,7 @@ pic_socket_socket_send(pic_state *pic)
|
||||||
pic_get_args(pic, "ob|i", &obj, &bv, &flags);
|
pic_get_args(pic, "ob|i", &obj, &bv, &flags);
|
||||||
validate_socket_object(pic, obj);
|
validate_socket_object(pic, obj);
|
||||||
|
|
||||||
sock = pic_socket_data_ptr(obj);
|
sock = pic_socket_data(pic, obj);
|
||||||
ensure_socket_is_open(pic, sock);
|
ensure_socket_is_open(pic, sock);
|
||||||
|
|
||||||
cursor = pic_blob(pic, bv, &remain);
|
cursor = pic_blob(pic, bv, &remain);
|
||||||
|
@ -236,7 +236,7 @@ pic_socket_socket_recv(pic_state *pic)
|
||||||
pic_errorf(pic, "size must not be negative");
|
pic_errorf(pic, "size must not be negative");
|
||||||
}
|
}
|
||||||
|
|
||||||
sock = pic_socket_data_ptr(obj);
|
sock = pic_socket_data(pic, obj);
|
||||||
ensure_socket_is_open(pic, sock);
|
ensure_socket_is_open(pic, sock);
|
||||||
|
|
||||||
buf = malloc(size);
|
buf = malloc(size);
|
||||||
|
@ -271,7 +271,7 @@ pic_socket_socket_shutdown(pic_state *pic)
|
||||||
pic_get_args(pic, "oi", &obj, &how);
|
pic_get_args(pic, "oi", &obj, &how);
|
||||||
validate_socket_object(pic, obj);
|
validate_socket_object(pic, obj);
|
||||||
|
|
||||||
sock = pic_socket_data_ptr(obj);
|
sock = pic_socket_data(pic, obj);
|
||||||
if (sock->fd != -1) {
|
if (sock->fd != -1) {
|
||||||
shutdown(sock->fd, how);
|
shutdown(sock->fd, how);
|
||||||
sock->fd = -1;
|
sock->fd = -1;
|
||||||
|
@ -288,7 +288,7 @@ pic_socket_socket_close(pic_state *pic)
|
||||||
pic_get_args(pic, "o", &obj);
|
pic_get_args(pic, "o", &obj);
|
||||||
validate_socket_object(pic, obj);
|
validate_socket_object(pic, obj);
|
||||||
|
|
||||||
socket_close(pic_socket_data_ptr(obj));
|
socket_close(pic_socket_data(pic, obj));
|
||||||
|
|
||||||
return pic_undef_value(pic);
|
return pic_undef_value(pic);
|
||||||
}
|
}
|
||||||
|
@ -346,7 +346,7 @@ pic_socket_socket_input_port(pic_state *pic)
|
||||||
pic_get_args(pic, "o", &obj);
|
pic_get_args(pic, "o", &obj);
|
||||||
validate_socket_object(pic, obj);
|
validate_socket_object(pic, obj);
|
||||||
|
|
||||||
sock = pic_socket_data_ptr(obj);
|
sock = pic_socket_data(pic, obj);
|
||||||
ensure_socket_is_open(pic, sock);
|
ensure_socket_is_open(pic, sock);
|
||||||
|
|
||||||
return pic_obj_value(make_socket_port(pic, sock, PIC_PORT_IN));
|
return pic_obj_value(make_socket_port(pic, sock, PIC_PORT_IN));
|
||||||
|
@ -361,7 +361,7 @@ pic_socket_socket_output_port(pic_state *pic)
|
||||||
pic_get_args(pic, "o", &obj);
|
pic_get_args(pic, "o", &obj);
|
||||||
validate_socket_object(pic, obj);
|
validate_socket_object(pic, obj);
|
||||||
|
|
||||||
sock = pic_socket_data_ptr(obj);
|
sock = pic_socket_data(pic, obj);
|
||||||
ensure_socket_is_open(pic, sock);
|
ensure_socket_is_open(pic, sock);
|
||||||
|
|
||||||
return pic_obj_value(make_socket_port(pic, sock, PIC_PORT_OUT));
|
return pic_obj_value(make_socket_port(pic, sock, PIC_PORT_OUT));
|
||||||
|
@ -377,7 +377,7 @@ pic_socket_call_with_socket(pic_state *pic)
|
||||||
pic_get_args(pic, "ol", &obj, &proc);
|
pic_get_args(pic, "ol", &obj, &proc);
|
||||||
validate_socket_object(pic, obj);
|
validate_socket_object(pic, obj);
|
||||||
|
|
||||||
sock = pic_socket_data_ptr(obj);
|
sock = pic_socket_data(pic, obj);
|
||||||
ensure_socket_is_open(pic, sock);
|
ensure_socket_is_open(pic, sock);
|
||||||
|
|
||||||
result = pic_call(pic, proc, 1, obj);
|
result = pic_call(pic, proc, 1, obj);
|
||||||
|
|
|
@ -1,2 +1,28 @@
|
||||||
#include "picrin.h"
|
#include "picrin.h"
|
||||||
|
#include "picrin/object.h"
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
pic_data(pic_state *pic, pic_value data)
|
||||||
|
{
|
||||||
|
pic_assert_type(pic, data, data);
|
||||||
|
|
||||||
|
return pic_data_ptr(data)->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct pic_data *
|
||||||
|
pic_data_value(pic_state *pic, void *userdata, const pic_data_type *type)
|
||||||
|
{
|
||||||
|
struct pic_data *data;
|
||||||
|
|
||||||
|
data = (struct pic_data *)pic_obj_alloc(pic, sizeof(struct pic_data), PIC_TYPE_DATA);
|
||||||
|
data->type = type;
|
||||||
|
data->data = userdata;
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
|
@ -123,7 +123,7 @@ PIC_INLINE char pic_char(pic_state *, pic_value);
|
||||||
#define pic_bool(pic,v) (! pic_false_p(pic, v))
|
#define pic_bool(pic,v) (! pic_false_p(pic, v))
|
||||||
const char *pic_str(pic_state *, struct pic_string *);
|
const char *pic_str(pic_state *, struct pic_string *);
|
||||||
unsigned char *pic_blob(pic_state *, struct pic_blob *, int *len);
|
unsigned char *pic_blob(pic_state *, struct pic_blob *, int *len);
|
||||||
void *pic_data(pic_state *, struct pic_data *);
|
void *pic_data(pic_state *, pic_value);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char *type_name;
|
const char *type_name;
|
||||||
|
@ -260,7 +260,6 @@ int pic_str_hash(pic_state *, struct pic_string *);
|
||||||
#include "picrin/state.h"
|
#include "picrin/state.h"
|
||||||
|
|
||||||
#include "picrin/cont.h"
|
#include "picrin/cont.h"
|
||||||
#include "picrin/data.h"
|
|
||||||
#include "picrin/error.h"
|
#include "picrin/error.h"
|
||||||
#include "picrin/macro.h"
|
#include "picrin/macro.h"
|
||||||
#include "picrin/pair.h"
|
#include "picrin/pair.h"
|
||||||
|
@ -296,6 +295,8 @@ pic_value pic_eval(pic_state *, pic_value, const char *);
|
||||||
|
|
||||||
struct pic_proc *pic_make_var(pic_state *, pic_value, struct pic_proc *);
|
struct pic_proc *pic_make_var(pic_state *, pic_value, struct pic_proc *);
|
||||||
|
|
||||||
|
bool pic_data_type_p(pic_state *, pic_value, const pic_data_type *);
|
||||||
|
|
||||||
#define pic_deflibrary(pic, lib) do { \
|
#define pic_deflibrary(pic, lib) do { \
|
||||||
if (! pic_find_library(pic, lib)) { \
|
if (! pic_find_library(pic, lib)) { \
|
||||||
pic_make_library(pic, lib); \
|
pic_make_library(pic, lib); \
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
/**
|
|
||||||
* See Copyright Notice in picrin.h
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef PICRIN_DATA_H
|
|
||||||
#define PICRIN_DATA_H
|
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct pic_data {
|
|
||||||
PIC_OBJECT_HEADER
|
|
||||||
const pic_data_type *type;
|
|
||||||
void *data;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define pic_data_ptr(o) ((struct pic_data *)pic_obj_ptr(o))
|
|
||||||
|
|
||||||
PIC_INLINE bool pic_data_type_p(pic_state *pic, const pic_value obj, const pic_data_type *type) {
|
|
||||||
return pic_data_p(pic, obj) && pic_data_ptr(obj)->type == type;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -69,6 +69,17 @@ struct pic_weak {
|
||||||
#define pic_weak_ptr(v) ((struct pic_weak *)pic_obj_ptr(v))
|
#define pic_weak_ptr(v) ((struct pic_weak *)pic_obj_ptr(v))
|
||||||
|
|
||||||
|
|
||||||
|
/* data */
|
||||||
|
|
||||||
|
struct pic_data {
|
||||||
|
PIC_OBJECT_HEADER
|
||||||
|
const pic_data_type *type;
|
||||||
|
void *data;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define pic_data_ptr(o) ((struct pic_data *)pic_obj_ptr(o))
|
||||||
|
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -72,21 +72,3 @@ pic_typename(pic_state *pic, int type)
|
||||||
pic_errorf(pic, "pic_typename: invalid type given %d", type);
|
pic_errorf(pic, "pic_typename: invalid type given %d", type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
|
||||||
pic_data(pic_state PIC_UNUSED(*pic), struct pic_data *data)
|
|
||||||
{
|
|
||||||
return data->data;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct pic_data *
|
|
||||||
pic_data_value(pic_state *pic, void *userdata, const pic_data_type *type)
|
|
||||||
{
|
|
||||||
struct pic_data *data;
|
|
||||||
|
|
||||||
data = (struct pic_data *)pic_obj_alloc(pic, sizeof(struct pic_data), PIC_TYPE_DATA);
|
|
||||||
data->type = type;
|
|
||||||
data->data = userdata;
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue