2 * ALSA lisp implementation
3 * Copyright (c) 2003 by Jaroslav Kysela <perex@perex.cz>
5 * Based on work of Sandro Sigala (slisp-1.2)
8 * This library is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as
10 * published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
41 ALISP_OBJ_LAST_SEARCH = ALISP_OBJ_CONS,
48 #define ALISP_TYPE_MASK 0xf0000000
49 #define ALISP_TYPE_SHIFT 28
50 #define ALISP_REFS_MASK 0x0fffffff
51 #define ALISP_REFS_SHIFT 0
52 #define ALISP_MAX_REFS (ALISP_REFS_MASK>>ALISP_REFS_SHIFT)
53 #define ALISP_MAX_REFS_LIMIT ((ALISP_MAX_REFS + 1) / 2)
56 struct list_head list;
57 unsigned int type_refs; /* type and count of references */
64 struct alisp_object *car;
65 struct alisp_object *cdr;
70 static inline enum alisp_objects alisp_get_type(struct alisp_object *p)
72 return (p->type_refs >> ALISP_TYPE_SHIFT);
75 static inline void alisp_set_type(struct alisp_object *p, enum alisp_objects type)
77 p->type_refs &= ~ALISP_TYPE_MASK;
78 p->type_refs |= (unsigned int)type << ALISP_TYPE_SHIFT;
81 static inline int alisp_compare_type(struct alisp_object *p, enum alisp_objects type)
83 return ((unsigned int)type << ALISP_TYPE_SHIFT) ==
84 (p->type_refs & ALISP_TYPE_MASK);
87 static inline void alisp_set_refs(struct alisp_object *p, unsigned int refs)
89 p->type_refs &= ~ALISP_REFS_MASK;
90 p->type_refs |= refs & ALISP_REFS_MASK;
93 static inline unsigned int alisp_get_refs(struct alisp_object *p)
95 return p->type_refs & ALISP_REFS_MASK;
98 static inline unsigned int alisp_inc_refs(struct alisp_object *p)
100 unsigned r = alisp_get_refs(p) + 1;
101 alisp_set_refs(p, r);
105 static inline unsigned int alisp_dec_refs(struct alisp_object *p)
107 unsigned r = alisp_get_refs(p) - 1;
108 alisp_set_refs(p, r);
112 struct alisp_object_pair {
113 struct list_head list;
115 struct alisp_object *value;
118 #define ALISP_LEX_BUF_MAX 16
119 #define ALISP_OBJ_PAIR_HASH_SHIFT 4
120 #define ALISP_OBJ_PAIR_HASH_SIZE (1<<ALISP_OBJ_PAIR_HASH_SHIFT)
121 #define ALISP_OBJ_PAIR_HASH_MASK (ALISP_OBJ_PAIR_HASH_SIZE-1)
122 #define ALISP_FREE_OBJ_POOL 512 /* free objects above this pool */
124 struct alisp_instance {
131 snd_output_t *eout; /* error output */
132 snd_output_t *vout; /* verbose output */
133 snd_output_t *wout; /* warning output */
134 snd_output_t *dout; /* debug output */
138 int lex_buf[ALISP_LEX_BUF_MAX];
141 int token_buffer_max;
143 /* object allocator / storage */
147 struct list_head free_objs_list;
148 struct list_head used_objs_list[ALISP_OBJ_PAIR_HASH_SIZE][ALISP_OBJ_LAST_SEARCH + 1];
150 struct list_head setobjs_list[ALISP_OBJ_PAIR_HASH_SIZE];