source: abuse/trunk/src/lisp.hpp @ 57

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