diff options
author | Andy Wingo <wingo@pobox.com> | 2009-06-05 16:31:38 +0200 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2009-06-05 16:31:38 +0200 |
commit | 782a82eed13abb64393f7acad92758ae191ce509 (patch) | |
tree | 517a209c703d8810789dbdf3cfc23a835e21e5b1 /libguile/bytevectors.c | |
parent | a9b0f876c12bbbca9bdf1890eb014a30f004d9f8 (diff) | |
download | guile-782a82eed13abb64393f7acad92758ae191ce509.tar.gz |
add ability to compile uniform arrays
* module/rnrs/bytevector.scm (rnrs):
* libguile/bytevectors.h:
* libguile/bytevectors.c (scm_uniform_array_to_bytevector): New function.
* libguile/unif.h:
* libguile/unif.c (scm_from_contiguous_typed_array): New function.
* libguile/vm-i-loader.c (load-array): New instruction, for loading byte
data into uniform vectors. Currently it copies out the data, though in
the future we could avoid that.
* module/language/assembly.scm (align-code): New exported function,
aligns code on some boundary.
(align-program): Use align-code.
* module/language/assembly/compile-bytecode.scm (write-bytecode): Support
the load-array instruction.
* module/language/glil/compile-assembly.scm (dump-object): Dump uniform
arrays. Neat :)
Diffstat (limited to 'libguile/bytevectors.c')
-rw-r--r-- | libguile/bytevectors.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/libguile/bytevectors.c b/libguile/bytevectors.c index 4c3a353a1..ced1b082f 100644 --- a/libguile/bytevectors.c +++ b/libguile/bytevectors.c @@ -29,6 +29,8 @@ #include "libguile/strings.h" #include "libguile/validate.h" #include "libguile/ieee-754.h" +#include "libguile/unif.h" +#include "libguile/srfi-4.h" #include <byteswap.h> #include <striconveh.h> @@ -511,6 +513,37 @@ SCM_DEFINE (scm_bytevector_copy, "bytevector-copy", 1, 0, 0, } #undef FUNC_NAME +SCM_DEFINE (scm_uniform_array_to_bytevector, "uniform-array->bytevector", + 1, 0, 0, (SCM array), + "Return a newly allocated bytevector whose contents\n" + "will be copied from the uniform array @var{array}.") +#define FUNC_NAME s_scm_uniform_array_to_bytevector +{ + SCM contents, ret; + size_t len; + scm_t_array_handle h; + const void *base; + size_t sz; + + contents = scm_array_contents (array, SCM_BOOL_T); + if (scm_is_false (contents)) + scm_wrong_type_arg_msg (FUNC_NAME, 0, array, "uniform contiguous array"); + + scm_array_get_handle (contents, &h); + + base = scm_array_handle_uniform_elements (&h); + len = h.dims->inc * (h.dims->ubnd - h.dims->lbnd + 1); + sz = scm_array_handle_uniform_element_size (&h); + + ret = make_bytevector (len * sz); + memcpy (SCM_BYTEVECTOR_CONTENTS (ret), base, len * sz); + + scm_array_handle_release (&h); + + return ret; +} +#undef FUNC_NAME + /* Operations on bytes and octets. */ |