~ubuntu-branches/ubuntu/quantal/gclcvs/quantal

« back to all changes in this revision

Viewing changes to h/object.h

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2004-06-24 15:13:46 UTC
  • Revision ID: james.westby@ubuntu.com-20040624151346-xh0xaaktyyp7aorc
Tags: 2.7.0-26
C_GC_OFFSET is 2 on m68k-linux

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 Copyright (C) 1994 M. Hagiya, W. Schelter, T. Yuasa
 
3
 
 
4
This file is part of GNU Common Lisp, herein referred to as GCL
 
5
 
 
6
GCL is free software; you can redistribute it and/or modify it under
 
7
the terms of the GNU LIBRARY GENERAL PUBLIC LICENSE as published by
 
8
the Free Software Foundation; either version 2, or (at your option)
 
9
any later version.
 
10
 
 
11
GCL is distributed in the hope that it will be useful, but WITHOUT
 
12
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
13
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public 
 
14
License for more details.
 
15
 
 
16
You should have received a copy of the GNU Library General Public License 
 
17
along with GCL; see the file COPYING.  If not, write to the Free Software
 
18
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
 
 
20
*/
 
21
 
 
22
/*
 
23
        object.h
 
24
*/
 
25
 
 
26
/*
 
27
        Some system constants.
 
28
*/
 
29
 
 
30
#define TRUE            1       /*  boolean true value  */
 
31
#define FALSE           0       /*  boolean false value  */
 
32
 
 
33
#define FIRSTWORD unsigned char  t,flag; char s,m
 
34
 
 
35
#define NBPP            4       /*  number of bytes per pointer  */
 
36
 
 
37
#ifndef PAGEWIDTH
 
38
#define PAGEWIDTH       11      /*  page width  */
 
39
#endif
 
40
                                /*  log2(PAGESIZE)  */
 
41
#undef PAGESIZE
 
42
#define PAGESIZE        (1 << PAGEWIDTH)        /*  page size in bytes  */
 
43
 
 
44
 
 
45
#define CHCODELIM       256     /*  character code limit  */
 
46
                                /*  ASCII character set  */
 
47
#define CHFONTLIM       1       /*  character font limit  */
 
48
#define CHBITSLIM       1       /*  character bits limit  */
 
49
#define CHCODEFLEN      8       /*  character code field length  */
 
50
#define CHFONTFLEN      0       /*  character font field length  */
 
51
#define CHBITSFLEN      0       /*  character bits field length  */
 
52
 
 
53
#define PHTABSIZE       512     /*  number of entries  */
 
54
                                /*  in the package hash table  */
 
55
 
 
56
#define ARANKLIM        64      /*  array rank limit  */
 
57
 
 
58
#define RTABSIZE        CHCODELIM
 
59
                                /*  read table size  */
 
60
 
 
61
#define CBMINSIZE       64      /*  contiguous block minimal size  */
 
62
 
 
63
#ifndef CHAR_SIZE
 
64
#define CHAR_SIZE        8     /* number of bits in a char */
 
65
#endif
 
66
 
 
67
#undef bool
 
68
typedef int bool;
 
69
typedef long fixnum;
 
70
typedef unsigned long ufixnum;
 
71
typedef float shortfloat;
 
72
typedef double longfloat;
 
73
typedef unsigned short fatchar;
 
74
 
 
75
#ifndef plong
 
76
#define plong int
 
77
#endif
 
78
 
 
79
 
 
80
#define SIGNED_CHAR(x) (((char ) -1) < (char )0 ? (char) x \
 
81
                  : (x >= (1<<(CHAR_SIZE-1)) ? \
 
82
                     x - (((int)(1<<(CHAR_SIZE-1))) << 1) \
 
83
                     : (char ) x))
 
84
 
 
85
 
 
86
/*
 
87
        Definition of the type of LISP objects.
 
88
*/
 
89
typedef union lispunion *object;
 
90
 
 
91
typedef union int_object iobject;
 
92
union int_object {object o; int i;};
 
93
 
 
94
/*
 
95
        OBJect NULL value.
 
96
        It should not coincide with any legal object value.
 
97
*/
 
98
#define OBJNULL         ((object)NULL)
 
99
 
 
100
/*
 
101
        Definition of each implementation type.
 
102
*/
 
103
 
 
104
struct fixnum_struct {
 
105
                FIRSTWORD;
 
106
        fixnum  FIXVAL;         /*  fixnum value  */
 
107
};
 
108
#define Mfix(obje)      (obje)->FIX.FIXVAL
 
109
#define fix(x) Mfix(x)
 
110
 
 
111
#define SMALL_FIXNUM_LIMIT      1024
 
112
 
 
113
EXTER
 
114
struct fixnum_struct small_fixnum_table[2*SMALL_FIXNUM_LIMIT];
 
115
 
 
116
#define small_fixnum(i)  \
 
117
        (object)(small_fixnum_table+SMALL_FIXNUM_LIMIT+(i))
 
118
 
 
119
struct shortfloat_struct {
 
120
                        FIRSTWORD;
 
121
        shortfloat      SFVAL;  /*  shortfloat value  */
 
122
};
 
123
#define Msf(obje)       (obje)->SF.SFVAL
 
124
#define sf(x) Msf(x)
 
125
 
 
126
struct longfloat_struct {
 
127
                        FIRSTWORD;
 
128
        longfloat       LFVAL;  /*  longfloat value  */
 
129
};
 
130
#define Mlf(obje)       (obje)->LF.LFVAL
 
131
#define lf(x) Mlf(x)
 
132
 
 
133
 
 
134
 
 
135
/*  #ifdef _MP_H */
 
136
 
 
137
/*  #else */
 
138
/*  typedef struct */
 
139
/*  { */
 
140
/*    int _mp_alloc;             Number of *limbs* allocated and pointed  */
 
141
/*                                 to by the _mp_d field.  */
 
142
/*    int _mp_size;                      abs(_mp_size) is the number of limbs the  */
 
143
/*                                 last field points to.  If _mp_size is  */
 
144
/*                                 negative this is a negative number.   */
 
145
/*    void *_mp_d;               Pointer to the limbs.  */
 
146
/*  } our_mpz_struct; */
 
147
/*  #endif */
 
148
 
 
149
struct bignum {
 
150
                        FIRSTWORD;
 
151
#ifdef GMP
 
152
  __mpz_struct big_mpz_t;
 
153
#else
 
154
  plong             *big_self;  /*  bignum body  */
 
155
  int           big_length;     /*  bignum length  */
 
156
#endif  
 
157
};
 
158
 
 
159
struct ratio {
 
160
                FIRSTWORD;
 
161
        object  rat_den;        /*  denominator  */
 
162
                                /*  must be an integer  */
 
163
        object  rat_num;        /*  numerator  */
 
164
                                /*  must be an integer  */
 
165
};
 
166
 
 
167
struct complex {
 
168
                FIRSTWORD;
 
169
        object  cmp_real;       /*  real part  */
 
170
                                /*  must be a number  */
 
171
        object  cmp_imag;       /*  imaginary part  */
 
172
                                /*  must be a number  */
 
173
};
 
174
 
 
175
struct character {
 
176
                        FIRSTWORD;
 
177
        unsigned short  ch_code;        /*  code  */
 
178
        unsigned char   ch_font;        /*  font  */
 
179
        unsigned char   ch_bits;        /*  bits  */
 
180
};
 
181
 
 
182
 
 
183
 
 
184
EXTER 
 
185
struct character character_table1[256+128];
 
186
#define character_table (character_table1+128)
 
187
#define code_char(c)            (object)(character_table+(c))
 
188
#define char_code(obje)         (obje)->ch.ch_code
 
189
#define char_font(obje)         (obje)->ch.ch_font
 
190
#define char_bits(obje)         (obje)->ch.ch_bits
 
191
 
 
192
enum stype {                    /*  symbol type  */
 
193
        stp_ordinary,           /*  ordinary  */
 
194
        stp_constant,           /*  constant  */
 
195
        stp_special             /*  special  */
 
196
};
 
197
 
 
198
#define Cnil                    ((object)&Cnil_body)
 
199
#define Ct                      ((object)&Ct_body)
 
200
#define sLnil Cnil
 
201
#define sLt Ct
 
202
 
 
203
#define NOT_SPECIAL             ((void (*)())Cnil)
 
204
#define s_fillp         st_fillp
 
205
#define s_self          st_self
 
206
 
 
207
struct symbol {
 
208
                FIRSTWORD;
 
209
        object  s_dbind;        /*  dynamic binding  */
 
210
        void    (*s_sfdef)();   /*  special form definition  */
 
211
                                /*  This field coincides with c_car  */
 
212
        char    *s_self;        /*  print name  */
 
213
                                /*  These fields coincide with  */
 
214
                                /*  st_fillp and st_self.  */
 
215
        int     s_fillp;        /*  print name length  */
 
216
 
 
217
        object  s_gfdef;        /*  global function definition  */
 
218
                                /*  For a macro,  */
 
219
                                /*  its expansion function  */
 
220
                                /*  is to be stored.  */
 
221
        object  s_plist;        /*  property list  */
 
222
        object  s_hpack;        /*  home package  */
 
223
                                /*  Cnil for uninterned symbols  */
 
224
        short   s_stype;        /*  symbol type  */
 
225
                                /*  of enum stype  */
 
226
        short   s_mflag;        /*  macro flag  */
 
227
};
 
228
EXTER 
 
229
struct symbol Cnil_body, Ct_body;
 
230
 
 
231
struct package {
 
232
                FIRSTWORD;
 
233
        object  p_name;         /*  package name  */
 
234
                                /*  a string  */
 
235
        object  p_nicknames;    /*  nicknames  */
 
236
                                /*  list of strings  */
 
237
        object  p_shadowings;   /*  shadowing symbol list  */
 
238
        object  p_uselist;      /*  use-list of packages  */
 
239
        object  p_usedbylist;   /*  used-by-list of packages  */
 
240
        object  *p_internal;    /*  hashtable for internal symbols  */
 
241
        object  *p_external;    /*  hashtable for external symbols  */
 
242
        int p_internal_size;    /* size of internal hash table*/
 
243
        int p_external_size;     /* size of external hash table */
 
244
        int p_internal_fp;       /* [rough] number of symbols */
 
245
        int p_external_fp;    /* [rough]  number of symbols */
 
246
        struct package
 
247
                *p_link;        /*  package link  */
 
248
};
 
249
 
 
250
/*
 
251
        The values returned by intern and find_symbol.
 
252
        File_symbol may return 0.
 
253
*/
 
254
#define INTERNAL        1
 
255
#define EXTERNAL        2
 
256
#define INHERITED       3
 
257
 
 
258
/*
 
259
        All the packages are linked through p_link.
 
260
*/
 
261
EXTER struct package *pack_pointer;     /*  package pointer  */
 
262
 
 
263
struct cons {
 
264
                FIRSTWORD;
 
265
        object  c_cdr;          /*  cdr  */
 
266
        object  c_car;          /*  car  */
 
267
};
 
268
 
 
269
enum httest {                   /*  hash table key test function  */
 
270
        htt_eq,                 /*  eq  */
 
271
        htt_eql,                /*  eql  */
 
272
        htt_equal               /*  equal  */
 
273
};
 
274
 
 
275
struct htent {                  /*  hash table entry  */
 
276
        object  hte_key;        /*  key  */
 
277
        object  hte_value;      /*  value  */
 
278
};
 
279
 
 
280
struct hashtable {              /*  hash table header  */
 
281
                FIRSTWORD;
 
282
        struct htent
 
283
                *ht_self;       /*  pointer to the hash table  */
 
284
        object  ht_rhsize;      /*  rehash size  */
 
285
        object  ht_rhthresh;    /*  rehash threshold  */
 
286
        int     ht_nent;        /*  number of entries  */
 
287
        int     ht_size;        /*  hash table size  */
 
288
        short   ht_test;        /*  key test function  */
 
289
                                /*  of enum httest  */
 
290
};
 
291
 
 
292
enum aelttype {                 /*  array element type  */
 
293
        aet_object,             /*  t  */
 
294
        aet_ch,                 /*  string-char  */
 
295
        aet_bit,                /*  bit  */
 
296
        aet_fix,                /*  fixnum  */
 
297
        aet_sf,                 /*  short-float  */
 
298
        aet_lf,                 /*  plong-float  */
 
299
        aet_char,               /* signed char */
 
300
        aet_uchar,               /* unsigned char */
 
301
        aet_short,              /* signed short */
 
302
        aet_ushort,             /*  unsigned short   */
 
303
        aet_last
 
304
          };
 
305
 
 
306
struct array {                  /*  array header  */
 
307
                FIRSTWORD;
 
308
        object  a_displaced;    /*  displaced  */
 
309
        short   a_rank;         /*  array rank  */
 
310
        short   a_elttype;      /*  element type  */
 
311
        object  *a_self;        /*  pointer to the array  */
 
312
        short   a_adjustable;   /*  adjustable flag  */
 
313
        short   a_offset;       /*  bitvector offset  */
 
314
        int     a_dim;          /*  dimension  */
 
315
        int     *a_dims;        /*  table of dimensions  */
 
316
 
 
317
};
 
318
 
 
319
 
 
320
 
 
321
struct vector {                 /*  vector header  */
 
322
                FIRSTWORD;
 
323
        object  v_displaced;    /*  displaced  */
 
324
        short   v_hasfillp;     /*  has-fill-pointer flag  */
 
325
        short   v_elttype;      /*  element type  */
 
326
                
 
327
        object  *v_self;        /*  pointer to the vector  */
 
328
        int     v_fillp;        /*  fill pointer  */
 
329
                                /*  For simple vectors,  */
 
330
                                /*  v_fillp is equal to v_dim.  */
 
331
        int     v_dim;          /*  dimension  */
 
332
        short   v_adjustable;   /*  adjustable flag  */
 
333
        short   v_offset;       /*  not used  */
 
334
};
 
335
 
 
336
struct string {                 /*  string header  */
 
337
                FIRSTWORD;
 
338
        object  st_displaced;   /*  displaced  */
 
339
        short   st_hasfillp;    /*  has-fill-pointer flag  */
 
340
        short   st_adjustable;  /*  adjustable flag  */
 
341
        char    *st_self;       /*  pointer to the string  */
 
342
        int     st_fillp;       /*  fill pointer  */
 
343
                                /*  For simple strings,  */
 
344
                                /*  st_fillp is equal to st_dim.  */
 
345
        int     st_dim;         /*  dimension  */
 
346
                                /*  string length  */
 
347
 
 
348
};
 
349
 
 
350
struct ustring {
 
351
                FIRSTWORD;
 
352
        object  ust_displaced;
 
353
        short   ust_hasfillp;
 
354
        short   ust_adjustable;         
 
355
        unsigned char *ust_self;
 
356
        int     ust_fillp;
 
357
 
 
358
        int     ust_dim;
 
359
 
 
360
 
 
361
};
 
362
 
 
363
#define USHORT_GCL(x,i) (((unsigned short *)(x)->ust.ust_self)[i])
 
364
#define SHORT_GCL(x,i) ((( short *)(x)->ust.ust_self)[i])
 
365
 
 
366
#define BV_OFFSET(x) ((type_of(x)==t_bitvector ? x->bv.bv_offset : \
 
367
                       type_of(x)== t_array ? x->a.a_offset : (abort(),0)))
 
368
 
 
369
#define SET_BV_OFFSET(x,val) ((type_of(x)==t_bitvector ? x->bv.bv_offset = val : \
 
370
                       type_of(x)== t_array ? x->a.a_offset=val : (abort(),0)))
 
371
 
 
372
 
 
373
                       
 
374
 
 
375
struct bitvector {              /*  bitvector header  */
 
376
                FIRSTWORD;
 
377
        object  bv_displaced;   /*  displaced  */
 
378
        short   bv_hasfillp;    /*  has-fill-pointer flag  */
 
379
        short   bv_elttype;     /*  not used  */
 
380
        char    *bv_self;       /*  pointer to the bitvector  */
 
381
        int     bv_fillp;       /*  fill pointer  */
 
382
                                /*  For simple bitvectors,  */
 
383
                                /*  st_fillp is equal to st_dim.  */
 
384
        int     bv_dim;         /*  dimension  */
 
385
                                /*  number of bits  */
 
386
        short   bv_adjustable;  /*  adjustable flag  */
 
387
        short   bv_offset;      /*  bitvector offset  */
 
388
                                /*  the position of the first bit  */
 
389
                                /*  in the first byte  */
 
390
};
 
391
 
 
392
struct fixarray {               /*  fixnum array header  */
 
393
                FIRSTWORD;
 
394
        object  fixa_displaced; /*  displaced  */
 
395
        short   fixa_rank;      /*  array rank  */
 
396
        short   fixa_elttype;   /*  element type  */
 
397
        fixnum  *fixa_self;     /*  pointer to the array  */
 
398
        short   fixa_adjustable;/*  adjustable flag  */
 
399
        short   fixa_offset;    /*  not used  */
 
400
        int     fixa_dim;       /*  dimension  */
 
401
        int     *fixa_dims;     /*  table of dimensions  */
 
402
 
 
403
};
 
404
 
 
405
struct sfarray {                /*  short-float array header  */
 
406
                FIRSTWORD;
 
407
        object  sfa_displaced;  /*  displaced  */
 
408
        short   sfa_rank;       /*  array rank  */
 
409
        short   sfa_elttype;    /*  element type  */
 
410
        shortfloat
 
411
                *sfa_self;      /*  pointer to the array  */
 
412
        short   sfa_adjustable; /*  adjustable flag  */
 
413
        short   sfa_offset;     /*  not used  */
 
414
        int     sfa_dim;        /*  dimension  */
 
415
 
 
416
        int     *sfa_dims;      /*  table of dimensions  */
 
417
 
 
418
 
 
419
 
 
420
};
 
421
 
 
422
struct lfarray {                /*  plong-float array header  */
 
423
                FIRSTWORD;
 
424
        object  lfa_displaced;  /*  displaced  */
 
425
        short   lfa_rank;       /*  array rank  */
 
426
        short   lfa_elttype;    /*  element type  */
 
427
        longfloat
 
428
                *lfa_self;      /*  pointer to the array  */
 
429
        short   lfa_adjustable; /*  adjustable flag  */
 
430
        short   lfa_offset;     /*  not used  */
 
431
        int     lfa_dim;                /*  dimension  */
 
432
        int     *lfa_dims;      /*  table of dimensions  */
 
433
 
 
434
 
 
435
};
 
436
 
 
437
struct structure {              /*  structure header  */
 
438
                FIRSTWORD;
 
439
        object  str_def;        /*  structure definition (a structure)  */
 
440
        object  *str_self;      /*  structure self  */
 
441
};
 
442
 
 
443
struct s_data {object name;
 
444
               int length;
 
445
               object raw;
 
446
               object included;
 
447
               object includes;
 
448
               object staticp;
 
449
               object print_function;
 
450
               object slot_descriptions;
 
451
               object slot_position;
 
452
               int    size;
 
453
               object has_holes;
 
454
             };
 
455
 
 
456
#define S_DATA(x) ((struct s_data *)((x)->str.str_self))
 
457
#define SLOT_TYPE(def,i) (((S_DATA(def))->raw->ust.ust_self[i]))
 
458
#define SLOT_POS(def,i) USHORT_GCL(S_DATA(def)->slot_position,i)
 
459
#define STREF(type,x,i) (*((type *)(((char *)((x)->str.str_self))+(i))))
 
460
 
 
461
 
 
462
 
 
463
enum smmode {                   /*  stream mode  */
 
464
        smm_input,              /*  input  */
 
465
        smm_output,             /*  output  */
 
466
        smm_io,                 /*  input-output  */
 
467
        smm_probe,              /*  probe  */
 
468
        smm_synonym,            /*  synonym  */
 
469
        smm_broadcast,          /*  broadcast  */
 
470
        smm_concatenated,       /*  concatenated  */
 
471
        smm_two_way,            /*  two way  */
 
472
        smm_echo,               /*  echo  */
 
473
        smm_string_input,       /*  string input  */
 
474
        smm_string_output,      /*  string output  */
 
475
        smm_user_defined,        /*  for user defined */
 
476
        smm_socket              /*  Socket stream  */
 
477
};
 
478
 
 
479
/* for any stream that takes writec_char, directly (not two_way or echo)
 
480
   ie.   smm_output,smm_io, smm_string_output, smm_socket
 
481
 */
 
482
#define STREAM_FILE_COLUMN(str) ((str)->sm.sm_int1)
 
483
 
 
484
/* for smm_echo */
 
485
#define ECHO_STREAM_N_UNREAD(strm) ((strm)->sm.sm_int0)
 
486
 
 
487
/* file fd for socket */
 
488
#define SOCKET_STREAM_FD(strm) ((strm)->sm.sm_fd)
 
489
#define SOCKET_STREAM_BUFFER(strm) ((strm)->sm.sm_object1)
 
490
 
 
491
/*  for     smm_string_input  */
 
492
#define STRING_INPUT_STREAM_NEXT(strm) ((strm)->sm.sm_int0)
 
493
#define STRING_INPUT_STREAM_END(strm) ((strm)->sm.sm_int1)
 
494
 
 
495
/* for smm_two_way and smm_echo */
 
496
#define STREAM_OUTPUT_STREAM(strm) ((strm)->sm.sm_object1)
 
497
#define STREAM_INPUT_STREAM(strm) ((strm)->sm.sm_object0)
 
498
 
 
499
/* for smm_string_{input,output} */
 
500
#define STRING_STREAM_STRING(strm) ((strm)->sm.sm_object0)
 
501
 
 
502
struct stream {
 
503
                FIRSTWORD;
 
504
        FILE    *sm_fp;         /*  file pointer  */
 
505
        object  sm_object0;     /*  some object  */
 
506
        object  sm_object1;     /*  some object */
 
507
        int     sm_int0;        /*  some int  */
 
508
        int     sm_int1;        /*  column for input or output, stream */
 
509
        char    *sm_buffer;     /*  ptr to BUFSIZE block of storage */
 
510
        char    sm_mode;        /*  stream mode  */
 
511
        unsigned char    sm_flags;         /* flags from gcl_sm_flags */
 
512
        short sm_fd;         /* stream fd */
 
513
     
 
514
};
 
515
/* flags */
 
516
#define GET_STREAM_FLAG(strm,name) ((strm)->sm.sm_flags & (1<<(name)))
 
517
#define SET_STREAM_FLAG(strm,name,val) (val ? \
 
518
                        ((strm)->sm.sm_flags |= (1<<(name))) : \
 
519
                        ((strm)->sm.sm_flags &= ~(1<<(name)))) 
 
520
 
 
521
#define GCL_MODE_BLOCKING 1
 
522
#define GCL_MODE_NON_BLOCKING 0
 
523
#define GCL_TCP_ASYNC 1
 
524
     
 
525
enum gcl_sm_flags {
 
526
  gcl_sm_blocking=1,
 
527
  gcl_sm_tcp_async,
 
528
  gcl_sm_input,
 
529
  gcl_sm_output,
 
530
  gcl_sm_had_error
 
531
  
 
532
  
 
533
};
 
534
  
 
535
#ifdef BSD
 
536
#ifdef SUN3
 
537
#define BASEFF          (unsigned char *)0xffffffff
 
538
#else
 
539
#define BASEFF          (char *)0xffffffff
 
540
#endif
 
541
#endif
 
542
 
 
543
#ifdef ATT
 
544
#define BASEFF          (unsigned char *)0xffffffff
 
545
#endif
 
546
 
 
547
#ifdef E15
 
548
#define BASEFF          (unsigned char *)0xffffffff
 
549
#endif
 
550
 
 
551
#ifdef MV
 
552
 
 
553
 
 
554
#endif
 
555
 
 
556
struct random {
 
557
                        FIRSTWORD;
 
558
        unsigned        rnd_value;      /*  random state value  */
 
559
};
 
560
 
 
561
enum chattrib {                 /*  character attribute  */
 
562
        cat_whitespace,         /*  whitespace  */
 
563
        cat_terminating,        /*  terminating macro  */
 
564
        cat_non_terminating,    /*  non-terminating macro  */
 
565
        cat_single_escape,      /*  single-escape  */
 
566
        cat_multiple_escape,    /*  multiple-escape  */
 
567
        cat_constituent         /*  constituent  */
 
568
};
 
569
 
 
570
struct rtent {                          /*  read table entry  */
 
571
        enum chattrib   rte_chattrib;   /*  character attribute  */
 
572
        object          rte_macro;      /*  macro function  */
 
573
        object          *rte_dtab;      /*  pointer to the  */
 
574
                                        /*  dispatch table  */
 
575
                                        /*  NULL for  */
 
576
                                        /*  non-dispatching  */
 
577
                                        /*  macro character, or  */
 
578
                                        /*  non-macro character  */
 
579
};
 
580
 
 
581
struct readtable {                      /*  read table  */
 
582
                        FIRSTWORD;
 
583
        struct rtent    *rt_self;       /*  read table itself  */
 
584
};
 
585
 
 
586
struct pathname {
 
587
                FIRSTWORD;
 
588
        object  pn_host;        /*  host  */
 
589
        object  pn_device;      /*  device  */
 
590
        object  pn_directory;   /*  directory  */
 
591
        object  pn_name;        /*  name  */
 
592
        object  pn_type;        /*  type  */
 
593
        object  pn_version;     /*  version  */
 
594
};
 
595
 
 
596
struct cfun {                   /*  compiled function header  */
 
597
                FIRSTWORD;
 
598
        object  cf_name;        /*  compiled function name  */
 
599
        void    (*cf_self)();   /*  entry address  */
 
600
        object  cf_data;        /*  data the function uses  */
 
601
                                /*  for GBC  */
 
602
};
 
603
 
 
604
struct cclosure {               /*  compiled closure header  */
 
605
                FIRSTWORD;
 
606
        object  cc_name;        /*  compiled closure name  */
 
607
        void    (*cc_self)();   /*  entry address  */
 
608
        object  cc_env;         /*  environment  */
 
609
        object  cc_data;        /*  data the closure uses  */
 
610
                                /*  for GBC  */
 
611
        int cc_envdim;
 
612
        object  *cc_turbo;      /*  turbo charger */
 
613
};
 
614
 
 
615
struct closure {
 
616
        FIRSTWORD; 
 
617
        object  cl_name;       /* name */
 
618
        object  (*cl_self)();  /* C start address of code */
 
619
        object  cl_data;       /* To object holding VV vector */
 
620
        int cl_argd;           /* description of args + number */
 
621
        int cl_envdim;         /* length of the environment vector */
 
622
        object *cl_env;        /* environment vector referenced by cl_self()*/
 
623
};
 
624
 
 
625
struct sfun {
 
626
                FIRSTWORD; 
 
627
        object  sfn_name;       /* name */
 
628
        object  (*sfn_self)();  /* C start address of code */
 
629
        object  sfn_data;       /* To object holding VV vector */
 
630
        int sfn_argd;           /* description of args + number */
 
631
 
 
632
              };
 
633
 
 
634
struct vfun {
 
635
                FIRSTWORD; 
 
636
        object  vfn_name;       /* name */
 
637
        object  (*vfn_self)();  /* C start address of code */
 
638
        object  vfn_data;       /* To object holding VV data */
 
639
        unsigned short vfn_minargs; /* Min args and where varargs start */
 
640
        unsigned short vfn_maxargs;    /* Max number of args */
 
641
              };
 
642
struct cfdata {
 
643
     FIRSTWORD;
 
644
     char *cfd_start;             /* beginning of contblock for fun */
 
645
     int cfd_size;              /* size of contblock */
 
646
     int cfd_fillp;             /* size of self */
 
647
     object *cfd_self;          /* body */
 
648
   };
 
649
 
 
650
struct spice {
 
651
                FIRSTWORD;
 
652
        int     spc_dummy;
 
653
};
 
654
 
 
655
/*
 
656
        dummy type
 
657
*/
 
658
struct dummy {
 
659
        FIRSTWORD;
 
660
};
 
661
 
 
662
/*
 
663
        Definition of lispunion.
 
664
*/
 
665
union lispunion {
 
666
        struct fixnum_struct
 
667
                        FIX;    /*  fixnum  */
 
668
        struct bignum   big;    /*  bignum  */
 
669
        struct ratio    rat;    /*  ratio  */
 
670
        struct shortfloat_struct
 
671
                        SF;     /*  short floating-point number  */
 
672
        struct longfloat_struct
 
673
                        LF;     /*  plong floating-point number  */
 
674
        struct complex  cmp;    /*  complex number  */
 
675
        struct character
 
676
                        ch;     /*  character  */
 
677
        struct symbol   s;      /*  symbol  */
 
678
        struct package  p;      /*  package  */
 
679
        struct cons     c;      /*  cons  */
 
680
        struct hashtable
 
681
                        ht;     /*  hash table  */
 
682
        struct array    a;      /*  array  */
 
683
        struct vector   v;      /*  vector  */
 
684
        struct string   st;     /*  string  */
 
685
        struct ustring  ust;
 
686
        struct bitvector
 
687
                        bv;     /*  bit-vector  */
 
688
        struct structure
 
689
                        str;    /*  structure  */
 
690
        struct stream   sm;     /*  stream  */
 
691
        struct random   rnd;    /*  random-states  */
 
692
        struct readtable
 
693
                        rt;     /*  read table  */
 
694
        struct pathname pn;     /*  path name  */
 
695
        struct cfun     cf;     /*  compiled function  uses value stack] */
 
696
        struct cclosure cc;     /*  compiled closure  uses value stack */
 
697
        struct closure  cl;     /*  compiled closure  uses c stack */
 
698
        struct sfun     sfn;    /*  simple function */
 
699
        struct vfun     vfn;    /*  function with variable number of args */
 
700
        struct cfdata   cfd;    /* compiled fun data */
 
701
        struct spice    spc;    /*  spice  */
 
702
 
 
703
        struct dummy    d;      /*  dummy  */
 
704
 
 
705
        struct fixarray fixa;   /*  fixnum array  */
 
706
        struct sfarray  sfa;    /*  short-float array  */
 
707
        struct lfarray  lfa;    /*  plong-float array  */
 
708
};
 
709
 
 
710
#define address_int unsigned long
 
711
 
 
712
/*
 
713
        The struct of free lists.
 
714
*/
 
715
struct freelist {
 
716
        FIRSTWORD;
 
717
        address_int f_link;
 
718
};
 
719
#ifndef INT_TO_ADDRESS
 
720
#define INT_TO_ADDRESS(x) ((object )(long )x)
 
721
#endif
 
722
 
 
723
#define F_LINK(x) ((struct freelist *)(long) x)->f_link
 
724
#define FL_LINK F_LINK
 
725
#define SET_LINK(x,val) F_LINK(x) = (address_int) (val)
 
726
#define OBJ_LINK(x) ((object) INT_TO_ADDRESS(F_LINK(x)))
 
727
 
 
728
#define FREE    (-1)            /*  free object  */
 
729
 
 
730
/*
 
731
        Type_of.
 
732
*/
 
733
#define type_of(obje)   ((enum type)(((object)(obje))->d.t))
 
734
 
 
735
/*
 
736
        Storage manager for each type.
 
737
*/
 
738
struct typemanager {
 
739
        enum type
 
740
                tm_type;        /*  type  */
 
741
        short   tm_size;        /*  element size in bytes  */
 
742
        short   tm_nppage;      /*  number per page  */
 
743
        object  tm_free;        /*  free list  */
 
744
                                /*  Note that it is of type object.  */
 
745
        long    tm_nfree;       /*  number of free elements  */
 
746
        long    tm_nused;       /*  number of elements used  */
 
747
        long    tm_npage;       /*  number of pages  */
 
748
        long    tm_maxpage;     /*  maximum number of pages  */
 
749
        char    *tm_name;       /*  type name  */
 
750
        int     tm_gbccount;    /*  GBC count  */
 
751
        object  tm_alt_free;    /*  Alternate free list (swap with tm_free) */
 
752
        long     tm_alt_nfree;   /*  Alternate nfree (length of nfree) */
 
753
        short   tm_sgc;         /*  this type has at least this many
 
754
                                    sgc pages */
 
755
        short   tm_sgc_minfree;   /* number free on a page to qualify for
 
756
                                    being an sgc page */
 
757
        short   tm_sgc_max;     /* max on sgc pages */
 
758
        short   tm_min_grow;    /* min amount to grow when growing */
 
759
        short   tm_max_grow;    /* max amount to grow when growing */
 
760
        short   tm_growth_percent;  /* percent to increase maxpages */
 
761
        short   tm_percent_free;  /* percent which must be free after a gc for this type */
 
762
        short   tm_distinct;       /* pages of this type are distinct */
 
763
        float   tm_adjgbccnt;
 
764
};
 
765
 
 
766
 
 
767
/*
 
768
        The table of type managers.
 
769
*/
 
770
EXTER struct typemanager tm_table[ 32  /* (int) t_relocatable */];
 
771
 
 
772
#define tm_of(t)        (&(tm_table[(int)tm_table[(int)(t)].tm_type]))
 
773
 
 
774
/*
 
775
        Contiguous block header.
 
776
*/
 
777
struct contblock {              /*  contiguous block header  */
 
778
        int     cb_size;        /*  size in bytes  */
 
779
        struct contblock
 
780
                *cb_link;       /*  contiguous block link  */
 
781
};
 
782
 
 
783
/*
 
784
        The pointer to the contiguous blocks.
 
785
*/
 
786
EXTER struct contblock *cb_pointer;     /*  contblock pointer  */
 
787
 
 
788
/* SGC cont pages: After SGC_start, old_cb_pointer will be a linked
 
789
   list of free blocks on non-SGC pages, and cb_pointer will be
 
790
   likewise for SGC pages.  CM 20030827*/
 
791
EXTER struct contblock *old_cb_pointer; /*  old contblock pointer when in SGC  */
 
792
 
 
793
/* SGC cont pages: FIXME -- at some point, enable runtime disabling of
 
794
   SGC cont pages.  Right now, the tm_sgc variable for type contiguous
 
795
   will govern only the possible attempt to get new pages for SGC.
 
796
   Contiguous pages normally allocated when SGC is on will always be
 
797
   marked with SGC_PAGE_FLAG, as the current GBC algorithm always uses
 
798
   sgc_contblock_sweep_phase in this case. */
 
799
/* #define SGC_CONT_ENABLED (sgc_enabled && tm_table[t_contiguous].tm_sgc) */
 
800
#define SGC_CONT_ENABLED (sgc_enabled)
 
801
 
 
802
/*
 
803
        Variables for memory management.
 
804
*/
 
805
EXTER long ncb;                 /*  number of contblocks  */
 
806
/* int ncbpage;                   number of contblock pages  */
 
807
#define ncbpage tm_table[t_contiguous].tm_npage
 
808
#define maxcbpage tm_table[t_contiguous].tm_maxpage
 
809
#define cbgbccount tm_table[t_contiguous].tm_gbccount  
 
810
  
 
811
 
 
812
/* int maxcbpage; maximum number of contblock pages  */
 
813
EXTER 
 
814
long holepage;                  /*  hole pages  */
 
815
#define nrbpage tm_table[t_relocatable].tm_npage
 
816
#define rbgbccount tm_table[t_relocatable].tm_gbccount
 
817
/* int nrbpage;                   number of relblock pages  */
 
818
  
 
819
 
 
820
EXTER 
 
821
char *rb_start;                 /*  relblock start  */
 
822
EXTER char *rb_end;                     /*  relblock end  */
 
823
EXTER char *rb_limit;                   /*  relblock limit  */
 
824
EXTER char *rb_pointer;         /*  relblock pointer  */
 
825
EXTER char *rb_start1;          /*  relblock start in copy space  */
 
826
EXTER char *rb_pointer1;                /*  relblock pointer in copy space  */
 
827
 
 
828
EXTER char *heap_end;                   /*  heap end  */
 
829
EXTER char *core_end;                   /*  core end  */
 
830
EXTER 
 
831
char *tmp_alloc;
 
832
 
 
833
/* make f allocate enough extra, so that we can round
 
834
   up, the address given to an even multiple.   Special
 
835
   case of size == 0 , in which case we just want an aligned
 
836
   number in the address range
 
837
   */
 
838
 
 
839
#define ALLOC_ALIGNED(f, size,align) \
 
840
  (align <= sizeof(plong) ? (char *)((f)(size)) : \
 
841
   (tmp_alloc = (char *)((f)(size+(size ?(align)-1 : 0)))+(align)-1 , \
 
842
   (char *)(align * (((unsigned long)tmp_alloc)/align))))
 
843
#define AR_ALLOC(f,n,type) (type *) \
 
844
  (ALLOC_ALIGNED(f,(n)*sizeof(type),sizeof(type)))
 
845
 
 
846
 
 
847
/* FIXME  Make all other page constants scale similarly by default. */
 
848
#ifndef HOLEPAGE
 
849
#define HOLEPAGE        (MAXPAGE/10)
 
850
#endif
 
851
 
 
852
 
 
853
/* #define      INIT_HOLEPAGE   150 */
 
854
/* #define      INIT_NRBPAGE    50 */
 
855
/* #define      RB_GETA         512 */
 
856
 
 
857
#define INIT_HOLEPAGE   (6*HOLEPAGE/5)
 
858
#define INIT_NRBPAGE    (INIT_HOLEPAGE/3)
 
859
#define RB_GETA         (10*INIT_NRBPAGE)
 
860
 
 
861
 
 
862
#ifdef AV
 
863
#define STATIC  register
 
864
#endif
 
865
#ifdef MV
 
866
 
 
867
#endif
 
868
 
 
869
#define TIME_ZONE       (-9)
 
870
EXTER 
 
871
fixnum FIXtemp;
 
872
 
 
873
/*  For IEEEFLOAT, the double may have exponent in the second word
 
874
(little endian) or first word.*/
 
875
 
 
876
#if defined(I386) || defined(LITTLE_END)
 
877
#define HIND 1  /* (int) of double where the exponent and most signif is */
 
878
#define LIND 0  /* low part of a double */
 
879
#else /* big endian */
 
880
#define HIND 0
 
881
#define LIND 1
 
882
#endif
 
883
#ifndef VOL
 
884
#define VOL
 
885
#endif
 
886
 
 
887
 
 
888
#define isUpper(xxx)    (((xxx)&0200) == 0 && isupper((int)xxx))
 
889
#define isLower(xxx)    (((xxx)&0200) == 0 && islower((int)xxx))
 
890
#define isDigit(xxx)    (((xxx)&0200) == 0 && isdigit((int)xxx))
 
891
enum ftype {f_object,f_fixnum};
 
892
EXTER 
 
893
char *alloca_val;
 
894
/*          ...xx|xx|xxxx|xxxx|   
 
895
                     ret  Narg     */
 
896
 
 
897
/*    a9a8a7a6a5a4a3a4a3a2a1a0rrrrnnnnnnnn
 
898
         ai=argtype(i)         ret   nargs
 
899
 */
 
900
#define SFUN_NARGS(x) (x & 0xff) /* 8 bits */
 
901
#define RESTYPE(x) (x<<8)   /* 3 bits */
 
902
   /* set if the VFUN_NARGS = m ; has been set correctly */
 
903
#define VFUN_NARG_BIT (1 <<11) 
 
904
#define ARGTYPE(i,x) ((x) <<(12+(i*2)))
 
905
#define ARGTYPE1(x)  (1 | ARGTYPE(0,x))
 
906
#define ARGTYPE2(x,y) (2 | ARGTYPE(0,x)  | ARGTYPE(1,y))
 
907
#define ARGTYPE3(x,y,z) (3 | ARGTYPE(0,x) | ARGTYPE(1,y) | ARGTYPE(2,z))
 
908
 
 
909
object make_si_sfun();
 
910
EXTER object MVloc[10];
 
911
 
 
912
/* Set new to be an (object *) whose [i]'th elmt is the
 
913
   ith elmnt in a va_list
 
914
   if 
 
915
   ((vl[0] == va_arg(ap,object)) ||
 
916
    (vl[1] == va_arg(ap,object)) || .. vl[n-1] == va_arg(ap,object))
 
917
   you may set
 
918
   #define DONT_COPY_VA_LIST
 
919
   In recent versions of gcc, i think the builtin_alist stuff does not
 
920
   allow setting this.
 
921
 */
 
922
#ifdef DONT_COPY_VA_LIST
 
923
#define COERCE_VA_LIST(new,vl,n) new = (object *) (vl)
 
924
#else
 
925
#define COERCE_VA_LIST(new,vl,n) \
 
926
 object Xxvl[65]; \
 
927
 {int i; \
 
928
  new=Xxvl; \
 
929
  if (n >= 65) FEerror("Too plong vl",0); \
 
930
  for (i=0 ; i < (n); i++) new[i]=va_arg(vl,object);}
 
931
#endif
 
932
 
 
933
#ifdef DONT_COPY_VA_LIST
 
934
#error Cannot set DONT_COPY_VA_LIST in ANSI C
 
935
#else
 
936
#define COERCE_VA_LIST_NEW(new,fst,vl,n) \
 
937
 object Xxvl[65]; \
 
938
 {int i; \
 
939
  new=Xxvl; \
 
940
  if (n >= 65) FEerror("va_list too long",0); \
 
941
  for (i=0 ; i < (n); i++) new[i]=i ? va_arg(vl,object) : fst;}
 
942
#endif
 
943
 
 
944
 
 
945
 
 
946
#define make_si_vfun(s,f,min,max) \
 
947
  make_si_vfun1(s,f,min | (max << 8))
 
948
 
 
949
/* Number of args supplied to a variable arg t_vfun
 
950
 Used by the C function to set optionals */
 
951
 
 
952
struct call_data { 
 
953
  object fun;
 
954
  int argd;
 
955
  int nvalues;
 
956
  object values[50];
 
957
  double double_return;
 
958
};
 
959
EXTER struct call_data fcall;
 
960
 
 
961
#define  VFUN_NARGS fcall.argd
 
962
#define RETURN2(x,y) do{/*  object _x = (void *) x;  */\
 
963
                          fcall.values[2]=y;fcall.nvalues=2; \
 
964
                          return (x) ;} while(0)
 
965
#define RETURN1(x) do{fcall.nvalues=1; return (x) ;} while(0)
 
966
#define RETURN0  do{fcall.nvalues=0; return Cnil ;} while(0)
 
967
 
 
968
#define RV(x) (*_p++ = x)
 
969
 
 
970
#define RETURNI(n,val1,listvals) RETURN(n,int,val1,listvals)
 
971
#define RETURNO(n,val1,listvals) RETURN(n,object,val1,listvals)
 
972
 
 
973
/* eg: RETURN(3,object,val1,(RV(val2),RV(val3))) */
 
974
#define RETURN(n,typ,val1,listvals) \
 
975
   do{typ _val1 = val1; object *_p=&fcall.values[1]; listvals; fcall.nvalues= n; return _val1;}while(0)
 
976
/* #define CALL(n,form) (VFUN_NARGS=n,form) */
 
977
 
 
978
        
 
979
 
 
980
/* we sometimes have to touch the header of arrays or structures
 
981
   to make sure the page is writable */
 
982
#ifdef SGC
 
983
#define SGC_TOUCH(x) if ((x)->d.m) system_error(); (x)->d.m=0
 
984
#else
 
985
#define SGC_TOUCH(x)
 
986
#endif
 
987
 
 
988
object funcall_cfun(void(*)(),int,...);
 
989
object clear_compiler_properties();
 
990
EXTER object sSlambda_block_expanded;
 
991
 
 
992
# ifdef __GNUC__ 
 
993
# define assert(ex)\
 
994
{if (!(ex)){(void)fprintf(stderr, \
 
995
                  "Assertion failed: file \"%s\", line %d\n", __FILE__, __LINE__);exit(1);}}
 
996
# else
 
997
# define assert(ex)
 
998
# endif
 
999
 
 
1000
#ifndef FIX_PATH_STRING
 
1001
#define FIX_PATH_STRING(file) file
 
1002
#endif
 
1003
        
 
1004
 
 
1005
#define CHECK_INTERRUPT   if (signals_pending) raise_pending_signals(sig_safe)
 
1006
 
 
1007
#define BEGIN_NO_INTERRUPT \
 
1008
 plong old_signals_allowed = signals_allowed; \
 
1009
  signals_allowed = 0
 
1010
 
 
1011
#define END_NO_INTERRUPT \
 
1012
  signals_allowed = old_signals_allowed
 
1013
/* could add:   if (signals_pending)
 
1014
   raise_pending_signals(sig_use_signals_allowed_value) */
 
1015
 
 
1016
 
 
1017
#define END_NO_INTERRUPT_SAFE \
 
1018
  signals_allowed = old_signals_allowed; \
 
1019
  if (signals_pending) \
 
1020
    do{ if(signals_allowed ==0) /* should not get here*/abort(); \
 
1021
          raise_pending_signals(sig_safe)}while(0)
 
1022
 
 
1023
void raise_pending_signals();
 
1024
 
 
1025
EXTER unsigned plong signals_allowed, signals_pending  ;
 
1026
 
 
1027
EXTER struct symbol Dotnil_body;
 
1028
#define Dotnil ((object)&Dotnil_body)
 
1029
 
 
1030
#define endp(x) ({\
 
1031
    static struct cons s_my_dot={t_cons,0,0,0,Dotnil,Dotnil};\
 
1032
    object _x=(x);\
 
1033
    bool _b=FALSE;\
 
1034
    \
 
1035
    if (type_of(_x)==t_cons) {\
 
1036
       if (type_of(_x->c.c_cdr)!=t_cons && _x->c.c_cdr!=Cnil)\
 
1037
          s_my_dot.c_car=_x->c.c_cdr;\
 
1038
       else \
 
1039
          s_my_dot.c_car=Dotnil;\
 
1040
    } else {\
 
1041
       if (_x==s_my_dot.c_car)\
 
1042
          x=(object)&s_my_dot;\
 
1043
       else {\
 
1044
         s_my_dot.c_car=Dotnil;\
 
1045
         if (_x==Cnil || _x==Dotnil)\
 
1046
             _b=TRUE;\
 
1047
         else\
 
1048
             FEwrong_type_argument(sLlist, _x);\
 
1049
       }\
 
1050
    }\
 
1051
    _b;\
 
1052
    })
 
1053
 
 
1054
#define endp_prop(a) (type_of(a)==t_cons ? FALSE : ((a)==Cnil ? TRUE : (FEwrong_type_argument(sLlist, (a)),FALSE)))
 
1055
    
 
1056
#define proper_list(a) (type_of(a)==t_cons || (a)==Cnil)
 
1057
#define fix_dot(a) ((a) == Dotnil ? Cnil : (type_of(a)==t_cons && (a)->c.c_cdr==Dotnil ? (a)->c.c_car : (a)))