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

Last change on this file since 492 was 492, checked in by Sam Hocevar, 12 years ago

lisp: rename core classes to slightly shorter names (LispObject? -> LObject).

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