Added math.h, stdlib.h, float.h, and stbool.h to std folder (and all their implementations). Opted to NOT implement malloc/free/etc. in favor of having our own functions init_mem, grow_mem, and get_mem.
This commit is contained in:
42
std/stdlib.h
Normal file
42
std/stdlib.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
File: stdlib.h
|
||||
Author: Taylor Robbins
|
||||
Date: 08\28\2025
|
||||
*/
|
||||
|
||||
#ifndef _STDLIB_H
|
||||
#define _STDLIB_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
MAYBE_START_EXTERN_C
|
||||
|
||||
int abs(int value);
|
||||
_Noreturn void exit(int exitCode);
|
||||
_Noreturn void abort();
|
||||
//NOTE: This is not a standard function but we want to pass a message to jsStdAbort so we added this
|
||||
_Noreturn void abort_msg(const char* message);
|
||||
|
||||
//NOTE: These are intentionally not available on WebAssembly because our memory model only allows for growth and
|
||||
// it's better to have the application decide how to manage memory on top of that simple model
|
||||
// void* malloc(size_t numBytes);
|
||||
// void* calloc(size_t numElements, size_t elemSize);
|
||||
// void* realloc(void* prevAllocPntr, size_t newSize);
|
||||
// void free(void* allocPntr);
|
||||
// void* aligned_alloc(size_t numBytes, size_t alignmentSize);
|
||||
|
||||
//These are our own std-like functions for interacting with WebAssembly memory
|
||||
WASM_EXPORT(init_mem) void init_mem(size_t numInitialPages);
|
||||
void* grow_mem(size_t numBytes);
|
||||
size_t get_mem();
|
||||
|
||||
// TODO: double atof(const char* str);
|
||||
// TODO: void* alloca(size_t numBytes);
|
||||
|
||||
// typedef int (StdCompareFunc_f)(const void* left, const void* right);
|
||||
// typedef int (StdCompareFuncEx_f)(const void* left, const void* right, void* compareFunc);
|
||||
//TODO: void qsort(void* basePntr, size_t numItems, size_t itemSize, StdCompareFunc_f* compareFunc);
|
||||
|
||||
MAYBE_END_EXTERN_C
|
||||
|
||||
#endif // _STDLIB_H
|
||||
Reference in New Issue
Block a user