2018-04-17 11:22:48 -07:00
|
|
|
#include "custom.h"
|
|
|
|
|
2018-05-16 15:26:03 -07:00
|
|
|
void libab_behavior_init_internal(libab_behavior* behavior,
|
2018-05-09 15:05:40 -07:00
|
|
|
libab_function_ptr func) {
|
|
|
|
behavior->impl.variant = BIMPL_INTERNAL;
|
|
|
|
behavior->impl.data_u.internal = func;
|
|
|
|
}
|
|
|
|
|
2018-05-16 15:26:03 -07:00
|
|
|
void libab_behavior_init_tree(libab_behavior* behavior,
|
2018-05-09 15:05:40 -07:00
|
|
|
libab_tree* tree) {
|
|
|
|
behavior->impl.variant = BIMPL_TREE;
|
|
|
|
behavior->impl.data_u.tree = tree;
|
|
|
|
}
|
|
|
|
|
2018-04-17 11:22:48 -07:00
|
|
|
void libab_behavior_free(libab_behavior* behavior) {
|
2018-04-21 14:09:01 -07:00
|
|
|
if (behavior->impl.variant == BIMPL_TREE) {
|
2018-05-09 15:05:40 -07:00
|
|
|
libab_tree_free_recursive(behavior->impl.data_u.tree);
|
2018-04-20 00:25:31 -07:00
|
|
|
}
|
2018-04-17 11:22:48 -07:00
|
|
|
}
|
|
|
|
|
2018-05-09 15:05:40 -07:00
|
|
|
void libab_operator_init(libab_operator* op, libab_operator_variant variant,
|
|
|
|
int precedence, int associativity, libab_ref* type,
|
|
|
|
libab_function_ptr func) {
|
|
|
|
op->type = variant;
|
|
|
|
op->precedence = precedence;
|
|
|
|
op->associativity = associativity;
|
2018-05-16 15:26:03 -07:00
|
|
|
libab_behavior_init_internal(&op->behavior, func);
|
2018-05-09 15:05:40 -07:00
|
|
|
}
|
|
|
|
|
2018-04-17 11:22:48 -07:00
|
|
|
void libab_operator_free(libab_operator* op) {
|
|
|
|
libab_behavior_free(&op->behavior);
|
|
|
|
}
|
|
|
|
|
2018-05-09 15:05:40 -07:00
|
|
|
libab_result _function_init(libab_function* function) {
|
|
|
|
return LIBAB_SUCCESS;
|
|
|
|
}
|
2018-05-16 15:26:03 -07:00
|
|
|
libab_result libab_function_init_internal(libab_function* function,
|
2018-05-09 15:05:40 -07:00
|
|
|
libab_function_ptr fun) {
|
|
|
|
libab_result result = _function_init(function);
|
2018-05-16 15:26:03 -07:00
|
|
|
libab_behavior_init_internal(&function->behavior, fun);
|
2018-05-09 15:05:40 -07:00
|
|
|
return result;
|
|
|
|
}
|
2018-05-16 15:26:03 -07:00
|
|
|
libab_result libab_function_init_tree(libab_function* function,
|
2018-05-09 15:05:40 -07:00
|
|
|
libab_tree* tree) {
|
|
|
|
libab_result result = _function_init(function);
|
2018-05-16 15:26:03 -07:00
|
|
|
libab_behavior_init_tree(&function->behavior, tree);
|
2018-05-09 15:05:40 -07:00
|
|
|
return result;
|
|
|
|
}
|
2018-04-17 11:22:48 -07:00
|
|
|
void libab_function_free(libab_function* fun) {
|
|
|
|
libab_behavior_free(&fun->behavior);
|
|
|
|
}
|