From b12f6d7a316e83f5117538b1dd588efc5e3528f0 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sat, 21 Apr 2018 17:32:38 -0700 Subject: [PATCH] Add a number implementation struct to libab. --- include/libabacus.h | 5 +++++ include/number.h | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 include/number.h diff --git a/include/libabacus.h b/include/libabacus.h index f1dcdd7..beb4ce9 100644 --- a/include/libabacus.h +++ b/include/libabacus.h @@ -7,6 +7,7 @@ #include "parser.h" #include "result.h" #include "table.h" +#include "number.h" /** * The main struct of libabacus, @@ -29,6 +30,10 @@ struct libab_s { * things like functions and operators. */ libab_table table; + /** + * The number implementation used by this instance. + */ + libab_number_impl impl; }; typedef struct libab_s libab; diff --git a/include/number.h b/include/number.h new file mode 100644 index 0000000..15bb543 --- /dev/null +++ b/include/number.h @@ -0,0 +1,37 @@ +#ifndef LIBABACUS_NUMBER_H +#define LIBABACUS_NUMBER_H + +typedef void (*libab_num_function)(void*, void*, void*); +typedef void (*libab_num_function_unary)(void*, void*); + +/** + * Struct that holds information + * about the implementation of numbers + * that is being used by libab. This is not + * assumed or inferred, and it's necessary to + * provide all of these definitions. + */ +struct libab_number_impl_s { + /** + * The function used to allocate a number. + */ + void* (*allocate)(); + /** + * The function used to free a number. + */ + void (*free)(void*); + /** + * The function used to construct a number + * out of a string. + */ + void* (*parse)(const char*); + /** + * A function to copy the value of one number + * into the value of another. + */ + void (*copy)(void*, void*); +}; + +typedef struct libab_number_impl_s libab_number_impl; + +#endif