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:
18
mie/arg.c
18
mie/arg.c
@@ -1,4 +1,22 @@
|
|||||||
#include <mie/arg.h>
|
#include <mie/arg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
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)
|
static struct mie_type *get_type(struct mie_value *v)
|
||||||
{
|
{
|
||||||
|
|||||||
32
mie/func.c
32
mie/func.c
@@ -1,14 +1,13 @@
|
|||||||
#include <blue/core/hash.h>
|
#include <blue/core/hash.h>
|
||||||
#include <blue/object/string.h>
|
#include <blue/object/string.h>
|
||||||
|
#include <mie/arg.h>
|
||||||
#include <mie/block.h>
|
#include <mie/block.h>
|
||||||
#include <mie/func.h>
|
#include <mie/func.h>
|
||||||
#include <mie/name.h>
|
#include <mie/name.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
struct mie_func *mie_func_create(
|
struct mie_func *mie_func_create(enum mie_func_type type, struct mie_type *ret_type)
|
||||||
const char *name, enum mie_func_type type, struct mie_type *ret_type,
|
|
||||||
struct mie_arg **args, unsigned int nr_args)
|
|
||||||
{
|
{
|
||||||
struct mie_func *out = malloc(sizeof *out);
|
struct mie_func *out = malloc(sizeof *out);
|
||||||
if (!out) {
|
if (!out) {
|
||||||
@@ -19,21 +18,30 @@ struct mie_func *mie_func_create(
|
|||||||
|
|
||||||
mie_value_init(&out->f_base, MIE_VALUE_FUNC);
|
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_type = type;
|
||||||
out->f_ret = ret_type;
|
out->f_ret = ret_type;
|
||||||
out->f_names = mie_name_map_create();
|
out->f_names = mie_name_map_create();
|
||||||
|
|
||||||
for (size_t i = 0; i < nr_args; i++) {
|
return out;
|
||||||
if (args[i]) {
|
}
|
||||||
struct mie_value *arg_value = MIE_VALUE(args[i]);
|
|
||||||
b_queue_push_back(&out->f_args, &arg_value->v_entry);
|
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)
|
struct mie_block *mie_func_create_block(struct mie_func *func, const char *name)
|
||||||
|
|||||||
@@ -10,4 +10,6 @@ struct mie_arg {
|
|||||||
struct mie_type *arg_type;
|
struct mie_type *arg_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern struct mie_arg *mie_arg_create(struct mie_type *type);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -31,8 +31,9 @@ struct mie_func {
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern struct mie_func *mie_func_create(
|
extern struct mie_func *mie_func_create(
|
||||||
const char *name, enum mie_func_type type, struct mie_type *ret_type,
|
enum mie_func_type type, struct mie_type *ret_type);
|
||||||
struct mie_arg **args, unsigned int nr_args);
|
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(
|
extern struct mie_block *mie_func_create_block(
|
||||||
struct mie_func *func, const char *name);
|
struct mie_func *func, const char *name);
|
||||||
extern void mie_func_insert_block(
|
extern void mie_func_insert_block(
|
||||||
|
|||||||
@@ -22,7 +22,8 @@ struct mie_module {
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern struct mie_module *mie_module_create(void);
|
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(
|
extern struct mie_data *mie_module_get_string_ptr(
|
||||||
struct mie_module *mod, const char *s);
|
struct mie_module *mod, const char *s);
|
||||||
extern struct mie_data *mie_module_get_data(
|
extern struct mie_data *mie_module_get_data(
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ enum mie_type_id {
|
|||||||
MIE_TYPE_ARRAY = 0x08u,
|
MIE_TYPE_ARRAY = 0x08u,
|
||||||
MIE_TYPE_LABEL = 0x09u,
|
MIE_TYPE_LABEL = 0x09u,
|
||||||
MIE_TYPE_SELECTOR = 0x0Au,
|
MIE_TYPE_SELECTOR = 0x0Au,
|
||||||
|
MIE_TYPE_FUNC = 0x0Bu,
|
||||||
__MIE_TYPE_COUNT,
|
__MIE_TYPE_COUNT,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
11
mie/module.c
11
mie/module.c
@@ -25,9 +25,16 @@ struct mie_module *mie_module_create(void)
|
|||||||
return out;
|
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)
|
struct mie_data *mie_module_get_string_ptr(struct mie_module *mod, const char *s)
|
||||||
|
|||||||
12
mie/name.c
12
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.
|
/* 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 */
|
* 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 suffix = B_ROPE_UINT(0);
|
||||||
b_rope unique_name;
|
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;
|
size_t i = 0;
|
||||||
if (!hint || hint[0] == '\0') {
|
if (!hint || hint[0] == '\0') {
|
||||||
@@ -171,9 +178,12 @@ struct mie_name *mie_name_map_put(
|
|||||||
|
|
||||||
if (B_OK(status)) {
|
if (B_OK(status)) {
|
||||||
entry->n_str = b_strdup(str);
|
entry->n_str = b_strdup(str);
|
||||||
|
b_rope_destroy(&unique_name);
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b_rope_destroy(&unique_name);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user