1 | /* |
---|
2 | * Abuse - dark 2D side-scrolling platform game |
---|
3 | * Copyright (c) 1995 Crack dot Com |
---|
4 | * |
---|
5 | * This software was released into the Public Domain. As with most public |
---|
6 | * domain software, no warranty is made or implied by Crack dot Com or |
---|
7 | * Jonathan Clark. |
---|
8 | */ |
---|
9 | |
---|
10 | #ifndef __LISP_HPP_ |
---|
11 | #define __LISP_HPP_ |
---|
12 | |
---|
13 | #include <stdint.h> |
---|
14 | |
---|
15 | #include "lisp_opt.h" |
---|
16 | |
---|
17 | #ifdef L_PROFILE |
---|
18 | #include "timing.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #define Cell void |
---|
22 | #define MAX_LISP_TOKEN_LEN 200 |
---|
23 | enum { PERM_SPACE, |
---|
24 | TMP_SPACE, |
---|
25 | USER_SPACE, |
---|
26 | GC_SPACE }; |
---|
27 | |
---|
28 | #define FIXED_TRIG_SIZE 360 // 360 degrees stored in table |
---|
29 | extern int32_t sin_table[FIXED_TRIG_SIZE]; // this should be filled in by external module |
---|
30 | #define TBS 1662 // atan table granularity |
---|
31 | extern uint16_t atan_table[TBS]; |
---|
32 | #define NILP(x) (x==NULL) |
---|
33 | #define DEFINEDP(x) (x!=l_undefined) |
---|
34 | class bFILE; |
---|
35 | extern int current_space; |
---|
36 | extern bFILE *current_print_file; |
---|
37 | |
---|
38 | |
---|
39 | enum { L_BAD_CELL, // error catching type |
---|
40 | L_CONS_CELL, L_NUMBER, L_SYMBOL, L_SYS_FUNCTION, L_USER_FUNCTION, |
---|
41 | L_STRING, L_CHARACTER, L_C_FUNCTION, L_C_BOOL, L_L_FUNCTION, L_POINTER, |
---|
42 | L_OBJECT_VAR, L_1D_ARRAY, |
---|
43 | L_FIXED_POINT, L_COLLECTED_OBJECT }; |
---|
44 | |
---|
45 | typedef uint32_t ltype; // make sure structures aren't packed differently on various compiler |
---|
46 | // and sure that word, etc are word aligned |
---|
47 | |
---|
48 | struct LispObject |
---|
49 | { |
---|
50 | ltype type; |
---|
51 | }; |
---|
52 | |
---|
53 | struct LispObjectVar : LispObject |
---|
54 | { |
---|
55 | long number; |
---|
56 | }; |
---|
57 | |
---|
58 | struct LispList : LispObject |
---|
59 | { |
---|
60 | void *cdr, *car; |
---|
61 | }; |
---|
62 | |
---|
63 | struct LispNumber : LispObject |
---|
64 | { |
---|
65 | long num; |
---|
66 | }; |
---|
67 | |
---|
68 | struct LispRedirect : LispObject |
---|
69 | { |
---|
70 | void *new_reference; |
---|
71 | }; |
---|
72 | |
---|
73 | struct LispString : LispObject |
---|
74 | { |
---|
75 | }; |
---|
76 | |
---|
77 | struct LispSymbol : LispObject |
---|
78 | { |
---|
79 | static LispSymbol *Find(char const *name); |
---|
80 | static LispSymbol *FindOrCreate(char const *name); |
---|
81 | |
---|
82 | void *GetName(); |
---|
83 | void *GetFunction(); |
---|
84 | void *GetValue(); |
---|
85 | |
---|
86 | void SetFunction(void *fun); |
---|
87 | void SetValue(void *value); |
---|
88 | void SetNumber(long num); |
---|
89 | |
---|
90 | #ifdef L_PROFILE |
---|
91 | float time_taken; |
---|
92 | #endif |
---|
93 | void *value, *function; |
---|
94 | LispString *name; |
---|
95 | LispSymbol *left, *right; // tree structure |
---|
96 | }; |
---|
97 | |
---|
98 | struct LispSysFunction : LispObject |
---|
99 | { |
---|
100 | short min_args, max_args; |
---|
101 | short fun_number; |
---|
102 | }; |
---|
103 | |
---|
104 | struct LispUserFunction : LispObject |
---|
105 | { |
---|
106 | #ifndef NO_LIBS |
---|
107 | intptr_t alist, blist; // id for cached blocks |
---|
108 | #else |
---|
109 | void *arg_list, *block_list; |
---|
110 | #endif |
---|
111 | }; |
---|
112 | |
---|
113 | struct LispArray : LispObject |
---|
114 | { |
---|
115 | static LispArray *Create(int size, void *rest); |
---|
116 | |
---|
117 | inline LispObject **GetData() { return data; } |
---|
118 | LispObject *Get(long x); |
---|
119 | |
---|
120 | unsigned short size; |
---|
121 | // size * sizeof (void *) follows1 |
---|
122 | |
---|
123 | private: |
---|
124 | LispObject *data[1]; |
---|
125 | }; |
---|
126 | |
---|
127 | struct LispChar : LispObject |
---|
128 | { |
---|
129 | int16_t pad; |
---|
130 | uint16_t ch; |
---|
131 | }; |
---|
132 | |
---|
133 | struct LispPointer : LispObject |
---|
134 | { |
---|
135 | void *addr; |
---|
136 | }; |
---|
137 | |
---|
138 | |
---|
139 | struct LispFixedPoint : LispObject |
---|
140 | { |
---|
141 | int32_t x; |
---|
142 | }; |
---|
143 | |
---|
144 | static inline void *&CAR(void *x) { return ((LispList *)x)->car; } |
---|
145 | static inline void *&CDR(void *x) { return ((LispList *)x)->cdr; } |
---|
146 | |
---|
147 | void perm_space(); |
---|
148 | void tmp_space(); |
---|
149 | void use_user_space(void *addr, long size); |
---|
150 | #define item_type(c) ((c) ? *((ltype *)c) : (ltype)L_CONS_CELL) |
---|
151 | void *lpointer_value(void *lpointer); |
---|
152 | int32_t lnumber_value(void *lnumber); |
---|
153 | char *lstring_value(void *lstring); |
---|
154 | unsigned short lcharacter_value(void *c); |
---|
155 | long lfixed_point_value(void *c); |
---|
156 | void *lisp_atom(void *i); |
---|
157 | void *lcdr(void *c); |
---|
158 | void *lcar(void *c); |
---|
159 | void *lisp_eq(void *n1, void *n2); |
---|
160 | void *lisp_equal(void *n1, void *n2); |
---|
161 | long list_length(void *i); |
---|
162 | void lprint(void *i); |
---|
163 | void *eval(void *prog); |
---|
164 | void *eval_block(void *list); |
---|
165 | void *eval_function(LispSymbol *sym, void *arg_list); |
---|
166 | void *eval_user_fun(LispSymbol *sym, void *arg_list); |
---|
167 | void *compile(char const *&s); |
---|
168 | void *assoc(void *item, void *list); |
---|
169 | void resize_tmp(int new_size); |
---|
170 | void resize_perm(int new_size); |
---|
171 | |
---|
172 | void push_onto_list(void *object, void *&list); |
---|
173 | LispSymbol *add_c_object(void *symbol, int16_t number); |
---|
174 | LispSymbol *add_c_function(char const *name, short min_args, short max_args, short number); |
---|
175 | LispSymbol *add_c_bool_fun(char const *name, short min_args, short max_args, short number); |
---|
176 | LispSymbol *add_lisp_function(char const *name, short min_args, short max_args, short number); |
---|
177 | int read_ltoken(char *&s, char *buffer); |
---|
178 | LispList *new_cons_cell(); |
---|
179 | void print_trace_stack(int max_levels); |
---|
180 | |
---|
181 | |
---|
182 | LispNumber *new_lisp_number(long num); |
---|
183 | LispPointer *new_lisp_pointer(void *addr); |
---|
184 | LispChar *new_lisp_character(uint16_t ch); |
---|
185 | LispString *new_lisp_string(char const *string); |
---|
186 | LispString *new_lisp_string(char const *string, int length); |
---|
187 | LispString *new_lisp_string(int length); |
---|
188 | LispFixedPoint *new_lisp_fixed_point(int32_t x); |
---|
189 | LispObjectVar *new_lisp_object_var(int16_t number); |
---|
190 | LispSysFunction *new_lisp_sys_function(int min_args, int max_args, int fun_number); |
---|
191 | LispSysFunction *new_lisp_c_function(int min_args, int max_args, int fun_number); |
---|
192 | LispSysFunction *new_lisp_c_bool(int min_args, int max_args, int fun_number); |
---|
193 | |
---|
194 | #ifdef NO_LIBS |
---|
195 | LispUserFunction *new_lisp_user_function(void *arg_list, void *block_list); |
---|
196 | #else |
---|
197 | LispUserFunction *new_lisp_user_function(intptr_t arg_list, intptr_t block_list); |
---|
198 | #endif |
---|
199 | |
---|
200 | LispSysFunction *new_user_lisp_function(int min_args, int max_args, int fun_number); |
---|
201 | |
---|
202 | int end_of_program(char *s); |
---|
203 | void clear_tmp(); |
---|
204 | void lisp_init(long perm_size, long tmp_size); |
---|
205 | void lisp_uninit(); |
---|
206 | extern LispSymbol *lsym_root; |
---|
207 | |
---|
208 | extern uint8_t *space[4], *free_space[4]; |
---|
209 | extern int space_size[4]; |
---|
210 | void *nth(int num, void *list); |
---|
211 | int32_t lisp_atan2(int32_t dy, int32_t dx); |
---|
212 | int32_t lisp_sin(int32_t x); |
---|
213 | int32_t lisp_cos(int32_t x); |
---|
214 | void restore_heap(void *val, int heap); |
---|
215 | void *mark_heap(int heap); |
---|
216 | |
---|
217 | extern "C" { |
---|
218 | void lbreak(const char *format, ...); |
---|
219 | } ; |
---|
220 | |
---|
221 | extern void clisp_init(); // external initalizer call by lisp_init() |
---|
222 | extern long c_caller(long number, void *arg); // exten c function switches on number |
---|
223 | extern void *l_caller(long number, void *arg); // exten lisp function switches on number |
---|
224 | |
---|
225 | extern void *l_obj_get(long number); // exten lisp function switches on number |
---|
226 | extern void l_obj_set(long number, void *arg); // exten lisp function switches on number |
---|
227 | extern void l_obj_print(long number); // exten lisp function switches on number |
---|
228 | |
---|
229 | // FIXME: get rid of this later |
---|
230 | static inline void *symbol_value(void *sym) { return ((LispSymbol *)sym)->GetValue(); } |
---|
231 | |
---|
232 | |
---|
233 | |
---|
234 | #endif |
---|