00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef LISP_H
00011 #define LISP_H
00012
00019 #include "parambox.h"
00020
00024 enum lisptype {
00025 NIL,
00026 CONS,
00027 NUMBER,
00028 STRING,
00029 SYMBOL,
00030 UTYPE,
00031 MTYPE,
00032 TTYPE,
00033 ATYPE,
00034 POINTER,
00035 EOFOBJ
00036 };
00037
00041 struct a_cons {
00042 struct a_obj *car;
00043 struct a_obj *cdr;
00044 };
00045
00049 struct a_symbol {
00050 struct a_symentry *symentry;
00051 struct a_obj *value;
00052 };
00053
00058 struct a_pointer {
00059 struct a_obj *sym;
00060 char *data;
00061 };
00062
00066 typedef struct a_obj {
00067 enum lisptype type;
00068 union {
00069 int num;
00070 char *str;
00071 struct a_symbol sym;
00072 struct a_cons cons;
00073 struct a_pointer ptr;
00074 } v;
00075 } Obj;
00076
00080 typedef struct a_symentry {
00081 char *name;
00082 struct a_obj *symbol;
00083 char constantp;
00084 struct a_symentry *next;
00085 } Symentry;
00086
00087
00089 #define CONTEXTSIZE 129
00090
00095 enum strmtype {
00096 stringstrm,
00097 filestrm
00098 };
00099
00103 typedef struct a_strm {
00104 enum strmtype type;
00105 union {
00106 char *sp;
00107 FILE *fp;
00108 } ptr;
00109 char lastread[CONTEXTSIZE];
00110 int numread;
00111 } Strm;
00112
00113 #undef DEF_KWD
00114 #define DEF_KWD(name,CODE) CODE,
00115
00118 enum keywords {
00119
00120 #include "keyword.def"
00121
00122 LAST_KEYWORD
00123 };
00124
00134 #define match_keyword(ob,key) \
00135 (symbolp(ob) && strcmp(c_string(ob), keyword_name(key)) == 0)
00136
00143 #define for_all_list(lis,rest) \
00144 for (rest = (lis); rest != lispnil; rest = cdr(rest))
00145
00154 #define for_both_lists(lis1,lis2,rest1,rest2) \
00155 for (rest1 = (lis1), rest2 = (lis2); \
00156 rest1 != lispnil && rest2 != lispnil; \
00157 rest1 = cdr(rest1), rest2 = cdr(rest2))
00158
00159
00160
00162 extern Obj *lispnil;
00164 extern Obj *lispeof;
00165
00166 extern void init_lisp(void);
00167 extern Obj *read_form(FILE *fp, int *p1, int *p2);
00168 extern Obj *read_form_from_string(char *str, int *p1, int *p2, char **endstr);
00169 extern int length(Obj *list);
00170 extern Obj *new_string(char *str);
00171 extern Obj *new_number(int num);
00172 extern Obj *new_utype(int u);
00173 extern Obj *new_mtype(int r);
00174 extern Obj *new_ttype(int t);
00175 extern Obj *new_atype(int s);
00176
00177 extern Obj *new_pointer(Obj *sym, char *ptr);
00178 extern Obj *cons(Obj *x, Obj *y);
00179 extern void type_warning(char *funname, Obj *x, char *errtype, Obj *subst);
00180 extern Obj *car(Obj *x);
00181 extern Obj *cdr(Obj *x);
00182 extern Obj *cadr(Obj *x);
00183 extern Obj *cddr(Obj *x);
00184 extern Obj *caddr(Obj *x);
00185 extern Obj *cdddr(Obj *x);
00186 extern void set_cdr(Obj *x, Obj *v);
00187 extern char *c_string(Obj *x);
00188 extern int c_number(Obj *x);
00189 extern Obj *intern_symbol(char *str);
00190 extern Obj *symbol_value(Obj *sym);
00191 extern Obj *setq(Obj *sym, Obj *x);
00192 extern void makunbound(Obj *sym);
00193 extern void flag_as_constant(Obj *sym);
00194 extern int constantp(Obj *sym);
00195 extern int numberp(Obj *x);
00196 extern int stringp(Obj *x);
00197 extern int symbolp(Obj *x);
00198 extern int consp(Obj *x);
00199 extern int utypep(Obj *x);
00200 extern int mtypep(Obj *x);
00201 extern int ttypep(Obj *x);
00202 extern int atypep(Obj *x);
00203 extern int pointerp(Obj *x);
00204 extern int boundp(Obj *sym);
00205 extern int numberishp(Obj *x);
00206 extern int listp(Obj *x);
00207 extern int equal(Obj *x, Obj *y);
00208 extern int member(Obj *x, Obj *lis);
00209 extern Obj *elt(Obj *lis, int n);
00210 extern Obj *reverse(Obj *lis);
00211 extern Obj *find_at_key(Obj *lis, char *key);
00212 extern Obj *replace_at_key(Obj *lis, char *key, Obj *newval);
00213 extern int is_quoted_lisp(Obj *x);
00214
00215 namespace Xconq {
00216
00218 extern void dice1_desc(char *buf, DiceRep dice);
00220 extern void dice2_desc(char *buf, DiceRep dice);
00221
00222 }
00223
00225 extern void fprint_num_or_dice(FILE *fp, int x, int valtype);
00226 extern void fprinttable(FILE *fp, int n);
00227 extern void fprintlisp(FILE *fp, Obj *oobj);
00228 extern void fprint_list(FILE *fp, Obj *obj);
00229 extern void sprintlisp(char *buf, Obj *obj, int maxlen);
00230 extern void sprint_list(char *buf, Obj *obj, int maxlen);
00231 extern void dlisp(Obj *x);
00232 extern void print_form_and_value(FILE *fp, Obj *form);
00233 extern Obj *append_two_lists(Obj *x1, Obj *x2);
00234 extern Obj *append_lists(Obj *lis);
00235 extern Obj *remove_from_list(Obj *element, Obj *lis);
00236 extern Obj *remove_list_from_list(Obj *rlist, Obj *slist);
00237 extern void push_binding(Obj **lis, Obj *key, Obj *val);
00238 extern void push_cdr_binding(Obj **lis, Obj *key, Obj *val);
00239 extern void push_int_binding(Obj **lis, Obj *key, int val);
00240 extern void push_key_binding(Obj **lis, int key, Obj *val);
00241 extern void push_key_cdr_binding(Obj **lis, int key, Obj *val);
00242 extern void push_key_int_binding(Obj **lis, int key, int val);
00243 extern Obj *eval(Obj *x);
00244 extern Obj *eval_symbol(Obj *x);
00245 extern Obj *eval_list(Obj *x);
00246 extern Obj* eval_boolean_expression(Obj *expr);
00247 extern int eval_boolean_expression(Obj *expr, int (*fn)(Obj *), int dflt);
00248 extern int eval_boolean_expression(Obj *expr, int (*fn)(Obj *, ParamBox *),
00249 int dflt, ParamBox *pbox);
00250 extern Obj* eval_arithmetic_expression(Obj *expr);
00251 extern Obj* eval_arithmetic_comparison_expression(Obj *expr);
00252 extern Obj *choose_from_weighted_list(Obj *lis, int *totalweightp, int flat);
00253 extern int interpolate_in_list(int val, Obj *lis, int *rslt);
00254 extern int interpolate_in_list_ext(int val, Obj *lis,
00255 int mindo, int minval, int minrslt,
00256 int maxdo, int maxval, int maxrslt,
00257 int *rslt);
00258
00259 extern char *escaped_symbol(char *str);
00260 extern char *escaped_string(char *str);
00261 extern char *safe_escaped_string(char *str, int len);
00262 extern void interp_short_array(short *arr, Obj *lis, int n);
00263 extern void interp_long_array(long *arr, Obj *lis, int n);
00264 extern int eval_number(Obj *val, int *isnumber);
00265 extern char *get_string(Obj *lis);
00266
00267
00268
00269 extern void init_warning(char *str, ...);
00270 extern void low_init_warning(char *str);
00271 extern void init_error(char *str, ...);
00272 extern void low_init_error(char *str);
00273 extern void run_warning(char *str, ...);
00274 extern void low_run_warning(char *str);
00275 extern void run_error(char *str, ...);
00276 extern void low_run_error(char *str);
00277 extern void announce_read_progress(void);
00278 extern int keyword_code(char *str);
00279 extern char *keyword_name(enum keywords k);
00280 extern int lazy_bind(Obj *sym);
00281 extern void init_predefined_symbols(void);
00282 extern void syntax_error(Obj *x, char *msg);
00283
00284 #endif