Mercurial > hg > xemacs-beta
view src/number-gmp.h @ 4690:257b468bf2ca
Move the #'query-coding-region implementation to C.
This is necessary because there is no reasonable way to access the
corresponding mswindows-multibyte functionality from Lisp, and we need such
functionality if we're going to have a reliable and portable
#'query-coding-region implementation. However, this change doesn't yet
provide #'query-coding-region for the mswindow-multibyte coding systems,
there should be no functional differences between an XEmacs with this change
and one without it.
src/ChangeLog addition:
2009-09-19 Aidan Kehoe <kehoea@parhasard.net>
Move the #'query-coding-region implementation to C.
This is necessary because there is no reasonable way to access the
corresponding mswindows-multibyte functionality from Lisp, and we
need such functionality if we're going to have a reliable and
portable #'query-coding-region implementation. However, this
change doesn't yet provide #'query-coding-region for the
mswindow-multibyte coding systems, there should be no functional
differences between an XEmacs with this change and one without it.
* mule-coding.c (struct fixed_width_coding_system):
Add a new coding system type, fixed_width, and implement it. It
uses the CCL infrastructure but has a much simpler creation API,
and its own query_method, formerly in lisp/mule/mule-coding.el.
* unicode.c:
Move the Unicode query method implementation here from
unicode.el.
* lisp.h: Declare Fmake_coding_system_internal, Fcopy_range_table
here.
* intl-win32.c (complex_vars_of_intl_win32):
Use Fmake_coding_system_internal, not Fmake_coding_system.
* general-slots.h: Add Qsucceeded, Qunencodable, Qinvalid_sequence
here.
* file-coding.h (enum coding_system_variant):
Add fixed_width_coding_system here.
(struct coding_system_methods):
Add query_method and query_lstream_method to the coding system
methods.
Provide flags for the query methods.
Declare the default query method; initialise it correctly in
INITIALIZE_CODING_SYSTEM_TYPE.
* file-coding.c (default_query_method):
New function, the default query method for coding systems that do
not set it. Moved from coding.el.
(make_coding_system_1):
Accept new elements in PROPS in #'make-coding-system; aliases, a
list of aliases; safe-chars and safe-charsets (these were
previously accepted but not saved); and category.
(Fmake_coding_system_internal):
New function, what used to be #'make-coding-system--on Mule
builds, we've now moved some of the functionality of this to
Lisp.
(Fcoding_system_canonical_name_p):
Move this earlier in the file, since it's now called from within
make_coding_system_1.
(Fquery_coding_region):
Move the implementation of this here, from coding.el.
(complex_vars_of_file_coding):
Call Fmake_coding_system_internal, not Fmake_coding_system;
specify safe-charsets properties when we're a mule build.
* extents.h (mouse_highlight_priority, Fset_extent_priority,
Fset_extent_face, Fmap_extents):
Make these available to other C files.
lisp/ChangeLog addition:
2009-09-19 Aidan Kehoe <kehoea@parhasard.net>
Move the #'query-coding-region implementation to C.
* coding.el:
Consolidate code that depends on the presence or absence of Mule
at the end of this file.
(default-query-coding-region, query-coding-region):
Move these functions to C.
(default-query-coding-region-safe-charset-skip-chars-map):
Remove this variable, the corresponding C variable is
Vdefault_query_coding_region_chartab_cache in file-coding.c.
(query-coding-string): Update docstring to reflect actual multiple
values, be more careful about not modifying a range table that
we're currently mapping over.
(encode-coding-char): Make the implementation of this simpler.
(featurep 'mule): Autoload #'make-coding-system from
mule/make-coding-system.el if we're a mule build; provide an
appropriate compiler macro.
Do various non-mule compatibility things if we're not a mule
build.
* update-elc.el (additional-dump-dependencies):
Add mule/make-coding-system as a dump time dependency if we're a
mule build.
* unicode.el (ccl-encode-to-ucs-2):
(decode-char):
(encode-char):
Move these earlier in the file, for the sake of some byte compile
warnings.
(unicode-query-coding-region):
Move this to unicode.c
* mule/make-coding-system.el:
New file, not dumped. Contains the functionality to rework the
arguments necessary for fixed-width coding systems, and contains
the implementation of #'make-coding-system, which now calls
#'make-coding-system-internal.
* mule/vietnamese.el (viscii):
* mule/latin.el (iso-8859-2):
(windows-1250):
(iso-8859-3):
(iso-8859-4):
(iso-8859-14):
(iso-8859-15):
(iso-8859-16):
(iso-8859-9):
(macintosh):
(windows-1252):
* mule/hebrew.el (iso-8859-8):
* mule/greek.el (iso-8859-7):
(windows-1253):
* mule/cyrillic.el (iso-8859-5):
(koi8-r):
(koi8-u):
(windows-1251):
(alternativnyj):
(koi8-ru):
(koi8-t):
(koi8-c):
(koi8-o):
* mule/arabic.el (iso-8859-6):
(windows-1256):
Move all these coding systems to being of type fixed-width, not of
type CCL. This allows the distinct query-coding-region for them to
be in C, something which will eventually allow us to implement
query-coding-region for the mswindows-multibyte coding systems.
* mule/general-late.el (posix-charset-to-coding-system-hash):
Document why we're pre-emptively persuading the byte compiler that
the ELC for this file needs to be written using escape-quoted.
Call #'set-unicode-query-skip-chars-args, now the Unicode
query-coding-region implementation is in C.
* mule/thai-xtis.el (tis-620):
Don't bother checking whether we're XEmacs or not here.
* mule/mule-coding.el:
Move the eight bit fixed-width functionality from this file to
make-coding-system.el.
tests/ChangeLog addition:
2009-09-19 Aidan Kehoe <kehoea@parhasard.net>
* automated/mule-tests.el:
Check a coding system's type, not an 8-bit-fixed property, for
whether that coding system should be treated as a fixed-width
coding system.
* automated/query-coding-tests.el:
Don't test the query coding functionality for mswindows-multibyte
coding systems, it's not yet implemented.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Sat, 19 Sep 2009 22:53:13 +0100 |
parents | ee35a8fdcfcd |
children | 2fc0e2f18322 |
line wrap: on
line source
/* Definitions of numeric types for XEmacs using the GNU MP library. Copyright (C) 2004 Jerry James. This file is part of XEmacs. XEmacs is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. XEmacs is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with XEmacs; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Synched up with: Not in FSF. */ /* This library defines the following types: bignum = mpz_t ratio = mpq_t bigfloat = mpf_t */ #ifndef INCLUDED_number_gmp_h_ #define INCLUDED_number_gmp_h_ #ifdef UNO /* Uno complains about several inline functions that include conditions with assignments and side effects if we don't do this */ #undef __GNUC__ #endif #ifdef _MSC_VER /* "unary minus operator applied to unsigned type, result still unsigned": Occurs on line 1596 of gmp.h in version 4.1.4. */ #pragma warning ( disable : 4146 ) #endif #include <gmp.h> #ifdef _MSC_VER #pragma warning ( default : 4146 ) #endif typedef mpz_t bignum; typedef mpq_t ratio; typedef mpf_t bigfloat; extern void init_number_gmp(void); /********************************* Bignums **********************************/ #define HAVE_BIGNUM 1 extern gmp_randstate_t random_state; /***** Bignum: basic functions *****/ #define bignum_init(b) mpz_init (b) #define bignum_fini(b) mpz_clear (b) #define bignum_hashcode(b) mpz_get_ui (b) #define bignum_sign(b) mpz_sgn (b) #define bignum_evenp(b) mpz_even_p (b) #define bignum_oddp(b) mpz_odd_p (b) /***** Bignum: size *****/ #define bignum_fits_int_p(b) mpz_fits_sint_p (b) #define bignum_fits_uint_p(b) mpz_fits_uint_p (b) #define bignum_fits_long_p(b) mpz_fits_slong_p (b) #define bignum_fits_ulong_p(b) mpz_fits_ulong_p (b) /***** Bignum: conversions *****/ #define bignum_to_string(b,base) mpz_get_str (NULL, base, b) #define bignum_to_int(b) ((int) mpz_get_si (b)) #define bignum_to_uint(b) ((unsigned int) mpz_get_ui (b)) #define bignum_to_long(b) mpz_get_si (b) #define bignum_to_ulong(b) mpz_get_ui (b) #define bignum_to_double(b) mpz_get_d (b) /***** Bignum: converting assignments *****/ #define bignum_set(b1,b2) mpz_set (b1, b2) #define bignum_set_string(b,s,base) mpz_set_str (b, s, base) #define bignum_set_long(b,l) mpz_set_si (b, l) #define bignum_set_ulong(b,l) mpz_set_ui (b, l) #define bignum_set_double(b,f) mpz_set_d (b, f) #define bignum_set_ratio(b,r) mpz_set_q (b, r) #define bignum_set_bigfloat(b,f) mpz_set_f (b, f) /***** Bignum: comparisons *****/ #define bignum_cmp(b1,b2) mpz_cmp (b1, b2) #define bignum_lt(b1,b2) (mpz_cmp (b1, b2) < 0) #define bignum_le(b1,b2) (mpz_cmp (b1, b2) <= 0) #define bignum_eql(b1,b2) (mpz_cmp (b1, b2) == 0) #define bignum_ge(b1,b2) (mpz_cmp (b1, b2) >= 0) #define bignum_gt(b1,b2) (mpz_cmp (b1, b2) > 0) /***** Bignum: arithmetic *****/ #define bignum_neg(b,b2) mpz_neg (b, b2) #define bignum_abs(b,b2) mpz_abs (b, b2) #define bignum_add(b,b1,b2) mpz_add (b, b1, b2) #define bignum_sub(b,b1,b2) mpz_sub (b, b1, b2) #define bignum_mul(b,b1,b2) mpz_mul (b, b1, b2) #define bignum_divisible_p(b1,b2) mpz_divisible_p (b1, b2) #define bignum_div(b,b1,b2) mpz_tdiv_q (b, b1, b2) #define bignum_ceil(b,b1,b2) mpz_cdiv_q (b, b1, b2) #define bignum_floor(b,b1,b2) mpz_fdiv_q (b, b1, b2) #define bignum_mod(b,b1,b2) mpz_mod (b, b1, b2) #define bignum_pow(res,b,pow) mpz_pow_ui (res, b, pow) #define bignum_gcd(res,b1,b2) mpz_gcd (res, b1, b2) #define bignum_lcm(res,b1,b2) mpz_lcm (res, b1, b2) /***** Bignum: bit manipulations *****/ #define bignum_and(res,b1,b2) mpz_and (res, b1, b2) #define bignum_ior(res,b1,b2) mpz_ior (res, b1, b2) #define bignum_xor(res,b1,b2) mpz_xor (res, b1, b2) #define bignum_not(res,b) mpz_com (res, b) #define bignum_setbit(b,bit) mpz_setbit (b, bit) #define bignum_clrbit(b,bit) mpz_clrbit (b, bit) #define bignum_testbit(b,bit) mpz_tstbit (b, bit) #define bignum_lshift(res,b,bits) mpz_mul_2exp (res, b, bits) #define bignum_rshift(res,b,bits) mpz_fdiv_q_2exp (res, b, bits) /***** Bignum: random numbers *****/ #define bignum_random_seed(seed) gmp_randseed_ui (random_state, seed) #define bignum_random(res,limit) mpz_urandomm (res, random_state, limit) /********************************** Ratios **********************************/ #define HAVE_RATIO 1 /***** Ratio: basic functions *****/ #define ratio_init(r) mpq_init (r) #define ratio_fini(r) mpq_clear (r) #define ratio_hashcode(r) \ (mpz_get_ui (mpq_denref (r)) * mpz_get_ui (mpq_numref (r))) #define ratio_sign(r) mpq_sgn (r) #define ratio_numerator(r) mpq_numref (r) #define ratio_denominator(r) mpq_denref (r) #define ratio_canonicalize(r) mpq_canonicalize (r) /***** Ratio: conversions *****/ #define ratio_to_string(r,base) mpq_get_str (NULL, base, r) #define ratio_to_int(r) ((int) (mpq_get_d (r))) #define ratio_to_uint(r) ((unsigned int) (mpq_get_d (r))) #define ratio_to_long(r) ((long) (mpq_get_d (r))) #define ratio_to_ulong(r) ((unsigned long) (mpq_get_d (r))) #define ratio_to_double(r) mpq_get_d (r) /***** Ratio: converting assignments *****/ #define ratio_set(r1,r2) mpq_set (r1, r2) #define ratio_set_string(r,s,base) mpq_set_str (r, s, base) #define ratio_set_long(r,l) mpq_set_si (r, l, 1UL) #define ratio_set_ulong(r,l) mpq_set_ui (r, l, 1UL) #define ratio_set_double(r,f) mpq_set_d (r, f) #define ratio_set_bignum(r,b) mpq_set_z (r, b) #define ratio_set_bigfloat(r,f) mpq_set_f (r, f) #define ratio_set_long_ulong(r,num,den) mpq_set_si (r, num, den) #define ratio_set_ulong_ulong(r,num,den) mpq_set_ui (r, num, den) /* FIXME: Why does this canonicalize, but the previous 2 don't? */ #define ratio_set_bignum_bignum(r,num,den) do { \ mpz_set (mpq_numref (r), num); \ mpz_set (mpq_denref (r), den); \ mpq_canonicalize (r); \ } while (0) /***** Ratio: comparisons *****/ #define ratio_cmp(r1,r2) mpq_cmp (r1, r2) #define ratio_lt(r1,r2) (mpq_cmp (r1, r2) < 0) #define ratio_le(r1,r2) (mpq_cmp (r1, r2) <= 0) #define ratio_eql(r1,r2) mpq_equal (r1, r2) #define ratio_ge(r1,r2) (mpq_cmp (r1, r2) >= 0) #define ratio_gt(r1,r2) (mpq_cmp (r1, r2) > 0) /***** Ratio: arithmetic *****/ #define ratio_neg(q,q2) mpq_neg (q, q2) #define ratio_abs(q,q2) mpq_abs (q, q2) #define ratio_inv(q,q2) mpq_inv (q, q2) #define ratio_add(res,q1,q2) mpq_add (res, q1, q2) #define ratio_sub(res,q1,q2) mpq_sub (res, q1, q2) #define ratio_mul(res,q1,q2) mpq_mul (res, q1, q2) #define ratio_div(res,q1,q2) mpq_div (res, q1, q2) /******************************** Bigfloats *********************************/ #define HAVE_BIGFLOAT 1 /***** Bigfloat: basic functions *****/ #define bigfloat_init(f) mpf_init (f) #define bigfloat_init_prec(f,prec) mpf_init2 (f, prec) #define bigfloat_fini(f) mpf_clear (f) #define bigfloat_hashcode(f) mpf_get_ui (f) #define bigfloat_sign(f) mpf_sgn (f) #define bigfloat_get_prec(f) mpf_get_prec (f) #define bigfloat_set_prec(f, prec) mpf_set_prec (f, prec) #define bigfloat_set_default_prec(prec) mpf_set_default_prec(prec) #define bigfloat_get_default_prec() mpf_get_default_prec () /***** Bigfloat: conversions *****/ extern CIbyte *bigfloat_to_string (bigfloat f, int base); #define bigfloat_to_int(f) ((int) mpf_get_si (f)) #define bigfloat_to_uint(f) ((unsigned int) mpf_get_ui (f)) #define bigfloat_to_long(f) mpf_get_si (f) #define bigfloat_to_ulong(f) mpf_get_ui (f) #define bigfloat_to_double(f) mpf_get_d (f) /***** Bigfloat: converting assignments *****/ #define bigfloat_set(f1,f2) mpf_set (f1, f2) #define bigfloat_set_string(f,str,base) mpf_set_str (f, str, base) #define bigfloat_set_long(f,l) mpf_set_si (f, l) #define bigfloat_set_ulong(f,l) mpf_set_ui (f, l) #define bigfloat_set_double(d,f) mpf_set_d (d, f) #define bigfloat_set_bignum(f,b) mpf_set_z (f, b) #define bigfloat_set_ratio(f,r) mpf_set_q (f, r) /***** Bigfloat: comparisons *****/ #define bigfloat_cmp(f1,f2) mpf_cmp (f1, f2) #define bigfloat_lt(f1,f2) (mpf_cmp (f1, f2) < 0) #define bigfloat_le(f1,f2) (mpf_cmp (f1, f2) <= 0) #define bigfloat_eql(f1,f2) (mpf_cmp (f1, f2) == 0) #define bigfloat_eql_bits(f1,f2,bits) mpf_eq (f1, f2, bits) #define bigfloat_ge(f1,f2) (mpf_cmp (f1, f2) >= 0) #define bigfloat_gt(f1,f2) (mpf_cmp (f1, f2) > 0) /***** Bigfloat: arithmetic *****/ #define bigfloat_neg(f,f2) mpf_neg (f, f2) #define bigfloat_abs(f,f2) mpf_abs (f, f2) #define bigfloat_add(res,f1,f2) mpf_add (res, f1, f2) #define bigfloat_sub(res,f1,f2) mpf_sub (res, f1, f2) #define bigfloat_mul(res,f1,f2) mpf_mul (res, f1, f2) #define bigfloat_div(res,f1,f2) mpf_div (res, f1, f2) #define bigfloat_ceil(res,f) mpf_ceil (res, f) #define bigfloat_floor(res,f) mpf_floor (res, f) #define bigfloat_trunc(res,f) mpf_trunc (res, f) #define bigfloat_sqrt(res,f) mpf_sqrt (res, f) #define bigfloat_pow(res,f,exp) mpf_pow_ui (res, f, exp) #endif /* INCLUDED_number_gmp_h_ */