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,v 1.3 2003/09/17 10:15:09 aida_s Exp $ */
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 #define CELLSIZE	10240	/* size of cell area (byte)		*/
37 
38 #define STKSIZE		1024	/* the depth of value & parameter stack	*/
39 #define BUFSIZE	 	256	/* universal buffer size (byte)		*/
40 
41 #define NIL	   0L		/* internal expression of NIL		*/
42 #define UNBOUND	  -2L		/* unbound mark of variable		*/
43 #define NON	  -1L		/* the mark of No. (unable to use NO)	*/
44 
45 #define UNDEF		0
46 #define	SPECIAL		1
47 #define	SUBR		2
48 #define	EXPR		3
49 #define	CMACRO		4
50 #define	MACRO		5
51 
52 #define TAG_MASK	0x07000000L
53 #define CELL_MASK	0x00ffffffL
54 #define GC_MASK		0x08000000L
55 
56 #define NIL_TAG		0L
57 #define NUMBER_TAG	0x01000000L
58 #define STRING_TAG	0x02000000L
59 #define SYMBOL_TAG	0x03000000L
60 #define CONS_TAG	0x04000000L
61 
62 #define MAX_DEPTH	20
63 
64 /* define macros */
65 
66 #define null(x)		!(x)
67 #define tag(x)		((x) & TAG_MASK)
68 #define atom(x)		(tag(x) < CONS_TAG)
69 #define constp(x)	(tag(x) < SYMBOL_TAG)
70 #define numberp(x)	(tag(x) == NUMBER_TAG)
71 #define stringp(x)	(tag(x) == STRING_TAG)
72 #define symbolp(x)	(tag(x) == SYMBOL_TAG)
73 #define consp(x)	(tag(x) == CONS_TAG)
74 
75 #define gcfield(x)	(((struct gccell *)x)->tagfield)
76 #define mkcopied(x)	((x) | GC_MASK)
77 #define alreadycopied(x) (gcfield(x) & GC_MASK)
78 #define newaddr(x)	((x) & ~GC_MASK)
79 
80 typedef	POINTERINT	list;
81 typedef POINTERINT	pointerint;
82 
83 /* cell area */
84 
85 #define celloffset(x)	((x) & CELL_MASK)
86 
87 #define car(x)		((struct cell *)(celltop + celloffset(x)))->head
88 #define cdr(x)		((struct cell *)(celltop + celloffset(x)))->tail
89 #define caar(x)		car(car(x))
90 #define cadr(x)		car(cdr(x))
91 #define cdar(x)		cdr(car(x))
92 #define cddr(x)		cdr(cdr(x))
93 
94 #define symbolpointer(x) ((struct atomcell *)(celltop + celloffset(x)))
95 
96 #define mknum(x)	(NUMBER_TAG | ((x) & CELL_MASK))
97 
98 #if SIZEOF_VOID_P == 8
99 #define xnum(x)   ((((x) & 0x00800000)) ? (x | 0xffffffffff000000) : (x & 0x00ffffff))
100 #elif SIZEOF_VOID_P == 4
101 #define xnum(x)   ((((x) & 0x00800000)) ? (x | 0xff000000) : (x & 0x00ffffff))
102 #else
103 #error unsupported memory model
104 #endif
105 
106 #define xstring(x) (((struct stringcell *)(celltop + celloffset(x)))->str)
107 #define xstrlen(x) (((struct stringcell *)(celltop + celloffset(x)))->length)
108 
109 #define argnchk(fn,x)	if (n != x) argnerr(fn)
110 
111 /* data type definitions */
112 
113 struct cell {
114   list tail;
115   list head;
116 };
117 
118 struct atomcell {
119   list	plist;
120   list	value;
121   char	*pname;
122   int	ftype;
123   list 	(*func)();
124   list  (*valfunc)();
125   int	mid;
126   int	fid;
127   list	hlink;
128 };
129 
130 struct stringcell {
131   int length;
132   char str[4]; /* dummy array */
133 };
134 
135 struct gccell {
136   list	tagfield;
137 };
138 
139 struct atomdefs {
140 	char	*symname;
141 	int	symtype;
142 	list	(*symfunc)();
143 };
144 
145 struct cannafndefs {
146   char *fnname;
147   int  fnid;
148 };
149 
150 struct cannamodedefs {
151   char *mdname;
152   int  mdid;
153 };
154 
155 struct cannavardefs {
156   char *varname;
157   list (*varfunc)();
158 };
159