source: abuse/tags/pd/abuse/inc/lisp.hpp @ 49

Last change on this file since 49 was 49, checked in by Sam Hocevar, 11 years ago
  • Imported original public domain release, for future reference.
File size: 5.6 KB
Line 
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
12enum { 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
21extern long sin_table[FIXED_TRIG_SIZE];   // this should be filled in by external module
22#define TBS 1662                          // atan table granularity
23extern unsigned short atan_table[TBS];
24#define NILP(x) (x==NULL)
25#define DEFINEDP(x) (x!=l_undefined)
26class bFILE;
27extern int current_space;
28extern bFILE *current_print_file;
29
30
31enum { 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
37typedef long ltype;    // make sure structures aren't packed differently on various compiler
38                       // and sure that word, etc are word alligned
39
40struct lisp_object_var
41
42  ltype type;
43  long number; 
44} ;
45
46struct cons_cell
47{
48  ltype type;
49  void *cdr,*car;
50} ;
51
52struct lisp_number
53{
54  ltype type;
55  long num;
56} ;
57
58struct lisp_collected_object
59{
60  ltype type;
61  void *new_reference;
62} ;
63
64struct 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
74struct lisp_sys_function
75{
76  ltype type;
77  short min_args,max_args,
78        fun_number;
79} ;
80
81struct 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
91struct lisp_1d_array
92{
93  ltype type;
94  unsigned short size;
95  // size * sizeof (void *) follows1
96} ;
97
98struct lisp_string
99{
100  ltype type;
101} ;
102
103struct lisp_character
104{
105  ltype type;
106  short pad;
107  unsigned short ch;
108} ;
109
110struct lisp_pointer
111{
112  ltype type;
113  void *addr;
114} ;
115
116
117struct lisp_fixed_point
118{
119  ltype type;
120  long x;
121} ;
122
123
124void perm_space();
125void tmp_space();
126void use_user_space(void *addr, long size);
127#define item_type(c) ((c) ? *((ltype *)c) : (ltype)L_CONS_CELL)
128void *lget_array_element(void *a, long x);
129void *lpointer_value(void *lpointer);
130long lnumber_value(void *lnumber);
131char *lstring_value(void *lstring);
132unsigned short lcharacter_value(void *c);
133long lfixed_point_value(void *c);
134void *lisp_atom(void *i);
135void *lcdr(void *c);
136void *lcar(void *c);
137void *lisp_eq(void *n1, void *n2);
138void *lisp_equal(void *n1, void *n2);
139lisp_symbol *find_symbol(char *name);
140long list_length(void *i);
141void lprint(void *i);
142void *eval(void *prog);
143void *eval_block(void *list);
144void *eval_function(lisp_symbol *sym, void *arg_list);
145void *eval_user_fun(lisp_symbol *sym, void *arg_list);
146void *compile(char *&s);
147void *symbol_value(void *symbol);
148void *symbol_function(void *symbol);
149void *set_symbol_number(void *symbol, long num);
150void *set_symbol_value(void *symbol, void *value);
151void *symbol_name(void *symbol);
152void *assoc(void *item, void *list);
153void resize_tmp(int new_size);
154void resize_perm(int new_size);
155lisp_symbol *make_find_symbol(char *name);
156
157void push_onto_list(void *object, void *&list);
158lisp_symbol *add_c_object(void *symbol, short number);
159lisp_symbol *add_c_function(char *name, short min_args, short max_args, short number);
160lisp_symbol *add_c_bool_fun(char *name, short min_args, short max_args, short number);
161lisp_symbol *add_lisp_function(char *name, short min_args, short max_args, short number);
162int read_ltoken(char *&s, char *buffer);
163cons_cell *new_cons_cell();
164void print_trace_stack(int max_levels);
165
166
167lisp_number *new_lisp_number(long num);
168lisp_pointer *new_lisp_pointer(void *addr);
169lisp_character *new_lisp_character(unsigned short ch);
170lisp_string *new_lisp_string(char *string);
171lisp_string *new_lisp_string(char *string, int length);
172lisp_string *new_lisp_string(long length);
173lisp_fixed_point *new_lisp_fixed_point(long x);
174lisp_object_var *new_lisp_object_var(short number);
175lisp_1d_array   *new_lisp_1d_array(unsigned short size, void *rest);
176lisp_sys_function *new_lisp_sys_function(int min_args, int max_args, int fun_number);
177lisp_sys_function *new_lisp_c_function(int min_args, int max_args, int fun_number);
178lisp_sys_function *new_lisp_c_bool(int min_args, int max_args, int fun_number);
179
180#ifdef NO_LIBS
181lisp_user_function *new_lisp_user_function(void *arg_list, void *block_list);
182#else
183lisp_user_function *new_lisp_user_function(long arg_list, long block_list);
184#endif
185
186lisp_sys_function *new_user_lisp_function(int min_args, int max_args, int fun_number);
187
188int end_of_program(char *s);
189void clear_tmp();
190void lisp_init(long perm_size, long tmp_size);
191void lisp_uninit();
192extern lisp_symbol *lsym_root;
193
194extern char *space[4],*free_space[4];
195extern int space_size[4];
196void *nth(int num, void *list);
197long lisp_atan2(long dy, long dx);
198long lisp_sin(long x);
199long lisp_cos(long x);
200void restore_heap(void *val, int heap);
201void *mark_heap(int heap);
202
203extern "C" {
204void lbreak(const char *format, ...);
205} ;
206
207extern void clisp_init();                      // external initalizer call by lisp_init()
208extern long c_caller(long number, void *arg);  // exten c function switches on number
209extern void *l_caller(long number, void *arg);  // exten lisp function switches on number
210
211extern void *l_obj_get(long number);  // exten lisp function switches on number
212extern void l_obj_set(long number, void *arg);  // exten lisp function switches on number
213extern void l_obj_print(long number);  // exten lisp function switches on number
214
215
216
217#endif
Note: See TracBrowser for help on using the repository browser.