From 79101a219423fa007987666f6d3e9fe6c6a6fa45 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Wed, 23 Mar 2016 20:48:25 -0400 Subject: [PATCH] Bugfixes for bytevector --- runtime.c | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/runtime.c b/runtime.c index 3beab532..f4c7f72e 100644 --- a/runtime.c +++ b/runtime.c @@ -593,7 +593,7 @@ object Cyc_display(object x, FILE *port) if (i > 0) { fprintf(port, " "); } - fprintf(port, "%d", (int)(((bytevector)x)->data[i])); + fprintf(port, "%u", (int)(((bytevector)x)->data[i])); } fprintf(port, ")"); break; @@ -1392,7 +1392,33 @@ 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, ...) { +#define Cyc_bytevector_va_list(argc) { \ + 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); \ + bv.len = argc; \ + bv.data = buffer; \ + } \ + return_closcall1(data, cont, &bv); \ +} + +void dispatch_bytevector(void *data, int _argc, object clo, object cont, object bval, ...) { + int argc = _argc - 1; int i = 0, val; va_list ap; object tmp; @@ -1411,13 +1437,20 @@ object Cyc_bytevector(void *data, object cont, int argc, object bval, ...) { buffer[i] = val; } va_end(ap); + bv.len = argc; + bv.data = buffer; } return_closcall1(data, cont, &bv); } +object Cyc_bytevector(void *data, object cont, int _argc, object bval, ...) { + Cyc_bytevector_va_list(_argc); +} + object Cyc_bytevector_u8_ref(void *data, object bv, object k) { const char *buf; - int idx, val; + int idx; + unsigned int val; Cyc_check_bvec(data, bv); Cyc_check_int(data, k); @@ -1446,7 +1479,7 @@ object Cyc_bytevector_u8_set(void *data, object bv, object k, object b) { len = ((bytevector)bv)->len; Cyc_check_bounds(data, "bytevector-u8-set!", len, idx); - buf[idx] = obj_obj2int(b); + buf[idx] = (unsigned char)(obj_obj2int(b)); return bv; } @@ -1921,7 +1954,8 @@ void _bytevector_91u8_91set_67(void *data, object cont, object args) { return_closcall1(data, cont, bv); }} void _bytevector(void *data, object cont, object args) { - return_closcall1(data, cont, boolean_f); } // TODO + object argc = Cyc_length(data, args); + dispatch(data, obj_obj2int(argc), (function_type)dispatch_bytevector, cont, cont, args); } void _vector_91length(void *data, object cont, object args){ Cyc_check_num_args(data, "vector_91length", 1, args);