Skip to content

Commit

Permalink
try to get eurydice_glue formatting right
Browse files Browse the repository at this point in the history
  • Loading branch information
franziskuskiefer committed Sep 19, 2024
1 parent e2639a9 commit 72563a3
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions libcrux-ml-kem/cg/eurydice_glue.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ typedef struct {
// (included), and an end index in x (excluded). The argument x must be suitably
// cast to something that can decay (see remark above about how pointer
// arithmetic works in C), meaning either pointer or array type.
#define EURYDICE_SLICE(x, start, end) \
#define EURYDICE_SLICE(x, start, end) \
(CLITERAL(Eurydice_slice){.ptr = (void *)(x + start), .len = end - start})
#define EURYDICE_SLICE_LEN(s, _) s.len
// This macro is a pain because in case the dereferenced element type is an
Expand All @@ -62,40 +62,40 @@ typedef struct {
// adds an extra argument to this macro at the last minute so that we have the
// correct type of *pointers* to elements.
#define Eurydice_slice_index(s, i, t, t_ptr_t) (((t_ptr_t)s.ptr)[i])
#define Eurydice_slice_subslice(s, r, t, _) \
#define Eurydice_slice_subslice(s, r, t, _) \
EURYDICE_SLICE((t *)s.ptr, r.start, r.end)
// Variant for when the start and end indices are statically known (i.e., the
// range argument `r` is a literal).
#define Eurydice_slice_subslice2(s, start, end, t) \
#define Eurydice_slice_subslice2(s, start, end, t) \
EURYDICE_SLICE((t *)s.ptr, start, end)
#define Eurydice_slice_subslice_to(s, subslice_end_pos, t, _) \
#define Eurydice_slice_subslice_to(s, subslice_end_pos, t, _) \
EURYDICE_SLICE((t *)s.ptr, 0, subslice_end_pos)
#define Eurydice_slice_subslice_from(s, subslice_start_pos, t, _) \
#define Eurydice_slice_subslice_from(s, subslice_start_pos, t, _) \
EURYDICE_SLICE((t *)s.ptr, subslice_start_pos, s.len)
#define Eurydice_array_to_slice(end, x, t) \
EURYDICE_SLICE(x, 0, \
#define Eurydice_array_to_slice(end, x, t) \
EURYDICE_SLICE(x, 0, \
end) /* x is already at an array type, no need for cast */
#define Eurydice_array_to_subslice(_arraylen, x, r, t, _) \
#define Eurydice_array_to_subslice(_arraylen, x, r, t, _) \
EURYDICE_SLICE((t *)x, r.start, r.end)
// Same as above, variant for when start and end are statically known
#define Eurydice_array_to_subslice2(x, start, end, t) \
#define Eurydice_array_to_subslice2(x, start, end, t) \
EURYDICE_SLICE((t *)x, start, end)
#define Eurydice_array_to_subslice_to(_size, x, r, t, _range_t) \
#define Eurydice_array_to_subslice_to(_size, x, r, t, _range_t) \
EURYDICE_SLICE((t *)x, 0, r)
#define Eurydice_array_to_subslice_from(size, x, r, t, _range_t) \
#define Eurydice_array_to_subslice_from(size, x, r, t, _range_t) \
EURYDICE_SLICE((t *)x, r, size)
#define Eurydice_slice_len(s, t) EURYDICE_SLICE_LEN(s, t)
#define Eurydice_slice_copy(dst, src, t) \
#define Eurydice_slice_copy(dst, src, t) \
memcpy(dst.ptr, src.ptr, dst.len * sizeof(t))
#define core_array___Array_T__N__23__as_slice(len_, ptr_, t, _ret_t) \
#define core_array___Array_T__N__23__as_slice(len_, ptr_, t, _ret_t) \
((Eurydice_slice){.ptr = ptr_, .len = len_})

#define core_array___core__clone__Clone_for__Array_T__N___20__clone( \
len, src, dst, elem_type, _ret_t) \
#define core_array___core__clone__Clone_for__Array_T__N___20__clone( \
len, src, dst, elem_type, _ret_t) \
(memcpy(dst, src, len * sizeof(elem_type)))
#define TryFromSliceError uint8_t

#define Eurydice_array_eq(sz, a1, a2, t, _) \
#define Eurydice_array_eq(sz, a1, a2, t, _) \
(memcmp(a1, a2, sz * sizeof(t)) == 0)
#define core_array_equality___core__cmp__PartialEq__Array_U__N___for__Array_T__N____eq( \
sz, a1, a2, t, _, _ret_t) \
Expand All @@ -104,21 +104,21 @@ typedef struct {
sz, a1, a2, t, _, _ret_t) \
Eurydice_array_eq(sz, a1, ((a2)->ptr), t, _)

#define Eurydice_slice_split_at(slice, mid, element_type, ret_t) \
(CLITERAL(ret_t){ \
.fst = EURYDICE_SLICE((element_type *)slice.ptr, 0, mid), \
#define Eurydice_slice_split_at(slice, mid, element_type, ret_t) \
(CLITERAL(ret_t){ \
.fst = EURYDICE_SLICE((element_type *)slice.ptr, 0, mid), \
.snd = EURYDICE_SLICE((element_type *)slice.ptr, mid, slice.len)})
#define Eurydice_slice_split_at_mut(slice, mid, element_type, ret_t) \
(CLITERAL(ret_t){ \
.fst = {.ptr = slice.ptr, .len = mid}, \
.snd = {.ptr = (char *)slice.ptr + mid * sizeof(element_type), \
#define Eurydice_slice_split_at_mut(slice, mid, element_type, ret_t) \
(CLITERAL(ret_t){ \
.fst = {.ptr = slice.ptr, .len = mid}, \
.snd = {.ptr = (char *)slice.ptr + mid * sizeof(element_type), \
.len = slice.len - mid}})

// Conversion of slice to an array, rewritten (by Eurydice) to name the
// destination array, since arrays are not values in C.
// N.B.: see note in karamel/lib/Inlining.ml if you change this.
#define Eurydice_slice_to_array2(dst, src, _, t_arr) \
Eurydice_slice_to_array3(&(dst)->tag, (char *)&(dst)->val.case_Ok, src, \
#define Eurydice_slice_to_array2(dst, src, _, t_arr) \
Eurydice_slice_to_array3(&(dst)->tag, (char *)&(dst)->val.case_Ok, src, \
sizeof(t_arr))

static inline void Eurydice_slice_to_array3(uint8_t *dst_tag, char *dst_ok,
Expand Down Expand Up @@ -162,9 +162,9 @@ static inline uint8_t core_num__u8_6__wrapping_sub(uint8_t x, uint8_t y) {

// ITERATORS

#define Eurydice_range_iter_next(iter_ptr, t, ret_t) \
(((iter_ptr)->start == (iter_ptr)->end) \
? (CLITERAL(ret_t){.tag = None, .f0 = 0}) \
#define Eurydice_range_iter_next(iter_ptr, t, ret_t) \
(((iter_ptr)->start == (iter_ptr)->end) \
? (CLITERAL(ret_t){.tag = None, .f0 = 0}) \
: (CLITERAL(ret_t){.tag = Some, .f0 = (iter_ptr)->start++}))

#define core_iter_range___core__iter__traits__iterator__Iterator_for_core__ops__range__Range_A__TraitClause_0___6__next \
Expand Down

0 comments on commit 72563a3

Please sign in to comment.