Commit Graph

15 Commits

Author SHA1 Message Date
Veit Heller
f23d5d0448
refactor: make Maybe.zip a macro (#1138) 2021-01-19 15:59:37 +01:00
scottolsen
a66a5126e6 Move Byte Order type outside of the Binary module
Issue #698 points out an bug related to reloading. The illustious
hellerve@ has discovered that the issue relates to types defined in
modules--for some reason, upon reloading, the type's delete, copy, etc.
functions are doubly defined, resulting in too high or a number of
functions for Carp to work out the dependencies.
2020-03-20 19:02:55 -04:00
Scott Olsen
7c7a65c43e Refactor bytes->int-seq, add exact variants
Instead of returning an array of Maybe UintNs, we now return a pair
comprised of the array of interpreted int values and the number of bytes
that were'nt read/interpreted.

We also provide an `exact` variant of this function that returns a
Result instead of a Pair. If there are excess bytes in the sequence one
attempts to interpret, the `exact` functions return a `Result.Error`
containing the number of extra bytes. If the byte sequence is exact , a
`Success` containing the interpreted values is returned instead.
2020-02-20 14:12:38 -05:00
Scott Olsen
3c95c4baeb Use unsafe as a prefix in unsafe functions
This brings our function naming scheme into parallelism with other core
modules (e.g. Array.carp).
2020-02-18 13:56:52 -05:00
Scott Olsen
6fc0562028 Group functions by int type 2020-02-18 13:50:07 -05:00
Scott Olsen
a0bb6c5242 Add functions for converting intN seq(uence)s to byte seqs 2020-02-18 13:45:18 -05:00
Scott Olsen
05ab70b196 Add UintN->Byte conversions
Note that we do not need an unsafe variant of these conversions since
they are simple projections to and from the Uint types.
2020-02-18 13:35:35 -05:00
Scott Olsen
b8afc39a3b Binary: Make names consistent. Update docs.
Specifically, we now reference the explicit unsigned int types we return
in the docs for each function, and I've dropped the term byte-seq in
favor of bytes in all cases.
2020-02-18 11:50:24 -05:00
Scott Olsen
511663409e Add safe variants of byte conversion functions
I've also adopted a new naming strategy for these functions--the seq in
byte-seq was redundant, so we now just name these bytes->intN-seq.
2020-02-18 11:41:29 -05:00
Scott Olsen
d3e198673b Use partitions in byte-seq->int16-seq-unsafe
This change brings the implementation of `byte-seq->int16-seq-unsafe`
into parity with the implementations of its 32 and 64 bit brethren.

I've also cleaned up some of my previous sloppiness:

- Correct function names in doc and sig annotations.
- Remove extra spaces before newlines.
2020-02-17 19:03:52 -05:00
Scott Olsen
38efca11fa Remove byte-seq->int8-seq-unsafe
This function is obsolete after the introduction of Int8.from-bytes
2020-02-17 18:47:51 -05:00
Scott Olsen
dec44984ca Use StdInt types in binary conversion functions 2020-02-17 16:04:09 -05:00
Scott Olsen
4faa721e1d Add a function for retrieving the system endianness
The technique here feels a bit hacky, but it's the common way to do it.
We exploit the fact that ints are 16bits and chars are 8bits to grab the
first byte in a systems int representation, which is indicative of its
endianness.
2020-02-17 15:38:55 -05:00
Scott Olsen
d3f99487db Move partition function into the Array module
Since the function is generic over arrays, it makes more sense to house
it here.

I've also fixed an issue with its definition whereby we produced extra
empty arrays when n was greater than the original array length. We now
return an array of a length that matches precisely the number of
partitions with values we're able to create.
2020-02-16 15:57:38 -05:00
Scott Olsen
ea1505779d Add Binary module
The binary module implements functions for interpreting byte sequences
as int16, int32, or int64 values depending on a given endianess (the
Byte module implements support for interpreting bytes as int8 values).

It'd be nice if we could implement these functions in pure Carp, using
the Bytes module--but unfortunately we need to rely on some type
conversions in C, which are only possible by registering C functions for
performing the necessary conversions.

At the moment, all of these functions are unsafe (they access byte
arrays using unsafe-nth).
2020-02-16 15:15:54 -05:00