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

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

lisp: make all lisp object inherit a common type.

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