pic_assert_type -> TYPE_CHECK
This commit is contained in:
parent
e93536bf9a
commit
54d9d4865c
|
@ -53,7 +53,7 @@ pic_blob_bytevector(pic_state *pic)
|
||||||
data = pic_blob(pic, blob, NULL);
|
data = pic_blob(pic, blob, NULL);
|
||||||
|
|
||||||
for (i = 0; i < argc; ++i) {
|
for (i = 0; i < argc; ++i) {
|
||||||
pic_assert_type(pic, argv[i], int);
|
TYPE_CHECK(pic, argv[i], int);
|
||||||
|
|
||||||
if (pic_int(pic, argv[i]) < 0 || pic_int(pic, argv[i]) > 255) {
|
if (pic_int(pic, argv[i]) < 0 || pic_int(pic, argv[i]) > 255) {
|
||||||
pic_error(pic, "byte out of range", 0);
|
pic_error(pic, "byte out of range", 0);
|
||||||
|
@ -181,7 +181,7 @@ pic_blob_bytevector_append(pic_state *pic)
|
||||||
|
|
||||||
len = 0;
|
len = 0;
|
||||||
for (i = 0; i < argc; ++i) {
|
for (i = 0; i < argc; ++i) {
|
||||||
pic_assert_type(pic, argv[i], blob);
|
TYPE_CHECK(pic, argv[i], blob);
|
||||||
pic_blob(pic, argv[i], &l);
|
pic_blob(pic, argv[i], &l);
|
||||||
len += l;
|
len += l;
|
||||||
}
|
}
|
||||||
|
@ -213,7 +213,7 @@ pic_blob_list_to_bytevector(pic_state *pic)
|
||||||
data = pic_blob(pic, blob, NULL);
|
data = pic_blob(pic, blob, NULL);
|
||||||
|
|
||||||
pic_for_each (e, list, it) {
|
pic_for_each (e, list, it) {
|
||||||
pic_assert_type(pic, e, int);
|
TYPE_CHECK(pic, e, int);
|
||||||
|
|
||||||
if (pic_int(pic, e) < 0 || pic_int(pic, e) > 255)
|
if (pic_int(pic, e) < 0 || pic_int(pic, e) > 255)
|
||||||
pic_error(pic, "byte out of range", 0);
|
pic_error(pic, "byte out of range", 0);
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "picrin.h"
|
#include "picrin.h"
|
||||||
#include "picrin/extra.h"
|
#include "picrin/extra.h"
|
||||||
|
#include "picrin/private/object.h"
|
||||||
|
|
||||||
static pic_value
|
static pic_value
|
||||||
pic_char_char_p(pic_state *pic)
|
pic_char_char_p(pic_state *pic)
|
||||||
|
@ -54,7 +55,7 @@ pic_char_integer_to_char(pic_state *pic)
|
||||||
\
|
\
|
||||||
for (i = 0; i < argc; ++i) { \
|
for (i = 0; i < argc; ++i) { \
|
||||||
c = d; \
|
c = d; \
|
||||||
pic_assert_type(pic, argv[i], char); \
|
TYPE_CHECK(pic, argv[i], char); \
|
||||||
d = pic_char(pic, argv[i]); \
|
d = pic_char(pic, argv[i]); \
|
||||||
\
|
\
|
||||||
if (! (c op d)) \
|
if (! (c op d)) \
|
||||||
|
|
|
@ -105,7 +105,7 @@ pic_dict_dictionary(pic_state *pic)
|
||||||
dict = pic_make_dict(pic);
|
dict = pic_make_dict(pic);
|
||||||
|
|
||||||
for (i = 0; i < argc; i += 2) {
|
for (i = 0; i < argc; i += 2) {
|
||||||
pic_assert_type(pic, argv[i], sym);
|
TYPE_CHECK(pic, argv[i], sym);
|
||||||
pic_dict_set(pic, dict, argv[i], argv[i+1]);
|
pic_dict_set(pic, dict, argv[i], argv[i+1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,7 +217,7 @@ pic_dict_alist_to_dictionary(pic_state *pic)
|
||||||
dict = pic_make_dict(pic);
|
dict = pic_make_dict(pic);
|
||||||
|
|
||||||
pic_for_each (e, pic_reverse(pic, alist), it) {
|
pic_for_each (e, pic_reverse(pic, alist), it) {
|
||||||
pic_assert_type(pic, pic_car(pic, e), sym);
|
TYPE_CHECK(pic, pic_car(pic, e), sym);
|
||||||
pic_dict_set(pic, dict, pic_car(pic, e), pic_cdr(pic, e));
|
pic_dict_set(pic, dict, pic_car(pic, e), pic_cdr(pic, e));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,7 +250,7 @@ pic_dict_plist_to_dictionary(pic_state *pic)
|
||||||
dict = pic_make_dict(pic);
|
dict = pic_make_dict(pic);
|
||||||
|
|
||||||
for (e = pic_reverse(pic, plist); ! pic_nil_p(pic, e); e = pic_cddr(pic, e)) {
|
for (e = pic_reverse(pic, plist); ! pic_nil_p(pic, e); e = pic_cddr(pic, e)) {
|
||||||
pic_assert_type(pic, pic_cadr(pic, e), sym);
|
TYPE_CHECK(pic, pic_cadr(pic, e), sym);
|
||||||
pic_dict_set(pic, dict, pic_cadr(pic, e), pic_car(pic, e));
|
pic_dict_set(pic, dict, pic_cadr(pic, e), pic_car(pic, e));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -257,7 +257,7 @@ pic_error_error_object_message(pic_state *pic)
|
||||||
|
|
||||||
pic_get_args(pic, "o", &e);
|
pic_get_args(pic, "o", &e);
|
||||||
|
|
||||||
pic_assert_type(pic, e, error);
|
TYPE_CHECK(pic, e, error);
|
||||||
|
|
||||||
return pic_obj_value(pic_error_ptr(pic, e)->msg);
|
return pic_obj_value(pic_error_ptr(pic, e)->msg);
|
||||||
}
|
}
|
||||||
|
@ -269,7 +269,7 @@ pic_error_error_object_irritants(pic_state *pic)
|
||||||
|
|
||||||
pic_get_args(pic, "o", &e);
|
pic_get_args(pic, "o", &e);
|
||||||
|
|
||||||
pic_assert_type(pic, e, error);
|
TYPE_CHECK(pic, e, error);
|
||||||
|
|
||||||
return pic_error_ptr(pic, e)->irrs;
|
return pic_error_ptr(pic, e)->irrs;
|
||||||
}
|
}
|
||||||
|
@ -281,7 +281,7 @@ pic_error_error_object_type(pic_state *pic)
|
||||||
|
|
||||||
pic_get_args(pic, "o", &e);
|
pic_get_args(pic, "o", &e);
|
||||||
|
|
||||||
pic_assert_type(pic, e, error);
|
TYPE_CHECK(pic, e, error);
|
||||||
|
|
||||||
return pic_obj_value(pic_error_ptr(pic, e)->type);
|
return pic_obj_value(pic_error_ptr(pic, e)->type);
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,11 +59,6 @@ xFILE *xfopen_null(pic_state *, const char *mode);
|
||||||
#define pic_push(pic, item, place) (place = pic_cons(pic, item, place))
|
#define pic_push(pic, item, place) (place = pic_cons(pic, item, place))
|
||||||
#define pic_pop(pic, place) (place = pic_cdr(pic, place))
|
#define pic_pop(pic, place) (place = pic_cdr(pic, place))
|
||||||
|
|
||||||
#define pic_assert_type(pic, v, type) do { \
|
|
||||||
if (! pic_##type##_p(pic, v)) \
|
|
||||||
pic_error(pic, #type " required", 1, v); \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
#define pic_void(exec) pic_void_(PIC_GENSYM(ai), exec)
|
#define pic_void(exec) pic_void_(PIC_GENSYM(ai), exec)
|
||||||
#define pic_void_(ai,exec) do { \
|
#define pic_void_(ai,exec) do { \
|
||||||
size_t ai = pic_enter(pic); \
|
size_t ai = pic_enter(pic); \
|
||||||
|
|
|
@ -158,6 +158,22 @@ struct object *pic_obj_ptr(pic_value);
|
||||||
pic_value pic_obj_value(void *ptr);
|
pic_value pic_obj_value(void *ptr);
|
||||||
struct object *pic_obj_alloc(pic_state *, size_t, int type);
|
struct object *pic_obj_alloc(pic_state *, size_t, int type);
|
||||||
|
|
||||||
|
#define TYPENAME_int "integer"
|
||||||
|
#define TYPENAME_blob "bytevector"
|
||||||
|
#define TYPENAME_char "character"
|
||||||
|
#define TYPENAME_sym "symbol"
|
||||||
|
#define TYPENAME_error "error"
|
||||||
|
#define TYPENAME_proc "procedure"
|
||||||
|
#define TYPENAME_str "string"
|
||||||
|
#define TYPENAME_id "identifier"
|
||||||
|
#define TYPENAME_env "environment"
|
||||||
|
#define TYPENAME_vec "vector"
|
||||||
|
|
||||||
|
#define TYPE_CHECK(pic, v, type) do { \
|
||||||
|
if (! pic_##type##_p(pic, v)) \
|
||||||
|
pic_error(pic, TYPENAME_##type " required", 1, v); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
#define VALID_INDEX(pic, len, i) do { \
|
#define VALID_INDEX(pic, len, i) do { \
|
||||||
if (i < 0 || len <= i) pic_error(pic, "index out of range", 1, pic_int_value(pic, i)); \
|
if (i < 0 || len <= i) pic_error(pic, "index out of range", 1, pic_int_value(pic, i)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
|
@ -947,7 +947,7 @@ pic_funcall(pic_state *pic, const char *lib, const char *name, int n, ...)
|
||||||
|
|
||||||
proc = pic_ref(pic, lib, name);
|
proc = pic_ref(pic, lib, name);
|
||||||
|
|
||||||
pic_assert_type(pic, proc, proc);
|
TYPE_CHECK(pic, proc, proc);
|
||||||
|
|
||||||
va_start(ap, n);
|
va_start(ap, n);
|
||||||
r = pic_vcall(pic, proc, n, ap);
|
r = pic_vcall(pic, proc, n, ap);
|
||||||
|
|
|
@ -370,7 +370,7 @@ pic_str_string(pic_state *pic)
|
||||||
buf = pic_alloca(pic, argc);
|
buf = pic_alloca(pic, argc);
|
||||||
|
|
||||||
for (i = 0; i < argc; ++i) {
|
for (i = 0; i < argc; ++i) {
|
||||||
pic_assert_type(pic, argv[i], char);
|
TYPE_CHECK(pic, argv[i], char);
|
||||||
buf[i] = pic_char(pic, argv[i]);
|
buf[i] = pic_char(pic, argv[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -565,7 +565,7 @@ pic_str_string_append(pic_state *pic)
|
||||||
pic_get_args(pic, "*", &argc, &argv);
|
pic_get_args(pic, "*", &argc, &argv);
|
||||||
|
|
||||||
for (i = 0; i < argc; ++i) {
|
for (i = 0; i < argc; ++i) {
|
||||||
pic_assert_type(pic, argv[i], str);
|
TYPE_CHECK(pic, argv[i], str);
|
||||||
str = pic_str_cat(pic, str, argv[i]);
|
str = pic_str_cat(pic, str, argv[i]);
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
|
@ -587,7 +587,7 @@ pic_str_string_map(pic_state *pic)
|
||||||
len = INT_MAX;
|
len = INT_MAX;
|
||||||
for (i = 0; i < argc; ++i) {
|
for (i = 0; i < argc; ++i) {
|
||||||
int l;
|
int l;
|
||||||
pic_assert_type(pic, argv[i], str);
|
TYPE_CHECK(pic, argv[i], str);
|
||||||
l = pic_str_len(pic, argv[i]);
|
l = pic_str_len(pic, argv[i]);
|
||||||
len = len < l ? len : l;
|
len = len < l ? len : l;
|
||||||
}
|
}
|
||||||
|
@ -602,7 +602,7 @@ pic_str_string_map(pic_state *pic)
|
||||||
vals = pic_reverse(pic, vals);
|
vals = pic_reverse(pic, vals);
|
||||||
val = pic_funcall(pic, "picrin.base", "apply", 2, proc, vals);
|
val = pic_funcall(pic, "picrin.base", "apply", 2, proc, vals);
|
||||||
|
|
||||||
pic_assert_type(pic, val, char);
|
TYPE_CHECK(pic, val, char);
|
||||||
|
|
||||||
buf[i] = pic_char(pic, val);
|
buf[i] = pic_char(pic, val);
|
||||||
}
|
}
|
||||||
|
@ -624,7 +624,7 @@ pic_str_string_for_each(pic_state *pic)
|
||||||
len = INT_MAX;
|
len = INT_MAX;
|
||||||
for (i = 0; i < argc; ++i) {
|
for (i = 0; i < argc; ++i) {
|
||||||
int l;
|
int l;
|
||||||
pic_assert_type(pic, argv[i], str);
|
TYPE_CHECK(pic, argv[i], str);
|
||||||
l = pic_str_len(pic, argv[i]);
|
l = pic_str_len(pic, argv[i]);
|
||||||
len = len < l ? len : l;
|
len = len < l ? len : l;
|
||||||
}
|
}
|
||||||
|
@ -653,7 +653,7 @@ pic_str_list_to_string(pic_state *pic)
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
pic_for_each (e, list, it) {
|
pic_for_each (e, list, it) {
|
||||||
pic_assert_type(pic, e, char);
|
TYPE_CHECK(pic, e, char);
|
||||||
|
|
||||||
buf[i++] = pic_char(pic, e);
|
buf[i++] = pic_char(pic, e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,8 +130,8 @@ pic_symbol_make_identifier(pic_state *pic)
|
||||||
|
|
||||||
pic_get_args(pic, "oo", &id, &env);
|
pic_get_args(pic, "oo", &id, &env);
|
||||||
|
|
||||||
pic_assert_type(pic, id, id);
|
TYPE_CHECK(pic, id, id);
|
||||||
pic_assert_type(pic, env, env);
|
TYPE_CHECK(pic, env, env);
|
||||||
|
|
||||||
return pic_make_identifier(pic, id, env);
|
return pic_make_identifier(pic, id, env);
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,7 @@ pic_symbol_identifier_base(pic_state *pic)
|
||||||
|
|
||||||
pic_get_args(pic, "o", &id);
|
pic_get_args(pic, "o", &id);
|
||||||
|
|
||||||
pic_assert_type(pic, id, id);
|
TYPE_CHECK(pic, id, id);
|
||||||
|
|
||||||
if (pic_sym_p(pic, id)) {
|
if (pic_sym_p(pic, id)) {
|
||||||
pic_error(pic, "non-symbol identifier required", 1, id);
|
pic_error(pic, "non-symbol identifier required", 1, id);
|
||||||
|
@ -159,7 +159,7 @@ pic_symbol_identifier_environment(pic_state *pic)
|
||||||
|
|
||||||
pic_get_args(pic, "o", &id);
|
pic_get_args(pic, "o", &id);
|
||||||
|
|
||||||
pic_assert_type(pic, id, id);
|
TYPE_CHECK(pic, id, id);
|
||||||
|
|
||||||
if (pic_sym_p(pic, id)) {
|
if (pic_sym_p(pic, id)) {
|
||||||
pic_error(pic, "non-symbol identifier required", 1, id);
|
pic_error(pic, "non-symbol identifier required", 1, id);
|
||||||
|
|
|
@ -180,7 +180,7 @@ pic_vec_vector_append(pic_state *pic)
|
||||||
|
|
||||||
len = 0;
|
len = 0;
|
||||||
for (i = 0; i < argc; ++i) {
|
for (i = 0; i < argc; ++i) {
|
||||||
pic_assert_type(pic, argv[i], vec);
|
TYPE_CHECK(pic, argv[i], vec);
|
||||||
len += pic_vec_len(pic, argv[i]);
|
len += pic_vec_len(pic, argv[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,7 +237,7 @@ pic_vec_vector_map(pic_state *pic)
|
||||||
len = INT_MAX;
|
len = INT_MAX;
|
||||||
for (i = 0; i < argc; ++i) {
|
for (i = 0; i < argc; ++i) {
|
||||||
int l;
|
int l;
|
||||||
pic_assert_type(pic, argv[i], vec);
|
TYPE_CHECK(pic, argv[i], vec);
|
||||||
l = pic_vec_len(pic, argv[i]);
|
l = pic_vec_len(pic, argv[i]);
|
||||||
len = len < l ? len : l;
|
len = len < l ? len : l;
|
||||||
}
|
}
|
||||||
|
@ -271,7 +271,7 @@ pic_vec_vector_for_each(pic_state *pic)
|
||||||
len = INT_MAX;
|
len = INT_MAX;
|
||||||
for (i = 0; i < argc; ++i) {
|
for (i = 0; i < argc; ++i) {
|
||||||
int l;
|
int l;
|
||||||
pic_assert_type(pic, argv[i], vec);
|
TYPE_CHECK(pic, argv[i], vec);
|
||||||
l = pic_vec_len(pic, argv[i]);
|
l = pic_vec_len(pic, argv[i]);
|
||||||
len = len < l ? len : l;
|
len = len < l ? len : l;
|
||||||
}
|
}
|
||||||
|
@ -356,7 +356,7 @@ pic_vec_vector_to_string(pic_state *pic)
|
||||||
for (i = start; i < end; ++i) {
|
for (i = start; i < end; ++i) {
|
||||||
t = pic_vec_ref(pic, vec, i);
|
t = pic_vec_ref(pic, vec, i);
|
||||||
|
|
||||||
pic_assert_type(pic, t, char);
|
TYPE_CHECK(pic, t, char);
|
||||||
|
|
||||||
buf[i - start] = pic_char(pic, t);
|
buf[i - start] = pic_char(pic, t);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue