1 | #ifndef __LISP_HPP_ |
---|
2 | #define __LISP_HPP_ |
---|
3 | |
---|
4 | #include "lisp_opt.hpp" |
---|
5 | |
---|
6 | #ifdef L_PROFILE |
---|
7 | #include "timing.hpp" |
---|
8 | #endif |
---|
9 | |
---|
10 | #define Cell void |
---|
11 | #define MAX_LISP_TOKEN_LEN 200 |
---|
12 | enum { PERM_SPACE, |
---|
13 | TMP_SPACE, |
---|
14 | USER_SPACE, |
---|
15 | GC_SPACE }; |
---|
16 | #define CAR(x) ((cons_cell *)x)->car |
---|
17 | #define CDR(x) ((cons_cell *)x)->cdr |
---|
18 | |
---|
19 | |
---|
20 | #define FIXED_TRIG_SIZE 360 // 360 degrees stored in table |
---|
21 | extern long sin_table[FIXED_TRIG_SIZE]; // this should be filled in by external module |
---|
22 | #define TBS 1662 // atan table granularity |
---|
23 | extern unsigned short atan_table[TBS]; |
---|
24 | #define NILP(x) (x==NULL) |
---|
25 | #define DEFINEDP(x) (x!=l_undefined) |
---|
26 | class bFILE; |
---|
27 | extern int current_space; |
---|
28 | extern bFILE *current_print_file; |
---|
29 | |
---|
30 | |
---|
31 | enum { L_BAD_CELL, // error catching type |
---|
32 | L_CONS_CELL, L_NUMBER, L_SYMBOL, L_SYS_FUNCTION, L_USER_FUNCTION, |
---|
33 | L_STRING, L_CHARACTER, L_C_FUNCTION, L_C_BOOL, L_L_FUNCTION, L_POINTER, |
---|
34 | L_OBJECT_VAR, L_1D_ARRAY, |
---|
35 | L_FIXED_POINT, L_COLLECTED_OBJECT }; |
---|
36 | |
---|
37 | typedef long ltype; // make sure structures aren't packed differently on various compiler |
---|
38 | // and sure that word, etc are word alligned |
---|
39 | |
---|
40 | struct lisp_object_var |
---|
41 | { |
---|
42 | ltype type; |
---|
43 | long number; |
---|
44 | } ; |
---|
45 | |
---|
46 | struct cons_cell |
---|
47 | { |
---|
48 | ltype type; |
---|
49 | void *cdr,*car; |
---|
50 | } ; |
---|
51 | |
---|
52 | struct lisp_number |
---|
53 | { |
---|
54 | ltype type; |
---|
55 | long num; |
---|
56 | } ; |
---|
57 | |
---|
58 | struct lisp_collected_object |
---|
59 | { |
---|
60 | ltype type; |
---|
61 | void *new_reference; |
---|
62 | } ; |
---|
63 | |
---|
64 | struct lisp_symbol |
---|
65 | { |
---|
66 | ltype type; |
---|
67 | #ifdef L_PROFILE |
---|
68 | float time_taken; |
---|
69 | #endif |
---|
70 | void *value, *function, *name; |
---|
71 | lisp_symbol *left,*right; // tree structure |
---|
72 | } ; |
---|
73 | |
---|
74 | struct lisp_sys_function |
---|
75 | { |
---|
76 | ltype type; |
---|
77 | short min_args,max_args, |
---|
78 | fun_number; |
---|
79 | } ; |
---|
80 | |
---|
81 | struct lisp_user_function |
---|
82 | { |
---|
83 | ltype type; |
---|
84 | #ifndef NO_LIBS |
---|
85 | long alist,blist; // id for cached blocks |
---|
86 | #else |
---|
87 | void *arg_list,*block_list; |
---|
88 | #endif |
---|
89 | } ; |
---|
90 | |
---|
91 | struct lisp_1d_array |
---|
92 | { |
---|
93 | ltype type; |
---|
94 | unsigned short size; |
---|
95 | // size * sizeof (void *) follows1 |
---|
96 | } ; |
---|
97 | |
---|
98 | struct lisp_string |
---|
99 | { |
---|
100 | ltype type; |
---|
101 | } ; |
---|
102 | |
---|
103 | struct lisp_character |
---|
104 | { |
---|
105 | ltype type; |
---|
106 | short pad; |
---|
107 | unsigned short ch; |
---|
108 | } ; |
---|
109 | |
---|
110 | struct lisp_pointer |
---|
111 | { |
---|
112 | ltype type; |
---|
113 | void *addr; |
---|
114 | } ; |
---|
115 | |
---|
116 | |
---|
117 | struct lisp_fixed_point |
---|
118 | { |
---|
119 | ltype type; |
---|
120 | long x; |
---|
121 | } ; |
---|
122 | |
---|
123 | |
---|
124 | void perm_space(); |
---|
125 | void tmp_space(); |
---|
126 | void use_user_space(void *addr, long size); |
---|
127 | #define item_type(c) ((c) ? *((ltype *)c) : (ltype)L_CONS_CELL) |
---|
128 | void *lget_array_element(void *a, long x); |
---|
129 | void *lpointer_value(void *lpointer); |
---|
130 | long lnumber_value(void *lnumber); |
---|
131 | char *lstring_value(void *lstring); |
---|
132 | unsigned short lcharacter_value(void *c); |
---|
133 | long lfixed_point_value(void *c); |
---|
134 | void *lisp_atom(void *i); |
---|
135 | void *lcdr(void *c); |
---|
136 | void *lcar(void *c); |
---|
137 | void *lisp_eq(void *n1, void *n2); |
---|
138 | void *lisp_equal(void *n1, void *n2); |
---|
139 | lisp_symbol *find_symbol(char *name); |
---|
140 | long list_length(void *i); |
---|
141 | void lprint(void *i); |
---|
142 | void *eval(void *prog); |
---|
143 | void *eval_block(void *list); |
---|
144 | void *eval_function(lisp_symbol *sym, void *arg_list); |
---|
145 | void *eval_user_fun(lisp_symbol *sym, void *arg_list); |
---|
146 | void *compile(char *&s); |
---|
147 | void *symbol_value(void *symbol); |
---|
148 | void *symbol_function(void *symbol); |
---|
149 | void *set_symbol_number(void *symbol, long num); |
---|
150 | void *set_symbol_value(void *symbol, void *value); |
---|
151 | void *symbol_name(void *symbol); |
---|
152 | void *assoc(void *item, void *list); |
---|
153 | void resize_tmp(int new_size); |
---|
154 | void resize_perm(int new_size); |
---|
155 | lisp_symbol *make_find_symbol(char *name); |
---|
156 | |
---|
157 | void push_onto_list(void *object, void *&list); |
---|
158 | lisp_symbol *add_c_object(void *symbol, short number); |
---|
159 | lisp_symbol *add_c_function(char *name, short min_args, short max_args, short number); |
---|
160 | lisp_symbol *add_c_bool_fun(char *name, short min_args, short max_args, short number); |
---|
161 | lisp_symbol *add_lisp_function(char *name, short min_args, short max_args, short number); |
---|
162 | int read_ltoken(char *&s, char *buffer); |
---|
163 | cons_cell *new_cons_cell(); |
---|
164 | void print_trace_stack(int max_levels); |
---|
165 | |
---|
166 | |
---|
167 | lisp_number *new_lisp_number(long num); |
---|
168 | lisp_pointer *new_lisp_pointer(void *addr); |
---|
169 | lisp_character *new_lisp_character(unsigned short ch); |
---|
170 | lisp_string *new_lisp_string(char *string); |
---|
171 | lisp_string *new_lisp_string(char *string, int length); |
---|
172 | lisp_string *new_lisp_string(long length); |
---|
173 | lisp_fixed_point *new_lisp_fixed_point(long x); |
---|
174 | lisp_object_var *new_lisp_object_var(short number); |
---|
175 | lisp_1d_array *new_lisp_1d_array(unsigned short size, void *rest); |
---|
176 | lisp_sys_function *new_lisp_sys_function(int min_args, int max_args, int fun_number); |
---|
177 | lisp_sys_function *new_lisp_c_function(int min_args, int max_args, int fun_number); |
---|
178 | lisp_sys_function *new_lisp_c_bool(int min_args, int max_args, int fun_number); |
---|
179 | |
---|
180 | #ifdef NO_LIBS |
---|
181 | lisp_user_function *new_lisp_user_function(void *arg_list, void *block_list); |
---|
182 | #else |
---|
183 | lisp_user_function *new_lisp_user_function(long arg_list, long block_list); |
---|
184 | #endif |
---|
185 | |
---|
186 | lisp_sys_function *new_user_lisp_function(int min_args, int max_args, int fun_number); |
---|
187 | |
---|
188 | int end_of_program(char *s); |
---|
189 | void clear_tmp(); |
---|
190 | void lisp_init(long perm_size, long tmp_size); |
---|
191 | void lisp_uninit(); |
---|
192 | extern lisp_symbol *lsym_root; |
---|
193 | |
---|
194 | extern char *space[4],*free_space[4]; |
---|
195 | extern int space_size[4]; |
---|
196 | void *nth(int num, void *list); |
---|
197 | long lisp_atan2(long dy, long dx); |
---|
198 | long lisp_sin(long x); |
---|
199 | long lisp_cos(long x); |
---|
200 | void restore_heap(void *val, int heap); |
---|
201 | void *mark_heap(int heap); |
---|
202 | |
---|
203 | extern "C" { |
---|
204 | void lbreak(const char *format, ...); |
---|
205 | } ; |
---|
206 | |
---|
207 | extern void clisp_init(); // external initalizer call by lisp_init() |
---|
208 | extern long c_caller(long number, void *arg); // exten c function switches on number |
---|
209 | extern void *l_caller(long number, void *arg); // exten lisp function switches on number |
---|
210 | |
---|
211 | extern void *l_obj_get(long number); // exten lisp function switches on number |
---|
212 | extern void l_obj_set(long number, void *arg); // exten lisp function switches on number |
---|
213 | extern void l_obj_print(long number); // exten lisp function switches on number |
---|
214 | |
---|
215 | |
---|
216 | |
---|
217 | #endif |
---|