diff --git a/mie/arg.c b/mie/arg.c index 628b6d8..c46321c 100644 --- a/mie/arg.c +++ b/mie/arg.c @@ -1,4 +1,22 @@ #include +#include +#include + +struct mie_arg *mie_arg_create(struct mie_type *type) +{ + struct mie_arg *out = malloc(sizeof *out); + if (!out) { + return NULL; + } + + memset(out, 0x0, sizeof *out); + + mie_value_init(&out->arg_base, MIE_VALUE_ARG); + + out->arg_type = type; + + return out; +} static struct mie_type *get_type(struct mie_value *v) { diff --git a/mie/func.c b/mie/func.c index 0b60e53..9a8fdc4 100644 --- a/mie/func.c +++ b/mie/func.c @@ -1,14 +1,13 @@ #include #include +#include #include #include #include #include #include -struct mie_func *mie_func_create( - const char *name, enum mie_func_type type, struct mie_type *ret_type, - struct mie_arg **args, unsigned int nr_args) +struct mie_func *mie_func_create(enum mie_func_type type, struct mie_type *ret_type) { struct mie_func *out = malloc(sizeof *out); if (!out) { @@ -19,21 +18,30 @@ struct mie_func *mie_func_create( mie_value_init(&out->f_base, MIE_VALUE_FUNC); - out->f_base.v_name.n_str = b_strdup(name); - out->f_base.v_name.n_base.e_hash = b_hash_string(name); - out->f_type = type; out->f_ret = ret_type; out->f_names = mie_name_map_create(); - for (size_t i = 0; i < nr_args; i++) { - if (args[i]) { - struct mie_value *arg_value = MIE_VALUE(args[i]); - b_queue_push_back(&out->f_args, &arg_value->v_entry); - } + return out; +} + +struct mie_value *mie_func_add_arg( + struct mie_func *func, struct mie_type *type, const char *name) +{ + struct mie_arg *arg = mie_arg_create(type); + if (!arg) { + return NULL; } - return out; + struct mie_value *v + = mie_func_generate_value_name(func, MIE_VALUE(arg), name); + if (!v) { + mie_value_destroy(MIE_VALUE(arg)); + return NULL; + } + + b_queue_push_back(&func->f_args, &v->v_entry); + return v; } struct mie_block *mie_func_create_block(struct mie_func *func, const char *name) diff --git a/mie/include/mie/arg.h b/mie/include/mie/arg.h index 803484f..88a2d03 100644 --- a/mie/include/mie/arg.h +++ b/mie/include/mie/arg.h @@ -10,4 +10,6 @@ struct mie_arg { struct mie_type *arg_type; }; +extern struct mie_arg *mie_arg_create(struct mie_type *type); + #endif diff --git a/mie/include/mie/func.h b/mie/include/mie/func.h index 2f39ce4..4935f03 100644 --- a/mie/include/mie/func.h +++ b/mie/include/mie/func.h @@ -31,8 +31,9 @@ struct mie_func { }; extern struct mie_func *mie_func_create( - const char *name, enum mie_func_type type, struct mie_type *ret_type, - struct mie_arg **args, unsigned int nr_args); + enum mie_func_type type, struct mie_type *ret_type); +extern struct mie_value *mie_func_add_arg( + struct mie_func *func, struct mie_type *type, const char *name); extern struct mie_block *mie_func_create_block( struct mie_func *func, const char *name); extern void mie_func_insert_block( diff --git a/mie/include/mie/module.h b/mie/include/mie/module.h index 7740faa..7e8c337 100644 --- a/mie/include/mie/module.h +++ b/mie/include/mie/module.h @@ -22,7 +22,8 @@ struct mie_module { }; extern struct mie_module *mie_module_create(void); -extern void mie_module_add_function(struct mie_module *mod, struct mie_func *func); +extern void mie_module_add_function( + struct mie_module *mod, struct mie_func *func, const char *name); extern struct mie_data *mie_module_get_string_ptr( struct mie_module *mod, const char *s); extern struct mie_data *mie_module_get_data( diff --git a/mie/include/mie/type.h b/mie/include/mie/type.h index 5207841..7f4b914 100644 --- a/mie/include/mie/type.h +++ b/mie/include/mie/type.h @@ -16,6 +16,7 @@ enum mie_type_id { MIE_TYPE_ARRAY = 0x08u, MIE_TYPE_LABEL = 0x09u, MIE_TYPE_SELECTOR = 0x0Au, + MIE_TYPE_FUNC = 0x0Bu, __MIE_TYPE_COUNT, }; diff --git a/mie/module.c b/mie/module.c index 8a794eb..6c896aa 100644 --- a/mie/module.c +++ b/mie/module.c @@ -25,9 +25,16 @@ struct mie_module *mie_module_create(void) return out; } -void mie_module_add_function(struct mie_module *mod, struct mie_func *func) +void mie_module_add_function( + struct mie_module *mod, struct mie_func *func, const char *name) { - b_queue_push_back(&mod->m_func, &func->f_base.v_entry); + struct mie_value *v + = mie_module_generate_value_name(mod, MIE_VALUE(func), name); + if (!v) { + return; + } + + b_queue_push_back(&mod->m_func, &v->v_entry); } struct mie_data *mie_module_get_string_ptr(struct mie_module *mod, const char *s) diff --git a/mie/name.c b/mie/name.c index 9439808..01fa134 100644 --- a/mie/name.c +++ b/mie/name.c @@ -151,9 +151,16 @@ struct mie_name *mie_name_map_put( /* that name already exists, use a suffix to make the name unique. * alternately, no hint was specified, so it's up to us to generate the name */ + b_rope dot = B_ROPE_CHAR('.'); b_rope suffix = B_ROPE_UINT(0); b_rope unique_name; - b_rope_concat(&unique_name, &base, &suffix); + + if (hint) { + const b_rope *parts[] = {&base, &dot, &suffix}; + b_rope_join(&unique_name, parts, sizeof parts / sizeof parts[0]); + } else { + b_rope_concat(&unique_name, &base, &suffix); + } size_t i = 0; if (!hint || hint[0] == '\0') { @@ -171,9 +178,12 @@ struct mie_name *mie_name_map_put( if (B_OK(status)) { entry->n_str = b_strdup(str); + b_rope_destroy(&unique_name); return entry; } } + b_rope_destroy(&unique_name); + return NULL; }