Merge 134a768172 into 17e3c7a5c5
This commit is contained in:
commit
b293bd97a4
6 changed files with 39 additions and 1 deletions
|
|
@ -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) \
|
||||
|
|
|
|||
|
|
@ -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_
|
||||
|
|
|
|||
|
|
@ -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':
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
9
crates/language/wasm/src/wctype.c
Normal file
9
crates/language/wasm/src/wctype.c
Normal 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;
|
||||
}
|
||||
|
|
@ -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"),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue