source: abuse/tags/pd/macabuse/inc/lisp.hpp

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