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

Last change on this file since 489 was 489, checked in by Sam Hocevar, 10 years ago

lisp: no LispSymbol? members are anonymous pointers any longer.

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