Create a more clear boundary between "library" and "client"
Even though "abcs" is technically a front-end for libab, what it does is fill in some blanks left available by it. However, I'm keeping most of this "fill-in-the-blanks" code standalone, so that it may be used in other projects.
This commit is contained in:
@@ -24,6 +24,7 @@ class abacus {
|
||||
void add_operator_infix(const std::string& op, const std::string& func, int assoc, int prec);
|
||||
void add_operator_prefix(const std::string& op, const std::string& func);
|
||||
void add_operator_postfix(const std::string& op, const std::string& func);
|
||||
void add_standard();
|
||||
ref run(const std::string& code);
|
||||
template <typename ... Ts>
|
||||
ref call(const std::string& bane, Ts...params);
|
||||
|
||||
32
include/function_utils.hpp
Normal file
32
include/function_utils.hpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#define FUNCTION(name) libab_result function_##name( \
|
||||
libab* ab, libab_ref* scope, libab_ref_vec* params, libab_ref* into)
|
||||
|
||||
#define FUNCTION_MPFR(name, func) FUNCTION(name) { \
|
||||
number* value = (number*) libab_unwrap_param(params, 0); \
|
||||
mpfr_t output; \
|
||||
mpfr_init2(output, PRECISION); \
|
||||
mpfr_##func(output, value->value, MPFR_RNDN); \
|
||||
ref to_return = create_value<number>(ab, new number(std::move(output))); \
|
||||
libab_ref_copy(to_return, into); \
|
||||
return LIBAB_SUCCESS; \
|
||||
}
|
||||
|
||||
#define FUNCTION_MPFR2(name, func) FUNCTION(name) { \
|
||||
number* left = (number*) libab_unwrap_param(params, 0); \
|
||||
number* right = (number*) libab_unwrap_param(params, 1); \
|
||||
mpfr_t output; \
|
||||
mpfr_init2(output, PRECISION); \
|
||||
mpfr_##func(output, left->value, right->value, MPFR_RNDN); \
|
||||
ref to_return = create_value<number>(ab, new number(std::move(output))); \
|
||||
libab_ref_copy(to_return, into); \
|
||||
return LIBAB_SUCCESS; \
|
||||
}
|
||||
|
||||
#define FUNCTION_COMPARE(name, op) FUNCTION(name) { \
|
||||
number* left = (number*) libab_unwrap_param(params, 0); \
|
||||
number* right = (number*) libab_unwrap_param(params, 1); \
|
||||
libab_get_bool_value(ab, mpfr_cmp(left->value, right->value) op 0, into); \
|
||||
return LIBAB_SUCCESS; \
|
||||
}
|
||||
@@ -2,41 +2,11 @@
|
||||
|
||||
#include "ref.hpp"
|
||||
#include "util.hpp"
|
||||
#include "function_utils.hpp"
|
||||
extern "C" {
|
||||
#include "libabacus.h"
|
||||
}
|
||||
|
||||
#define FUNCTION(name) libab_result function_##name( \
|
||||
libab* ab, libab_ref* scope, libab_ref_vec* params, libab_ref* into)
|
||||
|
||||
#define FUNCTION_MPFR(name, func) FUNCTION(name) { \
|
||||
number* value = (number*) libab_unwrap_param(params, 0); \
|
||||
mpfr_t output; \
|
||||
mpfr_init2(output, PRECISION); \
|
||||
mpfr_##func(output, value->value, MPFR_RNDN); \
|
||||
ref to_return = create_value<number>(ab, new number(std::move(output))); \
|
||||
libab_ref_copy(to_return, into); \
|
||||
return LIBAB_SUCCESS; \
|
||||
}
|
||||
|
||||
#define FUNCTION_MPFR2(name, func) FUNCTION(name) { \
|
||||
number* left = (number*) libab_unwrap_param(params, 0); \
|
||||
number* right = (number*) libab_unwrap_param(params, 1); \
|
||||
mpfr_t output; \
|
||||
mpfr_init2(output, PRECISION); \
|
||||
mpfr_##func(output, left->value, right->value, MPFR_RNDN); \
|
||||
ref to_return = create_value<number>(ab, new number(std::move(output))); \
|
||||
libab_ref_copy(to_return, into); \
|
||||
return LIBAB_SUCCESS; \
|
||||
}
|
||||
|
||||
#define FUNCTION_COMPARE(name, op) FUNCTION(name) { \
|
||||
number* left = (number*) libab_unwrap_param(params, 0); \
|
||||
number* right = (number*) libab_unwrap_param(params, 1); \
|
||||
libab_get_bool_value(ab, mpfr_cmp(left->value, right->value) op 0, into); \
|
||||
return LIBAB_SUCCESS; \
|
||||
}
|
||||
|
||||
FUNCTION(print_string);
|
||||
FUNCTION(to_string_num);
|
||||
FUNCTION(to_string_bool);
|
||||
|
||||
Reference in New Issue
Block a user