1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-07-01 15:20:34 +02:00
guile/libguile/symbols.h
Andy Wingo b25a743cf9 Get strings, symbols, stringbufs off scm_double_cell
* libguile/symbols.h (scm_is_symbol, scm_to_symbol, scm_from_symbol):
Define some helpers and a "struct scm_symbol".
* libguile/strings-internal.h (scm_i_string_data): Remove.
* libguile/print.c (write_char_in_string, write_narrow_string)
(write_wide_string): Refactor to avoid per-char narrow checks.
(write_character): Move up.
(iprin1): Adapt to call write_narrow_string / write_wide_string.
* libguile/srfi-13.c (scm_string_eq): Avoid scm_i_string_data.
* libguile/strings.c (scm_is_stringbuf, scm_to_stringbuf)
(scm_from_stringbuf, stringbuf_is_wide, stringbuf_is_narrow)
(stringbuf_is_mutable, stringbuf_set_mutable, stringbuf_length)
(as_narrow_stringbuf, as_wide_stringbuf, narrow_stringbuf_chars)
(wide_stringbuf_chars, scm_to_string, scm_from_string, string_is_read_only)
(string_is_shared, string_stringbuf, string_aliased_string, string_start)
(string_length): New inline function helpers, to replace a pile of
macros.  Adapt all users.
2025-06-23 15:00:09 +02:00

143 lines
4.1 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef SCM_SYMBOLS_H
#define SCM_SYMBOLS_H
/* Copyright 1995-1998,2000-2001,2003-2004,2006,2008,2010-2011,2018,2022,2025
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>
struct scm_symbol
{
scm_t_bits tag_and_flags;
struct scm_stringbuf *name;
scm_t_bits hash;
};
static inline int
scm_is_symbol (SCM x)
{
return SCM_HAS_TYP7 (x, scm_tc7_symbol);
}
static inline struct scm_symbol*
scm_to_symbol (SCM x)
{
if (!scm_is_symbol (x))
abort ();
return (struct scm_symbol *) SCM_UNPACK_POINTER (x);
}
static inline SCM
scm_from_symbol (struct scm_symbol *x)
{
return SCM_PACK_POINTER (x);
}
#define scm_i_symbol_hash(x) ((unsigned long) 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)
# 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)) \
)
/* 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 unsigned long scm_i_hash_symbol (SCM obj, unsigned long n,
void *closure);
SCM_INTERNAL void scm_symbols_prehistory (void);
SCM_INTERNAL void scm_init_symbols (void);
#endif /* SCM_SYMBOLS_H */