merged from ansiClib
[CommonLispStat.git] / cmpinclude.h
blobf7945de5150c1f443f9938a337b64602f7df928a
3 /* Begin for cmpinclude */
6 /* #define SGC */
9 /* End for cmpinclude */
11 (c) Copyright Taiichi Yuasa and Masami Hagiya, 1984. All rights reserved.
12 Copying of this file is authorized to users who have executed the true and
13 proper "License Agreement for Kyoto Common LISP" with SIGLISP.
15 #include <stdio.h>
16 #include <setjmp.h>
17 #include <varargs.h>
18 #define TRUE 1
19 #define FALSE 0
20 #ifdef SGC
21 #define FIRSTWORD short t; char s,m
22 #define SGC_TOUCH(x) x->d.m=0
23 #else
24 #define FIRSTWORD short t; short m
25 #define SGC_TOUCH(x)
26 #endif
27 #define STSET(type,x,i,val) do{SGC_TOUCH(x);STREF(type,x,i) = (val);} while(0)
28 #ifndef VOL
29 #define VOL
30 #endif
31 #ifndef COM_LENG
32 #define COM_LENG
33 #endif
34 #ifndef CHAR_SIZE
35 #define CHAR_SIZE 8
36 #endif
37 typedef int bool;
38 typedef int fixnum;
39 typedef float shortfloat;
40 typedef double longfloat;
41 typedef unsigned short fatchar;
42 #define SIGNED_CHAR(x) (((char ) -1) < (char )0 ? (char) x \
43 : (x >= (1<<(CHAR_SIZE-1)) ? \
44 x - (((int)(1<<(CHAR_SIZE-1))) << 1) \
45 : (char ) x))
46 typedef union lispunion *object;
47 typedef union int_object iobject;
48 union int_object {int i; object o;};
50 #define OBJNULL ((object)NULL)
51 struct fixnum_struct {
52 FIRSTWORD;
53 fixnum FIXVAL;
55 #define fix(x) (x)->FIX.FIXVAL
56 #define SMALL_FIXNUM_LIMIT 1024
57 extern struct fixnum_struct small_fixnum_table[COM_LENG];
58 #define small_fixnum(i) (object)(small_fixnum_table+SMALL_FIXNUM_LIMIT+(i))
60 struct bignum {
61 FIRSTWORD;
62 long *big_self; /* bignum body */
63 int big_length; /* bignum length */
65 #define MP(x) ((GEN)(x)->big.big_self)
66 struct shortfloat_struct {
67 FIRSTWORD;
68 shortfloat SFVAL;
70 #define sf(x) (x)->SF.SFVAL
71 struct longfloat_struct {
72 FIRSTWORD;
73 longfloat LFVAL;
75 #define lf(x) (x)->LF.LFVAL
76 struct character {
77 FIRSTWORD;
78 unsigned short ch_code;
79 unsigned char ch_font;
80 unsigned char ch_bits;
82 struct character character_table1[256+128];
83 #define character_table (character_table1+128)
84 #define code_char(c) (object)(character_table+(c))
85 #define char_code(x) (x)->ch.ch_code
86 #define char_font(x) (x)->ch.ch_font
87 #define char_bits(x) (x)->ch.ch_bits
88 enum stype {
89 stp_ordinary,
90 stp_constant,
91 stp_special
93 struct symbol {
94 FIRSTWORD;
95 object s_dbind;
96 int (*s_sfdef)();
97 #define s_fillp st_fillp
98 #define s_self st_self
99 int s_fillp;
100 char *s_self;
101 object s_gfdef;
102 object s_plist;
103 object s_hpack;
104 short s_stype;
105 short s_mflag;
107 struct cons {
108 FIRSTWORD;
109 object c_cdr;
110 object c_car;
112 struct array {
113 FIRSTWORD;
114 short a_rank;
115 short a_adjustable;
116 int a_dim;
117 int *a_dims;
118 object *a_self;
119 object a_displaced;
120 short a_elttype;
121 short a_offset;
126 struct fat_string { /* vector header */
127 FIRSTWORD;
128 unsigned fs_raw : 24; /* tells if the things in leader are raw */
129 unsigned char fs_leader_length; /* leader_Length */
130 int fs_dim; /* dimension */
131 int fs_fillp; /* fill pointer */
132 /* For simple vectors, */
133 /* fs_fillp is equal to fs_dim. */
134 fatchar *fs_self; /* pointer to the vector Note the leader starts at (int *) *fs_self - fs_leader_length */
138 struct vector {
139 FIRSTWORD;
140 short v_hasfillp;
141 short v_adjustable;
142 int v_dim;
143 int v_fillp;
144 object *v_self;
145 object v_displaced;
146 short v_elttype;
147 short v_offset;
149 struct string {
150 FIRSTWORD;
151 short st_hasfillp;
152 short st_adjustable;
153 int st_dim;
154 int st_fillp;
155 char *st_self;
156 object st_displaced;
158 struct ustring {
159 FIRSTWORD;
160 short ust_hasfillp;
161 short ust_adjustable;
162 int ust_dim;
163 int ust_fillp;
164 unsigned char
165 *ust_self;
166 object ust_displaced;
168 #define USHORT(x,i) (((unsigned short *)(x)->ust.ust_self)[i])
170 struct bitvector {
171 FIRSTWORD;
172 short bv_hasfillp;
173 short bv_adjustable;
174 int bv_dim;
175 int bv_fillp;
176 char *bv_self;
177 object bv_displaced;
178 short bv_elttype;
179 short bv_offset;
181 struct fixarray {
182 FIRSTWORD;
183 short fixa_rank;
184 short fixa_adjustable;
185 int fixa_dim;
186 int *fixa_dims;
187 fixnum *fixa_self;
188 object fixa_displaced;
189 short fixa_elttype;
190 short fixa_offset;
192 struct sfarray {
193 FIRSTWORD;
194 short sfa_rank;
195 short sfa_adjustable;
196 int sfa_dim;
197 int *sfa_dims;
198 shortfloat
199 *sfa_self;
200 object sfa_displaced;
201 short sfa_elttype;
202 short sfa_offset;
204 struct lfarray {
205 FIRSTWORD;
206 short lfa_rank;
207 short lfa_adjustable;
208 int lfa_dim;
209 int *lfa_dims;
210 longfloat
211 *lfa_self;
212 object lfa_displaced;
213 short lfa_elttype;
214 short lfa_offset;
217 struct structure { /* structure header */
218 FIRSTWORD;
219 object str_def; /* structure definition (a structure) */
220 object *str_self; /* structure self */
223 #define STREF(type,x,i) (*((type *)(((char *)((x)->str.str_self))+(i))))
225 struct cfun {
226 FIRSTWORD;
227 object cf_name;
228 int (*cf_self)();
229 object cf_data;
232 struct dclosure { /* compiled closure header */
233 FIRSTWORD;
234 int (*dc_self)(); /* entry address */
235 object *dc_env; /* environment */
238 struct cclosure {
239 FIRSTWORD;
241 object cc_name;
242 int (*cc_self)();
243 object cc_env;
244 object cc_data;
245 object *cc_turbo;
248 struct sfun {
249 FIRSTWORD;
250 object sfn_name;
251 int (*sfn_self)();
252 object sfn_data;
253 int sfn_argd;
256 struct vfun {
257 FIRSTWORD;
258 object vfn_name;
259 int (*vfn_self)();
260 object vfn_data;
261 unsigned short vfn_minargs;
262 unsigned short vfn_maxargs;
265 struct dummy {
266 FIRSTWORD;
268 struct stream {
269 FIRSTWORD;
270 FILE *sm_fp; /* file pointer */
271 object sm_object0; /* some object */
272 object sm_object1; /* some object */
273 int sm_int0; /* some int */
274 int sm_int1; /* some int */
275 char *sm_buffer; /* ptr to BUFSIZE block of storage */
276 short sm_mode; /* stream mode */
277 /* of enum smmode */
279 union lispunion {
280 struct fixnum_struct
281 FIX;
282 struct shortfloat_struct
284 struct stream sm;
285 struct longfloat_struct
287 struct character
289 struct symbol s;
290 struct cons c;
291 struct array a;
292 struct vector v;
293 struct string st;
294 struct ustring ust;
295 struct bignum big;
296 struct bitvector
298 struct structure
299 str;
300 struct cfun cf;
301 struct cclosure cc;
302 struct sfun sfn;
303 struct vfun vfn;
304 struct dummy d;
305 struct fat_string fs;
306 struct dclosure dc;
307 struct fixarray fixa;
308 struct sfarray sfa;
309 struct lfarray lfa;
311 enum type {
312 t_cons,
313 t_start = 0 , /* t_cons, */
314 t_fixnum,
315 t_bignum,
316 t_ratio,
317 t_shortfloat,
318 t_longfloat,
319 t_complex,
320 t_character,
321 t_symbol,
322 t_package,
323 t_hashtable,
324 t_array,
325 t_vector,
326 t_string,
327 t_bitvector,
328 t_structure,
329 t_stream,
330 t_random,
331 t_readtable,
332 t_pathname,
333 t_cfun,
334 t_cclosure,
335 t_sfun,
336 t_gfun,
337 t_vfun,
338 t_cfdata,
339 t_spice,
340 t_fat_string,
341 t_dclosure,
342 t_end,
343 t_contiguous,
344 t_relocatable,
345 t_other
347 #define type_of(obje) ((enum type)(((object)(obje))->d.t))
348 #define endp(obje) endp1(obje)
349 extern object value_stack[COM_LENG];
350 #define vs_org value_stack
351 object *vs_limit;
352 object *vs_base;
353 object *vs_top;
354 #define vs_push(obje) (*vs_top++ = (obje))
355 #define vs_pop (*--vs_top)
356 #define vs_head vs_top[-1]
357 #define vs_mark object *old_vs_top = vs_top
358 #define vs_reset vs_top = old_vs_top
359 #define vs_check if (vs_top >= vs_limit) \
360 vs_overflow();
361 #define vs_check_push(obje) \
362 (vs_top >= vs_limit ? \
363 (object)vs_overflow() : (*vs_top++ = (obje)))
364 #define check_arg(n) \
365 if (vs_top - vs_base != (n)) \
366 check_arg_failed(n)
367 #define MMcheck_arg(n) \
368 if (vs_top - vs_base < (n)) \
369 too_few_arguments(); \
370 else if (vs_top - vs_base > (n)) \
371 too_many_arguments()
372 #define vs_reserve(x) if(vs_base+(x) >= vs_limit) \
373 vs_overflow();
374 struct bds_bd {
375 object bds_sym;
376 object bds_val;
378 extern struct bds_bd bind_stack[COM_LENG];
379 typedef struct bds_bd *bds_ptr;
380 bds_ptr bds_org;
381 bds_ptr bds_limit;
382 bds_ptr bds_top;
383 #define bds_check \
384 if (bds_top >= bds_limit) \
385 bds_overflow()
386 #define bds_bind(sym, val) \
387 ((++bds_top)->bds_sym = (sym), \
388 bds_top->bds_val = (sym)->s.s_dbind, \
389 (sym)->s.s_dbind = (val))
390 #define bds_unwind1 \
391 ((bds_top->bds_sym)->s.s_dbind = bds_top->bds_val, --bds_top)
392 typedef struct invocation_history {
393 object ihs_function;
394 object *ihs_base;
395 } *ihs_ptr;
396 extern struct invocation_history ihs_stack[COM_LENG];
397 ihs_ptr ihs_org;
398 ihs_ptr ihs_limit;
399 ihs_ptr ihs_top;
400 #define ihs_check \
401 if (ihs_top >= ihs_limit) \
402 ihs_overflow()
403 #define ihs_push(function) \
404 (++ihs_top)->ihs_function = (function); \
405 ihs_top->ihs_base = vs_base
406 #define ihs_pop() (ihs_top--)
407 enum fr_class {
408 FRS_CATCH,
409 FRS_CATCHALL,
410 FRS_PROTECT
412 struct frame {
413 jmp_buf frs_jmpbuf;
414 object *frs_lex;
415 bds_ptr frs_bds_top;
416 enum fr_class frs_class;
417 object frs_val;
418 ihs_ptr frs_ihs;
420 typedef struct frame *frame_ptr;
421 #define alloc_frame_id() alloc_object(t_spice)
422 extern struct frame frame_stack[COM_LENG];
424 frame_ptr frs_org;
425 frame_ptr frs_limit;
426 frame_ptr frs_top;
427 #define frs_push(class, val) \
428 if (++frs_top >= frs_limit) \
429 frs_overflow(); \
430 frs_top->frs_lex = lex_env;\
431 frs_top->frs_bds_top = bds_top; \
432 frs_top->frs_class = (class); \
433 frs_top->frs_val = (val); \
434 frs_top->frs_ihs = ihs_top; \
435 setjmp(frs_top->frs_jmpbuf)
436 #define frs_pop() frs_top--
437 bool nlj_active;
438 frame_ptr nlj_fr;
439 object nlj_tag;
440 object *lex_env;
441 object caar();
442 object cadr();
443 object cdar();
444 object cddr();
445 object caaar();
446 object caadr();
447 object cadar();
448 object caddr();
449 object cdaar();
450 object cdadr();
451 object cddar();
452 object cdddr();
453 object caaaar();
454 object caaadr();
455 object caadar();
456 object caaddr();
457 object cadaar();
458 object cadadr();
459 object caddar();
460 object cadddr();
461 object cdaaar();
462 object cdaadr();
463 object cdadar();
464 object cdaddr();
465 object cddaar();
466 object cddadr();
467 object cdddar();
468 object cddddr();
469 #define MMcons(a,d) make_cons((a),(d))
470 #define MMcar(x) (x)->c.c_car
471 #define MMcdr(x) (x)->c.c_cdr
472 #define CMPcar(x) (x)->c.c_car
473 #define CMPcdr(x) (x)->c.c_cdr
474 #define CMPcaar(x) (x)->c.c_car->c.c_car
475 #define CMPcadr(x) (x)->c.c_cdr->c.c_car
476 #define CMPcdar(x) (x)->c.c_car->c.c_cdr
477 #define CMPcddr(x) (x)->c.c_cdr->c.c_cdr
478 #define CMPcaaar(x) (x)->c.c_car->c.c_car->c.c_car
479 #define CMPcaadr(x) (x)->c.c_cdr->c.c_car->c.c_car
480 #define CMPcadar(x) (x)->c.c_car->c.c_cdr->c.c_car
481 #define CMPcaddr(x) (x)->c.c_cdr->c.c_cdr->c.c_car
482 #define CMPcdaar(x) (x)->c.c_car->c.c_car->c.c_cdr
483 #define CMPcdadr(x) (x)->c.c_cdr->c.c_car->c.c_cdr
484 #define CMPcddar(x) (x)->c.c_car->c.c_cdr->c.c_cdr
485 #define CMPcdddr(x) (x)->c.c_cdr->c.c_cdr->c.c_cdr
486 #define CMPcaaaar(x) (x)->c.c_car->c.c_car->c.c_car->c.c_car
487 #define CMPcaaadr(x) (x)->c.c_cdr->c.c_car->c.c_car->c.c_car
488 #define CMPcaadar(x) (x)->c.c_car->c.c_cdr->c.c_car->c.c_car
489 #define CMPcaaddr(x) (x)->c.c_cdr->c.c_cdr->c.c_car->c.c_car
490 #define CMPcadaar(x) (x)->c.c_car->c.c_car->c.c_cdr->c.c_car
491 #define CMPcadadr(x) (x)->c.c_cdr->c.c_car->c.c_cdr->c.c_car
492 #define CMPcaddar(x) (x)->c.c_car->c.c_cdr->c.c_cdr->c.c_car
493 #define CMPcadddr(x) (x)->c.c_cdr->c.c_cdr->c.c_cdr->c.c_car
494 #define CMPcdaaar(x) (x)->c.c_car->c.c_car->c.c_car->c.c_cdr
495 #define CMPcdaadr(x) (x)->c.c_cdr->c.c_car->c.c_car->c.c_cdr
496 #define CMPcdadar(x) (x)->c.c_car->c.c_cdr->c.c_car->c.c_cdr
497 #define CMPcdaddr(x) (x)->c.c_cdr->c.c_cdr->c.c_car->c.c_cdr
498 #define CMPcddaar(x) (x)->c.c_car->c.c_car->c.c_cdr->c.c_cdr
499 #define CMPcddadr(x) (x)->c.c_cdr->c.c_car->c.c_cdr->c.c_cdr
500 #define CMPcdddar(x) (x)->c.c_car->c.c_cdr->c.c_cdr->c.c_cdr
501 #define CMPcddddr(x) (x)->c.c_cdr->c.c_cdr->c.c_cdr->c.c_cdr
502 #define CMPfuncall funcall
503 #define cclosure_call funcall
504 object simple_lispcall();
505 object simple_lispcall_no_event();
506 object simple_symlispcall();
507 object simple_symlispcall_no_event();
508 object CMPtemp;
509 object CMPtemp1;
510 object CMPtemp2;
511 object CMPtemp3;
512 #define Cnil ((object)&Cnil_body)
513 #define Ct ((object)&Ct_body)
514 struct symbol Cnil_body, Ct_body;
515 object MF();
516 object MFnew();
517 object MM();
518 object Scons;
519 object siSfunction_documentation;
520 object siSvariable_documentation;
521 object siSpretty_print_format;
522 object Slist;
523 object keyword_package;
524 object alloc_object();
525 object car();
526 object cdr();
527 object list();
528 object listA();
529 object coerce_to_string();
530 object elt();
531 object elt_set();
532 frame_ptr frs_sch();
533 frame_ptr frs_sch_catch();
534 object make_cclosure();
535 object make_cclosure_new();
536 object nth();
537 object nthcdr();
538 object make_cons();
539 object append();
540 object nconc();
541 object reverse();
542 object nreverse();
543 object number_expt();
544 object number_minus();
545 object number_negate();
546 object number_plus();
547 object number_times();
548 object one_minus();
549 object one_plus();
550 object get();
551 object getf();
552 object putprop();
553 object sputprop();
554 object remprop();
555 object string_to_object();
556 object symbol_function();
557 object symbol_value();
558 object make_fixnum();
559 object make_shortfloat();
560 object make_longfloat();
561 object structure_ref();
562 object structure_set();
563 object princ();
564 object prin1();
565 object print();
566 object terpri();
567 object aref();
568 object aset();
569 object aref1();
570 object aset1();
571 void call_or_link();
572 object call_proc();
573 object call_proc0();
574 object call_proc1();
575 object call_proc2();
576 object ifuncall();
577 object ifuncall1();
578 object ifuncall2();
579 object symbol_name();
580 char object_to_char();
581 int object_to_int();
582 float object_to_float();
583 double object_to_double();
584 char *object_to_string();
585 int FIXtemp;
586 #define CMPmake_fixnum(x) \
587 ((((FIXtemp=(x))+1024)&-2048)==0?small_fixnum(FIXtemp):make_fixnum(FIXtemp))
588 #define Creturn(v) return((vs_top=vs,(v)))
589 #define Cexit return((vs_top=vs,0))
590 double sin(), cos(), tan();
591 object read_byte1(),read_char1();
593 #define fs_leader(ar,i) (((object *)((ar)->fs.fs_self))[-(i+1)])
594 #define RPAREN )
595 object make_list();
596 #ifdef HAVE_ALLOCA
597 #ifndef alloca
598 char *alloca();
599 #endif
600 char *alloca_val;
601 #define ALLOCA_CONS(n) (alloca_val=alloca((n)*sizeof(struct cons)))
602 #define ON_STACK_CONS(x,y) (alloca_val=alloca(sizeof(struct cons)), on_stack_cons(x,y))
603 #define ON_STACK_LIST on_stack_list
604 #define ON_STACK_LIST_VECTOR on_stack_list_vector
605 #define ON_STACK_MAKE_LIST on_stack_make_list
606 object on_stack_cons();
607 object on_stack_list();
608 object on_stack_list_vector();
609 object on_stack_make_list();
610 #else
611 #define ALLOCA_CONS(n) 0
612 #define ON_STACK_CONS(x,y) MMcons(x,y)
613 #define ON_STACK_LIST list
614 #define ON_STACK_LIST_VECTOR list_vector
615 #define ON_STACK_MAKE_LIST make_list
616 #endif
619 struct call_data { object fun;
620 int argd;};
621 struct call_data fcall;
622 object fcalln();
623 object list_vector();
624 object MVloc[10];
625 #define VARG(min,max) ((min) | (max << 8))
626 #define VFUN_NARGS fcall.argd
627 extern object Cstd_key_defaults[];
628 int vfun_wrong_number_of_args();
629 int eql(),equal(),eq();
630 object sublis1();
631 object LVformat(),LVerror();
632 #define EQ(x,y) ((x)==(y))
636 /* #include "../h/genpari.h"*/
637 typedef unsigned long *GEN;
638 GEN addii(),mulii(),mulsi(),powerii(),shifti(),stoi(),dvmdii(),subii();
639 int cmpii();
640 #define signe(x) (((GEN)(x))[1]>>24)
641 #define lg(x) (((GEN)(x))[0]&0xffff)
642 #define setlg(x,s) (((GEN)(x))[0]=(((GEN)(x))[0]&0xffff0000)+s)
643 #define lgef(x) (((GEN)(x))[1]&0xffff)
644 #define setlgef(x,s) (((GEN)(x))[1]=(((GEN)(x))[1]&0xffff0000)+s)
646 int in_saved_avma ;
647 #define ulong unsigned long
648 /* #define DEBUG_AVMA */
650 #ifdef DEBUG_AVMA
651 #define save_avma long lvma = (in_saved_avma = 1, avma)
652 #define restore_avma avma = (in_saved_avma = 0, lvma)
653 #else
654 #define save_avma long lvma = avma
655 #define restore_avma avma = lvma
656 #endif
657 unsigned long avma;
658 GEN gzero;
659 GEN icopy_x;
661 object make_integer();
662 /* copy x to y, increasing space by factor of 2 */
665 GEN otoi();
667 object integ_temp;
668 #define otoi(x) (integ_temp = (x) , (type_of(integ_temp) == t_bignum \
669 ? MP(integ_temp) :stoi(fix(integ_temp))))
672 void isetq_fix();
673 #ifdef HAVE_ALLOCA
674 #define SETQ_II(var,alloc,val) \
675 do{GEN _xx =(val) ; \
676 int _n = replace_copy1(_xx,var); \
677 if(_n) var = replace_copy2(_xx,alloca(_n));}while(0)
679 #define SETQ_IO(var,alloc,val) {object _xx =(val) ; \
680 int _n = obj_replace_copy1(_xx,var); \
681 if(_n) var = obj_replace_copy2(_xx,alloca(_n));}
682 #define IDECL(a,b,c) ulong b[4];a =(b[0]=0x1010000 +4,b)
683 #else
684 GEN setq_io(),setq_ii();
685 #define SETQ_IO(x,alloc,val) (x)=setq_io(x,&alloc,val)
686 #define SETQ_II(x,alloc,val) (x)=setq_ii(x,&alloc,val)
687 #define IDECL(a,b,c) ulong b[4];a =(b[0]=0x1010000 +4,b);object c
688 #endif
691 #ifdef __GNUC__
692 #define alloca __builtin_alloca
693 #endif