symbols.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #ifndef SCM_SYMBOLS_H
  2. #define SCM_SYMBOLS_H
  3. /* Copyright 1995-1998,2000-2001,2003-2004,2006,2008,2010-2011,2018
  4. Free Software Foundation, Inc.
  5. This file is part of Guile.
  6. Guile is free software: you can redistribute it and/or modify it
  7. under the terms of the GNU Lesser General Public License as published
  8. by the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Guile is distributed in the hope that it will be useful, but WITHOUT
  11. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  13. License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with Guile. If not, see
  16. <https://www.gnu.org/licenses/>. */
  17. #include <libguile/error.h>
  18. #include <libguile/gc.h>
  19. #include <libguile/snarf.h>
  20. #include <libguile/strings.h>
  21. #define scm_is_symbol(x) (SCM_HAS_TYP7 (x, scm_tc7_symbol))
  22. #define scm_i_symbol_hash(x) ((unsigned long) SCM_CELL_WORD_2 (x))
  23. #define scm_i_symbol_is_interned(x) \
  24. (!(SCM_CELL_WORD_0 (x) & SCM_I_F_SYMBOL_UNINTERNED))
  25. #define SCM_I_F_SYMBOL_UNINTERNED 0x100
  26. #define SCM_VALIDATE_SYMBOL(pos, str) \
  27. do { \
  28. SCM_ASSERT_TYPE (scm_is_symbol (str), str, pos, FUNC_NAME, "symbol"); \
  29. } while (0)
  30. #ifdef SCM_SUPPORT_STATIC_ALLOCATION
  31. # define SCM_SYMBOL(c_name, scheme_name) \
  32. SCM_SNARF_HERE( \
  33. SCM_IMMUTABLE_STRING (scm_i_paste (c_name, _string), scheme_name); \
  34. static SCM c_name) \
  35. SCM_SNARF_INIT( \
  36. c_name = scm_string_to_symbol (scm_i_paste (c_name, _string)) \
  37. )
  38. # define SCM_GLOBAL_SYMBOL(c_name, scheme_name) \
  39. SCM_SNARF_HERE( \
  40. SCM_IMMUTABLE_STRING (scm_i_paste (c_name, _string), scheme_name); \
  41. SCM c_name) \
  42. SCM_SNARF_INIT( \
  43. c_name = scm_string_to_symbol (scm_i_paste (c_name, _string)) \
  44. )
  45. #else /* !SCM_SUPPORT_STATIC_ALLOCATION */
  46. # define SCM_SYMBOL(c_name, scheme_name) \
  47. SCM_SNARF_HERE(static SCM c_name) \
  48. SCM_SNARF_INIT(c_name = scm_from_utf8_symbol (scheme_name))
  49. # define SCM_GLOBAL_SYMBOL(c_name, scheme_name) \
  50. SCM_SNARF_HERE(SCM c_name) \
  51. SCM_SNARF_INIT(c_name = scm_from_utf8_symbol (scheme_name))
  52. #endif /* !SCM_SUPPORT_STATIC_ALLOCATION */
  53. /* Older spellings; don't use in new code.
  54. */
  55. #define SCM_SYMBOLP(x) (scm_is_symbol (x))
  56. #define SCM_SYMBOL_FUNC(x) (scm_symbol_fref (x))
  57. #define SCM_SET_SYMBOL_FUNC(x,f) (scm_symbol_fset_x (x, f))
  58. #define SCM_SYMBOL_PROPS(x) (scm_symbol_pref (x))
  59. #define SCM_SET_SYMBOL_PROPS(x,p) (scm_symbol_pset_x (x, p))
  60. #define SCM_SYMBOL_HASH(x) (scm_i_symbol_hash (x))
  61. #define SCM_SYMBOL_INTERNED_P(x) (scm_i_symbol_is_interned (x))
  62. #ifdef GUILE_DEBUG
  63. SCM_API SCM scm_sys_symbols (void);
  64. #endif
  65. SCM_API SCM scm_symbol_p (SCM x);
  66. SCM_API SCM scm_symbol_interned_p (SCM sym);
  67. SCM_API SCM scm_make_symbol (SCM name);
  68. SCM_API SCM scm_symbol_to_string (SCM s);
  69. SCM_API SCM scm_string_to_symbol (SCM s);
  70. SCM_API SCM scm_string_ci_to_symbol (SCM s);
  71. SCM_API SCM scm_symbol_fref (SCM s);
  72. SCM_API SCM scm_symbol_pref (SCM s);
  73. SCM_API SCM scm_symbol_fset_x (SCM s, SCM val);
  74. SCM_API SCM scm_symbol_pset_x (SCM s, SCM val);
  75. SCM_API SCM scm_symbol_hash (SCM s);
  76. SCM_API SCM scm_gensym (SCM prefix);
  77. /* Use locale encoding for user input, user output, or interacting with
  78. the C library. Use latin-1 for ASCII, and for literals in source
  79. code. Use UTF-8 for interaction with modern libraries which deal in
  80. UTF-8. Otherwise use scm_to_stringn or scm_from_stringn, and
  81. convert. */
  82. SCM_API SCM scm_from_locale_symbol (const char *str);
  83. SCM_API SCM scm_from_locale_symboln (const char *str, size_t len);
  84. SCM_API SCM scm_take_locale_symbol (char *sym);
  85. SCM_API SCM scm_take_locale_symboln (char *sym, size_t len);
  86. SCM_API SCM scm_from_latin1_symbol (const char *str);
  87. SCM_API SCM scm_from_latin1_symboln (const char *str, size_t len);
  88. SCM_API SCM scm_take_latin1_symbol (char *sym);
  89. SCM_API SCM scm_take_latin1_symboln (char *sym, size_t len);
  90. SCM_API SCM scm_from_utf8_symbol (const char *str);
  91. SCM_API SCM scm_from_utf8_symboln (const char *str, size_t len);
  92. SCM_API SCM scm_take_utf8_symbol (char *sym);
  93. SCM_API SCM scm_take_utf8_symboln (char *sym, size_t len);
  94. /* internal functions. */
  95. SCM_INTERNAL unsigned long scm_i_hash_symbol (SCM obj, unsigned long n,
  96. void *closure);
  97. SCM_INTERNAL void scm_symbols_prehistory (void);
  98. SCM_INTERNAL void scm_init_symbols (void);
  99. #endif /* SCM_SYMBOLS_H */