mie: func name and args are now specified separately from func creation
func args are added manually using mie_func_add_arg, while the func's name is specified when the func is added to a module, to allow the module to generate a unique name.
This commit is contained in:
32
mie/func.c
32
mie/func.c
@@ -1,14 +1,13 @@
|
||||
#include <blue/core/hash.h>
|
||||
#include <blue/object/string.h>
|
||||
#include <mie/arg.h>
|
||||
#include <mie/block.h>
|
||||
#include <mie/func.h>
|
||||
#include <mie/name.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user