mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
moved all crates into seperate folder + related path fixes
This commit is contained in:
parent
12ef03bb86
commit
eee85fa45d
1063 changed files with 92 additions and 93 deletions
77
crates/repl_wasm/src/repl_platform.c
Normal file
77
crates/repl_wasm/src/repl_platform.c
Normal file
|
@ -0,0 +1,77 @@
|
|||
#include <stdio.h>
|
||||
|
||||
/*
|
||||
A bare-bones Roc "platform" for REPL code, providing heap allocation for builtins.
|
||||
*/
|
||||
|
||||
// Enable/disable printf debugging. Leave disabled to avoid bloating .wasm files and slowing down Wasmer tests.
|
||||
#define ENABLE_PRINTF 0
|
||||
|
||||
//--------------------------
|
||||
|
||||
void *roc_alloc(size_t size, unsigned int alignment)
|
||||
{
|
||||
void *allocated = malloc(size);
|
||||
|
||||
#if ENABLE_PRINTF
|
||||
if (!allocated)
|
||||
{
|
||||
fprintf(stderr, "roc_alloc failed\n");
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("roc_alloc allocated %d bytes with alignment %d at %p\n", size, alignment, allocated);
|
||||
}
|
||||
#endif
|
||||
return allocated;
|
||||
}
|
||||
|
||||
//--------------------------
|
||||
|
||||
void *roc_realloc(void *ptr, size_t new_size, size_t old_size,
|
||||
unsigned int alignment)
|
||||
{
|
||||
#if ENABLE_PRINTF
|
||||
printf("roc_realloc reallocated %p from %d to %d with alignment %zd\n",
|
||||
ptr, old_size, new_size, alignment);
|
||||
#endif
|
||||
return realloc(ptr, new_size);
|
||||
}
|
||||
|
||||
//--------------------------
|
||||
|
||||
void roc_dealloc(void *ptr, unsigned int alignment)
|
||||
{
|
||||
|
||||
#if ENABLE_PRINTF
|
||||
printf("roc_dealloc deallocated %p with alignment %zd\n", ptr, alignment);
|
||||
#endif
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
//--------------------------
|
||||
|
||||
void roc_panic(void *ptr, unsigned int alignment)
|
||||
{
|
||||
#if ENABLE_PRINTF
|
||||
char *msg = (char *)ptr;
|
||||
fprintf(stderr,
|
||||
"Application crashed with message\n\n %s\n\nShutting down\n", msg);
|
||||
#endif
|
||||
abort();
|
||||
}
|
||||
|
||||
//--------------------------
|
||||
|
||||
void *roc_memcpy(void *dest, const void *src, size_t n)
|
||||
{
|
||||
return memcpy(dest, src, n);
|
||||
}
|
||||
|
||||
//--------------------------
|
||||
|
||||
void *roc_memset(void *str, int c, size_t n)
|
||||
{
|
||||
return memset(str, c, n);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue