diff options
| author | Philipp Stephani | 2019-04-18 22:38:29 +0200 |
|---|---|---|
| committer | Philipp Stephani | 2019-04-24 12:53:54 +0200 |
| commit | e290a7d1730c99010272bbff7f497c3041cef46d (patch) | |
| tree | d17ccf1313e8b408c6e8cbef64e71a4f1311da4e /src/emacs-module.c | |
| parent | bffceab6339fb4042588b893ef754c6264379e75 (diff) | |
| download | emacs-e290a7d1730c99010272bbff7f497c3041cef46d.tar.gz emacs-e290a7d1730c99010272bbff7f497c3041cef46d.zip | |
Add module functions to convert from and to big integers.
* src/module-env-27.h: Add new module functions to convert big
integers.
* src/emacs-module.h.in (emacs_mpz): Define if GMP is available.
* src/emacs-module.c (module_extract_big_integer)
(module_make_big_integer): New functions.
(initialize_environment): Use them.
* test/data/emacs-module/mod-test.c (Fmod_test_double): New test
function.
(emacs_module_init): Define it.
* test/src/emacs-module-tests.el (mod-test-double): New unit test.
* doc/lispref/internals.texi (Module Values): Document new functions.
Diffstat (limited to 'src/emacs-module.c')
| -rw-r--r-- | src/emacs-module.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/emacs-module.c b/src/emacs-module.c index e46af30ce84..e203ce1d348 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c | |||
| @@ -70,6 +70,7 @@ To add a new module function, proceed as follows: | |||
| 70 | 70 | ||
| 71 | #include <config.h> | 71 | #include <config.h> |
| 72 | 72 | ||
| 73 | #define EMACS_MODULE_GMP | ||
| 73 | #include "emacs-module.h" | 74 | #include "emacs-module.h" |
| 74 | 75 | ||
| 75 | #include <stdarg.h> | 76 | #include <stdarg.h> |
| @@ -79,7 +80,10 @@ To add a new module function, proceed as follows: | |||
| 79 | #include <stdlib.h> | 80 | #include <stdlib.h> |
| 80 | #include <time.h> | 81 | #include <time.h> |
| 81 | 82 | ||
| 83 | #include <gmp.h> | ||
| 84 | |||
| 82 | #include "lisp.h" | 85 | #include "lisp.h" |
| 86 | #include "bignum.h" | ||
| 83 | #include "dynlib.h" | 87 | #include "dynlib.h" |
| 84 | #include "coding.h" | 88 | #include "coding.h" |
| 85 | #include "keyboard.h" | 89 | #include "keyboard.h" |
| @@ -752,6 +756,27 @@ module_make_time (emacs_env *env, struct timespec time) | |||
| 752 | return lisp_to_value (env, make_lisp_time (time)); | 756 | return lisp_to_value (env, make_lisp_time (time)); |
| 753 | } | 757 | } |
| 754 | 758 | ||
| 759 | static void | ||
| 760 | module_extract_big_integer (emacs_env *env, emacs_value value, | ||
| 761 | struct emacs_mpz *result) | ||
| 762 | { | ||
| 763 | MODULE_FUNCTION_BEGIN (); | ||
| 764 | Lisp_Object o = value_to_lisp (value); | ||
| 765 | CHECK_INTEGER (o); | ||
| 766 | if (FIXNUMP (o)) | ||
| 767 | mpz_set_intmax (result->value, XFIXNUM (o)); | ||
| 768 | else | ||
| 769 | mpz_set (result->value, XBIGNUM (o)->value); | ||
| 770 | } | ||
| 771 | |||
| 772 | static emacs_value | ||
| 773 | module_make_big_integer (emacs_env *env, const struct emacs_mpz *value) | ||
| 774 | { | ||
| 775 | MODULE_FUNCTION_BEGIN (NULL); | ||
| 776 | mpz_set (mpz[0], value->value); | ||
| 777 | return lisp_to_value (env, make_integer_mpz ()); | ||
| 778 | } | ||
| 779 | |||
| 755 | 780 | ||
| 756 | /* Subroutines. */ | 781 | /* Subroutines. */ |
| 757 | 782 | ||
| @@ -1157,6 +1182,8 @@ initialize_environment (emacs_env *env, struct emacs_env_private *priv) | |||
| 1157 | env->process_input = module_process_input; | 1182 | env->process_input = module_process_input; |
| 1158 | env->extract_time = module_extract_time; | 1183 | env->extract_time = module_extract_time; |
| 1159 | env->make_time = module_make_time; | 1184 | env->make_time = module_make_time; |
| 1185 | env->extract_big_integer = module_extract_big_integer; | ||
| 1186 | env->make_big_integer = module_make_big_integer; | ||
| 1160 | Vmodule_environments = Fcons (make_mint_ptr (env), Vmodule_environments); | 1187 | Vmodule_environments = Fcons (make_mint_ptr (env), Vmodule_environments); |
| 1161 | return env; | 1188 | return env; |
| 1162 | } | 1189 | } |