
louise
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#1207 · main · 10 min 04 s
1Étoiles
0Forks
0Issues
| 1 | --- |
| 2 | source: crates/louise_bindgen/tests/generate.rs |
| 3 | expression: b.c |
| 4 | --- |
| 5 | /* The C shim of the bindings for kitchen.h, generated by `louise bindgen`: |
| 6 | * do not edit, regenerate. */ |
| 7 | #include <stdbool.h> |
| 8 | #include <stdint.h> |
| 9 | |
| 10 | #include "louise_rt.h" |
| 11 | #include "kitchen.h" |
| 12 | |
| 13 | /* Int to the C integer type T and back: a value out of range panics. An |
| 14 | * Int may be big (ADR 0014): it is read with tl_int_to_i64 and made with |
| 15 | * tl_int_from_i64. */ |
| 16 | #define LOUISE_FITS(T, x) ((int64_t)(T)(x) == (x) && ((T)(x) < 0) == ((x) < 0)) |
| 17 | #define LOUISE_I64_OK(x) ((x) < 0 || (uint64_t)(x) <= (uint64_t)INT64_MAX) |
| 18 | |
| 19 | static void louise_finalize_KMap(void *p) { k_map_free(p); } |
| 20 | |
| 21 | /* void (*)(const char *key, int64_t value, void *env) */ |
| 22 | static void louise_trampoline_0(const char *a0, int64_t a1, void *env) { |
| 23 | const tl_callback *cb = env; |
| 24 | if (tl_callback_failed(cb)) return; |
| 25 | if (!a0) { tl_panic_str(cb->ctx, "a callback argument is NULL"); return; } |
| 26 | if (!LOUISE_I64_OK(a1)) { tl_panic_str(cb->ctx, "a callback argument is out of Int's range"); return; } |
| 27 | tl_value args[] = {tl_string_cstr(cb->ctx, a0), tl_int_from_i64(cb->ctx, (int64_t)a1)}; |
| 28 | tl_value r = tl_callback_call(cb, 2, args); |
| 29 | tl_drop(cb->ctx, r); |
| 30 | } |
| 31 | |
| 32 | /* k_weight */ |
| 33 | static double louise_trampoline_1(void *env, double a1, bool a2) { |
| 34 | const tl_callback *cb = env; |
| 35 | if (tl_callback_failed(cb)) return 0; |
| 36 | tl_value args[] = {tl_float_from(cb->ctx, (double)a1), tl_bool(a2)}; |
| 37 | tl_value r = tl_callback_call(cb, 2, args); |
| 38 | if (tl_callback_failed(cb)) return 0; |
| 39 | double x = tl_float_get(r); |
| 40 | tl_drop(cb->ctx, r); |
| 41 | return (double)x; |
| 42 | } |
| 43 | |
| 44 | /* int k_add(int a, int b) */ |
| 45 | tl_value louise_k_add(tl_ctx *ctx, tl_value p0, tl_value p1) { |
| 46 | int64_t vp0; if (!tl_int_to_i64(p0, &vp0) || !LOUISE_FITS(int, vp0)) return tl_panic_str(ctx, "k_add: `a` is out of range for int"); |
| 47 | int64_t vp1; if (!tl_int_to_i64(p1, &vp1) || !LOUISE_FITS(int, vp1)) return tl_panic_str(ctx, "k_add: `b` is out of range for int"); |
| 48 | int r = k_add((int)vp0, (int)vp1); |
| 49 | if (!LOUISE_I64_OK(r)) return tl_panic_str(ctx, "k_add: the result is out of Int's range"); |
| 50 | return tl_int_from_i64(ctx, (int64_t)r); |
| 51 | } |
| 52 | |
| 53 | /* unsigned long k_hash(uint64_t seed, short salt) */ |
| 54 | tl_value louise_k_hash(tl_ctx *ctx, tl_value p0, tl_value p1) { |
| 55 | int64_t vp0; if (!tl_int_to_i64(p0, &vp0) || !LOUISE_FITS(uint64_t, vp0)) return tl_panic_str(ctx, "k_hash: `seed` is out of range for uint64_t"); |
| 56 | int64_t vp1; if (!tl_int_to_i64(p1, &vp1) || !LOUISE_FITS(short, vp1)) return tl_panic_str(ctx, "k_hash: `salt` is out of range for short"); |
| 57 | unsigned long r = k_hash((uint64_t)vp0, (short)vp1); |
| 58 | if (!LOUISE_I64_OK(r)) return tl_panic_str(ctx, "k_hash: the result is out of Int's range"); |
| 59 | return tl_int_from_i64(ctx, (int64_t)r); |
| 60 | } |
| 61 | |
| 62 | /* long long k_wide(long long x) */ |
| 63 | tl_value louise_k_wide(tl_ctx *ctx, tl_value p0) { |
| 64 | int64_t vp0; if (!tl_int_to_i64(p0, &vp0) || !LOUISE_FITS(long long, vp0)) return tl_panic_str(ctx, "k_wide: `x` is out of range for long long"); |
| 65 | long long r = k_wide((long long)vp0); |
| 66 | if (!LOUISE_I64_OK(r)) return tl_panic_str(ctx, "k_wide: the result is out of Int's range"); |
| 67 | return tl_int_from_i64(ctx, (int64_t)r); |
| 68 | } |
| 69 | |
| 70 | /* double k_scale(double x, float by) */ |
| 71 | tl_value louise_k_scale(tl_ctx *ctx, tl_value p0, tl_value p1) { |
| 72 | double r = k_scale((double)tl_float_get(p0), (float)tl_float_get(p1)); |
| 73 | return tl_float_from(ctx, (double)r); |
| 74 | } |
| 75 | |
| 76 | /* bool k_is_even(int64_t n) */ |
| 77 | tl_value louise_k_is_even(tl_ctx *ctx, tl_value p0) { |
| 78 | int64_t vp0; if (!tl_int_to_i64(p0, &vp0) || !LOUISE_FITS(int64_t, vp0)) return tl_panic_str(ctx, "k_is_even: `n` is out of range for int64_t"); |
| 79 | bool r = k_is_even((int64_t)vp0); |
| 80 | return tl_bool(r); |
| 81 | } |
| 82 | |
| 83 | /* void k_reset(void) */ |
| 84 | tl_value louise_k_reset(tl_ctx *ctx) { |
| 85 | (void)ctx; |
| 86 | k_reset(); |
| 87 | return TL_UNIT; |
| 88 | } |
| 89 | |
| 90 | /* k_code k_last_error(void) */ |
| 91 | tl_value louise_k_last_error(tl_ctx *ctx) { |
| 92 | k_code r = k_last_error(); |
| 93 | if (!LOUISE_I64_OK(r)) return tl_panic_str(ctx, "k_last_error: the result is out of Int's range"); |
| 94 | return tl_int_from_i64(ctx, (int64_t)r); |
| 95 | } |
| 96 | |
| 97 | /* size_t k_count(const char *text, size_t text_len, char c) */ |
| 98 | tl_value louise_k_count(tl_ctx *ctx, tl_value p0, tl_value p1) { |
| 99 | if (!LOUISE_FITS(size_t, (int64_t)tl_string_len(p0))) return tl_panic_str(ctx, "k_count: `text` is too long"); |
| 100 | int64_t vp1; if (!tl_int_to_i64(p1, &vp1) || !LOUISE_FITS(char, vp1)) return tl_panic_str(ctx, "k_count: `c` is out of range for char"); |
| 101 | size_t r = k_count(tl_string_ptr(p0), (size_t)tl_string_len(p0), (char)vp1); |
| 102 | if (!LOUISE_I64_OK(r)) return tl_panic_str(ctx, "k_count: the result is out of Int's range"); |
| 103 | return tl_int_from_i64(ctx, (int64_t)r); |
| 104 | } |
| 105 | |
| 106 | /* int k_parse(const char *s) */ |
| 107 | tl_value louise_k_parse(tl_ctx *ctx, tl_value p0) { |
| 108 | int r = k_parse(tl_string_ptr(p0)); |
| 109 | if (!LOUISE_I64_OK(r)) return tl_panic_str(ctx, "k_parse: the result is out of Int's range"); |
| 110 | return tl_int_from_i64(ctx, (int64_t)r); |
| 111 | } |
| 112 | |
| 113 | /* const char *k_name(int code) */ |
| 114 | tl_value louise_k_name(tl_ctx *ctx, tl_value p0) { |
| 115 | int64_t vp0; if (!tl_int_to_i64(p0, &vp0) || !LOUISE_FITS(int, vp0)) return tl_panic_str(ctx, "k_name: `code` is out of range for int"); |
| 116 | const char *r = k_name((int)vp0); |
| 117 | if (!r) return tl_panic_str(ctx, "k_name returned NULL"); |
| 118 | return tl_string_cstr(ctx, r); |
| 119 | } |
| 120 | |
| 121 | /* k_map *k_map_new(size_t capacity) */ |
| 122 | tl_value louise_k_map_new(tl_ctx *ctx, tl_value p0) { |
| 123 | int64_t vp0; if (!tl_int_to_i64(p0, &vp0) || !LOUISE_FITS(size_t, vp0)) return tl_panic_str(ctx, "k_map_new: `capacity` is out of range for size_t"); |
| 124 | k_map *r = k_map_new((size_t)vp0); |
| 125 | if (!r) return tl_panic_str(ctx, "k_map_new returned NULL"); |
| 126 | return tl_resource_new(ctx, (void *)r, louise_finalize_KMap, false); |
| 127 | } |
| 128 | |
| 129 | /* k_map *k_map_copy(const k_map *m) */ |
| 130 | tl_value louise_k_map_copy(tl_ctx *ctx, tl_value p0) { |
| 131 | k_map *r = k_map_copy(tl_resource_get(p0)); |
| 132 | if (!r) return tl_panic_str(ctx, "k_map_copy returned NULL"); |
| 133 | return tl_resource_new(ctx, (void *)r, louise_finalize_KMap, false); |
| 134 | } |
| 135 | |
| 136 | /* bool k_map_put(k_map *m, const char *key, int64_t value) */ |
| 137 | tl_value louise_k_map_put(tl_ctx *ctx, tl_value p0, tl_value p1, tl_value p2) { |
| 138 | int64_t vp2; if (!tl_int_to_i64(p2, &vp2) || !LOUISE_FITS(int64_t, vp2)) return tl_panic_str(ctx, "k_map_put: `value` is out of range for int64_t"); |
| 139 | bool r = k_map_put(tl_resource_get(p0), tl_string_ptr(p1), (int64_t)vp2); |
| 140 | return tl_bool(r); |
| 141 | } |
| 142 | |
| 143 | /* struct k_buf *k_buf_create(void) */ |
| 144 | tl_value louise_k_buf_create(tl_ctx *ctx) { |
| 145 | struct k_buf *r = k_buf_create(); |
| 146 | if (!r) return tl_panic_str(ctx, "k_buf_create returned NULL"); |
| 147 | return tl_resource_new(ctx, (void *)r, NULL, false); |
| 148 | } |
| 149 | |
| 150 | /* void k_buf_append(struct k_buf *b, const char *bytes, size_t n) */ |
| 151 | tl_value louise_k_buf_append(tl_ctx *ctx, tl_value p0, tl_value p1) { |
| 152 | if (!LOUISE_FITS(size_t, (int64_t)tl_string_len(p1))) return tl_panic_str(ctx, "k_buf_append: `bytes` is too long"); |
| 153 | k_buf_append(tl_resource_get(p0), tl_string_ptr(p1), (size_t)tl_string_len(p1)); |
| 154 | return TL_UNIT; |
| 155 | } |
| 156 | |
| 157 | /* void k_map_each(k_map *m, void (*visit)(const char *key, int64_t value, void *env), void *env) */ |
| 158 | tl_value louise_k_map_each(tl_ctx *ctx, tl_value p0, tl_value p1) { |
| 159 | tl_callback cb; |
| 160 | tl_callback_begin(ctx, &cb, p1); |
| 161 | k_map_each(tl_resource_get(p0), louise_trampoline_0, &cb); |
| 162 | return tl_callback_end(&cb, TL_UNIT); |
| 163 | } |
| 164 | |
| 165 | /* double k_integrate(k_weight f, void *data, double from, double to) */ |
| 166 | tl_value louise_k_integrate(tl_ctx *ctx, tl_value p0, tl_value p1, tl_value p2) { |
| 167 | tl_callback cb; |
| 168 | tl_callback_begin(ctx, &cb, p0); |
| 169 | double r = k_integrate(louise_trampoline_1, &cb, (double)tl_float_get(p1), (double)tl_float_get(p2)); |
| 170 | tl_callback_end(&cb, TL_UNIT); |
| 171 | if (tl_callback_failed(&cb)) { return TL_UNIT; } |
| 172 | return tl_float_from(ctx, (double)r); |
| 173 | } |