Blame src/alisp/alisp_local.h

Packit 4a16fb
/*
Packit 4a16fb
 *  ALSA lisp implementation
Packit 4a16fb
 *  Copyright (c) 2003 by Jaroslav Kysela <perex@perex.cz>
Packit 4a16fb
 *
Packit 4a16fb
 *  Based on work of Sandro Sigala (slisp-1.2)
Packit 4a16fb
 *
Packit 4a16fb
 *
Packit 4a16fb
 *   This library is free software; you can redistribute it and/or modify
Packit 4a16fb
 *   it under the terms of the GNU Lesser General Public License as
Packit 4a16fb
 *   published by the Free Software Foundation; either version 2.1 of
Packit 4a16fb
 *   the License, or (at your option) any later version.
Packit 4a16fb
 *
Packit 4a16fb
 *   This program is distributed in the hope that it will be useful,
Packit 4a16fb
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 4a16fb
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 4a16fb
 *   GNU Lesser General Public License for more details.
Packit 4a16fb
 *
Packit 4a16fb
 *   You should have received a copy of the GNU Lesser General Public
Packit 4a16fb
 *   License along with this library; if not, write to the Free Software
Packit 4a16fb
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
Packit 4a16fb
 *
Packit 4a16fb
 */
Packit 4a16fb
Packit 4a16fb
#include "list.h"
Packit 4a16fb
Packit 4a16fb
enum alisp_tokens {
Packit 4a16fb
	ALISP_IDENTIFIER,
Packit 4a16fb
	ALISP_INTEGER,
Packit 4a16fb
	ALISP_FLOAT,
Packit 4a16fb
	ALISP_FLOATE,
Packit 4a16fb
	ALISP_STRING
Packit 4a16fb
};
Packit 4a16fb
Packit 4a16fb
enum alisp_objects {
Packit 4a16fb
	ALISP_OBJ_INTEGER,
Packit 4a16fb
	ALISP_OBJ_FLOAT,
Packit 4a16fb
	ALISP_OBJ_IDENTIFIER,
Packit 4a16fb
	ALISP_OBJ_STRING,
Packit 4a16fb
	ALISP_OBJ_POINTER,
Packit 4a16fb
	ALISP_OBJ_CONS,
Packit 4a16fb
	ALISP_OBJ_LAST_SEARCH = ALISP_OBJ_CONS,
Packit 4a16fb
	ALISP_OBJ_NIL,
Packit 4a16fb
	ALISP_OBJ_T,
Packit 4a16fb
};
Packit 4a16fb
Packit 4a16fb
struct alisp_object;
Packit 4a16fb
Packit 4a16fb
#define ALISP_TYPE_MASK	0xf0000000
Packit 4a16fb
#define ALISP_TYPE_SHIFT 28
Packit 4a16fb
#define ALISP_REFS_MASK 0x0fffffff
Packit 4a16fb
#define ALISP_REFS_SHIFT 0
Packit 4a16fb
#define ALISP_MAX_REFS (ALISP_REFS_MASK>>ALISP_REFS_SHIFT)
Packit 4a16fb
#define ALISP_MAX_REFS_LIMIT ((ALISP_MAX_REFS + 1) / 2)
Packit 4a16fb
Packit 4a16fb
struct alisp_object {
Packit 4a16fb
	struct list_head list;
Packit 4a16fb
	unsigned int	type_refs;	/* type and count of references */
Packit 4a16fb
	union {
Packit 4a16fb
		char	*s;
Packit 4a16fb
		long	i;
Packit 4a16fb
		double	f;
Packit 4a16fb
		const void *ptr;
Packit 4a16fb
		struct {
Packit 4a16fb
			struct alisp_object *car;
Packit 4a16fb
			struct alisp_object *cdr;
Packit 4a16fb
		} c;
Packit 4a16fb
	} value;
Packit 4a16fb
};
Packit 4a16fb
Packit 4a16fb
static inline enum alisp_objects alisp_get_type(struct alisp_object *p)
Packit 4a16fb
{
Packit 4a16fb
	return (p->type_refs >> ALISP_TYPE_SHIFT);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static inline void alisp_set_type(struct alisp_object *p, enum alisp_objects type)
Packit 4a16fb
{
Packit 4a16fb
	p->type_refs &= ~ALISP_TYPE_MASK;
Packit 4a16fb
	p->type_refs |= (unsigned int)type << ALISP_TYPE_SHIFT;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static inline int alisp_compare_type(struct alisp_object *p, enum alisp_objects type)
Packit 4a16fb
{
Packit 4a16fb
	return ((unsigned int)type << ALISP_TYPE_SHIFT) ==
Packit 4a16fb
	       (p->type_refs & ALISP_TYPE_MASK);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static inline void alisp_set_refs(struct alisp_object *p, unsigned int refs)
Packit 4a16fb
{
Packit 4a16fb
	p->type_refs &= ~ALISP_REFS_MASK;
Packit 4a16fb
	p->type_refs |= refs & ALISP_REFS_MASK;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static inline unsigned int alisp_get_refs(struct alisp_object *p)
Packit 4a16fb
{
Packit 4a16fb
	return p->type_refs & ALISP_REFS_MASK;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static inline unsigned int alisp_inc_refs(struct alisp_object *p)
Packit 4a16fb
{
Packit 4a16fb
	unsigned r = alisp_get_refs(p) + 1;
Packit 4a16fb
	alisp_set_refs(p, r);
Packit 4a16fb
	return r;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
static inline unsigned int alisp_dec_refs(struct alisp_object *p)
Packit 4a16fb
{
Packit 4a16fb
	unsigned r = alisp_get_refs(p) - 1;
Packit 4a16fb
	alisp_set_refs(p, r);
Packit 4a16fb
	return r;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
struct alisp_object_pair {
Packit 4a16fb
	struct list_head list;
Packit 4a16fb
	const char *name;
Packit 4a16fb
 	struct alisp_object *value;
Packit 4a16fb
};
Packit 4a16fb
Packit 4a16fb
#define ALISP_LEX_BUF_MAX	16
Packit 4a16fb
#define ALISP_OBJ_PAIR_HASH_SHIFT 4
Packit 4a16fb
#define ALISP_OBJ_PAIR_HASH_SIZE (1<
Packit 4a16fb
#define ALISP_OBJ_PAIR_HASH_MASK (ALISP_OBJ_PAIR_HASH_SIZE-1)
Packit 4a16fb
#define ALISP_FREE_OBJ_POOL	512	/* free objects above this pool */
Packit 4a16fb
Packit 4a16fb
struct alisp_instance {
Packit 4a16fb
	int verbose: 1,
Packit 4a16fb
	    warning: 1,
Packit 4a16fb
	    debug: 1;
Packit 4a16fb
	/* i/o */
Packit 4a16fb
	snd_input_t *in;
Packit 4a16fb
	snd_output_t *out;
Packit 4a16fb
	snd_output_t *eout;	/* error output */
Packit 4a16fb
	snd_output_t *vout;	/* verbose output */
Packit 4a16fb
	snd_output_t *wout;	/* warning output */
Packit 4a16fb
	snd_output_t *dout;	/* debug output */
Packit 4a16fb
	/* lexer */
Packit 4a16fb
	int charno;
Packit 4a16fb
	int lineno;
Packit 4a16fb
	int lex_buf[ALISP_LEX_BUF_MAX];
Packit 4a16fb
	int *lex_bufp;
Packit 4a16fb
	char *token_buffer;
Packit 4a16fb
	int token_buffer_max;
Packit 4a16fb
	int thistoken;
Packit 4a16fb
	/* object allocator / storage */
Packit 4a16fb
	long free_objs;
Packit 4a16fb
	long used_objs;
Packit 4a16fb
	long max_objs;
Packit 4a16fb
	struct list_head free_objs_list;
Packit 4a16fb
	struct list_head used_objs_list[ALISP_OBJ_PAIR_HASH_SIZE][ALISP_OBJ_LAST_SEARCH + 1];
Packit 4a16fb
	/* set object */
Packit 4a16fb
	struct list_head setobjs_list[ALISP_OBJ_PAIR_HASH_SIZE];
Packit 4a16fb
};