add bytevector procedure
This commit is contained in:
parent
1b97362653
commit
0f2a172ffc
28
blob.c
28
blob.c
|
@ -46,6 +46,33 @@ pic_blob_bytevector_p(pic_state *pic)
|
||||||
return pic_bool_value(pic_blob_p(v));
|
return pic_bool_value(pic_blob_p(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static pic_value
|
||||||
|
pic_blob_bytevector(pic_state *pic)
|
||||||
|
{
|
||||||
|
pic_value *argv;
|
||||||
|
size_t argc, i;
|
||||||
|
pic_blob *blob;
|
||||||
|
char *data;
|
||||||
|
|
||||||
|
pic_get_args(pic, "*", &argc, &argv);
|
||||||
|
|
||||||
|
blob = pic_make_blob(pic, argc);
|
||||||
|
|
||||||
|
data = blob->data;
|
||||||
|
|
||||||
|
for (i = 0; i < argc; ++i) {
|
||||||
|
pic_assert_type(pic, argv[i], int);
|
||||||
|
|
||||||
|
if (pic_int(argv[i]) < 0 || pic_int(argv[i]) > 255) {
|
||||||
|
pic_error(pic, "byte out of range");
|
||||||
|
}
|
||||||
|
|
||||||
|
*data++ = pic_int(argv[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return pic_obj_value(blob);
|
||||||
|
}
|
||||||
|
|
||||||
static pic_value
|
static pic_value
|
||||||
pic_blob_make_bytevector(pic_state *pic)
|
pic_blob_make_bytevector(pic_state *pic)
|
||||||
{
|
{
|
||||||
|
@ -235,6 +262,7 @@ void
|
||||||
pic_init_blob(pic_state *pic)
|
pic_init_blob(pic_state *pic)
|
||||||
{
|
{
|
||||||
pic_defun(pic, "bytevector?", pic_blob_bytevector_p);
|
pic_defun(pic, "bytevector?", pic_blob_bytevector_p);
|
||||||
|
pic_defun(pic, "bytevector", pic_blob_bytevector);
|
||||||
pic_defun(pic, "make-bytevector", pic_blob_make_bytevector);
|
pic_defun(pic, "make-bytevector", pic_blob_make_bytevector);
|
||||||
pic_defun(pic, "bytevector-length", pic_blob_bytevector_length);
|
pic_defun(pic, "bytevector-length", pic_blob_bytevector_length);
|
||||||
pic_defun(pic, "bytevector-u8-ref", pic_blob_bytevector_u8_ref);
|
pic_defun(pic, "bytevector-u8-ref", pic_blob_bytevector_u8_ref);
|
||||||
|
|
Loading…
Reference in New Issue