Add type parameters to behavior.

This commit is contained in:
Danila Fedorin 2018-05-11 11:38:10 -07:00
parent 8253cd1f69
commit 92186911ad
2 changed files with 8 additions and 0 deletions

View File

@ -3,6 +3,7 @@
#include "parsetype.h" #include "parsetype.h"
#include "tree.h" #include "tree.h"
#include "ref_trie.h"
/** /**
* A function pointer that is called * A function pointer that is called
@ -58,6 +59,10 @@ struct libab_behavior_s {
* The type of the function. * The type of the function.
*/ */
libab_ref type; libab_ref type;
/**
* The type parameters for the given behavior.
*/
libab_ref_trie type_params;
}; };
/** /**
* A struct that holds informatiion * A struct that holds informatiion

View File

@ -5,6 +5,7 @@ void libab_behavior_init_internal(libab_behavior* behavior, libab_ref* type,
behavior->impl.variant = BIMPL_INTERNAL; behavior->impl.variant = BIMPL_INTERNAL;
behavior->impl.data_u.internal = func; behavior->impl.data_u.internal = func;
libab_ref_copy(type, &behavior->type); libab_ref_copy(type, &behavior->type);
libab_ref_trie_init(&behavior->type_params);
} }
void libab_behavior_init_tree(libab_behavior* behavior, libab_ref* type, void libab_behavior_init_tree(libab_behavior* behavior, libab_ref* type,
@ -12,10 +13,12 @@ void libab_behavior_init_tree(libab_behavior* behavior, libab_ref* type,
behavior->impl.variant = BIMPL_TREE; behavior->impl.variant = BIMPL_TREE;
behavior->impl.data_u.tree = tree; behavior->impl.data_u.tree = tree;
libab_ref_copy(type, &behavior->type); libab_ref_copy(type, &behavior->type);
libab_ref_trie_init(&behavior->type_params);
} }
void libab_behavior_free(libab_behavior* behavior) { void libab_behavior_free(libab_behavior* behavior) {
libab_ref_free(&behavior->type); libab_ref_free(&behavior->type);
libab_ref_trie_free(&behavior->type_params);
if (behavior->impl.variant == BIMPL_TREE) { if (behavior->impl.variant == BIMPL_TREE) {
libab_tree_free_recursive(behavior->impl.data_u.tree); libab_tree_free_recursive(behavior->impl.data_u.tree);
} }