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

Last change on this file since 488 was 488, checked in by Sam Hocevar, 11 years ago

lisp: implement LispString::Create.

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