diff --git a/include/function_utils.hpp b/include/function_utils.hpp index 35e9178..5fd2bdb 100644 --- a/include/function_utils.hpp +++ b/include/function_utils.hpp @@ -1,5 +1,9 @@ #pragma once +extern "C" { +#include "libabacus.h" +} + #define FUNCTION(name) libab_result function_##name( \ libab* ab, libab_ref* scope, libab_ref_vec* params, libab_ref* into) diff --git a/include/functions.hpp b/include/functions.hpp index db6de04..c1e334c 100644 --- a/include/functions.hpp +++ b/include/functions.hpp @@ -1,44 +1,5 @@ #pragma once -#include "ref.hpp" -#include "util.hpp" -#include "function_utils.hpp" -extern "C" { -#include "libabacus.h" -} - -FUNCTION(print_string); -FUNCTION(to_string_num); -FUNCTION(to_string_bool); -FUNCTION(to_string_unit); - -FUNCTION(plus); -FUNCTION(minus); -FUNCTION(times); -FUNCTION(divide); -FUNCTION(pow); - -FUNCTION(lt); -FUNCTION(lte); -FUNCTION(equals); -FUNCTION(gt); -FUNCTION(gte); - -FUNCTION(negate); -FUNCTION(factorial); - -FUNCTION(ln); -FUNCTION(exp); - -FUNCTION(sqrt); - -FUNCTION(sin); -FUNCTION(cos); -FUNCTION(tan); - -FUNCTION(arcsin); -FUNCTION(arccos); -FUNCTION(arctan); - -FUNCTION(quit); -FUNCTION(request_precision); +#include "operator_functions.hpp" +#include "other_functions.hpp" +#include "trig_functions.hpp" diff --git a/include/operator_functions.hpp b/include/operator_functions.hpp new file mode 100644 index 0000000..c01e351 --- /dev/null +++ b/include/operator_functions.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include "function_utils.hpp" + +FUNCTION(plus); +FUNCTION(minus); +FUNCTION(times); +FUNCTION(divide); +FUNCTION(pow); + +FUNCTION(lt); +FUNCTION(lte); +FUNCTION(equals); +FUNCTION(gt); +FUNCTION(gte); + +FUNCTION(negate); +FUNCTION(factorial); diff --git a/include/other_functions.hpp b/include/other_functions.hpp new file mode 100644 index 0000000..6aaf25a --- /dev/null +++ b/include/other_functions.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include "function_utils.hpp" + +FUNCTION(ln); +FUNCTION(exp); + +FUNCTION(sqrt); diff --git a/include/repl_functions.hpp b/include/repl_functions.hpp new file mode 100644 index 0000000..4e0e556 --- /dev/null +++ b/include/repl_functions.hpp @@ -0,0 +1,6 @@ +#pragma once + +#include "function_utils.hpp" + +FUNCTION(quit); +FUNCTION(request_precision); diff --git a/include/string_functions.hpp b/include/string_functions.hpp new file mode 100644 index 0000000..1e8f77d --- /dev/null +++ b/include/string_functions.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include "function_utils.hpp" + +FUNCTION(print_string); +FUNCTION(to_string_num); +FUNCTION(to_string_bool); +FUNCTION(to_string_unit); diff --git a/include/trig_functions.hpp b/include/trig_functions.hpp new file mode 100644 index 0000000..8fef160 --- /dev/null +++ b/include/trig_functions.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include "function_utils.hpp" + +FUNCTION(sin); +FUNCTION(cos); +FUNCTION(tan); + +FUNCTION(arcsin); +FUNCTION(arccos); +FUNCTION(arctan); + diff --git a/src/abacus.cpp b/src/abacus.cpp index 761ac5d..5b64910 100644 --- a/src/abacus.cpp +++ b/src/abacus.cpp @@ -44,14 +44,6 @@ void abacus::add_operator_postfix(const std::string& op, const std::string& func } void abacus::add_standard() { - add_function("quit", function_quit, "()->unit"); - add_function("request_precision", function_request_precision, "(num)->unit"); - - add_function("print", function_print_string, "(str)->unit"); - add_function("to_string", function_to_string_num, "(num)->str"); - add_function("to_string", function_to_string_bool, "(bool)->str"); - add_function("to_string", function_to_string_unit, "(unit)->str"); - add_function("lt", function_lt, "(num, num)->num"); add_function("lte", function_lte, "(num, num)->num"); add_function("equals", function_equals, "(num, num)->num"); diff --git a/src/main.cpp b/src/main.cpp index 2d922fa..9dc975c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,7 +7,8 @@ #include #include "types.hpp" #include "ref.hpp" -#include "function_utils.hpp" +#include "repl_functions.hpp" +#include "string_functions.hpp" #include "abacus.hpp" extern "C" { #include "libabacus.h" @@ -48,6 +49,14 @@ int main() { size_t index = 0; ab.add_standard(); + ab.add_function("quit", function_quit, "()->unit"); + ab.add_function("request_precision", function_request_precision, "(num)->unit"); + + ab.add_function("print", function_print_string, "(str)->unit"); + ab.add_function("to_string", function_to_string_num, "(num)->str"); + ab.add_function("to_string", function_to_string_bool, "(bool)->str"); + ab.add_function("to_string", function_to_string_unit, "(unit)->str"); + run_rc(ab); while(!close_requested) { char* data = readline(" > "); diff --git a/src/operator_functions.cpp b/src/operator_functions.cpp index acc31ad..db3d5ca 100644 --- a/src/operator_functions.cpp +++ b/src/operator_functions.cpp @@ -1,4 +1,11 @@ -#include "functions.hpp" +#include "operator_functions.hpp" +#include +#include "types.hpp" +#include "ref.hpp" +#include "util.hpp" +extern "C" { +#include "util.h" +} FUNCTION_MPFR2(plus, add) FUNCTION_MPFR2(minus, sub) diff --git a/src/other_functions.cpp b/src/other_functions.cpp index 45c9a97..d194436 100644 --- a/src/other_functions.cpp +++ b/src/other_functions.cpp @@ -1,4 +1,7 @@ -#include "functions.hpp" +#include "other_functions.hpp" +#include +#include "types.hpp" +#include "util.hpp" FUNCTION_MPFR(ln, log); FUNCTION_MPFR(exp, exp); diff --git a/src/string_functions.cpp b/src/string_functions.cpp index fbd3c5e..1febb89 100644 --- a/src/string_functions.cpp +++ b/src/string_functions.cpp @@ -1,4 +1,7 @@ -#include "functions.hpp" +#include "string_functions.hpp" +#include "ref.hpp" +#include "types.hpp" +#include "util.hpp" #include #include diff --git a/src/trig_functions.cpp b/src/trig_functions.cpp index b7a7334..29f0ef7 100644 --- a/src/trig_functions.cpp +++ b/src/trig_functions.cpp @@ -1,4 +1,8 @@ -#include "functions.hpp" +#include "trig_functions.hpp" +#include +#include "ref.hpp" +#include "types.hpp" +#include "util.hpp" FUNCTION_MPFR(sin, sin); FUNCTION_MPFR(cos, cos);