mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 03:40:34 +02:00
On x86-64-MinGW the size of long is 4. As long is used for SCM_FIXNUM_BIT, that would mean incompatible .go files, and waste of cell space. So we would like to use long long, but the GMP interface uses long. To get around this, the x86-64-MinGW port now requires the use of mini-GMP. Mini-GMP has been changed to use intptr_t and uintptr_t. Likewise, "integers.{h,c}" and "numbers.{h,c}" now use intptr_t instead of scm_t_inum or long, and uintptr_t instead of unsigned long. * configure.ac: When x86_64-w64-mingw32, require mini-GMP. * libguile/mini-gmp.h: Use intptr_t instead of long, uintptr_t instead of unsigned long throughout. * libguile/mini-gmp.c: Likewise. * libguile/scm.h (SCM_INTPTR_T_BIT): New define. * libguile/numbers.h (SCM_FIXNUM_BIT): Use it. * libguile/numbers.c (L1, UL1): New macros. Use them thoughout instead of 1L, 1UL. (verify): Use SCM_INTPTR_T_BIT. (verify): Use SCM_INTPTR_T_MAX and SCM_INTPTR_T_MIN. (scm_from_inum): Remove macro. Use intptr_t and uintptr_t instead of scm_t_inum or long, and unsigned long. * libguile/numbers.h (scm_from_intptr, scm_from_uintptr, scm_to_intptr, scm_to_uintptr): New defines. * libguile/integers.h: Use intptr_t and uintptr_t instead of scm_t_inum and unsigned long. * libguile/integers.c (L1) : New macro. Use it thoughout instead of 1L. Use intptr_t and uintptr_t instead of long and unsigned long. (long_magnitude): Rename to... (intptr_t_magnitude): ...this. Use intptr_t, uintptr_t. (negative_long): Rename to... (negative_t_intptr): ...this. Use uintptr_t, INTPTR_MIN. (inum_magnitude): Use intptr_t. (ulong_to_bignum): Rename to... (uintptr_t_to_bignum): ...this. Use uintptr_t. (long_to_bignum): Rename to... (intptr_t_to_bignum): ...this. Use intptr_t. (long_to_scm): Rename to... (intptr_t_to_scm): ...this. Use intptr_to_bignum. (ulong_to_scm): Rename to... (uintptr_t_to_scm): ...this. Use uintptr_to_bignum. (long_sign): Rename to.. (intptr_t_sign): ...this. Use SCM_SIZEOF_INTPTR_T. (bignum_cmp_long): Rename to... (bignum_cmp_intptr_t): ...this. Use uintptr_t. * libguile/array-map.c (array_compare): Use uintptr_t instead of unsigned long and intptr_t instead of long. * libguile/arrays.c (make-shared-array): Use ssize_t instead of long. * libguile/bytevectors.c (is_signed_int32, is_unsigned_int32) [MINGW32 && __x86_64__]: Use ULL. (twos_complement): Use uintptr_t instead of unsigned long. * libguile/hash.c (JENKINS_LOOKUP3_HASHWORD2): Likewise. (narrow_string_hash, wide_string_hash, scm_i_string_hash, scm_i_locale_string_hash, scm_i_latin1_string_hash, scm_i_utf8_string_hash, scm_i_struct_hash, scm_raw_ihashq, scm_raw_ihash): Use and return uintptr_t instead of unsigned long. (scm_hashv, scm_hash): Use SCM_UINTPTR_T_MAX. * libguile/hash.h (scm_i_locale_string_hash, scm_i_latin1_string_hash, scm_i_utf8_string_hash): update prototypes. * libguile/scmsigs.c (sigaction): Use intptr_t instead of long. * libguile/strings.c (scm_i_make_symbol, (scm_i_c_make_symbol): Use uintptr_t instead of unsigned long. * libguile/strings.h (scm_i_make_symbol, (scm_i_c_make_symbol): Update declacations. * libguile/srfi-60.c: Use scm_to_uintptr, scm_from_intptr and variants throughout. * libguile/symbols.c (symbol-hash): Use scm_from_uintptr. Co-authored-by: Mike Gran <spk121@yahoo.com> Co-authored-by: Andy Wingo <wingo@pobox.com>
131 lines
4.1 KiB
C
131 lines
4.1 KiB
C
#ifndef SCM_SYMBOLS_H
|
||
#define SCM_SYMBOLS_H
|
||
|
||
/* Copyright 1995-1998,2000-2001,2003-2004,2006,2008,2010-2011,2018,2022
|
||
Free Software Foundation, Inc.
|
||
|
||
This file is part of Guile.
|
||
|
||
Guile is free software: you can redistribute it and/or modify it
|
||
under the terms of the GNU Lesser General Public License as published
|
||
by the Free Software Foundation, either version 3 of the License, or
|
||
(at your option) any later version.
|
||
|
||
Guile 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 Lesser General Public
|
||
License for more details.
|
||
|
||
You should have received a copy of the GNU Lesser General Public
|
||
License along with Guile. If not, see
|
||
<https://www.gnu.org/licenses/>. */
|
||
|
||
|
||
|
||
#include <libguile/error.h>
|
||
#include <libguile/gc.h>
|
||
#include <libguile/snarf.h>
|
||
#include <libguile/strings.h>
|
||
|
||
|
||
|
||
|
||
#define scm_is_symbol(x) (SCM_HAS_TYP7 (x, scm_tc7_symbol))
|
||
#define scm_i_symbol_hash(x) ((uintptr_t) SCM_CELL_WORD_2 (x))
|
||
#define scm_i_symbol_is_interned(x) \
|
||
(!(SCM_CELL_WORD_0 (x) & SCM_I_F_SYMBOL_UNINTERNED))
|
||
|
||
#define SCM_I_F_SYMBOL_UNINTERNED 0x100
|
||
|
||
#define SCM_VALIDATE_SYMBOL(pos, str) \
|
||
do { \
|
||
SCM_ASSERT_TYPE (scm_is_symbol (str), str, pos, FUNC_NAME, "symbol"); \
|
||
} while (0)
|
||
|
||
|
||
|
||
|
||
#ifdef SCM_SUPPORT_STATIC_ALLOCATION
|
||
|
||
# define SCM_SYMBOL(c_name, scheme_name) \
|
||
SCM_SNARF_HERE( \
|
||
SCM_IMMUTABLE_STRING (scm_i_paste (c_name, _string), scheme_name); \
|
||
static SCM c_name) \
|
||
SCM_SNARF_INIT( \
|
||
c_name = scm_string_to_symbol (scm_i_paste (c_name, _string)) \
|
||
)
|
||
|
||
# define SCM_GLOBAL_SYMBOL(c_name, scheme_name) \
|
||
SCM_SNARF_HERE( \
|
||
SCM_IMMUTABLE_STRING (scm_i_paste (c_name, _string), scheme_name); \
|
||
SCM c_name) \
|
||
SCM_SNARF_INIT( \
|
||
c_name = scm_string_to_symbol (scm_i_paste (c_name, _string)) \
|
||
)
|
||
|
||
#else /* !SCM_SUPPORT_STATIC_ALLOCATION */
|
||
|
||
# define SCM_SYMBOL(c_name, scheme_name) \
|
||
SCM_SNARF_HERE(static SCM c_name) \
|
||
SCM_SNARF_INIT(c_name = scm_from_utf8_symbol (scheme_name))
|
||
|
||
# define SCM_GLOBAL_SYMBOL(c_name, scheme_name) \
|
||
SCM_SNARF_HERE(SCM c_name) \
|
||
SCM_SNARF_INIT(c_name = scm_from_utf8_symbol (scheme_name))
|
||
|
||
#endif /* !SCM_SUPPORT_STATIC_ALLOCATION */
|
||
|
||
|
||
|
||
/* Older spellings; don't use in new code.
|
||
*/
|
||
#define SCM_SYMBOLP(x) (scm_is_symbol (x))
|
||
#define SCM_SYMBOL_HASH(x) (scm_i_symbol_hash (x))
|
||
#define SCM_SYMBOL_INTERNED_P(x) (scm_i_symbol_is_interned (x))
|
||
|
||
|
||
|
||
#ifdef GUILE_DEBUG
|
||
SCM_API SCM scm_sys_symbols (void);
|
||
#endif
|
||
|
||
SCM_API SCM scm_symbol_p (SCM x);
|
||
SCM_API SCM scm_symbol_interned_p (SCM sym);
|
||
SCM_API SCM scm_make_symbol (SCM name);
|
||
SCM_API SCM scm_symbol_to_string (SCM s);
|
||
SCM_API SCM scm_string_to_symbol (SCM s);
|
||
SCM_API SCM scm_string_ci_to_symbol (SCM s);
|
||
|
||
SCM_API SCM scm_symbol_hash (SCM s);
|
||
SCM_API SCM scm_gensym (SCM prefix);
|
||
|
||
/* Use locale encoding for user input, user output, or interacting with
|
||
the C library. Use latin-1 for ASCII, and for literals in source
|
||
code. Use UTF-8 for interaction with modern libraries which deal in
|
||
UTF-8. Otherwise use scm_to_stringn or scm_from_stringn, and
|
||
convert. */
|
||
|
||
SCM_API SCM scm_from_locale_symbol (const char *str);
|
||
SCM_API SCM scm_from_locale_symboln (const char *str, size_t len);
|
||
SCM_API SCM scm_take_locale_symbol (char *sym);
|
||
SCM_API SCM scm_take_locale_symboln (char *sym, size_t len);
|
||
|
||
SCM_API SCM scm_from_latin1_symbol (const char *str);
|
||
SCM_API SCM scm_from_latin1_symboln (const char *str, size_t len);
|
||
SCM_API SCM scm_take_latin1_symbol (char *sym);
|
||
SCM_API SCM scm_take_latin1_symboln (char *sym, size_t len);
|
||
|
||
SCM_API SCM scm_from_utf8_symbol (const char *str);
|
||
SCM_API SCM scm_from_utf8_symboln (const char *str, size_t len);
|
||
SCM_API SCM scm_take_utf8_symbol (char *sym);
|
||
SCM_API SCM scm_take_utf8_symboln (char *sym, size_t len);
|
||
|
||
/* internal functions. */
|
||
|
||
SCM_INTERNAL uintptr_t scm_i_hash_symbol (SCM obj, uintptr_t n,
|
||
void *closure);
|
||
|
||
SCM_INTERNAL void scm_symbols_prehistory (void);
|
||
SCM_INTERNAL void scm_init_symbols (void);
|
||
|
||
#endif /* SCM_SYMBOLS_H */
|