Integrating bytevector-append

This commit is contained in:
Justin Ethier 2016-03-23 22:58:56 -04:00
parent 0128ff32b5
commit 56278989eb
2 changed files with 38 additions and 38 deletions

View file

@ -1426,45 +1426,42 @@ object Cyc_bytevector(void *data, object cont, int _argc, object bval, ...) {
}
#define Cyc_bytevector_append_va_list(argc) { \
int i = 0, buf_idx = 0, val, total_length = 0; \
va_list ap; \
object tmp; \
char *buffer; \
char **buffers = NULL; \
int *lengths = NULL; \
make_empty_bytevector(result); \
if (argc > 0) { \
buffers = alloca(sizeof(char *) * argc); \
lengths = alloca(sizeof(int) * argc); \
Cyc_check_bvec(data, bv); \
total_length = ((bytevector)bv)->len; \
lengths[0] = ((bytevector)bv)->len; \
buffers[0] = ((bytevector)bv)->data; \
va_start(ap, bv); \
for(i = 1; i < argc; i++) { \
tmp = va_arg(ap, object); \
Cyc_check_bvec(data, tmp); \
total_length += ((bytevector)tmp)->len; \
lengths[i] = ((bytevector)tmp)->len; \
buffers[i] = ((bytevector)tmp)->data; \
} \
va_end(ap); \
buffer = alloca(sizeof(char) * total_length); \
for (i = 0; i < argc; i++) { \
memcpy(&buffer[buf_idx], buffers[i], lengths[i]); \
buf_idx += lengths[i]; \
} \
result.len = total_length; \
result.data = buffer; \
} \
return_closcall1(data, cont, &result); \
}
void dispatch_bytevector_91append(void *data, int _argc, object clo, object cont, object bv, ...) {
//Cyc_bytevector_append_va_list((_argc - 1));
int argc = _argc - 1; // TODO: temporary
int i = 0, buf_idx = 0, val, total_length = 0;
va_list ap;
object tmp;
char *buffer;
char **buffers = NULL;
int *lengths = NULL;
make_empty_bytevector(result);
if (argc > 0) {
buffers = alloca(sizeof(char *) * argc);
lengths = alloca(sizeof(int) * argc);
Cyc_check_bvec(data, bv);
total_length = ((bytevector)bv)->len;
lengths[0] = ((bytevector)bv)->len;
buffers[0] = ((bytevector)bv)->data;
va_start(ap, bv);
for(i = 1; i < argc; i++) {
tmp = va_arg(ap, object);
Cyc_check_bvec(data, tmp);
total_length += ((bytevector)tmp)->len;
lengths[i] = ((bytevector)tmp)->len;
buffers[i] = ((bytevector)tmp)->data;
}
va_end(ap);
buffer = alloca(sizeof(char) * total_length);
for (i = 0; i < argc; i++) {
memcpy(&buffer[buf_idx], buffers[i], lengths[i]);
buf_idx += lengths[i];
}
result.len = total_length;
result.data = buffer;
}
return_closcall1(data, cont, &result);
Cyc_bytevector_append_va_list((_argc - 1));
}
object Cyc_bytevector_append(void *data, object cont, int _argc, object bval, ...) {

View file

@ -526,7 +526,8 @@
((eq? p 'list->string) "Cyc_list2string")
((eq? p 'make-bytevector) "Cyc_make_bytevector")
((eq? p 'bytevector-length) "Cyc_bytevector_length")
((eq? p 'bytevector) "Cyc_bytevector")
((eq? p 'bytevector) "Cyc_bytevector")
((eq? p 'bytevector-append) "Cyc_bytevector_append")
((eq? p 'bytevector-u8-ref) "Cyc_bytevector_u8_ref")
((eq? p 'bytevector-u8-set!) "Cyc_bytevector_u8_set")
((eq? p 'make-vector) "Cyc_make_vector")
@ -614,6 +615,7 @@
list->string
make-bytevector
bytevector-length
bytevector-append
bytevector
bytevector-u8-ref
bytevector-u8-set!
@ -669,7 +671,6 @@
((eq? p 'symbol->string) "object")
((eq? p 'substring) "object")
((eq? p 'make-bytevector) "object")
;((eq? p 'bytevector) "object")
((eq? p 'make-vector) "object")
((eq? p 'list->string) "object")
((eq? p 'list->vector) "object")
@ -706,6 +707,7 @@
read-char peek-char
symbol->string list->string substring string-append string->number
make-bytevector
bytevector-append
bytevector
bytevector-u8-ref
bytevector-u8-set!
@ -723,6 +725,7 @@
string->number string-append
make-bytevector
bytevector
bytevector-append
make-vector
+ - * /))))