This commit is contained in:
Sasha Koss 2026-01-04 21:31:19 -08:00 committed by GitHub
commit b293bd97a4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 39 additions and 1 deletions

View file

@ -4,7 +4,7 @@
#ifdef NDEBUG
#define assert(e) ((void)0)
#else
__attribute__((noreturn)) void __assert_fail(const char *assertion, const char *file, unsigned line, const char *function) {
__attribute__((noreturn)) static inline void __assert_fail(const char *assertion, const char *file, unsigned line, const char *function) {
__builtin_trap();
}
#define assert(expression) \

View file

@ -3,6 +3,8 @@
#include <stdint.h>
void *memchr(const void *src, int c, size_t n);
int memcmp(const void *lhs, const void *rhs, size_t count);
void *memcpy(void *restrict dst, const void *restrict src, size_t size);
@ -13,4 +15,6 @@ void *memset(void *dst, int value, size_t count);
int strncmp(const char *left, const char *right, size_t n);
char *strchr(const char *str, int c);
#endif // TREE_SITTER_WASM_STRING_H_

View file

@ -1,8 +1,14 @@
#ifndef TREE_SITTER_WASM_WCTYPE_H_
#define TREE_SITTER_WASM_WCTYPE_H_
#include <stdbool.h>
typedef int wint_t;
int iswlower(wint_t wch);
int iswupper(wint_t wch);
static inline bool iswalpha(wint_t wch) {
switch (wch) {
case L'a':

View file

@ -1,5 +1,13 @@
#include <string.h>
// Derived from musl (MIT): https://git.musl-libc.org/cgit/musl/tree/src/string/memchr.c
void *memchr(const void *src, int c, size_t n) {
const unsigned char *s = src;
c = (unsigned char)c;
for (; n && *s != c; s++, n--);
return n ? (void *)s : 0;
}
int memcmp(const void *lhs, const void *rhs, size_t count) {
const unsigned char *l = lhs;
const unsigned char *r = rhs;
@ -58,3 +66,13 @@ int strncmp(const char *left, const char *right, size_t n) {
}
return 0;
}
char *strchr(const char *str, int c) {
while (*str != (char)c) {
if (*str == '\0') {
return 0;
}
str++;
}
return (char *)str;
}

View file

@ -0,0 +1,9 @@
#include <wctype.h>
int iswlower(wint_t wch) {
return (unsigned)wch - L'a' < 26;
}
int iswupper(wint_t wch) {
return (unsigned)wch - L'A' < 26;
}

View file

@ -70,6 +70,7 @@ fn configure_wasm_build(config: &mut cc::Build) {
wasm_src.join("stdio.c"),
wasm_src.join("stdlib.c"),
wasm_src.join("string.c"),
wasm_src.join("wctype.c"),
]);
}