add pic_size_value

This commit is contained in:
Yuichi Nishiwaki 2014-09-27 19:40:10 +09:00
parent b3def908b6
commit cf9d48a865
6 changed files with 17 additions and 5 deletions

2
blob.c
View File

@ -83,7 +83,7 @@ pic_blob_bytevector_length(pic_state *pic)
pic_get_args(pic, "b", &bv);
return pic_int_value((int)bv->len);
return pic_size_value(bv->len);
}
static pic_value

2
dict.c
View File

@ -213,7 +213,7 @@ pic_dict_dictionary_size(pic_state *pic)
pic_get_args(pic, "d", &dict);
return pic_int_value((int)pic_dict_size(pic, dict));
return pic_size_value(pic_dict_size(pic, dict));
}
static pic_value

View File

@ -189,6 +189,7 @@ static inline pic_value pic_undef_value();
static inline pic_value pic_obj_value(void *);
static inline pic_value pic_float_value(double);
static inline pic_value pic_int_value(int);
static inline pic_value pic_size_value(size_t);
static inline pic_value pic_sym_value(pic_sym);
static inline pic_value pic_char_value(char c);
static inline pic_value pic_none_value();
@ -323,6 +324,17 @@ pic_bool_value(bool b)
return v;
}
static inline pic_value
pic_size_value(size_t s)
{
if (sizeof(unsigned) < sizeof(size_t)) {
if (s > (size_t)INT_MAX) {
return pic_float_value(s);
}
}
return pic_int_value((int)s);
}
#if PIC_NAN_BOXING
static inline pic_value

2
pair.c
View File

@ -559,7 +559,7 @@ pic_pair_length(pic_state *pic)
pic_get_args(pic, "o", &list);
return pic_int_value(pic_length(pic, list));
return pic_size_value(pic_length(pic, list));
}
static pic_value

View File

@ -271,7 +271,7 @@ pic_str_string_length(pic_state *pic)
pic_get_args(pic, "s", &str);
return pic_int_value(pic_strlen(str));
return pic_size_value(pic_strlen(str));
}
static pic_value

View File

@ -92,7 +92,7 @@ pic_vec_vector_length(pic_state *pic)
pic_get_args(pic, "v", &v);
return pic_int_value((int)v->len);
return pic_size_value(v->len);
}
static pic_value