1/* Copyright 1992 NEC Corporation, Tokyo, Japan.
2 *
3 * Permission to use, copy, modify, distribute and sell this software
4 * and its documentation for any purpose is hereby granted without
5 * fee, provided that the above copyright notice appear in all copies
6 * and that both that copyright notice and this permission notice
7 * appear in supporting documentation, and that the name of NEC
8 * Corporation not be used in advertising or publicity pertaining to
9 * distribution of the software without specific, written prior
10 * permission.  NEC Corporation makes no representations about the
11 * suitability of this software for any purpose.  It is provided "as
12 * is" without express or implied warranty.
13 *
14 * NEC CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
16 * NO EVENT SHALL NEC CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
18 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19 * OTHER TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
21 */
22
23/* $Id: lisp.h 10525 2004-12-23 21:23:50Z korli $ */
24
25#include "canna.h"
26
27#include <stdio.h>
28#include "symbolname.h"
29
30#define	YES	1
31#define NO	0
32
33#define VALGET  1
34#define VALSET  0
35
36#ifdef WIN
37#define CELLSIZE	5120	/* size of cell area (byte)		*/
38#else
39#define CELLSIZE	10240	/* size of cell area (byte)		*/
40#endif
41
42#define STKSIZE		1024	/* the depth of value & parameter stack	*/
43#define BUFSIZE	 	256	/* universal buffer size (byte)		*/
44
45#ifdef NIL
46#undef NIL
47#endif
48#define NIL	   0L		/* internal expression of NIL		*/
49#define UNBOUND	  -2L		/* unbound mark of variable		*/
50#define NON	  -1L		/* the mark of No. (unable to use NO)	*/
51
52#define UNDEF		0
53#define	SPECIAL		1
54#define	SUBR		2
55#define	EXPR		3
56#define	CMACRO		4
57#define	MACRO		5
58
59#define TAG_MASK	0x07000000L
60#define CELL_MASK	0x00ffffffL
61#define GC_MASK		0x08000000L
62
63#define NIL_TAG		0L
64#define NUMBER_TAG	0x01000000L
65#define STRING_TAG	0x02000000L
66#define SYMBOL_TAG	0x03000000L
67#define CONS_TAG	0x04000000L
68
69#define MAX_DEPTH	20
70
71/* define macros */
72
73#define null(x)		!(x)
74#define tag(x)		((x) & TAG_MASK)
75#define atom(x)		(tag(x) < CONS_TAG)
76#define constp(x)	(tag(x) < SYMBOL_TAG)
77#define numberp(x)	(tag(x) == NUMBER_TAG)
78#define stringp(x)	(tag(x) == STRING_TAG)
79#define symbolp(x)	(tag(x) == SYMBOL_TAG)
80#define consp(x)	(tag(x) == CONS_TAG)
81
82#define gcfield(x)	(((struct gccell *)x)->tagfield)
83#define mkcopied(x)	((x) | GC_MASK)
84#define alreadycopied(x) (gcfield(x) & GC_MASK)
85#define newaddr(x)	((x) & ~GC_MASK)
86
87typedef	POINTERINT	list;
88typedef POINTERINT	pointerint;
89
90/* cell area */
91
92#define celloffset(x)	((x) & CELL_MASK)
93
94#define car(x)		((struct cell *)(celltop + celloffset(x)))->head
95#define cdr(x)		((struct cell *)(celltop + celloffset(x)))->tail
96#define caar(x)		car(car(x))
97#define cadr(x)		car(cdr(x))
98#define cdar(x)		cdr(car(x))
99#define cddr(x)		cdr(cdr(x))
100
101#define symbolpointer(x) ((struct atomcell *)(celltop + celloffset(x)))
102
103#define mknum(x)	(NUMBER_TAG | ((x) & CELL_MASK))
104
105#ifdef BIGPOINTER
106#define xnum(x)   ((((x) & 0x00800000)) ? (x | 0xffffffffff000000) : (x & 0x00ffffff))
107#else
108#define xnum(x)   ((((x) & 0x00800000)) ? (x | 0xff000000) : (x & 0x00ffffff))
109#endif
110
111#define xstring(x) (((struct stringcell *)(celltop + celloffset(x)))->str)
112#define xstrlen(x) (((struct stringcell *)(celltop + celloffset(x)))->length)
113
114#define argnchk(fn,x)	if (n != x) argnerr(fn)
115
116/* data type definitions */
117
118struct cell {
119  list tail;
120  list head;
121};
122
123struct atomcell {
124  list	plist;
125  list	value;
126  char	*pname;
127  int	ftype;
128  list 	(*func)(...);
129  list  (*valfunc)(...);
130  int	mid;
131  int	fid;
132  list	hlink;
133};
134
135struct stringcell {
136  int length;
137  char str[4]; /* dummy array */
138};
139
140struct gccell {
141  list	tagfield;
142};
143
144struct atomdefs {
145	char	*symname;
146	int	symtype;
147	list	(*symfunc)(...);
148};
149
150struct cannafndefs {
151  char *fnname;
152  int  fnid;
153};
154
155struct cannamodedefs {
156  char *mdname;
157  int  mdid;
158};
159
160struct cannavardefs {
161  char *varname;
162  list (*varfunc)(...);
163};
164