1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588
|
/*
Copyright (C) 1994 M. Hagiya, W. Schelter, T. Yuasa
This file is part of GNU Common Lisp, herein referred to as GCL
GCL is free software; you can redistribute it and/or modify it under
the terms of the GNU LIBRARY GENERAL PUBLIC LICENSE as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GCL is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with GCL; see the file COPYING. If not, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
object.h
*/
/*
Some system constants.
*/
#define TRUE 1 /* boolean true value */
#define FALSE 0 /* boolean false value */
#define NBPP 4 /* number of bytes per pointer */
#ifndef PAGEWIDTH
#define PAGEWIDTH 11 /* page width */
#endif
/* log2(PAGESIZE) */
#undef PAGESIZE
#define PAGESIZE (1L << PAGEWIDTH) /* page size in bytes */
#define CHCODELIM 256 /* character code limit */
/* ASCII character set */
#define CHFONTLIM 1 /* character font limit */
#define CHBITSLIM 1 /* character bits limit */
#define CHCODEFLEN 8 /* character code field length */
#define CHFONTFLEN 0 /* character font field length */
#define CHBITSFLEN 0 /* character bits field length */
#define PHTABSIZE 512 /* number of entries */
/* in the package hash table */
#define ARANKLIM 64 /* array rank limit */
#define RTABSIZE CHCODELIM
/* read table size */
#define CBMINSIZE 64 /* contiguous block minimal size */
#ifndef CHAR_SIZE
#define CHAR_SIZE 8 /* number of bits in a char */
#endif
#ifndef plong
#define plong long
#endif
#define SIGNED_CHAR(x) (((char ) -1) < (char )0 ? (char) x \
: (x >= (1<<(CHAR_SIZE-1)) ? \
x - (((int)(1<<(CHAR_SIZE-1))) << 1) \
: (char ) x))
/*
Definition of the type of LISP objects.
*/
typedef union int_object iobject;
union int_object {object *o; fixnum i;};
#define SMALL_FIXNUM_LIMIT 1024
#define Msf(obje) (obje)->SF.SFVAL
#define sf(x) Msf(x)
#define Mlf(obje) (obje)->LF.LFVAL
#define lf(x) Mlf(x)
enum stype { /* symbol type */
stp_ordinary, /* ordinary */
stp_constant, /* constant */
stp_special /* special */
};
#define Cnil ((object)&Cnil_body)
#define Ct ((object)&Ct_body)
#define sLnil Cnil
#define sLt Ct
#define NOT_SPECIAL ((void (*)())Cnil)
#define NOT_OBJECT_ALIGNED(a_) ({union lispunion _t={.vw=(void *)(a_)};_t.td.emf;})
/*
The values returned by intern and find_symbol.
File_symbol may return 0.
*/
#define INTERNAL 1
#define EXTERNAL 2
#define INHERITED 3
/*
All the packages are linked through p_link.
*/
EXTER struct package *pack_pointer; /* package pointer */
#ifdef WIDE_CONS
#define Scdr(a_) (a_)->c.c_cdr
#else
#define Scdr(a_) ({union lispunion _t={.vw=(a_)->c.c_cdr};unmark(&_t);_t.vw;})
#endif
enum httest { /* hash table key test function */
htt_eq, /* eq */
htt_eql, /* eql */
htt_equal, /* equal */
htt_equalp /* equalp */
};
enum aelttype { /* array element type */
aet_object, /* t */
aet_ch, /* string-char */
aet_bit, /* bit */
aet_fix, /* fixnum */
aet_sf, /* short-float */
aet_lf, /* plong-float */
aet_char, /* signed char */
aet_uchar, /* unsigned char */
aet_short, /* signed short */
aet_ushort, /* unsigned short */
aet_last
};
#define USHORT_GCL(x,i) (((unsigned short *)(x)->ust.ust_self)[i])
#define SHORT_GCL(x,i) ((( short *)(x)->ust.ust_self)[i])
#define BV_OFFSET(x) ((type_of(x)==t_bitvector ? x->bv.bv_offset : \
type_of(x)== t_array ? x->a.a_offset : (abort(),0)))
#define SET_BV_OFFSET(x,val) ((type_of(x)==t_bitvector ? x->bv.bv_offset = val : \
type_of(x)== t_array ? x->a.a_offset=val : (abort(),0)))
#if !defined(DOUBLE_BIGENDIAN)
#define BIT_ENDIAN(a_) (7-(a_))
#else
#define BIT_ENDIAN(a_) (a_)
#endif
#define S_DATA(x) ((struct s_data *)((x)->str.str_self))
#define SLOT_TYPE(def,i) (((S_DATA(def))->raw->ust.ust_self[i]))
#define SLOT_POS(def,i) USHORT_GCL(S_DATA(def)->slot_position,i)
#define STREF(type,x,i) (*((type *)(((char *)((x)->str.str_self))+(i))))
#define STSET(type,x,i,val) do{SGC_TOUCH(x);STREF(type,x,i) = (val);} while(0)
/* for any stream that takes writec_char, directly (not two_way or echo)
ie. smm_output,smm_io, smm_string_output, smm_socket
*/
#define STREAM_FILE_COLUMN(str) ((str)->sm.sm_int)
/* for smm_echo */
#define ECHO_STREAM_N_UNREAD(strm) ((strm)->sm.sm_int)
/* file fd for socket */
#define SOCKET_STREAM_FD(strm) ((strm)->sm.sm_fd)
#define SOCKET_STREAM_BUFFER(strm) ((strm)->sm.sm_object1)
/* for smm_string_input */
#define STRING_INPUT_STREAM_NEXT(strm) ((strm)->sm.sm_object0->st.st_fillp)
#define STRING_INPUT_STREAM_END(strm) ((strm)->sm.sm_object0->st.st_dim)
/* for smm_two_way and smm_echo */
#define STREAM_OUTPUT_STREAM(strm) ((strm)->sm.sm_object1)
#define STREAM_INPUT_STREAM(strm) ((strm)->sm.sm_object0)
/* for smm_string_{input,output} */
#define STRING_STREAM_STRING(strm) ((strm)->sm.sm_object0)
/* flags */
#define GET_STREAM_FLAG(strm,name) ((strm)->sm.sm_flags & (1<<(name)))
#define SET_STREAM_FLAG(strm,name,val) {if (val) (strm)->sm.sm_flags |= (1<<(name)); else (strm)->sm.sm_flags &= ~(1<<(name));}
#define GCL_MODE_BLOCKING 1
#define GCL_MODE_NON_BLOCKING 0
#define GCL_TCP_ASYNC 1
enum gcl_sm_flags {
gcl_sm_blocking=1,
gcl_sm_tcp_async,
gcl_sm_input,
gcl_sm_output,
gcl_sm_closed,
gcl_sm_had_error
};
enum chattrib { /* character attribute */
cat_whitespace, /* whitespace */
cat_terminating, /* terminating macro */
cat_non_terminating, /* non-terminating macro */
cat_single_escape, /* single-escape */
cat_multiple_escape, /* multiple-escape */
cat_constituent /* constituent */
};
struct rtent { /* read table entry */
enum chattrib rte_chattrib; /* character attribute */
object rte_macro; /* macro function */
object *rte_dtab; /* pointer to the */
/* dispatch table */
/* NULL for */
/* non-dispatching */
/* macro character, or */
/* non-macro character */
};
/* struct character character_table1[256+128]; */
#define character_table (character_table1+128)
#define code_char(c) (object)(character_table+((unsigned char)(c)))
#define char_code(obje) ((object)obje)->ch.ch_code
#define char_font(obje) ((object)obje)->ch.ch_font
#define char_bits(obje) ((object)obje)->ch.ch_bits
#define address_int unsigned long
/*
The struct of free lists.
*/
struct freelist {
FIRSTWORD;
address_int f_link;
};
#ifndef INT_TO_ADDRESS
#define INT_TO_ADDRESS(x) ((object )(long )x)
#endif
#define F_LINK(x) ((struct freelist *)(long) x)->f_link
#define FL_LINK F_LINK
#define SET_LINK(x,val) F_LINK(x) = (address_int) (val)
#define OBJ_LINK(x) ((object) INT_TO_ADDRESS(F_LINK(x)))
#define PHANTOM_FREELIST(x) ({struct freelist f;(object)((void *)&x+((void *)&f-(void *)&f.f_link));})
#define FREELIST_TAIL(tm_) ({struct typemanager *_tm=tm_;\
_tm->tm_free==OBJNULL ? PHANTOM_FREELIST(_tm->tm_free) : _tm->tm_tail;})
#define FREE (-1) /* free object */
struct fasd {
object stream; /* lisp object of type stream */
object table; /* hash table used in dumping or vector on input*/
object eof; /* lisp object to be returned on coming to eof mark */
object direction; /* holds Cnil or sKinput or sKoutput */
object package; /* the package symbols are in by default */
object index; /* integer. The current_dump index on write */
object filepos; /* nil or the position of the start */
object table_length; /* On read it is set to the size dump array needed
or 0
*/
object evald_items; /* a list of items which have been eval'd and must
not be walked by fasd_patch_sharp */
};
/*
Storage manager for each type.
*/
struct typemanager {
enum type tm_type; /* type */
long tm_size; /* element size in bytes */
long tm_nppage; /* number per page */
object tm_free; /* free list */
/* Note that it is of type object. */
object tm_tail; /* free list tail */
/* Note that it is of type object. */
long tm_nfree; /* number of free elements */
long tm_npage; /* number of pages */
long tm_maxpage; /* maximum number of pages */
char *tm_name; /* type name */
long tm_gbccount; /* GBC count */
object tm_alt_free; /* Alternate free list (swap with tm_free) */
long tm_alt_nfree; /* Alternate nfree (length of nfree) */
long tm_alt_npage; /* number of pages */
long tm_sgc; /* this type has at least this many sgc pages */
long tm_sgc_minfree; /* number free on a page to qualify for being an sgc page */
long tm_sgc_max; /* max on sgc pages */
long tm_min_grow; /* min amount to grow when growing */
long tm_max_grow; /* max amount to grow when growing */
long tm_growth_percent; /* percent to increase maxpages */
long tm_percent_free; /* percent which must be free after a gc for this type */
long tm_distinct; /* pages of this type are distinct */
float tm_adjgbccnt;
long tm_opt_maxpage;
};
/*
The table of type managers.
*/
EXTER struct typemanager tm_table[ 32 /* (int) t_relocatable */];
#define tm_of(t) (&(tm_table[(int)tm_table[(int)(t)].tm_type]))
/*
Contiguous block header.
*/
EXTER ufixnum contblock_lim;
struct contblock { /* contiguous block header */
ufixnum cb_size; /* size in bytes */
struct contblock
*cb_link; /* contiguous block link */
};
/*
The pointer to the contiguous blocks.
*/
EXTER struct contblock *cb_pointer; /* contblock pointer */
/* SGC cont pages: After SGC_start, old_cb_pointer will be a linked
list of free blocks on non-SGC pages, and cb_pointer will be
likewise for SGC pages. CM 20030827*/
EXTER struct contblock *old_cb_pointer; /* old contblock pointer when in SGC */
/*
Variables for memory management.
*/
#define ncbpage tm_table[t_contiguous].tm_npage
#define maxcbpage tm_table[t_contiguous].tm_maxpage
#define cbgbccount tm_table[t_contiguous].tm_gbccount
EXTER long holepage; /* hole pages */
#define nrbpage tm_table[t_relocatable].tm_npage
#define maxrbpage tm_table[t_relocatable].tm_maxpage
#define rbgbccount tm_table[t_relocatable].tm_gbccount
EXTER long new_holepage,starting_hole_div,starting_relb_heap_mult;
EXTER ufixnum recent_allocation,wait_on_abort;
EXTER double gc_alloc_min,mem_multiple,gc_page_min,gc_page_max;
EXTER bool multiprocess_memory_pool;
EXTER char *new_rb_start; /* desired relblock start after next gc */
EXTER char *rb_start; /* relblock start */
EXTER char *rb_end; /* relblock end */
EXTER char *rb_limit; /* relblock limit */
EXTER char *rb_pointer; /* relblock pointer */
INLINE ufixnum
rb_size(void) {
return rb_end-rb_start;
}
INLINE bool
rb_high(void) {
return rb_pointer>=rb_end&&rb_size();
}
INLINE char *
rb_begin(void) {
return rb_high() ? rb_end : rb_start;
}
INLINE bool
rb_emptyp(void) {
return rb_pointer == rb_begin();
}
INLINE ufixnum
ufmin(ufixnum a,ufixnum b) {
return a<=b ? a : b;
}
INLINE ufixnum
ufmax(ufixnum a,ufixnum b) {
return a>=b ? a : b;
}
#include <unistd.h>
#include <stdio.h>
#include <stdarg.h>
INLINE int
emsg(const char *s,...) {
va_list args;
ufixnum n=0;
void *v=NULL;
va_start(args,s);
n=vsnprintf(v,n,s,args)+1;
va_end(args);
v=alloca(n);
va_start(args,s);
vsnprintf(v,n,s,args);
va_end(args);
return write(2,v,n-1) ? n : -1;
}
EXTER char *heap_end; /* heap end */
EXTER char *core_end; /* core end */
EXTER
char *tmp_alloc;
/* make f allocate enough extra, so that we can round
up, the address given to an even multiple. Special
case of size == 0 , in which case we just want an aligned
number in the address range
*/
#define ALLOC_ALIGNED(f, size,align) \
({ufixnum _size=size,_align=align;_align <= sizeof(plong) ? (char *)((f)(_size)) : \
(tmp_alloc = (char *)((f)(_size+(_size ?(_align)-1 : 0)))+(_align)-1 , \
(char *)(_align * (((unsigned long)tmp_alloc)/_align)));})
#define AR_ALLOC(f,n,type) (type *) \
(ALLOC_ALIGNED(f,(n)*sizeof(type),sizeof(type)))
#define RB_GETA PAGESIZE
#ifdef AV
#define STATIC register
#endif
#define TIME_ZONE (-9)
/* For IEEEFLOAT, the double may have exponent in the second word
(little endian) or first word.*/
#if !defined(DOUBLE_BIGENDIAN)
#define HIND 1 /* (int) of double where the exponent and most signif is */
#define LIND 0 /* low part of a double */
#else /* big endian */
#define HIND 0
#define LIND 1
#endif
#ifndef VOL
#define VOL volatile
#endif
#define isUpper(xxx) (((xxx)&0200) == 0 && isupper((int)xxx))
#define isLower(xxx) (((xxx)&0200) == 0 && islower((int)xxx))
#define isDigit(xxx) (((xxx)&0200) == 0 && isdigit((int)xxx))
enum ftype {f_object,f_fixnum};
object make_si_sfun();
/* Set new to be an (object *) whose [i]'th elmt is the
ith elmnt in a va_list
if
((vl[0] == va_arg(ap,object)) ||
(vl[1] == va_arg(ap,object)) || .. vl[n-1] == va_arg(ap,object))
you may set
#define DONT_COPY_VA_LIST
In recent versions of gcc, i think the builtin_alist stuff does not
allow setting this.
*/
#ifdef DONT_COPY_VA_LIST
#define COERCE_VA_LIST(new,vl,n) new = (object *) (vl)
#else
#define COERCE_VA_LIST(new,vl,n) \
object Xxvl[65]; \
{int i; \
new=Xxvl; \
if (n >= 65) FEerror("Too plong vl",0); \
for (i=0 ; i < (n); i++) new[i]=va_arg(vl,object);}
#endif
#ifdef DONT_COPY_VA_LIST
#error Cannot set DONT_COPY_VA_LIST in ANSI C
#else
#define COERCE_VA_LIST_NEW(new,fst,vl,n) \
object Xxvl[65]; \
{int i; \
new=Xxvl; \
if (n >= 65) FEerror("va_list too long",0); \
for (i=0 ; i < (n); i++) new[i]=i ? va_arg(vl,object) : fst;}
#define COERCE_VA_LIST_KR_NEW(new,fst,vl,n) \
object Xxvl[65]; \
{int i; \
new=Xxvl; \
if (n >= 65) FEerror("va_list too long",0); \
for (i=0 ; i < (n); i++) new[i]=i||fst==OBJNULL ? va_arg(vl,object) : fst;}
#endif
#define make_si_vfun(s,f,min,max) \
make_si_vfun1(s,f,min | (max << 8))
/* Number of args supplied to a variable arg t_vfun
Used by the C function to set optionals */
#define VFUN_NARGS fcall.argd
#define RETURN4(x,y,z,w) do{/* object _x = (void *) x; */ \
fcall.values[1]=y;fcall.values[2]=z;fcall.values[3]=w;fcall.nvalues=4; \
return (x) ;} while(0)
#define RETURN2(x,y) do{/* object _x = (void *) x; */\
fcall.values[1]=y;fcall.nvalues=2; \
return (x) ;} while(0)
#define RETURN1(x) do{fcall.nvalues=1; return (x) ;} while(0)
#define RETURN0 do{fcall.nvalues=0; return Cnil ;} while(0)
#define RV(x) (*_p++ = x)
#define RETURNI(n,val1,listvals) RETURN(n,int,val1,listvals)
#define RETURNO(n,val1,listvals) RETURN(n,object,val1,listvals)
/* eg: RETURN(3,object,val1,(RV(val2),RV(val3))) */
#undef RETURN
#define RETURN(n,typ,val1,listvals) \
do{typ _val1 = val1; object *_p=&fcall.values[1]; listvals; fcall.nvalues= n; return _val1;}while(0)
/* we sometimes have to touch the header of arrays or structures
to make sure the page is writable */
#ifdef SGC
#define SGC_TOUCH(x) (x)->d.e=1 /*if (is_marked(x)) system_error(); unmark(x)*/
#else
#define SGC_TOUCH(x)
#endif
object funcall_cfun(void(*)(),int,...);
object clear_compiler_properties();
EXTER object sSlambda_block_expanded;
# ifdef __GNUC__
# define assert(ex)\
{if (!(ex)){(void)fprintf(stderr, \
"Assertion failed: file \"%s\", line %d\n", __FILE__, __LINE__);exit(1);}}
# else
# define assert(ex)
# endif
#ifndef FIX_PATH_STRING
#define FIX_PATH_STRING(file) file
#endif
#define CHECK_INTERRUPT /* if (signals_pending) raise_pending_signals(sig_safe) */
#define BEGIN_NO_INTERRUPT \
plong old_signals_allowed = signals_allowed; \
signals_allowed = 0
#define END_NO_INTERRUPT \
({signals_allowed = old_signals_allowed; if (signals_pending) raise_pending_signals(sig_use_signals_allowed_value);})
/* could add: if (signals_pending)
raise_pending_signals(sig_use_signals_allowed_value) */
#define END_NO_INTERRUPT_SAFE \
signals_allowed = old_signals_allowed; \
if (signals_pending) \
do{ if(signals_allowed ==0) /* should not get here*/abort(); \
raise_pending_signals(sig_safe)}while(0)
void raise_pending_signals();
EXTER unsigned plong signals_allowed, signals_pending;
#define endp_prop(a) (consp(a) ? FALSE : ((a)==Cnil ? TRUE : endp_error(a)))
#define endp(a) endp_prop(a)
#define proper_list(a) (type_of(a)==t_cons || (a)==Cnil)
#define IMMNIL(x) (is_imm_fixnum(x)||x==Cnil)
/*gcc boolean expression tail position bug*/
/* #define eql(a_,b_) ({register object _a=(a_);register object _b=(b_);_a==_b || (!IMMNIL(_a)&&!IMMNIL(_b)&&eql1(_a,_b));}) */
/* #define equal(a_,b_) ({register object _a=(a_);register object _b=(b_);_a==_b || (!IMMNIL(_a)&&!IMMNIL(_b)&&equal1(_a,_b));}) */
/* #define equalp(a_,b_) ({register object _a=(a_);register object _b=(b_);_a==_b || (_a!=Cnil&&_b!=Cnil&&equalp1(_a,_b));}) */
#define eql_is_eq(a_) (is_imm_fixnum(a_)||valid_cdr(a_)||(a_->d.t>t_complex))
#define eql(a_,b_) ({register object _a=(a_);register object _b=(b_);\
_a==_b ? TRUE : (eql_is_eq(_a)||eql_is_eq(_b)||_a->d.t!=_b->d.t ? FALSE : eql1(_a,_b));})
#define equal(a_,b_) ({register object _a=(a_);register object _b=(b_);_a==_b ? TRUE : (IMMNIL(_a)||IMMNIL(_b) ? FALSE : equal1(_a,_b));})
#define equalp(a_,b_) ({register object _a=(a_);register object _b=(b_);_a==_b ? TRUE : (_a==Cnil||_b==Cnil ? FALSE : equalp1(_a,_b));})
|