diff --git a/include/custom.h b/include/custom.h index 42c9835..2f2115a 100644 --- a/include/custom.h +++ b/include/custom.h @@ -55,14 +55,6 @@ struct libab_behavior_s { * The implementation of this behavior. */ struct libab_behavior_impl_s impl; - /** - * The type of the function. - */ - libab_ref type; - /** - * The type parameters for the given behavior. - */ - libab_ref_trie type_params; }; /** * A struct that holds informatiion @@ -116,7 +108,7 @@ typedef struct libab_function_s libab_function; * @param func the function that this behavior calls. */ void libab_behavior_init_internal(libab_behavior* behavior, - libab_ref* type, libab_function_ptr func); + libab_function_ptr func); /** * Initializes a behavior that uses a tree that has been * parsed from the user. @@ -124,8 +116,8 @@ void libab_behavior_init_internal(libab_behavior* behavior, * @param type the type of the behavior. * @param tree the tree that this behavior uses. */ -void libab_behavior_init_tree(libab_behavior* behavior, libab_ref* type, - libab_tree* tree); +void libab_behavior_init_tree(libab_behavior* behavior, + libab_tree* tree); /** * Frees the given behavior. * @param behavior the behavior to free. @@ -155,7 +147,7 @@ void libab_operator_free(libab_operator* op); * @param fun the function implementation. * @return the result of the initialization. */ -libab_result libab_function_init_internal(libab_function* function, libab_ref* type, +libab_result libab_function_init_internal(libab_function* function, libab_function_ptr fun); /** * Initializes a function with the given tree behavior. @@ -164,7 +156,7 @@ libab_result libab_function_init_internal(libab_function* function, libab_ref* t * @param tree the tree that represents the function's behavior. * @return the result of the initialization. */ -libab_result libab_function_init_tree(libab_function* function, libab_ref* type, +libab_result libab_function_init_tree(libab_function* function, libab_tree* tree); /** * Frees the given function. diff --git a/include/util.h b/include/util.h index 6c62722..53bda1a 100644 --- a/include/util.h +++ b/include/util.h @@ -92,20 +92,20 @@ libab_result libab_create_value_raw(libab_ref* into, void* data, libab_ref* type /** * Allocates a function that uses internal code to run. * @param into the reference into which to store the new function. - * @param type the type of the function. + * @param free_function the free function used to free function instances. * @param fun the function implementation. * @return libab_result the result of any necessary allocations. */ -libab_result libab_create_function_internal(libab_ref* into, libab_ref* type, +libab_result libab_create_function_internal(libab_ref* into, void (*free_function)(void*), libab_function_ptr fun); /** * Allocates a function that uses a tree to run. * @param into the reference into which to store the new function. - * @param type the type of the function. + * @param free_function the free function used to free function instances. * @param tree the function implementation. * @return libab_result the result of any necessary allocations. */ -libab_result libab_create_function_tree(libab_ref* into, libab_ref* type, +libab_result libab_create_function_tree(libab_ref* into, void (*free_function)(void*), libab_tree* tree); /** * Creates a function list object, storing it in to the given reference. diff --git a/src/custom.c b/src/custom.c index cf60dfc..bc7312e 100644 --- a/src/custom.c +++ b/src/custom.c @@ -1,24 +1,18 @@ #include "custom.h" -void libab_behavior_init_internal(libab_behavior* behavior, libab_ref* type, +void libab_behavior_init_internal(libab_behavior* behavior, libab_function_ptr func) { behavior->impl.variant = BIMPL_INTERNAL; behavior->impl.data_u.internal = func; - 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_tree* tree) { behavior->impl.variant = BIMPL_TREE; behavior->impl.data_u.tree = tree; - libab_ref_copy(type, &behavior->type); - libab_ref_trie_init(&behavior->type_params); } void libab_behavior_free(libab_behavior* behavior) { - libab_ref_free(&behavior->type); - libab_ref_trie_free(&behavior->type_params); if (behavior->impl.variant == BIMPL_TREE) { libab_tree_free_recursive(behavior->impl.data_u.tree); } @@ -30,7 +24,7 @@ void libab_operator_init(libab_operator* op, libab_operator_variant variant, op->type = variant; op->precedence = precedence; op->associativity = associativity; - libab_behavior_init_internal(&op->behavior, type, func); + libab_behavior_init_internal(&op->behavior, func); } void libab_operator_free(libab_operator* op) { @@ -40,16 +34,16 @@ void libab_operator_free(libab_operator* op) { libab_result _function_init(libab_function* function) { return LIBAB_SUCCESS; } -libab_result libab_function_init_internal(libab_function* function, libab_ref* type, +libab_result libab_function_init_internal(libab_function* function, libab_function_ptr fun) { libab_result result = _function_init(function); - libab_behavior_init_internal(&function->behavior, type, fun); + libab_behavior_init_internal(&function->behavior, fun); return result; } -libab_result libab_function_init_tree(libab_function* function, libab_ref* type, +libab_result libab_function_init_tree(libab_function* function, libab_tree* tree) { libab_result result = _function_init(function); - libab_behavior_init_tree(&function->behavior, type, tree); + libab_behavior_init_tree(&function->behavior, tree); return result; } void libab_function_free(libab_function* fun) { diff --git a/src/libabacus.c b/src/libabacus.c index fade17f..be81384 100644 --- a/src/libabacus.c +++ b/src/libabacus.c @@ -95,7 +95,6 @@ void _initialize_behavior(libab_behavior* behavior, libab_ref* type, libab_function_ptr func) { behavior->impl.variant = BIMPL_INTERNAL; behavior->impl.data_u.internal = func; - libab_ref_copy(type, &behavior->type); } libab_result _register_operator(libab* ab, const char* op, @@ -158,7 +157,7 @@ libab_result libab_register_operator_postfix(libab* ab, const char* op, libab_result _create_value_function_internal(libab_ref* into, libab_ref* type, libab_function_ptr func) { libab_ref function_ref; - libab_result result = libab_create_function_internal(&function_ref, type, func); + libab_result result = libab_create_function_internal(&function_ref, _free_function, func); libab_ref_null(into); if(result == LIBAB_SUCCESS) { libab_ref_free(into); diff --git a/src/util.c b/src/util.c index 9dce91b..33f65a0 100644 --- a/src/util.c +++ b/src/util.c @@ -200,20 +200,19 @@ libab_result libab_create_value_raw(libab_ref* into, void* data, libab_ref* type return result; } -libab_result libab_create_function_internal(libab_ref* into, libab_ref* type, +libab_result libab_create_function_internal(libab_ref* into, void (*free_function)(void*), libab_function_ptr fun) { libab_function* new_function; libab_result result = LIBAB_SUCCESS; if((new_function = malloc(sizeof(*new_function)))) { - result = libab_function_init_internal(new_function, type, fun); + result = libab_function_init_internal(new_function, fun); } else { result = LIBAB_MALLOC; } if(result == LIBAB_SUCCESS) { - result = libab_ref_new(into, new_function, - ((libab_parsetype*) libab_ref_get(type))->data_u.base->free_function); + result = libab_ref_new(into, new_function, free_function); if(result != LIBAB_SUCCESS) { libab_function_free(new_function); } @@ -227,19 +226,19 @@ libab_result libab_create_function_internal(libab_ref* into, libab_ref* type, return result; } -libab_result libab_create_function_tree(libab_ref* into, libab_ref* type, +libab_result libab_create_function_tree(libab_ref* into, void (*free_function)(void*), libab_tree* tree) { libab_function* new_function; libab_result result = LIBAB_SUCCESS; if((new_function = malloc(sizeof(*new_function)))) { - result = libab_function_init_tree(new_function, type, tree); + result = libab_function_init_tree(new_function, tree); } else { result = LIBAB_MALLOC; } if(result == LIBAB_SUCCESS) { - result = libab_ref_new(into, new_function, ((libab_parsetype*) libab_ref_get(type))->data_u.base->free_function); + result = libab_ref_new(into, new_function, free_function); if(result != LIBAB_SUCCESS) { libab_function_free(new_function); }