mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-07-04 16:50:25 +02:00
Move keywords off of scm_cell
* libguile/keywords-internal.h: New file. * libguile/Makefile.am (noinst_HEADERS): Add new file. * libguile/hash.c: * libguile/init.c: * libguile/keywords.c: Include new file. (scm_symbol_to_keyword): Allocate via scm_allocate_tagged.
This commit is contained in:
parent
27caa4cb98
commit
b262df6ca7
6 changed files with 77 additions and 25 deletions
|
@ -521,6 +521,7 @@ noinst_HEADERS = custom-ports.h \
|
||||||
gc-inline.h \
|
gc-inline.h \
|
||||||
gc-internal.h \
|
gc-internal.h \
|
||||||
gsubr-internal.h \
|
gsubr-internal.h \
|
||||||
|
keywords-internal.h \
|
||||||
posix-w32.h \
|
posix-w32.h \
|
||||||
private-options.h \
|
private-options.h \
|
||||||
programs.h \
|
programs.h \
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
#include "chars.h"
|
#include "chars.h"
|
||||||
#include "foreign.h"
|
#include "foreign.h"
|
||||||
#include "gsubr.h"
|
#include "gsubr.h"
|
||||||
#include "keywords.h"
|
#include "keywords-internal.h"
|
||||||
#include "numbers.h"
|
#include "numbers.h"
|
||||||
#include "pairs.h"
|
#include "pairs.h"
|
||||||
#include "ports.h"
|
#include "ports.h"
|
||||||
|
|
|
@ -87,7 +87,7 @@
|
||||||
#include "intrinsics.h"
|
#include "intrinsics.h"
|
||||||
#include "ioext.h"
|
#include "ioext.h"
|
||||||
#include "jit.h"
|
#include "jit.h"
|
||||||
#include "keywords.h"
|
#include "keywords-internal.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "load.h"
|
#include "load.h"
|
||||||
#include "loader.h"
|
#include "loader.h"
|
||||||
|
|
56
libguile/keywords-internal.h
Normal file
56
libguile/keywords-internal.h
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
#ifndef SCM_KEYWORDS_INTERNAL_H
|
||||||
|
#define SCM_KEYWORDS_INTERNAL_H
|
||||||
|
|
||||||
|
/* Copyright 1995-1996,1999-2001,2006,2008,2015,2018-2019,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/keywords.h>
|
||||||
|
#include <libguile/scm.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct scm_keyword
|
||||||
|
{
|
||||||
|
scm_t_bits tag;
|
||||||
|
SCM symbol;
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline struct scm_keyword *
|
||||||
|
scm_to_keyword (SCM x)
|
||||||
|
{
|
||||||
|
return (struct scm_keyword *) SCM_UNPACK_POINTER (x);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline SCM
|
||||||
|
scm_from_keyword (struct scm_keyword *keyword)
|
||||||
|
{
|
||||||
|
return SCM_PACK_POINTER (keyword);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define SCM_KEYWORDP(x) (scm_is_keyword (x))
|
||||||
|
#define SCM_VALIDATE_KEYWORD(pos, v) \
|
||||||
|
SCM_MAKE_VALIDATE_MSG (pos, v, KEYWORDP, "keyword")
|
||||||
|
|
||||||
|
#define SCM_I_KEYWORD_HASH(x) scm_i_symbol_hash (scm_to_keyword (x)->symbol)
|
||||||
|
|
||||||
|
SCM_INTERNAL void scm_init_keywords (void);
|
||||||
|
|
||||||
|
#endif /* SCM_KEYWORDS_INTERNAL_H */
|
|
@ -35,23 +35,21 @@
|
||||||
#include "ports.h"
|
#include "ports.h"
|
||||||
#include "strings.h"
|
#include "strings.h"
|
||||||
#include "symbols.h"
|
#include "symbols.h"
|
||||||
|
#include "threads.h"
|
||||||
|
|
||||||
#include "keywords.h"
|
#include "keywords-internal.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static SCM keyword_obarray;
|
static SCM keyword_obarray;
|
||||||
|
|
||||||
#define SCM_KEYWORDP(x) (SCM_HAS_TYP7 (x, scm_tc7_keyword))
|
|
||||||
#define SCM_KEYWORD_SYMBOL(x) (SCM_CELL_OBJECT_1 (x))
|
|
||||||
|
|
||||||
SCM_DEFINE (scm_keyword_p, "keyword?", 1, 0, 0,
|
SCM_DEFINE (scm_keyword_p, "keyword?", 1, 0, 0,
|
||||||
(SCM obj),
|
(SCM obj),
|
||||||
"Return @code{#t} if the argument @var{obj} is a keyword, else\n"
|
"Return @code{#t} if the argument @var{obj} is a keyword, else\n"
|
||||||
"@code{#f}.")
|
"@code{#f}.")
|
||||||
#define FUNC_NAME s_scm_keyword_p
|
#define FUNC_NAME s_scm_keyword_p
|
||||||
{
|
{
|
||||||
return scm_from_bool (SCM_KEYWORDP (obj));
|
return scm_from_bool (scm_is_keyword (obj));
|
||||||
}
|
}
|
||||||
#undef FUNC_NAME
|
#undef FUNC_NAME
|
||||||
|
|
||||||
|
@ -66,12 +64,16 @@ SCM_DEFINE (scm_symbol_to_keyword, "symbol->keyword", 1, 0, 0,
|
||||||
|
|
||||||
scm_dynwind_begin (0);
|
scm_dynwind_begin (0);
|
||||||
scm_i_dynwind_pthread_mutex_lock (&scm_i_misc_mutex);
|
scm_i_dynwind_pthread_mutex_lock (&scm_i_misc_mutex);
|
||||||
/* Note: `scm_cell' and `scm_hashq_set_x' can raise an out-of-memory
|
/* Note: allocating and `scm_hashq_set_x' can raise an out-of-memory
|
||||||
error. */
|
error. */
|
||||||
keyword = scm_hashq_ref (keyword_obarray, symbol, SCM_BOOL_F);
|
keyword = scm_hashq_ref (keyword_obarray, symbol, SCM_BOOL_F);
|
||||||
if (scm_is_false (keyword))
|
if (scm_is_false (keyword))
|
||||||
{
|
{
|
||||||
keyword = scm_cell (scm_tc7_keyword, SCM_UNPACK (symbol));
|
struct scm_keyword *kw = scm_allocate_tagged (SCM_I_CURRENT_THREAD,
|
||||||
|
sizeof (*kw));
|
||||||
|
kw->tag = scm_tc7_keyword;
|
||||||
|
kw->symbol = symbol;
|
||||||
|
keyword = scm_from_keyword (kw);
|
||||||
scm_hashq_set_x (keyword_obarray, symbol, keyword);
|
scm_hashq_set_x (keyword_obarray, symbol, keyword);
|
||||||
}
|
}
|
||||||
scm_dynwind_end ();
|
scm_dynwind_end ();
|
||||||
|
@ -85,16 +87,10 @@ SCM_DEFINE (scm_keyword_to_symbol, "keyword->symbol", 1, 0, 0,
|
||||||
#define FUNC_NAME s_scm_keyword_to_symbol
|
#define FUNC_NAME s_scm_keyword_to_symbol
|
||||||
{
|
{
|
||||||
SCM_VALIDATE_KEYWORD (1, keyword);
|
SCM_VALIDATE_KEYWORD (1, keyword);
|
||||||
return SCM_KEYWORD_SYMBOL (keyword);
|
return scm_to_keyword (keyword)->symbol;
|
||||||
}
|
}
|
||||||
#undef FUNC_NAME
|
#undef FUNC_NAME
|
||||||
|
|
||||||
int
|
|
||||||
scm_is_keyword (SCM val)
|
|
||||||
{
|
|
||||||
return SCM_KEYWORDP (val);
|
|
||||||
}
|
|
||||||
|
|
||||||
SCM
|
SCM
|
||||||
scm_from_locale_keyword (const char *name)
|
scm_from_locale_keyword (const char *name)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef SCM_KEYWORDS_H
|
#ifndef SCM_KEYWORDS_H
|
||||||
#define SCM_KEYWORDS_H
|
#define SCM_KEYWORDS_H
|
||||||
|
|
||||||
/* Copyright 1995-1996,1999-2001,2006,2008,2015,2018-2019
|
/* Copyright 1995-1996,1999-2001,2006,2008,2015,2018-2019,2025
|
||||||
Free Software Foundation, Inc.
|
Free Software Foundation, Inc.
|
||||||
|
|
||||||
This file is part of Guile.
|
This file is part of Guile.
|
||||||
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
#include <libguile/error.h>
|
#include <libguile/error.h>
|
||||||
#include <libguile/snarf.h>
|
#include <libguile/snarf.h>
|
||||||
|
#include <libguile/scm.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,15 +32,17 @@ SCM_API SCM scm_keyword_p (SCM obj);
|
||||||
SCM_API SCM scm_symbol_to_keyword (SCM symbol);
|
SCM_API SCM scm_symbol_to_keyword (SCM symbol);
|
||||||
SCM_API SCM scm_keyword_to_symbol (SCM keyword);
|
SCM_API SCM scm_keyword_to_symbol (SCM keyword);
|
||||||
|
|
||||||
SCM_API int scm_is_keyword (SCM val);
|
static inline int
|
||||||
|
scm_is_keyword (SCM x)
|
||||||
|
{
|
||||||
|
return SCM_HAS_TYP7 (x, scm_tc7_keyword);
|
||||||
|
}
|
||||||
|
|
||||||
SCM_API SCM scm_from_locale_keyword (const char *name);
|
SCM_API SCM scm_from_locale_keyword (const char *name);
|
||||||
SCM_API SCM scm_from_locale_keywordn (const char *name, size_t len);
|
SCM_API SCM scm_from_locale_keywordn (const char *name, size_t len);
|
||||||
SCM_API SCM scm_from_latin1_keyword (const char *name);
|
SCM_API SCM scm_from_latin1_keyword (const char *name);
|
||||||
SCM_API SCM scm_from_utf8_keyword (const char *name);
|
SCM_API SCM scm_from_utf8_keyword (const char *name);
|
||||||
|
|
||||||
#define SCM_VALIDATE_KEYWORD(pos, v) \
|
|
||||||
SCM_MAKE_VALIDATE_MSG (pos, v, KEYWORDP, "keyword")
|
|
||||||
|
|
||||||
#define SCM_KEYWORD(c_name, scheme_name) \
|
#define SCM_KEYWORD(c_name, scheme_name) \
|
||||||
SCM_SNARF_HERE(static SCM c_name) \
|
SCM_SNARF_HERE(static SCM c_name) \
|
||||||
SCM_SNARF_INIT(c_name = scm_from_utf8_keyword (scheme_name))
|
SCM_SNARF_INIT(c_name = scm_from_utf8_keyword (scheme_name))
|
||||||
|
@ -60,8 +63,4 @@ SCM_API void
|
||||||
scm_c_bind_keyword_arguments (const char *subr, SCM rest,
|
scm_c_bind_keyword_arguments (const char *subr, SCM rest,
|
||||||
scm_t_keyword_arguments_flags flags, ...);
|
scm_t_keyword_arguments_flags flags, ...);
|
||||||
|
|
||||||
#define SCM_I_KEYWORD_HASH(x) scm_i_symbol_hash (SCM_CELL_OBJECT_1 (x))
|
|
||||||
|
|
||||||
SCM_INTERNAL void scm_init_keywords (void);
|
|
||||||
|
|
||||||
#endif /* SCM_KEYWORDS_H */
|
#endif /* SCM_KEYWORDS_H */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue