source: abuse/trunk/src/include/lisp.hpp @ 17

Last change on this file since 17 was 16, checked in by Sam Hocevar, 17 years ago
  • shitloads of long -> int32_t changes for 64 bit safety.
File size: 5.6 KB
RevLine 
[2]1#ifndef __LISP_HPP_
2#define __LISP_HPP_
3
[11]4#include <stdint.h>
5
[2]6#include "lisp_opt.hpp"
7
8#ifdef L_PROFILE
9#include "timing.hpp"
10#endif
11
12#define Cell void
13#define MAX_LISP_TOKEN_LEN 200
14enum { PERM_SPACE,
15       TMP_SPACE,
16       USER_SPACE,
17       GC_SPACE };
18#define CAR(x) ((cons_cell *)x)->car
19#define CDR(x) ((cons_cell *)x)->cdr
20
21
22#define FIXED_TRIG_SIZE 360               // 360 degrees stored in table
23extern long sin_table[FIXED_TRIG_SIZE];   // this should be filled in by external module
24#define TBS 1662                          // atan table granularity
25extern unsigned short atan_table[TBS];
26#define NILP(x) (x==NULL)
27#define DEFINEDP(x) (x!=l_undefined)
28class bFILE;
29extern int current_space;
30extern bFILE *current_print_file;
31
32
33enum { L_BAD_CELL,   // error catching type
34       L_CONS_CELL, L_NUMBER, L_SYMBOL,     L_SYS_FUNCTION, L_USER_FUNCTION,
35       L_STRING, L_CHARACTER, L_C_FUNCTION, L_C_BOOL,       L_L_FUNCTION, L_POINTER,
36       L_OBJECT_VAR, L_1D_ARRAY,
37       L_FIXED_POINT, L_COLLECTED_OBJECT };
38
[11]39typedef uint64_t ltype;    // make sure structures aren't packed differently on various compiler
[2]40                       // and sure that word, etc are word alligned
41
42struct lisp_object_var
43
44  ltype type;
45  long number; 
46} ;
47
48struct cons_cell
49{
50  ltype type;
51  void *cdr,*car;
52} ;
53
54struct lisp_number
55{
56  ltype type;
57  long num;
58} ;
59
60struct lisp_collected_object
61{
62  ltype type;
63  void *new_reference;
64} ;
65
66struct lisp_symbol
67{
68  ltype type;
69#ifdef L_PROFILE
70  float time_taken;
71#endif
72  void *value, *function, *name;
73  lisp_symbol *left,*right;       // tree structure
74} ;
75
76struct lisp_sys_function
77{
78  ltype type;
79  short min_args,max_args,
80        fun_number;
81} ;
82
83struct lisp_user_function
84{
85  ltype type;
86#ifndef NO_LIBS
[11]87  intptr_t alist,blist;      // id for cached blocks
[2]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;
[11]108  int16_t pad;
109  uint16_t ch;
[2]110} ;
111
112struct lisp_pointer
113{
114  ltype type;
115  void *addr;
116} ;
117
118
119struct lisp_fixed_point
120{
121  ltype type;
[11]122  int32_t x;
[2]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);
[16]132int32_t lnumber_value(void *lnumber);
[2]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);
[11]160lisp_symbol *add_c_object(void *symbol, int16_t number);
[2]161lisp_symbol *add_c_function(char *name, short min_args, short max_args, short number);
162lisp_symbol *add_c_bool_fun(char *name, short min_args, short max_args, short number);
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);
[11]171lisp_character *new_lisp_character(uint16_t ch);
[2]172lisp_string *new_lisp_string(char *string);
173lisp_string *new_lisp_string(char *string, int length);
[11]174lisp_string *new_lisp_string(int length);
175lisp_fixed_point *new_lisp_fixed_point(int32_t x);
176lisp_object_var *new_lisp_object_var(int16_t number);
177lisp_1d_array   *new_lisp_1d_array(int size, void *rest);
[2]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, int fun_number);
180lisp_sys_function *new_lisp_c_bool(int min_args, int max_args, int fun_number);
181
182#ifdef NO_LIBS
183lisp_user_function *new_lisp_user_function(void *arg_list, void *block_list);
184#else
[11]185lisp_user_function *new_lisp_user_function(intptr_t arg_list, intptr_t block_list);
[2]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 long c_caller(long number, void *arg);  // exten c function switches on number
211extern void *l_caller(long number, void *arg);  // exten lisp function switches on number
212
213extern void *l_obj_get(long number);  // exten lisp function switches on number
214extern void l_obj_set(long number, void *arg);  // exten lisp function switches on number
215extern void l_obj_print(long number);  // exten lisp function switches on number
216
217
218
219#endif
Note: See TracBrowser for help on using the repository browser.