Update Files

This commit is contained in:
2025-01-22 16:18:30 +01:00
parent ed4603cf95
commit a36294b518
16718 changed files with 2960346 additions and 0 deletions

View File

@ -0,0 +1,7 @@
#pragma once
#ifdef NDEBUG
#define assert(condition)
#else
static void assert(int condition) {}
#endif

View File

@ -0,0 +1,3 @@
#pragma once
#define errno 0

100
Kha/Kinc/miniClib/math.c Normal file
View File

@ -0,0 +1,100 @@
#include "math.h"
#ifdef KINC_WASM
__attribute__((import_module("imports"), import_name("js_pow"))) float js_pow(float base, float exponent);
__attribute__((import_module("imports"), import_name("js_floor"))) float js_floor(float x);
__attribute__((import_module("imports"), import_name("js_sin"))) float js_sin(float x);
__attribute__((import_module("imports"), import_name("js_cos"))) float js_cos(float x);
__attribute__((import_module("imports"), import_name("js_tan"))) float js_tan(float x);
__attribute__((import_module("imports"), import_name("js_log"))) float js_log(float x);
__attribute__((import_module("imports"), import_name("js_exp"))) float js_exp(float x);
__attribute__((import_module("imports"), import_name("js_sqrt"))) float js_sqrt(float x);
#endif
double ldexp(double x, int exp) {
return 0.0;
}
double pow(double base, double exponent) {
#ifdef KINC_WASM
return js_pow(base, exponent);
#endif
return 0.0;
}
double floor(double x) {
#ifdef KINC_WASM
return js_floor(x);
#endif
return 0.0;
}
float floorf(float x) {
#ifdef KINC_WASM
return js_floor(x);
#endif
return 0.0f;
}
double sin(double x) {
#ifdef KINC_WASM
return js_sin(x);
#endif
return 0.0;
}
float sinf(float x) {
#ifdef KINC_WASM
return js_sin(x);
#endif
return 0.0f;
}
double cos(double x) {
#ifdef KINC_WASM
return js_cos(x);
#endif
return 0.0;
}
float cosf(float x) {
#ifdef KINC_WASM
return js_cos(x);
#endif
return 0.0f;
}
double tan(double x) {
#ifdef KINC_WASM
return js_tan(x);
#endif
return 0.0;
}
float tanf(float x) {
#ifdef KINC_WASM
return js_tan(x);
#endif
return 0.0f;
}
double log(double x) {
#ifdef KINC_WASM
return js_log(x);
#endif
return 0.0;
}
double exp(double x) {
#ifdef KINC_WASM
return js_exp(x);
#endif
return 0.0;
}
double sqrt(double x) {
#ifdef KINC_WASM
return js_sqrt(x);
#endif
return 0.0;
}

35
Kha/Kinc/miniClib/math.h Normal file
View File

@ -0,0 +1,35 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
double ldexp(double x, int exp);
double pow(double base, double exponent);
double floor(double x);
float floorf(float x);
double sin(double x);
float sinf(float x);
double cos(double x);
float cosf(float x);
double tan(double x);
float tanf(float x);
double log(double x);
double exp(double x);
double sqrt(double x);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,68 @@
#include "stdlib.h"
#ifdef KINC_WASM
__attribute__((import_module("imports"), import_name("js_fprintf"))) void js_fprintf(const char *format);
#define HEAP_SIZE 1024 * 1024 * 8
static unsigned char heap[HEAP_SIZE];
static size_t heap_top = 4;
#endif
#ifdef KINC_WASM
__attribute__((export_name("malloc")))
#endif
void *malloc(size_t size) {
#ifdef KINC_WASM
// Align to 4 bytes to make js typed arrays work
if (size % 4 != 0) {
size += 4 - size % 4;
}
size_t old_top = heap_top;
heap_top += size;
if (heap_top >= HEAP_SIZE) {
js_fprintf("malloc: out of memory");
}
return &heap[old_top];
#endif
return NULL;
}
void *alloca(size_t size) {
return NULL;
}
void *realloc(void *mem, size_t size) {
return NULL;
}
void free(void *mem) {
}
void *memset(void *ptr, int value, size_t num) {
unsigned char *data = (unsigned char *)ptr;
for (size_t i = 0; i < num; ++i) {
data[i] = (unsigned char)value;
}
return ptr;
}
void *memcpy(void *destination, const void *source, size_t num) {
unsigned char *s = (unsigned char *)source;
unsigned char *d = (unsigned char *)destination;
for (size_t i = 0; i < num; ++i) {
d[i] = s[i];
}
return destination;
}
int memcmp(const void *ptr1, const void *ptr2, size_t num) {
unsigned char *p1 = (unsigned char *)ptr1;
unsigned char *p2 = (unsigned char *)ptr2;
for (size_t i = 0; i < num; ++i) {
if (p1[i] != p2[i]) {
return (int)p1[i] - (int)p2[i];
}
}
return 0;
}

View File

@ -0,0 +1,11 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <stddef.h>
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,7 @@
#pragma once
#ifndef __cplusplus
typedef _Bool bool;
#define true 1
#define false 0
#endif

62
Kha/Kinc/miniClib/stdio.c Normal file
View File

@ -0,0 +1,62 @@
#include "stdio.h"
#ifdef KINC_WASM
__attribute__((import_module("imports"), import_name("js_fprintf"))) void js_fprintf(const char *format);
__attribute__((import_module("imports"), import_name("js_fopen"))) FILE *js_fopen(const char *filename);
__attribute__((import_module("imports"), import_name("js_ftell"))) long int js_ftell(FILE *stream);
__attribute__((import_module("imports"), import_name("js_fseek"))) int js_fseek(FILE *stream, long int offset, int origin);
__attribute__((import_module("imports"), import_name("js_fread"))) size_t js_fread(void *ptr, size_t size, size_t count, FILE *stream);
#endif
FILE *stdout = NULL, *stderr = NULL;
int fprintf(FILE *stream, const char *format, ...) {
#ifdef KINC_WASM
js_fprintf(format);
#endif
return 0;
}
int vsnprintf(char *s, size_t n, const char *format, va_list arg) {
return 0;
}
size_t fwrite(const void *ptr, size_t size, size_t count, FILE *stream) {
return 0;
}
FILE *fopen(const char *filename, const char *mode) {
#ifdef KINC_WASM
return js_fopen(filename);
#endif
return NULL;
}
int fclose(FILE *stream) {
return 0;
}
long int ftell(FILE *stream) {
#ifdef KINC_WASM
return js_ftell(stream);
#endif
return 0;
}
int fseek(FILE *stream, long int offset, int origin) {
#ifdef KINC_WASM
return js_fseek(stream, offset, origin);
#endif
return 0;
}
size_t fread(void *ptr, size_t size, size_t count, FILE *stream) {
#ifdef KINC_WASM
return js_fread(ptr, size, count, stream);
#endif
return 0;
}
int fputs(const char *str, FILE *stream) {
return 0;
}

37
Kha/Kinc/miniClib/stdio.h Normal file
View File

@ -0,0 +1,37 @@
#pragma once
#include <stdarg.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
#define SEEK_SET 0
#define SEEK_END 1
typedef int FILE;
extern FILE *stdout, *stderr;
int fprintf(FILE *stream, const char *format, ...);
int vsnprintf(char *s, size_t n, const char *format, va_list arg);
size_t fwrite(const void *ptr, size_t size, size_t count, FILE *stream);
FILE *fopen(const char *filename, const char *mode);
int fclose(FILE *stream);
long int ftell(FILE *stream);
int fseek(FILE *stream, long int offset, int origin);
size_t fread(void *ptr, size_t size, size_t count, FILE *stream);
int fputs(const char *str, FILE *stream);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,21 @@
#include "stdlib.h"
void exit(int code) {
exit(code);
}
long int strtol(const char *str, char **endptr, int base) {
return 0;
}
int abs(int n) {
return n < 0 ? -n : n;
}
long long int llabs(long long int n) {
return n < 0 ? -n : n;
}
void qsort(void *base, size_t num, size_t size, int (*compar)(const void*,const void*)) {
}

View File

@ -0,0 +1,32 @@
#pragma once
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef unsigned long size_t;
#define EXIT_FAILURE 1
void *malloc(size_t size);
void *alloca(size_t size);
void *realloc(void *mem, size_t size);
void free(void *mem);
void exit(int code);
long int strtol(const char *str, char **endptr, int base);
int abs(int n);
long long int llabs(long long int n);
void qsort(void *base, size_t num, size_t size, int (*compar)(const void *, const void *));
#ifdef __cplusplus
}
#endif

173
Kha/Kinc/miniClib/string.c Normal file
View File

@ -0,0 +1,173 @@
#include "string.h"
#include <stdbool.h>
size_t strlen(const char *str) {
size_t size = 0;
while (true) {
if (str[size] == 0) {
return size;
}
++size;
}
return 0;
}
char *strcpy(char *destination, const char *source) {
for (size_t i = 0;; ++i) {
destination[i] = source[i];
if (source[i] == 0) {
return destination;
}
}
return destination;
}
char *strncpy(char *destination, const char *source, size_t num) {
for (size_t i = 0; i < num; ++i) {
destination[i] = source[i];
if (source[i] == 0) {
return destination;
}
}
return destination;
}
char *strcat(char *destination, const char *source) {
size_t di = 0;
while (destination[di] != 0) {
++di;
}
for (size_t si = 0;; ++si) {
destination[di] = source[si];
if (source[si] == 0) {
return destination;
}
++di;
}
return destination;
}
char *strstr(const char *str1, const char *str2) {
for (size_t i1 = 0;; ++i1) {
if (str1[i1] == 0) {
return NULL;
}
for (size_t i2 = 0;; ++i2) {
if (str2[i2] == 0) {
return (char*)&str1[i1];
}
if (str1[i1 + i2] != str2[i2]) {
break;
}
}
}
}
int strcmp(const char *str1, const char *str2) {
for (size_t i = 0;; ++i) {
if (str1[i] != str2[i]) {
return str1[i] - str2[i];
}
if (str1[i] == 0) {
return 0;
}
}
}
int strncmp(const char *str1, const char *str2, size_t num) {
for (size_t i = 0; i < num; ++i) {
if (str1[i] != str2[i]) {
return str1[i] - str2[i];
}
if (str1[i] == 0) {
return 0;
}
}
return 0;
}
size_t wcslen(const wchar_t *str) {
size_t size = 0;
while (true) {
if (str[size] == 0) {
return size;
}
++size;
}
return 0;
}
wchar_t *wcscpy(wchar_t *destination, const wchar_t *source) {
for (size_t i = 0;; ++i) {
destination[i] = source[i];
if (source[i] == 0) {
return destination;
}
}
return destination;
}
wchar_t *wcsncpy(wchar_t *destination, const wchar_t *source, size_t num) {
for (size_t i = 0; i < num; ++i) {
destination[i] = source[i];
if (source[i] == 0) {
return destination;
}
}
return destination;
}
wchar_t *wcscat(wchar_t *destination, const wchar_t *source) {
size_t di = 0;
while (destination[di] != 0) {
++di;
}
for (size_t si = 0;; ++si) {
destination[di] = source[si];
if (source[si] == 0) {
return destination;
}
++di;
}
return destination;
}
wchar_t *wcsstr(wchar_t *str1, const wchar_t *str2) {
for (size_t i1 = 0;; ++i1) {
if (str1[i1] == 0) {
return NULL;
}
for (size_t i2 = 0;; ++i2) {
if (str2[i2] == 0) {
return &str1[i1];
}
if (str1[i1 + i2] != str2[i2]) {
break;
}
}
}
}
int wcscmp(const wchar_t *str1, const wchar_t *str2) {
for (size_t i = 0;; ++i) {
if (str1[i] != str2[i]) {
return str1[i] - str2[i];
}
if (str1[i] == 0) {
return 0;
}
}
}
int wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t num) {
for (size_t i = 0; i < num; ++i) {
if (str1[i] != str2[i]) {
return str1[i] - str2[i];
}
if (str1[i] == 0) {
return 0;
}
}
return 0;
}

View File

@ -0,0 +1,46 @@
#pragma once
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
void *memset(void *ptr, int value, size_t num);
void *memcpy(void *destination, const void *source, size_t num);
int memcmp(const void *ptr1, const void *ptr2, size_t num);
size_t strlen(const char *str);
char *strcpy(char *destination, const char *source);
char *strncpy(char *destination, const char *source, size_t num);
char *strcat(char *destination, const char *source);
// built-in in Clang
char *strstr(const char *str1, const char *str2);
int strcmp(const char *str1, const char *str2);
int strncmp(const char *str1, const char *str2, size_t num);
size_t wcslen(const wchar_t *str);
wchar_t *wcscpy(wchar_t *destination, const wchar_t *source);
wchar_t *wcsncpy(wchar_t *destination, const wchar_t *source, size_t num);
wchar_t *wcscat(wchar_t *destination, const wchar_t *source);
wchar_t *wcsstr(wchar_t *str1, const wchar_t *str2);
int wcscmp(const wchar_t *str1, const wchar_t *str2);
int wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t num);
#ifdef __cplusplus
}
#endif

11
Kha/Kinc/miniClib/time.h Normal file
View File

@ -0,0 +1,11 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <stddef.h>
#ifdef __cplusplus
}
#endif