nshell/src/wren_utils.c

38 lines
1.2 KiB
C

#include "uns_wren_utils.h"
#include <gint/kmalloc.h>
#include "term.h"
static void wn_write(WrenVM __attribute__((unused)) * vm, const char *text) { term_print(text); }
static void wn_error(WrenVM __attribute__((unused)) * vm, WrenErrorType errorType, const char *module, const int line,
const char *msg) {
switch (errorType) {
case WREN_ERROR_COMPILE:
term_printf("[%s line %d] [Error] %s\n", module, line, msg);
break;
case WREN_ERROR_STACK_TRACE:
term_eprintf("[%s line %d] in %s\n", module, line, msg);
break;
case WREN_ERROR_RUNTIME:
term_eprintf("[Runtime Error] %s\n", msg);
break;
default:
break;
}
}
static void *wn_reallocate(void *memory, size_t newSize, __attribute__((unused)) void *userData) {
return krealloc(memory, newSize);
}
void init_wren_config(WrenConfiguration *config) {
wrenInitConfiguration(config);
config->reallocateFn = &wn_reallocate;
config->initialHeapSize = 4 * 1024; // 4 kiB
config->minHeapSize = 1024; // 1 kiB
config->heapGrowthPercent = 50;
config->writeFn = &wn_write;
config->errorFn = &wn_error;
}