tobogganSe connecter

packages

The Louise packages, each released on its own

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

136 lignes · 7633 octetsBrut · Historique
1/* The C shim of the bindings for api.h, generated by `louise bindgen`:
2 * do not edit, regenerate. */
3#include <stdbool.h>
4#include <stdint.h>
5
6#include "louise_rt.h"
7#include "api.h"
8
9/* Int to the C integer type T and back: a value out of range panics. An
10 * Int may be big (ADR 0014): it is read with tl_int_to_i64 and made with
11 * tl_int_from_i64. */
12#define LOUISE_FITS(T, x) ((int64_t)(T)(x) == (x) && ((T)(x) < 0) == ((x) < 0))
13#define LOUISE_I64_OK(x) ((x) < 0 || (uint64_t)(x) <= (uint64_t)INT64_MAX)
14
15static void louise_finalize_SzlSort(void *p) { szl_sort_free(p); }
16
17/* int64_t szl_find(const char *haystack, size_t haystack_len, const char *needle, size_t needle_len) */
18tl_value louise_szl_find(tl_ctx *ctx, tl_value p0, tl_value p1) {
19 if (!LOUISE_FITS(size_t, (int64_t)tl_string_len(p0))) return tl_panic_str(ctx, "szl_find: `haystack` is too long");
20 if (!LOUISE_FITS(size_t, (int64_t)tl_string_len(p1))) return tl_panic_str(ctx, "szl_find: `needle` is too long");
21 int64_t r = szl_find(tl_string_ptr(p0), (size_t)tl_string_len(p0), tl_string_ptr(p1), (size_t)tl_string_len(p1));
22 if (!LOUISE_I64_OK(r)) return tl_panic_str(ctx, "szl_find: the result is out of Int's range");
23 return tl_int_from_i64(ctx, (int64_t)r);
24}
25
26/* int64_t szl_rfind(const char *haystack, size_t haystack_len, const char *needle, size_t needle_len) */
27tl_value louise_szl_rfind(tl_ctx *ctx, tl_value p0, tl_value p1) {
28 if (!LOUISE_FITS(size_t, (int64_t)tl_string_len(p0))) return tl_panic_str(ctx, "szl_rfind: `haystack` is too long");
29 if (!LOUISE_FITS(size_t, (int64_t)tl_string_len(p1))) return tl_panic_str(ctx, "szl_rfind: `needle` is too long");
30 int64_t r = szl_rfind(tl_string_ptr(p0), (size_t)tl_string_len(p0), tl_string_ptr(p1), (size_t)tl_string_len(p1));
31 if (!LOUISE_I64_OK(r)) return tl_panic_str(ctx, "szl_rfind: the result is out of Int's range");
32 return tl_int_from_i64(ctx, (int64_t)r);
33}
34
35/* size_t szl_count(const char *haystack, size_t haystack_len, const char *needle, size_t needle_len) */
36tl_value louise_szl_count(tl_ctx *ctx, tl_value p0, tl_value p1) {
37 if (!LOUISE_FITS(size_t, (int64_t)tl_string_len(p0))) return tl_panic_str(ctx, "szl_count: `haystack` is too long");
38 if (!LOUISE_FITS(size_t, (int64_t)tl_string_len(p1))) return tl_panic_str(ctx, "szl_count: `needle` is too long");
39 size_t r = szl_count(tl_string_ptr(p0), (size_t)tl_string_len(p0), tl_string_ptr(p1), (size_t)tl_string_len(p1));
40 if (!LOUISE_I64_OK(r)) return tl_panic_str(ctx, "szl_count: the result is out of Int's range");
41 return tl_int_from_i64(ctx, (int64_t)r);
42}
43
44/* int64_t szl_find_byte(const char *s, size_t len, uint8_t byte) */
45tl_value louise_szl_find_byte(tl_ctx *ctx, tl_value p0, tl_value p1) {
46 if (!LOUISE_FITS(size_t, (int64_t)tl_string_len(p0))) return tl_panic_str(ctx, "szl_find_byte: `s` is too long");
47 int64_t vp1; if (!tl_int_to_i64(p1, &vp1) || !LOUISE_FITS(uint8_t, vp1)) return tl_panic_str(ctx, "szl_find_byte: `byte` is out of range for uint8_t");
48 int64_t r = szl_find_byte(tl_string_ptr(p0), (size_t)tl_string_len(p0), (uint8_t)vp1);
49 if (!LOUISE_I64_OK(r)) return tl_panic_str(ctx, "szl_find_byte: the result is out of Int's range");
50 return tl_int_from_i64(ctx, (int64_t)r);
51}
52
53/* int64_t szl_rfind_byte(const char *s, size_t len, uint8_t byte) */
54tl_value louise_szl_rfind_byte(tl_ctx *ctx, tl_value p0, tl_value p1) {
55 if (!LOUISE_FITS(size_t, (int64_t)tl_string_len(p0))) return tl_panic_str(ctx, "szl_rfind_byte: `s` is too long");
56 int64_t vp1; if (!tl_int_to_i64(p1, &vp1) || !LOUISE_FITS(uint8_t, vp1)) return tl_panic_str(ctx, "szl_rfind_byte: `byte` is out of range for uint8_t");
57 int64_t r = szl_rfind_byte(tl_string_ptr(p0), (size_t)tl_string_len(p0), (uint8_t)vp1);
58 if (!LOUISE_I64_OK(r)) return tl_panic_str(ctx, "szl_rfind_byte: the result is out of Int's range");
59 return tl_int_from_i64(ctx, (int64_t)r);
60}
61
62/* int szl_order(const char *a, size_t a_len, const char *b, size_t b_len) */
63tl_value louise_szl_order(tl_ctx *ctx, tl_value p0, tl_value p1) {
64 if (!LOUISE_FITS(size_t, (int64_t)tl_string_len(p0))) return tl_panic_str(ctx, "szl_order: `a` is too long");
65 if (!LOUISE_FITS(size_t, (int64_t)tl_string_len(p1))) return tl_panic_str(ctx, "szl_order: `b` is too long");
66 int r = szl_order(tl_string_ptr(p0), (size_t)tl_string_len(p0), tl_string_ptr(p1), (size_t)tl_string_len(p1));
67 if (!LOUISE_I64_OK(r)) return tl_panic_str(ctx, "szl_order: the result is out of Int's range");
68 return tl_int_from_i64(ctx, (int64_t)r);
69}
70
71/* int64_t szl_hash(const char *s, size_t len, int64_t seed) */
72tl_value louise_szl_hash(tl_ctx *ctx, tl_value p0, tl_value p1) {
73 if (!LOUISE_FITS(size_t, (int64_t)tl_string_len(p0))) return tl_panic_str(ctx, "szl_hash: `s` is too long");
74 int64_t vp1; if (!tl_int_to_i64(p1, &vp1) || !LOUISE_FITS(int64_t, vp1)) return tl_panic_str(ctx, "szl_hash: `seed` is out of range for int64_t");
75 int64_t r = szl_hash(tl_string_ptr(p0), (size_t)tl_string_len(p0), (int64_t)vp1);
76 if (!LOUISE_I64_OK(r)) return tl_panic_str(ctx, "szl_hash: the result is out of Int's range");
77 return tl_int_from_i64(ctx, (int64_t)r);
78}
79
80/* int64_t szl_bytesum(const char *s, size_t len) */
81tl_value louise_szl_bytesum(tl_ctx *ctx, tl_value p0) {
82 if (!LOUISE_FITS(size_t, (int64_t)tl_string_len(p0))) return tl_panic_str(ctx, "szl_bytesum: `s` is too long");
83 int64_t r = szl_bytesum(tl_string_ptr(p0), (size_t)tl_string_len(p0));
84 if (!LOUISE_I64_OK(r)) return tl_panic_str(ctx, "szl_bytesum: the result is out of Int's range");
85 return tl_int_from_i64(ctx, (int64_t)r);
86}
87
88/* const char *szl_version(void) */
89tl_value louise_szl_version(tl_ctx *ctx) {
90 const char *r = szl_version();
91 if (!r) return tl_panic_str(ctx, "szl_version returned NULL");
92 return tl_string_cstr(ctx, r);
93}
94
95/* const char *szl_capabilities(void) */
96tl_value louise_szl_capabilities(tl_ctx *ctx) {
97 const char *r = szl_capabilities();
98 if (!r) return tl_panic_str(ctx, "szl_capabilities returned NULL");
99 return tl_string_cstr(ctx, r);
100}
101
102/* szl_sort *szl_sort_new(void) */
103tl_value louise_szl_sort_new(tl_ctx *ctx) {
104 szl_sort *r = szl_sort_new();
105 if (!r) return tl_panic_str(ctx, "szl_sort_new returned NULL");
106 return tl_resource_new(ctx, (void *)r, louise_finalize_SzlSort, false);
107}
108
109/* bool szl_sort_push(szl_sort *s, const char *text, size_t text_len) */
110tl_value louise_szl_sort_push(tl_ctx *ctx, tl_value p0, tl_value p1) {
111 if (!LOUISE_FITS(size_t, (int64_t)tl_string_len(p1))) return tl_panic_str(ctx, "szl_sort_push: `text` is too long");
112 bool r = szl_sort_push(tl_resource_get(p0), tl_string_ptr(p1), (size_t)tl_string_len(p1));
113 return tl_bool(r);
114}
115
116/* size_t szl_sort_count(const szl_sort *s) */
117tl_value louise_szl_sort_count(tl_ctx *ctx, tl_value p0) {
118 size_t r = szl_sort_count(tl_resource_get(p0));
119 if (!LOUISE_I64_OK(r)) return tl_panic_str(ctx, "szl_sort_count: the result is out of Int's range");
120 return tl_int_from_i64(ctx, (int64_t)r);
121}
122
123/* bool szl_sort_argsort(szl_sort *s) */
124tl_value louise_szl_sort_argsort(tl_ctx *ctx, tl_value p0) {
125 (void)ctx;
126 bool r = szl_sort_argsort(tl_resource_get(p0));
127 return tl_bool(r);
128}
129
130/* int64_t szl_sort_order(const szl_sort *s, size_t i) */
131tl_value louise_szl_sort_order(tl_ctx *ctx, tl_value p0, tl_value p1) {
132 int64_t vp1; if (!tl_int_to_i64(p1, &vp1) || !LOUISE_FITS(size_t, vp1)) return tl_panic_str(ctx, "szl_sort_order: `i` is out of range for size_t");
133 int64_t r = szl_sort_order(tl_resource_get(p0), (size_t)vp1);
134 if (!LOUISE_I64_OK(r)) return tl_panic_str(ctx, "szl_sort_order: the result is out of Int's range");
135 return tl_int_from_i64(ctx, (int64_t)r);
136}