mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-12 15:27:36 +02:00
Added more u8 primitives
This commit is contained in:
parent
d73686194b
commit
d3bbc46b29
3 changed files with 63 additions and 0 deletions
|
@ -156,7 +156,10 @@ object Cyc_vector_ref(void *d, object v, object k);
|
|||
object Cyc_vector_set(void *d, object v, object k, object obj);
|
||||
object Cyc_make_vector(void *data, object cont, int argc, object len, ...);
|
||||
object Cyc_make_bytevector(void *data, object cont, int argc, object len, ...);
|
||||
object Cyc_bytevector(void *data, object cont, int argc, object bval, ...);
|
||||
object Cyc_bytevector_length(void *data, object bv);
|
||||
object Cyc_bytevector_u8_ref(void *data, object bv, object k);
|
||||
object Cyc_bytevector_u8_set(void *data, object bv, object k, object b);
|
||||
object Cyc_list2vector(void *data, object cont, object l);
|
||||
object Cyc_number2string(void *d, object cont, object n);
|
||||
object Cyc_symbol2string(void *d, object cont, object sym) ;
|
||||
|
|
|
@ -303,6 +303,8 @@ typedef vector_type *vector;
|
|||
typedef struct {gc_header_type hdr; tag_type tag; int len; char *data;} bytevector_type;
|
||||
typedef bytevector_type *bytevector;
|
||||
|
||||
#define make_empty_bytevector(v) bytevector_type v; v.hdr.mark = gc_color_red; v.hdr.grayed = 0; v.tag = bytevector_tag; v.len = 0; v.data = NULL;
|
||||
|
||||
/* Define cons type. */
|
||||
|
||||
typedef struct {gc_header_type hdr; tag_type tag; object cons_car,cons_cdr;} cons_type;
|
||||
|
|
58
runtime.c
58
runtime.c
|
@ -1392,6 +1392,64 @@ object Cyc_make_bytevector(void *data, object cont, int argc, object len, ...) {
|
|||
return_closcall1(data, cont, bv);
|
||||
}
|
||||
|
||||
object Cyc_bytevector(void *data, object cont, int argc, object bval, ...) {
|
||||
int i = 0, val;
|
||||
va_list ap;
|
||||
object tmp;
|
||||
char *buffer;
|
||||
make_empty_bytevector(bv);
|
||||
if (argc > 0) {
|
||||
Cyc_check_int(data, bval);
|
||||
buffer = alloca(sizeof(char) * argc);
|
||||
val = obj_is_int(bval) ? obj_obj2int(bval) : integer_value(bval);
|
||||
buffer[i] = val;
|
||||
va_start(ap, bval);
|
||||
for(i = 1; i < argc; i++) {
|
||||
tmp = va_arg(ap, object);
|
||||
Cyc_check_int(data, tmp);
|
||||
val = obj_is_int(tmp) ? obj_obj2int(tmp) : integer_value(tmp);
|
||||
buffer[i] = val;
|
||||
}
|
||||
va_end(ap);
|
||||
}
|
||||
return_closcall1(data, cont, &bv);
|
||||
}
|
||||
|
||||
object Cyc_bytevector_u8_ref(void *data, object bv, object k) {
|
||||
const char *buf;
|
||||
int idx, val;
|
||||
|
||||
Cyc_check_bvec(data, bv);
|
||||
Cyc_check_int(data, k);
|
||||
|
||||
buf = ((bytevector)bv)->data;
|
||||
idx = obj_is_int(k) ? obj_obj2int(k) : integer_value(k);
|
||||
|
||||
if (idx < 0 || idx >= ((bytevector)bv)->len) {
|
||||
Cyc_rt_raise2(data, "bytevector-u8-ref - invalid index", k);
|
||||
}
|
||||
|
||||
val = buf[idx];
|
||||
return obj_int2obj(val);
|
||||
}
|
||||
|
||||
object Cyc_bytevector_u8_set(void *data, object bv, object k, object b) {
|
||||
char *buf;
|
||||
int idx, len, val;
|
||||
|
||||
Cyc_check_bvec(data, bv);
|
||||
Cyc_check_int(data, k);
|
||||
Cyc_check_int(data, b);
|
||||
|
||||
buf = ((bytevector)bv)->data;
|
||||
idx = obj_is_int(k) ? obj_obj2int(k) : integer_value(k),
|
||||
len = ((bytevector)bv)->len;
|
||||
|
||||
Cyc_check_bounds(data, "bytevector-u8-set!", len, idx);
|
||||
buf[idx] = obj_obj2int(b);
|
||||
return bv;
|
||||
}
|
||||
|
||||
object Cyc_bytevector_length(void *data, object bv) {
|
||||
if (!nullp(bv) && !is_value_type(bv) && ((list)bv)->tag == bytevector_tag) {
|
||||
return obj_int2obj(((bytevector)bv)->len);
|
||||
|
|
Loading…
Add table
Reference in a new issue