libabacus/src/custom.c

52 lines
1.7 KiB
C
Raw Normal View History

#include "custom.h"
2018-05-16 15:26:03 -07:00
void libab_behavior_init_internal(libab_behavior* behavior,
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,
libab_tree* tree) {
behavior->impl.variant = BIMPL_TREE;
behavior->impl.data_u.tree = tree;
}
void libab_behavior_free(libab_behavior* behavior) {
2018-04-21 14:09:01 -07:00
if (behavior->impl.variant == BIMPL_TREE) {
libab_tree_free_recursive(behavior->impl.data_u.tree);
}
}
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);
}
void libab_operator_free(libab_operator* op) {
libab_behavior_free(&op->behavior);
}
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,
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);
return result;
}
2018-05-16 15:26:03 -07:00
libab_result libab_function_init_tree(libab_function* function,
libab_tree* tree) {
libab_result result = _function_init(function);
2018-05-16 15:26:03 -07:00
libab_behavior_init_tree(&function->behavior, tree);
return result;
}
void libab_function_free(libab_function* fun) {
libab_behavior_free(&fun->behavior);
}