This commit is contained in:
Yuichi Nishiwaki 2016-02-20 19:47:46 +09:00
parent d0dc577810
commit b5a27437e3
4 changed files with 19 additions and 29 deletions

View File

@ -49,14 +49,6 @@ 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_data(pic, o) ((struct pic_socket_t *)pic_data(pic, o))
PIC_INLINE void
validate_socket_object(pic_state *pic, pic_value v)
{
if (! pic_socket_p(pic, v)) {
pic_errorf(pic, "~s is not a socket object", v);
}
}
static pic_value
pic_socket_socket_p(pic_state *pic)
{
@ -152,7 +144,7 @@ pic_socket_socket_accept(pic_state *pic)
struct pic_socket_t *sock, *new_sock;
pic_get_args(pic, "o", &obj);
validate_socket_object(pic, obj);
pic_assert_type(pic, obj, socket);
sock = pic_socket_data(pic, obj);
ensure_socket_is_open(pic, sock);
@ -191,7 +183,7 @@ pic_socket_socket_send(pic_state *pic)
struct pic_socket_t *sock;
pic_get_args(pic, "ob|i", &obj, &bv, &flags);
validate_socket_object(pic, obj);
pic_assert_type(pic, obj, socket);
sock = pic_socket_data(pic, obj);
ensure_socket_is_open(pic, sock);
@ -229,7 +221,7 @@ pic_socket_socket_recv(pic_state *pic)
struct pic_socket_t *sock;
pic_get_args(pic, "oi|i", &obj, &size, &flags);
validate_socket_object(pic, obj);
pic_assert_type(pic, obj, socket);
if (size < 0) {
pic_errorf(pic, "size must not be negative");
}
@ -263,7 +255,7 @@ pic_socket_socket_shutdown(pic_state *pic)
struct pic_socket_t *sock;
pic_get_args(pic, "oi", &obj, &how);
validate_socket_object(pic, obj);
pic_assert_type(pic, obj, socket);
sock = pic_socket_data(pic, obj);
if (sock->fd != -1) {
@ -280,7 +272,7 @@ pic_socket_socket_close(pic_state *pic)
pic_value obj;
pic_get_args(pic, "o", &obj);
validate_socket_object(pic, obj);
pic_assert_type(pic, obj, socket);
socket_close(pic_socket_data(pic, obj));
@ -341,7 +333,7 @@ pic_socket_socket_input_port(pic_state *pic)
struct pic_socket_t *sock;
pic_get_args(pic, "o", &obj);
validate_socket_object(pic, obj);
pic_assert_type(pic, obj, socket);
sock = pic_socket_data(pic, obj);
ensure_socket_is_open(pic, sock);
@ -356,7 +348,7 @@ pic_socket_socket_output_port(pic_state *pic)
struct pic_socket_t *sock;
pic_get_args(pic, "o", &obj);
validate_socket_object(pic, obj);
pic_assert_type(pic, obj, socket);
sock = pic_socket_data(pic, obj);
ensure_socket_is_open(pic, sock);
@ -371,7 +363,7 @@ pic_socket_call_with_socket(pic_state *pic)
struct pic_socket_t *sock;
pic_get_args(pic, "ol", &obj, &proc);
validate_socket_object(pic, obj);
pic_assert_type(pic, obj, socket);
sock = pic_socket_data(pic, obj);
ensure_socket_is_open(pic, sock);

View File

@ -82,6 +82,7 @@ void pic_set(pic_state *, const char *lib, const char *name, pic_value v);
pic_value pic_closure_ref(pic_state *, int i);
void pic_closure_set(pic_state *, int i, pic_value v);
pic_value pic_funcall(pic_state *, const char *lib, const char *name, int n, ...);
pic_value pic_make_var(pic_state *, pic_value init, pic_value conv);
pic_value pic_return(pic_state *, int n, ...);
pic_value pic_vreturn(pic_state *, int n, va_list);
@ -337,8 +338,6 @@ pic_value pic_eval(pic_state *, pic_value program, const char *lib);
void pic_load(pic_state *, pic_value port);
void pic_load_cstr(pic_state *, const char *);
pic_value pic_make_var(pic_state *, pic_value init, pic_value conv);
bool pic_data_type_p(pic_state *, pic_value, const pic_data_type *);
#define pic_deflibrary(pic, lib) do { \
@ -348,10 +347,6 @@ bool pic_data_type_p(pic_state *, pic_value, const pic_data_type *);
pic_in_library(pic, lib); \
} while (0)
pic_value pic_make_cont(pic_state *, struct pic_cont *);
void pic_wind(pic_state *, struct pic_checkpoint *, struct pic_checkpoint *);
/* do not return from try block! */
#define pic_try \
@ -360,6 +355,7 @@ void pic_wind(pic_state *, struct pic_checkpoint *, struct pic_checkpoint *);
pic_catch_(PIC_GENSYM(label))
#define pic_try_(cont, handler) \
do { \
extern pic_value pic_make_cont(pic_state *, struct pic_cont *); \
extern void pic_push_handler(pic_state *, pic_value proc); \
extern pic_value pic_pop_handler(pic_state *); \
extern pic_value pic_native_exception_handler(pic_state *); \

View File

@ -193,6 +193,8 @@ void pic_rope_decref(pic_state *, struct pic_rope *);
#define pic_proc_func_p(proc) ((proc)->tag == PIC_PROC_TAG_FUNC)
#define pic_proc_irep_p(proc) ((proc)->tag == PIC_PROC_TAG_IREP)
void pic_wind(pic_state *, struct pic_checkpoint *, struct pic_checkpoint *);
#if defined(__cplusplus)
}

View File

@ -21,13 +21,13 @@
* c char * char
* z char ** c string
* m pic_value * symbol
* v pic_value * vector object
* s pic_value * string object
* b pic_value * bytevector object
* l pic_value * lambda object
* p pic_value * port object
* d pic_value * dictionary object
* r pic_value * record object
* v pic_value * vector
* s pic_value * string
* b pic_value * bytevector
* l pic_value * lambda
* p pic_value * port
* d pic_value * dictionary
* r pic_value * record
*
* | optional operator
* * int *, pic_value ** variable length operator