From f29fce26a8d5671daabfca400aa6d26517060a97 Mon Sep 17 00:00:00 2001 From: Ludovic 'Archivist' Lagouardette Date: Thu, 30 May 2024 08:31:58 +0200 Subject: [PATCH] Exposing array functions --- include/ink.h | 27 +++++++++++++++++++++++++++ lib.c | 10 ++-------- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/include/ink.h b/include/ink.h index e77d8ee..b33ad9b 100644 --- a/include/ink.h +++ b/include/ink.h @@ -321,6 +321,33 @@ struct elem ink_make_transparent(struct context* ctx, int type_id, void* ptr); */ void ink_gc(struct context* ctx); +/** + * Obtains the type id from the declared name of the type + * @param ctx The context where we want to detect the type + * @param name The name of the type + * @return the type id if it exists, -1 otherwise + */ +int get_type_by_name(struct context* ctx, const char* name); + +/** + * The internal representation of arrays in ink + */ +struct ink_array { + int top; + int capacity; + struct elem* elements; +}; + +/** + * Pushes a value in an array. in case of failure, panics the routine + * + * @param ctx the working context + * @param currentRoutine the routine that will panic + * @param ary the array to be incremented + * @param value the value to push + */ +void array_push(struct context* ctx, struct ink_routine* currentRoutine, struct ink_array* ary, struct elem value); + #ifdef __cplusplus }; #endif \ No newline at end of file diff --git a/lib.c b/lib.c index 34c26ee..29192c8 100644 --- a/lib.c +++ b/lib.c @@ -1509,7 +1509,7 @@ static void print_as_utf8(struct context* ctx) { ink_pop(ctx); } -static int get_type_by_name(struct context* ctx, const char* name) { +int get_type_by_name(struct context* ctx, const char* name) { int i; for(i = 0; i < ctx->types_top; ++i) { if(strcmp(ctx->types[i].name, name) == 0) { @@ -1570,12 +1570,6 @@ static struct ink_collection_list gc_noop(struct context* _1, void* _2) { #ifndef NOARRAYLIB -struct ink_array { - int top; - int capacity; - struct elem* elements; -}; - static void collect_array(struct context* ctx, void* array) { struct ink_array* ary; ary = array; @@ -1613,7 +1607,7 @@ static void push_array_stack_delim(struct context* ctx) { ink_push(ctx, e); } -static void array_push(struct context* ctx, struct ink_routine* currentRoutine, struct ink_array* ary, struct elem value) { +void array_push(struct context* ctx, struct ink_routine* currentRoutine, struct ink_array* ary, struct elem value) { if(ary->elements == NULL) { ary->elements = ctx->malloc(sizeof(struct elem) * 8); ary->top = 0;