5 * (c) 2000 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of the mLib utilities library.
12 * mLib is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
17 * mLib is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with mLib; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
35 /*----- Header files ------------------------------------------------------*/
41 /*----- Data structures ---------------------------------------------------*/
43 typedef struct atom_table {
44 sym_table t; /* Symbol table of interned atoms */
45 hash_base *g; /* List of uninterned atoms */
46 unsigned long gseq; /* Sequence number for @gensym@ */
50 sym_base b; /* Base structure for symbol table */
51 unsigned f; /* Various useful flags */
54 #define ATOMF_GENSYM 1u /* Atom is uninterned */
56 typedef struct { sym_iter i; } atom_iter;
58 /*----- Global magic ------------------------------------------------------*/
62 /*----- Functions provided ------------------------------------------------*/
64 /* --- @atom_createtable@ --- *
66 * Arguments: @atom_table *t@ = pointer to an atom table
70 * Use: Initializes an atom table.
73 extern void atom_createtable(atom_table */*t*/);
75 /* --- @atom_destroytable@ --- *
77 * Arguments: @atom_table *t@ = pointer to an atom table
81 * Use: Destroys all of the atoms in an atom table. All of the atoms
82 * (including uninterned atoms) are freed. Any references to
83 * atoms from the table become invalid, and any association
84 * tables dependent on the atom table are unusable, except that
85 * they may be destroyed safely.
88 extern void atom_destroytable(atom_table */*t*/);
90 /* --- @atom_intern@ --- *
92 * Arguments: @atom_table *t@ = pointer to an atom table
93 * @const char *p@ = pointer to the string to intern
94 * @size_t n@ = size of the string (for @atom_nintern)
96 * Returns: A pointer to the atom block for the given symbol string.
98 * Use: Interns an atom, returning the atom block. The string can be
99 * extracted from the atom by means of the @ATOM_NAME@ macro.
102 #define INTERN(p) atom_intern(ATOM_GLOBAL, (p))
104 extern atom *atom_intern(atom_table */*t*/, const char */*p*/);
105 extern atom *atom_nintern(atom_table */*t*/,
106 const char */*p*/, size_t /*n*/);
108 /* --- @atom_gensym@ --- *
110 * Arguments: @atom_table *t@ = pointer to a symbol table
112 * Returns: A pointer to a new atom block, not previously interned.
114 * Use: Creates a new, uninterned atom. This atom will never be
115 * returned by either @atom_intern@ or any other call to
116 * @atom_gensym@, while the symbol table exists.
119 #define GENSYM atom_gensym(ATOM_GLOBAL)
121 extern atom *atom_gensym(atom_table */*t*/);
123 /* --- @atom_name@ --- *
125 * Arguments: @atom *a@ = pointer to an atom
127 * Returns: The atom's textual name.
129 * Use: Given an atom, returns the name with which it was interned
130 * (or a made-up name if it was created using @gensym@.
133 #define ATOM_NAME(a) SYM_NAME(a)
135 extern const char *atom_name(const atom */*a*/);
137 /* --- @atom_len@ --- *
139 * Arguments: @atom *a@ = pointer to an atom
141 * Returns: The atom string's length.
143 * Use: Given an atom, return the length of its textual
147 #define ATOM_LEN(a) SYM_LEN(a)
149 extern size_t atom_len(const atom */*a*/);
151 /* --- @atom_hash@ --- *
153 * Arguments: @atom *a@ = pointer to an atom
155 * Returns: The atom's hash.
157 * Use: Given an atom, returns its hash.
160 #define ATOM_HASH(a) SYM_HASH(a)
162 extern uint32 atom_hash(const atom */*a*/);
164 /* --- @atom_mkiter@ , @atom_next@ --- *
166 * Arguments: @atom_table *t@ = pointer to an atom table
167 * @atom_iter *i@ = pointer to an iterator structure
169 * Returns: Next atom, for @atom_next@; nothing for @atom_mkiter@.
171 * Use: Iterates over atoms (both interned and uninterned).
174 extern void atom_mkiter(atom_iter */*i*/, atom_table */*t*/);
175 extern atom *atom_next(atom_iter */*i*/);
177 /*----- That's all, folks -------------------------------------------------*/