|
|
@ -102,21 +102,21 @@ static int atoi(const char* c) { |
|
|
|
|
|
|
|
int ink_add_native(struct context* ctx, const char* name, void(*value)(struct context*)) { |
|
|
|
if(ctx->native_words == NULL) { |
|
|
|
ctx->native_words = ctx->malloc(sizeof(struct native_fn) * 8); |
|
|
|
ctx->native_words = ctx->inner_malloc(sizeof(struct native_fn) * 8); |
|
|
|
ctx->native_words_top = 0; |
|
|
|
ctx->native_words_capacity = 8; |
|
|
|
} else if(ctx->native_words_top == ctx->native_words_capacity) { |
|
|
|
int new_count = (ctx->native_words_capacity + ctx->native_words_capacity/2); |
|
|
|
void* renewed = ctx->realloc(ctx->native_words, sizeof(struct native_fn) * new_count); |
|
|
|
void* renewed = ctx->inner_realloc(ctx->native_words, sizeof(struct native_fn) * new_count); |
|
|
|
if(renewed == NULL) { |
|
|
|
return -3; |
|
|
|
return -3; |
|
|
|
} else { |
|
|
|
ctx->native_words = renewed; |
|
|
|
ctx->native_words_capacity = new_count; |
|
|
|
} |
|
|
|
} |
|
|
|
int len = strlen(name); |
|
|
|
char* copy = ctx->malloc(len+1); |
|
|
|
char* copy = ctx->inner_malloc(len+1); |
|
|
|
if(copy == NULL) { |
|
|
|
return -4; |
|
|
|
} |
|
|
@ -170,12 +170,12 @@ static int ink_add_indigenous(struct context* ctx, const char* name, struct elem |
|
|
|
static int ink_add_lex_string(struct context* ctx, const char* name) { |
|
|
|
int i; |
|
|
|
if(ctx->lex_reserved_words == NULL) { |
|
|
|
ctx->lex_reserved_words = ctx->malloc(sizeof(char*) * 8); |
|
|
|
ctx->lex_reserved_words = ctx->inner_malloc(sizeof(char*) * 8); |
|
|
|
ctx->lex_reserved_words_top = 0; |
|
|
|
ctx->lex_reserved_words_capacity = 8; |
|
|
|
} else if(ctx->lex_reserved_words_top == ctx->lex_reserved_words_capacity) { |
|
|
|
int new_count = (ctx->lex_reserved_words_capacity + ctx->lex_reserved_words_capacity/2); |
|
|
|
void* renewed = ctx->realloc(ctx->lex_reserved_words, sizeof(struct native_fn) * new_count); |
|
|
|
void* renewed = ctx->inner_realloc(ctx->lex_reserved_words, sizeof(struct native_fn) * new_count); |
|
|
|
if(renewed == NULL) { |
|
|
|
return -5; |
|
|
|
} else { |
|
|
@ -260,10 +260,13 @@ void ink_pop(struct context* ctx) { |
|
|
|
|
|
|
|
struct context* ink_make_context(void*(*malloc)(size_t), void*(*realloc)(void*, size_t), void(*free)(void*), int(*putchar)(int)) { |
|
|
|
struct context* ctx = (struct context*)malloc(sizeof(struct context)); |
|
|
|
ctx->malloc = malloc; |
|
|
|
ctx->realloc = realloc; |
|
|
|
ctx->free = free; |
|
|
|
ctx->putchar = putchar; |
|
|
|
ctx->malloc = malloc; |
|
|
|
ctx->realloc = realloc; |
|
|
|
ctx->free = free; |
|
|
|
ctx->inner_malloc = malloc; |
|
|
|
ctx->inner_realloc = realloc; |
|
|
|
ctx->inner_free = free; |
|
|
|
ctx->putchar = putchar; |
|
|
|
ctx->panic = 0; |
|
|
|
ctx->routines = NULL; |
|
|
|
ctx->routines_capacity = 0; |
|
|
@ -452,7 +455,7 @@ static int lblcmp(const char* label, const char* other, size_t label_sz) { |
|
|
|
|
|
|
|
int ink_make_routine(struct context* ctx) { |
|
|
|
if(ctx->routines == NULL) { |
|
|
|
ctx->routines = ctx->malloc(sizeof(struct ink_routine) * 8); |
|
|
|
ctx->routines = ctx->inner_malloc(sizeof(struct ink_routine) * 8); |
|
|
|
ctx->routines_top = 0; |
|
|
|
ctx->routines_capacity = 8; |
|
|
|
struct ink_routine* it = ctx->routines; |
|
|
@ -464,7 +467,7 @@ int ink_make_routine(struct context* ctx) { |
|
|
|
} |
|
|
|
} else if(ctx->routines_top == ctx->routines_capacity) { |
|
|
|
int new_count = (ctx->routines_capacity + ctx->routines_capacity/2); |
|
|
|
void* renewed = ctx->realloc(ctx->routines, sizeof(struct stack_frame) * new_count); |
|
|
|
void* renewed = ctx->inner_realloc(ctx->routines, sizeof(struct stack_frame) * new_count); |
|
|
|
if(renewed == NULL) { |
|
|
|
return -99; |
|
|
|
} else { |
|
|
|