2003-02-19 16:16:46 +00:00
|
|
|
|
/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2003 Free Software Foundation, Inc.
|
1999-03-14 16:50:01 +00:00
|
|
|
|
*
|
2003-04-05 19:15:35 +00:00
|
|
|
|
* This library 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 2.1 of the License, or (at your option) any later version.
|
1999-03-14 16:50:01 +00:00
|
|
|
|
*
|
2003-04-05 19:15:35 +00:00
|
|
|
|
* This library 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.
|
1999-03-14 16:50:01 +00:00
|
|
|
|
*
|
2003-04-05 19:15:35 +00:00
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
|
*/
|
1999-12-12 02:36:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
1999-03-14 16:50:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
2001-01-26 17:30:54 +00:00
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
2000-04-21 14:16:44 +00:00
|
|
|
|
#include "libguile/_scm.h"
|
|
|
|
|
|
#include "libguile/ports.h"
|
|
|
|
|
|
#include "libguile/root.h"
|
|
|
|
|
|
#include "libguile/smob.h"
|
2001-02-02 04:56:25 +00:00
|
|
|
|
#include "libguile/hashtab.h"
|
2000-04-21 14:16:44 +00:00
|
|
|
|
|
|
|
|
|
|
#include "libguile/validate.h"
|
|
|
|
|
|
#include "libguile/keywords.h"
|
1999-03-14 16:50:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
2001-06-14 19:50:43 +00:00
|
|
|
|
scm_t_bits scm_tc16_keyword;
|
2000-12-08 17:32:56 +00:00
|
|
|
|
|
1999-03-14 16:50:01 +00:00
|
|
|
|
static int
|
2001-06-07 21:12:19 +00:00
|
|
|
|
keyword_print (SCM exp, SCM port, scm_print_state *pstate SCM_UNUSED)
|
1999-03-14 16:50:01 +00:00
|
|
|
|
{
|
2001-06-08 10:02:33 +00:00
|
|
|
|
SCM symbol = SCM_KEYWORDSYM (exp);
|
|
|
|
|
|
|
1999-03-14 16:50:01 +00:00
|
|
|
|
scm_puts ("#:", port);
|
2001-06-08 10:02:33 +00:00
|
|
|
|
scm_print_symbol_name (SCM_SYMBOL_CHARS (symbol) + 1,
|
|
|
|
|
|
SCM_SYMBOL_LENGTH (symbol) - 1,
|
2001-05-30 23:48:13 +00:00
|
|
|
|
port);
|
2001-06-08 10:02:33 +00:00
|
|
|
|
scm_remember_upto_here_1 (symbol);
|
1999-03-14 16:50:01 +00:00
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2000-01-05 19:05:23 +00:00
|
|
|
|
SCM_DEFINE (scm_make_keyword_from_dash_symbol, "make-keyword-from-dash-symbol", 1, 0, 0,
|
1999-12-12 02:36:16 +00:00
|
|
|
|
(SCM symbol),
|
2000-08-11 15:12:37 +00:00
|
|
|
|
"Make a keyword object from a @var{symbol} that starts with a dash.")
|
1999-12-12 02:36:16 +00:00
|
|
|
|
#define FUNC_NAME s_scm_make_keyword_from_dash_symbol
|
1999-03-14 16:50:01 +00:00
|
|
|
|
{
|
2001-05-15 14:57:22 +00:00
|
|
|
|
SCM keyword;
|
1999-03-14 16:50:01 +00:00
|
|
|
|
|
2000-01-04 22:23:42 +00:00
|
|
|
|
SCM_ASSERT (SCM_SYMBOLP (symbol)
|
2000-09-22 17:17:55 +00:00
|
|
|
|
&& ('-' == SCM_SYMBOL_CHARS(symbol)[0]),
|
1999-12-12 02:36:16 +00:00
|
|
|
|
symbol, SCM_ARG1, FUNC_NAME);
|
1999-03-14 16:50:01 +00:00
|
|
|
|
|
|
|
|
|
|
SCM_DEFER_INTS;
|
2001-05-15 14:57:22 +00:00
|
|
|
|
keyword = scm_hashq_ref (scm_keyword_obarray, symbol, SCM_BOOL_F);
|
|
|
|
|
|
if (SCM_FALSEP (keyword))
|
1999-03-14 16:50:01 +00:00
|
|
|
|
{
|
2000-04-03 08:47:51 +00:00
|
|
|
|
SCM_NEWSMOB (keyword, scm_tc16_keyword, SCM_UNPACK (symbol));
|
2001-05-15 14:57:22 +00:00
|
|
|
|
scm_hashq_set_x (scm_keyword_obarray, symbol, keyword);
|
1999-03-14 16:50:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
SCM_ALLOW_INTS;
|
2001-05-15 14:57:22 +00:00
|
|
|
|
return keyword;
|
1999-03-14 16:50:01 +00:00
|
|
|
|
}
|
1999-12-12 02:36:16 +00:00
|
|
|
|
#undef FUNC_NAME
|
1999-03-14 16:50:01 +00:00
|
|
|
|
|
1999-06-23 11:16:09 +00:00
|
|
|
|
SCM
|
|
|
|
|
|
scm_c_make_keyword (char *s)
|
|
|
|
|
|
{
|
* gc.h, gc.c (scm_gc_sweep): Issue deprecation warning when
non-zero is returned from a port or smob free function.
(scm_malloc, scm_realloc, scm_strndup, scm_strdup,
scm_gc_register_collectable_memory,
scm_gc_unregister_collectable_memory, scm_gc_malloc,
scm_gc_realloc, scm_gc_free, scm_gc_strndup, scm_gc_strdup): New.
* backtrace.c, continuations.c, convert.i.c, coop-threads.c,
debug-malloc.c, dynl.c, environments.c, environments.h,
extensions.c, filesys.c, fports.c, gc.c, gc.h, gh_data.c, goops.c,
guardians.c, hooks.c, init.c, keywords.c, load.c, numbers.c,
ports.c, posix.c, procs.c, rdelim.c, regex-posix.c, root.c,
smob.c, stime.c, strings.c, struct.c, struct.h, symbols.c, unif.c,
vectors.c, weaks.c: Use scm_gc_malloc/scm_malloc and
scm_gc_free/free instead of scm_must_malloc and scm_must_free, as
appropriate. Return zero from smob and port free functions.
* debug-malloc.c (scm_malloc_reregister): Handle "old == NULL".
* fports.c (scm_setvbuf): Reset read buffer to saved values when
it is pointing to the putback buffer.
2002-02-11 18:06:50 +00:00
|
|
|
|
char *buf = scm_malloc (strlen (s) + 2);
|
2000-12-11 14:48:23 +00:00
|
|
|
|
SCM symbol;
|
|
|
|
|
|
|
1999-06-23 11:16:09 +00:00
|
|
|
|
buf[0] = '-';
|
|
|
|
|
|
strcpy (buf + 1, s);
|
2000-12-11 14:48:23 +00:00
|
|
|
|
symbol = scm_str2symbol (buf);
|
* gc.h, gc.c (scm_gc_sweep): Issue deprecation warning when
non-zero is returned from a port or smob free function.
(scm_malloc, scm_realloc, scm_strndup, scm_strdup,
scm_gc_register_collectable_memory,
scm_gc_unregister_collectable_memory, scm_gc_malloc,
scm_gc_realloc, scm_gc_free, scm_gc_strndup, scm_gc_strdup): New.
* backtrace.c, continuations.c, convert.i.c, coop-threads.c,
debug-malloc.c, dynl.c, environments.c, environments.h,
extensions.c, filesys.c, fports.c, gc.c, gc.h, gh_data.c, goops.c,
guardians.c, hooks.c, init.c, keywords.c, load.c, numbers.c,
ports.c, posix.c, procs.c, rdelim.c, regex-posix.c, root.c,
smob.c, stime.c, strings.c, struct.c, struct.h, symbols.c, unif.c,
vectors.c, weaks.c: Use scm_gc_malloc/scm_malloc and
scm_gc_free/free instead of scm_must_malloc and scm_must_free, as
appropriate. Return zero from smob and port free functions.
* debug-malloc.c (scm_malloc_reregister): Handle "old == NULL".
* fports.c (scm_setvbuf): Reset read buffer to saved values when
it is pointing to the putback buffer.
2002-02-11 18:06:50 +00:00
|
|
|
|
free (buf);
|
2000-12-11 14:48:23 +00:00
|
|
|
|
|
|
|
|
|
|
return scm_make_keyword_from_dash_symbol (symbol);
|
1999-06-23 11:16:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2000-01-05 19:25:37 +00:00
|
|
|
|
SCM_DEFINE (scm_keyword_p, "keyword?", 1, 0, 0,
|
2000-01-26 01:17:16 +00:00
|
|
|
|
(SCM obj),
|
2001-04-03 13:19:05 +00:00
|
|
|
|
"Return @code{#t} if the argument @var{obj} is a keyword, else\n"
|
|
|
|
|
|
"@code{#f}.")
|
1999-12-12 02:36:16 +00:00
|
|
|
|
#define FUNC_NAME s_scm_keyword_p
|
1999-03-14 16:50:01 +00:00
|
|
|
|
{
|
2001-03-30 15:03:23 +00:00
|
|
|
|
return SCM_BOOL (SCM_KEYWORDP (obj));
|
1999-03-14 16:50:01 +00:00
|
|
|
|
}
|
1999-12-12 02:36:16 +00:00
|
|
|
|
#undef FUNC_NAME
|
1999-03-14 16:50:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
2000-01-05 19:25:37 +00:00
|
|
|
|
SCM_DEFINE (scm_keyword_dash_symbol, "keyword-dash-symbol", 1, 0, 0,
|
2000-01-26 01:17:16 +00:00
|
|
|
|
(SCM keyword),
|
2000-08-11 15:12:37 +00:00
|
|
|
|
"Return the dash symbol for @var{keyword}.\n"
|
|
|
|
|
|
"This is the inverse of @code{make-keyword-from-dash-symbol}.")
|
1999-12-12 02:36:16 +00:00
|
|
|
|
#define FUNC_NAME s_scm_keyword_dash_symbol
|
1999-03-14 16:50:01 +00:00
|
|
|
|
{
|
2001-03-30 15:03:23 +00:00
|
|
|
|
SCM_VALIDATE_KEYWORD (1, keyword);
|
|
|
|
|
|
return SCM_KEYWORDSYM (keyword);
|
1999-03-14 16:50:01 +00:00
|
|
|
|
}
|
1999-12-12 02:36:16 +00:00
|
|
|
|
#undef FUNC_NAME
|
1999-03-14 16:50:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
scm_init_keywords ()
|
|
|
|
|
|
{
|
2000-12-08 17:32:56 +00:00
|
|
|
|
scm_tc16_keyword = scm_make_smob_type ("keyword", 0);
|
|
|
|
|
|
scm_set_smob_mark (scm_tc16_keyword, scm_markcdr);
|
|
|
|
|
|
scm_set_smob_print (scm_tc16_keyword, keyword_print);
|
2000-05-15 11:47:48 +00:00
|
|
|
|
|
2003-02-19 16:16:46 +00:00
|
|
|
|
scm_keyword_obarray = scm_c_make_hash_table (0);
|
2000-04-21 14:16:44 +00:00
|
|
|
|
#include "libguile/keywords.x"
|
1999-03-14 16:50:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2000-03-19 19:01:16 +00:00
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
Local Variables:
|
|
|
|
|
|
c-file-style: "gnu"
|
|
|
|
|
|
End:
|
|
|
|
|
|
*/
|