source: abuse/trunk/src/lisp/lisp.h @ 481

Last change on this file since 481 was 481, checked in by Sam Hocevar, 7 years ago

Fuck the history, I'm renaming all .hpp files to .h for my own sanity.

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