/* The C shim of the bindings for api.h, generated by `louise bindgen`: * do not edit, regenerate. */ #include #include #include "louise_rt.h" #include "api.h" /* Int to the C integer type T and back: a value out of range panics. An * Int may be big (ADR 0014): it is read with tl_int_to_i64 and made with * tl_int_from_i64. */ #define LOUISE_FITS(T, x) ((int64_t)(T)(x) == (x) && ((T)(x) < 0) == ((x) < 0)) #define LOUISE_I64_OK(x) ((x) < 0 || (uint64_t)(x) <= (uint64_t)INT64_MAX) static void louise_finalize_SzlSort(void *p) { szl_sort_free(p); } /* int64_t szl_find(const char *haystack, size_t haystack_len, const char *needle, size_t needle_len) */ tl_value louise_szl_find(tl_ctx *ctx, tl_value p0, tl_value p1) { if (!LOUISE_FITS(size_t, (int64_t)tl_string_len(p0))) return tl_panic_str(ctx, "szl_find: `haystack` is too long"); if (!LOUISE_FITS(size_t, (int64_t)tl_string_len(p1))) return tl_panic_str(ctx, "szl_find: `needle` is too long"); 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)); if (!LOUISE_I64_OK(r)) return tl_panic_str(ctx, "szl_find: the result is out of Int's range"); return tl_int_from_i64(ctx, (int64_t)r); } /* int64_t szl_rfind(const char *haystack, size_t haystack_len, const char *needle, size_t needle_len) */ tl_value louise_szl_rfind(tl_ctx *ctx, tl_value p0, tl_value p1) { if (!LOUISE_FITS(size_t, (int64_t)tl_string_len(p0))) return tl_panic_str(ctx, "szl_rfind: `haystack` is too long"); if (!LOUISE_FITS(size_t, (int64_t)tl_string_len(p1))) return tl_panic_str(ctx, "szl_rfind: `needle` is too long"); 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)); if (!LOUISE_I64_OK(r)) return tl_panic_str(ctx, "szl_rfind: the result is out of Int's range"); return tl_int_from_i64(ctx, (int64_t)r); } /* size_t szl_count(const char *haystack, size_t haystack_len, const char *needle, size_t needle_len) */ tl_value louise_szl_count(tl_ctx *ctx, tl_value p0, tl_value p1) { if (!LOUISE_FITS(size_t, (int64_t)tl_string_len(p0))) return tl_panic_str(ctx, "szl_count: `haystack` is too long"); if (!LOUISE_FITS(size_t, (int64_t)tl_string_len(p1))) return tl_panic_str(ctx, "szl_count: `needle` is too long"); 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)); if (!LOUISE_I64_OK(r)) return tl_panic_str(ctx, "szl_count: the result is out of Int's range"); return tl_int_from_i64(ctx, (int64_t)r); } /* int64_t szl_find_byte(const char *s, size_t len, uint8_t byte) */ tl_value louise_szl_find_byte(tl_ctx *ctx, tl_value p0, tl_value p1) { if (!LOUISE_FITS(size_t, (int64_t)tl_string_len(p0))) return tl_panic_str(ctx, "szl_find_byte: `s` is too long"); 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"); int64_t r = szl_find_byte(tl_string_ptr(p0), (size_t)tl_string_len(p0), (uint8_t)vp1); if (!LOUISE_I64_OK(r)) return tl_panic_str(ctx, "szl_find_byte: the result is out of Int's range"); return tl_int_from_i64(ctx, (int64_t)r); } /* int64_t szl_rfind_byte(const char *s, size_t len, uint8_t byte) */ tl_value louise_szl_rfind_byte(tl_ctx *ctx, tl_value p0, tl_value p1) { if (!LOUISE_FITS(size_t, (int64_t)tl_string_len(p0))) return tl_panic_str(ctx, "szl_rfind_byte: `s` is too long"); 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"); int64_t r = szl_rfind_byte(tl_string_ptr(p0), (size_t)tl_string_len(p0), (uint8_t)vp1); if (!LOUISE_I64_OK(r)) return tl_panic_str(ctx, "szl_rfind_byte: the result is out of Int's range"); return tl_int_from_i64(ctx, (int64_t)r); } /* int szl_order(const char *a, size_t a_len, const char *b, size_t b_len) */ tl_value louise_szl_order(tl_ctx *ctx, tl_value p0, tl_value p1) { if (!LOUISE_FITS(size_t, (int64_t)tl_string_len(p0))) return tl_panic_str(ctx, "szl_order: `a` is too long"); if (!LOUISE_FITS(size_t, (int64_t)tl_string_len(p1))) return tl_panic_str(ctx, "szl_order: `b` is too long"); int r = szl_order(tl_string_ptr(p0), (size_t)tl_string_len(p0), tl_string_ptr(p1), (size_t)tl_string_len(p1)); if (!LOUISE_I64_OK(r)) return tl_panic_str(ctx, "szl_order: the result is out of Int's range"); return tl_int_from_i64(ctx, (int64_t)r); } /* int64_t szl_hash(const char *s, size_t len, int64_t seed) */ tl_value louise_szl_hash(tl_ctx *ctx, tl_value p0, tl_value p1) { if (!LOUISE_FITS(size_t, (int64_t)tl_string_len(p0))) return tl_panic_str(ctx, "szl_hash: `s` is too long"); 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"); int64_t r = szl_hash(tl_string_ptr(p0), (size_t)tl_string_len(p0), (int64_t)vp1); if (!LOUISE_I64_OK(r)) return tl_panic_str(ctx, "szl_hash: the result is out of Int's range"); return tl_int_from_i64(ctx, (int64_t)r); } /* int64_t szl_bytesum(const char *s, size_t len) */ tl_value louise_szl_bytesum(tl_ctx *ctx, tl_value p0) { if (!LOUISE_FITS(size_t, (int64_t)tl_string_len(p0))) return tl_panic_str(ctx, "szl_bytesum: `s` is too long"); int64_t r = szl_bytesum(tl_string_ptr(p0), (size_t)tl_string_len(p0)); if (!LOUISE_I64_OK(r)) return tl_panic_str(ctx, "szl_bytesum: the result is out of Int's range"); return tl_int_from_i64(ctx, (int64_t)r); } /* const char *szl_version(void) */ tl_value louise_szl_version(tl_ctx *ctx) { const char *r = szl_version(); if (!r) return tl_panic_str(ctx, "szl_version returned NULL"); return tl_string_cstr(ctx, r); } /* const char *szl_capabilities(void) */ tl_value louise_szl_capabilities(tl_ctx *ctx) { const char *r = szl_capabilities(); if (!r) return tl_panic_str(ctx, "szl_capabilities returned NULL"); return tl_string_cstr(ctx, r); } /* szl_sort *szl_sort_new(void) */ tl_value louise_szl_sort_new(tl_ctx *ctx) { szl_sort *r = szl_sort_new(); if (!r) return tl_panic_str(ctx, "szl_sort_new returned NULL"); return tl_resource_new(ctx, (void *)r, louise_finalize_SzlSort, false); } /* bool szl_sort_push(szl_sort *s, const char *text, size_t text_len) */ tl_value louise_szl_sort_push(tl_ctx *ctx, tl_value p0, tl_value p1) { if (!LOUISE_FITS(size_t, (int64_t)tl_string_len(p1))) return tl_panic_str(ctx, "szl_sort_push: `text` is too long"); bool r = szl_sort_push(tl_resource_get(p0), tl_string_ptr(p1), (size_t)tl_string_len(p1)); return tl_bool(r); } /* size_t szl_sort_count(const szl_sort *s) */ tl_value louise_szl_sort_count(tl_ctx *ctx, tl_value p0) { size_t r = szl_sort_count(tl_resource_get(p0)); if (!LOUISE_I64_OK(r)) return tl_panic_str(ctx, "szl_sort_count: the result is out of Int's range"); return tl_int_from_i64(ctx, (int64_t)r); } /* bool szl_sort_argsort(szl_sort *s) */ tl_value louise_szl_sort_argsort(tl_ctx *ctx, tl_value p0) { (void)ctx; bool r = szl_sort_argsort(tl_resource_get(p0)); return tl_bool(r); } /* int64_t szl_sort_order(const szl_sort *s, size_t i) */ tl_value louise_szl_sort_order(tl_ctx *ctx, tl_value p0, tl_value p1) { 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"); int64_t r = szl_sort_order(tl_resource_get(p0), (size_t)vp1); if (!LOUISE_I64_OK(r)) return tl_panic_str(ctx, "szl_sort_order: the result is out of Int's range"); return tl_int_from_i64(ctx, (int64_t)r); }