PageRenderTime 203ms CodeModel.GetById 32ms RepoModel.GetById 19ms app.codeStats 3ms

/src/lispbibl.d

https://github.com/ynd/clisp-branch--ynd-devel
D | 12025 lines | 7981 code | 741 blank | 3303 comment | 1075 complexity | c404e42f858ad768575a5be350bf7543 MD5 | raw file
Possible License(s): LGPL-2.0, GPL-2.0, BSD-3-Clause
  1. /*
  2. * Main include-file for CLISP
  3. * Bruno Haible 1990-2008
  4. * Marcus Daniels 11.11.1994
  5. * Sam Steingold 1998-2008
  6. * German comments translated into English: Stefan Kain 2001-09-24
  7. Flags intended to be set through CFLAGS:
  8. Readline library:
  9. NO_READLINE
  10. Termcap/ncurses library:
  11. NO_TERMCAP_NCURSES
  12. Internationalization:
  13. NO_GETTEXT, UNICODE
  14. Fault handling:
  15. NO_SIGSEGV
  16. Foreign function interface:
  17. DYNAMIC_FFI
  18. Dynamic loading of modules:
  19. DYNAMIC_MODULES
  20. Safety level:
  21. SAFETY={0,1,2,3}
  22. Exploit GCC global register variables:
  23. USE_GCC_REGISTER_VARIABLES
  24. Debugging (turned on by --with-debug configure option):
  25. DEBUG_GCSAFETY (requires G++)
  26. DEBUG_OS_ERROR
  27. DEBUG_SPVW
  28. DEBUG_BYTECODE
  29. DEBUG_BACKTRACE
  30. DEBUG_COMPILER
  31. Flags that may be set through CFLAGS, in order to override the defaults:
  32. Object representation (on 32-bit platforms only):
  33. TYPECODES, HEAPCODES, STANDARD_HEAPCODES, LINUX_NOEXEC_HEAPCODES, WIDE
  34. Advanced memory management:
  35. NO_SINGLEMAP, NO_TRIVIALMAP, NO_MULTIMAP_FILE, NO_MULTIMAP_SHM,
  36. NO_VIRTUAL_MEMORY, CONS_HEAP_GROWS_DOWN, CONS_HEAP_GROWS_UP,
  37. NO_MORRIS_GC, NO_GENERATIONAL_GC
  38. String representation:
  39. NO_SMALL_SSTRING
  40. Implementation is prepared for the following computers,
  41. operating systems and c-compilers
  42. (Only a rough listing, check the file PLATFORMS for further details.)
  43. Machine Producer Operating system C-Compiler recognized through
  44. AMIGA Commodore AMIGA-OS (AMIGADOS) GNU amiga or AMIGA, __GNUC__, maybe MC68000 or AMIGA3000
  45. any any UNIX GNU unix, __GNUC__, ...
  46. any any UNIX CC unix, ...
  47. Amiga 3000 Commodore Amiga UNIX 2.1 SVR4.0 GNU unix, __unix__, AMIX, __AMIX__, __svr4__, m68k, __m68k__, __motorola__, __GNUC__
  48. SUN-3 Sun SUN-OS3 (UNIX BSD 4.2) GNU sun, unix, mc68020, __GNUC__
  49. SUN-3 Sun SUN-OS4 (UNIX SUNOS 4.1) GNU sun, unix, mc68020, __GNUC__
  50. SUN-386 Sun SUN-OS4 (UNIX SUNOS 4.0) GNU sun, unix, sun386, i386, __GNUC__
  51. SUN-386 Sun SUN-OS4 (UNIX SUNOS 4.0) CC sun, unix, sun386, i386
  52. SUN-4 Sun SUN-OS4 (UNIX SUNOS 4.1) GNU sun, unix, sparc, __GNUC__
  53. SUN-4 Sun SUN-OS4 (UNIX SUNOS 4.1) CC sun, unix, sparc
  54. SUN-4 Sun SUN-OS5 (UNIX Solaris) GCC sun, unix, sparc, __GNUC__
  55. UltraSparc Sun Solaris 7 (UNIX SUNOS 5.7) CC sun, unix, __sparc, __sparcv9
  56. UltraSparc Sun Solaris 7 (UNIX SUNOS 5.7) GCC sun, unix, __sparc, __arch64__, __GNUC__
  57. IBM-PC/386 any SUN-OS5 (UNIX Solaris) GCC sun, unix, __svr4__, i386, __GNUC__
  58. HP9000-300 Hewlett-Packard NetBSD 0.9 (UNIX BSD 4.3) GNU unix, __NetBSD__, mc68000, __GNUC__
  59. HP9000-300 Hewlett-Packard HP-UX 8.0 (UNIX SYS V) GNU [__]hpux, [__]unix, [__]hp9000s300, mc68000, __GNUC__
  60. HP9000-800 Hewlett-Packard HP-UX 8.0 (UNIX SYS V) GNU [__]hpux, [__]unix, [__]hp9000s800
  61. IRIS Silicon Graphics IRIX (UNIX SYS V 3.2) GNU unix, SVR3, mips, sgi, __GNUC__
  62. IRIS Silicon Graphics IRIX (UNIX SYS V) cc -ansi [__]unix, [__]SVR3, [__]mips, [__]sgi
  63. IRIS Silicon Graphics IRIX 5 (UNIX SYS V 4) GNU [__]unix, [__]SYSTYPE_SVR4, [__]mips, [__]host_mips, [__]MIPSEB, [__]sgi, __DSO__, [__]_MODERN_C, __GNUC__
  64. DECstation 5000 RISC/OS (Ultrix V4.2A) GNU unix, [__]mips, [__]ultrix
  65. DG-UX 88k Data General DG/UX GNU unix, m88000, DGUX
  66. DEC Alpha DEC OSF/1 1.3 cc [unix,] __unix__, __osf__, __alpha
  67. DEC Alpha DEC OSF/1 1.3 GNU unix, __unix__, __osf__, __alpha, __alpha__, _LONGLONG
  68. Apple MacII Apple A/UX (UNIX SYS V 2) GNU [__]unix, [__]AUX, [__]macII, [__]m68k, mc68020, mc68881, __GNUC__
  69. NeXT NeXT NeXTstep 3.1 (UNIX) cc NeXT, m68k
  70. PowerPC Apple Mach 3.0 + MkLinux GNU unix, __powerpc__, __PPC__, _ARCH_PPC, _CALL_SYSV, __ELF__, __linux__
  71. PowerPC Apple Mach + Rhapsody cc __MACH__, __APPLE__, __ppc[__], __GNUC__, __APPLE_CC__
  72. PowerPC Apple Mach + MacOS X cc __MACH__, __APPLE__, __ppc__, __GNUC__, __APPLE_CC__
  73. Sequent Sequent PTX 3.2.0 V2.1.0 i386 (SYS V) GNU unix, i386, _SEQUENT_, __GNUC__
  74. Sequent Sequent PTX V4.1.3 GNU unix, i386, _SEQUENT_, __svr4__, __GNUC__
  75. Convex C2 Convex ConvexOS 10.1 GNU __convex__, __GNUC__
  76. IBM RS/6000 IBM AIX 3.2 GNU _AIX, _AIX32, _IBMR2, __CHAR_UNSIGNED__, __GNUC__
  77. IBM-PC/386 any LINUX (free UNIX) GNU unix, linux, i386, __GNUC__
  78. IBM-PC/386 any LINUX (free UNIX) Intel 5.0 __unix__, __linux__, __INTEL_COMPILER, __ICC, __USLC__
  79. IBM-PC/386 any 386BSD 0.1 (UNIX BSD 4.2) GNU unix, __386BSD__, i386, __GNUC__
  80. IBM-PC/386 any NetBSD 0.9 (UNIX BSD 4.3) GNU unix, __NetBSD__, i386, __GNUC__
  81. IBM-PC/386 any FreeBSD 4.0 (UNIX BSD 4.4) GNU unix, __FreeBSD__, i386, __GNUC__
  82. IBM-PC/386 any EMX 0.9c (UNIXlike on OS/2) GNU [unix,] i386, __GNUC__, __EMX__
  83. IBM-PC/386 any Cygwin32 on WinNT/Win95 GNU _WIN32, __WINNT__, __CYGWIN32__, __POSIX__, _X86_, i386, __GNUC__
  84. IBM-PC/386 any Mingw32 on WinNT/Win95 GNU _WIN32, __WINNT__, __MINGW32__, _X86_, i386, __GNUC__
  85. IBM-PC/386 any WinNT/Win95 MSVC _WIN32, _M_IX86, _MSC_VER
  86. IBM-PC/386 any WinNT/Win95 Borland 5.0 __WIN32__, _M_IX86, __TURBOC__, __BORLANDC__
  87. IBM-PC/386 any WinNT/Win95 and Cygwin32 GNU _WIN32, __WINNT__, __CYGWIN32__, __POSIX__, __i386__, _X86_, __GNUC__
  88. IBM-PC/586 any BeOS 5 GNU __BEOS__, __INTEL__, __i386__, _X86_, __GNUC__
  89. IBM-PC/586 any HP NUE/ski, Linux GNU unix, linux, __ia64[__], __GNUC__, __LP64__
  90. RM400 Siemens-Nixdorf SINIX-N 5.42 c89 unix, mips, MIPSEB, host_mips, sinix, SNI, _XPG_IV
  91. Acorn Risc PC RISC OS 3.x GNU [__]arm, [__]riscos, __GNUC__
  92. Acorn Risc PC RISC OS 3.x Norcroft [__]arm, [__]riscos
  93. APPLE IIGS Apple ?? ??
  94. For ANSI-C-Compiler: use pre-processors comment5, varbrace
  95. (and maybe gcc-cpp, ccpaux).
  96. this machine: WIN32 or GENERIC_UNIX */
  97. #if (defined(__unix) || defined(__unix__) || defined(_AIX) || defined(sinix) || defined(__MACH__) || defined(__POSIX__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__BEOS__)) && !defined(unix)
  98. #define unix
  99. #endif
  100. #if (defined(_WIN32) && (defined(_MSC_VER) || defined(__MINGW32__))) || (defined(__WIN32__) && defined(__BORLANDC__))
  101. #undef WIN32 /* because of __MINGW32__ */
  102. #define WIN32
  103. #endif
  104. #if !defined(WIN32)
  105. #if defined(unix)
  106. #define GENERIC_UNIX
  107. #else
  108. #error "Unknown machine type -- set machine again!"
  109. #endif
  110. #endif
  111. /* additional specification of the machine: */
  112. #if defined(WIN32)
  113. /* declare availability of typical PC facilities,
  114. like a console with a graphics mode that differs from the text mode,
  115. or a keyboard with function keys F1..F12. */
  116. #define PC386 /* IBMPC-compatible with 80386/80486-processor */
  117. #endif
  118. #ifdef GENERIC_UNIX
  119. #if (defined(sun) && defined(unix) && defined(sun386))
  120. #define SUN386
  121. #endif
  122. #if (defined(unix) && (defined(linux) || defined(__CYGWIN32__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)) && (defined(i386) || defined(__i386__) || defined(__x86_64__) || defined(__amd64__)))
  123. #define PC386
  124. #endif
  125. #if (defined(sun) && defined(unix) && defined(mc68020))
  126. #define SUN3
  127. #endif
  128. #if (defined(sun) && defined(unix) && defined(sparc))
  129. #define SUN4
  130. #endif
  131. #if defined(sparc) || defined(__sparc__)
  132. /* maybe SUN4_29 if only addresses <2^29 are supported */
  133. #endif
  134. #if defined(hp9000s800) || defined(__hp9000s800)
  135. #define HP8XX
  136. #endif
  137. #endif
  138. /* Determine the processor:
  139. MC680X0 == all processors of the Motorola 68000 series
  140. MC680Y0 == all processors of the Motorola 68000 series, starting at MC68020
  141. SPARC == the Sun SPARC processor
  142. HPPA == all processors of the HP Precision Architecture
  143. MIPS == all processors of the MIPS series
  144. M88000 == all processors of the Motorola 88000 series
  145. POWERPC == the IBM RS/6000 and PowerPC processor family
  146. I80386 == all processors of the Intel 8086 series, starting at 80386,
  147. nowadays called IA32
  148. VAX == the VAX processor
  149. ARM == the ARM processor
  150. DECALPHA == the DEC Alpha superchip
  151. IA64 == the Intel IA-64 latecomer chip
  152. AMD64 == the AMD hammer chip
  153. S390 == the IBM S/390 processor */
  154. #if defined(__vax__)
  155. #define VAX
  156. #endif
  157. #if defined(arm) || defined(__arm) || defined(__arm__)
  158. #define ARM
  159. #endif
  160. #ifdef WIN32
  161. #if defined(_M_IX86) || defined(_X86_)
  162. #define I80386
  163. #endif
  164. #endif
  165. #ifdef GENERIC_UNIX
  166. #if defined(m68k) || defined(__m68k__) || defined(mc68000)
  167. #define MC680X0
  168. #endif
  169. #if defined(mc68020) || defined(__mc68020__) || (defined(m68k) && defined(NeXT))
  170. #define MC680X0
  171. #define MC680Y0
  172. #endif
  173. #if defined(i386) || defined(__i386) || defined(__i386__) || defined(_I386)
  174. #define I80386
  175. #endif
  176. #if defined(sparc) || defined(__sparc__)
  177. #define SPARC
  178. #if defined(__sparcv9) || defined(__arch64__)
  179. #define SPARC64
  180. #endif
  181. #endif
  182. #if defined(mips) || defined(__mips) || defined(__mips__)
  183. #define MIPS
  184. #if defined(_MIPS_SZLONG)
  185. #if (_MIPS_SZLONG == 64)
  186. /* We should also check for (_MIPS_SZPTR == 64), but gcc keeps this at 32. */
  187. #define MIPS64
  188. #endif
  189. #endif
  190. #endif
  191. #if defined(HP8XX) || defined(hppa) || defined(__hppa) || defined(__hppa__)
  192. #define HPPA
  193. #endif
  194. #if defined(m88000) || defined(__m88k__)
  195. #define M88000
  196. #endif
  197. #if defined(_IBMR2) || defined(__powerpc) || defined(__ppc) || defined(__ppc__) || defined(__powerpc__)
  198. #define POWERPC
  199. #endif
  200. #ifdef __alpha
  201. #define DECALPHA
  202. #endif
  203. #ifdef __ia64__
  204. #define IA64
  205. #endif
  206. #if defined(__x86_64__) || defined(__amd64__)
  207. #define AMD64
  208. #endif
  209. #ifdef __s390__
  210. #define S390
  211. #endif
  212. #endif
  213. /* Selection of the operating system */
  214. #ifdef WIN32
  215. /* Windows NT, Windows 95 */
  216. #define WIN32_NATIVE /* native NT API, no DOS calls */
  217. #endif
  218. #ifdef GENERIC_UNIX
  219. #define UNIX
  220. #ifdef __linux__
  221. #define UNIX_LINUX /* Linux (Linus Torvalds Unix) */
  222. #endif
  223. #ifdef __GNU__
  224. #define UNIX_HURD /* the GNU system (Hurd + glibc) */
  225. #endif
  226. #ifdef __NetBSD__
  227. #define UNIX_NETBSD
  228. #endif
  229. #if defined(__FreeBSD__) || defined(__DragonFly__)
  230. /* FreeBSD or its fork called DragonFly BSD. */
  231. #define UNIX_FREEBSD
  232. #endif
  233. #ifdef __OpenBSD__
  234. #define UNIX_OPENBSD
  235. #endif
  236. #if defined(hpux) || defined(__hpux)
  237. #define UNIX_HPUX /* HP-UX */
  238. #endif
  239. #if defined(SVR3) || defined(__SVR3) || defined(SVR4) || defined(__SVR4) || defined(SYSTYPE_SVR4) || defined(__SYSTYPE_SVR4) || defined(__svr4__) || defined(USG) || defined(UNIX_HPUX) /* ?? */
  240. #define UNIX_SYSV /* UNIX System V */
  241. #endif
  242. #if defined(UNIX_SYSV) && (defined(sgi) || defined(__sgi))
  243. #define UNIX_IRIX /* Irix */
  244. #if defined(SYSTYPE_SVR4) || defined(__SYSTYPE_SVR4)
  245. #define UNIX_IRIX5 /* Irix 5 */
  246. #endif
  247. #endif
  248. #if defined(MIPS) && (defined(ultrix) || defined(__ultrix))
  249. #define UNIX_DEC_ULTRIX /* DEC's (or IBM's ?) RISC/OS Ultrix on DEC MIPS */
  250. #ifdef __GNUC__
  251. #define UNIX_DEC_ULTRIX_GCCBUG /* work around a bug in GCC 2.3.3 */
  252. #endif
  253. #endif
  254. #if defined(MIPS) && defined(sinix) /* && defined(SNI) */
  255. #define UNIX_SINIX /* Siemens is nix */
  256. #endif
  257. #if defined(USL) || (defined(__svr4__) && defined(I80386) && !defined(__sun))
  258. /* A couple of Unices for 386s (all running under different names)
  259. derive from USL SysV R 4:
  260. 386 UHC UNIX System V release 4
  261. Consensys System V 4.2
  262. Onsite System V 4.2
  263. SINIX-Z
  264. DYNIX/ptx V4.1.3
  265. SunOS 5 */
  266. #define UNIX_SYSV_USL /* Unix System V R 4 by AT&T's subsidiary USL */
  267. #define UNIX_SYSV_UHC_1 /* treat like HPPA && UNIX_HPUX */
  268. #ifdef SNI
  269. #define UNIX_SINIX /* Siemens is nix */
  270. #endif
  271. #endif
  272. #if defined(_SEQUENT_) && !defined(__svr4__)
  273. #define UNIX_SYSV_PTX /* Dynix/ptx v. 2 or 3 */
  274. #endif
  275. #ifdef _AIX
  276. #define UNIX_AIX /* IBM AIX */
  277. #endif
  278. #ifdef DGUX
  279. #define UNIX_DGUX /* Data General DG/UX */
  280. #endif
  281. #ifdef __osf__
  282. #define UNIX_OSF /* OSF/1 */
  283. #endif
  284. #ifdef AUX
  285. #define UNIX_AUX /* Apple A/UX, a spiced-up SVR2 */
  286. #endif
  287. #ifdef NeXT
  288. #define UNIX_NEXTSTEP /* NeXTstep */
  289. #endif
  290. #if defined(__APPLE__) && defined(__MACH__)
  291. #define UNIX_MACOSX /* MacOS X */
  292. #endif
  293. #ifdef AMIX
  294. #define UNIX_AMIX /* Amiga UNIX */
  295. #endif
  296. #ifdef __CYGWIN32__
  297. #define UNIX_CYGWIN32 /* Cygwin32 (UNIXlike on WinNT/Win95) */
  298. #endif
  299. #ifdef __BEOS__
  300. #define UNIX_BEOS /* BeOS (UNIXlike) */
  301. #endif
  302. #endif
  303. %% #ifdef WIN32_NATIVE
  304. %% puts("#define WIN32_NATIVE");
  305. %% #endif
  306. %% #ifdef UNIX
  307. %% puts("#define UNIX");
  308. %% #endif
  309. /* Determine properties of compiler and environment: */
  310. #if defined(UNIX) || defined(__MINGW32__)
  311. #include "config.h" /* configuration generated by configure */
  312. #include "intparam.h" /* integer-type characteristics created by the machine */
  313. #include "floatparam.h" /* floating-point type characteristics */
  314. #elif defined(WIN32) && !defined(__MINGW32__)
  315. #include "version.h" /* defines PACKAGE_* */
  316. #define char_bitsize 8
  317. #define short_bitsize 16
  318. #define int_bitsize 32
  319. #if defined(I80386)
  320. #define long_bitsize 32
  321. #elif defined(DECALPHA)
  322. #define long_bitsize 64
  323. #endif
  324. #if defined(I80386)
  325. #define pointer_bitsize 32
  326. #elif defined(DECALPHA)
  327. #define pointer_bitsize 64
  328. #endif
  329. #define alignment_long 4
  330. #if defined(I80386) || defined(VAX) || defined(ARM) || defined(DECALPHA)
  331. #define short_little_endian
  332. #define long_little_endian
  333. #endif
  334. #define stack_grows_down
  335. #define CODE_ADDRESS_RANGE 0
  336. #define MALLOC_ADDRESS_RANGE 0
  337. #define SHLIB_ADDRESS_RANGE 0
  338. #define STACK_ADDRESS_RANGE ~0UL
  339. #define ICONV_CONST
  340. #else
  341. #error "where is the configuration for your platform?"
  342. #endif
  343. /* A more precise classification of the operating system: */
  344. #if defined(UNIX) && defined(SIGNALBLOCK_BSD) && !defined(SIGNALBLOCK_SYSV)
  345. #define UNIX_BSD /* BSD Unix */
  346. #endif
  347. #if (defined(SUN3) || defined(SUN386) || defined(SUN4)) && defined(HAVE_MMAP) && defined(HAVE_VADVISE)
  348. #define UNIX_SUNOS4 /* Sun OS Version 4 */
  349. #endif
  350. #if (defined(SUN4) || (defined(I80386) && defined(__svr4__) && defined(__sun))) && !defined(HAVE_VADVISE) /* && !defined(HAVE_GETPAGESIZE) */
  351. #define UNIX_SUNOS5 /* Sun OS Version 5.[1-5] (Solaris 2) */
  352. #endif
  353. #if defined(UNIX_MACOSX) && !defined(HAVE_MSYNC)
  354. #define UNIX_RHAPSODY /* MacOS X Server, a.k.a. Rhapsody */
  355. #endif
  356. #if defined(UNIX_MACOSX) && defined(HAVE_MSYNC)
  357. #define UNIX_DARWIN /* MacOS X, a.k.a. Darwin */
  358. #endif
  359. /* Choose the character set: */
  360. #if defined(UNIX) || defined(WIN32)
  361. #define ISOLATIN_CHS /* ISO 8859-1, see isolatin.chs */
  362. /* Most Unix systems today support the ISO Latin-1 character set, in
  363. particular because they have X11 and the X11 fonts are in ISO Latin-1.
  364. Exceptions below.
  365. On Win32, the standard character set is ISO-8859-1. Only the DOS box
  366. displays CP437, but we convert from ISO-8859-1 to CP437 in the
  367. low-level output routine full_write(). */
  368. #endif
  369. #ifdef UNIX_BEOS
  370. /* The default encoding on BeOS is UTF-8, not ISO 8859-1.
  371. If compiling with Unicode support, we use it. Else fall back to ASCII. */
  372. #undef ISOLATIN_CHS
  373. #ifdef UNICODE
  374. #define UTF8_CHS /* UTF-8 */
  375. #endif
  376. #endif
  377. #ifdef HP8XX
  378. #undef ISOLATIN_CHS
  379. #define HPROMAN8_CHS /* HP-Roman8, see hproman8.chs */
  380. /* under X-Term however: #define ISOLATIN_CHS ?? */
  381. #endif
  382. #ifdef UNIX_NEXTSTEP
  383. #undef ISOLATIN_CHS
  384. #define NEXTSTEP_CHS /* NeXTstep, see nextstep.chs */
  385. #endif
  386. #if !(defined(ISOLATIN_CHS) || defined(HPROMAN8_CHS) || defined(NEXTSTEP_CHS))
  387. #define ASCII_CHS /* Default: plain ASCII charset without special chars */
  388. #endif
  389. /* Choose the compiler: */
  390. #if defined(__GNUC__)
  391. #define GNU
  392. #endif
  393. #if defined(__STDC__) || defined(__BORLANDC__) || defined(__cplusplus)
  394. /* ANSI C compilers define __STDC__ (but some define __STDC__=0 !).
  395. Borland C has an ANSI preprocessor and compiler, but fails to define
  396. __STDC__.
  397. HP aCC is an example of a C++ compiler which defines __cplusplus but
  398. not __STDC__. */
  399. #define ANSI
  400. #endif
  401. #if defined(_MSC_VER)
  402. #define MICROSOFT
  403. #endif
  404. #if defined(__BORLANDC__)
  405. #define BORLAND
  406. #endif
  407. #if defined(__INTEL_COMPILER)
  408. #define INTEL
  409. #endif
  410. /* Selection of floating-point capabilities:
  411. FAST_DOUBLE should be defined if there is a floating-point coprocessor
  412. with a 'double'-type IEEE-Floating-Points with 64 Bits.
  413. FAST_FLOAT should be defined if there is a floating-point co-processor
  414. with a 'float'-type IEEE-Floating-Points with 32 Bits,
  415. and a C-Compiler that generates 'float'-operations
  416. instead of 'double'-operations */
  417. #if (float_mant_bits == 24) && (float_rounds == rounds_to_nearest) && float_rounds_correctly && !defined(FLOAT_OVERFLOW_EXCEPTION) && !defined(FLOAT_UNDERFLOW_EXCEPTION) && !defined(FLOAT_INEXACT_EXCEPTION)
  418. #define FAST_FLOAT
  419. #endif
  420. #if (double_mant_bits == 53) && (double_rounds == rounds_to_nearest) && double_rounds_correctly && !defined(DOUBLE_OVERFLOW_EXCEPTION) && !defined(DOUBLE_UNDERFLOW_EXCEPTION) && !defined(DOUBLE_INEXACT_EXCEPTION)
  421. #define FAST_DOUBLE
  422. #endif
  423. #ifdef ARM
  424. /* The processor is little-endian w.r.t. integer types but stores 'double'
  425. floats in big-endian word order! */
  426. #undef FAST_DOUBLE
  427. #endif
  428. #ifdef NO_FAST_DOUBLE
  429. #undef FAST_DOUBLE
  430. #endif
  431. #ifdef NO_FAST_FLOAT
  432. #undef FAST_FLOAT
  433. #endif
  434. /* Selection of the language: */
  435. #ifdef ENGLISH
  436. #undef ENGLISH
  437. #define ENGLISH 1
  438. #define LANGUAGE_STATIC
  439. #endif
  440. /* Selection of the safety-level:
  441. SAFETY=0 : all optimizations are turned on
  442. SAFETY=1 : all optimizations on, but keep STACKCHECKs
  443. SAFETY=2 : only simple assembler-support
  444. SAFETY=3 : no optimizations */
  445. #ifndef SAFETY
  446. #define SAFETY 0
  447. #endif
  448. #if SAFETY >= 3
  449. #define NO_ASM
  450. #define NO_ARI_ASM
  451. #define NO_FAST_DISPATCH
  452. #endif
  453. /* We don't support pre-ANSI-C compilers any more. */
  454. #if !defined(ANSI)
  455. #error "An ANSI C or C++ compiler is required to compile CLISP!"
  456. #endif
  457. /* gcc-2.7.2 has a bug: it interpretes `const' as meaning `not modified by
  458. other parts of the program', and thus miscompiles at least justify_empty_2
  459. and pr_enter_1 in io.d. */
  460. #if defined(GNU) && (__GNUC__ == 2) && (__GNUC_MINOR__ == 7)
  461. #undef const
  462. #define const
  463. #define __const const
  464. /* We define __const to const, not to empty, to avoid warnings on
  465. UNIX_RHAPSODY, which unconditionally defines __const to const when
  466. <sys/cdefs.h> is included via <setjmp.h> below. */
  467. #ifdef MULTITHREAD
  468. #warning "Multithreading will not be efficient because of a workaround to a gcc bug."
  469. #warning "Get a newer version of gcc."
  470. #endif
  471. #endif
  472. /* A property of the processor:
  473. The sequence in which words/long-words are being put into bytes */
  474. #if defined(short_little_endian) || defined(int_little_endian) || defined(long_little_endian)
  475. /* Z80, VAX, I80386, DECALPHA, MIPSEL, IA64, AMD64, ...:
  476. Low Byte is the lowest, High Byte in a higher address */
  477. #if defined(BIG_ENDIAN_P)
  478. #error "Bogus BIG_ENDIAN_P -- set BIG_ENDIAN_P again!"
  479. #endif
  480. #define BIG_ENDIAN_P 0
  481. #endif
  482. #if defined(short_big_endian) || defined(int_big_endian) || defined(long_big_endian)
  483. /* MC680X0, SPARC, HPPA, MIPSEB, M88000, POWERPC, S390, ...:
  484. High Byte is the lowest, Low Byte is a higher adress (easier to read) */
  485. #if defined(BIG_ENDIAN_P)
  486. #error "Bogus BIG_ENDIAN_P -- set BIG_ENDIAN_P again"
  487. #endif
  488. #define BIG_ENDIAN_P 1
  489. #endif
  490. #if !defined(BIG_ENDIAN_P)
  491. #error "Bogus BIG_ENDIAN_P -- set BIG_ENDIAN_P again!"
  492. #endif
  493. %% export_def(BIG_ENDIAN_P);
  494. /* A property of the processor (and C compiler): The alignment of C functions.
  495. (See gcc's machine descriptions, macro FUNCTION_BOUNDARY, for information.) */
  496. #if defined(IA64)
  497. #define C_CODE_ALIGNMENT 16
  498. #define log2_C_CODE_ALIGNMENT 4
  499. #endif
  500. #if defined(DECALPHA)
  501. #define C_CODE_ALIGNMENT 8
  502. #define log2_C_CODE_ALIGNMENT 3
  503. #endif
  504. #if (defined(I80386) && defined(GNU)) || defined(SPARC) || defined(MIPS) || defined(M88000) || defined(POWERPC) || defined(ARM) || defined(AMD64) || defined(S390)
  505. /* When using gcc on i386, this assumes that -malign-functions has not been
  506. used to specify an alignment smaller than 4 bytes. */
  507. #define C_CODE_ALIGNMENT 4
  508. #define log2_C_CODE_ALIGNMENT 2
  509. #endif
  510. #if defined(HPPA)
  511. /* A function pointer on hppa is either
  512. - a code pointer == 0 mod 4, or
  513. - a pointer to a two-word structure (first word: a code pointer,
  514. second word: a value which will be put in register %r19),
  515. incremented by 2, hence == 2 mod 4.
  516. The current compilers only emit the second kind of function pointers,
  517. hence we can assume that all function pointers are == 2 mod 4. */
  518. #define C_CODE_ALIGNMENT 2
  519. #define log2_C_CODE_ALIGNMENT 1
  520. #endif
  521. #if defined(MC680X0)
  522. #define C_CODE_ALIGNMENT 2
  523. #define log2_C_CODE_ALIGNMENT 1
  524. #endif
  525. #if !defined(C_CODE_ALIGNMENT) /* e.g. (defined(I80386) && defined(MICROSOFT)) */
  526. #define C_CODE_ALIGNMENT 1
  527. #define log2_C_CODE_ALIGNMENT 0
  528. #endif
  529. /* Flags for the system's include files. */
  530. #ifdef MULTITHREAD
  531. #if defined(UNIX_GNU) || defined(UNIX_SUNOS5)
  532. #define _REENTRANT
  533. #endif
  534. #if defined(__GNUC__)
  535. #define per_thread __thread
  536. #else
  537. #error "how does your compiler specify per-thread storage class?"
  538. #endif
  539. #else
  540. #define per_thread
  541. #endif
  542. /* Width of object representation:
  543. WIDE means than an object (pointer) occupies 64 bits (instead of 32 bits).
  544. WIDE_HARD means on a 64-bit platform.
  545. WIDE_SOFT means on a 32-bit platform, each object pointer occupies 2 words.
  546. WIDE_AUXI means on a 32-bit platform, each object occupies 2 words, the
  547. pointer and some auxiliary word. */
  548. #if defined(DECALPHA) || defined(MIPS64) || defined(SPARC64) || defined(IA64) || defined(AMD64)
  549. #define WIDE_HARD
  550. #endif
  551. #if defined(WIDE_SOFT_LARGEFIXNUM) && !defined(WIDE_SOFT)
  552. #define WIDE_SOFT
  553. #endif
  554. #if defined(WIDE) && !(defined(WIDE_HARD) || defined(WIDE_SOFT) || defined(WIDE_AUXI))
  555. #define WIDE_SOFT
  556. #endif
  557. #if (defined(WIDE_HARD) || defined(WIDE_SOFT) || defined(WIDE_AUXI)) && !defined(WIDE)
  558. #define WIDE
  559. #endif
  560. /* Now: defined(WIDE) == defined(WIDE_HARD) || defined(WIDE_SOFT) || defined(WIDE_AUXI) */
  561. /* Global register declarations.
  562. Speed benefit: Just putting the STACK into a register, brought 5% of speed
  563. around 1992. Now, with an AMD Athlon CPU from 2000, with good caches, it
  564. still brings 4%.
  565. The declarations must occur before any system include files define any
  566. inline function, which is the case on UNIX_DGUX and UNIX_GNU.
  567. Only GCC supports global register variables. Not Apple's variant of GCC.
  568. And only the C frontend, not the C++ frontend, understands the syntax.
  569. And gcc-3.0 to 3.3.3 has severe bugs with global register variables, see
  570. CLISP bugs 710737 and 723097 and
  571. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=7871
  572. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=10684
  573. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14937
  574. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14938
  575. Likewise, gcc-4.2 has severe bugs with global register variables, see
  576. CLISP bug 1836142 and http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34300
  577. Likewise for gcc-4.3-20080215 and probably future versions of GCC as well.
  578. Therefore for these versions of gcc enable the global register variables
  579. only when USE_GCC_REGISTER_VARIABLES is explicitly defined. */
  580. #if defined(GNU) && !(__APPLE_CC__ > 1) && !defined(__cplusplus) && !(__GNUC__ == 3 && (__GNUC_MINOR__ < 3 || (__GNUC_MINOR__ == 3 && __GNUC_PATCHLEVEL__ < 4))) && !(((__GNUC__ == 4 && __GNUC_MINOR__ >= 2) || __GNUC__ > 4) && !defined(USE_GCC_REGISTER_VARIABLES)) && !defined(MULTITHREAD) && (SAFETY < 2) && !defined(USE_JITC)
  581. /* Overview of use of registers in gcc terminology:
  582. fixed: mentioned in FIXED_REGISTERS
  583. used: mentioned in CALL_USED_REGISTERS but not FIXED_REGISTERS
  584. (i.e. caller-saved)
  585. save: otherwise (i.e. call-preserved, callee-saved)
  586. STACK mv_count value1 back_trace
  587. MC680X0 used
  588. I80386 save
  589. SPARC (gcc2) fixed fixed fixed used
  590. MIPS
  591. HPPA save save save save
  592. M88000 save save save
  593. ARM save
  594. DECALPHA save save save
  595. IA64
  596. AMD64
  597. S390 save
  598. Special notes:
  599. - gcc3/Sparc (Linux & Solaris) handles registers differently from gcc2. FIXME
  600. - If STACK is in a "used"/"save" register, it needs to be saved into
  601. saved_STACK upon begin_call(), so that asynchronous interrupts will
  602. be able to restore it.
  603. - All of the "used" registers need to be backed up upon begin_call()
  604. and restored during end_call().
  605. - All of the "save" registers need to be backed up upon begin_callback()
  606. and restored during end_callback().
  607. - When the interpreter does a longjmp(), the registers STACK, mv_count,
  608. value1 may need to be temporarily saved. This is highly machine
  609. dependent and is indicated by the NEED_temp_xxxx macros.
  610. * Register for STACK. */
  611. #if defined(MC680X0)
  612. #define STACK_register "a4" /* highest address register after sp=A7,fp=A6/A5 */
  613. #endif
  614. #if defined(I80386) && !defined(UNIX_BEOS) && !defined(DYNAMIC_MODULES)
  615. /* On BeOS, everything is compiled as PIC, hence %ebx is already booked.
  616. If DYNAMIC_MODULES is defined, external modules are compiled as PIC,
  617. which is why %ebx is already in use. */
  618. #if (__GNUC__ >= 2) /* The register names have changed */
  619. #define STACK_register "%ebx" /* one of the call-saved registers without special hardware commands */
  620. #else
  621. #define STACK_register "bx"
  622. #endif
  623. #endif
  624. #if defined(SPARC)
  625. #define STACK_register "%g5" /* a global register */
  626. #endif
  627. #if defined(HPPA) && (__GNUC__*100 + __GNUC_MINOR__ >= 2*100+7) /* gcc versions earlier than 2.7 had bugs */
  628. #define STACK_register "%r10" /* one of the general registers %r5..%r18 */
  629. #endif
  630. #if defined(M88000)
  631. #define STACK_register "%r14" /* one of the general registers %r14..%r25 */
  632. #endif
  633. #if defined(ARM)
  634. #define STACK_register "%r8" /* one of the general registers %r4..%r8 */
  635. #endif
  636. #if defined(DECALPHA)
  637. #define STACK_register "$9" /* one of the general registers $9..$14 */
  638. #endif
  639. #if defined(S390) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
  640. /* global register assignment did not work on s390 until gcc 3.1 */
  641. #define STACK_register "9" /* one of the general registers %r8..%r9 */
  642. #endif
  643. /* What about NEED_temp_STACK ?? Needed if STACK is in a "used" register??
  644. Register for mv_count. */
  645. #if defined(SPARC)
  646. #define mv_count_register "%g6"
  647. #if defined(UNIX_NETBSD)
  648. #define NEED_temp_mv_count
  649. #endif
  650. #endif
  651. #if defined(HPPA)
  652. #define mv_count_register "%r11" /* one of the general registers %r5..%r18 */
  653. #define NEED_temp_mv_count
  654. #endif
  655. #if defined(M88000)
  656. #define mv_count_register "%r15" /* one of the general registers %r14..%r25 */
  657. #define NEED_temp_mv_count
  658. #endif
  659. #if defined(DECALPHA)
  660. #define mv_count_register "$10" /* one of the general registers $9..$14 */
  661. #define NEED_temp_mv_count
  662. #endif
  663. /* Register for value1. */
  664. #if !(defined(WIDE) && !defined(WIDE_HARD))
  665. #if defined(SPARC)
  666. #define value1_register "%g7"
  667. #if defined(UNIX_NETBSD)
  668. #define NEED_temp_value1
  669. #endif
  670. #endif
  671. #if defined(HPPA)
  672. #define value1_register "%r12" /* one of the general registers %r5..%r18 */
  673. #define NEED_temp_value1
  674. #endif
  675. #if defined(M88000)
  676. #define value1_register "%r16" /* one of the general registers %r14..%r25 */
  677. #define NEED_temp_value1
  678. #endif
  679. #if defined(DECALPHA)
  680. #define value1_register "$11" /* one of the general registers $9..$14 */
  681. #define NEED_temp_value1
  682. #endif
  683. #endif
  684. /* Register for back_trace. */
  685. #if !(defined(WIDE) && !defined(WIDE_HARD))
  686. #if defined(SPARC)
  687. #define back_trace_register "%g4" /* a global register */
  688. /* %g4 seems to be a scratch-register as of lately with gcc 2.3
  689. This causes problems with libc.so.1.6.1 (and higher) (in getwd())
  690. That's why HAVE_SAVED_back_trace has been defined above. */
  691. #endif
  692. #if defined(HPPA)
  693. #define back_trace_register "%r13" /* one of the general registers %r5..%r18 */
  694. #endif
  695. #endif
  696. /* Declare the registers now (before any system include file which could
  697. contain some inline functions). */
  698. #ifdef STACK_register
  699. register long STACK_reg __asm__(STACK_register);
  700. #endif
  701. #ifdef mv_count_register
  702. register long mv_count_reg __asm__(mv_count_register);
  703. #endif
  704. #ifdef value1_register
  705. register long value1_reg __asm__(value1_register);
  706. #endif
  707. #ifdef back_trace_register
  708. register long back_trace_reg __asm__(back_trace_register);
  709. #endif
  710. /* Saving "save" registers. */
  711. #if (defined(I80386) || defined(HPPA) || defined(M88000) || defined(ARM) || defined(DECALPHA) || defined(S390)) && (defined(STACK_register) || defined(mv_count_register) || defined(value1_register) || defined(back_trace_register))
  712. #define HAVE_SAVED_REGISTERS
  713. struct registers {
  714. #ifdef STACK_register
  715. long STACK_register_contents;
  716. #endif
  717. #ifdef mv_count_register
  718. long mv_count_register_contents;
  719. #endif
  720. #ifdef value1_register
  721. long value1_register_contents;
  722. #endif
  723. #ifdef back_trace_register
  724. long back_trace_register_contents;
  725. #endif
  726. };
  727. extern per_thread struct registers * callback_saved_registers;
  728. #ifdef STACK_register
  729. #define SAVE_STACK_register(registers) \
  730. registers->STACK_register_contents = STACK_reg
  731. #define RESTORE_STACK_register(registers) \
  732. STACK_reg = registers->STACK_register_contents
  733. #else
  734. #define SAVE_STACK_register(registers)
  735. #define RESTORE_STACK_register(registers)
  736. #endif
  737. #ifdef mv_count_register
  738. #define SAVE_mv_count_register(registers) \
  739. registers->mv_count_register_contents = mv_count_reg
  740. #define RESTORE_mv_count_register(registers) \
  741. mv_count_reg = registers->mv_count_register_contents
  742. #else
  743. #define SAVE_mv_count_register(registers)
  744. #define RESTORE_mv_count_register(registers)
  745. #endif
  746. #ifdef value1_register
  747. #define SAVE_value1_register(registers) \
  748. registers->value1_register_contents = value1_reg
  749. #define RESTORE_value1_register(registers) \
  750. value1_reg = registers->value1_register_contents
  751. #else
  752. #define SAVE_value1_register(registers)
  753. #define RESTORE_value1_register(registers)
  754. #endif
  755. #ifdef back_trace_register
  756. #define SAVE_back_trace_register(registers) \
  757. registers->back_trace_register_contents = back_trace_reg
  758. #define RESTORE_back_trace_register(registers) \
  759. back_trace_reg = registers->back_trace_register_contents
  760. #else
  761. #define SAVE_back_trace_register(registers)
  762. #define RESTORE_back_trace_register(registers)
  763. #endif
  764. #define SAVE_REGISTERS(inner_statement) \
  765. do { \
  766. var struct registers * registers = alloca(sizeof(struct registers)); \
  767. SAVE_STACK_register(registers); \
  768. SAVE_mv_count_register(registers); \
  769. SAVE_value1_register(registers); \
  770. SAVE_back_trace_register(registers); \
  771. inner_statement; \
  772. { var gcv_object_t* top_of_frame = STACK; \
  773. pushSTACK(fake_gcv_object((aint)callback_saved_registers)); \
  774. finish_frame(CALLBACK); \
  775. } \
  776. callback_saved_registers = registers; \
  777. } while(0)
  778. #define RESTORE_REGISTERS(inner_statement) \
  779. do { \
  780. var struct registers * registers = callback_saved_registers; \
  781. if (!(framecode(STACK_0) == CALLBACK_frame_info)) abort(); \
  782. callback_saved_registers = (struct registers *)(aint)as_oint(STACK_1);\
  783. skipSTACK(2); \
  784. inner_statement; \
  785. RESTORE_STACK_register(registers); \
  786. RESTORE_mv_count_register(registers); \
  787. RESTORE_value1_register(registers); \
  788. RESTORE_back_trace_register(registers); \
  789. } while(0)
  790. #endif
  791. /* Saving the STACK (for asynchronous interrupts).
  792. If STACK is a global variable or lies in a register which is left
  793. untouched by operating system and library (this is the case on SUN4),
  794. we don't need to worry about it. */
  795. #if defined(STACK_register) && !defined(SUN4)
  796. #define HAVE_SAVED_STACK
  797. #endif
  798. /* Saving "used" registers. */
  799. #if defined(mv_count_register) && 0
  800. #define HAVE_SAVED_mv_count
  801. #endif
  802. #if defined(value1_register) && 0
  803. #define HAVE_SAVED_value1
  804. #endif
  805. #if defined(back_trace_register) && defined(SPARC)
  806. #define HAVE_SAVED_back_trace
  807. #endif
  808. #endif
  809. #ifndef HAVE_SAVED_REGISTERS
  810. #define SAVE_REGISTERS(inner_statement)
  811. #define RESTORE_REGISTERS(inner_statement)
  812. #endif
  813. %% #ifdef HAVE_SAVED_REGISTERS
  814. %% puts("#ifndef IN_MODULE_CC");
  815. %% #ifdef STACK_register
  816. %% printf("register long STACK_reg __asm__(\"%s\");\n",STACK_register);
  817. %% #endif
  818. %% #ifdef mv_count_register
  819. %% printf("register long mv_count_reg __asm__(\"%s\");\n",mv_count_register);
  820. %% #endif
  821. %% #ifdef value1_register
  822. %% printf("register long value1_reg __asm__(\"%s\");\n",value1_register);
  823. %% #endif
  824. %% #ifdef back_trace_register
  825. %% printf("register long back_trace_reg __asm__(\"%s\");\n",back_trace_register);
  826. %% #endif
  827. %% printf("struct registers { ");
  828. %% #ifdef STACK_register
  829. %% printf("long STACK_register_contents; ");
  830. %% #endif
  831. %% #ifdef mv_count_register
  832. %% printf("long mv_count_register_contents; ");
  833. %% #endif
  834. %% #ifdef value1_register
  835. %% printf("long value1_register_contents; ");
  836. %% #endif
  837. %% #ifdef back_trace_register
  838. %% printf("long back_trace_register_contents; ");
  839. %% #endif
  840. %% puts("};");
  841. %% puts("extern struct registers * callback_saved_registers;");
  842. %% puts("#endif");
  843. %% #endif
  844. #define VALUES_IF(cond) \
  845. do { value1 = (cond) ? T : NIL; mv_count = 1; } while (0)
  846. %% export_def(VALUES_IF(C));
  847. #define VALUES0 \
  848. do { value1 = NIL; mv_count = 0; } while (0)
  849. %% export_def(VALUES0);
  850. #define VALUES1(A) \
  851. do { value1 = (A); mv_count = 1; } while (0)
  852. %% export_def(VALUES1(A));
  853. #define VALUES2(A,B) \
  854. do { value1 = (A); value2 = (B); mv_count = 2; } while (0)
  855. %% export_def(VALUES2(A,B));
  856. #define VALUES3(A,B,C) \
  857. do { value1 = (A); value2 = (B); value3 = (C); mv_count = 3; } while (0)
  858. %% export_def(VALUES3(A,B,C));
  859. /* ###################### Macros for C #################### */
  860. #if !defined(return_void)
  861. /* To return a type of value void: return_void(...); */
  862. #ifdef GNU
  863. #define return_void return /* 'return void;' is admissible */
  864. #else
  865. /* In general it is not legal to return `void' values. */
  866. #define return_void /* Don't use 'return' for expressions of type 'void'. */
  867. #endif
  868. #endif
  869. #if defined(GNU) && defined(__GNUG__)
  870. /* Although legal, g++ warns about 'return void;'. Shut up the warning. */
  871. #undef return_void
  872. #define return_void
  873. #endif
  874. #if !defined(GNU) && !defined(inline)
  875. #define inline /* inline foo() {...} --> foo() {...} */
  876. #endif
  877. %% puts("#if !defined(__GNUC__) && !defined(inline)");
  878. %% puts("#define inline");
  879. %% puts("#endif");
  880. /* Definitions for C++-Compilers: */
  881. #ifdef __cplusplus
  882. #define BEGIN_DECLS extern "C" {
  883. #define END_DECLS }
  884. #else
  885. #define BEGIN_DECLS
  886. #define END_DECLS
  887. #endif
  888. %% export_def(BEGIN_DECLS);
  889. %% export_def(END_DECLS);
  890. /* Empty macro-arguments:
  891. Some compilers (ie. cc under HP-UX) seem to interpret a macro call
  892. foo(arg1,...,argn,) as equivalent to foo(arg1,...,argn), which will
  893. yield an error. _EMA_ stands for "empty macro argument".
  894. It will be inserted by CC_NEED_DEEMA,
  895. each time between comma and closing parentheses.
  896. It is also needed when potentially empty arguments
  897. are returned to other macros */
  898. #define _EMA_
  899. /* Concatenation of two macro-expanded tokens:
  900. Example:
  901. #undef x
  902. #define y 16
  903. CONCAT(x,y) ==> 'x16' (not 'xy' !) */
  904. #define CONCAT_(xxx,yyy) xxx##yyy
  905. #define CONCAT3_(aaa,bbb,ccc) aaa##bbb##ccc
  906. #define CONCAT4_(aaa,bbb,ccc,ddd) aaa##bbb##ccc##ddd
  907. #define CONCAT5_(aaa,bbb,ccc,ddd,eee) aaa##bbb##ccc##ddd##eee
  908. #define CONCAT6_(aaa,bbb,ccc,ddd,eee,fff) aaa##bbb##ccc##ddd##eee##fff
  909. #define CONCAT7_(aaa,bbb,ccc,ddd,eee,fff,ggg) aaa##bbb##ccc##ddd##eee##fff##ggg
  910. #define CONCAT(xxx,yyy) CONCAT_(xxx,yyy)
  911. #define CONCAT3(aaa,bbb,ccc) CONCAT3_(aaa,bbb,ccc)
  912. #define CONCAT4(aaa,bbb,ccc,ddd) CONCAT4_(aaa,bbb,ccc,ddd)
  913. #define CONCAT5(aaa,bbb,ccc,ddd,eee) CONCAT5_(aaa,bbb,ccc,ddd,eee)
  914. #define CONCAT6(aaa,bbb,ccc,ddd,eee,fff) CONCAT6_(aaa,bbb,ccc,ddd,eee,fff)
  915. #define CONCAT7(aaa,bbb,ccc,ddd,eee,fff,ggg) CONCAT7_(aaa,bbb,ccc,ddd,eee,fff,ggg)
  916. %% puts("#define CONCAT_(xxx,yyy) xxx##yyy");
  917. %% puts("#define CONCAT3_(aaa,bbb,ccc) aaa##bbb##ccc");
  918. %% #if notused
  919. %% puts("#define CONCAT4_(aaa,bbb,ccc,ddd) aaa##bbb##ccc##ddd");
  920. %% puts("#define CONCAT5_(aaa,bbb,ccc,ddd,eee) aaa##bbb##ccc##ddd##eee");
  921. %% #endif
  922. %% puts("#define CONCAT(xxx,yyy) CONCAT_(xxx,yyy)");
  923. %% puts("#define CONCAT3(aaa,bbb,ccc) CONCAT3_(aaa,bbb,ccc)");
  924. %% #if notused
  925. %% puts("#define CONCAT4(aaa,bbb,ccc,ddd) CONCAT4_(aaa,bbb,ccc,ddd)");
  926. %% puts("#define CONCAT5(aaa,bbb,ccc,ddd,eee) CONCAT5_(aaa,bbb,ccc,ddd,eee)");
  927. %% #endif
  928. /* Generation of goto-tag macros:
  929. GENTAG(end) ==> end116
  930. This allows a macro defining marks to be used more than once per function
  931. but still only once per source-line. */
  932. #define GENTAG(xxx) CONCAT(xxx,__LINE__)
  933. /* Converting tokens to strings:
  934. STRING(token) ==> "token" */
  935. #define STRING(token) #token
  936. #define STRINGIFY(token) STRING(token)
  937. %% puts("#define STRING(token) #token");
  938. %% puts("#define STRINGIFY(token) STRING(token)");
  939. /* Storage-Class-Specifier in top-level-declarations:
  940. for variables:
  941. global globally visible variable
  942. local variable that is only visible in the file (local)
  943. extern pointer to a variable that's defined externally
  944. for functions:
  945. global globally visible function
  946. local function that is only visible in the file (local)
  947. extern pointer to a function that's defined externally
  948. extern_C pointer to a c-function that's defined externally
  949. nonreturning function that will never return
  950. maygc function that can trigger GC */
  951. #define global
  952. #define local static
  953. /* #define extern extern */
  954. #ifdef __cplusplus
  955. #define extern_C extern "C"
  956. #else
  957. #define extern_C extern
  958. #endif
  959. /* Declaration of a function that will never return (nonreturning function)
  960. nonreturning_function(extern,abort,(void)); == extern void abort (void); */
  961. #if defined(GNU) && !(__APPLE_CC__ > 1)
  962. #if (__GNUC__ >= 3) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 7))
  963. /* Note:
  964. storclass __attribute__((__noreturn__)) void funname arguments
  965. works in gcc 2.95 or newer, and in g++ 2.7.2 or newer.
  966. storclass void __attribute__((__noreturn__)) funname arguments
  967. works in gcc 2.7.2 or newer and in g++ 2.7.2 or newer.
  968. storclass void funname arguments __attribute__((__noreturn__))
  969. works in gcc 2.7.2 or newer and in g++ 2.7.2 or newer, but
  970. only when followed by a semicolon, not in a function definition. */
  971. #define nonreturning_function(storclass,funname,arguments) \
  972. storclass void __attribute__((__noreturn__)) funname arguments
  973. #else
  974. #define nonreturning_function(storclass,funname,arguments) \
  975. storclass void funname arguments
  976. #endif
  977. #elif defined(MICROSOFT)
  978. #define nonreturning_function(storclass,funname,arguments) \
  979. __declspec(noreturn) storclass void funname arguments
  980. #else
  981. #define nonreturning_function(storclass,funname,arguments) \
  982. storclass void funname arguments
  983. #endif
  984. %% export_def(nonreturning_function(storclass,funname,arguments));
  985. /* A function that can trigger GC is declared either as
  986. - maygc, if (1) all callers must assume the worst case: that it triggers GC,
  987. and (2) the function uses only the 'object's passed as arguments and
  988. on the STACK, but no objects stored in other non-GCsafe locations.
  989. - /*maygc*/ otherwise. If (1) is not fulfilled, the functions begins
  990. with an appropriate GCTRIGGER_IF statement. If (2) is not
  991. fulfilled, the GCTRIGGER call needs to mention all other
  992. non-GCsafe locations whose values are used by the function,
  993. such as 'value1' or 'mv_space'. */
  994. #define maygc
  995. /* Storage-Class-Specifier in declarations at the beginning of a block:
  996. var will lead a variable declaration
  997. used by utils/varbrace to allow declarations mixed with other statements */
  998. #define var
  999. /* Ignore C++ keyword. */
  1000. #define export export_sym
  1001. /* Swap the contents of two variables: swap(register int, x1, x2); */
  1002. #define swap(swap_type,swap_var1,swap_var2) \
  1003. do { var swap_type swap_temp; \
  1004. swap_temp = swap_var1; swap_var1 = swap_var2; swap_var2 = swap_temp; \
  1005. } while(0)
  1006. /* Marking a program line that may not be reached: NOTREACHED; */
  1007. #define NOTREACHED error_notreached(__FILE__,__LINE__)
  1008. %% puts("#define NOTREACHED error_notreached(__FILE__,__LINE__)");
  1009. /* Asserting an arithmetic expression: ASSERT(expr); */
  1010. #define ASSERT(expr) do { if (!(expr)) NOTREACHED; } while(0)
  1011. %% puts("#define ASSERT(expr) do { if (!(expr)) NOTREACHED; } while(0)");
  1012. /* alloca() */
  1013. #ifdef GNU
  1014. #define alloca __builtin_alloca
  1015. #elif defined(MICROSOFT)
  1016. #include <malloc.h>
  1017. #define alloca _alloca
  1018. #elif defined(HAVE_ALLOCA_H)
  1019. #include <alloca.h>
  1020. #ifndef alloca /* Manche definieren 'alloca' als Macro... */
  1021. #if !(defined(UNIX_OSF) || defined(UNIX_DEC_ULTRIX))
  1022. /* OSF/1 V3 declares `alloca' as returning char*, but in OSF/1 V4
  1023. it returns void*. I don't know how to distinguish the two. */
  1024. extern_C void* alloca (int size); /* see MALLOC(3V) */
  1025. #endif
  1026. #endif
  1027. #elif defined(_AIX)
  1028. #pragma alloca /* AIX requires this to be the first thing in the file. */
  1029. #elif defined(BORLAND)
  1030. #include <malloc.h> /* defines 'alloca' as macro */
  1031. #elif !defined(NO_ALLOCA)
  1032. extern_C void* alloca (int size); /* see MALLOC(3V) */
  1033. #endif
  1034. %% #ifdef GNU
  1035. %% emit_define("alloca","__builtin_alloca");
  1036. %% #elif defined(MICROSOFT)
  1037. %% puts("#include <malloc.h>");
  1038. %% emit_define("alloca","_alloca");
  1039. %% #elif defined(HAVE_ALLOCA_H)
  1040. %% puts("#include <alloca.h>");
  1041. %% #ifndef alloca
  1042. %% #if !(defined(UNIX_OSF) || defined(UNIX_DEC_ULTRIX))
  1043. %% puts("extern void* alloca (int size);");
  1044. %% #endif
  1045. %% #endif
  1046. %% #elif defined(_AIX)
  1047. %% puts("#pragma alloca");
  1048. %% #elif !defined(NO_ALLOCA)
  1049. %% puts("extern void* alloca (int size);");
  1050. %% #endif
  1051. #define MALLOC(size,type) (type*)malloc((size)*sizeof(type))
  1052. /* Literal constants of 64-bit integer types
  1053. LL(nnnn) = nnnn parsed as a sint64
  1054. ULL(nnnn) = nnnn parsed as a uint64 */
  1055. #if defined(HAVE_LONG_LONG_INT)
  1056. #define LL(nnnn) nnnn##LL
  1057. #define ULL(nnnn) nnnn##ULL
  1058. #elif defined(MICROSOFT)
  1059. #define LL(nnnn) nnnn##i64
  1060. #define ULL(nnnn) nnnn##ui64
  1061. #endif
  1062. %% #if defined(HAVE_LONG_LONG_INT)
  1063. %% puts("#define LL(nnnn) nnnn##LL");
  1064. %% puts("#define ULL(nnnn) nnnn##ULL");
  1065. %% #elif defined(MICROSOFT)
  1066. %% puts("#define LL(nnnn) nnnn##i64");
  1067. %% puts("#define ULL(nnnn) nnnn##ui64");
  1068. %% #endif
  1069. /* Synonyms for Byte, Word, Longword:
  1070. SBYTE = signed 8 bit integer
  1071. UBYTE = unsigned 8 bit int
  1072. SWORD = signed 16 bit int
  1073. UWORD = unsigned 16 bit int
  1074. SLONG = signed 32 bit int
  1075. ULONG = unsigned 32 bit int
  1076. On the other hand, "char" is only used as an element of a string
  1077. You never really compute with a "char"; it might depend on
  1078. __CHAR_UNSIGNED___! */
  1079. #if (char_bitsize==8)
  1080. #ifdef __CHAR_UNSIGNED__
  1081. typedef signed char SBYTE;
  1082. #else
  1083. typedef char SBYTE;
  1084. #endif
  1085. typedef unsigned char UBYTE;
  1086. #else
  1087. #error "No 8 bit integer type? -- Which Interger-type has 8 Bit?"
  1088. #endif
  1089. #if (short_bitsize==16)
  1090. typedef short SWORD;
  1091. typedef unsigned short UWORD;
  1092. #else
  1093. #error "No 16 bit integer type? -- Which Integer-type has 16 Bit?"
  1094. #endif
  1095. #if (long_bitsize==32)
  1096. typedef long SLONG;
  1097. typedef unsigned long ULONG;
  1098. #elif (int_bitsize==32)
  1099. typedef int SLONG;
  1100. typedef unsigned int ULONG;
  1101. #else
  1102. #error "No 32 bit integer type? -- Which Integer-type has 32 Bit?"
  1103. #endif
  1104. #if (long_bitsize==64)
  1105. typedef long SLONGLONG;
  1106. typedef unsigned long ULONGLONG;
  1107. #ifndef HAVE_LONG_LONG_INT
  1108. #define HAVE_LONG_LONG_INT
  1109. #endif
  1110. #elif defined(MICROSOFT)
  1111. typedef __int64 SLONGLONG;
  1112. typedef unsigned __int64 ULONGLONG;
  1113. #define HAVE_LONG_LONG_INT
  1114. #elif defined(HAVE_LONG_LONG_INT)
  1115. #if defined(long_long_bitsize) && (long_long_bitsize==64)
  1116. typedef long long SLONGLONG;
  1117. typedef unsigned long long ULONGLONG;
  1118. #else /* useless type */
  1119. #undef HAVE_LONG_LONG_INT
  1120. #endif
  1121. #endif
  1122. #if defined(WIDE) && !defined(HAVE_LONG_LONG_INT)
  1123. #error "No 64 bit integer type? -- Which Integer-type has 64 Bit?"
  1124. #endif
  1125. %% #ifdef __CHAR_UNSIGNED__
  1126. %% emit_typedef("signed char","SBYTE");
  1127. %% #else
  1128. %% emit_typedef("char","SBYTE");
  1129. %% #endif
  1130. %% emit_typedef("unsigned char","UBYTE");
  1131. %% emit_typedef("short","SWORD");
  1132. %% emit_typedef("unsigned short","UWORD");
  1133. %% #if (long_bitsize==32)
  1134. %% emit_typedef("long","SLONG");
  1135. %% emit_typedef("unsigned long","ULONG");
  1136. %% #elif (int_bitsize==32)
  1137. %% emit_typedef("int","SLONG");
  1138. %% emit_typedef("unsigned int","ULONG");
  1139. %% #endif
  1140. %% #if (long_bitsize==64)
  1141. %% emit_typedef("long","SLONGLONG");
  1142. %% emit_typedef("unsigned long","ULONGLONG");
  1143. %% #elif defined(MICROSOFT)
  1144. %% emit_typedef("__int64","SLONGLONG");
  1145. %% emit_typedef("unsigned __int64","ULONGLONG");
  1146. %% #elif defined(HAVE_LONG_LONG_INT)
  1147. %% emit_typedef("long long","SLONGLONG");
  1148. %% emit_typedef("unsigned long long","ULONGLONG");
  1149. %% #endif
  1150. #include <stdbool.h> /* boolean values */
  1151. %% #ifdef HAVE_STDBOOL_H
  1152. %% puts("#include <stdbool.h>");
  1153. %% #else
  1154. %% print_file("stdbool.h");
  1155. %% #endif
  1156. /* Type for signed values, results of comparisons, tertiary enums
  1157. with values +1, 0, -1 */
  1158. typedef signed int signean;
  1159. #define signean_plus 1 /* +1 */
  1160. #define signean_null 0 /* 0 */
  1161. #define signean_minus -1 /* -1 */
  1162. /* Null pointers */
  1163. #ifdef __cplusplus
  1164. #undef NULL
  1165. #define NULL 0
  1166. #elif !(defined(INTEL) || defined(_AIX))
  1167. #undef NULL
  1168. #define NULL ((void*) 0L)
  1169. #endif
  1170. %% puts("#undef NULL");
  1171. %% export_def(NULL);
  1172. #include <stdio.h> /* libc i/o */
  1173. /* A more precise classification of the operating system:
  1174. (This test works only after at least one system header has been included.) */
  1175. #if (__GLIBC__ >= 2)
  1176. #define UNIX_GNU /* glibc2 (may be UNIX_LINUX, UNIX_HURD or UNIX_FREEBSD) */
  1177. #endif
  1178. /* Determine the offset of a component 'ident' in a struct of the type 'type':
  1179. See 0 as pointer to 'type', put a struct 'type' there and determine the
  1180. address of its component 'ident' and return it as number: */
  1181. #if defined(HAVE_OFFSETOF) || defined(__MINGW32__) || (defined(BORLAND) && defined(WIN32)) || defined(MICROSOFT)
  1182. #include <stddef.h>
  1183. #else
  1184. #undef offsetof
  1185. #define offsetof(type,ident) ((ULONG)&(((type*)0)->ident))
  1186. #endif
  1187. /* Determine the offset of an array 'ident' in a struct of the type 'type': */
  1188. #if defined(__cplusplus) || defined(MICROSOFT)
  1189. #define offsetofa(type,ident) offsetof(type,ident)
  1190. #else
  1191. #define offsetofa(type,ident) offsetof(type,ident[0])
  1192. #endif
  1193. /* alignof(type) is a constant expression, returning the alignment of type. */
  1194. #ifdef __cplusplus
  1195. #ifdef GNU
  1196. #define alignof(type) __alignof__(type)
  1197. #else
  1198. template <class type> struct alignof_helper { char slot1; type slot2; };
  1199. #define alignof(type) offsetof(alignof_helper<type>, slot2)
  1200. #endif
  1201. #else
  1202. #define alignof(type) offsetof(struct { char slot1; type slot2; }, slot2)
  1203. #endif
  1204. /* Unspecified length of arrays in structures:
  1205. struct { ...; ...; type x[unspecified]; }
  1206. Instead of sizeof(..) you'll always have to use offsetof(..,x). */
  1207. #if defined(GNU) || defined(MICROSOFT) /* GNU & MS C are able to work with arrays of length 0 */
  1208. #define unspecified 0
  1209. #elif 0
  1210. /* Usually one would omit the array's limit */
  1211. #define unspecified
  1212. #else
  1213. /* However, HP-UX- and IRIX-compilers will only work with this: */
  1214. #define unspecified 1
  1215. #endif
  1216. %% export_def(unspecified);
  1217. /* Pointer arithmetics: add a given offset (measured in bytes)
  1218. to a pointer. */
  1219. #if defined(GNU) || (pointer_bitsize > 32)
  1220. /* Essential for GNU-C for initialization of static-variables
  1221. (must be a bug in 'c-typeck.c' in 'initializer_constant_valid_p'):
  1222. The only correct way, if sizeof(ULONG) < sizeof(void*): */
  1223. #define pointerplus(pointer,offset) ((UBYTE*)(pointer)+(offset))
  1224. #else
  1225. /* Cheap way: */
  1226. #define pointerplus(pointer,offset) ((void*)((ULONG)(pointer)+(offset)))
  1227. #endif
  1228. %% export_def(pointerplus(pointer,offset));
  1229. /* Bit number n (0<=n<32)
  1230. This is an unsigned expression, in order to avoid signed integer overflow
  1231. in expressions like bit(31) or bit(31)-1. */
  1232. #define bit(n) (1UL<<(n))
  1233. /* Bit number n (0<n<=32) mod 2^32 */
  1234. #define bitm(n) (2UL<<((n)-1))
  1235. /* Bit-test of bit n in x, n constant, x an oint: */
  1236. #if !defined(SPARC)
  1237. #define bit_test(x,n) ((x) & bit(n))
  1238. #else
  1239. /* On SPARC-processors, long constants are slower than shifts. */
  1240. #if defined(SPARC64)
  1241. #if !defined(GNU)
  1242. #define bit_test(x,n) \
  1243. ((n)<12 ? ((x) & bit(n)) : ((sint64)((uint64)(x) << (63-(n))) < 0))
  1244. #else /* the GNU-compiler will optimize boolean expressions better this way: */
  1245. #define bit_test(x,n) \
  1246. ( ( ((n)<12) && ((x) & bit(n)) ) \
  1247. || ( ((n)>=12) && ((sint64)((uint64)(x) << (63-(n))) < 0) ) \
  1248. )
  1249. #endif
  1250. #else
  1251. #if !defined(GNU)
  1252. #define bit_test(x,n) \
  1253. ((n)<12 ? ((x) & bit(n)) : ((sint32)((uint32)(x) << (31-(n))) < 0))
  1254. #else /* the GNU-compiler will optimize boolean expressions better this way: */
  1255. #define bit_test(x,n) \
  1256. ( ( ((n)<12) && ((x) & bit(n)) ) \
  1257. || ( ((n)>=12) && ((sint32)((uint32)(x) << (31-(n))) < 0) ) \
  1258. )
  1259. #endif
  1260. #endif
  1261. #endif
  1262. /* Minus bit number n (0<=n<32) */
  1263. #define minus_bit(n) (-1L<<(n))
  1264. /* Minus bit number n (0<n<=32) mod 2^32 */
  1265. #define minus_bitm(n) (-2L<<((n)-1))
  1266. %% export_def(bit(n));
  1267. %% #if notused
  1268. %% export_def(bitm(n));
  1269. %% #endif
  1270. %% export_def(bit_test(x,n));
  1271. %% export_def(minus_bit(n));
  1272. %% #if notused
  1273. %% export_def(minus_bitm(n));
  1274. %% #endif
  1275. /* floor(a,b) yields for a>=0, b>0 floor(a/b).
  1276. b should be a 'constant expression'. */
  1277. #define floor(a_from_floor,b_from_floor) ((a_from_floor) / (b_from_floor))
  1278. %% /* FIXME: Difference between lispbibl.d and clisp.h */
  1279. %% puts("#define ifloor(a_from_floor,b_from_floor) ((a_from_floor) / (b_from_floor))");
  1280. /* ceiling(a,b) yields for a>=0, b>0 ceiling(a/b) = floor((a+b-1)/b).
  1281. b should be a 'constant expression'. */
  1282. #define ceiling(a_from_ceiling,b_from_ceiling) \
  1283. (((a_from_ceiling) + (b_from_ceiling) - 1) / (b_from_ceiling))
  1284. %% export_def(ceiling(a_from_ceiling,b_from_ceiling));
  1285. /* round_down(a,b) rounds a>=0 so that b>0 divides it.
  1286. b should be a 'constant expression'. */
  1287. #define round_down(a_from_round,b_from_round) \
  1288. (floor(a_from_round,b_from_round)*(b_from_round))
  1289. %% /* FIXME: Difference between lispbibl.d and clisp.h */
  1290. %% puts("#define round_down(a_from_round,b_from_round) (ifloor(a_from_round,b_from_round)*(b_from_round))");
  1291. /* round_up(a,b) rounds a>=0 so that b>0 divides it.
  1292. b should be a 'constant expression'. */
  1293. #define round_up(a_from_round,b_from_round) \
  1294. (ceiling(a_from_round,b_from_round)*(b_from_round))
  1295. %% export_def(round_up(a_from_round,b_from_round));
  1296. /* non-local exits */
  1297. #include <setjmp.h>
  1298. #if defined(UNIX) && defined(HAVE__JMP) && !defined(UNIX_LINUX) && !defined(UNIX_GNU) && !defined(UNIX_BEOS) && !defined(UNIX_CYGWIN32)
  1299. /* The following routines are more efficient (don't use with signal-masks): */
  1300. #undef setjmp
  1301. #undef longjmp
  1302. #define setjmp _setjmp
  1303. #define longjmp _longjmp
  1304. #ifdef LONGJMP_RETURNS
  1305. /* _longjmp(jmpbuf,value) can return if jmpbuf is invalid. */
  1306. #undef longjmp
  1307. #define longjmp(x,y) (_longjmp(x,y), NOTREACHED)
  1308. #endif
  1309. #endif
  1310. /* A longjmp() can only be called using an `int'.
  1311. But if we want to use a `long' and if sizeof(int) < sizeof(long),
  1312. we'll need a global variable: */
  1313. #if (int_bitsize == long_bitsize)
  1314. #define setjmpl(x) setjmp(x)
  1315. #define longjmpl(x,y) longjmp(x,y)
  1316. #else /* (int_bitsize < long_bitsize) */
  1317. extern long jmpl_value;
  1318. #define setjmpl(x) (setjmp(x) ? jmpl_value : 0)
  1319. #define longjmpl(x,y) (jmpl_value = (y), longjmp(x,1))
  1320. #endif
  1321. /* An alloca() replacement, used for DYNAMIC_ARRAY and SAVE_NUM_STACK.
  1322. See spvw_alloca.d. */
  1323. #if !(defined(GNU) || (defined(UNIX) && !defined(NO_ALLOCA) && !defined(SPARC)) || defined(BORLAND) || defined(MICROSOFT))
  1324. #define NEED_MALLOCA
  1325. #include <stdlib.h>
  1326. extern void* malloca (size_t size);
  1327. extern void freea (void* ptr);
  1328. #endif
  1329. /* Dynamically allocated array with dynamic extent:
  1330. Example:
  1331. var DYNAMIC_ARRAY(my_array,uintL,n);
  1332. ...
  1333. FREE_DYNAMIC_ARRAY(my_array);
  1334. Attention: depending on your implementation my_array is either the array
  1335. itself or a pointer to the array! Always use my_array only as expression! */
  1336. #if defined(GNU)
  1337. /* can deal with dynamically allocated arrays in the machine stack
  1338. { var uintL my_array[n]; ... } */
  1339. #define DYNAMIC_ARRAY(arrayvar,arrayeltype,arraysize) \
  1340. arrayeltype arrayvar[arraysize]
  1341. #define FREE_DYNAMIC_ARRAY(arrayvar)
  1342. #ifdef DECALPHA /* GCC 2.5.5 Bug umgehen */
  1343. #undef DYNAMIC_ARRAY
  1344. #define DYNAMIC_ARRAY(arrayvar,arrayeltype,arraysize) \
  1345. arrayeltype arrayvar[(arraysize)+1]
  1346. #endif
  1347. #elif (defined(UNIX) && (defined(HAVE_ALLOCA_H) || defined(_AIX) || !defined(NO_ALLOCA))) || defined(BORLAND) || defined(MICROSOFT)
  1348. /* Allocate space in machine stack.
  1349. { var uintL* my_array = (uintL*)alloca(n*sizeof(uintL)); ... } */
  1350. #define DYNAMIC_ARRAY(arrayvar,arrayeltype,arraysize) \
  1351. arrayeltype* arrayvar = (arrayeltype*)alloca((arraysize)*sizeof(arrayeltype))
  1352. #define FREE_DYNAMIC_ARRAY(arrayvar)
  1353. /* no error check?? */
  1354. #else
  1355. /* Allocate space somewhere else and then free it.
  1356. { var uintL* my_array = (uintL*)malloc(n*sizeof(uintL)); ... free(my_array); } */
  1357. #define DYNAMIC_ARRAY(arrayvar,arrayeltype,arraysize) \
  1358. arrayeltype* arrayvar = (arrayeltype*)malloca((arraysize)*sizeof(arrayeltype))
  1359. #define FREE_DYNAMIC_ARRAY(arrayvar) freea(arrayvar)
  1360. #endif
  1361. %% export_def(DYNAMIC_ARRAY(arrayvar,arrayeltype,arraysize));
  1362. %% export_def(FREE_DYNAMIC_ARRAY(arrayvar));
  1363. /* Signed/Unsigned-Integer-types with given minumum size: */
  1364. typedef UBYTE uint1; /* unsigned 1 bit Integer */
  1365. typedef SBYTE sint1; /* signed 1 bit Integer */
  1366. typedef UBYTE uint2; /* unsigned 2 bit Integer */
  1367. typedef SBYTE sint2; /* signed 2 bit Integer */
  1368. typedef UBYTE uint3; /* unsigned 3 bit Integer */
  1369. typedef SBYTE sint3; /* signed 3 bit Integer */
  1370. typedef UBYTE uint4; /* unsigned 4 bit Integer */
  1371. typedef SBYTE sint4; /* signed 4 bit Integer */
  1372. typedef UBYTE uint5; /* unsigned 5 bit Integer */
  1373. typedef SBYTE sint5; /* signed 5 bit Integer */
  1374. typedef UBYTE uint6; /* unsigned 6 bit Integer */
  1375. typedef SBYTE sint6; /* signed 6 bit Integer */
  1376. typedef UBYTE uint7; /* unsigned 7 bit Integer */
  1377. typedef SBYTE sint7; /* signed 7 bit Integer */
  1378. typedef UBYTE uint8; /* unsigned 8 bit Integer */
  1379. typedef SBYTE sint8; /* signed 8 bit Integer */
  1380. typedef UWORD uint9; /* unsigned 9 bit Integer */
  1381. typedef SWORD sint9; /* signed 9 bit Integer */
  1382. typedef UWORD uint10; /* unsigned 10 bit Integer */
  1383. typedef SWORD sint10; /* signed 10 bit Integer */
  1384. typedef UWORD uint11; /* unsigned 11 bit Integer */
  1385. typedef SWORD sint11; /* signed 11 bit Integer */
  1386. typedef UWORD uint12; /* unsigned 12 bit Integer */
  1387. typedef SWORD sint12; /* signed 12 bit Integer */
  1388. typedef UWORD uint13; /* unsigned 13 bit Integer */
  1389. typedef SWORD sint13; /* signed 13 bit Integer */
  1390. typedef UWORD uint14; /* unsigned 14 bit Integer */
  1391. typedef SWORD sint14; /* signed 14 bit Integer */
  1392. typedef UWORD uint15; /* unsigned 15 bit Integer */
  1393. typedef SWORD sint15; /* signed 15 bit Integer */
  1394. typedef UWORD uint16; /* unsigned 16 bit Integer */
  1395. typedef SWORD sint16; /* signed 16 bit Integer */
  1396. typedef ULONG uint17; /* unsigned 17 bit Integer */
  1397. typedef SLONG sint17; /* signed 17 bit Integer */
  1398. typedef ULONG uint18; /* unsigned 18 bit Integer */
  1399. typedef SLONG sint18; /* signed 18 bit Integer */
  1400. typedef ULONG uint19; /* unsigned 19 bit Integer */
  1401. typedef SLONG sint19; /* signed 19 bit Integer */
  1402. typedef ULONG uint20; /* unsigned 20 bit Integer */
  1403. typedef SLONG sint20; /* signed 20 bit Integer */
  1404. typedef ULONG uint21; /* unsigned 21 bit Integer */
  1405. typedef SLONG sint21; /* signed 21 bit Integer */
  1406. typedef ULONG uint22; /* unsigned 22 bit Integer */
  1407. typedef SLONG sint22; /* signed 22 bit Integer */
  1408. typedef ULONG uint23; /* unsigned 23 bit Integer */
  1409. typedef SLONG sint23; /* signed 23 bit Integer */
  1410. typedef ULONG uint24; /* unsigned 24 bit Integer */
  1411. typedef SLONG sint24; /* signed 24 bit Integer */
  1412. typedef ULONG uint25; /* unsigned 25 bit Integer */
  1413. typedef SLONG sint25; /* signed 25 bit Integer */
  1414. typedef ULONG uint26; /* unsigned 26 bit Integer */
  1415. typedef SLONG sint26; /* signed 26 bit Integer */
  1416. typedef ULONG uint27; /* unsigned 27 bit Integer */
  1417. typedef SLONG sint27; /* signed 27 bit Integer */
  1418. typedef ULONG uint28; /* unsigned 28 bit Integer */
  1419. typedef SLONG sint28; /* signed 28 bit Integer */
  1420. typedef ULONG uint29; /* unsigned 29 bit Integer */
  1421. typedef SLONG sint29; /* signed 29 bit Integer */
  1422. typedef ULONG uint30; /* unsigned 30 bit Integer */
  1423. typedef SLONG sint30; /* signed 30 bit Integer */
  1424. typedef ULONG uint31; /* unsigned 31 bit Integer */
  1425. typedef SLONG sint31; /* signed 31 bit Integer */
  1426. typedef ULONG uint32; /* unsigned 32 bit Integer */
  1427. typedef SLONG sint32; /* signed 32 bit Integer */
  1428. #ifdef HAVE_LONG_LONG_INT
  1429. typedef ULONGLONG uint33; /* unsigned 33 bit Integer */
  1430. typedef SLONGLONG sint33; /* signed 33 bit Integer */
  1431. typedef ULONGLONG uint48; /* unsigned 48 bit Integer */
  1432. typedef SLONGLONG sint48; /* signed 48 bit Integer */
  1433. typedef ULONGLONG uint64; /* unsigned 64 bit Integer */
  1434. typedef SLONGLONG sint64; /* signed 64 bit Integer */
  1435. #endif
  1436. #define exact_uint_size_p(n) (((n)==char_bitsize)||((n)==short_bitsize)||((n)==int_bitsize)||((n)==long_bitsize))
  1437. #define signed_int_with_n_bits(n) CONCAT(sint,n)
  1438. #define unsigned_int_with_n_bits(n) CONCAT(uint,n)
  1439. /* Use 'uintn' and 'sintn' for Integers with exactly specified width.
  1440. exact_uint_size_p(n) specifies, whether the uint with n Bits has really
  1441. only n Bits. */
  1442. %% { int i;
  1443. %% for (i=1; i<=8; i++) {
  1444. %% sprintf(buf,"uint%d",i); emit_typedef("UBYTE",buf);
  1445. %% sprintf(buf,"sint%d",i); emit_typedef("SBYTE",buf);
  1446. %% }
  1447. %% for (i=9; i<=16; i++) {
  1448. %% sprintf(buf,"uint%d",i); emit_typedef("UWORD",buf);
  1449. %% sprintf(buf,"sint%d",i); emit_typedef("SWORD",buf);
  1450. %% }
  1451. %% for (i=17; i<=32; i++) {
  1452. %% sprintf(buf,"uint%d",i); emit_typedef("ULONG",buf);
  1453. %% sprintf(buf,"sint%d",i); emit_typedef("SLONG",buf);
  1454. %% }
  1455. %% #ifdef HAVE_LONG_LONG_INT
  1456. %% for (i=33; i<=64; i++)
  1457. %% if ((i==33) || (i==48) || (i==64)) {
  1458. %% sprintf(buf,"uint%d",i); emit_typedef("ULONGLONG",buf);
  1459. %% sprintf(buf,"sint%d",i); emit_typedef("SLONGLONG",buf);
  1460. %% }
  1461. %% #endif
  1462. %% }
  1463. /* 'uintX' and 'sintX' mean unsigned bzw. signed integer - types with
  1464. wordsize X (X=B,W,L,Q) here as well. */
  1465. #define intBsize 8
  1466. typedef signed_int_with_n_bits(intBsize) sintB;
  1467. typedef unsigned_int_with_n_bits(intBsize) uintB;
  1468. #define intWsize 16
  1469. typedef signed_int_with_n_bits(intWsize) sintW;
  1470. typedef unsigned_int_with_n_bits(intWsize) uintW;
  1471. #define intLsize 32
  1472. typedef signed_int_with_n_bits(intLsize) sintL;
  1473. typedef unsigned_int_with_n_bits(intLsize) uintL;
  1474. #if defined(DECALPHA) || defined(MIPS64) || defined(SPARC64) || defined(IA64) || defined(AMD64)
  1475. /* Machine has real 64-bit integers in hardware. */
  1476. #define intQsize 64
  1477. typedef signed_int_with_n_bits(intQsize) sintQ;
  1478. typedef unsigned_int_with_n_bits(intQsize) uintQ;
  1479. typedef sintQ sintL2;
  1480. typedef uintQ uintL2;
  1481. #else
  1482. /* Emulate 64-Bit-numbers using two 32-Bit-numbers. */
  1483. typedef struct { sintL hi; uintL lo; } sintL2; /* signed 64 Bit integer */
  1484. typedef struct { uintL hi; uintL lo; } uintL2; /* unsigned 64 Bit integer */
  1485. #endif
  1486. /* Use 'uintX' and 'sintX' for Integers with approximately given width
  1487. and a minumum of storage space. */
  1488. %% sprintf(buf,"sint%d",intBsize); emit_typedef(buf,"sintB");
  1489. %% sprintf(buf,"uint%d",intBsize); emit_typedef(buf,"uintB");
  1490. %% #if notused
  1491. %% sprintf(buf,"sint%d",intWsize); emit_typedef(buf,"sintW");
  1492. %% #endif
  1493. %% sprintf(buf,"uint%d",intWsize); emit_typedef(buf,"uintW");
  1494. %% sprintf(buf,"sint%d",intLsize); emit_typedef(buf,"sintL");
  1495. %% sprintf(buf,"uint%d",intLsize); emit_typedef(buf,"uintL");
  1496. %% #if notused
  1497. %% #ifdef intQsize
  1498. %% sprintf(buf,"sint%d",intQsize); emit_typedef(buf,"sintQ");
  1499. %% sprintf(buf,"uint%d",intQsize); emit_typedef(buf,"uintQ");
  1500. %% #else
  1501. %% emit_typedef("struct { sintL hi; uintL lo; }","sintL2");
  1502. %% emit_typedef("struct { uintL hi; uintL lo; }","uintL2");
  1503. %% #endif
  1504. %% #endif
  1505. /* From here on 'uintP' and 'sintP' are unsigned or signed integer types,
  1506. which are as wide as void* - pointers */
  1507. typedef signed_int_with_n_bits(pointer_bitsize) sintP;
  1508. typedef unsigned_int_with_n_bits(pointer_bitsize) uintP;
  1509. %% sprintf(buf,"sint%d",pointer_bitsize); emit_typedef(buf,"sintP");
  1510. %% sprintf(buf,"uint%d",pointer_bitsize); emit_typedef(buf,"uintP");
  1511. /* From here on 'uintXY' and 'sintXY' mean unsigned or signed integer types,
  1512. with word sizes X or Y (X,Y=B,W,L). */
  1513. #if (defined(MC680X0) && !defined(HPUX_ASSEMBLER)) || defined(VAX)
  1514. /* The 68000 offers good processing of uintB and uintW, especially
  1515. DBRA-commands for uintW. */
  1516. #define intBWsize intBsize
  1517. #define intWLsize intWsize
  1518. #define intBWLsize intBsize
  1519. #elif (defined(MC680X0) && defined(HPUX_ASSEMBLER)) || defined(SPARC) || defined(HPPA) || defined(MIPS) || defined(M88000) || defined(POWERPC) || defined(S390)
  1520. /* The Sparc-processor computes rather badly with uintB and uintW.
  1521. Other 32-Bit-processoren have similar weaknesses. */
  1522. #define intBWsize intWsize
  1523. #define intWLsize intLsize
  1524. #define intBWLsize intLsize
  1525. #elif defined(I80386) || defined(AMD64)
  1526. /* If you compute using uintB and uintW on a 80386, there will be many
  1527. Zero-Extends, that will - because there aren't enough registers - load
  1528. other variables into memory, which is rather unnecessary. */
  1529. #define intBWsize intWsize
  1530. #define intWLsize intLsize
  1531. #define intBWLsize intLsize
  1532. #elif defined(ARM)
  1533. /* The ARM computes very badly when it uses uintB and uintW. */
  1534. #define intBWsize intBsize
  1535. #define intWLsize intLsize
  1536. #define intBWLsize intLsize
  1537. #elif defined(DECALPHA) || defined(IA64)
  1538. /* 64-bit processors also compute badly with uintB and uintW. */
  1539. #define intBWsize intWsize
  1540. #define intWLsize intLsize
  1541. #define intBWLsize intLsize
  1542. #else
  1543. #error "Preferred integer sizes depend on CPU -- readjust intBWsize, intWLsize, intBWLsize!"
  1544. #endif
  1545. typedef signed_int_with_n_bits(intBWsize) sintBW;
  1546. typedef unsigned_int_with_n_bits(intBWsize) uintBW;
  1547. typedef signed_int_with_n_bits(intWLsize) sintWL;
  1548. typedef unsigned_int_with_n_bits(intWLsize) uintWL;
  1549. typedef signed_int_with_n_bits(intBWLsize) sintBWL;
  1550. typedef unsigned_int_with_n_bits(intBWLsize) uintBWL;
  1551. /* Use 'uintXY' and 'sintXY' for integers with given minumum width,
  1552. that allow easy computations. */
  1553. %% #if notused
  1554. %% sprintf(buf,"sint%d",intBWsize); emit_typedef(buf,"sintBW");
  1555. %% sprintf(buf,"uint%d",intBWsize); emit_typedef(buf,"uintBW");
  1556. %% sprintf(buf,"sint%d",intWLsize); emit_typedef(buf,"sintWL");
  1557. %% #endif
  1558. %% sprintf(buf,"uint%d",intWLsize); emit_typedef(buf,"uintWL");
  1559. %% #if notused
  1560. %% sprintf(buf,"sint%d",intBWLsize); emit_typedef(buf,"sintBWL");
  1561. %% #endif
  1562. %% sprintf(buf,"uint%d",intBWLsize); emit_typedef(buf,"uintBWL");
  1563. /* Loop that will excute as statement a certain number of times:
  1564. dotimesW(countvar,count,statement); if count fits into a uintW,
  1565. dotimesL(countvar,count,statement); if count only fits into a uintL,
  1566. dotimesV(countvar,count,statement); if count only fits into a uintV,
  1567. dotimespW(countvar,count,statement); if count fits into a uintW and is >0,
  1568. dotimespL(countvar,count,statement); if count fits only into a uintL and is >0.
  1569. dotimespV(countvar,count,statement); if count fits only into a uintV and is >0.
  1570. The variable countvar has to be declared previously, be of type uintW or uintL,
  1571. and will be changed by this expression.
  1572. It must not be used in the statement itself!
  1573. The expression count will only be evaluated once (at the beginning). */
  1574. #if defined(GNU) && defined(MC680X0) && !defined(HPUX_ASSEMBLER)
  1575. /* GNU-C on a 680X0 can be persuaded to use the DBRA-instruction: */
  1576. #define fast_dotimesW
  1577. /* To find out, what the best was to 'persuade' GNU-C is, check the
  1578. code, that'll be generated for spvw.d:gc_markphase().
  1579. Or a small test program (dbratest.c), that is compiled with
  1580. "gcc -O6 -da -S dbratest.c", and take a look at dbratest.s
  1581. and dbratest.c.flow as well as dbratest.c.combine. */
  1582. #if (__GNUC__<2) /* GNU C Version 1 */
  1583. #define dotimesW_(countvar_from_dotimesW,count_from_dotimesW,statement_from_dotimesW) \
  1584. { countvar_from_dotimesW = (count_from_dotimesW); \
  1585. if (!(countvar_from_dotimesW==0)) \
  1586. { countvar_from_dotimesW--; \
  1587. do {statement_from_dotimesW} \
  1588. while ((sintW)--countvar_from_dotimesW != -1); \
  1589. } }
  1590. #define dotimespW_(countvar_from_dotimespW,count_from_dotimespW,statement_from_dotimespW) \
  1591. { countvar_from_dotimespW = (count_from_dotimespW)-1; \
  1592. do {statement_from_dotimespW} while ((sintW)--countvar_from_dotimespW != -1); \
  1593. }
  1594. #else
  1595. #define dotimesW_(countvar_from_dotimesW,count_from_dotimesW,statement_from_dotimesW) \
  1596. { countvar_from_dotimesW = (count_from_dotimesW); \
  1597. if (!(countvar_from_dotimesW==0)) \
  1598. { countvar_from_dotimesW--; \
  1599. do {statement_from_dotimesW} \
  1600. while ((sintW)(--countvar_from_dotimesW)+1 != 0); \
  1601. } }
  1602. #define dotimespW_(countvar_from_dotimespW,count_from_dotimespW,statement_from_dotimespW) \
  1603. { countvar_from_dotimespW = (count_from_dotimespW)-1; \
  1604. do {statement_from_dotimespW} while ((sintW)(--countvar_from_dotimespW)+1 != 0); \
  1605. }
  1606. #endif
  1607. #else
  1608. #define dotimesW_(countvar_from_dotimesW,count_from_dotimesW,statement_from_dotimesW) \
  1609. { countvar_from_dotimesW = (count_from_dotimesW); \
  1610. while (countvar_from_dotimesW != 0) \
  1611. {statement_from_dotimesW; countvar_from_dotimesW--; } \
  1612. }
  1613. #define dotimespW_(countvar_from_dotimespW,count_from_dotimespW,statement_from_dotimespW) \
  1614. { countvar_from_dotimespW = (count_from_dotimespW); \
  1615. do {statement_from_dotimespW} while (--countvar_from_dotimespW != 0); \
  1616. }
  1617. #endif
  1618. #if defined(GNU) && defined(MC680X0) && !defined(HPUX_ASSEMBLER)
  1619. /* GNU-C on a 680X0 can be 'persuaded' to use the DBRA-instruction
  1620. in an intelligent manner: */
  1621. #define fast_dotimesL
  1622. #define dotimesL_(countvar_from_dotimesL,count_from_dotimesL,statement_from_dotimesL) \
  1623. { countvar_from_dotimesL = (count_from_dotimesL); \
  1624. if (!(countvar_from_dotimesL==0)) \
  1625. { countvar_from_dotimesL--; \
  1626. do {statement_from_dotimesL} \
  1627. while ((sintL)(--countvar_from_dotimesL) != -1); \
  1628. } }
  1629. #define dotimespL_(countvar_from_dotimespL,count_from_dotimespL,statement_from_dotimespL) \
  1630. { countvar_from_dotimespL = (count_from_dotimespL)-1; \
  1631. do {statement_from_dotimespL} while ((sintL)(--countvar_from_dotimespL) != -1); \
  1632. }
  1633. #endif
  1634. #ifndef dotimesL_
  1635. #define dotimesL_(countvar_from_dotimesL,count_from_dotimesL,statement_from_dotimesL) \
  1636. { countvar_from_dotimesL = (count_from_dotimesL); \
  1637. while (countvar_from_dotimesL != 0) \
  1638. {statement_from_dotimesL; countvar_from_dotimesL--; } \
  1639. }
  1640. #define dotimespL_(countvar_from_dotimespL,count_from_dotimespL,statement_from_dotimespL) \
  1641. { countvar_from_dotimespL = (count_from_dotimespL); \
  1642. do {statement_from_dotimespL} while (--countvar_from_dotimespL != 0); \
  1643. }
  1644. #endif
  1645. #if defined(GNU) && defined(__OPTIMIZE__)
  1646. /* It happened twice to me that I used dotimesL on a
  1647. variable of type uintC. I check for that now, so that
  1648. Joerg and Marcus won't have to search for that anymore.
  1649. The GCC will optimize the dummy-call away, if things go by plan.
  1650. If not, you'll see a linker error. */
  1651. #define dotimes_check_sizeof(countvar,type) \
  1652. if (!(sizeof(countvar)==sizeof(type))) { dotimes_called_with_count_of_wrong_size(); }
  1653. extern void dotimes_called_with_count_of_wrong_size (void); /* non-existing function */
  1654. #else
  1655. #define dotimes_check_sizeof(countvar,type)
  1656. #endif
  1657. #define dotimesW(countvar_from_dotimesW,count_from_dotimesW,statement_from_dotimesW) \
  1658. do { dotimes_check_sizeof(countvar_from_dotimesW,uintW); \
  1659. dotimesW_(countvar_from_dotimesW,count_from_dotimesW,statement_from_dotimesW); \
  1660. } while(0)
  1661. #define dotimespW(countvar_from_dotimespW,count_from_dotimespW,statement_from_dotimespW) \
  1662. do { dotimes_check_sizeof(countvar_from_dotimespW,uintW); \
  1663. dotimespW_(countvar_from_dotimespW,count_from_dotimespW,statement_from_dotimespW); \
  1664. } while(0)
  1665. #define dotimesL(countvar_from_dotimesL,count_from_dotimesL,statement_from_dotimesL) \
  1666. do { dotimes_check_sizeof(countvar_from_dotimesL,uintL); \
  1667. dotimesL_(countvar_from_dotimesL,count_from_dotimesL,statement_from_dotimesL); \
  1668. } while(0)
  1669. #define dotimespL(countvar_from_dotimespL,count_from_dotimespL,statement_from_dotimespL) \
  1670. do { dotimes_check_sizeof(countvar_from_dotimespL,uintL); \
  1671. dotimespL_(countvar_from_dotimespL,count_from_dotimespL,statement_from_dotimespL); \
  1672. } while(0)
  1673. #define dotimesV(countvar_from_dotimesV,count_from_dotimesV,statement_from_dotimesV) \
  1674. do { dotimes_check_sizeof(countvar_from_dotimesV,uintV); \
  1675. dotimesL_(countvar_from_dotimesV,count_from_dotimesV,statement_from_dotimesV); \
  1676. } while(0)
  1677. #define dotimespV(countvar_from_dotimespV,count_from_dotimespV,statement_from_dotimespV) \
  1678. do { dotimes_check_sizeof(countvar_from_dotimespV,uintV); \
  1679. dotimespL_(countvar_from_dotimespV,count_from_dotimespV,statement_from_dotimespV); \
  1680. } while(0)
  1681. /* doconsttimes(count,statement);
  1682. executes a statement count times (count times the code!),
  1683. where count is a constant-expression >=0, <=8. */
  1684. #define doconsttimes(count_from_doconsttimes,statement_from_doconsttimes) \
  1685. do { if (0 < (count_from_doconsttimes)) { statement_from_doconsttimes; } \
  1686. if (1 < (count_from_doconsttimes)) { statement_from_doconsttimes; } \
  1687. if (2 < (count_from_doconsttimes)) { statement_from_doconsttimes; } \
  1688. if (3 < (count_from_doconsttimes)) { statement_from_doconsttimes; } \
  1689. if (4 < (count_from_doconsttimes)) { statement_from_doconsttimes; } \
  1690. if (5 < (count_from_doconsttimes)) { statement_from_doconsttimes; } \
  1691. if (6 < (count_from_doconsttimes)) { statement_from_doconsttimes; } \
  1692. if (7 < (count_from_doconsttimes)) { statement_from_doconsttimes; } \
  1693. } while(0)
  1694. /* DOCONSTTIMES(count,macroname);
  1695. calls the macro macroname count times (count times the code!),
  1696. where count is a constant-expression >=0, <=8.
  1697. And macroname will get the values 0,...,count-1 in sequence. */
  1698. #define DOCONSTTIMES(count_from_DOCONSTTIMES,macroname_from_DOCONSTTIMES) \
  1699. do { if (0 < (count_from_DOCONSTTIMES)) { macroname_from_DOCONSTTIMES((0 < (count_from_DOCONSTTIMES) ? 0 : 0)); } \
  1700. if (1 < (count_from_DOCONSTTIMES)) { macroname_from_DOCONSTTIMES((1 < (count_from_DOCONSTTIMES) ? 1 : 0)); } \
  1701. if (2 < (count_from_DOCONSTTIMES)) { macroname_from_DOCONSTTIMES((2 < (count_from_DOCONSTTIMES) ? 2 : 0)); } \
  1702. if (3 < (count_from_DOCONSTTIMES)) { macroname_from_DOCONSTTIMES((3 < (count_from_DOCONSTTIMES) ? 3 : 0)); } \
  1703. if (4 < (count_from_DOCONSTTIMES)) { macroname_from_DOCONSTTIMES((4 < (count_from_DOCONSTTIMES) ? 4 : 0)); } \
  1704. if (5 < (count_from_DOCONSTTIMES)) { macroname_from_DOCONSTTIMES((5 < (count_from_DOCONSTTIMES) ? 5 : 0)); } \
  1705. if (6 < (count_from_DOCONSTTIMES)) { macroname_from_DOCONSTTIMES((6 < (count_from_DOCONSTTIMES) ? 6 : 0)); } \
  1706. if (7 < (count_from_DOCONSTTIMES)) { macroname_from_DOCONSTTIMES((7 < (count_from_DOCONSTTIMES) ? 7 : 0)); } \
  1707. } while(0)
  1708. /* From here on uintC means an unsigned integer type, that'll allow
  1709. easy counting. Subset relation: uintW <= uintC <= uintL. */
  1710. #define intCsize intWLsize
  1711. #define uintC uintWL
  1712. #define sintC sintWL
  1713. #if (intCsize==intWsize)
  1714. #define dotimesC dotimesW
  1715. #define dotimespC dotimespW
  1716. #endif
  1717. #if (intCsize==intLsize)
  1718. #define dotimesC dotimesL
  1719. #define dotimespC dotimespL
  1720. #endif
  1721. /* Use 'uintC' for counters, which are small most of the time. */
  1722. %% export_def(uintC);
  1723. %% #if notused
  1724. %% export_def(sintC);
  1725. %% #endif
  1726. /* The arithmetics use "digit sequences" of "digits".
  1727. They are unsigned ints with intDsize bits (should be =8 or =16 or =32).
  1728. If HAVE_DD: "double-digits" are unsigned ints with 2*intDsize<=32 bits. */
  1729. #if defined(MC680X0) && !defined(MC680Y0)
  1730. #define intDsize 16
  1731. #define intDDsize 32 /* = 2*intDsize */
  1732. #define log2_intDsize 4 /* = log2(intDsize) */
  1733. #elif defined(MC680Y0) || defined(I80386) || defined(SPARC) || defined(HPPA) || defined(MIPS) || defined(M88000) || defined(POWERPC) || defined(VAX) || defined(ARM) || defined(DECALPHA) || defined(IA64) || defined(AMD64) || defined(S390)
  1734. #define intDsize 32
  1735. #define intDDsize 64 /* = 2*intDsize */
  1736. #define log2_intDsize 5 /* = log2(intDsize) */
  1737. #else
  1738. #error "Preferred digit size depends on CPU -- readjust intDsize!"
  1739. #endif
  1740. typedef unsigned_int_with_n_bits(intDsize) uintD;
  1741. typedef signed_int_with_n_bits(intDsize) sintD;
  1742. #if (intDDsize<=32) || ((intDDsize<=64) && (defined(DECALPHA) || defined(MIPS64) || defined(SPARC64) || defined(IA64) || defined(AMD64)))
  1743. #define HAVE_DD 1
  1744. typedef unsigned_int_with_n_bits(intDDsize) uintDD;
  1745. typedef signed_int_with_n_bits(intDDsize) sintDD;
  1746. #else
  1747. #define HAVE_DD 0
  1748. #endif
  1749. %% #if notused
  1750. %% sprintf(buf,"sint%d",intDsize); emit_typedef(buf,"sintD");
  1751. %% #endif
  1752. %% sprintf(buf,"uint%d",intDsize); emit_typedef(buf,"uintD");
  1753. /* Other acronyms like 'oint', 'tint', 'aint', 'cint' will be used
  1754. for the corresponding integer types:
  1755. Integer type contains information equivalent to
  1756. oint LISP object
  1757. tint type code of a LISP object
  1758. aint address of a LISP object
  1759. cint LISP character
  1760. Usually sizeof(oint) = sizeof(aint) = sizeof(uintL) = 32 Bit.
  1761. Under the model WIDE sizeof(oint) is > sizeof(uintL).
  1762. Model WIDE_HARD stands for sizeof(aint) > sizeof(uintL).
  1763. This model is to be chosen if the following holds true:
  1764. sizeof(void*) > sizeof(uintL) = 32 bit. It also requires that
  1765. sizeof(long) = sizeof(void*) = 64 bit, because some 64-bit numbers
  1766. appear as pre-processor constants.
  1767. Model WIDE_SOFT stands for sizeof(oint) = 64 bit and sizeof(aint) = 32 bit.
  1768. This model can be chosen on any 32-Bit-Machine, if the
  1769. compiler has 64-bit numbers (in software or hardware).
  1770. You will also need to choose it, if there would not be enough space
  1771. for the type-bits in a 32-bit pointer.
  1772. Model HEAPCODES stands for sizeof(oint) = sizeof(aint), and only minimal
  1773. type information is stored in a pointer. All heap allocated objects
  1774. (except conses) must contain the complete type and a length field in the
  1775. first word. The heap gets somewhat bigger by this, and type tests require
  1776. more memory accesses on average, but this model is portable even to
  1777. systems whose memory map looks like Swiss Cheese. */
  1778. %% #if notused
  1779. %% #ifdef WIDE_HARD
  1780. %% puts("#define WIDE_HARD");
  1781. %% #endif
  1782. %% #ifdef WIDE_SOFT
  1783. %% puts("#define WIDE_SOFT");
  1784. %% #endif
  1785. %% #ifdef WIDE_AUXI
  1786. %% puts("#define WIDE_AUXI");
  1787. %% #endif
  1788. %% #ifdef WIDE
  1789. %% puts("#define WIDE");
  1790. %% #endif
  1791. %% #endif
  1792. #if defined(STANDARD_HEAPCODES) || defined(LINUX_NOEXEC_HEAPCODES)
  1793. #define HEAPCODES
  1794. #endif
  1795. #if defined(WIDE_SOFT) && defined(HEAPCODES)
  1796. #error "WIDE_SOFT and HEAPCODES make no sense together, no need for WIDE_SOFT"
  1797. #endif
  1798. #if defined(TYPECODES) && defined(HEAPCODES)
  1799. #error "TYPECODES and HEAPCODES make no sense together"
  1800. #endif
  1801. #if !(defined(TYPECODES) || defined(HEAPCODES))
  1802. /* Choose typecodes on 64-bit machines (because there's enough room for type
  1803. bits), but not on 32-bit machines (because a 16 MB limit is ridiculous
  1804. today), except if the CPU cannot address more than 16 MB anyway.
  1805. HEAPCODES will normally not work if alignof(subr_t) = alignof(long) < 4,
  1806. but with egcs-1.1 or newer we can force alignof(subr_t) = 4. */
  1807. #if defined(WIDE_HARD) || defined(WIDE_SOFT) || defined(MC68000) || ((alignment_long < 4) && !defined(GNU))
  1808. #define TYPECODES
  1809. #else
  1810. #define HEAPCODES
  1811. #endif
  1812. #endif
  1813. %% #ifdef HEAPCODES
  1814. %% puts("#define HEAPCODES");
  1815. %% #endif
  1816. #ifdef WIDE_SOFT
  1817. #if defined(GNU) && !defined(WIDE_SOFT_LARGEFIXNUM)
  1818. /* Use the GNU-C extensions, to regard the wide oints as structs. */
  1819. #define WIDE_STRUCT
  1820. #endif
  1821. /* defines the arrangement of an oint's elements: */
  1822. #define WIDE_ENDIANNESS true /* more efficient this way */
  1823. #endif
  1824. #if defined(GNU) && (SAFETY >= 3)
  1825. #if (__GNUC__ >= 2)
  1826. #if (__GNUC__ > 2) || (__GNUC_MINOR__ >= 7) /* circumvent gcc-2.6.3 bug */
  1827. /* Typechecking by the C-compiler */
  1828. #define OBJECT_STRUCT
  1829. #if !(defined(MC680X0) || defined(ARM)) && !(defined(__GNUG__) && (__GNUC__ == 3) && (__GNUC_MINOR__ == 3)) /* only if struct_alignment==1, and not with g++ 3.3 */
  1830. #define CHART_STRUCT
  1831. #endif
  1832. #endif
  1833. #endif
  1834. #endif
  1835. /* ###################### OS-related routines #################### */
  1836. /* general standard constants for control chars: */
  1837. #define BS 8 /* #\Backspace Backspace */
  1838. #define TAB 9 /* #\Tab Tabulator */
  1839. #define LF 10 /* #\Linefeed linefeed */
  1840. #define CR 13 /* #\Return carriage return */
  1841. #define PG 12 /* #\Page form feed, new page */
  1842. /* Desired reaction when an I/O operation cannot be completed immediately. */
  1843. typedef enum {
  1844. persev_full, /* Continue the I/O operation until the whole buffer is
  1845. handled or EOF or an error occurred. May hang. */
  1846. persev_partial, /* Continue the I/O operation until some (non-empty) part
  1847. of the buffer is handled or EOF or an error occurred.
  1848. May hang. */
  1849. persev_immediate, /* Act immediately. Perform I/O only if we know in advance
  1850. that it will not block. In case of doubt, perform it
  1851. anyway. May return with 0 bytes handled. Does usually
  1852. not hang. */
  1853. persev_bonus /* Act immediately. Perform I/O only if we know in advance
  1854. that it will not block. In case of doubt, don't perform
  1855. it. May return with 0 bytes handled. Does not hang. */
  1856. } perseverance_t;
  1857. %% printf("typedef enum { persev_full=%d, persev_partial=%d, persev_immediate=%d, persev_bonus=%d } perseverance_t;\n",persev_full,persev_partial,persev_immediate,persev_bonus);
  1858. #if defined(UNIX) || defined(WIN32)
  1859. #ifdef UNIX
  1860. #include "unix.c"
  1861. #endif
  1862. #ifdef WIN32_NATIVE
  1863. #include "win32.c"
  1864. #endif
  1865. %% puts("#include <stdlib.h>");
  1866. %% puts("#include <sys/types.h>");
  1867. %% #if defined(UNIX)
  1868. %% emit_typedef("int","Handle");
  1869. %% emit_typedef("int","SOCKET");
  1870. %% #ifdef UNIX_CYGWIN32
  1871. %% puts("#include <windows.h>");
  1872. %% puts("#undef WIN32");
  1873. %% puts("extern long time_t_from_filetime (const FILETIME * ptr);");
  1874. %% puts("extern void time_t_to_filetime (time_t time_in, FILETIME * out);");
  1875. %% #endif
  1876. %% #elif defined(WIN32_NATIVE)
  1877. %% puts("#include <windows.h>");
  1878. %% export_def(Handle);
  1879. %% puts("#include <winsock2.h>"); /* defines SOCKET */
  1880. %% #else
  1881. %% puts("#error \"what is Handle on your platform?!\"");
  1882. %% #endif
  1883. %% #if defined(UNIX)
  1884. %% puts("extern ssize_t fd_read (int fd, void* buf, size_t nbyte, perseverance_t persev);");
  1885. %% puts("extern ssize_t fd_write (int fd, const void* buf, size_t nbyte, perseverance_t persev);");
  1886. %% #elif defined(WIN32_NATIVE)
  1887. %% puts("extern ssize_t fd_read (Handle fd, void* buf, size_t nbyte, perseverance_t persev);");
  1888. %% puts("extern ssize_t fd_write (Handle fd, const void* buf, size_t nbyte, perseverance_t persev);");
  1889. %% #endif
  1890. /* execute statement on interrupt:
  1891. interruptp(statement); */
  1892. #if defined(UNIX) || defined(WIN32_NATIVE)
  1893. /* A keyboard interrupt (signal SIGINT, generated by Ctrl-C)
  1894. is pending for one second. It can be treated with 'interruptp' in
  1895. a continuing manner in that time. After this time has passed, the
  1896. program will be interrupted and can't be continued.. */
  1897. #define PENDING_INTERRUPTS
  1898. extern uintB interrupt_pending;
  1899. #define interruptp(statement) if (interrupt_pending) { statement; }
  1900. #endif
  1901. /* used by EVAL, IO, SPVW, STREAM */
  1902. #endif /* UNIX || WIN32 */
  1903. #if (defined(UNIX) || defined(WIN32_NATIVE)) && !defined(NO_SIGSEGV)
  1904. /* Support for fault handling. */
  1905. #include <sigsegv.h>
  1906. #if defined(UNIX_CYGWIN32)
  1907. /* <sigsegv.h> includes <windows.h> */
  1908. #undef WIN32
  1909. #endif
  1910. #endif
  1911. /* Ignoring of a value (instead of assigning it to a variable)
  1912. unused ...
  1913. <sigsegv.h> includes <windows.h> which uses unused! */
  1914. #ifndef unused /* win32.d defines unused */
  1915. #ifdef GNU /* to prevent a gcc-warning "statement with no effect" */
  1916. #define unused (void)
  1917. #else
  1918. #define unused
  1919. #endif
  1920. #endif
  1921. %% export_def(unused);
  1922. /* Consensys and Solaris: "#define DS 3", "#define SP ESP", "#define EAX 11".
  1923. Grr... */
  1924. #undef DS
  1925. #undef SP
  1926. #undef EAX
  1927. /* 386BSD does "#define CBLOCK 64". Grr... */
  1928. #undef CBLOCK
  1929. /* AIX 3.2.5 does "#define hz 100". Grr... */
  1930. #undef hz
  1931. /* MacOS X does "#define TIME_ABSOLUTE 0x00" and "#define TIME_RELATIVE 0x01".
  1932. Grr... */
  1933. #undef TIME_ABSOLUTE
  1934. #undef TIME_RELATIVE
  1935. #ifdef UNIX
  1936. /* Handling of UNIX errors
  1937. OS_error();
  1938. > int errno: error code */
  1939. nonreturning_function(extern, OS_error, (void));
  1940. /* used by SPVW, STREAM, PATHNAME, GRAPH */
  1941. #endif
  1942. #if defined(WIN32_NATIVE)
  1943. /* Handling of Win32 errors
  1944. OS_error();
  1945. > GetLastError(): error code */
  1946. nonreturning_function(extern, OS_error, (void));
  1947. /* Handling of Winsock errors
  1948. SOCK_error();
  1949. > WSAGetLastError(): error code */
  1950. nonreturning_function(extern, SOCK_error, (void));
  1951. #endif
  1952. #if defined(DEBUG_OS_ERROR)
  1953. /* Show the file and line number of the caller of OS_error(). For debugging. */
  1954. #define OS_error() \
  1955. (fprintf(stderr,"\n[%s:%d] ",__FILE__,__LINE__), (OS_error)())
  1956. #endif
  1957. %% puts("nonreturning_function(extern, OS_error, (void));");
  1958. /* Handling of ANSI C errors
  1959. ANSIC_error();
  1960. > int errno: error code */
  1961. #ifdef UNIX
  1962. #define ANSIC_error OS_error
  1963. #else
  1964. nonreturning_function(extern, ANSIC_error, (void));
  1965. #endif
  1966. /* used by SPVW, STREAM */
  1967. #ifdef MULTITHREAD
  1968. #include "xthread.c"
  1969. #if !(defined(HAVE_MMAP_ANON) || defined(HAVE_MMAP_DEVZERO) || defined(HAVE_MACH_VM) || defined(HAVE_WIN32_VM))
  1970. #error "Multithreading requires memory mapping facilities!"
  1971. #endif
  1972. #endif
  1973. /* ##################### Further system-dependencies #################### */
  1974. /* At first dependencies that are visible to the LISP-level: */
  1975. /* setting of the table of character-names: */
  1976. #ifdef WIN32
  1977. #define WIN32_CHARNAMES
  1978. #endif
  1979. #ifdef UNIX
  1980. #define UNIX_CHARNAMES
  1981. #endif
  1982. /* When changed: extend CONSTOBJ, CHARSTRG, FORMAT.LISP. */
  1983. /* Whether to use the GNU gettext library for internationalization: */
  1984. #if defined(ENABLE_NLS) && !defined(NO_GETTEXT)
  1985. #define GNU_GETTEXT
  1986. #endif
  1987. /* Whether to create a stream *KEYBOARD-INPUT*
  1988. and whether it will be used for the stream *TERMINAL-IO*: */
  1989. #if (defined(UNIX) && !defined(NO_TERMCAP_NCURSES)) || defined(WIN32_NATIVE)
  1990. #define KEYBOARD
  1991. #if 0
  1992. #define TERMINAL_USES_KEYBOARD
  1993. #endif
  1994. #endif
  1995. /* When changed: extend stream.d, keyboard.lisp */
  1996. /* Whether to use the GNU readline library for *TERMINAL-IO*: */
  1997. #if defined(HAVE_READLINE) && !defined(NO_READLINE)
  1998. #define GNU_READLINE
  1999. #endif
  2000. /* Whether there are Window-streams and a package SCREEN: */
  2001. #if (defined(UNIX) && !defined(NO_TERMCAP_NCURSES)) || defined(WIN32_NATIVE)
  2002. #define SCREEN
  2003. #endif
  2004. /* When changed: extend stream.d (loads of work!). */
  2005. /* Whether there are Pipe-streams: */
  2006. #if defined(UNIX) || defined(WIN32_NATIVE)
  2007. #define PIPES
  2008. #if defined(UNIX) || defined(WIN32_NATIVE)
  2009. #define PIPES2 /* bidirectional pipes */
  2010. #endif
  2011. #endif
  2012. /* When changed: extend stream.d and runprog.lisp. */
  2013. /* If the system has sockets, we support socket streams:
  2014. We assume that if we have gethostbyname(), we have a networking OS
  2015. (Unix or Win32). Then we decide independently about UNIX domain connections
  2016. and TCP/IP connections. */
  2017. #if defined(HAVE_GETHOSTBYNAME) /* ==> defined(UNIX) || defined(WIN32_NATIVE) */
  2018. #ifdef HAVE_SYS_UN_H /* have <sys/un.h> and Unix domain sockets? */
  2019. #define UNIXCONN /* use Unix domain sockets */
  2020. #endif
  2021. #if defined(HAVE_NETINET_IN_H) || defined(WIN32_NATIVE) /* have <netinet/in.h> ? */
  2022. #define TCPCONN /* use TCP/IP sockets */
  2023. #endif
  2024. /* Now, which kinds of socket streams: */
  2025. #define X11SOCKETS /* works even without TCPCONN (very young Linux) */
  2026. #ifdef TCPCONN
  2027. #define SOCKET_STREAMS
  2028. #endif
  2029. #endif
  2030. /* When changed: extend stream.d, socket.d */
  2031. /* Whether there are generic streams: */
  2032. #if 1
  2033. #define GENERIC_STREAMS
  2034. #endif
  2035. /* When changed: do nothing */
  2036. /* Whether the OS provides the required information for the
  2037. functions MACHINE-TYPE, MACHINE-VERSION, MACHINE-INSTANCE */
  2038. #if defined(UNIX) || defined(WIN32_NATIVE)
  2039. #define MACHINE_KNOWN
  2040. #endif
  2041. /* When changed: extend misc.d, socket.d */
  2042. /* Whether there are LOGICAL-PATHNAMEs: */
  2043. #if 1
  2044. #define LOGICAL_PATHNAMES
  2045. #endif
  2046. /* When changed: do nothing */
  2047. /* Whether the function USER-HOMEDIR-PATHNAME exists: */
  2048. #if defined(UNIX) || defined(WIN32)
  2049. #define USER_HOMEDIR
  2050. #endif
  2051. /* When changed: extend pathname.d */
  2052. /* Whether the operating system manages an environment that associates Strings
  2053. with Strings */
  2054. #if defined(UNIX) || defined(WIN32)
  2055. #define HAVE_ENVIRONMENT
  2056. #endif
  2057. /* When changed: do nothing */
  2058. /* Whether the operating system has a preferred command-interpreter: */
  2059. #if defined(UNIX) || defined(WIN32_NATIVE)
  2060. #define HAVE_SHELL
  2061. #endif
  2062. /* When changed: extend pathname.d */
  2063. /* Whether a foreign function interface is provided: */
  2064. #if (defined(UNIX) && !defined(UNIX_BINARY_DISTRIB)) || defined(DYNAMIC_FFI)
  2065. #define HAVE_FFI
  2066. #endif
  2067. /* When changed: ?? */
  2068. /* Now the ones that are only relevant internally: */
  2069. /* Whether the GC closes files that aren't referenced any longer: */
  2070. #if defined(UNIX) || defined(WIN32)
  2071. #define GC_CLOSES_FILES
  2072. #endif
  2073. /* When changed: do nothing */
  2074. /* How time is measured: */
  2075. #ifdef UNIX
  2076. #if defined(HAVE_GETTIMEOFDAY) || defined(HAVE_FTIME)
  2077. #define TIME_UNIX
  2078. #elif defined(HAVE_TIMES_CLOCK)
  2079. #define TIME_UNIX_TIMES
  2080. #endif
  2081. #endif
  2082. #ifdef WIN32_NATIVE
  2083. #define TIME_WIN32
  2084. #endif
  2085. #if defined(TIME_UNIX_TIMES)
  2086. /* There's only a medium time resolution, so you can use 32-bit numbers
  2087. to store the time-differences without any problems. */
  2088. #define TIME_METHOD 1
  2089. /* We fetch the time once on system sart. All further times are taken
  2090. relatively to that one. */
  2091. #define TIME_RELATIVE
  2092. #elif defined(TIME_UNIX) || defined(TIME_WIN32)
  2093. /* The time resolution is so high that you need two 32-bit numbers to
  2094. measure time differences: seconds and and fractions of seconds. */
  2095. #define TIME_METHOD 2
  2096. /* In this case we can use absolute and relative times for measurements. */
  2097. #define TIME_ABSOLUTE
  2098. #else
  2099. #error TIME_METHOD is not defined
  2100. #endif
  2101. /* When changed: extend time.d */
  2102. /* Whether the operating system can give us the run-time, or whether we'll have
  2103. to accumulate it ourselves: */
  2104. #if defined(UNIX) || defined(WIN32_NATIVE)
  2105. #define HAVE_RUN_TIME
  2106. #endif
  2107. /* When changed: extend time.d */
  2108. /* Whether the operating system provides virtual memory. */
  2109. #if (defined(UNIX) || defined(WIN32)) && !defined(NO_VIRTUAL_MEMORY)
  2110. #define VIRTUAL_MEMORY
  2111. #endif
  2112. /* When changed: do nothing */
  2113. /* Whether the operating system allocates memory (via mmap or malloc) at
  2114. randomized locations. */
  2115. #if defined(UNIX_OPENBSD)
  2116. #define ADDRESS_RANGE_RANDOMIZED
  2117. #endif
  2118. /* When changed: do nothing */
  2119. /* Whether the operating system is capable of sending interruptions
  2120. (Ctrl-C and others) as signal: */
  2121. #if defined(UNIX)
  2122. #define HAVE_SIGNALS
  2123. #endif
  2124. /* pass on for clx/new-clx */
  2125. %% #ifdef HAVE_SIGNALS
  2126. %% puts("#define HAVE_SIGNALS");
  2127. %% #endif
  2128. /* Whether we can even react to asynchronous signals:
  2129. (If WIDE && !WIDE_HARD, writing a pointer is usually no elementary
  2130. operation anymore!) */
  2131. #if (defined(WIDE) && !defined(WIDE_HARD)) && !(defined(GNU) && defined(SPARC))
  2132. #define NO_ASYNC_INTERRUPTS
  2133. #endif
  2134. #if defined(NO_ASYNC_INTERRUPTS) && defined(MULTITHREAD)
  2135. #error "No multithreading possible with this memory model!"
  2136. #endif
  2137. /* When changed: extend SPVW, write a interruptp(). */
  2138. /* Flavors of Pathname-management: */
  2139. #ifdef UNIX
  2140. #define PATHNAME_UNIX
  2141. #endif
  2142. #ifdef WIN32
  2143. #define PATHNAME_WIN32
  2144. #endif
  2145. /* Components of pathnames: */
  2146. #ifdef PATHNAME_WIN32
  2147. #define HAS_HOST 1
  2148. #define HAS_DEVICE 1
  2149. #endif
  2150. #ifdef PATHNAME_UNIX
  2151. #define HAS_HOST 0
  2152. #define HAS_DEVICE 0
  2153. #endif
  2154. /* Handling of the file "extension" (pathname-type): */
  2155. #if 0
  2156. #define PATHNAME_EXT /* Name and Type are separated, so no limitation of the length */
  2157. #endif
  2158. #if defined(PATHNAME_UNIX) || defined(PATHNAME_WIN32)
  2159. #define PATHNAME_NOEXT /* no explicit extension. */
  2160. #endif
  2161. /* Whether "//" at the beginning of a pathname has to remain (and not to be shortened to "/"): */
  2162. #ifdef UNIX_CYGWIN32
  2163. #define PATHNAME_UNIX_UNC
  2164. #endif
  2165. /* When changed: extend pathname.d */
  2166. /* Whether there is a type FOREIGN (a wrapper for various kinds of pointers): */
  2167. #if defined(UNIX) || defined(DYNAMIC_FFI) || defined(WIN32_NATIVE)
  2168. /* (Used by FFI and by CLX.) */
  2169. #define FOREIGN void*
  2170. #endif
  2171. /* When changed: do nothing */
  2172. %% #ifdef FOREIGN
  2173. %% export_def(FOREIGN);
  2174. %% #endif
  2175. /* Whether the STACK is checked at certain key points: */
  2176. #define STACKCHECKS (SAFETY >= 1) /* when SUBRs and FSUBRs are called */
  2177. #define STACKCHECKC (SAFETY >= 1) /* when compiled closures are interpreted */
  2178. #define STACKCHECKR (SAFETY >= 1) /* in the reader */
  2179. #define STACKCHECKP (SAFETY >= 1) /* in the printer */
  2180. #define STACKCHECKB (SAFETY >= 1) /* in the bindings */
  2181. /* When changed: do nothing */
  2182. /* Feature dependent include files. */
  2183. #ifdef HAVE_ICONV
  2184. #include <stdlib.h>
  2185. #include <iconv.h>
  2186. #if _LIBICONV_VERSION
  2187. /* We use GNU libiconv. */
  2188. #define GNU_LIBICONV
  2189. #define HAVE_GOOD_ICONV
  2190. #elif (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2))
  2191. /* glibc-2.2 iconv is also very reliable. Use it. */
  2192. #define HAVE_GOOD_ICONV
  2193. #else
  2194. /* Other iconv implementations are too unreliable.
  2195. Don't define HAVE_GOOD_ICONV. */
  2196. #endif
  2197. #endif
  2198. /* ############### List of implemented CLtL2-features ############### */
  2199. #define X3J13_005 /* 18.5.1993 */
  2200. #define X3J13_014 /* 22.1.1995 */
  2201. #define X3J13_149 /* 22.7.1993 */
  2202. #define X3J13_175 /* 25.7.1993 */
  2203. /* ##################### Memory representation of objects ###################
  2204. Memory Representation and the Type Code of the various data types
  2205. =================================================================
  2206. 1. The type code
  2207. ----------------
  2208. An object consists of - in the same word - some type information and, for
  2209. immediate types, a couple of data bits, or, for heap allocated types,
  2210. a pointer to memory. There are many models of mixing type and pointer.
  2211. In the standard model, 6 to 8 bits (the word's high bits) are used for the
  2212. type. In the WIDE_HARD and WIDE_SOFT models, type and pointer are each 32
  2213. bits. In the HEAPCODES model, there are only 2 to 6 bits.
  2214. One bit (normally bit 31) is used as mark bit by the garbage collector.
  2215. Outside of GC, it is always cleared. (Except for the get_circularities and
  2216. subst_circ routines, and in the STACK, the GC bit is used for marking frames.)
  2217. 2. Memory formats
  2218. -----------------
  2219. 2.1. Immediate objects
  2220. 2.1.1. Machine pointers
  2221. Machine pointers are immediate objects. They may point to the code area
  2222. (.text segment), to data areas (.bss, .data segments, malloc'ed areas).
  2223. Other values (e.g. pointers to text/data in shared libraries) are not
  2224. allowed, because they may contain bits which are interpreted as a type code.
  2225. To use such machine addresses, you must wrap them in foreign-pointers or
  2226. simple-bit-vectors.
  2227. 2.1.2. Other immediate objects
  2228. Character, Fixnum, Short-Float, and, if IMMEDIATE_FFLOAT, Single-Float.
  2229. Furthermore: Frame-Pointer, Small-Read-Label, System. (System means some
  2230. finite number of special values, such as #<UNBOUND>.)
  2231. 2.2. SUBRs
  2232. They are immediate in the sense that they do not move (they do not need to,
  2233. because they are allocated statically), but they have to be traversed by GC.
  2234. 2.3. Pairs
  2235. These are heap objects containing just two pointers: Cons and, if SPVW_PURE,
  2236. Ratio and Complex.
  2237. 2.4. Varobjects
  2238. These are heap objects of varying size. GC needs a header word at the
  2239. beginning of the object.
  2240. 2.4.1. Records
  2241. These are varobjects which have additional type information and flags
  2242. in the second header word. Closure, Structure, Stream, Instance are always
  2243. records. Depending on the memory model, arrays, symbols etc. may or may
  2244. not be records.
  2245. 2.4.2. Arrays
  2246. Simple-Bit-Vector, Simple-String, Simple-Vector are the "simple" arrays.
  2247. The non-simple ones are represented by a Iarray, yet the type code gives
  2248. some information about the rank, the representation and the element type:
  2249. | "simple" | "not simple" |
  2250. | Sarray | Iarray |
  2251. ------------------------------+-----------------+----------------+
  2252. (vector bit) | sbvector_type | bvector_type |
  2253. ------------------------------+-----------------+----------------+
  2254. (vector (unsigned-byte 2)) | sb2vector_type | b2vector_type |
  2255. ------------------------------+-----------------+----------------+
  2256. (vector (unsigned-byte 4)) | sb4vector_type | b4vector_type |
  2257. ------------------------------+-----------------+----------------+
  2258. (vector (unsigned-byte 8)) | sb8vector_type | b8vector_type |
  2259. ------------------------------+-----------------+----------------+
  2260. (vector (unsigned-byte 16)) | sb16vector_type | b16vector_type |
  2261. ------------------------------+-----------------+----------------+
  2262. (vector (unsigned-byte 32)) | sb32vector_type | b32vector_type |
  2263. ------------------------------+-----------------+----------------+
  2264. (vector character) | sstring_type | string_type |
  2265. ------------------------------+-----------------+----------------+
  2266. (vector t) | svector_type | vector_type |
  2267. ------------------------------+-----------------+----------------+
  2268. array of dimension /= 1 | -- | mdarray_type |
  2269. ------------------------------+-----------------+----------------+
  2270. 2.4.3. Other varobjects
  2271. Symbol has some special flags (keyword, constant, special) in the header,
  2272. if possible.
  2273. FSUBR, Bignum, Single-Float (unless IMMEDIATE_FFLOAT), Double-Float,
  2274. Long-Float, Ratio and Complex (only if SPVW_MIXED).
  2275. ######################## LISP-objects in general ######################## */
  2276. #if defined(DEBUG_GCSAFETY)
  2277. #ifndef __cplusplus
  2278. #error "DEBUG_GCSAFETY works only with a C++ compiler! Reconfigure with CC=g++."
  2279. #endif
  2280. #if defined(WIDE_SOFT) || defined(WIDE_AUXI)
  2281. #error "DEBUG_GCSAFETY cannot be used together with WIDE_SOFT or WIDE_AUXI (not yet implemented)!"
  2282. #endif
  2283. /* The 'gcv_object_t' and 'object' types share the major part of their innards. */
  2284. #ifndef OBJECT_STRUCT
  2285. #define OBJECT_STRUCT
  2286. #endif
  2287. #endif
  2288. /* The type 'object' denotes an object in registers or in memory that is
  2289. not seen by the GC.
  2290. The type `gcv_object_t' denotes a GC visible object, i.e. a slot inside
  2291. a heap-allocated object or a STACK slot. If its value is not an immediate
  2292. object, any call that can trigger GC can modify the pointer value.
  2293. NEVER write "var gcv_object_t foo;" - this is forbidden!
  2294. You can write "var gcunsafe_object_t foo;" instead - but then you must not
  2295. trigger GC during the entire lifetime of the variable 'foo'! */
  2296. %% #if (defined(WIDE_AUXI) || defined(OBJECT_STRUCT) || defined(WIDE_STRUCT)) && defined(WIDE) && !defined(WIDE_HARD) && defined(GENERATIONAL_GC)
  2297. %% #define attribute_aligned_object " __attribute__ ((aligned(8)))"
  2298. %% #else
  2299. %% #define attribute_aligned_object ""
  2300. %% #endif
  2301. #if !defined(WIDE_SOFT)
  2302. /* An object pointer is an empty pointer to begin with (so you cannot do
  2303. anything unwanted with it in C): */
  2304. #if defined(WIDE_AUXI)
  2305. /* Make room for an auxiliary word in every object.
  2306. The struct around the union is needed to work around a gcc-2.95 bug. */
  2307. #if BIG_ENDIAN_P
  2308. #define INNARDS_OF_GCV_OBJECT \
  2309. union { \
  2310. struct { uintP auxi_ob; uintP one_ob; } both; \
  2311. oint align_o _attribute_aligned_object_; \
  2312. } u _attribute_aligned_object_;
  2313. #else
  2314. #define INNARDS_OF_GCV_OBJECT \
  2315. union { \
  2316. struct { uintP one_ob; uintP auxi_ob; } both; \
  2317. oint align_o _attribute_aligned_object_; \
  2318. } u _attribute_aligned_object_;
  2319. #endif
  2320. #define one_o u.both.one_ob
  2321. #define auxi_o u.both.auxi_ob
  2322. #elif defined(OBJECT_STRUCT)
  2323. #define INNARDS_OF_GCV_OBJECT \
  2324. uintP one_o;
  2325. #else
  2326. typedef void * gcv_object_t;
  2327. #endif
  2328. /* But there is an address and type bits in the representation. */
  2329. /* An (unsigned) Integer of the object's size: */
  2330. #ifdef WIDE_AUXI
  2331. typedef uint64 oint;
  2332. typedef sint64 soint;
  2333. #else
  2334. typedef uintP oint;
  2335. typedef sintP soint;
  2336. #endif
  2337. #else /* defined(WIDE_SOFT) */
  2338. /* An object consists of a separated 32 bit address and a 32 bit type info. */
  2339. typedef uint64 oint;
  2340. typedef sint64 soint;
  2341. #ifdef WIDE_STRUCT
  2342. /* The struct around the union is needed to work around a gcc-2.95 bug. */
  2343. #if BIG_ENDIAN_P==WIDE_ENDIANNESS
  2344. #define INNARDS_OF_GCV_OBJECT \
  2345. union { \
  2346. struct { /* tint */ uintL type; /* aint */ uintL addr; } both; \
  2347. oint one_u _attribute_aligned_object_; \
  2348. } u _attribute_aligned_object_;
  2349. #else
  2350. #define INNARDS_OF_GCV_OBJECT \
  2351. union { \
  2352. struct { /* aint */ uintL addr; /* tint */ uintL type; } both; \
  2353. oint one_u _attribute_aligned_object_; \
  2354. } u _attribute_aligned_object_;
  2355. #endif
  2356. #define one_o u.one_u
  2357. #else
  2358. typedef oint gcv_object_t;
  2359. #endif
  2360. #endif
  2361. /* sizeof(gcv_object_t) = sizeof(oint) must hold true! */
  2362. %% #if !defined(WIDE_SOFT)
  2363. %% #if defined(WIDE_AUXI)
  2364. %% strcpy(buf,"struct { union { struct { ");
  2365. %% #if BIG_ENDIAN_P
  2366. %% strcat(buf,"uintP auxi_ob; uintP one_ob;");
  2367. %% #else
  2368. %% strcat(buf,"uintP one_ob; uintP auxi_ob;");
  2369. %% #endif
  2370. %% strcat(buf," } both; oint align_o");
  2371. %% strcat(buf,attribute_aligned_object);
  2372. %% strcat(buf,"; } u");
  2373. %% strcat(buf,attribute_aligned_object);
  2374. %% strcat(buf,"; }");
  2375. %% emit_typedef(buf,"gcv_object_t");
  2376. %% emit_define("one_o","u.both.one_ob");
  2377. %% emit_define("auxi_o","u.both.auxi_ob");
  2378. %% #elif defined(OBJECT_STRUCT)
  2379. %% #ifdef DEBUG_GCSAFETY
  2380. %% puts("struct object { uintP one_o; uintL allocstamp; };");
  2381. %% puts("struct gcv_object_t { uintP one_o; operator object () const; gcv_object_t (object obj); gcv_object_t (struct fake_gcv_object obj); gcv_object_t (); };");
  2382. %% #else
  2383. %% emit_typedef("struct { uintP one_o; }","gcv_object_t");
  2384. %% #endif
  2385. %% #else
  2386. %% emit_typedef("void *","gcv_object_t");
  2387. %% #endif
  2388. %% #ifdef WIDE_AUXI
  2389. %% emit_typedef("uint64","oint");
  2390. %% emit_typedef("sint64","soint");
  2391. %% #else
  2392. %% emit_typedef("uintP","oint");
  2393. %% emit_typedef("sintP","soint");
  2394. %% #endif
  2395. %% #else
  2396. %% emit_typedef("uint64","oint");
  2397. %% emit_typedef("sint64","soint");
  2398. %% #ifdef WIDE_STRUCT
  2399. %% strcpy(buf,"struct { union {\n");
  2400. %% #if BIG_ENDIAN_P==WIDE_ENDIANNESS
  2401. %% strcat(buf," struct { /*tint*/ uintL type; /*aint*/ uintL addr; } both;\n");
  2402. %% #else
  2403. %% strcat(buf," struct { /*aint*/ uintL addr; /*tint*/ uintL type; } both;\n");
  2404. %% #endif
  2405. %% strcat(buf," oint one_u");
  2406. %% strcat(buf,attribute_aligned_object);
  2407. %% strcat(buf,"; } u");
  2408. %% strcat(buf,attribute_aligned_object);
  2409. %% strcat(buf,"; }");
  2410. %% emit_typedef(buf,"gcv_object_t");
  2411. %% emit_define("one_o","u.one_u");
  2412. %% #else
  2413. %% emit_typedef("oint","gcv_object_t");
  2414. %% #endif
  2415. %% #endif
  2416. /* conversion between gcv_object_t/object and oint:
  2417. as_oint(expr) gcv_object_t/object --> oint
  2418. as_object(x) oint --> gcv_object_t
  2419. The conversion gcv_object_t --> object
  2420. is implicit. */
  2421. #if defined(WIDE_STRUCT) || defined(OBJECT_STRUCT)
  2422. #define as_oint(expr) ((expr).one_o)
  2423. #if defined(WIDE_STRUCT)
  2424. #define as_object(o) ((object){u:{one_u:(o)}INIT_ALLOCSTAMP})
  2425. #elif defined(OBJECT_STRUCT)
  2426. #define as_object(o) ((object){one_o:(o)INIT_ALLOCSTAMP})
  2427. #else
  2428. extern __inline__ object as_object (register oint o)
  2429. { register object obj; obj.one_o = o; return obj; }
  2430. #endif
  2431. #elif defined(WIDE_AUXI)
  2432. #define as_oint(expr) ((expr).u.align_o)
  2433. /* These could store arbitrary information in auxi_o. */
  2434. #define as_object_with_auxi(o) ((object){u:{both:{ one_ob: (o), auxi_ob: 0 }} INIT_ALLOCSTAMP })
  2435. #define as_object(o) ((object){u:{align_o:(o)}INIT_ALLOCSTAMP})
  2436. #else
  2437. #define as_oint(expr) (oint)(expr)
  2438. #define as_object(o) (gcv_object_t)(o)
  2439. #endif
  2440. %% export_def(as_oint(expr));
  2441. %% export_def(as_object(o));
  2442. /* Separation of an oint in type bits and address:
  2443. oint_type_mask is always subset (2^oint_type_len-1)<<oint_type_shift
  2444. and oint_addr_mask superset (2^oint_addr_len-1)<<oint_addr_shift . */
  2445. #if !defined(TYPECODES)
  2446. /* HEAPCODES model:
  2447. For pointers, the address takes the full word (with type info in the
  2448. lowest two bits). For immediate objects, we use 24 bits for the data
  2449. (but exclude the highest available bit, which is the garcol_bit). */
  2450. #if !(defined(STANDARD_HEAPCODES) || defined(LINUX_NOEXEC_HEAPCODES))
  2451. /* Choose the appropriate HEAPCODES variant for the machine.
  2452. On most systems, one of the high bits is suitable as GC bit; here we
  2453. choose STANDARD_HEAPCODES.
  2454. On some Linux/x86 systems, starting in 2004, a "no-exec" kernel patch
  2455. is used that distributes virtual addresses over the entire address
  2456. space from 0x00000000 to 0xBFFFFFFF (as a function of its access
  2457. permissions); here we use LINUX_NOEXEC_HEAPCODES.
  2458. On OpenBSD 3.8 or newer, starting in 2005, the addresses of mmap and
  2459. malloc results (and hence also of shared libraries) are randomized;
  2460. only the code address is fixed around 0x1C000000 and the stack address
  2461. is around 0xCF000000. In this case, we also use LINUX_NOEXEC_HEAPCODES. */
  2462. #if (defined(I80386) && defined(UNIX_LINUX)) || (defined(I80386) && defined(UNIX_OPENBSD) && defined(ADDRESS_RANGE_RANDOMIZED))
  2463. #define LINUX_NOEXEC_HEAPCODES
  2464. #else
  2465. #define STANDARD_HEAPCODES
  2466. #endif
  2467. #endif
  2468. #ifdef STANDARD_HEAPCODES
  2469. /* The portable case. Assumes only that the GC bit can be chosen. */
  2470. #if defined(SPARC) && defined(UNIX_LINUX) && (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 2))
  2471. #define LINUX_SPARC_OLD_GLIBC
  2472. #endif
  2473. #if defined(WIDE_HARD)
  2474. #define oint_type_shift 0
  2475. #define oint_type_len 8
  2476. #define oint_type_mask 0x000000000000007FUL
  2477. #define oint_data_shift 7
  2478. #define oint_data_len 48
  2479. #define oint_data_mask 0x007FFFFFFFFFFF80UL
  2480. #define garcol_bit_o 63
  2481. #elif !((defined(MC680X0) && defined(UNIX_LINUX)) || (defined(I80386) && defined(UNIX_BEOS)) || defined(LINUX_SPARC_OLD_GLIBC))
  2482. #define oint_type_shift 0
  2483. #define oint_type_len 8
  2484. #define oint_type_mask 0x0000007FUL
  2485. #define oint_data_shift 7
  2486. #define oint_data_len 24
  2487. #define oint_data_mask 0x7FFFFF80UL
  2488. #define garcol_bit_o 31
  2489. #elif defined(I80386) && defined(UNIX_BEOS)
  2490. /* On BeOS 5, malloc()ed addresses are of the form 0x80...... Bit 31
  2491. is therefore part of an address and cannot be used as garcol_bit. */
  2492. #define oint_type_shift 0
  2493. #define oint_type_len 8
  2494. #define oint_type_mask 0x0000003FUL
  2495. #define oint_data_shift 6
  2496. #define oint_data_len 24
  2497. #define oint_data_mask 0x3FFFFFC0UL
  2498. #define garcol_bit_o 30
  2499. #elif (defined(MC680X0) && defined(UNIX_LINUX)) || defined(LINUX_SPARC_OLD_GLIBC)
  2500. /* On Sparc-Linux with glibc 2.1 and older:
  2501. malloc()ed addresses are of the form 0x0....... or 0xe........
  2502. Bits 31..29 are therefore part of an address and cannot
  2503. be used as garcol_bit. We therefore choose bit 28 as garcol_bit.
  2504. Now, the 24 data bits of an immediate value must not intersect the
  2505. garcol_bit, so we use bits 27..4 for that (we could use bits 26..3
  2506. as well).
  2507. On m68k-Linux, malloc()ed addresses are of the form 0x80...... or
  2508. 0xc0....... Bits 31..30 are therefore part of an address and cannot
  2509. be used as garcol_bit. We therefore have three choices:
  2510. data bits: bits 26..3, garcol_bit_o = 28/27
  2511. data bits: bits 27..4, garcol_bit_o = 28/3
  2512. data bits: bits 28..5, garcol_bit_o = 4/3 */
  2513. #define oint_type_shift 0
  2514. #define oint_type_len 32
  2515. #define oint_type_mask 0xE000000FUL
  2516. #define oint_data_shift 4
  2517. #define oint_data_len 24
  2518. #define oint_data_mask 0x0FFFFFF0UL
  2519. #define garcol_bit_o 28
  2520. #endif
  2521. #endif /* STANDARD_HEAPCODES */
  2522. #ifdef LINUX_NOEXEC_HEAPCODES
  2523. /* The Linux/32-bit case. Assumes 1. that the virtual memory addresses end
  2524. at 0xC0000000, or at least that we can put a black hole on the range
  2525. 0xC0000000..0xDFFFFFFF, 2. that the compiler and linker can enforce an
  2526. 8-byte alignment of symbol_tab and subr_tab.
  2527. Only bit 0 or 1 can be used as GC-bit. */
  2528. #define oint_type_shift 0
  2529. #define oint_type_len 32
  2530. #define oint_type_mask 0xE000001FUL
  2531. #define oint_data_shift 5
  2532. #define oint_data_len 24
  2533. #define oint_data_mask 0x1FFFFFE0UL
  2534. #define garcol_bit_o 0
  2535. #endif /* LINUX_NOEXEC_HEAPCODES */
  2536. #if defined(WIDE_HARD)
  2537. #define oint_addr_shift 0
  2538. #define oint_addr_len 64
  2539. #define oint_addr_mask 0xFFFFFFFFFFFFFFFFUL
  2540. #else
  2541. #define oint_addr_shift 0
  2542. #define oint_addr_len 32
  2543. #define oint_addr_mask 0xFFFFFFFFUL
  2544. #endif
  2545. /* Now come the platforms with TYPECODES. oint_type_len should be >= 8,
  2546. and oint_type_mask should have at least 8 bits set and at most one bit in
  2547. common with oint_addr_mask. */
  2548. #elif defined(WIDE_HARD)
  2549. #if defined(DECALPHA) && (defined(UNIX_OSF) || defined(UNIX_LINUX) || defined(UNIX_FREEBSD) || defined(UNIX_NETBSD))
  2550. /* UNIX_OSF:
  2551. Ordinary pointers are in the range 1*2^32..2*2^32.
  2552. Code address range: 0x000000012xxxxxxx
  2553. Malloc address range: 0x000000014xxxxxxx
  2554. Shared libraries: 0x000003FFCxxxxxxx
  2555. UNIX_LINUX:
  2556. Code address range: 0x000000012xxxxxxx
  2557. Malloc address range: 0x000000012xxxxxxx
  2558. and: 0x0000015555xxxxxx
  2559. Shared libraries: 0x0000015555xxxxxx
  2560. Virtual address limit: 0x0000040000000000
  2561. UNIX_FREEBSD
  2562. Code address range: 0x0000000120000000
  2563. Malloc address range: 0x0000000120000000
  2564. Shared libraries: 0x0000000160000000
  2565. Stack address range: 0x0000000011000000
  2566. UNIX_NETBSD
  2567. Code address range: 0x0000000120000000
  2568. Malloc address range: 0x0000000120000000
  2569. Shared libraries: 0x0000000160000000
  2570. Stack address range: 0x00000001FF000000 */
  2571. /* This is the safest.
  2572. Bits 63..48 = type code, Bits 47..0 = address */
  2573. #define oint_type_shift 48
  2574. #define oint_type_len 16
  2575. #define oint_type_mask 0xFFFF000000000000UL
  2576. #define oint_addr_shift 0
  2577. #define oint_addr_len 48
  2578. #define oint_addr_mask 0x0000FFFFFFFFFFFFUL
  2579. #define oint_data_shift oint_addr_shift
  2580. #define oint_data_len oint_addr_len
  2581. #define oint_data_mask oint_addr_mask
  2582. #endif
  2583. #if defined(MIPS64)
  2584. /* Bits 63..48 = type code, bits 31..0 = address */
  2585. #define oint_type_shift 48
  2586. #define oint_type_len 16
  2587. #define oint_type_mask 0xFFFF000000000000UL
  2588. #define oint_addr_shift 0
  2589. #define oint_addr_len 64
  2590. #define oint_addr_mask 0x00000000FFFFFFFFUL
  2591. #define oint_data_shift 0
  2592. #define oint_data_len 48
  2593. #define oint_data_mask 0x0000FFFFFFFFFFFFUL
  2594. #endif
  2595. #if defined(SPARC64)
  2596. /* Virtual address limit on some systems: -2^43..2^43.
  2597. This is the safest.
  2598. Bits 63..48 = type code, bits 47..0 = address */
  2599. #define oint_type_shift 48
  2600. #define oint_type_len 16
  2601. #define oint_type_mask 0xFFFF000000000000UL
  2602. #define oint_addr_shift 0
  2603. #define oint_addr_len 48
  2604. #define oint_addr_mask 0x0000FFFFFFFFFFFFUL
  2605. #define oint_data_shift oint_addr_shift
  2606. #define oint_data_len oint_addr_len
  2607. #define oint_data_mask oint_addr_mask
  2608. #endif
  2609. #if defined(IA64) && defined(UNIX_LINUX)
  2610. /* Bits 63..61 = region code,
  2611. bits 60..39 all zero or all one,
  2612. virtual address limit: R*2^61..R*2^61+2^39, (R+1)*2^61-2^39..(R+1)*2^61.
  2613. SHLIB_ADDRESS_RANGE = 0x2000000000000000UL (region 1)
  2614. CODE_ADDRESS_RANGE = 0x4000000000000000UL (region 2)
  2615. MALLOC_ADDRESS_RANGE = 0x6000000000000000UL (region 3)
  2616. STACK_ADDRESS_RANGE = 0x9FFFFFFFFF000000UL (region 4)
  2617. This is the safest.
  2618. Bits 63..48 = Typcode, Bits 47..0 = address */
  2619. #define oint_type_shift 48
  2620. #define oint_type_len 16
  2621. #define oint_type_mask 0x1FFF000000000000UL
  2622. #define oint_addr_shift 0
  2623. #define oint_addr_len 64
  2624. #define oint_addr_mask 0xE000FFFFFFFFFFFFUL
  2625. #define oint_data_shift 0
  2626. #define oint_data_len 48
  2627. #define oint_data_mask 0x0000FFFFFFFFFFFFUL
  2628. #endif
  2629. #if defined(AMD64)
  2630. /* UNIX_LINUX:
  2631. CODE_ADDRESS_RANGE 0x0000000000000000UL
  2632. MALLOC_ADDRESS_RANGE 0x0000000000000000UL
  2633. SHLIB_ADDRESS_RANGE 0x00000034F5000000UL
  2634. STACK_ADDRESS_RANGE 0x0000007FBF000000UL
  2635. UNIX_FREEBSD
  2636. CODE_ADDRESS_RANGE 0x0000000000000000UL
  2637. MALLOC_ADDRESS_RANGE 0x0000000000000000UL
  2638. SHLIB_ADDRESS_RANGE 0x0000000800000000UL
  2639. STACK_ADDRESS_RANGE 0x00007FFFFF000000UL
  2640. Bits 63..48 = type code, Bits 47..0 = address */
  2641. #define oint_type_shift 48
  2642. #define oint_type_len 16
  2643. #define oint_type_mask 0xFFFF000000000000UL
  2644. #define oint_addr_shift 0
  2645. #define oint_addr_len 48
  2646. #define oint_addr_mask 0x0000FFFFFFFFFFFFUL
  2647. #define oint_data_shift oint_addr_shift
  2648. #define oint_data_len oint_addr_len
  2649. #define oint_data_mask oint_addr_mask
  2650. #endif
  2651. #elif defined(WIDE_SOFT)
  2652. /* separate one 32-bit word for typcode and address. */
  2653. #if defined(WIDE_SOFT_LARGEFIXNUM)
  2654. /* Used to test large fixnums on 32-bit platforms.
  2655. Bits 63..48 = Typcode, Bits 47..32 = zero, Bits 31..0 = address */
  2656. #define oint_type_shift 48
  2657. #define oint_type_len 16
  2658. #define oint_type_mask ULL(0xFFFF000000000000)
  2659. #define oint_addr_shift 0
  2660. #define oint_addr_len 48
  2661. #define oint_addr_mask ULL(0x0000FFFFFFFFFFFF)
  2662. #elif WIDE_ENDIANNESS
  2663. /* Bits 63..32 = Typcode, Bits 31..0 = address */
  2664. #define oint_type_shift 32
  2665. #define oint_type_len 32
  2666. #define oint_type_mask ULL(0xFFFFFFFF00000000)
  2667. #define oint_addr_shift 0
  2668. #define oint_addr_len 32
  2669. #define oint_addr_mask ULL(0x00000000FFFFFFFF)
  2670. #else /* conversely it is a little slower: */
  2671. /* Bits 63..32 = Adress, Bits 31..0 = Typcode */
  2672. #define oint_type_shift 0
  2673. #define oint_type_len 32
  2674. #define oint_type_mask ULL(0x00000000FFFFFFFF)
  2675. #define oint_addr_shift 32
  2676. #define oint_addr_len 32
  2677. #define oint_addr_mask ULL(0xFFFFFFFF00000000)
  2678. #endif
  2679. /* Now come the 32-bit platforms with TYPECODES. We need to support it only on
  2680. MC680X0 platforms without new gcc.
  2681. It worked on the following platforms in the past, and may still work on:
  2682. (defined(MC680X0) && !defined(UNIX_AMIX) && !defined(UNIX_NEXTSTEP) && !(defined(UNIX_LINUX) && CODE_ADDRESS_RANGE))
  2683. (defined(I80386) && !(defined(UNIX_LINUX) && (CODE_ADDRESS_RANGE != 0)) && !defined(UNIX_HURD) && !defined(UNIX_SYSV_UHC_1) && !defined(UNIX_NEXTSTEP) && !defined(UNIX_SYSV_PTX) && !defined(UNIX_SUNOS5) && !defined(UNIX_CYGWIN32) && !defined(WIN32_NATIVE))
  2684. (defined(SPARC) && !defined(SUN4_29))
  2685. (defined(MIPS) && !defined(UNIX_IRIX) && !defined(UNIX_DEC_ULTRIX))
  2686. defined(M88000)
  2687. (defined(POWERPC) && !defined(UNIX_AIX) && !defined(UNIX_LINUX))
  2688. defined(VAX) */
  2689. #elif (defined(I80386) && ((defined(UNIX_LINUX) && (CODE_ADDRESS_RANGE != 0)) || (defined(UNIX_FREEBSD) && !defined(UNIX_GNU)))) || (defined(POWERPC) && defined(UNIX_DARWIN)) || defined(TRY_TYPECODES_1)
  2690. /* You can add more platforms here provided that
  2691. 1. you need it,
  2692. 2. CODE_ADDRESS_RANGE | MALLOC_ADDRESS_RANGE has at most one bit set,
  2693. 3. it works. */
  2694. #define oint_type_shift 24
  2695. #define oint_type_len 8
  2696. #define oint_type_mask (0xFF000000UL & ~(CODE_ADDRESS_RANGE | MALLOC_ADDRESS_RANGE))
  2697. #define oint_addr_shift 0
  2698. #define oint_addr_len 24
  2699. #define oint_addr_mask (0x00FFFFFFUL | CODE_ADDRESS_RANGE | MALLOC_ADDRESS_RANGE)
  2700. #define oint_data_shift 0
  2701. #define oint_data_len 24
  2702. #define oint_data_mask 0x00FFFFFFUL
  2703. #elif 0 || defined(TRY_TYPECODES_2)
  2704. /* You can add more platforms here provided that
  2705. 1. you need it,
  2706. 2. it works.
  2707. Bits 31..24 = Typcode, Bits 23..0 = Adress */
  2708. #define oint_type_shift 24
  2709. #define oint_type_len 8
  2710. #define oint_type_mask 0xFF000000UL
  2711. #define oint_addr_shift 0
  2712. #define oint_addr_len 24
  2713. #define oint_addr_mask 0x00FFFFFFUL
  2714. #else
  2715. #error "TYPECODES maybe not supported any more on this platform. Try defining TRY_TYPECODES_1 or TRY_TYPECODES_2, or use -DHEAPCODES."
  2716. #endif
  2717. %% #if notused
  2718. %% export_def(oint_type_shift);
  2719. %% export_def(oint_type_len);
  2720. %% export_def(oint_type_mask);
  2721. %% export_def(oint_addr_shift);
  2722. %% export_def(oint_addr_len);
  2723. %% export_def(oint_addr_mask);
  2724. %% #endif
  2725. #ifndef oint_type_len
  2726. #error "CLISP has not been ported to this platform - oint_type_len undefined"
  2727. #endif
  2728. /* Generally we use all of the space of an address for the data of Fixnums etc.
  2729. Always [oint_data_shift..oint_data_shift+oint_data_len-1] is subset of
  2730. [oint_addr_shift..oint_addr_shift+oint_addr_len-1],
  2731. thus oint_data_len <= oint_addr_len. */
  2732. #ifndef oint_data_len
  2733. #define oint_data_shift oint_addr_shift
  2734. #define oint_data_len oint_addr_len
  2735. #define oint_data_mask oint_addr_mask
  2736. #endif
  2737. %% #if notused
  2738. %% export_def(oint_data_shift);
  2739. %% export_def(oint_data_len);
  2740. %% export_def(oint_data_mask);
  2741. %% #endif
  2742. /* Integer type for typebits: */
  2743. typedef unsigned_int_with_n_bits(oint_type_len) tint;
  2744. %% sprintf(buf,"uint%d",oint_type_len); emit_typedef(buf,"tint");
  2745. /* Integer type for addresses: */
  2746. typedef unsigned_int_with_n_bits(oint_addr_len) aint;
  2747. typedef signed_int_with_n_bits(oint_addr_len) saint;
  2748. %% sprintf(buf,"uint%d",oint_addr_len); emit_typedef(buf,"aint");
  2749. %% #if notused
  2750. %% sprintf(buf,"sint%d",oint_addr_len); emit_typedef(buf,"saint");
  2751. %% #endif
  2752. /* Integer type for immediate values:
  2753. Always 32 = intLsize <= intVsize <= 64. */
  2754. #if (oint_data_len <= 32)
  2755. #define intVsize 32
  2756. #else
  2757. #define intVsize 64
  2758. #endif
  2759. typedef unsigned_int_with_n_bits(intVsize) uintV;
  2760. typedef signed_int_with_n_bits(intVsize) sintV;
  2761. %% sprintf(buf,"uint%d",intVsize); emit_typedef(buf,"uintV");
  2762. %% sprintf(buf,"sint%d",intVsize); emit_typedef(buf,"sintV");
  2763. /* Integer type used to represent an amount of memory:
  2764. (This may be larger than size_t or ptrdiff_t: size_t is required by ISO C to
  2765. be enough for the size of a single memory block; ptrdiff_t is required by
  2766. ISO C to be enough for the size of a single memory block plus room for a sign
  2767. bit. But on segmented architectures which allow many medium-sized memory
  2768. blocks, like the 80286 was, the total available memory size may be bigger.
  2769. Also, we avoid size_t because it's likely to be wrong on 64-bit Woe32.) */
  2770. #if !defined(WIDE_HARD) || ((oint_addr_mask & ~0xFFFFFFFFUL) == 0)
  2771. /* A 32-bit integer is sufficient. */
  2772. #define intMsize intLsize
  2773. typedef uintL uintM;
  2774. typedef sintL sintM;
  2775. #else
  2776. /* An integer as wide as a pointer may be required. */
  2777. #define intMsize pointer_bitsize
  2778. typedef uintP uintM;
  2779. typedef sintP sintM;
  2780. #endif
  2781. /* Number of bits by which an address is finally being shifted: */
  2782. #ifndef addr_shift
  2783. #define addr_shift 0
  2784. #endif
  2785. %% #if notused
  2786. %% export_def(addr_shift);
  2787. %% #endif
  2788. /* Verify the values w.r.t. the autoconfigured CODE_ADDRESS_RANGE and
  2789. MALLOC_ADDRESS_RANGE values. */
  2790. #if !defined(WIDE_SOFT)
  2791. #if (CODE_ADDRESS_RANGE >> addr_shift) & ~(oint_addr_mask >> oint_addr_shift)
  2792. #error "oint_addr_mask doesn't cover CODE_ADDRESS_RANGE !!"
  2793. #endif
  2794. #if (MALLOC_ADDRESS_RANGE >> addr_shift) & ~(oint_addr_mask >> oint_addr_shift)
  2795. #error "oint_addr_mask doesn't cover MALLOC_ADDRESS_RANGE !!"
  2796. #endif
  2797. #endif
  2798. #if (oint_addr_shift == 0) && (addr_shift == 0) && defined(TYPECODES) && !defined(WIDE_SOFT) && !(defined(SUN3) && !defined(UNIX_SUNOS4) && !defined(WIDE_SOFT)) && !(defined(AMD64) && defined(UNIX_LINUX))
  2799. /* If the address bits are the lower ones and not WIDE_SOFT,
  2800. memory mapping may be possible. */
  2801. #if (defined(HAVE_MMAP_ANON) || defined(HAVE_MMAP_DEVZERO) || defined(HAVE_MACH_VM) || defined(HAVE_WIN32_VM)) && !defined(MULTIMAP_MEMORY) && !(defined(UNIX_SINIX) || defined(UNIX_AIX)) && !defined(NO_SINGLEMAP)
  2802. /* Access to LISP-objects is made easier by putting each LISP-object
  2803. to an address that already contains its type information.
  2804. But this does not work on SINIX and AIX. */
  2805. #define SINGLEMAP_MEMORY
  2806. #endif
  2807. #if defined(UNIX_SUNOS4) && !defined(MULTIMAP_MEMORY) && !defined(SINGLEMAP_MEMORY) && !defined(NO_MULTIMAP_FILE)
  2808. /* Access to Lisp-objects is done through memory-mapping: Each
  2809. memory page can be accessed at several addresses. */
  2810. #define MULTIMAP_MEMORY
  2811. #define MULTIMAP_MEMORY_VIA_FILE
  2812. #endif
  2813. #if defined(HAVE_SHM) && !defined(MULTIMAP_MEMORY) && !defined(SINGLEMAP_MEMORY) && !defined(NO_MULTIMAP_SHM)
  2814. /* Access to Lisp-objects is done through memory-mapping: Each
  2815. memory page can be accessed at several addresses. */
  2816. #define MULTIMAP_MEMORY
  2817. #define MULTIMAP_MEMORY_VIA_SHM
  2818. #endif
  2819. #if (defined(UNIX_LINUX) || defined(UNIX_FREEBSD)) && !defined(MULTIMAP_MEMORY) && !defined(SINGLEMAP_MEMORY) && !defined(NO_MULTIMAP_FILE)
  2820. /* Access to Lisp-objects is done through memory-mapping: Each
  2821. memory page can be accessed at several addresses. */
  2822. #define MULTIMAP_MEMORY
  2823. #define MULTIMAP_MEMORY_VIA_FILE
  2824. #endif
  2825. #endif
  2826. #if defined(MULTIMAP_MEMORY) || defined(SINGLEMAP_MEMORY)
  2827. #define MAP_MEMORY
  2828. #endif
  2829. #if (defined(HAVE_MMAP_ANON) || defined(HAVE_MMAP_DEVZERO) || defined(HAVE_MACH_VM) || defined(HAVE_WIN32_VM)) && !defined(MAP_MEMORY) && !(defined(UNIX_HPUX) || defined(UNIX_AIX) || defined(ADDRESS_RANGE_RANDOMIZED)) && !defined(NO_TRIVIALMAP)
  2830. /* mmap() allows for a more flexible way of memory management than malloc().
  2831. It's not really memory-mapping, but a more comfortable way to
  2832. manage two large memory blocks.
  2833. But it doesn't work on HP-UX 9 and AIX.
  2834. Also it does not work reliably when address space layout randomization
  2835. is in effect: TRIVIALMAP_MEMORY assumes that one can increase existing a
  2836. memory region by mmapping the pages after it; but this might overwrite
  2837. some small malloc regions that have been put there by the system. */
  2838. #define TRIVIALMAP_MEMORY
  2839. #endif
  2840. /* Flavor of the garbage collection: normal or generational. */
  2841. #if defined(VIRTUAL_MEMORY) && (defined(SINGLEMAP_MEMORY) || defined(TRIVIALMAP_MEMORY) || (defined(MULTIMAP_MEMORY) && (defined(UNIX_LINUX) || defined(UNIX_FREEBSD)))) && defined(HAVE_WORKING_MPROTECT) && defined(HAVE_SIGSEGV_RECOVERY) && !defined(UNIX_IRIX) && !defined(WIDE_SOFT_LARGEFIXNUM) && (SAFETY < 3) && !defined(NO_GENERATIONAL_GC)
  2842. /* "generational garbage collection" has some requirements.
  2843. With Linux, it will only work with 1.1.52, and higher, which will be checked in makemake.
  2844. On IRIX 6, it worked in the past, but leads to core dumps now. Reason unknown. FIXME! */
  2845. #define GENERATIONAL_GC
  2846. #endif
  2847. #ifdef MAP_MEMORY
  2848. /* Some type-bit combinations might not be allowed */
  2849. #ifdef vm_addr_mask
  2850. #define tint_allowed_type_mask ((oint_type_mask & vm_addr_mask) >> oint_type_shift)
  2851. #endif
  2852. #endif
  2853. /* Complete the definition of the type 'gcv_object_t'. */
  2854. #if defined(WIDE_AUXI) || defined(OBJECT_STRUCT) || defined(WIDE_STRUCT)
  2855. #if defined(WIDE) && !defined(WIDE_HARD)
  2856. #ifdef GENERATIONAL_GC
  2857. /* The generational GC can't deal with an object-pointer that points
  2858. towards two memory pages.
  2859. Thus we enforce alignof(gcv_object_t) = sizeof(gcv_object_t). */
  2860. #define _attribute_aligned_object_ __attribute__ ((aligned(8)))
  2861. #else
  2862. #define _attribute_aligned_object_
  2863. #endif
  2864. #endif
  2865. #ifdef DEBUG_GCSAFETY
  2866. struct object;
  2867. struct gcv_object_t {
  2868. INNARDS_OF_GCV_OBJECT
  2869. /* Conversion to object. */
  2870. operator object () const;
  2871. /* Conversion from object. */
  2872. gcv_object_t (object obj);
  2873. /* Conversion from fake_gcv_object. */
  2874. gcv_object_t (struct fake_gcv_object obj);
  2875. /* Uninitialized object. */
  2876. gcv_object_t ();
  2877. };
  2878. #else
  2879. typedef struct { INNARDS_OF_GCV_OBJECT } gcv_object_t;
  2880. #endif
  2881. #endif
  2882. #ifndef _attribute_aligned_object_
  2883. #define _attribute_aligned_object_
  2884. #endif
  2885. /* Define the type 'object'. */
  2886. #ifdef DEBUG_GCSAFETY
  2887. /* A counter that is incremented each time an allocation occurs that could
  2888. trigger GC. */
  2889. extern uintL alloccount;
  2890. /* A register-allocated object contains, if not GC-invariant, the timestamp
  2891. of when it was fetched from a GC-visible location. */
  2892. struct object {
  2893. INNARDS_OF_GCV_OBJECT
  2894. uintL allocstamp;
  2895. };
  2896. /* Always initialize allocstamp with the current(!) value of alloccount. */
  2897. #define INIT_ALLOCSTAMP , allocstamp: alloccount
  2898. #else
  2899. typedef gcv_object_t object;
  2900. #define INIT_ALLOCSTAMP
  2901. #endif
  2902. %% #ifdef DEBUG_GCSAFETY
  2903. %% puts("extern uintL alloccount;");
  2904. %% #else
  2905. %% emit_typedef("gcv_object_t","object");
  2906. %% #endif
  2907. /* fake_gcv_object(value)
  2908. creates a gcv_object that is actually not seen by GC,
  2909. for use as second word in SKIP2 frames. */
  2910. #ifdef DEBUG_GCSAFETY
  2911. struct fake_gcv_object {
  2912. oint fake_value;
  2913. fake_gcv_object (oint value) : fake_value (value) {}
  2914. };
  2915. #else
  2916. #define fake_gcv_object(value) as_object((oint)(value))
  2917. #endif
  2918. /* Hack for use only in areas where no GC can be triggered. */
  2919. #ifdef DEBUG_GCSAFETY
  2920. struct gcunsafe_object_t : gcv_object_t {
  2921. uintL allocstamp;
  2922. /* Conversion from object. */
  2923. gcunsafe_object_t (object obj);
  2924. /* Conversion from gcv_object_t. */
  2925. gcunsafe_object_t (gcv_object_t obj);
  2926. /* Verification that no GC has been triggered. */
  2927. ~gcunsafe_object_t ();
  2928. };
  2929. #else
  2930. typedef gcv_object_t gcunsafe_object_t;
  2931. #endif
  2932. /* mask of those bits of a tint, which really belong to the type:
  2933. tint_type_mask = oint_type_mask >> oint_type_shift
  2934. (a constant expression, without any 'long long's in it!) */
  2935. #ifdef WIDE_SOFT
  2936. #define tint_type_mask (bitm(oint_type_len)-1)
  2937. #else
  2938. #define tint_type_mask (oint_type_mask >> oint_type_shift)
  2939. #endif
  2940. %% #if notused
  2941. %% export_def(tint_type_mask);
  2942. %% #endif
  2943. /* To add something to an object/oint:
  2944. objectplus(obj,offset) */
  2945. #if !(defined(WIDE_SOFT) || defined(WIDE_AUXI) || defined(OBJECT_STRUCT))
  2946. #define objectplus(obj,offset) ((object)pointerplus(obj,offset))
  2947. #elif defined(WIDE_AUXI)
  2948. static inline object objectplus (object obj, saint offset) {
  2949. return (object){u:{both:{ one_ob: obj.one_o+offset, auxi_ob: obj.auxi_o }}};
  2950. }
  2951. #else /* defined(WIDE_SOFT) || defined(OBJECT_STRUCT) */
  2952. #define objectplus(obj,offset) as_object(as_oint(obj)+(soint)(offset))
  2953. #endif
  2954. %% #if !(defined(WIDE_SOFT) || defined(WIDE_AUXI) || defined(OBJECT_STRUCT))
  2955. %% emit_define("objectplus(obj,offset)","((object)pointerplus(obj,offset))");
  2956. %% #elif defined(WIDE_AUXI)
  2957. %% puts("static inline object objectplus (object obj, saint offset) { return (object){u:{both:{ one_ob: obj.one_o+offset, auxi_ob: obj.auxi_o }}}; }");
  2958. %% #else
  2959. %% emit_define("objectplus(obj,offset)","as_object(as_oint(obj)+(soint)(offset))");
  2960. %% #endif
  2961. /* Bit operations on entities of type uintV:
  2962. ...vbit... instead of ...bit..., "v" = "value". */
  2963. #if (intVsize > 32)
  2964. #define vbit(n) (LL(1)<<(n))
  2965. #define vbitm(n) (LL(2)<<((n)-1))
  2966. #define vbit_test(x,n) ((x) & vbit(n))
  2967. #define minus_vbit(n) (-LL(1)<<(n))
  2968. #else
  2969. #define vbit bit
  2970. #define vbitm bitm
  2971. #define vbit_test bit_test
  2972. #define minus_vbit minus_bit
  2973. #endif
  2974. %% #if notused
  2975. %% export_def(vbit(n));
  2976. %% export_def(vbitm(n));
  2977. %% export_def(vbit_test(x,n));
  2978. %% export_def(minus_vbit(n));
  2979. %% #endif
  2980. /* Bit operations on entities of type oint:
  2981. ...wbit... instead of ...bit..., "w" = "wide". */
  2982. #if defined(WIDE_SOFT) || defined(WIDE_AUXI)
  2983. #define wbit(n) (LL(1)<<(n))
  2984. #define wbitm(n) (LL(2)<<((n)-1))
  2985. #define wbit_test(x,n) ((x) & wbit(n))
  2986. #define minus_wbit(n) (-LL(1)<<(n))
  2987. #else
  2988. #define wbit bit
  2989. #define wbitm bitm
  2990. #define wbit_test bit_test
  2991. #define minus_wbit minus_bit
  2992. #endif
  2993. %% export_def(wbit);
  2994. %% #if notused
  2995. %% export_def(wbitm);
  2996. %% #endif
  2997. %% export_def(wbit_test);
  2998. %% export_def(minus_wbit);
  2999. #ifdef TYPECODES
  3000. /* Type info:
  3001. typecode(object) and mtypecode(object) yield the type code of
  3002. an object obj. For mtypecode it has to be in memory. */
  3003. #if !(exact_uint_size_p(oint_type_len) && (tint_type_mask == bit(oint_type_len)-1))
  3004. #define typecode(expr) \
  3005. ((tint)(as_oint(expr) >> oint_type_shift) & (oint_type_mask >> oint_type_shift))
  3006. #define mtypecode(expr) typecode(expr)
  3007. #else
  3008. /* The type 'tint' has exactly oint_type_len bits,
  3009. and tint_type_mask = 2^oint_type_len-1.
  3010. So it's not necessary for you to AND.
  3011. On the other hand on a 68000 a ROL.L #8 is faster,
  3012. as is a shift on a SPARC. */
  3013. #define typecode(expr) ((tint)(as_oint(expr) >> oint_type_shift))
  3014. #if defined(MC68000) && defined(GNU) && !defined(NO_ASM) && (oint_type_shift==24) && (oint_type_len==8)
  3015. /* GNU C on a 68000, replace LSR.L #24 with ROL.L #8 : */
  3016. #undef typecode
  3017. #define typecode(expr) \
  3018. ({var tint __typecode; \
  3019. __asm__ ("roll #8,%0" : "=d" (__typecode) : "0" (as_oint(expr)) ); \
  3020. __typecode; \
  3021. })
  3022. #elif defined(SPARC) && !defined(WIDE)
  3023. #undef typecode
  3024. #define typecode(expr) \
  3025. ((as_oint(expr) << (32-oint_type_len-oint_type_shift)) >> (32-oint_type_len))
  3026. #elif defined(WIDE) && defined(WIDE_STRUCT)
  3027. #undef typecode
  3028. #define typecode(expr) ((expr).u.both.type)
  3029. #endif
  3030. /* Furthermore you can do accesses in memory without shift: */
  3031. #if !defined(WIDE) && (((oint_type_shift==24) && BIG_ENDIAN_P) || ((oint_type_shift==0) && !BIG_ENDIAN_P))
  3032. #define mtypecode(expr) (*(tint*)&(expr))
  3033. #define fast_mtypecode
  3034. #elif !defined(WIDE) && (((oint_type_shift==24) && !BIG_ENDIAN_P) || ((oint_type_shift==0) && BIG_ENDIAN_P))
  3035. #define mtypecode(expr) (*((tint*)&(expr)+3))
  3036. #define fast_mtypecode
  3037. #elif defined(WIDE)
  3038. #ifdef WIDE_STRUCT
  3039. #define mtypecode(expr) ((expr).u.both.type)
  3040. #elif (oint_type_len==16)
  3041. #if (oint_type_shift==0) == BIG_ENDIAN_P
  3042. #define mtypecode(expr) (*((tint*)&(expr)+3))
  3043. #else /* (oint_type_shift==48) == BIG_ENDIAN_P */
  3044. #define mtypecode(expr) (*(tint*)&(expr))
  3045. #endif
  3046. #elif (oint_type_len==32)
  3047. #if (oint_type_shift==0) == BIG_ENDIAN_P
  3048. #define mtypecode(expr) (*((tint*)&(expr)+1))
  3049. #else /* (oint_type_shift==32) == BIG_ENDIAN_P */
  3050. #define mtypecode(expr) (*(tint*)&(expr))
  3051. #endif
  3052. #endif
  3053. #define fast_mtypecode
  3054. #else /* no optimization is possible */
  3055. #define mtypecode(expr) typecode(expr)
  3056. #endif
  3057. #endif
  3058. /* Extraction of the address field without type info.
  3059. untype(obj) */
  3060. #if defined(WIDE) && defined(WIDE_STRUCT)
  3061. #define untype(expr) ((expr).u.both.addr)
  3062. #elif !(defined(SPARC) && (oint_addr_len+oint_addr_shift<32))
  3063. #define untype(expr) \
  3064. ((aint)(as_oint(expr) >> oint_addr_shift) & (aint)(oint_addr_mask >> oint_addr_shift))
  3065. #else
  3066. /* On a SPARC processor long constants are slower than shifts:
  3067. Possibly, one does not need to use AND here. */
  3068. #define untype(expr) \
  3069. ((aint)((as_oint(expr) << (32-oint_addr_len-oint_addr_shift)) >> (32-oint_addr_len)))
  3070. #endif
  3071. /* Object from type info and address field:
  3072. type_untype_object(type,address) */
  3073. #if defined(WIDE) && defined(WIDE_STRUCT)
  3074. #if BIG_ENDIAN_P==WIDE_ENDIANNESS
  3075. #define type_untype_object(type,address) ((object){{(tint)(type),(aint)(address)}INIT_ALLOCSTAMP})
  3076. #else
  3077. #define type_untype_object(type,address) ((object){{(aint)(address),(tint)(type)}INIT_ALLOCSTAMP})
  3078. #endif
  3079. #elif !(oint_addr_shift==0)
  3080. #define type_untype_object(type,address) \
  3081. (as_object( ((oint)(tint)(type) << oint_type_shift) + \
  3082. ((oint)(aint)(address) << oint_addr_shift) ))
  3083. #else /* you don't have to shift if oint_addr_shift=0: */
  3084. #if defined(WIDE_SOFT)
  3085. /* Beware: Conversion of address to oint by Zero-Extend! */
  3086. #define type_untype_object(type,address) \
  3087. objectplus((oint)(aint)(address),(oint)(tint)(type)<<oint_type_shift)
  3088. #elif defined(WIDE_AUXI)
  3089. #define type_untype_object(type,address) \
  3090. as_object_with_auxi((aint)pointerplus((address),(aint)(tint)(type)<<oint_type_shift))
  3091. #elif defined(OBJECT_STRUCT)
  3092. #define type_untype_object(type,address) \
  3093. as_object((oint)pointerplus((address),(oint)(tint)(type)<<oint_type_shift))
  3094. #else /* normal case */
  3095. /* In order for this (NIL_IS_CONSTANT) to be a valid initializer
  3096. under gcc-2.5.8, you must not cast from pointer to oint and then
  3097. back to pointer, but you'll have to stay in the pointer's range.. */
  3098. #define type_untype_object(type,address) \
  3099. as_object(pointerplus((address),(oint)(tint)(type)<<oint_type_shift))
  3100. #endif
  3101. #endif
  3102. /* Object from type info and direct data (as "address"):
  3103. type_data_object(type,data) */
  3104. #if defined(WIDE) && defined(WIDE_STRUCT)
  3105. #if BIG_ENDIAN_P==WIDE_ENDIANNESS
  3106. #define type_data_object(type,data) ((object){{(tint)(type),(aint)(data)}INIT_ALLOCSTAMP})
  3107. #else
  3108. #define type_data_object(type,data) ((object){{(aint)(data),(tint)(type)}INIT_ALLOCSTAMP})
  3109. #endif
  3110. #elif !(oint_addr_shift==0)
  3111. #define type_data_object(type,data) \
  3112. (as_object( ((oint)(tint)(type) << oint_type_shift) + \
  3113. ((oint)(aint)(data) << oint_addr_shift) ))
  3114. #else /* if oint_addr_shift=0, you don't have to shift: */
  3115. #define type_data_object(type,data) \
  3116. (as_object( ((oint)(tint)(type) << oint_type_shift) + (oint)(aint)(data) ))
  3117. #endif
  3118. /* Extraction of the address without type info:
  3119. upointer(obj)
  3120. (upointer means "untyped pointer".) */
  3121. #if (addr_shift==0)
  3122. #define upointer untype
  3123. #else
  3124. #define optimized_upointer(obj) \
  3125. ((aint)((as_oint(obj) << (32-oint_addr_len-oint_addr_shift)) >> (32-oint_addr_len-addr_shift)))
  3126. #define upointer(obj) (untype(obj)<<addr_shift)
  3127. #endif
  3128. /* Object from type info and address:
  3129. type_pointer_object(type,address) */
  3130. #if defined(WIDE_SOFT) && !defined(WIDE_STRUCT)
  3131. /* Cast to uintP, so that conversion of address to aint is done by Zero-Extend! */
  3132. #define type_pointer_object(type,address) \
  3133. type_untype_object(type,(aint)(uintP)(address)>>addr_shift)
  3134. #elif (addr_shift==0)
  3135. /* (No cast to aint, so NIL can be used to initialize.) */
  3136. #define type_pointer_object(type,address) \
  3137. type_untype_object(type,address)
  3138. #else /* more efficient, */
  3139. /* but this requires address to be divisible by 2^addr_shift: */
  3140. #define type_pointer_object(type,address) \
  3141. (as_object(((oint)(tint)(type) << oint_type_shift) + \
  3142. ((oint)(aint)(address) << (oint_addr_shift-addr_shift))))
  3143. #endif
  3144. /* Object from constant type info and constant address:
  3145. type_constpointer_object(type,address) */
  3146. #define type_constpointer_object(type,address) type_pointer_object(type,address)
  3147. /* oint from constant type info and address = 0:
  3148. type_zero_oint(type) */
  3149. #if defined(WIDE_SOFT) && defined(WIDE_STRUCT)
  3150. #define type_zero_oint(type) as_oint(type_untype_object(type,0))
  3151. #else
  3152. #define type_zero_oint(type) ((oint)(tint)(type) << oint_type_shift)
  3153. #endif
  3154. #else /* HEAPCODES */
  3155. #ifdef STANDARD_HEAPCODES
  3156. /* We can assume a general alignment of 4 bytes, and thus have the low 2
  3157. bits for encoding type. Here's how we divide the address space:
  3158. machine, frame_pointer 1/4
  3159. subr 1/4
  3160. cons 1/8
  3161. varobject 1/4 (not 1/8 because symbol_tab is not 8-aligned)
  3162. immediate > 0 (anything >= 7/256 does it).
  3163. Note that cons and varobject cannot have the same encoding mod 8
  3164. (otherwise gc_mark:up wouldn't work).
  3165. So, here are the encodings.
  3166. machine ... .00 encodes pointers, offset 0
  3167. subr ... .10 encodes pointers, offset 2
  3168. varobject ... .01 offset 1, the pointers are == 0 mod 4
  3169. cons ... 011 offset 3, the pointers are == 0 mod 8
  3170. immediate ... 111
  3171. fixnum 00s 111 s = sign bit
  3172. sfloat 01s 111 s = sign bit
  3173. char 100 111
  3174. small-read-label 110 111
  3175. system 111 111
  3176. Varobjects all start with a word containing the type (1 byte) and a
  3177. length field (up to 24 bits). */
  3178. /* These are the biases, mod 8. */
  3179. #define machine_bias 0UL /* mod 4 */
  3180. #define subr_bias 2UL /* mod 4 */
  3181. #define varobject_bias 1UL /* mod 4 */
  3182. #define cons_bias 3UL /* mod 8 */
  3183. #define immediate_bias 7UL /* mod 8 */
  3184. /* Immediate objects have a second type field. */
  3185. #if defined(LINUX_SPARC_OLD_GLIBC)
  3186. #define imm_type_shift 29
  3187. #else
  3188. #define imm_type_shift 3
  3189. #endif
  3190. /* The types of immediate objects. */
  3191. #define fixnum_type ((0 << imm_type_shift) + immediate_bias)
  3192. #define sfloat_type ((2 << imm_type_shift) + immediate_bias)
  3193. #define char_type ((4 << imm_type_shift) + immediate_bias)
  3194. #define small_read_label_type ((6 << imm_type_shift) + immediate_bias)
  3195. #define system_type ((7 << imm_type_shift) + immediate_bias)
  3196. /* The sign bit, for immediate numbers only. */
  3197. #define sign_bit_t (0 + imm_type_shift)
  3198. #define sign_bit_o (sign_bit_t+oint_type_shift)
  3199. /* Distinction between fixnums and bignums. */
  3200. #define bignum_bit_o 1
  3201. #define NUMBER_BITS_INVERTED
  3202. /* Distinction between fixnums, short-floats and other kinds of numbers.
  3203. (NB: IMMEDIATE_FFLOAT is not defined for HEAPCODES.) */
  3204. #define number_immediatep(obj) ((as_oint(obj) & wbit(1)) != 0)
  3205. /* For masking out the nonimmediate biases.
  3206. This must be 3, not 7, otherwise gc_mark won't work. */
  3207. #define nonimmediate_bias_mask 3
  3208. #define nonimmediate_heapcode_mask 3
  3209. /* Combine an object from type info and immediate data.
  3210. type_data_object(type,data) */
  3211. #define type_data_object(type,data) \
  3212. (as_object( ((oint)(tint)(type) << oint_type_shift) + \
  3213. ((oint)(aint)(data) << oint_data_shift) ))
  3214. /* An oint made up with a given type info, and address = 0.
  3215. type_zero_oint(type) */
  3216. #define type_zero_oint(type) ((oint)(tint)(type) << oint_type_shift)
  3217. /* The GC bit. Addresses may not have this bit set. */
  3218. /* define garcol_bit_o (already defined above) # only set during garbage collection */
  3219. /* Test for immediate object.
  3220. immediate_object_p(obj) */
  3221. #define immediate_object_p(obj) ((7 & ~as_oint(obj)) == 0)
  3222. /* Test for gc-invariant object. (This includes immediate, machine, subr.)
  3223. gcinvariant_object_p(obj) */
  3224. #define gcinvariant_object_p(obj) \
  3225. (((as_oint(obj) & 1) == 0) || immediate_object_p(obj))
  3226. #define gcinvariant_oint_p(obj_o) \
  3227. ((((obj_o) & 1) == 0) || ((7 & ~(obj_o)) == 0))
  3228. /* Test for gc-invariant object, given only the bias. */
  3229. #define gcinvariant_bias_p(bias) \
  3230. ((((bias) & 1) == 0) || ((7 & ~(bias)) == 0))
  3231. /* The heap of a heap allocated object. 0 for varobjects, 1 for conses. */
  3232. #define nonimmediate_heapnr(obj) \
  3233. ((as_oint(obj) >> 1) & 1)
  3234. #endif /* STANDARD_HEAPCODES */
  3235. #ifdef LINUX_NOEXEC_HEAPCODES
  3236. /* We must assume a general alignment of 4 bytes and an enforced alignment
  3237. of 8 bytes for Lisp objects, and thus have the low 2 to 3 bits for
  3238. encoding heap and the garcol_bit. Here's how we divide the address space:
  3239. machine, frame_pointer 1/4 * 3/4
  3240. immediate 1/4 * 1/4
  3241. cons 1/8
  3242. varobject 1/8
  3243. Note that cons and varobject cannot have the same encoding mod 8
  3244. (otherwise gc_mark:up wouldn't work).
  3245. Immediates look like pointers in the range 0xC0000000..0xFFFFFFFF.
  3246. We know that the Linux kernel never assigns virtual memory in this area.
  3247. So, here are the encodings. Bit 0 is used as the garcol_bit.
  3248. machine ... ... .00 encodes pointers, offset 0
  3249. cons ... ... 010 offset 2, the pointers are == 0 mod 8
  3250. varobject ... ... 110 offset 6, the pointers are == 4 mod 8
  3251. immediate 11 ... ... 00
  3252. fixnum 11 ... 00s 00 s = sign bit
  3253. sfloat 11 ... 01s 00 s = sign bit
  3254. char 11 ... 100 00
  3255. small-read-label 11 ... 110 00
  3256. system 11 ... 111 00
  3257. Varobjects all start with a word containing the type (1 byte) and a
  3258. length field (up to 24 bits). */
  3259. /* These are the biases. */
  3260. #define machine_bias 0 /* + 0 mod 4 */
  3261. #define varobject_bias 2 /* + 4 mod 8 */
  3262. #define cons_bias 2 /* + 0 mod 8 */
  3263. #define immediate_bias 0xC0000000 /* + 0 mod 4 */
  3264. #define subr_bias varobject_bias
  3265. /* Immediate objects have a second type field. */
  3266. #define imm_type_shift 2 /* could also be 3, if oint_data_shift == 6 */
  3267. /* The types of immediate objects. */
  3268. #define fixnum_type ((0 << imm_type_shift) + immediate_bias)
  3269. #define sfloat_type ((2 << imm_type_shift) + immediate_bias)
  3270. #define char_type ((4 << imm_type_shift) + immediate_bias)
  3271. #define small_read_label_type ((6 << imm_type_shift) + immediate_bias)
  3272. #define system_type ((7 << imm_type_shift) + immediate_bias)
  3273. /* The sign bit, for immediate numbers only. */
  3274. #define sign_bit_t (0 + imm_type_shift)
  3275. #define sign_bit_o (sign_bit_t+oint_type_shift)
  3276. /* Distinction between fixnums and bignums. */
  3277. #define bignum_bit_o 1
  3278. /* Distinction between fixnums, short-floats and other kinds of numbers.
  3279. (NB: IMMEDIATE_FFLOAT is not defined for HEAPCODES.) */
  3280. #define number_immediatep(obj) ((as_oint(obj) & wbit(1)) == 0)
  3281. /* The misalignment of varobjects, modulo varobject_alignment. */
  3282. #define varobjects_misaligned 4
  3283. /* For masking out the nonimmediate biases. */
  3284. #define nonimmediate_bias_mask 3
  3285. #define nonimmediate_heapcode_mask 7
  3286. /* Combine an object from type info and immediate data.
  3287. type_data_object(type,data) */
  3288. #define type_data_object(type,data) \
  3289. (as_object( ((oint)(tint)(type) << oint_type_shift) + \
  3290. ((oint)(aint)(data) << oint_data_shift) ))
  3291. /* An oint made up with a given type info, and address = 0.
  3292. type_zero_oint(type) */
  3293. #define type_zero_oint(type) ((oint)(tint)(type) << oint_type_shift)
  3294. /* The GC bit. Addresses may not have this bit set. */
  3295. /* define garcol_bit_o (already defined above) # only set during garbage collection */
  3296. /* Test for immediate object.
  3297. immediate_object_p(obj) */
  3298. #define immediate_object_p(obj) \
  3299. ((as_oint(obj) & 0xE0000003) == (immediate_bias & 0xE0000003))
  3300. /* Test for gc-invariant object. (This includes immediate, machine.)
  3301. gcinvariant_object_p(obj) */
  3302. #define gcinvariant_object_p(obj) \
  3303. ((as_oint(obj) & bit(1)) == 0)
  3304. #define gcinvariant_oint_p(obj_o) \
  3305. (((obj_o) & bit(1)) == 0)
  3306. /* NB: Subrs are not included in this test, because subrp(obj) require a
  3307. memory access. */
  3308. /* Test for gc-invariant object, given only the bias. */
  3309. #define gcinvariant_bias_p(bias) \
  3310. (((bias) & 2) == 0)
  3311. /* The heap of a heap allocated object. 0 for varobjects, 1 for conses. */
  3312. #define nonimmediate_heapnr(obj) \
  3313. (1 & ~(as_oint(obj) >> 2))
  3314. #endif /* LINUX_NOEXEC_HEAPCODES */
  3315. #endif /* TYPECODES */
  3316. %% #ifdef TYPECODES
  3317. %% export_def(typecode(expr));
  3318. %% export_def(mtypecode(expr));
  3319. %% export_def(type_untype_object(type,address));
  3320. %% export_def(upointer(obj));
  3321. %% export_def(type_pointer_object(type,address));
  3322. %% export_def(type_constpointer_object(type,address));
  3323. %% #else
  3324. %% export_def(number_immediatep(obj));
  3325. %% export_def(immediate_object_p(obj));
  3326. %% export_def(gcinvariant_object_p(obj));
  3327. %% export_def(gcinvariant_oint_p(obj_o));
  3328. %% export_def(gcinvariant_bias_p(bias));
  3329. %% #endif
  3330. %% export_def(type_data_object(type,address));
  3331. %% export_def(type_zero_oint(obj));
  3332. /* The misalignment of varobjects, modulo varobject_alignment. */
  3333. #ifndef varobjects_misaligned
  3334. #define varobjects_misaligned 0
  3335. #endif
  3336. #if varobjects_misaligned
  3337. #define VAROBJECTS_ALIGNMENT_DUMMY_DECL char alignment_dummy[varobjects_misaligned];
  3338. #else
  3339. #define VAROBJECTS_ALIGNMENT_DUMMY_DECL
  3340. #endif
  3341. %% export_def(varobjects_misaligned);
  3342. %% export_def(VAROBJECTS_ALIGNMENT_DUMMY_DECL);
  3343. /* The misalignment of conses, modulo 2*sizeof(gcv_object_t). */
  3344. #ifndef conses_misaligned
  3345. #define conses_misaligned 0
  3346. #endif
  3347. /* Objects with variable length must reside at addresses that are divisable by 2 */
  3348. #if defined(VAX) /* ?? gcc/config/vax/vax.h sagt: Alignment = 4 */
  3349. #define varobject_alignment 1
  3350. #endif
  3351. #if defined(MC680X0)
  3352. #if addr_shift!=0
  3353. #define varobject_alignment bit(addr_shift) /* because of the condensed distribution of typecodes */
  3354. #else
  3355. #define varobject_alignment 2
  3356. #endif
  3357. #endif
  3358. #if defined(I80386) || defined(POWERPC) || defined(ARM) || defined(S390)
  3359. #define varobject_alignment 4
  3360. #endif
  3361. #if defined(SPARC) || defined(HPPA) || defined(MIPS) || defined(M88000) || defined(DECALPHA) || defined(IA64) || defined(AMD64)
  3362. #define varobject_alignment 8
  3363. #endif
  3364. #if (!defined(TYPECODES) || defined(GENERATIONAL_GC)) && (varobject_alignment < 4)
  3365. #undef varobject_alignment
  3366. #define varobject_alignment 4
  3367. #endif
  3368. #if ((defined(GENERATIONAL_GC) && defined(WIDE)) || defined(LINUX_NOEXEC_HEAPCODES)) && (varobject_alignment < 8)
  3369. #undef varobject_alignment
  3370. #define varobject_alignment 8
  3371. #endif
  3372. /* varobject_alignment should be defined: */
  3373. #ifndef varobject_alignment
  3374. #error "varobject_alignment depends on CPU -- readjust varobject_alignment!!"
  3375. #endif
  3376. /* varobject_alignment should be a power of 2: */
  3377. #if !((varobject_alignment & (varobject_alignment-1)) ==0)
  3378. #error "Bogus varobject_alignment -- readjust varobject_alignment!!"
  3379. #endif
  3380. /* varobject_alignment should be a multiple of 2^addr_shift : */
  3381. #if (varobject_alignment % bit(addr_shift))
  3382. #error "Bogus varobject_alignment -- readjust varobject_alignment!!"
  3383. #endif
  3384. %% export_def(varobject_alignment);
  3385. #ifdef TYPECODES
  3386. /* Now we'll define the various type bits and type codes. */
  3387. /* Single-floats can be immediate objects, like short-floats, if there are
  3388. enough bits in a 'gcv_object_t'. */
  3389. #if defined(WIDE_HARD) || defined(WIDE_SOFT)
  3390. #define IMMEDIATE_FFLOAT
  3391. #endif
  3392. /* Determine whether a type isn't changed by the GC
  3393. (ie. if it's not a pointer): */
  3394. #if 0 && (defined(GNU) || defined(INTEL))
  3395. #define gcinvariant_type_p(type) \
  3396. ({var bool _erg; \
  3397. switch (type) \
  3398. { case_machine: \
  3399. case_char: case_subr: case_system: \
  3400. case_fixnum: case_sfloat: \
  3401. /* with WIDE also: case_ffloat: */ \
  3402. _erg = true; break; \
  3403. default: _erg = false; break; \
  3404. } \
  3405. _erg; \
  3406. })
  3407. #endif
  3408. #ifndef tint_allowed_type_mask
  3409. #define tint_allowed_type_mask tint_type_mask
  3410. #endif
  3411. /* There are 7 to 8 type bits available: TB7, [TB6,] TB5, TB4, ..., TB0.
  3412. All of them have to be set in tint_allowed_type_mask and thus in tint_type_mask as well
  3413. We distribute them under the assumption that only one bit is missing in tint_type_mask.
  3414. TB6 will be set to -1, if it can't be used. */
  3415. #if ((0xFF & ~tint_allowed_type_mask) == 0)
  3416. #define TB7 7
  3417. #define TB6 6
  3418. #define TB5 5
  3419. #define TB4 4
  3420. #define TB3 3
  3421. #define TB2 2
  3422. #define TB1 1
  3423. #define TB0 0
  3424. #elif (oint_type_len==7)
  3425. #define TB7 6
  3426. #define TB6 -1
  3427. #define TB5 5
  3428. #define TB4 4
  3429. #define TB3 3
  3430. #define TB2 2
  3431. #define TB1 1
  3432. #define TB0 0
  3433. #else
  3434. /* Some bits have to be avoided */
  3435. #define tint_avoid ((bitm(oint_type_len)-1) & ~tint_allowed_type_mask)
  3436. /* tint_avoid must only contain one bit: */
  3437. #if (tint_avoid & (tint_avoid-1))
  3438. #error "Bogus oint_type_mask -- oint_type_mask has more than one extraneous bit!!"
  3439. #endif
  3440. /* tint_avoid consists of exactly one bit that has to be avoided. */
  3441. #if (tint_avoid > bit(0))
  3442. #define TB0 0
  3443. #else
  3444. #define TB0 1
  3445. #endif
  3446. #if (tint_avoid > bit(1))
  3447. #define TB1 1
  3448. #else
  3449. #define TB1 2
  3450. #endif
  3451. #if (tint_avoid > bit(2))
  3452. #define TB2 2
  3453. #else
  3454. #define TB2 3
  3455. #endif
  3456. #if (tint_avoid > bit(3))
  3457. #define TB3 3
  3458. #else
  3459. #define TB3 4
  3460. #endif
  3461. #if (tint_avoid > bit(4))
  3462. #define TB4 4
  3463. #else
  3464. #define TB4 5
  3465. #endif
  3466. #if (tint_avoid > bit(5))
  3467. #define TB5 5
  3468. #else
  3469. #define TB5 6
  3470. #endif
  3471. #if ((tint_allowed_type_mask & ~0xFF) == 0)
  3472. #define TB6 -1
  3473. #if (tint_avoid > bit(6))
  3474. #define TB7 6
  3475. #else
  3476. #define TB7 7
  3477. #endif
  3478. #else
  3479. #if (tint_avoid > bit(6))
  3480. #define TB6 6
  3481. #else
  3482. #define TB6 7
  3483. #endif
  3484. #if (tint_avoid > bit(7))
  3485. #define TB7 7
  3486. #else
  3487. #define TB7 8
  3488. #endif
  3489. #endif
  3490. #endif
  3491. /* bit masks for the type bits: */
  3492. #define BTB0 bit(TB0)
  3493. #define BTB1 bit(TB1)
  3494. #define BTB2 bit(TB2)
  3495. #define BTB3 bit(TB3)
  3496. #define BTB4 bit(TB4)
  3497. #define BTB5 bit(TB5)
  3498. #define BTB6 bit(TB6)
  3499. #define BTB7 bit(TB7)
  3500. #define STANDARD_8BIT_TYPECODES
  3501. #ifdef STANDARD_8BIT_TYPECODES
  3502. #if defined(I80386) && defined(UNIX_LINUX) && (CODE_ADDRESS_RANGE == 0)
  3503. /* At 0x60000000 there are the shared-libraries.
  3504. At 0x50000000 (Linux 1.2) resp. 0x40000000 (Linux 2.0) there are several
  3505. mmap-pages,for example ones allocated by setlocale() or gettext().
  3506. Therefore we only have to do a few changes to the distribution of the type codes. */
  3507. #endif
  3508. #if defined(I80386) && defined(UNIX_LINUX) && (CODE_ADDRESS_RANGE != 0)
  3509. /* Code and malloc memory is at 0x08000000.
  3510. Therefore avoid allocating typecode 0x08 for the moment. */
  3511. #endif
  3512. #if (defined(MC680X0) || (defined(SPARC) && !defined(SUN4_29))) && defined(UNIX_LINUX)
  3513. /* At 0x50000000 there are shared libraries located.
  3514. But this doesn't mean we have to change the type code distribution. */
  3515. #endif
  3516. #if (defined(MIPS) || defined(POWERPC)) && defined(UNIX_LINUX)
  3517. /* At 0x2AAAB000 there are shared libraries located.
  3518. But this doesn't mean we have to change the type code distribution. */
  3519. #endif
  3520. #if defined(DECALPHA) && defined(UNIX_OSF) && !(defined(NO_SINGLEMAP) || defined(NO_TRIVIALMAP))
  3521. /* mmap() only works with addresses >=0, <2^38, but since ordinary pointers are in the range
  3522. 1*2^32..2*2^32, only the Bits 37..33 remain as type-bits. */
  3523. #endif
  3524. #if defined(SPARC64) && defined(UNIX_LINUX)
  3525. /* At 0x70000000 there are shared libraries located.
  3526. But this doesn't mean we have to change the type code distribution. */
  3527. #endif
  3528. /* Type bits:
  3529. in Typcodes (tint): */
  3530. #define garcol_bit_t TB7 /* only set during GC */
  3531. #if (TB6 >= 0)
  3532. #define cons_bit_t TB6 /* only set for CONS */
  3533. #endif
  3534. #define number_bit_t TB5 /* only set for numbers */
  3535. #define notsimple_bit_t TB3 /* for arrays: deleted for simple arrays */
  3536. #define sign_bit_t TB0 /* Sign for real numbers (set <==> number <0) */
  3537. #define float_bit_t TB1
  3538. #define float1_bit_t TB3
  3539. #define float2_bit_t TB2
  3540. #define ratio_bit_t TB3
  3541. #define bignum_bit_t TB2
  3542. /* in Objects (oint): */
  3543. #define garcol_bit_o (garcol_bit_t+oint_type_shift) /* only set during the garbage collection! */
  3544. #if (TB6 >= 0)
  3545. #define cons_bit_o (cons_bit_t+oint_type_shift) /* only set for cons CONS */
  3546. #endif
  3547. #define number_bit_o (number_bit_t+oint_type_shift) /* only set for numbers */
  3548. #define notsimple_bit_o (notsimple_bit_t+oint_type_shift) /* for arrays: deleted for simple arrays */
  3549. #define sign_bit_o (sign_bit_t+oint_type_shift) /* Sign for real numbers */
  3550. #define float_bit_o (float_bit_t+oint_type_shift)
  3551. #define float1_bit_o (float1_bit_t+oint_type_shift)
  3552. #define float2_bit_o (float2_bit_t+oint_type_shift)
  3553. #define ratio_bit_o (ratio_bit_t+oint_type_shift)
  3554. #define bignum_bit_o (bignum_bit_t+oint_type_shift)
  3555. /* constant type codes: */
  3556. #define machine_type (0) /* 0x00 # %00000000 ; machine pointer */
  3557. #define subr_type ( BTB0) /* 0x01 # %00000001 ; SUBR */
  3558. #define char_type ( BTB1 ) /* 0x02 # %00000010 ; character */
  3559. #define system_type ( BTB1|BTB0) /* 0x03 # %00000011 ; frame-pointer, small-read-label, system */
  3560. #define symbol_type ( BTB2 ) /* 0x04 # %000001xx ; symbol */
  3561. /* bits for symbols in the GCself pointer: */
  3562. #define var_bit0_t TB0 /* set if the symbol is proclaimed SPECIAL or constant */
  3563. #define var_bit1_t TB1 /* set if the symbol is a symbol-macro or constant */
  3564. #if (TB6 < 0)
  3565. #define cons_type ( BTB3 ) /* 0x08 # %00001000 ; cons */
  3566. #endif
  3567. #define closure_type ( BTB3 |BTB0) /* 0x09 # %00001001 ; closure */
  3568. #define structure_type ( BTB3 |BTB1 ) /* 0x0A # %00001010 ; structure */
  3569. #define stream_type ( BTB3 |BTB1|BTB0) /* 0x0B # %00001011 ; stream */
  3570. #define orecord_type ( BTB3|BTB2 ) /* 0x0C # %00001100 ; OtherRecord (Package, Byte, ...) */
  3571. #define instance_type ( BTB3|BTB2 |BTB0) /* 0x0D # %00001101 ; CLOS instance */
  3572. #define lrecord_type ( BTB3|BTB2|BTB1 ) /* 0x0E # %00001110 ; LongRecord (WeakList, WeakAlist, ...) */
  3573. #define mdarray_type ( BTB3|BTB2|BTB1|BTB0) /* 0x0F # %00001111 ; other array (rank/=1 or other eltype) */
  3574. #define sbvector_type ( BTB4 ) /* 0x10 # %00010000 ; simple-bit-vector */
  3575. #define sb2vector_type ( BTB4 |BTB0) /* 0x11 # %00010001 ; simple (VECTOR (UNSIGNED-BYTE 2)) */
  3576. #define sb4vector_type ( BTB4 |BTB1 ) /* 0x12 # %00010010 ; simple (VECTOR (UNSIGNED-BYTE 4)) */
  3577. #define sb8vector_type ( BTB4 |BTB1|BTB0) /* 0x13 # %00010011 ; simple (VECTOR (UNSIGNED-BYTE 8)) */
  3578. #define sb16vector_type ( BTB4 |BTB2 ) /* 0x14 # %00010100 ; simple (VECTOR (UNSIGNED-BYTE 16)) */
  3579. #define sb32vector_type ( BTB4 |BTB2 |BTB0) /* 0x15 # %00010101 ; simple (VECTOR (UNSIGNED-BYTE 32)) */
  3580. #define sstring_type ( BTB4 |BTB2|BTB1 ) /* 0x16 # %00010110 ; simple-string */
  3581. #define svector_type ( BTB4 |BTB2|BTB1|BTB0) /* 0x17 # %00010111 ; simple-vector */
  3582. #define bvector_type ( BTB4|BTB3 ) /* 0x18 # %00011000 ; non-simple bit-vector */
  3583. #define b2vector_type ( BTB4|BTB3 |BTB0) /* 0x19 # %00011001 ; non-simple (VECTOR (UNSIGNED-BYTE 2)) */
  3584. #define b4vector_type ( BTB4|BTB3 |BTB1 ) /* 0x1A # %00011010 ; non-simple (VECTOR (UNSIGNED-BYTE 4)) */
  3585. #define b8vector_type ( BTB4|BTB3 |BTB1|BTB0) /* 0x1B # %00011011 ; non-simple (VECTOR (UNSIGNED-BYTE 8)) */
  3586. #define b16vector_type ( BTB4|BTB3|BTB2 ) /* 0x1C # %00011100 ; non-simple (VECTOR (UNSIGNED-BYTE 16)) */
  3587. #define b32vector_type ( BTB4|BTB3|BTB2 |BTB0) /* 0x1D # %00011101 ; non-simple (VECTOR (UNSIGNED-BYTE 32)) */
  3588. #define string_type ( BTB4|BTB3|BTB2|BTB1 ) /* 0x1E # %00011110 ; non-simple string */
  3589. #define vector_type ( BTB4|BTB3|BTB2|BTB1|BTB0) /* 0x1F # %00011111 ; non-simple (VECTOR T) */
  3590. #define fixnum_type ( BTB5 ) /* 0x20 # %00100000 ; fixnum */
  3591. #define sfloat_type ( BTB5 |BTB1 ) /* 0x22 # %00100010 ; short-float */
  3592. #define bignum_type ( BTB5 |BTB2 ) /* 0x24 # %00100100 ; bignum */
  3593. #define ffloat_type ( BTB5 |BTB2|BTB1 ) /* 0x26 # %00100110 ; single-float */
  3594. #define ratio_type ( BTB5 |BTB3 ) /* 0x28 # %00101000 ; ratio */
  3595. #define dfloat_type ( BTB5 |BTB3 |BTB1 ) /* 0x2A # %00101010 ; double-float */
  3596. #define complex_type ( BTB5 |BTB3|BTB2 ) /* 0x2C # %00101100 ; complex */
  3597. #define lfloat_type ( BTB5 |BTB3|BTB2|BTB1 ) /* 0x2E # %00101110 ; long-float */
  3598. #if (TB6 >= 0)
  3599. #define cons_type (BTB6 ) /* 0x40 # %01000000 ; cons */
  3600. #endif
  3601. /* Bits for symbols in VAR/FUN-Frames (in LISP-Stack):
  3602. aren't in the oint_type-part, but in the oint_addr-part. */
  3603. #define active_bit 0 /* set: binding is active */
  3604. #define dynam_bit 1 /* set: binding is dynamic */
  3605. #define svar_bit 2 /* set: next parameter is supplied-p-parameter for this */
  3606. #if (varobject_alignment >= bit(3))
  3607. #define oint_symbolflags_shift oint_addr_shift
  3608. #else
  3609. #define NO_symbolflags /* there's no space in the symbol for active_bit, dynam_bit, svar_bit */
  3610. #endif
  3611. #ifndef IMMEDIATE_FFLOAT
  3612. /* type is GC-invariant, if
  3613. type-info-byte >=0, <= system_type or >= fixnum_type, < bignum_type. */
  3614. #define gcinvariant_type_p(type) \
  3615. (((type) & ~(BTB5|BTB1|BTB0)) == 0)
  3616. #else
  3617. /* type is GC-invariant, if
  3618. type-info-byte is one of 0x00..0x03,0x20..0x23,0x26..0x27 ist. */
  3619. #if (TB1==TB0+1) && (TB2==TB0+2) && (TB3==TB0+3) && (TB4==TB0+4) && (TB5==TB0+5)
  3620. #define gcinvariant_type_p(type) \
  3621. ((((type)>>(TB0+1))<0x14) && ((bit((type)>>(TB0+1)) & 0xFFF4FFFCUL) == 0))
  3622. #else
  3623. /* Test whether ((type)>>TB1) is one of
  3624. 0, 1, bit(TB5-TB1), bit(TB5-TB1) | 1, bit(TB5-TB1) | bit(TB2-TB1) | 1. */
  3625. #define gcinvariant_type_p(type) gcinvariant_type_aux((type)>>TB1)
  3626. #define gcinvariant_type_sum(type) \
  3627. (((type) | ((type)>>(TB5-(TB2+1)))) & (((BTB2<<1)+BTB2+BTB1)>>TB1))
  3628. #define gcinvariant_type_aux(type) \
  3629. (((type) < ((BTB5+(BTB2<<1))>>TB1)) \
  3630. && ((type) & ~((BTB5|BTB2|BTB1)>>TB1)) == 0 \
  3631. && (bit(gcinvariant_type_sum(type)) \
  3632. & ( bit(0) \
  3633. | bit(1) \
  3634. | bit(bit(TB2+1-TB1)) \
  3635. | bit(bit(TB2+1-TB1) | 1) \
  3636. | bit(bit(TB2+1-TB1) | bit(TB2-TB1) | 1))) != 0)
  3637. #endif
  3638. #endif
  3639. #endif /* STANDARD_8BIT_TYPECODES */
  3640. #if !(gcinvariant_type_p(ffloat_type) == defined(IMMEDIATE_FFLOAT))
  3641. #error "gcinvariant_type_p() incorrectly implemented!"
  3642. #endif
  3643. /* Test for gc-invariant object. (This includes immediate, machine, subr.)
  3644. gcinvariant_object_p(obj) */
  3645. #define gcinvariant_object_p(obj) \
  3646. gcinvariant_type_p(typecode(obj))
  3647. #define gcinvariant_oint_p(obj_o) \
  3648. gcinvariant_type_p((tint)((obj_o) >> oint_type_shift) & (oint_type_mask >> oint_type_shift))
  3649. #else /* no TYPECODES */
  3650. /* Bits for symbols in VAR/FUN-Frames (on LISP-Stack):
  3651. are not located in the oint_type-part, but in the oint_data-part. */
  3652. #define active_bit 0 /* set: binding is active */
  3653. #define dynam_bit 1 /* set: binding is dynamic */
  3654. #define svar_bit 2 /* set: next parameter is supplied-p-parameter for this one */
  3655. #define NO_symbolflags /* there's no space in the symbol for active_bit, dynam_bit, svar_bit */
  3656. /* Bits for symbols in the flags: */
  3657. #define var_bit0_f 0 /* set if the symbol is proclaimed SPECIAL or constant */
  3658. #define var_bit1_f 1 /* set if the symbol is a symbol-macro or constant */
  3659. #endif /* TYPECODES */
  3660. %% #ifdef TYPECODES
  3661. %% export_def(gcinvariant_type_p(type));
  3662. %% export_def(gcinvariant_type_sum(type));
  3663. %% export_def(gcinvariant_type_aux(type));
  3664. %% export_def(gcinvariant_object_p(obj));
  3665. %% export_def(gcinvariant_oint_p(obj_o));
  3666. %% #endif
  3667. /* What's really being sent from an address to the address-bus */
  3668. #if defined(MC68000)
  3669. #define hardware_ 0x00FFFFFFUL /* 68000 drops 8 */
  3670. #elif defined(SUN3) && !defined(UNIX_SUNOS4)
  3671. #define hardware_addressbus_mask 0x0FFFFFFFUL /* SUN3 unter SunOS 3.5 wirft 4 Bits weg */
  3672. #else
  3673. #define hardware_addressbus_mask ~0UL /* Default: nothing is dropped */
  3674. #endif
  3675. /* Clever memory-mapping spares us from masking out of certain
  3676. bits before one accesses the address */
  3677. #define addressbus_mask hardware_addressbus_mask
  3678. #ifdef MAP_MEMORY
  3679. #if defined(SUN4_29)
  3680. /* Memory-mapping makes the bits 28..24 of an address redundant now. */
  3681. #undef addressbus_mask
  3682. #define addressbus_mask 0xE0FFFFFFUL
  3683. #elif defined(DECALPHA) && defined(UNIX_OSF)
  3684. /* Memory-mapping makes the bits 39..33 of an address redundant now. */
  3685. #undef addressbus_mask
  3686. #define addressbus_mask 0xFFFFFF01FFFFFFFFUL
  3687. #elif !defined(WIDE_SOFT)
  3688. /* Memory-mapping makes the bits 31..24 of an address redundant now. */
  3689. #undef addressbus_mask
  3690. #define addressbus_mask oint_addr_mask /* most of the time it's = 0x00FFFFFFUL */
  3691. #endif
  3692. #endif
  3693. %% #if notused
  3694. %% export_def(addressbus_mask);
  3695. %% #endif
  3696. #ifdef TYPECODES
  3697. /* You have to remove the typebits in order to access the components
  3698. of an object.
  3699. pointable(obj) does this, returning a void*.
  3700. pointable_unchecked(obj) likewise, but without the DEBUG_GCSAFETY check.
  3701. pointable_address_unchecked(obj_o) likewise, but takes an oint as argument
  3702. and returns an aint. */
  3703. #if !((oint_addr_shift==0) && (addr_shift==0))
  3704. #define pointable_unchecked(obj) ((void*)upointer(obj))
  3705. #define pointable_address_unchecked(obj_o) \
  3706. (((aint)((obj_o) >> oint_addr_shift) & (aint)(oint_addr_mask >> oint_addr_shift)) << addr_shift)
  3707. #else
  3708. #define pointable_unchecked(obj) \
  3709. ((void*)pointable_address_unchecked(as_oint(obj)))
  3710. /* If oint_addr_shift=0 and addr_shift=0, you don't have to shift. */
  3711. #if !((tint_type_mask & (addressbus_mask>>oint_type_shift)) == 0)
  3712. #define pointable_address_unchecked(obj_o) \
  3713. ((aint)(obj_o) & ((aint)oint_addr_mask | ~addressbus_mask))
  3714. #else
  3715. /* Moreover if oint_type_mask and addressbus_mask are disjoint
  3716. (((tint_type_mask<<oint_type_shift) & addressbus_mask) == 0),
  3717. no typebits are being sent to the address bus anyway.
  3718. So there's nothing to be done: */
  3719. #define pointable_address_unchecked(obj_o) (aint)(obj_o)
  3720. #endif
  3721. #endif
  3722. #ifdef DEBUG_GCSAFETY
  3723. /* Check that obj has not been held in a GC-unsafe variable while a
  3724. memory allocation was made. */
  3725. static inline void* pointable (gcv_object_t obj) {
  3726. return pointable_unchecked(obj);
  3727. }
  3728. static inline void* pointable (object obj) {
  3729. return pointable_unchecked((gcv_object_t)obj); /* The cast does the check. */
  3730. }
  3731. #else
  3732. #define pointable(obj) pointable_unchecked(obj)
  3733. #endif
  3734. /* If you want to access an object with a known type-info whose
  3735. set typebits are being swallowed by the address bus (the
  3736. typebits, that are =0 don't matter), you can do without 'untype': */
  3737. #if defined(DEBUG_GCSAFETY)
  3738. #define type_pointable(type,obj) pointable(obj)
  3739. #elif defined(WIDE_STRUCT)
  3740. #define type_pointable(type,obj) ((void*)((obj).u.both.addr))
  3741. #elif !((oint_addr_shift==0) && (addr_shift==0) && (((tint_type_mask<<oint_type_shift) & addressbus_mask) == 0))
  3742. #if (addr_shift==0)
  3743. #define type_pointable(type,obj) \
  3744. ((oint_addr_shift==0) && ((type_zero_oint(type) & addressbus_mask) == 0) \
  3745. ? (void*)(aint)as_oint(obj) \
  3746. : (void*)(aint)pointable(obj) \
  3747. )
  3748. #elif !(addr_shift==0)
  3749. /* Analogous, but here the macro 'optimized_upointer'
  3750. assumes the role of the address bus: */
  3751. #define type_pointable(type,obj) \
  3752. ((optimized_upointer(type_data_object(type,0)) == 0) \
  3753. ? (void*)(aint)optimized_upointer(obj) \
  3754. : (void*)(aint)pointable(obj) \
  3755. )
  3756. #endif
  3757. #else
  3758. /* If pointable(obj) = obj, type_pointable() doesn't do anything as well: */
  3759. #define type_pointable(type,obj) ((void*)(aint)as_oint(obj))
  3760. #endif
  3761. /* If you want to access an object that has one of several known
  3762. type infos, you can probably omit the 'untype'.
  3763. The OR of the type infos is more authoritative. */
  3764. #define types_pointable(ORed_types,obj) type_pointable(ORed_types,obj)
  3765. #else /* HEAPCODES */
  3766. #define pointable_address_unchecked(obj_o) \
  3767. (((aint)((obj_o) >> oint_addr_shift) & (aint)(oint_addr_mask >> oint_addr_shift)) << addr_shift)
  3768. #endif
  3769. %% #ifdef TYPECODES
  3770. %% export_def(pointable_unchecked(obj));
  3771. %% export_def(pointable_address_unchecked(obj_o));
  3772. %% #ifdef DEBUG_GCSAFETY
  3773. %% puts("static inline void* pointable (gcv_object_t obj) { return pointable_unchecked(obj); }");
  3774. %% puts("static inline void* pointable (object obj) { return pointable_unchecked((gcv_object_t)obj); }");
  3775. %% #else
  3776. %% emit_define("pointable(obj)","pointable_unchecked(obj)");
  3777. %% #endif
  3778. %% #endif
  3779. #if defined(SINGLEMAP_MEMORY) && (((system_type*1UL << oint_type_shift) & addressbus_mask) == 0)
  3780. /* The STACK resides in a singlemap-area as well, Typinfo system_type. */
  3781. #define SINGLEMAP_MEMORY_STACK
  3782. #endif
  3783. #ifdef oint_symbolflags_shift
  3784. #if defined(SINGLEMAP_MEMORY) && (oint_symbolflags_shift==oint_type_shift)
  3785. /* Since we can't multimap the symbol_tab, we can't use extrabits in
  3786. a symbol's typecode. */
  3787. #undef oint_symbolflags_shift
  3788. #define NO_symbolflags
  3789. #endif
  3790. #endif
  3791. #ifdef NO_symbolflags
  3792. #define oint_symbolflags_shift -1 /* invalid value */
  3793. #endif
  3794. /* Whether we try to initialize subr_tab statically.
  3795. (g++ 3.3 doesn't accept compound expressions as initializers: PR#12615.
  3796. g++ 3.4 similarly: PR#15180.) */
  3797. #if !(defined(WIDE_SOFT) && !defined(WIDE_STRUCT)) && !(defined(__GNUG__) && (__GNUC__ == 3) && (__GNUC_MINOR__ == 3 || __GNUC_MINOR__ == 4) && defined(OBJECT_STRUCT))
  3798. #define INIT_SUBR_TAB
  3799. #endif
  3800. /* NB: This has to be defined so external modules can work.
  3801. When changed: do nothing */
  3802. /* Whether we try to initialize symbol_tab statically.
  3803. (Make initialization easier, but there is not enough space for the
  3804. compilation of SPVWTABS on some systems.
  3805. EMX 0.9c (gcc-2.7.2.1) says "Virtual memory exhausted".
  3806. g++ 3.3 doesn't accept compound expressions as initializers: PR#12615.
  3807. g++ 3.4 similarly: PR#15180.) */
  3808. #if !(defined(WIDE_SOFT) && !defined(WIDE_STRUCT)) && !(defined(__GNUG__) && (__GNUC__ == 3) && (__GNUC_MINOR__ == 3 || __GNUC_MINOR__ == 4) && defined(OBJECT_STRUCT))
  3809. #define INIT_SYMBOL_TAB
  3810. #endif
  3811. /* When changed: nothing to do */
  3812. /* Whether we try to initialize object_tab statically.
  3813. (g++ 3.3 doesn't accept compound expressions as initializers: PR#12615.
  3814. g++ 3.4 similarly: PR#15180.) */
  3815. #if !(defined(WIDE_SOFT) && !defined(WIDE_STRUCT)) && !(defined(__GNUG__) && (__GNUC__ == 3) && (__GNUC_MINOR__ == 3 || __GNUC_MINOR__ == 4) && defined(OBJECT_STRUCT))
  3816. #define INIT_OBJECT_TAB
  3817. #endif
  3818. /* When changed: do nothing */
  3819. /* Set during the core of GC.
  3820. When this is set, unexpected handle_fault() calls that can
  3821. - if defined(MORRIS_GC) && defined(GENERATIONAL_GC) - copy
  3822. Morris-chain backpointers from a cons cell to an old_new_pointer_t with set
  3823. garcol_bit(!) into the heap, where they are guaranteed to lead to a crash
  3824. later. So, uncontrolled memory accesses are forbidden while inside_gc. */
  3825. extern bool inside_gc;
  3826. %% puts("extern bool inside_gc;");
  3827. #ifdef DEBUG_GCSAFETY
  3828. /* Forward declarations. */
  3829. static inline bool gcinvariant_symbol_p (object obj);
  3830. #ifdef LINUX_NOEXEC_HEAPCODES
  3831. static inline bool nonimmsubrp (object obj);
  3832. #else
  3833. #define nonimmsubrp(obj) false
  3834. #endif
  3835. /* Force a crash if a memory pointer points to nonexistent memory. */
  3836. #define nonimmprobe(obj_o) \
  3837. do { \
  3838. /* Don't do probes inside GC. It leads to unexpected handle_fault() \
  3839. calls that can - if defined(MORRIS_GC) && defined(GENERATIONAL_GC) - \
  3840. copy Morris-chain backpointers from a cons cell to an old_new_pointer_t \
  3841. with set garcol_bit(!) into the heap, where they are guaranteed to \
  3842. lead to a crash later. */ \
  3843. if (!inside_gc) \
  3844. if (((obj_o) & wbit(garcol_bit_o)) == 0) /* exclude frame words from the STACK */ \
  3845. if (!gcinvariant_oint_p(obj_o)) /* exclude immediate objects */ \
  3846. /* Access a single char, without needing to subtract the bias. */ \
  3847. *(volatile char *)pointable_address_unchecked(obj_o); \
  3848. } while (0)
  3849. /* When a gcv_object_t is fetched from a GC visible location (in the heap or
  3850. on the STACK) we can assume that GC has updated it. */
  3851. inline gcv_object_t::operator object () const {
  3852. nonimmprobe(one_o);
  3853. return (object){ one_o: one_o INIT_ALLOCSTAMP };
  3854. }
  3855. /* When an object is put into a GC visible location (in the heap or
  3856. on the STACK) we check that it has not been held in a GC-unsafe variable
  3857. while a memory allocation was made. */
  3858. inline gcv_object_t::gcv_object_t (object obj) {
  3859. if (!(gcinvariant_object_p(obj) || gcinvariant_symbol_p(obj)
  3860. || obj.allocstamp == alloccount || nonimmsubrp(obj)))
  3861. abort();
  3862. one_o = as_oint(obj);
  3863. nonimmprobe(one_o);
  3864. }
  3865. /* The only exception are fake gcv_objects. */
  3866. inline gcv_object_t::gcv_object_t (fake_gcv_object obj) {
  3867. one_o = obj.fake_value;
  3868. }
  3869. /* Uninitialized. */
  3870. inline gcv_object_t::gcv_object_t () {
  3871. }
  3872. /* Start of an area where no GC can be triggered. */
  3873. inline gcunsafe_object_t::gcunsafe_object_t (object obj)
  3874. : gcv_object_t (obj), allocstamp (alloccount) {}
  3875. inline gcunsafe_object_t::gcunsafe_object_t (gcv_object_t obj)
  3876. : gcv_object_t (obj), allocstamp (alloccount) {}
  3877. /* End of an area where no GC can be triggered. */
  3878. inline gcunsafe_object_t::~gcunsafe_object_t () {
  3879. if (!(allocstamp == alloccount))
  3880. abort();
  3881. }
  3882. #endif
  3883. %% #ifdef DEBUG_GCSAFETY
  3884. %% puts("static inline bool gcinvariant_symbol_p (object obj);");
  3885. %% #ifdef LINUX_NOEXEC_HEAPCODES
  3886. %% puts("static inline bool nonimmsubrp (object obj);");
  3887. %% #else
  3888. %% emit_define("nonimmsubrp(obj)","false");
  3889. %% #endif
  3890. %% export_def(nonimmprobe(obj_o));
  3891. %% puts("inline gcv_object_t::operator object () const { nonimmprobe(one_o); return (object){ one_o: one_o, allocstamp: alloccount }; }");
  3892. %% puts("inline gcv_object_t::gcv_object_t (object obj) { if (!(gcinvariant_object_p(obj) || gcinvariant_symbol_p(obj) || obj.allocstamp == alloccount || nonimmsubrp(obj))) abort(); one_o = as_oint(obj); nonimmprobe(one_o); }");
  3893. %% puts("inline gcv_object_t::gcv_object_t () {}");
  3894. %% #endif
  3895. /* Force a memory allocation for all functions which can trigger GC but
  3896. sometimes do and sometimes don't. This makes DEBUG_GCSAFETY more efficient.
  3897. GCTRIGGER() does a no-op memory allocation
  3898. GCTRIGGER1(obj1) likewise, but saves obj1 temporarily
  3899. GCTRIGGER2(obj1,obj2) likewise, but saves obj1, obj2 temporarily
  3900. ...
  3901. GCTRIGGER_IF(condition, statement)
  3902. likewise, but only if the condition is fulfilled */
  3903. #ifdef DEBUG_GCSAFETY
  3904. /* When these macros are used in C macros, obj1, obj2 etc. can sometimes be
  3905. expressions of type 'object' and sometimes of type 'gcv_object_t'. Need
  3906. two implementations of inc_allocstamp. */
  3907. inline void inc_allocstamp (object& obj) { obj.allocstamp++; }
  3908. inline void inc_allocstamp (gcv_object_t& obj) { }
  3909. #define GCTRIGGER() \
  3910. (void)(alloccount++)
  3911. #define GCTRIGGER1(obj1) \
  3912. (void)(inc_allocstamp(obj1), alloccount++)
  3913. #define GCTRIGGER2(obj1,obj2) \
  3914. (void)(inc_allocstamp(obj1), inc_allocstamp(obj2), alloccount++)
  3915. #define GCTRIGGER3(obj1,obj2,obj3) \
  3916. (void)(inc_allocstamp(obj1), inc_allocstamp(obj2), inc_allocstamp(obj3), alloccount++)
  3917. #define GCTRIGGER4(obj1,obj2,obj3,obj4) \
  3918. (void)(inc_allocstamp(obj1), inc_allocstamp(obj2), inc_allocstamp(obj3), inc_allocstamp(obj4), alloccount++)
  3919. #define GCTRIGGER5(obj1,obj2,obj3,obj4,obj5) \
  3920. (void)(inc_allocstamp(obj1), inc_allocstamp(obj2), inc_allocstamp(obj3), inc_allocstamp(obj4), inc_allocstamp(obj5), alloccount++)
  3921. #define GCTRIGGER6(obj1,obj2,obj3,obj4,obj5,obj6) \
  3922. (void)(inc_allocstamp(obj1), inc_allocstamp(obj2), inc_allocstamp(obj3), inc_allocstamp(obj4), inc_allocstamp(obj5), inc_allocstamp(obj6), alloccount++)
  3923. #define GCTRIGGER_IF(condition,statement) \
  3924. if (condition) statement
  3925. #else
  3926. #define GCTRIGGER() (void)0
  3927. #define GCTRIGGER1(obj1) (void)0
  3928. #define GCTRIGGER2(obj1,obj2) (void)0
  3929. #define GCTRIGGER3(obj1,obj2,obj3) (void)0
  3930. #define GCTRIGGER4(obj1,obj2,obj3,obj4) (void)0
  3931. #define GCTRIGGER5(obj1,obj2,obj3,obj4,obj5) (void)0
  3932. #define GCTRIGGER6(obj1,obj2,obj3,obj4,obj5,obj6) (void)0
  3933. #define GCTRIGGER_IF(condition,statement) (void)0
  3934. #endif
  3935. /* ################### Methods for memory management #####################
  3936. SPVW_BLOCKS : Memory management with few memory blocks
  3937. SPVW_PAGES : Memory management with many memory blocks
  3938. SPVW_MIXED : Objects of mixed types are possible on the same page or block
  3939. SPVW_PURE : Every memory block/every memory page contains only objects
  3940. of exactly one type */
  3941. #if defined(MAP_MEMORY) || defined(TRIVIALMAP_MEMORY)
  3942. /* Multimapping of single pages isn't implemented yet.??
  3943. Singlemapping of single pages isn't implemented yet.??
  3944. If you use mmap() as malloc()-replacement, single pages aren't needed. */
  3945. #define SPVW_BLOCKS
  3946. #elif defined(VIRTUAL_MEMORY)
  3947. /* On Unix-systems you can still fetch more memory afterwards,
  3948. but you should concentrate the data - if possible - on few pages. */
  3949. #define SPVW_PAGES
  3950. #else
  3951. #define SPVW_BLOCKS
  3952. #endif
  3953. #if defined(MULTIMAP_MEMORY)
  3954. /* MULTIMAP_MEMORY -> Mixed pages allow a better usage of memory. */
  3955. #define SPVW_MIXED
  3956. #elif defined(SINGLEMAP_MEMORY)
  3957. /* SINGLEMAP_MEMORY -> Ony pure pages/blocks make sense, since
  3958. the address of a page determines the type of the objects it contains. */
  3959. #define SPVW_PURE
  3960. #elif !defined(TYPECODES) || defined(MC68000) || defined(SUN3) || defined(SPVW_BLOCKS) || defined(TRIVIALMAP_MEMORY)
  3961. /* !TYPECODES -> there aren't real typecodes, only Cons and Varobject.
  3962. MC68000 or SUN3 -> type_pointable(...) costs little or nothing.
  3963. SPVW_BLOCKS -> SPVW_PURE_BLOCKS is only implemented for SINGLEMAP_MEMORY.
  3964. TRIVIALMAP_MEMORY -> not many blocks available, small adress space. */
  3965. #define SPVW_MIXED
  3966. #elif 1 /* provisionally!?? */
  3967. #define SPVW_MIXED
  3968. #endif
  3969. #if !(defined(SPVW_BLOCKS) || defined(SPVW_PAGES))
  3970. #error "readjust SPVW_BLOCKS/SPVW_PAGES!"
  3971. #endif
  3972. #if !(defined(SPVW_MIXED) || defined(SPVW_PURE))
  3973. #error "readjust SPVW_MIXED/SPVW_PURE!"
  3974. #endif
  3975. #if (defined(SPVW_BLOCKS) && defined(SPVW_PURE)) != defined(SINGLEMAP_MEMORY)
  3976. #error "SINGLEMAP_MEMORY <==> SPVW_PURE_BLOCKS!"
  3977. #endif
  3978. #if (defined(SPVW_BLOCKS) && defined(SPVW_MIXED)) < defined(TRIVIALMAP_MEMORY)
  3979. #error "TRIVIALMAP_MEMORY ==> SPVW_MIXED_BLOCKS!"
  3980. #endif
  3981. #if defined(SPVW_PURE) && !defined(TYPECODES)
  3982. #error "SPVW_PURE ==> TYPECODES!"
  3983. #endif
  3984. #if (defined(SPVW_BLOCKS) && (defined(SPVW_PURE) || defined(SPVW_MIXED))) < defined(GENERATIONAL_GC)
  3985. #error "GENERATIONAL_GC ==> SPVW_PURE_BLOCKS or SPVW_MIXED_BLOCKS_STAGGERED or SPVW_MIXED_BLOCKS_OPPOSITE!"
  3986. #endif
  3987. /* Algorithm by Morris, that compacts Conses without mixing them up: */
  3988. #if defined(SPVW_BLOCKS) && defined(VIRTUAL_MEMORY) && !defined(NO_MORRIS_GC)
  3989. /* Morris-GC is recommended, as it preserves the locality. */
  3990. #define MORRIS_GC
  3991. #endif
  3992. /* Put subr_tab and symbol_tab to given addresses through memory-mapping.
  3993. (The Morris-GC uses the macro upointer() for MULTIMAP_MEMORY. For
  3994. &symbol_tab = 0x20000000 it'd be upointer(NIL)=0. Darn!) */
  3995. #if defined(MAP_MEMORY) && !defined(WIDE_SOFT) && !(defined(MULTIMAP_MEMORY) && defined(MORRIS_GC))
  3996. #define MAP_MEMORY_TABLES
  3997. #endif
  3998. /* ################# definitions by cases with respect to type codes ################# */
  3999. #ifdef TYPECODES
  4000. /* Has to start with switch (typecode(obj)), after that it's like a
  4001. switch-statement with arbitrarily many case-labels.
  4002. Example: switch (typecode(arg)) { case_string: ...; break; ... } */
  4003. #define case_machine case machine_type /* machine-pointer */
  4004. #define case_sstring case sstring_type /* Simple-String */
  4005. #define case_ostring case string_type /* Other String */
  4006. #define case_sbvector case sbvector_type /* Simple-Bit-Vector */
  4007. #define case_obvector case bvector_type /* Other Bit-Vector */
  4008. #define case_sb2vector case sb2vector_type /* Simple-2Bit-Vector */
  4009. #define case_ob2vector case b2vector_type /* Other 2Bit-Vector */
  4010. #define case_sb4vector case sb4vector_type /* Simple-4Bit-Vector */
  4011. #define case_ob4vector case b4vector_type /* Other 4Bit-Vector */
  4012. #define case_sb8vector case sb8vector_type /* Simple-8Bit-Vector */
  4013. #define case_ob8vector case b8vector_type /* Other 8Bit-Vector */
  4014. #define case_sb16vector case sb16vector_type /* Simple-16Bit-Vector */
  4015. #define case_ob16vector case b16vector_type /* Other 16Bit-Vector */
  4016. #define case_sb32vector case sb32vector_type /* Simple-32Bit-Vector */
  4017. #define case_ob32vector case b32vector_type /* Other 32Bit-Vector */
  4018. #define case_svector case svector_type /* Simple-(General-)Vector */
  4019. #define case_ovector case vector_type /* Other (General-)Vector */
  4020. #define case_mdarray case mdarray_type /* other Array */
  4021. #define case_string case_sstring: case_ostring /* general string */
  4022. #define case_bvector case_sbvector: case_obvector /* general bit vector */
  4023. #define case_b2vector case_sb2vector: case_ob2vector /* general 2bit vector */
  4024. #define case_b4vector case_sb4vector: case_ob4vector /* general 4bit vector */
  4025. #define case_b8vector case_sb8vector: case_ob8vector /* general 8bit vector */
  4026. #define case_b16vector case_sb16vector: case_ob16vector /* general 16bit vector */
  4027. #define case_b32vector case_sb32vector: case_ob32vector /* general 32bit vector */
  4028. #define case_vector case_svector: case_ovector /* general vector */
  4029. #define case_array case_string: case_bvector: case_b2vector: case_b4vector: case_b8vector: case_b16vector: case_b32vector: case_vector: case_mdarray /* general Array */
  4030. #define case_closure case closure_type /* Closure */
  4031. #ifdef structure_type
  4032. #define case_structure case structure_type /* Structure */
  4033. #define _case_structure case_structure:
  4034. #else
  4035. #define structure_type orecord_type /* Structures are OtherRecords */
  4036. #define _case_structure
  4037. #endif
  4038. #ifdef stream_type
  4039. #define case_stream case stream_type /* Stream */
  4040. #define _case_stream case_stream:
  4041. #else
  4042. #define stream_type orecord_type /* Streams are OtherRecords */
  4043. #define _case_stream
  4044. #endif
  4045. #define case_orecord case orecord_type /* Other Record */
  4046. #define case_instance case instance_type /* CLOS-Instance */
  4047. #define case_lrecord case lrecord_type /* Long Record */
  4048. #define case_char case char_type /* Character */
  4049. #define case_subr case subr_type /* SUBR */
  4050. #define case_system case system_type /* Frame-Pointer, Small-Read-Label, System */
  4051. #define case_posfixnum case fixnum_type /* Fixnum >=0 */
  4052. #define case_negfixnum case fixnum_type|bit(sign_bit_t) /* Fixnum <0 */
  4053. #define case_fixnum case_posfixnum: case_negfixnum /* Fixnum */
  4054. #define case_posbignum case bignum_type /* Bignum >0 */
  4055. #define case_negbignum case bignum_type|bit(sign_bit_t) /* Bignum <0 */
  4056. #define case_bignum case_posbignum: case_negbignum /* Bignum */
  4057. #define case_integer case_fixnum: case_bignum /* Integer */
  4058. #define case_ratio case ratio_type: case ratio_type|bit(sign_bit_t) /* Ratio */
  4059. #ifdef SPVW_MIXED
  4060. #define _case_ratio case_ratio:
  4061. #else
  4062. #define _case_ratio
  4063. #endif
  4064. #define case_rational case_integer: case_ratio /* Rational */
  4065. #define case_sfloat case sfloat_type: case sfloat_type|bit(sign_bit_t) /* Short-Float */
  4066. #define case_ffloat case ffloat_type: case ffloat_type|bit(sign_bit_t) /* Single-Float */
  4067. #define case_dfloat case dfloat_type: case dfloat_type|bit(sign_bit_t) /* Double-Float */
  4068. #define case_lfloat case lfloat_type: case lfloat_type|bit(sign_bit_t) /* Long-Float */
  4069. #define case_float case_sfloat: case_ffloat: case_dfloat: case_lfloat /* Float */
  4070. #define case_real case_rational: case_float /* Real */
  4071. #define case_complex case complex_type /* Complex */
  4072. #ifdef SPVW_MIXED
  4073. #define _case_complex case_complex:
  4074. #else
  4075. #define _case_complex
  4076. #endif
  4077. #define case_number case_real: case_complex /* Number */
  4078. #define case_symbol case symbol_type /* Symbol */
  4079. #define case_sxrecord case_closure: _case_structure _case_stream _case_ratio _case_complex case_orecord: case_instance /* Srecord/Xrecord general */
  4080. #define case_record case_sxrecord: case_lrecord /* Lrecord/Srecord/Xrecord general */
  4081. #if /* !defined(NO_symbolflags) && */ (oint_symbolflags_shift==oint_type_shift)
  4082. #define case_symbolflagged /* Symbol with Flags */\
  4083. case symbol_type: \
  4084. case symbol_type|bit(active_bit): \
  4085. case symbol_type|bit(dynam_bit): \
  4086. case symbol_type|bit(dynam_bit)|bit(active_bit): \
  4087. case symbol_type|bit(svar_bit): \
  4088. case symbol_type|bit(svar_bit)|bit(active_bit): \
  4089. case symbol_type|bit(svar_bit)|bit(dynam_bit): \
  4090. case symbol_type|bit(svar_bit)|bit(dynam_bit)|bit(active_bit)
  4091. #else
  4092. #define case_symbolflagged case_symbol /* Symbol with flags */
  4093. #endif
  4094. #define case_cons case cons_type /* Cons */
  4095. #else
  4096. #define _case_structure
  4097. #define _case_stream
  4098. #endif
  4099. /* ################## Structure of memory of LISP objects ###################
  4100. uintWC is the Integer type for the lengths of Bignum, Lfloat, Iarray.
  4101. Subset relation: uintW <= uintWC <= uintC. */
  4102. #ifdef TYPECODES
  4103. #define intWCsize intCsize
  4104. typedef uintC uintWC;
  4105. typedef sintC sintWC;
  4106. #else
  4107. /* Type and sign are stored in the heap - only 16 bits for the length. */
  4108. #define intWCsize intWsize
  4109. typedef uintW uintWC;
  4110. typedef sintW sintWC;
  4111. #endif
  4112. /* uintWCoverflow(x) checks, if there has been an overflow after the execution
  4113. of an x++. */
  4114. #define uintWCoverflow(x) ((intWCsize<intLsize) && ((uintWC)(x)==0))
  4115. /* ---------------------- Objects with two pointers ---------------------- #
  4116. They contain just the two pointers, no header. The type must already be
  4117. known when the object is accessed.
  4118. Normally, Cons, Ratio, Complex can all be considered as pairs. But if
  4119. SPVW_MIXED, the heap statistics are a little unspecific if we mix the
  4120. three types; therefore in that case we let Ratio and Complex be Varobjects. */
  4121. #ifdef SPVW_MIXED
  4122. #define case_pair case_cons
  4123. #else
  4124. #define case_pair case_cons: case_ratio: case_complex
  4125. #endif
  4126. /* ---------------------- Objects of varying length ---------------------- #
  4127. The first word is reserved for garbage collection. Outside of garbage
  4128. collection, it contains a pointer to the object itself. Note that the
  4129. GC, when it moves an object, takes care not to modify the typecode of
  4130. this first word (except the GC bit, which it temporarily uses).
  4131. Type of the header flags: */
  4132. #if (oint_type_len<=8) && !defined(ARM) && !defined(DECALPHA) && !defined(IA64) && !defined(DEBUG_GCSAFETY)
  4133. /* Access to an individual byte is possible */
  4134. #define hfintsize intBsize
  4135. typedef uintB hfint;
  4136. #else
  4137. /* access to a full word */
  4138. #define hfintsize pointer_bitsize
  4139. typedef uintP hfint;
  4140. #endif
  4141. %% #if (oint_type_len<=8) && !defined(ARM) && !defined(DECALPHA) && !defined(IA64) && !defined(DEBUG_GCSAFETY)
  4142. %% emit_typedef("uintB","hfint");
  4143. %% #else
  4144. %% emit_typedef("uintP","hfint");
  4145. %% #endif
  4146. /* Objecs with variable length */
  4147. #ifdef TYPECODES
  4148. #ifdef DEBUG_GCSAFETY
  4149. #define VAROBJECT_HEADER \
  4150. gcv_object_t _GCself; /* Self pointer for GC, contains flags */
  4151. #else
  4152. #define VAROBJECT_HEADER \
  4153. union { \
  4154. gcv_object_t _GCself; /* Self pointer for GC */\
  4155. hfint flags[sizeof(gcv_object_t)/sizeof(hfint)]; /* Flags */\
  4156. } header;
  4157. #endif
  4158. #else
  4159. #define VAROBJECT_HEADER \
  4160. gcv_object_t GCself; /* Self pointer for GC */\
  4161. uintL tfl; /* type, flags, length */
  4162. #endif
  4163. typedef struct {
  4164. VAROBJECT_HEADER
  4165. } varobject_;
  4166. typedef varobject_ * Varobject;
  4167. #ifdef TYPECODES
  4168. #ifdef DEBUG_GCSAFETY
  4169. #define GCself _GCself
  4170. #define header_flags _GCself.one_o
  4171. #else
  4172. #define GCself header._GCself
  4173. /* The typecode can be found in the byte ((Varobject)p)->header_flags. */
  4174. #if !(oint_type_len>=hfintsize ? oint_type_shift%hfintsize==0 : floor(oint_type_shift,hfintsize)==floor(oint_type_shift+oint_type_len-1,hfintsize))
  4175. #error "Bogus header_flags -- redefine header_flags!"
  4176. #endif
  4177. #if BIG_ENDIAN_P
  4178. #define header_flags header.flags[sizeof(gcv_object_t)/sizeof(hfint)-1-floor(oint_type_shift,hfintsize)]
  4179. #else
  4180. #define header_flags header.flags[floor(oint_type_shift,hfintsize)]
  4181. #endif
  4182. #endif
  4183. /* it applies mtypecode(((Varobject)p)->GCself) =
  4184. (((Varobject)p)->header_flags >> (oint_type_shift%hfintsize)) & tint_type_mask
  4185. Bits for Symbols in the self pointer (see above):
  4186. define var_bit0_t ... # set if the symbol is proclaimed SPECIAL or constant
  4187. define var_bit1_t ... # set if the symbol is a symbol-macro or constant */
  4188. #define var_bit0_hf (var_bit0_t+(oint_type_shift%hfintsize))
  4189. #define var_bit1_hf (var_bit1_t+(oint_type_shift%hfintsize))
  4190. #else
  4191. /* Three possible layouts of type, flags, length:
  4192. 8 bits type, 24 bits length [Vrecord, Lrecord]
  4193. 8 bits type, 8 bits flags, 16 bits length [Srecord]
  4194. 8 bits type, 8 bits flags, 8 bits length, 8 bits xlength [Xrecord] */
  4195. #define vrecord_tfl(type,length) \
  4196. ((uintL)(uintB)(type)+((uintL)(length)<<8))
  4197. #define lrecord_tfl(type,length) \
  4198. ((uintL)(uintB)(type)+((uintL)(length)<<8))
  4199. #define srecord_tfl(type,flags,length) \
  4200. ((uintL)(uintB)(type)+((uintL)(uintB)(flags)<<8)+((uintL)(length)<<16))
  4201. #define xrecord_tfl(type,flags,length,xlength) \
  4202. ((uintL)(uintB)(type)+((uintL)(uintB)(flags)<<8)+((uintL)(uintB)(length)<<16)+((uintL)(uintB)(xlength)<<24))
  4203. #define varobject_type(ptr) ((sintB)((ptr)->tfl & 0xFF))
  4204. #if defined(__GNUC__) && (__GNUC__ == 2) && ((__GNUC_MINOR__ == 8) || (__GNUC_MINOR__ == 90))
  4205. /* Work around for a gcc bug present (at least) in gcc-2.8.1 on hppa and
  4206. egcs-1.0.3a on i386. It miscompiles xpathnamep. */
  4207. #undef varobject_type
  4208. #define varobject_type(ptr) ((sintB)((sintL)((ptr)->tfl) & 0xFF))
  4209. #endif
  4210. /* Bits for symbols in the flags: */
  4211. #define header_flags tfl
  4212. #define var_bit0_hf (var_bit0_f+8)
  4213. #define var_bit1_hf (var_bit1_f+8)
  4214. #endif
  4215. %% export_def(VAROBJECT_HEADER);
  4216. %% #ifndef TYPECODES
  4217. %% export_def(GCself);
  4218. %% export_def(varobject_type(ptr));
  4219. %% #endif
  4220. /* Records
  4221. These are varobjects with a one-byte type field in memory.
  4222. There are three types of records:
  4223. Vector-Records can have up to 16777215 elements, but have no flags and
  4224. if TYPECODES also no type (because the type info is in the pointer).
  4225. Long-Records can have up to 16777215 elements, but have no flags.
  4226. Simple-Records can have up to 65535 elements,
  4227. Extended-Records have room for up to 255 elements and 255 extra (non-Lisp)
  4228. elements.
  4229. Vector-Records are recognized by their type field:
  4230. rectype == Rectype_Sbvector, Rectype_Sb[2|4|8|16|32]vector,
  4231. Rectype_S[8|16|32]string, Rectype_Imm_S[8|16|32]string,
  4232. Rectype_Svector.
  4233. Long-Records are recognized by rectype >= rectype_longlimit, or if TYPECODES
  4234. equivalently by their typecode lrecord_type.
  4235. The others are partitioned into:
  4236. - Simple-Records, if rectype < rectype_limit.
  4237. - Extended-Records, if rectype >= rectype_limit. */
  4238. #ifdef TYPECODES
  4239. #define RECORD_HEADER \
  4240. VAROBJECT_HEADER /* self-pointer GC */ \
  4241. sintB rectype; /* for OtherRecord and LongRecord: sub-type */ \
  4242. uintB recflags; /* for OtherRecord: flags */ \
  4243. uintW reclength; /* lengths and others */
  4244. #else
  4245. #define RECORD_HEADER \
  4246. VAROBJECT_HEADER /* self-pointer for GC, tfl */
  4247. #endif
  4248. typedef struct {
  4249. RECORD_HEADER
  4250. gcv_object_t recdata[unspecified] _attribute_aligned_object_; /* elements */
  4251. } record_;
  4252. typedef record_ * Record;
  4253. /* access to type, flags: */
  4254. #ifdef TYPECODES
  4255. #define record_type(ptr) ((ptr)->rectype)
  4256. #else
  4257. #define record_type(ptr) varobject_type(ptr)
  4258. #endif
  4259. #define Record_type(obj) record_type(TheRecord(obj))
  4260. #ifdef TYPECODES
  4261. #define record_flags(ptr) ((ptr)->recflags)
  4262. #else
  4263. #define record_flags(ptr) (((ptr)->tfl >> 8) & 0xFF)
  4264. #endif
  4265. #define Record_flags(obj) record_flags(TheRecord(obj))
  4266. #ifdef TYPECODES
  4267. #define record_flags_clr(ptr,bits) ((ptr)->recflags &= ~(bits))
  4268. #define record_flags_set(ptr,bits) ((ptr)->recflags |= (bits))
  4269. #define record_flags_replace(ptr,newflags) ((ptr)->recflags = (newflags))
  4270. #else
  4271. #define record_flags_clr(ptr,bits) ((ptr)->tfl &= ~((uintL)(bits) << 8))
  4272. #define record_flags_set(ptr,bits) ((ptr)->tfl |= ((uintL)(bits) << 8))
  4273. #define record_flags_replace(ptr,newflags) \
  4274. ((ptr)->tfl ^= (((ptr)->tfl ^ (uintL)(newflags)<<8) & 0xFF00))
  4275. #endif
  4276. %% export_def(RECORD_HEADER);
  4277. %% sprintf(buf,"struct { RECORD_HEADER gcv_object_t recdata[unspecified]%s; }",attribute_aligned_object);
  4278. %% emit_typedef(buf,"record_");
  4279. %% emit_typedef("record_ *","Record");
  4280. %% export_def(record_type(ptr));
  4281. %% export_def(Record_type(obj));
  4282. %% export_def(record_flags(ptr));
  4283. %% export_def(record_flags_set(ptr,bits));
  4284. %% export_def(Record_flags(obj));
  4285. #ifdef TYPECODES
  4286. #define VRECORD_HEADER \
  4287. VAROBJECT_HEADER /* self-pointer for GC */\
  4288. uintL length; /* length */
  4289. #else
  4290. #define VRECORD_HEADER \
  4291. VAROBJECT_HEADER /* self-pointer for GC, tfl */
  4292. #endif
  4293. typedef struct {
  4294. VRECORD_HEADER
  4295. } vrecord_;
  4296. typedef vrecord_ * Vrecord;
  4297. #ifdef TYPECODES
  4298. #define vrecord_length(ptr) ((ptr)->length)
  4299. #else
  4300. #define vrecord_length(ptr) ((ptr)->tfl >> 8)
  4301. #endif
  4302. %% export_def(VRECORD_HEADER);
  4303. %% emit_typedef("struct { VRECORD_HEADER }","vrecord_");
  4304. %% emit_typedef("vrecord_ *","Vrecord");
  4305. %% export_def(vrecord_length(ptr));
  4306. #ifdef TYPECODES
  4307. #define LRECORD_HEADER \
  4308. VAROBJECT_HEADER /* self-pointer for GC */\
  4309. uintL tfl; /* subtype (1 byte), then length (3 bytes) */
  4310. #else
  4311. #define LRECORD_HEADER \
  4312. VAROBJECT_HEADER /* self-pointer for GC, tfl */
  4313. #endif
  4314. typedef struct {
  4315. LRECORD_HEADER
  4316. gcv_object_t recdata[unspecified] _attribute_aligned_object_; /* reclength elements */
  4317. } lrecord_;
  4318. typedef lrecord_ * Lrecord;
  4319. #ifdef TYPECODES
  4320. #if BIG_ENDIAN_P
  4321. #define lrecord_tfl(type,length) \
  4322. (((uintL)(uintB)(type)<<24)+(uintL)(length))
  4323. #define lrecord_length(ptr) ((ptr)->tfl & 0xFFFFFF)
  4324. #else
  4325. #define lrecord_tfl(type,length) \
  4326. ((uintL)(uintB)(type)+((uintL)(length)<<8))
  4327. #define lrecord_length(ptr) ((ptr)->tfl >> 8)
  4328. #endif
  4329. #else
  4330. #define lrecord_length(ptr) ((ptr)->tfl >> 8)
  4331. #endif
  4332. #define Lrecord_length(obj) lrecord_length(TheLrecord(obj))
  4333. #ifdef TYPECODES
  4334. #define SRECORD_HEADER \
  4335. VAROBJECT_HEADER /* self-pointer GC */\
  4336. sintB rectype; /* subtype, < rectype_limit */\
  4337. uintB recflags; /* flags */\
  4338. uintW reclength; /* lengths in objects */
  4339. #else
  4340. #define SRECORD_HEADER \
  4341. VAROBJECT_HEADER /* self-pointer for GC, tfl */
  4342. #endif
  4343. typedef struct {
  4344. SRECORD_HEADER
  4345. gcv_object_t recdata[unspecified] _attribute_aligned_object_; /* reclength elements */
  4346. } srecord_;
  4347. typedef srecord_ * Srecord;
  4348. #ifdef TYPECODES
  4349. #define srecord_length(ptr) ((ptr)->reclength)
  4350. #else
  4351. #define srecord_length(ptr) ((ptr)->tfl >> 16)
  4352. #endif
  4353. #define Srecord_length(obj) srecord_length(TheSrecord(obj))
  4354. %% export_def(SRECORD_HEADER);
  4355. %% sprintf(buf,"struct { SRECORD_HEADER gcv_object_t recdata[unspecified]%s; }",attribute_aligned_object);
  4356. %% emit_typedef(buf,"srecord_");
  4357. %% emit_typedef("srecord_ *","Srecord");
  4358. %% export_def(srecord_length(ptr));
  4359. #ifdef TYPECODES
  4360. #define XRECORD_HEADER \
  4361. VAROBJECT_HEADER /* self-pointer for GC */\
  4362. sintB rectype; /* subtype, >= rectype_limit */\
  4363. uintB recflags; /* flags */\
  4364. uintB reclength; /* lengths in objects */\
  4365. uintB recxlength; /* lengths of the extra objects */
  4366. #else
  4367. #define XRECORD_HEADER \
  4368. VAROBJECT_HEADER /* self-pointer for GC, tfl */
  4369. #endif
  4370. typedef struct {
  4371. XRECORD_HEADER
  4372. gcv_object_t recdata[unspecified] _attribute_aligned_object_; /* reclength elements */
  4373. /* uintB recxdata[unspecified]; # recxlength extra elements */
  4374. } xrecord_;
  4375. typedef xrecord_ * Xrecord;
  4376. #ifdef TYPECODES
  4377. #define xrecord_length(ptr) ((ptr)->reclength)
  4378. #define xrecord_xlength(ptr) ((ptr)->recxlength)
  4379. #else
  4380. #define xrecord_length(ptr) (((ptr)->tfl >> 16) & 0xFF)
  4381. #define xrecord_xlength(ptr) ((ptr)->tfl >> 24)
  4382. #endif
  4383. #define Xrecord_length(obj) xrecord_length(TheXrecord(obj))
  4384. #define Xrecord_xlength(obj) xrecord_xlength(TheXrecord(obj))
  4385. %% export_def(XRECORD_HEADER);
  4386. %% #if notused
  4387. %% sprintf(buf,"struct { XRECORD_HEADER gcv_object_t recdata[unspecified]%s; }",attribute_aligned_object);
  4388. %% emit_typedef(buf,"xrecord_");
  4389. %% emit_typedef("xrecord_ *","Xrecord");
  4390. %% #endif
  4391. /* *** Possible rectype values for records. *** */
  4392. enum {
  4393. enum_rectype_first = -4, /* Try to keep rectype_limit = 0. */
  4394. Rectype_Closure,
  4395. %% printf("#define Rectype_Closure %d\n",Rectype_Closure);
  4396. Rectype_Structure, /* only used #ifndef case_structure */
  4397. %% printf("#define Rectype_Structure %d\n",Rectype_Structure);
  4398. Rectype_Instance,
  4399. %% printf("#define Rectype_Instance %d\n",Rectype_Instance);
  4400. rectype_limit, /* Here is the limit between Srecord and Xrecord. */
  4401. Rectype_Hashtable = rectype_limit,
  4402. %% printf("#define Rectype_Hashtable %d\n",Rectype_Hashtable);
  4403. #ifndef TYPECODES
  4404. %% #ifndef TYPECODES
  4405. /* Rectype_vector is the bottom ARRAY & VECTOR */
  4406. Rectype_vector, /* 1 -- Iarray, not Srecord/Xrecord */
  4407. %% printf("#define Rectype_vector %d\n",Rectype_vector);
  4408. Rectype_bvector, /* 2 -- Iarray, not Srecord/Xrecord */
  4409. %% printf("#define Rectype_bvector %d\n",Rectype_bvector);
  4410. Rectype_b2vector, /* 3 -- Iarray, not Srecord/Xrecord */
  4411. %% printf("#define Rectype_b2vector %d\n",Rectype_b2vector);
  4412. Rectype_b4vector, /* 4 -- Iarray, not Srecord/Xrecord */
  4413. %% printf("#define Rectype_b4vector %d\n",Rectype_b4vector);
  4414. Rectype_b8vector, /* 5 -- Iarray, not Srecord/Xrecord */
  4415. %% printf("#define Rectype_b8vector %d\n",Rectype_b8vector);
  4416. Rectype_b16vector, /* 6 -- Iarray, not Srecord/Xrecord */
  4417. %% printf("#define Rectype_b16vector %d\n",Rectype_b16vector);
  4418. Rectype_b32vector, /* 7 -- Iarray, not Srecord/Xrecord */
  4419. %% printf("#define Rectype_b32vector %d\n",Rectype_b32vector);
  4420. Rectype_unused1, /* 8 */
  4421. /* Rectype_Svector is the bottom SIMPLE VECTOR */
  4422. Rectype_Svector, /* 9 -- Svector, not Srecord/Xrecord */
  4423. %% printf("#define Rectype_Svector %d\n",Rectype_Svector);
  4424. Rectype_Sbvector, /* 10 -- Sbvector, not Srecord/Xrecord */
  4425. %% printf("#define Rectype_Sbvector %d\n",Rectype_Sbvector);
  4426. Rectype_Sb2vector, /* 11 -- Sbvector, not Srecord/Xrecord */
  4427. %% printf("#define Rectype_Sb2vector %d\n",Rectype_Sb2vector);
  4428. Rectype_Sb4vector, /* 12 -- Sbvector, not Srecord/Xrecord */
  4429. %% printf("#define Rectype_Sb4vector %d\n",Rectype_Sb4vector);
  4430. Rectype_Sb8vector, /* 13 -- Sbvector, not Srecord/Xrecord */
  4431. %% printf("#define Rectype_Sb8vector %d\n",Rectype_Sb8vector);
  4432. Rectype_Sb16vector, /* 14 -- Sbvector, not Srecord/Xrecord */
  4433. %% printf("#define Rectype_Sb16vector %d\n",Rectype_Sb16vector);
  4434. Rectype_Sb32vector, /* 15 -- Sbvector, not Srecord/Xrecord */
  4435. %% printf("#define Rectype_Sb32vector %d\n",Rectype_Sb32vector);
  4436. Rectype_unused2, /* 16 */
  4437. /* Rectype_S8string is the bottom STRING */
  4438. Rectype_S8string, /* 17 -- S8string, not Srecord/Xrecord */
  4439. %% printf("#define Rectype_S8string %d\n",Rectype_S8string);
  4440. Rectype_Imm_S8string, /* 18 -- immutable S8string, not Srecord/Xrecord */
  4441. %% printf("#define Rectype_Imm_S8string %d\n",Rectype_Imm_S8string);
  4442. Rectype_S16string, /* 19 -- S16string, not Srecord/Xrecord */
  4443. %% printf("#define Rectype_S16string %d\n",Rectype_S16string);
  4444. Rectype_Imm_S16string, /* 20 -- immutable S16string, not Srecord/Xrecord */
  4445. %% printf("#define Rectype_Imm_S16string %d\n",Rectype_Imm_S16string);
  4446. Rectype_S32string, /* 21 -- S32string, not Srecord/Xrecord */
  4447. %% printf("#define Rectype_S32string %d\n",Rectype_S32string);
  4448. Rectype_Imm_S32string, /* 22 -- immutable S32string, not Srecord/Xrecord */
  4449. %% printf("#define Rectype_Imm_S32string %d\n",Rectype_Imm_S32string);
  4450. Rectype_reallocstring, /* 23 -- reallocated simple string, an Sistring, only used #ifdef HAVE_SMALL_SSTRING */
  4451. %% printf("#define Rectype_reallocstring %d\n",Rectype_reallocstring);
  4452. /* Rectype_reallocstring is the top SIMPLE-STRING & SIMPLE-VECTOR */
  4453. Rectype_string, /* 24 -- Iarray, not Srecord/Xrecord */
  4454. %% printf("#define Rectype_string %d\n",Rectype_string);
  4455. /* Rectype_string is the top STRING */
  4456. Rectype_mdarray, /* 25 -- Iarray, not Srecord/Xrecord */
  4457. %% printf("#define Rectype_mdarray %d\n",Rectype_mdarray);
  4458. /* Rectype_mdarray is the top ARRAY
  4459. Rectype_Bignum is the bottom NUMBER */
  4460. Rectype_Bignum, /* Bignum, not Srecord/Xrecord */
  4461. %% printf("#define Rectype_Bignum %d\n",Rectype_Bignum);
  4462. Rectype_Lfloat, /* Lfloat, not Srecord/Xrecord */
  4463. %% printf("#define Rectype_Lfloat %d\n",Rectype_Lfloat);
  4464. Rectype_Dfloat,
  4465. %% printf("#define Rectype_Dfloat %d\n",Rectype_Dfloat);
  4466. Rectype_Ffloat,
  4467. %% printf("#define Rectype_Ffloat %d\n",Rectype_Ffloat);
  4468. %% #endif
  4469. #endif /* TYPECODES */
  4470. #ifdef SPVW_MIXED
  4471. %% #ifdef SPVW_MIXED
  4472. Rectype_Ratio,
  4473. %% printf("#define Rectype_Ratio %d\n",Rectype_Ratio);
  4474. Rectype_Complex,
  4475. %% printf("#define Rectype_Complex %d\n",Rectype_Complex);
  4476. %% #endif
  4477. #endif /* SPVW_MIXED */
  4478. /* *** Here the numbers end. *** */
  4479. #ifndef TYPECODES
  4480. %% #ifndef TYPECODES
  4481. Rectype_Symbol,
  4482. %% printf("#define Rectype_Symbol %d\n",Rectype_Symbol);
  4483. %% #endif
  4484. #endif /* TYPECODES */
  4485. Rectype_Package,
  4486. %% printf("#define Rectype_Package %d\n",Rectype_Package);
  4487. Rectype_Readtable,
  4488. %% printf("#define Rectype_Readtable %d\n",Rectype_Readtable);
  4489. Rectype_Pathname,
  4490. %% printf("#define Rectype_Pathname %d\n",Rectype_Pathname);
  4491. #ifdef LOGICAL_PATHNAMES
  4492. %% #ifdef LOGICAL_PATHNAMES
  4493. Rectype_Logpathname,
  4494. %% printf("#define Rectype_Logpathname %d\n",Rectype_Logpathname);
  4495. %% #endif
  4496. #endif /* LOGICAL_PATHNAMES */
  4497. Rectype_Random_State,
  4498. %% printf("#define Rectype_Random_State %d\n",Rectype_Random_State);
  4499. #ifndef case_stream
  4500. %% #ifndef case_stream
  4501. Rectype_Stream,
  4502. %% printf("#define Rectype_Stream %d\n",Rectype_Stream);
  4503. %% #endif
  4504. #endif /* case_stream */
  4505. Rectype_Byte,
  4506. %% printf("#define Rectype_Byte %d\n",Rectype_Byte);
  4507. Rectype_Subr,
  4508. %% printf("#define Rectype_Subr %d\n",Rectype_Subr);
  4509. Rectype_Fsubr,
  4510. %% printf("#define Rectype_Fsubr %d\n",Rectype_Fsubr);
  4511. Rectype_Loadtimeeval,
  4512. %% printf("#define Rectype_Loadtimeeval %d\n",Rectype_Loadtimeeval);
  4513. Rectype_Symbolmacro,
  4514. %% printf("#define Rectype_Symbolmacro %d\n",Rectype_Symbolmacro);
  4515. Rectype_GlobalSymbolmacro,
  4516. %% printf("#define Rectype_GlobalSymbolmacro %d\n",Rectype_GlobalSymbolmacro);
  4517. Rectype_Macro,
  4518. %% printf("#define Rectype_Macro %d\n",Rectype_Macro);
  4519. Rectype_FunctionMacro,
  4520. %% printf("#define Rectype_FunctionMacro %d\n",Rectype_FunctionMacro);
  4521. Rectype_BigReadLabel,
  4522. %% printf("#define Rectype_BigReadLabel %d\n",Rectype_BigReadLabel);
  4523. Rectype_Encoding,
  4524. %% printf("#define Rectype_Encoding %d\n",Rectype_Encoding);
  4525. Rectype_Fpointer, /* only used #ifdef FOREIGN */
  4526. %% printf("#define Rectype_Fpointer %d\n",Rectype_Fpointer);
  4527. #ifdef DYNAMIC_FFI
  4528. %% #ifdef DYNAMIC_FFI
  4529. Rectype_Faddress,
  4530. %% printf("#define Rectype_Faddress %d\n",Rectype_Faddress);
  4531. Rectype_Fvariable,
  4532. %% printf("#define Rectype_Fvariable %d\n",Rectype_Fvariable);
  4533. Rectype_Ffunction,
  4534. %% printf("#define Rectype_Ffunction %d\n",Rectype_Ffunction);
  4535. %% #endif
  4536. #endif /* DYNAMIC_FFI */
  4537. Rectype_Weakpointer,
  4538. %% printf("#define Rectype_Weakpointer %d\n",Rectype_Weakpointer);
  4539. Rectype_MutableWeakList,
  4540. %% printf("#define Rectype_MutableWeakList %d\n",Rectype_MutableWeakList);
  4541. Rectype_MutableWeakAlist,
  4542. %% printf("#define Rectype_MutableWeakAlist %d\n",Rectype_MutableWeakAlist);
  4543. Rectype_Weakmapping,
  4544. %% printf("#define Rectype_Weakmapping %d\n",Rectype_Weakmapping);
  4545. Rectype_Finalizer,
  4546. %% printf("#define Rectype_Finalizer %d\n",Rectype_Finalizer);
  4547. #ifdef SOCKET_STREAMS
  4548. %% #ifdef SOCKET_STREAMS
  4549. Rectype_Socket_Server,
  4550. %% printf("#define Rectype_Socket_Server %d\n",Rectype_Socket_Server);
  4551. %% #endif
  4552. #endif /* SOCKET_STREAMS */
  4553. #ifdef YET_ANOTHER_RECORD
  4554. %% #ifdef YET_ANOTHER_RECORD
  4555. Rectype_Yetanother,
  4556. %% printf("#define Rectype_Yetanother %d\n",Rectype_Yetanother);
  4557. %% #endif
  4558. #endif /* YET_ANOTHER_RECORD */
  4559. rectype_longlimit, /* the boundary between Srecord/Xrecord and Lrecord. */
  4560. Rectype_WeakList,
  4561. %% printf("#define Rectype_WeakList %d\n",Rectype_WeakList);
  4562. Rectype_WeakAnd,
  4563. %% printf("#define Rectype_WeakAnd %d\n",Rectype_WeakAnd);
  4564. Rectype_WeakOr,
  4565. %% printf("#define Rectype_WeakOr %d\n",Rectype_WeakOr);
  4566. Rectype_WeakAndMapping,
  4567. %% printf("#define Rectype_WeakAndMapping %d\n",Rectype_WeakAndMapping);
  4568. Rectype_WeakOrMapping,
  4569. %% printf("#define Rectype_WeakOrMapping %d\n",Rectype_WeakOrMapping);
  4570. Rectype_WeakAlist_Key,
  4571. %% printf("#define Rectype_WeakAlist_Key %d\n",Rectype_WeakAlist_Key);
  4572. Rectype_WeakAlist_Value,
  4573. %% printf("#define Rectype_WeakAlist_Value %d\n",Rectype_WeakAlist_Value);
  4574. Rectype_WeakAlist_Either,
  4575. %% printf("#define Rectype_WeakAlist_Either %d\n",Rectype_WeakAlist_Either);
  4576. Rectype_WeakAlist_Both,
  4577. %% printf("#define Rectype_WeakAlist_Both %d\n",Rectype_WeakAlist_Both);
  4578. Rectype_WeakHashedAlist_Key,
  4579. %% printf("#define Rectype_WeakHashedAlist_Key %d\n",Rectype_WeakHashedAlist_Key);
  4580. Rectype_WeakHashedAlist_Value,
  4581. %% printf("#define Rectype_WeakHashedAlist_Value %d\n",Rectype_WeakHashedAlist_Value);
  4582. Rectype_WeakHashedAlist_Either,
  4583. %% printf("#define Rectype_WeakHashedAlist_Either %d\n",Rectype_WeakHashedAlist_Either);
  4584. Rectype_WeakHashedAlist_Both,
  4585. %% printf("#define Rectype_WeakHashedAlist_Both %d\n",Rectype_WeakHashedAlist_Both);
  4586. #ifdef MULTITHREAD
  4587. %% #ifdef MULTITHREAD
  4588. Rectype_Thread,
  4589. %% printf("#define Rectype_Thread %d\n",Rectype_Thread);
  4590. Rectype_Mutex,
  4591. %% printf("#define Rectype_Mutex %d\n",Rectype_Mutex);
  4592. Rectype_Exemption,
  4593. %% printf("#define Rectype_Exemption %d\n",Rectype_Exemption);
  4594. %% #endif
  4595. #endif
  4596. rectype_for_broken_compilers_that_dont_like_trailing_commas
  4597. };
  4598. /* -------------------------- the various types -------------------------- */
  4599. /* Cons */
  4600. typedef struct {
  4601. gcv_object_t cdr _attribute_aligned_object_; /* CDR */
  4602. gcv_object_t car _attribute_aligned_object_; /* CAR */
  4603. } cons_;
  4604. typedef cons_ * Cons;
  4605. %% sprintf(buf,"struct { gcv_object_t cdr%s; gcv_object_t car%s; }",attribute_aligned_object,attribute_aligned_object);
  4606. %% emit_typedef(buf,"cons_");
  4607. %% emit_typedef("cons_ *","Cons");
  4608. /* Ratio */
  4609. typedef struct {
  4610. #ifdef SPVW_MIXED
  4611. XRECORD_HEADER
  4612. #endif
  4613. gcv_object_t rt_num _attribute_aligned_object_; /* numerator, Integer */
  4614. gcv_object_t rt_den _attribute_aligned_object_; /* denominator, Integer >0 */
  4615. } ratio_;
  4616. typedef ratio_ * Ratio;
  4617. %% #if notused
  4618. %% #ifdef SPVW_MIXED
  4619. %% sprintf(buf,"struct { XRECORD_HEADER gcv_object_t rt_num%s; gcv_object_t rt_den%s; }",attribute_aligned_object,attribute_aligned_object);
  4620. %% #else
  4621. %% sprintf(buf,"struct { gcv_object_t rt_num%s; gcv_object_t rt_den%s; }",attribute_aligned_object,attribute_aligned_object);
  4622. %% #endif
  4623. %% emit_typedef(buf,"ratio_");
  4624. %% emit_typedef("ratio_ *","Ratio");
  4625. %% #endif
  4626. /* Complex */
  4627. typedef struct {
  4628. #ifdef SPVW_MIXED
  4629. XRECORD_HEADER
  4630. #endif
  4631. gcv_object_t c_real _attribute_aligned_object_; /* real part, real number */
  4632. gcv_object_t c_imag _attribute_aligned_object_; /* imaginary part, real number */
  4633. } complex_;
  4634. typedef complex_ * Complex;
  4635. %% #if notused
  4636. %% #ifdef SPVW_MIXED
  4637. %% sprintf(buf,"struct { XRECORD_HEADER gcv_object_t c_real%s; gcv_object_t c_imag%s; }",attribute_aligned_object,attribute_aligned_object);
  4638. %% #else
  4639. %% sprintf(buf,"struct { gcv_object_t c_real%s; gcv_object_t c_imag%s; }",attribute_aligned_object,attribute_aligned_object);
  4640. %% #endif
  4641. %% emit_typedef(buf,"complex_");
  4642. %% emit_typedef("complex_ *","Complex");
  4643. %% #endif
  4644. /* Symbol */
  4645. typedef struct {
  4646. VAROBJECT_HEADER
  4647. gcv_object_t symvalue _attribute_aligned_object_; /* value cell */
  4648. gcv_object_t symfunction _attribute_aligned_object_; /* function definition cell */
  4649. gcv_object_t hashcode _attribute_aligned_object_; /* hash code */
  4650. gcv_object_t proplist _attribute_aligned_object_; /* property list */
  4651. gcv_object_t pname _attribute_aligned_object_; /* Printname */
  4652. gcv_object_t homepackage _attribute_aligned_object_; /* Home-Package or NIL */
  4653. /* If necessary, add fillers here to ensure sizeof(subr_t) is a multiple of
  4654. varobject_alignment. */
  4655. #if defined(LINUX_NOEXEC_HEAPCODES) && 0
  4656. gcv_object_t filler _attribute_aligned_object_;
  4657. #endif
  4658. } symbol_;
  4659. typedef symbol_ * Symbol;
  4660. #ifdef LINUX_NOEXEC_HEAPCODES
  4661. /* Compile-time check: sizeof(symbol_) is a multiple of varobject_alignment. */
  4662. typedef int symbol_size_check[1 - 2 * (int)(sizeof(symbol_) % varobject_alignment)];
  4663. #endif
  4664. #define symbol_objects_offset offsetof(symbol_,symvalue)
  4665. #define symbol_length 6
  4666. %% #if defined(LINUX_NOEXEC_HEAPCODES) && 0
  4667. %% sprintf(buf,"struct { VAROBJECT_HEADER gcv_object_t symvalue%s; gcv_object_t symfunction%s; gcv_object_t hashcode%s; gcv_object_t proplist%s; gcv_object_t pname%s; gcv_object_t homepackage%s; gcv_object_t filler%s; }",attribute_aligned_object,attribute_aligned_object,attribute_aligned_object,attribute_aligned_object,attribute_aligned_object,attribute_aligned_object,attribute_aligned_object);
  4668. %% #else
  4669. %% sprintf(buf,"struct { VAROBJECT_HEADER gcv_object_t symvalue%s; gcv_object_t symfunction%s; gcv_object_t hashcode%s; gcv_object_t proplist%s; gcv_object_t pname%s; gcv_object_t homepackage%s; }",attribute_aligned_object,attribute_aligned_object,attribute_aligned_object,attribute_aligned_object,attribute_aligned_object,attribute_aligned_object);
  4670. %% #endif
  4671. %% emit_typedef(buf,"symbol_");
  4672. %% emit_typedef("symbol_ *","Symbol");
  4673. /* Every keyword is a constant. */
  4674. /* Tests whether a symbol is a keyword: */
  4675. #define keywordp(sym) \
  4676. (eq(TheSymbol(sym)->homepackage,O(keyword_package)))
  4677. /* For constants, the special-bit is meaningless (since constants
  4678. can't be bound lexically nor dynamically). */
  4679. /* Tests whether a symbol is a constant: */
  4680. #define constant_var_p(sym) \
  4681. (((bit(var_bit0_hf)|bit(var_bit1_hf)) & ~((sym)->header_flags)) == 0)
  4682. /* Tests whether a symbol is a SPECIAL-proclaimed variable or a constant: */
  4683. #define special_var_p(sym) (((sym)->header_flags) & bit(var_bit0_hf))
  4684. /* Tests whether a symbol is a symbol-macro: */
  4685. #define symmacro_var_p(sym) \
  4686. ((((sym)->header_flags) & bit(var_bit1_hf)) \
  4687. && ((((sym)->header_flags) & bit(var_bit0_hf)) == 0))
  4688. /* Set the constant-flag of a non-symbol-macro symbol: */
  4689. #define set_const_flag(sym) \
  4690. (((sym)->header_flags) |= bit(var_bit0_hf)|bit(var_bit1_hf))
  4691. /* Delete the constant-flag of a symbol that is a constant:
  4692. (Symbol must not be a Keyword, comp. spvw.d:case_symbolwithflags) */
  4693. #define clear_const_flag(sym) \
  4694. (((sym)->header_flags) &= ~(bit(var_bit0_hf)|bit(var_bit1_hf)))
  4695. /* Set the special-flag of a non-symbol-macro symbol: */
  4696. #define set_special_flag(sym) \
  4697. (((sym)->header_flags) |= bit(var_bit0_hf))
  4698. /* Delete the special-flag of a symbol that is special and non-constant: */
  4699. #define clear_special_flag(sym) \
  4700. (((sym)->header_flags) &= ~bit(var_bit0_hf))
  4701. /* Set the symbol-macro-flag of a non-special/constant symbol: */
  4702. #define set_symmacro_flag(sym) \
  4703. (((sym)->header_flags) |= bit(var_bit1_hf))
  4704. /* Delete the symbol-macro-flag of a symbol that is a symbol-macro: */
  4705. #define clear_symmacro_flag(sym) \
  4706. (((sym)->header_flags) &= ~bit(var_bit1_hf))
  4707. /* Define symbol as constant with given value val.
  4708. val must not trigger the GC! */
  4709. #define define_constant(sym,val) \
  4710. do { var Symbol sym_from_define_constant = TheSymbol(sym); \
  4711. set_const_flag(sym_from_define_constant); \
  4712. sym_from_define_constant->symvalue = (val); \
  4713. } while(0)
  4714. /* Define symbol as variable and initialize it with a given value val.
  4715. val must not trigger the GC! */
  4716. #define define_variable(sym,val) \
  4717. do { var Symbol sym_from_define_variable = TheSymbol(sym); \
  4718. set_special_flag(sym_from_define_variable); \
  4719. sym_from_define_variable->symvalue = (val); \
  4720. } while(0)
  4721. /* Remove flag-bits of a symbol: */
  4722. #if defined(NO_symbolflags)
  4723. #define symbol_without_flags(symbol) symbol
  4724. #elif (oint_symbolflags_shift==oint_type_shift)
  4725. #define symbol_without_flags(symbol) \
  4726. as_object(as_oint(symbol) & (type_zero_oint(symbol_type) | oint_addr_mask))
  4727. #else
  4728. #define symbol_without_flags(symbol) \
  4729. as_object(as_oint(symbol) & ~((wbit(active_bit)|wbit(dynam_bit)|wbit(svar_bit))<<oint_symbolflags_shift))
  4730. #endif
  4731. /* add a flag to the object */
  4732. #define SET_BIT(o,b) as_object(as_oint(o) | wbit(b));
  4733. /* remove a flag from the object */
  4734. #define CLR_BIT(o,b) as_object(as_oint(o) & ~wbit(b));
  4735. /* Characters */
  4736. /* Integer type holding the data of a character: */
  4737. #ifdef UNICODE
  4738. #define char_int_len 24 /* anything between 21 and 32 will do */
  4739. #define char_int_limit 0x110000UL
  4740. #else
  4741. #define char_int_len 8
  4742. #define char_int_limit 0x100UL
  4743. #endif
  4744. typedef unsigned_int_with_n_bits(char_int_len) cint;
  4745. #define char_code_limit char_int_limit
  4746. /* Converting an integral code to a character: */
  4747. #define int_char(int_from_int_char) \
  4748. type_data_object(char_type,(aint)(cint)(int_from_int_char))
  4749. /* Converting a character to an integral code: */
  4750. #if !((oint_data_shift==0) && (char_int_len<=oint_data_len) && (exact_uint_size_p(char_int_len)))
  4751. #ifdef TYPECODES
  4752. #define char_int(char_from_char_int) \
  4753. ((cint)(untype(char_from_char_int)))
  4754. #else
  4755. #if (char_type>>oint_data_shift)==0 || (char_int_len<=16)
  4756. #define char_int(char_from_char_int) \
  4757. ((cint)(as_oint(char_from_char_int)>>oint_data_shift))
  4758. #else
  4759. #define char_int(char_from_char_int) \
  4760. ((cint)((as_oint(char_from_char_int)>>oint_data_shift)&(bitm(oint_data_len)-1)))
  4761. #endif
  4762. #endif
  4763. #else
  4764. /* If oint_data_shift=0, untype does not need to shift. If also
  4765. char_int_len<=oint_data_len, and if a cint has exactly char_int_len
  4766. bits, untype does not need to AND. */
  4767. #define char_int(char_from_char_int) \
  4768. ((cint)as_oint(char_from_char_int))
  4769. #endif
  4770. /* Characters can therefore be compared for equality using EQ, this is an
  4771. oint comparison, among the characters a comparison of their integral code. */
  4772. %% sprintf(buf,"uint%d",char_int_len); emit_typedef(buf,"cint");
  4773. %% export_def(int_char(int_from_int_char));
  4774. %% export_def(char_int(char_from_char_int));
  4775. /* A standalone character. Prefer `chart' to `cint' wherever possible because
  4776. it is typesafe. sizeof(chart) = sizeof(cint). */
  4777. #ifdef CHART_STRUCT
  4778. #ifdef __cplusplus
  4779. struct chart { chart() {} chart(int c) : one_c(c) {} cint one_c; };
  4780. #else
  4781. typedef struct { cint one_c; } chart;
  4782. #endif
  4783. #else
  4784. typedef cint chart;
  4785. #endif
  4786. /* Conversions between both:
  4787. as_cint(ch) chart --> cint
  4788. as_chart(c) cint --> chart */
  4789. #ifdef CHART_STRUCT
  4790. #define as_cint(ch) ((ch).one_c)
  4791. #if 1
  4792. #ifdef __cplusplus
  4793. inline chart as_chart(int c) { return chart(c); }
  4794. #else
  4795. #define as_chart(c) ((chart){one_c:(c)})
  4796. #endif
  4797. #else
  4798. extern __inline__ chart as_chart (register cint c)
  4799. { register chart ch; ch.one_c = c; return ch; }
  4800. #endif
  4801. #else
  4802. #define as_cint(ch) (ch)
  4803. #define as_chart(c) (c)
  4804. #endif
  4805. /* Conversion chart --> object. */
  4806. #define code_char(ch) int_char(as_cint(ch))
  4807. /* Conversion object --> chart. */
  4808. #define char_code(obj) as_chart(char_int(obj))
  4809. /* Comparison operations. */
  4810. #define chareq(ch1,ch2) (as_cint(ch1) == as_cint(ch2))
  4811. #define charlt(ch1,ch2) (as_cint(ch1) < as_cint(ch2))
  4812. #define chargt(ch1,ch2) (as_cint(ch1) > as_cint(ch2))
  4813. %% #ifdef CHART_STRUCT
  4814. %% emit_typedef("struct { cint one_c; }","chart");
  4815. %% #else
  4816. %% emit_typedef("cint","chart");
  4817. %% #endif
  4818. %% export_def(as_cint(ch));
  4819. %% export_def(as_chart(c));
  4820. %% export_def(code_char(ch));
  4821. %% export_def(char_code(obj));
  4822. /* Conversion standard char (in ASCII encoding) --> chart. */
  4823. #define ascii(x) as_chart((uintB)(x))
  4824. /* Conversion standard char (in ASCII encoding) --> object. */
  4825. #define ascii_char(x) code_char(ascii(x))
  4826. /* Test for STANDARD-CHAR. */
  4827. #define standard_cint_p(x) ((('~' >= (x)) && ((x) >= ' ')) || ((x) == NL))
  4828. /* Whether to use three different kinds of string representations. */
  4829. #if defined(UNICODE) && (defined(GNU) || (defined(UNIX) && !defined(NO_ALLOCA) && !defined(SPARC)) || defined(BORLAND) || defined(MICROSOFT)) && !defined(NO_SMALL_SSTRING)
  4830. #define HAVE_SMALL_SSTRING
  4831. #endif
  4832. #ifdef HAVE_SMALL_SSTRING
  4833. #define if_HAVE_SMALL_SSTRING(statement) statement
  4834. /* We have three kinds of simple strings, with 8-bit codes (ISO-8859-1
  4835. strings), with 16-bit codes (UCS-2 strings) and with 32-bit codes
  4836. (UCS-4/UTF-32 strings). */
  4837. typedef uint8 cint8;
  4838. #define cint8_limit (1UL<<8)
  4839. typedef uint16 cint16;
  4840. #define cint16_limit (1UL<<16)
  4841. typedef uint32 cint32;
  4842. #define cint32_limit 0x110000UL
  4843. #else
  4844. #define if_HAVE_SMALL_SSTRING(statement) /*nop*/
  4845. /* Only one kind of simple strings. */
  4846. typedef cint cint8;
  4847. #define cint8_limit char_int_limit
  4848. typedef cint cint16;
  4849. #define cint16_limit char_int_limit
  4850. typedef cint cint32;
  4851. #define cint32_limit char_int_limit
  4852. #endif
  4853. %% #ifdef HAVE_SMALL_SSTRING
  4854. %% emit_typedef("uint8","cint8");
  4855. %% emit_typedef("uint16","cint16");
  4856. %% emit_typedef("uint32","cint32");
  4857. %% #endif
  4858. /* Base characters. */
  4859. #define base_char_int_len char_int_len
  4860. #define base_char_code_limit char_code_limit
  4861. /* The BASE-CHAR type is defined as
  4862. (upgraded-array-element-type 'standard-char),
  4863. i.e. the element-type of arrays created with (make-array 'standard-char ...).
  4864. Since it defeats the purpose of UNICODE to have different 8-bit, 16-bit
  4865. and 24-bit character types, we define BASE-CHAR=CHARACTER. */
  4866. /* Fixnums */
  4867. /* fixnum(x) is a fixnum with value x>=0.
  4868. x is an expression with 0 <= x < 2^oint_data_len.
  4869. (Should really be called posfixnum(x).) */
  4870. #define fixnum(x) type_data_object(fixnum_type,x)
  4871. %% export_def(fixnum(x));
  4872. /* Fixnum_0 is the number 0, Fixnum_1 is the number 1,
  4873. Fixnum_minus1 is the number -1 */
  4874. #define Fixnum_0 fixnum(0)
  4875. #define Fixnum_1 fixnum(1)
  4876. #define Fixnum_minus1 type_data_object( fixnum_type | bit(sign_bit_t), vbitm(oint_data_len)-1 )
  4877. %% export_def(Fixnum_0);
  4878. %% export_def(Fixnum_1);
  4879. %% export_def(Fixnum_minus1);
  4880. /* Value of a non-negative fixnum:
  4881. posfixnum_to_V(obj)
  4882. result is >= 0, < 2^oint_data_len. */
  4883. #if !(defined(SPARC) && (oint_data_len+oint_data_shift<32))
  4884. #define posfixnum_to_V(obj) \
  4885. ((uintV)((as_oint(obj)&((oint)wbitm(oint_data_len+oint_data_shift)-1))>>oint_data_shift))
  4886. #else
  4887. /* Long constants are slower than shifts on a SPARC-processor: */
  4888. #define posfixnum_to_V(obj) \
  4889. ((uintV)((as_oint(obj) << (32-oint_data_len-oint_data_shift)) >> (32-oint_data_len)))
  4890. #endif
  4891. %% export_def(posfixnum_to_V(obj));
  4892. /* Value of a negative fixnum:
  4893. negfixnum_to_V(obj)
  4894. Result is >= - 2^oint_data_len, < 0. */
  4895. #define negfixnum_to_V(obj) (posfixnum_to_V(obj) | (-vbitm(oint_data_len)))
  4896. %% #if notused
  4897. %% export_def(negfixnum_to_V(obj));
  4898. %% #endif
  4899. /* Absolute value of a negative fixnum:
  4900. negfixnum_abs_V(obj)
  4901. Result is > 0, <= 2^oint_data_len.
  4902. Beware: Possible wraparound at oint_data_len=intVsize! */
  4903. #define negfixnum_abs_V(obj) \
  4904. ((uintV)((as_oint(fixnum_inc(Fixnum_minus1,1))-as_oint(obj))>>oint_data_shift))
  4905. /* Value of a fixnum, obj should be a variable:
  4906. fixnum_to_V(obj)
  4907. Result is >= - 2^oint_data_len, < 2^oint_data_len and of Type sintV.
  4908. This macro should only be used for oint_data_len+1 <= intLsize! */
  4909. #if (oint_data_len>=intVsize)
  4910. /* No space left for the sign-bit, thus fixnum_to_V = posfixnum_to_V = negfixnum_to_V ! */
  4911. #define fixnum_to_V(obj) (sintV)posfixnum_to_V(obj)
  4912. #elif (sign_bit_o == oint_data_len+oint_data_shift)
  4913. #define fixnum_to_V(obj) \
  4914. (((sintV)as_oint(obj) << (intVsize-1-sign_bit_o)) >> (intVsize-1-sign_bit_o+oint_data_shift))
  4915. #else
  4916. #if !defined(SPARC)
  4917. #define fixnum_to_V(obj) \
  4918. (sintV)( ((((sintV)as_oint(obj) >> sign_bit_o) << (intVsize-1)) >> (intVsize-1-oint_data_len)) \
  4919. |((uintV)((as_oint(obj) & ((oint)wbitm(oint_data_len+oint_data_shift)-1)) >> oint_data_shift)) \
  4920. )
  4921. #else
  4922. /* Long constants are slower than shifts on a SPARC-processor: */
  4923. #define fixnum_to_V(obj) \
  4924. (sintV)( ((((sintV)as_oint(obj) >> sign_bit_o) << (intVsize-1)) >> (intVsize-1-oint_data_len)) \
  4925. |(((uintV)as_oint(obj) << (intVsize-oint_data_len-oint_data_shift)) >> (intVsize-oint_data_len)) \
  4926. )
  4927. #endif
  4928. #endif
  4929. %% export_def(fixnum_to_V(obj));
  4930. #ifdef intQsize
  4931. /* Value of a fixnum, obj should be a variable:
  4932. fixnum_to_Q(obj)
  4933. Result is >= - 2^oint_data_len, < 2^oint_data_len. */
  4934. #if (sign_bit_o == oint_data_len+oint_data_shift)
  4935. #define fixnum_to_Q(obj) \
  4936. (((sintQ)as_oint(obj) << (intQsize-1-sign_bit_o)) >> (intQsize-1-sign_bit_o+oint_data_shift))
  4937. #else
  4938. #define fixnum_to_Q(obj) \
  4939. (sintQ)( ((((sintQ)as_oint(obj) >> sign_bit_o) << (intQsize-1)) >> (intQsize-1-oint_data_len)) \
  4940. |((uintQ)((as_oint(obj) & (wbitm(oint_data_len+oint_data_shift)-1)) >> oint_data_shift)) \
  4941. )
  4942. #endif
  4943. #endif
  4944. /* Add a constant to a non-negative fixnum, given that
  4945. the result is a non-negative fixnum as well:
  4946. fixnum_inc(obj,delta)
  4947. > obj: a fixnum
  4948. > delta: a constant
  4949. < result: incremented fixnum */
  4950. #define fixnum_inc(obj,delta) \
  4951. objectplus(obj, (soint)(delta) << oint_data_shift)
  4952. %% export_def(fixnum_inc(obj,delta));
  4953. /* posfixnum(x) is a fixnum with value x>=0. */
  4954. #define posfixnum(x) fixnum_inc(Fixnum_0,x)
  4955. %% export_def(posfixnum(x));
  4956. /* negfixnum(x) is a fixnum with value x<0.
  4957. (Beware if x is unsigned!) */
  4958. #define negfixnum(x) fixnum_inc(fixnum_inc(Fixnum_minus1,1),x)
  4959. %% export_def(negfixnum(x));
  4960. /* sfixnum(x) is a fixnum with value x,
  4961. x is a constant-expression with -2^oint_data_len <= x < 2^oint_data_len. */
  4962. #define sfixnum(x) ((x)>=0 ? posfixnum(x) : negfixnum(x))
  4963. %% export_def(sfixnum(x));
  4964. /* Convert a character into a fixnum >=0 (the same as for char-int): */
  4965. #ifdef WIDE_STRUCT
  4966. #define char_to_fixnum(obj) \
  4967. type_data_object(fixnum_type,untype(obj))
  4968. #else
  4969. #define char_to_fixnum(obj) \
  4970. objectplus(obj,type_zero_oint(fixnum_type)-type_zero_oint(char_type))
  4971. #endif
  4972. /* Make a character from a fitting fixnum >=0 (the same as for int-char): */
  4973. #ifdef WIDE_STRUCT
  4974. #define fixnum_to_char(obj) \
  4975. type_data_object(char_type,untype(obj))
  4976. #else
  4977. #define fixnum_to_char(obj) \
  4978. objectplus(obj,type_zero_oint(char_type)-type_zero_oint(fixnum_type))
  4979. #endif
  4980. /* Bignums */
  4981. typedef struct {
  4982. VAROBJECT_HEADER /* self-pointer for GC */
  4983. #ifdef TYPECODES
  4984. uintC length; /* length in digits */
  4985. #endif
  4986. uintD data[unspecified]; /* number as its two's complement representation */
  4987. } bignum_;
  4988. typedef bignum_ * Bignum;
  4989. /* The length is actually an uintWC. */
  4990. #ifdef TYPECODES
  4991. #define bignum_length(ptr) ((ptr)->length)
  4992. #else
  4993. #define bignum_length(ptr) srecord_length(ptr)
  4994. #endif
  4995. #define Bignum_length(obj) bignum_length(TheBignum(obj))
  4996. %% #ifdef TYPECODES
  4997. %% emit_typedef("struct { VAROBJECT_HEADER uintC length; uintD data[unspecified]; }","bignum_");
  4998. %% #else
  4999. %% emit_typedef("struct { VAROBJECT_HEADER uintD data[unspecified]; }","bignum_");
  5000. %% #endif
  5001. %% emit_typedef("bignum_ *","Bignum");
  5002. %% export_def(bignum_length(ptr));
  5003. %% export_def(Bignum_length(obj));
  5004. /* Single-Floats */
  5005. typedef uint32 ffloat; /* 32-Bit-Float in IEEE-format */
  5006. typedef union {
  5007. ffloat eksplicit; /* Value, explicit */
  5008. #ifdef FAST_FLOAT
  5009. float machine_float; /* Value, as C-'float' */
  5010. #endif
  5011. } ffloatjanus;
  5012. #if !defined(IMMEDIATE_FFLOAT)
  5013. typedef struct {
  5014. VAROBJECT_HEADER /* self-pointer for GC */
  5015. ffloatjanus representation; /* Value */
  5016. } ffloat_;
  5017. typedef ffloat_ * Ffloat;
  5018. #define ffloat_value(obj) (TheFfloat(obj)->float_value)
  5019. #else
  5020. /* The float-value is stored in the pointer itself, like short-floats. */
  5021. #define ffloat_value(obj) ((ffloat)untype(obj))
  5022. #endif
  5023. %% emit_typedef("uint32","ffloat");
  5024. %% emit_typedef("union { ffloat eksplicit; }","ffloatjanus");
  5025. /* Double-Floats */
  5026. typedef /* 64-Bit-Float in IEEE-format: */
  5027. #ifdef intQsize
  5028. /* Sign/Exponent/Mantissa */
  5029. uint64
  5030. #else
  5031. /* Sign/Exponent/MantissaHigh and MantissaLow */
  5032. #if BIG_ENDIAN_P || defined(ARM)
  5033. struct {uint32 semhi,mlo;}
  5034. #else
  5035. struct {uint32 mlo,semhi;}
  5036. #endif
  5037. #endif
  5038. dfloat;
  5039. typedef union {
  5040. dfloat eksplicit; /* Value, explicit */
  5041. #ifdef FAST_DOUBLE
  5042. double machine_double; /* Value, as C-'double' */
  5043. #endif
  5044. } dfloatjanus;
  5045. typedef struct {
  5046. VAROBJECT_HEADER /* self-pointer for GC */
  5047. dfloatjanus representation; /* value */
  5048. } dfloat_;
  5049. typedef dfloat_ * Dfloat;
  5050. %% #ifdef intQsize
  5051. %% emit_typedef("uint64","dfloat");
  5052. %% #else
  5053. %% #if BIG_ENDIAN_P
  5054. %% emit_typedef("struct {uint32 semhi,mlo;}","dfloat");
  5055. %% #else
  5056. %% emit_typedef("struct {uint32 mlo,semhi;}","dfloat");
  5057. %% #endif
  5058. %% #endif
  5059. %% emit_typedef("union { dfloat eksplicit; }","dfloatjanus");
  5060. /* Single- and Double-Floats */
  5061. #define float_value representation.eksplicit
  5062. /* Long-Floats */
  5063. typedef struct {
  5064. VAROBJECT_HEADER /* Self-pointer for GC */
  5065. #ifdef TYPECODES
  5066. uintC len; /* length of the mantissa in digits */
  5067. #endif
  5068. uint32 expo; /* exponent */
  5069. uintD data[unspecified]; /* mantissa */
  5070. } lfloat_;
  5071. typedef lfloat_ * Lfloat;
  5072. /* The length is actually an uintWC. */
  5073. #ifdef TYPECODES
  5074. #define lfloat_length(ptr) ((ptr)->len)
  5075. #else
  5076. #define lfloat_length(ptr) srecord_length(ptr)
  5077. #endif
  5078. #define Lfloat_length(obj) lfloat_length(TheLfloat(obj))
  5079. /* simple array (cover simple linear arrays: simple bit vector, simple vector) */
  5080. typedef struct {
  5081. VRECORD_HEADER /* Self-pointer for GC, length in elements */
  5082. } sarray_;
  5083. typedef sarray_ * Sarray;
  5084. #define sarray_length(ptr) vrecord_length(ptr)
  5085. #define Sarray_length(obj) sarray_length(TheSarray(obj))
  5086. %% #if notused
  5087. %% emit_typedef("struct { VRECORD_HEADER }","sarray_");
  5088. %% emit_typedef("sarray_ *","Sarray");
  5089. %% #endif
  5090. %% export_def(sarray_length(ptr));
  5091. %% export_def(Sarray_length(obj));
  5092. /* simple bit vector */
  5093. typedef struct {
  5094. VRECORD_HEADER /* self-pointer for GC, length in bits */
  5095. uint8 data[unspecified]; /* Bits, divided into bytes */
  5096. } sbvector_;
  5097. typedef sbvector_ * Sbvector;
  5098. #define sbvector_length(ptr) sarray_length(ptr)
  5099. #define Sbvector_length(obj) sbvector_length(TheSbvector(obj))
  5100. %% emit_typedef("struct { VRECORD_HEADER uint8 data[unspecified]; }","sbvector_");
  5101. %% emit_typedef("sbvector_ *","Sbvector");
  5102. %% export_def(sbvector_length(ptr));
  5103. %% export_def(Sbvector_length(obj));
  5104. /* simple string template */
  5105. #ifdef TYPECODES
  5106. #define SSTRING_HEADER \
  5107. VAROBJECT_HEADER /* self-pointer for GC */\
  5108. uintL tfl; /* type, flags, length */
  5109. #else
  5110. #define SSTRING_HEADER \
  5111. VAROBJECT_HEADER /* self-pointer for GC, tfl */
  5112. #endif
  5113. typedef struct {
  5114. SSTRING_HEADER
  5115. } sstring_;
  5116. typedef sstring_ * Sstring;
  5117. #define STRUCT_SSTRING(cint_type) \
  5118. struct { \
  5119. SSTRING_HEADER /* self-pointer for GC, type+flags, length in characters */ \
  5120. cint_type data[unspecified]; /* characters */ \
  5121. }
  5122. #ifdef HAVE_SMALL_SSTRING
  5123. typedef STRUCT_SSTRING(cint8) s8string_;
  5124. typedef s8string_ * S8string;
  5125. typedef STRUCT_SSTRING(cint16) s16string_;
  5126. typedef s16string_ * S16string;
  5127. typedef STRUCT_SSTRING(cint32) s32string_;
  5128. typedef s32string_ * S32string;
  5129. #else
  5130. /* Only one kind of simple strings. */
  5131. #ifdef UNICODE
  5132. typedef STRUCT_SSTRING(cint32) s32string_;
  5133. typedef s32string_ * S32string;
  5134. /* Aliases. */
  5135. typedef s32string_ s16string_;
  5136. typedef S32string S16string;
  5137. typedef s32string_ s8string_;
  5138. typedef S32string S8string;
  5139. #else
  5140. typedef STRUCT_SSTRING(cint8) s8string_;
  5141. typedef s8string_ * S8string;
  5142. /* Aliases. */
  5143. typedef s8string_ s16string_;
  5144. typedef S8string S16string;
  5145. typedef s8string_ s32string_;
  5146. typedef S8string S32string;
  5147. #endif
  5148. #endif
  5149. /* A "normal simple string" is one of maximum-width element type.
  5150. It cannot be reallocated. Only strings with smaller element type
  5151. (called "small simple strings") can be reallocated. */
  5152. typedef STRUCT_SSTRING(chart) snstring_;
  5153. typedef snstring_ * Snstring;
  5154. /* These accessors work on any simple string, except reallocated simple-strings. */
  5155. #ifdef TYPECODES
  5156. #define sstring_length(ptr) ((ptr)->tfl >> 6)
  5157. #else
  5158. #define sstring_length(ptr) ((ptr)->tfl >> 10)
  5159. #endif
  5160. #define Sstring_length(obj) sstring_length(TheSstring(obj))
  5161. /* Maximum allowed simple-string length: */
  5162. #ifdef TYPECODES
  5163. #define stringsize_limit_1 ((uintL)(bit(intLsize-6)-1))
  5164. #else
  5165. #define stringsize_limit_1 ((uintL)(bit(intLsize-10)-1))
  5166. #endif
  5167. /* Constructing the tfl word: */
  5168. #ifdef TYPECODES
  5169. #define sstring_tfl(eltype,imm,flags,length) \
  5170. (((length) << 6) + ((eltype) << 4) + ((imm) << 3) + (flags))
  5171. #else
  5172. /* This must be consistent with vrecord_tfl. */
  5173. #define sstringrecord_tfl(rectype,flags,length) \
  5174. (((length) << 10) + ((flags) << 8) + (rectype))
  5175. #define sstring_tfl(eltype,imm,flags,length) \
  5176. sstringrecord_tfl(Rectype_S8string + ((eltype) << 1) + (imm),flags,length)
  5177. #endif
  5178. /* Test whether a simple string is reallocated: */
  5179. #ifdef HAVE_SMALL_SSTRING
  5180. #ifdef TYPECODES
  5181. #define sstringflags_forwarded_B bit(2)
  5182. #define sstring_reallocatedp(ptr) ((ptr)->tfl & sstringflags_forwarded_B)
  5183. #else
  5184. #define sstring_reallocatedp(ptr) (record_type(ptr) == Rectype_reallocstring)
  5185. #endif
  5186. #else
  5187. #define sstring_reallocatedp(ptr) 0
  5188. #endif
  5189. /* Extract the element type of a not-reallocated simple string: */
  5190. #ifdef TYPECODES
  5191. #define sstring_eltype(ptr) (((ptr)->tfl >> 4) & 3)
  5192. #else
  5193. #define sstring_eltype(ptr) ((record_type(ptr) - Rectype_S8string) >> 1)
  5194. #endif
  5195. /* Possible values of sstring_eltype: */
  5196. #define Sstringtype_8Bit 0
  5197. #define Sstringtype_16Bit 1
  5198. #define Sstringtype_32Bit 2
  5199. /* Extract the immutable bit of a simple string (reallocated or not): */
  5200. #ifdef TYPECODES
  5201. #define sstring_immutable(ptr) (((ptr)->tfl >> 3) & 1)
  5202. #else
  5203. #define sstring_immutable(ptr) ((record_type(ptr) - Rectype_S8string) & 1)
  5204. #endif
  5205. /* Extract the flags of a simple string (reallocated or not): */
  5206. #ifdef TYPECODES
  5207. /* Three bits, containing also sstringflags_forwarded_B. */
  5208. #define sstring_flags(ptr) ((ptr)->tfl & 7)
  5209. #define sstring_flags_clr(ptr,bits) ((ptr)->tfl &= ~(uintL)(bits))
  5210. #define sstring_flags_set(ptr,bits) ((ptr)->tfl |= (uintL)(bits))
  5211. #else
  5212. #define sstring_flags(ptr) (((ptr)->tfl >> 8) & 3)
  5213. #define sstring_flags_clr(ptr,bits) ((ptr)->tfl &= ~((uintL)(bits) << 8))
  5214. #define sstring_flags_set(ptr,bits) ((ptr)->tfl |= ((uintL)(bits) << 8))
  5215. #endif
  5216. /* Bit masks in the flags. Only used during garbage collection. */
  5217. #define sstringflags_backpointer_B bit(0)
  5218. #define sstringflags_relocated_B bit(1)
  5219. #define mark_sstring_clean(ptr) \
  5220. sstring_flags_clr(ptr,sstringflags_backpointer_B|sstringflags_relocated_B)
  5221. %% export_def(SSTRING_HEADER);
  5222. %% emit_typedef("struct { SSTRING_HEADER }","sstring_");
  5223. %% emit_typedef("sstring_ *","Sstring");
  5224. %% #ifdef HAVE_SMALL_SSTRING
  5225. %% export_def(STRUCT_SSTRING(cint_type));
  5226. %% emit_typedef("STRUCT_SSTRING(cint8)","s8string_");
  5227. %% emit_typedef("s8string_ *","S8string");
  5228. %% emit_typedef("STRUCT_SSTRING(cint16)","s16string_");
  5229. %% emit_typedef("s16string_ *","S16string");
  5230. %% emit_typedef("STRUCT_SSTRING(cint32)","s32string_");
  5231. %% emit_typedef("s32string_ *","S32string");
  5232. %% #endif
  5233. %% emit_typedef("struct { SSTRING_HEADER chart data[unspecified]; }","snstring_");
  5234. %% emit_typedef("snstring_*","Snstring");
  5235. %% export_def(sstring_length(ptr));
  5236. %% export_def(Sstring_length(obj));
  5237. %% export_def(sstring_eltype(ptr));
  5238. /* simple vector */
  5239. typedef struct {
  5240. VRECORD_HEADER /* self-pointer for GC, length in objects */
  5241. gcv_object_t data[unspecified] _attribute_aligned_object_; /* elements */
  5242. } svector_;
  5243. typedef svector_ * Svector;
  5244. #define svector_length(ptr) sarray_length(ptr)
  5245. #define Svector_length(obj) svector_length(TheSvector(obj))
  5246. %% sprintf(buf,"struct { VRECORD_HEADER gcv_object_t data[unspecified]%s; }",attribute_aligned_object);
  5247. %% emit_typedef(buf,"svector_");
  5248. %% emit_typedef("svector_ *","Svector");
  5249. /* simple indirect string */
  5250. typedef struct {
  5251. SSTRING_HEADER /* self-pointer for GC, tfl */
  5252. gcv_object_t data _attribute_aligned_object_; /* data vector */
  5253. } sistring_;
  5254. typedef sistring_ * Sistring;
  5255. #define sistring_data_offset offsetof(sistring_,data)
  5256. /* non-simple indirect Array */
  5257. typedef struct {
  5258. VAROBJECT_HEADER /* self-pointer for GC */
  5259. #ifdef TYPECODES
  5260. uintB flags; /* flags */
  5261. uintC rank; /* rank n */
  5262. #endif
  5263. gcv_object_t data _attribute_aligned_object_; /* data vector */
  5264. uintL totalsize; /* totalsize = product of the n dimensions */
  5265. uintL dims[unspecified]; /* poss. displaced-offset, n dimensions, poss. fill-pointer */
  5266. } iarray_;
  5267. typedef iarray_ * Iarray;
  5268. #define iarray_data_offset offsetof(iarray_,data)
  5269. /* The rank is actually an uintWC.
  5270. access Rang, Flags: */
  5271. #ifdef TYPECODES
  5272. #define iarray_rank(ptr) ((ptr)->rank)
  5273. #else
  5274. #define iarray_rank(ptr) srecord_length(ptr)
  5275. #endif
  5276. #define Iarray_rank(obj) iarray_rank(TheIarray(obj))
  5277. #ifdef TYPECODES
  5278. #define iarray_flags(ptr) ((ptr)->flags)
  5279. #else
  5280. #define iarray_flags(ptr) record_flags(ptr)
  5281. #endif
  5282. #define Iarray_flags(obj) iarray_flags(TheIarray(obj))
  5283. #ifdef TYPECODES
  5284. #define iarray_flags_clr(ptr,bits) ((ptr)->flags &= ~(bits))
  5285. #define iarray_flags_set(ptr,bits) ((ptr)->flags |= (bits))
  5286. #define iarray_flags_replace(ptr,newflags) ((ptr)->flags = (newflags))
  5287. #else
  5288. #define iarray_flags_clr(ptr,bits) record_flags_clr(ptr,bits)
  5289. #define iarray_flags_set(ptr,bits) record_flags_set(ptr,bits)
  5290. #define iarray_flags_replace(ptr,newflags) record_flags_replace(ptr,newflags)
  5291. #endif
  5292. /* Bits in the Flags: */
  5293. #define arrayflags_adjustable_bit 7 /* set, if array is adjustable */
  5294. #define arrayflags_fillp_bit 6 /* set, if a fill-pointer exists (only possible for n=1) */
  5295. #define arrayflags_displaced_bit 5 /* set, if array is displaced */
  5296. #define arrayflags_dispoffset_bit 4 /* set, if there is space for the
  5297. displaced-offset
  5298. (<==> array adjustable or displaced) */
  5299. #define arrayflags_atype_mask 0x0F /* mask for the element-type */
  5300. /* Element-types of arrays in Bits 3..0 of its flags:
  5301. The first ones are chosen, so that 2^Atype_nBit = n. */
  5302. #define Atype_Bit 0 /* storage vector is of type sbvector_type */
  5303. #define Atype_2Bit 1 /* storage vector is of type sb2vector_type */
  5304. #define Atype_4Bit 2 /* storage vector is of type sb4vector_type */
  5305. #define Atype_8Bit 3 /* storage vector is of type sb8vector_type */
  5306. #define Atype_16Bit 4 /* storage vector is of type sb16vector_type */
  5307. #define Atype_32Bit 5 /* storage vector is of type sb32vector_type */
  5308. #define Atype_T 6 /* storage vector is of type svector_type */
  5309. #define Atype_Char 7 /* storage vector is of type sstring_type */
  5310. #define Atype_NIL 8 /* storage vector is NIL */
  5311. %% export_def(Atype_Bit);
  5312. %% export_def(Atype_8Bit);
  5313. %% export_def(Atype_32Bit);
  5314. %% export_def(Atype_T);
  5315. /* array-types */
  5316. #ifdef TYPECODES
  5317. #define Array_type(obj) typecode(obj)
  5318. #define Array_type_bvector bvector_type /* Iarray */
  5319. #define Array_type_b2vector b2vector_type /* Iarray */
  5320. #define Array_type_b4vector b4vector_type /* Iarray */
  5321. #define Array_type_b8vector b8vector_type /* Iarray */
  5322. #define Array_type_b16vector b16vector_type /* Iarray */
  5323. #define Array_type_b32vector b32vector_type /* Iarray */
  5324. #define Array_type_string string_type /* Iarray */
  5325. #define Array_type_vector vector_type /* Iarray */
  5326. #define Array_type_mdarray mdarray_type /* Iarray */
  5327. #define Array_type_sbvector sbvector_type /* Sbvector */
  5328. #define Array_type_sb2vector sb2vector_type /* Sbvector */
  5329. #define Array_type_sb4vector sb4vector_type /* Sbvector */
  5330. #define Array_type_sb8vector sb8vector_type /* Sbvector */
  5331. #define Array_type_sb16vector sb16vector_type /* Sbvector */
  5332. #define Array_type_sb32vector sb32vector_type /* Sbvector */
  5333. #define Array_type_sstring sstring_type /* Sstring */
  5334. #define Array_type_svector svector_type /* Svector */
  5335. #define Array_type_snilvector symbol_type /* Symbol NIL */
  5336. /* Array_type_simple_bit_vector(atype)
  5337. maps Atype_[n]Bit to Array_type_sb[n]vector. Depends on TB0, TB1, TB2.
  5338. The formula works because there are only 4 possible cases:
  5339. (TB0,TB1,TB2) formula
  5340. (0, 1, 2) atype
  5341. (0, 1, 3) atype + (atype & -4)
  5342. (0, 2, 3) atype + (atype & -2)
  5343. (1, 2, 3) atype + (atype & -1) = atype << 1 */
  5344. #define Array_type_simple_bit_vector(atype) \
  5345. (Array_type_sbvector + ((atype)<<TB0) + ((atype)&(bit(TB0+1)-bit(TB1))) + ((atype)&(bit(TB1+1)-bit(TB2))))
  5346. #else
  5347. #define Array_type(obj) Record_type(obj)
  5348. #define Array_type_bvector Rectype_bvector /* Iarray */
  5349. #define Array_type_b2vector Rectype_b2vector /* Iarray */
  5350. #define Array_type_b4vector Rectype_b4vector /* Iarray */
  5351. #define Array_type_b8vector Rectype_b8vector /* Iarray */
  5352. #define Array_type_b16vector Rectype_b16vector /* Iarray */
  5353. #define Array_type_b32vector Rectype_b32vector /* Iarray */
  5354. #define Array_type_string Rectype_string /* Iarray */
  5355. #define Array_type_vector Rectype_vector /* Iarray */
  5356. #define Array_type_mdarray Rectype_mdarray /* Iarray */
  5357. #define Array_type_sbvector Rectype_Sbvector /* Sbvector */
  5358. #define Array_type_sb2vector Rectype_Sb2vector /* Sbvector */
  5359. #define Array_type_sb4vector Rectype_Sb4vector /* Sbvector */
  5360. #define Array_type_sb8vector Rectype_Sb8vector /* Sbvector */
  5361. #define Array_type_sb16vector Rectype_Sb16vector /* Sbvector */
  5362. #define Array_type_sb32vector Rectype_Sb32vector /* Sbvector */
  5363. #define Array_type_sstring Rectype_S8string: case Rectype_Imm_S8string: case Rectype_S16string: case Rectype_Imm_S16string: case Rectype_S32string: case Rectype_Imm_S32string: case Rectype_reallocstring /* S[8|16|32]string, reallocated string */
  5364. #define Array_type_svector Rectype_Svector /* Svector */
  5365. #define Array_type_snilvector Rectype_Symbol /* Symbol NIL */
  5366. #endif
  5367. /* Determining the atype of a [simple-]bit-array: */
  5368. #define sbNvector_atype(obj) \
  5369. type_bits_to_atype(Array_type(obj) - Array_type_sbvector)
  5370. #define bNvector_atype(obj) \
  5371. type_bits_to_atype(Array_type(obj) - Array_type_bvector)
  5372. #ifdef TYPECODES
  5373. /* There are only 4 cases:
  5374. (TB0,TB1,TB2) formula
  5375. (0, 1, 2) type
  5376. (0, 1, 3) (type + (type & 3)) >> 1 = type - ((type & -8) >> 1)
  5377. (0, 2, 3) (type + (type & 1)) >> 1 = type - ((type & -4) >> 1)
  5378. (1, 2, 3) type >> 1 = type - ((type & -2) >> 1) */
  5379. #if TB2 > 2
  5380. #define type_bits_to_atype(type) \
  5381. (((type) + ((type)&(bit(6-TB0-TB1-TB2)-1))) >> 1)
  5382. #else
  5383. #define type_bits_to_atype(type) (type)
  5384. #endif
  5385. #else
  5386. #define type_bits_to_atype(type) (type)
  5387. #endif
  5388. %% #ifdef TYPECODES
  5389. %% export_def(Array_type_simple_bit_vector(atype));
  5390. %% #endif
  5391. /* Packages */
  5392. typedef struct {
  5393. XRECORD_HEADER
  5394. gcv_object_t pack_external_symbols _attribute_aligned_object_;
  5395. gcv_object_t pack_internal_symbols _attribute_aligned_object_;
  5396. gcv_object_t pack_shadowing_symbols _attribute_aligned_object_;
  5397. gcv_object_t pack_use_list _attribute_aligned_object_;
  5398. gcv_object_t pack_used_by_list _attribute_aligned_object_;
  5399. gcv_object_t pack_name _attribute_aligned_object_;
  5400. gcv_object_t pack_nicknames _attribute_aligned_object_;
  5401. gcv_object_t pack_docstring _attribute_aligned_object_;
  5402. gcv_object_t pack_shortest_name _attribute_aligned_object_;
  5403. } * Package;
  5404. #define package_length ((sizeof(*(Package)0)-offsetofa(record_,recdata))/sizeof(gcv_object_t))
  5405. /* Some packages are case-sensitive. */
  5406. #define mark_pack_casesensitive(obj) record_flags_set(ThePackage(obj),bit(0))
  5407. #define mark_pack_caseinsensitive(obj) record_flags_clr(ThePackage(obj),bit(0))
  5408. #define pack_casesensitivep(obj) (record_flags(ThePackage(obj)) & bit(0))
  5409. /* Some packages are case-inverted. */
  5410. #define mark_pack_caseinverted(obj) record_flags_set(ThePackage(obj),bit(1))
  5411. #define mark_pack_casepreserved(obj) record_flags_clr(ThePackage(obj),bit(1))
  5412. #define pack_caseinvertedp(obj) (record_flags(ThePackage(obj)) & bit(1))
  5413. /* Some packages, such as COMMON-LISP, are locked. */
  5414. #define mark_pack_locked(obj) record_flags_set(ThePackage(obj),bit(2))
  5415. #define mark_pack_unlocked(obj) record_flags_clr(ThePackage(obj),bit(2))
  5416. #define pack_locked_p(obj) (record_flags(ThePackage(obj)) & bit(2))
  5417. /* Do not do anything with deleted packages. */
  5418. #define mark_pack_deleted(obj) record_flags_set(ThePackage(obj),bit(7))
  5419. #define pack_deletedp(obj) (record_flags(ThePackage(obj)) & bit(7))
  5420. %% #if notused
  5421. %% sprintf(buf,"struct { XRECORD_HEADER gcv_object_t pack_external_symbols%s; gcv_object_t pack_internal_symbols%s; gcv_object_t pack_shadowing_symbols%s; gcv_object_t pack_use_list%s; gcv_object_t pack_used_by_list%s; gcv_object_t pack_name%s; gcv_object_t pack_nicknames%s; gcv_object_t pack_docstring%s; gcv_object_t pack_shortest_name%s; } *",attribute_aligned_object,attribute_aligned_object,attribute_aligned_object,attribute_aligned_object,attribute_aligned_object,attribute_aligned_object,attribute_aligned_object,attribute_aligned_object);
  5422. %% emit_typedef(buf,"Package");
  5423. %% #endif
  5424. /* Hash-Tables */
  5425. typedef struct {
  5426. XRECORD_HEADER
  5427. #ifdef GENERATIONAL_GC
  5428. gcv_object_t ht_lastrehash _attribute_aligned_object_;
  5429. #endif
  5430. gcv_object_t ht_maxcount _attribute_aligned_object_;
  5431. gcv_object_t ht_kvtable _attribute_aligned_object_;
  5432. gcv_object_t ht_lookupfn _attribute_aligned_object_;
  5433. gcv_object_t ht_hashcodefn _attribute_aligned_object_;
  5434. gcv_object_t ht_testfn _attribute_aligned_object_;
  5435. gcv_object_t ht_gcinvariantfn _attribute_aligned_object_;
  5436. gcv_object_t ht_rehash_size _attribute_aligned_object_;
  5437. gcv_object_t ht_mincount_threshold _attribute_aligned_object_;
  5438. gcv_object_t ht_mincount _attribute_aligned_object_;
  5439. gcv_object_t ht_test _attribute_aligned_object_; /* hash-table-test - for define-hash-table-test */
  5440. gcv_object_t ht_hash _attribute_aligned_object_; /* hash function */
  5441. uintL ht_size;
  5442. } * Hashtable;
  5443. #ifdef GENERATIONAL_GC
  5444. #define hashtable_length 12
  5445. #else
  5446. #define hashtable_length 11
  5447. #endif
  5448. #define hashtable_xlength (sizeof(*(Hashtable)0)-offsetofa(record_,recdata)-hashtable_length*sizeof(gcv_object_t))
  5449. /* Mark a Hash Table as now to reorganize
  5450. set_ht_invalid(TheHashtable(ht));
  5451. mark_ht_invalid(TheHashtable(ht));
  5452. A bit that is set when the list structure is invalid and a rehash is needed. */
  5453. #define htflags_invalid_B bit(7)
  5454. /* A bit that is set if the table has a key whose hash code is not GC-invariant. */
  5455. #define htflags_gc_rehash_B bit(6)
  5456. #ifdef GENERATIONAL_GC
  5457. #define mark_ht_invalid(ptr) \
  5458. (record_flags_set(ptr,htflags_invalid_B), \
  5459. (ptr)->ht_lastrehash = unbound)
  5460. #define mark_ht_valid(ptr) \
  5461. (record_flags_clr(ptr,htflags_invalid_B), \
  5462. (ptr)->ht_lastrehash = O(gc_count))
  5463. #define ht_validp(ptr) \
  5464. ((record_flags(ptr) & htflags_invalid_B) == 0 \
  5465. && ((record_flags(ptr) & htflags_gc_rehash_B) == 0 \
  5466. || eq((ptr)->ht_lastrehash,O(gc_count))))
  5467. #else
  5468. #define mark_ht_invalid(ptr) record_flags_set(ptr,htflags_invalid_B)
  5469. #define mark_ht_valid(ptr) record_flags_clr(ptr,htflags_invalid_B)
  5470. #define ht_validp(ptr) ((record_flags(ptr) & htflags_invalid_B) == 0)
  5471. #endif
  5472. #ifdef GENERATIONAL_GC
  5473. #define set_ht_invalid(ptr) mark_ht_invalid(ptr)
  5474. #define set_ht_valid(ptr) mark_ht_valid(ptr)
  5475. #else
  5476. extern bool hash_lookup_builtin (object ht, object obj, bool allowgc, gcv_object_t** KVptr_, gcv_object_t** Iptr_);
  5477. extern bool hash_lookup_builtin_with_rehash (object ht, object obj, bool allowgc, gcv_object_t** KVptr_, gcv_object_t** Iptr_);
  5478. #define set_ht_invalid(ptr) \
  5479. (mark_ht_invalid(ptr), \
  5480. eq((ptr)->ht_lookupfn,P(hash_lookup_builtin)) \
  5481. ? ((ptr)->ht_lookupfn = P(hash_lookup_builtin_with_rehash), 0) : 0)
  5482. #define set_ht_valid(ptr) \
  5483. (mark_ht_valid(ptr), \
  5484. eq((ptr)->ht_lookupfn,P(hash_lookup_builtin_with_rehash)) \
  5485. ? ((ptr)->ht_lookupfn = P(hash_lookup_builtin), 0) : 0)
  5486. #endif
  5487. #define set_ht_invalid_if_needed(ptr) \
  5488. if (record_flags(ptr) & htflags_gc_rehash_B) \
  5489. set_ht_invalid(ptr)/*;*/
  5490. /* A bit that indicates whether to warn about this situation. */
  5491. #define htflags_warn_gc_rehash_B bit(5)
  5492. /* Extract the part of the flags that encodes the test. */
  5493. #define ht_test_code(flags) \
  5494. (flags & (bit(0) | bit(1) | bit(2) | bit(3)))
  5495. /* Tests whether a test code indicates a user-defined test function. */
  5496. #define ht_test_code_user_p(test_code) \
  5497. (((test_code) & bit(2)) != 0)
  5498. /* Test whether a hash table is weak. */
  5499. #define ht_weak_p(ht) \
  5500. !simple_vector_p(TheHashtable(ht)->ht_kvtable)
  5501. /* The kvtable array is either a HashedAlist or a WeakHashedAlist.
  5502. Both share the same layout, i.e.
  5503. &((HashedAlist)0)->hal_data == &((WeakHashedAlist)0)->whal_data. */
  5504. typedef struct {
  5505. VRECORD_HEADER /* self-pointer for GC, length in objects */
  5506. gcv_object_t hal_filler _attribute_aligned_object_; /* for consistency with WeakHashedAlist */
  5507. gcv_object_t hal_itable _attribute_aligned_object_; /* index-vector */
  5508. gcv_object_t hal_count _attribute_aligned_object_; /* remaining pairs */
  5509. gcv_object_t hal_freelist _attribute_aligned_object_; /* start index of freelist */
  5510. gcv_object_t hal_data[unspecified] _attribute_aligned_object_; /* (key, value, next) triples */
  5511. } * HashedAlist;
  5512. /* TheHashedAlist is used to access both HashedAlist and WeakHashedAlist. */
  5513. #define TheHashedAlist(obj) ((HashedAlist)TheVarobject(obj))
  5514. /* Readtables */
  5515. typedef struct {
  5516. XRECORD_HEADER
  5517. gcv_object_t readtable_syntax_table _attribute_aligned_object_;
  5518. gcv_object_t readtable_macro_table _attribute_aligned_object_;
  5519. gcv_object_t readtable_case _attribute_aligned_object_;
  5520. } * Readtable;
  5521. #define readtable_length ((sizeof(*(Readtable)0)-offsetofa(record_,recdata))/sizeof(gcv_object_t))
  5522. /* Pathnames */
  5523. typedef struct {
  5524. XRECORD_HEADER
  5525. #if HAS_HOST
  5526. gcv_object_t pathname_host _attribute_aligned_object_;
  5527. #endif
  5528. #if HAS_DEVICE
  5529. gcv_object_t pathname_device _attribute_aligned_object_;
  5530. #endif
  5531. #if 1
  5532. gcv_object_t pathname_directory _attribute_aligned_object_;
  5533. gcv_object_t pathname_name _attribute_aligned_object_;
  5534. gcv_object_t pathname_type _attribute_aligned_object_;
  5535. gcv_object_t pathname_version _attribute_aligned_object_;
  5536. #endif
  5537. } * Pathname;
  5538. #define pathname_length ((sizeof(*(Pathname)0)-offsetofa(record_,recdata))/sizeof(gcv_object_t))
  5539. #ifdef LOGICAL_PATHNAMES
  5540. /* Logical Pathnames */
  5541. typedef struct {
  5542. XRECORD_HEADER
  5543. gcv_object_t pathname_host _attribute_aligned_object_;
  5544. gcv_object_t pathname_directory _attribute_aligned_object_;
  5545. gcv_object_t pathname_name _attribute_aligned_object_;
  5546. gcv_object_t pathname_type _attribute_aligned_object_;
  5547. gcv_object_t pathname_version _attribute_aligned_object_;
  5548. } * Logpathname;
  5549. #define logpathname_length ((sizeof(*(Logpathname)0)-offsetofa(record_,recdata))/sizeof(gcv_object_t))
  5550. #endif
  5551. /* Random-States */
  5552. typedef struct {
  5553. XRECORD_HEADER
  5554. gcv_object_t random_state_seed _attribute_aligned_object_;
  5555. } * Random_state;
  5556. #define random_state_length ((sizeof(*(Random_state)0)-offsetofa(record_,recdata))/sizeof(gcv_object_t))
  5557. /* Bytes */
  5558. typedef struct {
  5559. XRECORD_HEADER
  5560. gcv_object_t byte_size _attribute_aligned_object_;
  5561. gcv_object_t byte_position _attribute_aligned_object_;
  5562. } * Byte;
  5563. #define byte_length ((sizeof(*(Byte)0)-offsetofa(record_,recdata))/sizeof(gcv_object_t))
  5564. /* Fsubrs */
  5565. typedef struct {
  5566. XRECORD_HEADER
  5567. gcv_object_t name _attribute_aligned_object_;
  5568. gcv_object_t argtype _attribute_aligned_object_;
  5569. void* function; /* actually a fsubr_function_t* */
  5570. } * Fsubr;
  5571. #define fsubr_length 2
  5572. #define fsubr_xlength (sizeof(*(Fsubr)0)-offsetofa(record_,recdata)-fsubr_length*sizeof(gcv_object_t))
  5573. /* Load-time-evals */
  5574. typedef struct {
  5575. XRECORD_HEADER
  5576. gcv_object_t loadtimeeval_form _attribute_aligned_object_;
  5577. } * Loadtimeeval;
  5578. #define loadtimeeval_length ((sizeof(*(Loadtimeeval)0)-offsetofa(record_,recdata))/sizeof(gcv_object_t))
  5579. /* Symbol-macros */
  5580. typedef struct {
  5581. XRECORD_HEADER
  5582. gcv_object_t symbolmacro_expansion _attribute_aligned_object_;
  5583. } * Symbolmacro;
  5584. #define symbolmacro_length ((sizeof(*(Symbolmacro)0)-offsetofa(record_,recdata))/sizeof(gcv_object_t))
  5585. /* Global-Symbol-macros */
  5586. typedef struct {
  5587. XRECORD_HEADER
  5588. gcv_object_t globalsymbolmacro_definition _attribute_aligned_object_;
  5589. } * GlobalSymbolmacro;
  5590. #define globalsymbolmacro_length ((sizeof(*(GlobalSymbolmacro)0)-offsetofa(record_,recdata))/sizeof(gcv_object_t))
  5591. /* Macros */
  5592. typedef struct {
  5593. XRECORD_HEADER
  5594. gcv_object_t macro_expander _attribute_aligned_object_;
  5595. gcv_object_t macro_lambda_list _attribute_aligned_object_;
  5596. } * Macro;
  5597. #define macro_length ((sizeof(*(Macro)0)-offsetofa(record_,recdata))/sizeof(gcv_object_t))
  5598. /* FunctionMacros */
  5599. typedef struct {
  5600. XRECORD_HEADER
  5601. gcv_object_t functionmacro_macro_expander _attribute_aligned_object_;
  5602. gcv_object_t functionmacro_function _attribute_aligned_object_;
  5603. } * FunctionMacro;
  5604. #define functionmacro_length ((sizeof(*(FunctionMacro)0)-offsetofa(record_,recdata))/sizeof(gcv_object_t))
  5605. /* BigReadLabel */
  5606. typedef struct {
  5607. XRECORD_HEADER
  5608. gcv_object_t brl_value _attribute_aligned_object_;
  5609. } * BigReadLabel;
  5610. #define bigreadlabel_length ((sizeof(*(BigReadLabel)0)-offsetofa(record_,recdata))/sizeof(gcv_object_t))
  5611. /* Encoding */
  5612. typedef struct {
  5613. XRECORD_HEADER
  5614. gcv_object_t enc_eol _attribute_aligned_object_; /* line termination, a keyword (:UNIX, :MAC, :DOS) */
  5615. gcv_object_t enc_towcs_error _attribute_aligned_object_; /* input error action, :ERROR or :IGNORE or a character */
  5616. gcv_object_t enc_tombs_error _attribute_aligned_object_; /* output error action, :ERROR or :IGNORE or a character or an uint8 */
  5617. #ifdef UNICODE
  5618. gcv_object_t enc_charset _attribute_aligned_object_; /* character set, a symbol in the CHARSET package or a simple-string */
  5619. /* Functions to convert bytes to characters. */
  5620. gcv_object_t enc_mblen _attribute_aligned_object_; /* uintL (*) (object encoding, const uintB* src, const uintB* srcend); */
  5621. gcv_object_t enc_mbstowcs _attribute_aligned_object_; /* void (*) (object encoding, object stream, const uintB* *srcp, const uintB* srcend, chart* *destp, chart* destend); */
  5622. /* Functions to convert characters to bytes. */
  5623. gcv_object_t enc_wcslen _attribute_aligned_object_; /* uintL (*) (object encoding, const chart* src, const chart* srcend); */
  5624. gcv_object_t enc_wcstombs _attribute_aligned_object_; /* void (*) (object encoding, object stream, const chart* *srcp, const chart* srcend, uintB* *destp, uintB* destend); */
  5625. /* Function to return the set of defined characters in the range [start,end],
  5626. as a simple-string of intervals #(start1 end1 ... startm endm). */
  5627. gcv_object_t enc_range _attribute_aligned_object_; /* object (*) (object encoding, uintL start, uintL end, uintL maxintervals); */
  5628. /* An auxiliary pointer. */
  5629. gcv_object_t enc_table _attribute_aligned_object_;
  5630. /* Minimum number of bytes needed to represent a character
  5631. caveat: correct only for some encodings, defaults to 1 */
  5632. uintL min_bytes_per_char;
  5633. /* Maximum number of bytes needed to represent a character
  5634. caveat: correct only for some encodings, defaults to 8 */
  5635. uintL max_bytes_per_char;
  5636. #endif
  5637. } * Encoding;
  5638. #ifdef UNICODE
  5639. #define encoding_length 10
  5640. #else
  5641. #define encoding_length 3
  5642. #endif
  5643. #define encoding_xlength (sizeof(*(Encoding)0)-offsetofa(record_,recdata)-encoding_length*sizeof(gcv_object_t))
  5644. #ifdef UNICODE
  5645. #define Encoding_mblen(encoding) ((uintL (*) (object, const uintB*, const uintB*)) ThePseudofun(TheEncoding(encoding)->enc_mblen))
  5646. #define Encoding_mbstowcs(encoding) ((void (*) (object, object, const uintB**, const uintB*, chart**, chart*)) ThePseudofun(TheEncoding(encoding)->enc_mbstowcs))
  5647. #define Encoding_wcslen(encoding) ((uintL (*) (object, const chart*, const chart*)) ThePseudofun(TheEncoding(encoding)->enc_wcslen))
  5648. #define Encoding_wcstombs(encoding) ((void (*) (object, object, const chart**, const chart*, uintB**, uintB*)) ThePseudofun(TheEncoding(encoding)->enc_wcstombs))
  5649. #define Encoding_range(encoding) ((object (*) (object, uintL, uintL, uintL)) ThePseudofun(TheEncoding(encoding)->enc_range))
  5650. #endif
  5651. #ifdef UNICODE
  5652. #define cslen(encoding,src,srclen) \
  5653. Encoding_wcslen(encoding)(encoding,src,(src)+(srclen))
  5654. #define cstombs_help_(encoding,src,srclen,dest,destlen,A) \
  5655. do { var const chart* _srcptr = (src); \
  5656. var const chart* _srcendptr = _srcptr+(srclen); \
  5657. var uintB* _destptr = (dest); \
  5658. var uintB* _destendptr = _destptr+(destlen); \
  5659. Encoding_wcstombs(encoding)(encoding,nullobj,&_srcptr,_srcendptr,&_destptr,_destendptr); \
  5660. A((_srcptr == _srcendptr) && (_destptr == _destendptr)); \
  5661. } while(0)
  5662. #else
  5663. #define cslen(encoding,src,srclen) (srclen)
  5664. #define cstombs_help_(encoding,src,srclen,dest,destlen,A) \
  5665. do { A((srclen) == (destlen)); \
  5666. begin_system_call(); memcpy(dest,src,srclen); end_system_call(); \
  5667. } while(0)
  5668. #endif
  5669. #define cstombs(encoding,src,srclen,dest,destlen) cstombs_help_(encoding,src,srclen,dest,destlen,ASSERT)
  5670. %% sprintf(buf,"struct { XRECORD_HEADER gcv_object_t enc_eol%s; gcv_object_t enc_towcs_error%s; gcv_object_t enc_tombs_error%s;",attribute_aligned_object,attribute_aligned_object,attribute_aligned_object);
  5671. %% #ifdef UNICODE
  5672. %% sprintf(buf+strlen(buf)," gcv_object_t enc_charset%s; gcv_object_t enc_mblen%s; gcv_object_t enc_mbstowcs%s; gcv_object_t enc_wcslen%s; gcv_object_t enc_wcstombs%s; gcv_object_t enc_range%s; gcv_object_t enc_table%s; uintL min_bytes_per_char; uintL max_bytes_per_char;",attribute_aligned_object,attribute_aligned_object,attribute_aligned_object,attribute_aligned_object,attribute_aligned_object,attribute_aligned_object,attribute_aligned_object);
  5673. %% #endif
  5674. %% strcat(buf," } *");
  5675. %% emit_typedef(buf,"Encoding");
  5676. %% #ifdef UNICODE
  5677. %% export_def(Encoding_wcslen(encoding));
  5678. %% export_def(Encoding_wcstombs(encoding));
  5679. %% #endif
  5680. %% export_def(cslen(encoding,src,srclen));
  5681. %% export_def(cstombs_help_(encoding,src,srclen,dest,destlen,A));
  5682. %% puts("#define cstombs(encoding,src,srclen,dest,destlen) cstombs_help_(encoding,src,srclen,dest,destlen,ASSERT)");
  5683. #ifdef FOREIGN
  5684. /* foreign pointer wrap */
  5685. typedef struct {
  5686. XRECORD_HEADER
  5687. void* fp_pointer;
  5688. } * Fpointer;
  5689. #define fpointer_length 0
  5690. #define fpointer_xlength (sizeof(*(Fpointer)0)-offsetofa(record_,recdata)-fpointer_length*sizeof(gcv_object_t))
  5691. #define mark_fp_invalid(ptr) record_flags_set(ptr,bit(7))
  5692. #define mark_fp_valid(ptr) record_flags_clr(ptr,bit(7))
  5693. #define fp_validp(ptr) ((record_flags(ptr) & bit(7)) == 0)
  5694. #else
  5695. #define mark_fp_invalid(ptr)
  5696. #endif
  5697. %% #ifdef FOREIGN
  5698. %% emit_typedef("struct { XRECORD_HEADER void* fp_pointer;} *","Fpointer");
  5699. %% export_def(fp_validp(ptr));
  5700. %% export_def(mark_fp_invalid(ptr));
  5701. %% #endif
  5702. #ifdef DYNAMIC_FFI
  5703. /* foreign adresses */
  5704. typedef struct {
  5705. XRECORD_HEADER
  5706. gcv_object_t fa_base _attribute_aligned_object_;
  5707. sintP fa_offset;
  5708. } * Faddress;
  5709. #define faddress_length 1
  5710. #define faddress_xlength (sizeof(*(Faddress)0)-offsetofa(record_,recdata)-faddress_length*sizeof(gcv_object_t))
  5711. /* foreign variables */
  5712. typedef struct {
  5713. XRECORD_HEADER
  5714. gcv_object_t fv_name _attribute_aligned_object_;
  5715. gcv_object_t fv_version _attribute_aligned_object_;
  5716. gcv_object_t fv_address _attribute_aligned_object_;
  5717. gcv_object_t fv_size _attribute_aligned_object_;
  5718. gcv_object_t fv_type _attribute_aligned_object_;
  5719. } * Fvariable;
  5720. #define fvariable_length ((sizeof(*(Fvariable)0)-offsetofa(record_,recdata))/sizeof(gcv_object_t))
  5721. /* foreign functions */
  5722. typedef struct {
  5723. XRECORD_HEADER
  5724. gcv_object_t ff_name _attribute_aligned_object_;
  5725. gcv_object_t ff_version _attribute_aligned_object_;
  5726. gcv_object_t ff_address _attribute_aligned_object_;
  5727. gcv_object_t ff_resulttype _attribute_aligned_object_;
  5728. gcv_object_t ff_argtypes _attribute_aligned_object_;
  5729. gcv_object_t ff_flags _attribute_aligned_object_;
  5730. gcv_object_t ff_properties _attribute_aligned_object_;
  5731. } * Ffunction;
  5732. #define ffunction_length ((sizeof(*(Ffunction)0)-offsetofa(record_,recdata))/sizeof(gcv_object_t))
  5733. #endif
  5734. /* weak pointer */
  5735. typedef struct {
  5736. XRECORD_HEADER
  5737. gcv_object_t wp_cdr _attribute_aligned_object_; /* active weak-pointers form a chained list */
  5738. gcv_object_t wp_value _attribute_aligned_object_; /* the referenced object */
  5739. } * Weakpointer;
  5740. /* Both wp_cdr and wp_value are invisible to gc_mark routines.
  5741. When the weak-pointer becomes inactive, both fields are turned to unbound.
  5742. When wp_value is GC-invariant, WP does not have to be on the
  5743. O(all_weakpointers) list! WP is on the list <==> ( wp_cdr != unbound ) */
  5744. #define weakpointer_length ((sizeof(*(Weakpointer)0)-offsetofa(record_,recdata))/sizeof(gcv_object_t))
  5745. #define weakpointer_broken_p(wp) (!boundp(TheWeakpointer(wp)->wp_value))
  5746. /* weak list */
  5747. typedef struct {
  5748. LRECORD_HEADER
  5749. gcv_object_t wp_cdr _attribute_aligned_object_; /* active weak-pointers form a chained list */
  5750. gcv_object_t wl_count _attribute_aligned_object_; /* remaining objects */
  5751. gcv_object_t wl_elements[unspecified] _attribute_aligned_object_; /* the referenced objects */
  5752. } * WeakList;
  5753. /* mutable weak list */
  5754. typedef struct {
  5755. XRECORD_HEADER
  5756. gcv_object_t mwl_list _attribute_aligned_object_;
  5757. } * MutableWeakList;
  5758. #define mutableweaklist_length ((sizeof(*(MutableWeakList)0)-offsetofa(record_,recdata))/sizeof(gcv_object_t))
  5759. /* weak "and" relation */
  5760. typedef struct {
  5761. LRECORD_HEADER
  5762. gcv_object_t wp_cdr _attribute_aligned_object_; /* active weak-pointers form a chained list */
  5763. gcv_object_t war_keys_list _attribute_aligned_object_; /* list to copy the keys into */
  5764. gcv_object_t war_keys[unspecified] _attribute_aligned_object_; /* the referenced objects */
  5765. } * WeakAnd;
  5766. /* weak "or" relation */
  5767. typedef struct {
  5768. LRECORD_HEADER
  5769. gcv_object_t wp_cdr _attribute_aligned_object_; /* active weak-pointers form a chained list */
  5770. gcv_object_t wor_keys_list _attribute_aligned_object_; /* list to copy the keys into */
  5771. gcv_object_t wor_keys[unspecified] _attribute_aligned_object_; /* the referenced objects */
  5772. } * WeakOr;
  5773. /* weak mapping */
  5774. typedef struct {
  5775. XRECORD_HEADER
  5776. gcv_object_t wp_cdr _attribute_aligned_object_; /* active weak-pointers form a chained list */
  5777. gcv_object_t wm_value _attribute_aligned_object_; /* the dependent referenced object */
  5778. gcv_object_t wm_key _attribute_aligned_object_; /* the weak referenced object */
  5779. } * Weakmapping;
  5780. #define weakmapping_length ((sizeof(*(Weakmapping)0)-offsetofa(record_,recdata))/sizeof(gcv_object_t))
  5781. /* weak "and" mapping */
  5782. typedef struct {
  5783. LRECORD_HEADER
  5784. gcv_object_t wp_cdr _attribute_aligned_object_; /* active weak-pointers form a chained list */
  5785. gcv_object_t wam_value _attribute_aligned_object_; /* the dependent referenced object */
  5786. gcv_object_t wam_keys_list _attribute_aligned_object_; /* list to copy the keys into */
  5787. gcv_object_t wam_keys[unspecified] _attribute_aligned_object_; /* the referenced objects */
  5788. } * WeakAndMapping;
  5789. /* weak "or" mapping */
  5790. typedef struct {
  5791. LRECORD_HEADER
  5792. gcv_object_t wp_cdr _attribute_aligned_object_; /* active weak-pointers form a chained list */
  5793. gcv_object_t wom_value _attribute_aligned_object_; /* the dependent referenced object */
  5794. gcv_object_t wom_keys_list _attribute_aligned_object_; /* list to copy the keys into */
  5795. gcv_object_t wom_keys[unspecified] _attribute_aligned_object_; /* the referenced objects */
  5796. } * WeakOrMapping;
  5797. /* weak alist (rectype = Rectype_WeakAlist_{Key,Value,Either,Both}) */
  5798. typedef struct {
  5799. LRECORD_HEADER
  5800. gcv_object_t wp_cdr _attribute_aligned_object_; /* active weak-pointers form a chained list */
  5801. gcv_object_t wal_count _attribute_aligned_object_; /* remaining pairs */
  5802. gcv_object_t wal_data[unspecified] _attribute_aligned_object_; /* key, value alternating */
  5803. } * WeakAlist;
  5804. /* mutable weak alist */
  5805. typedef struct {
  5806. XRECORD_HEADER
  5807. gcv_object_t mwal_list _attribute_aligned_object_;
  5808. } * MutableWeakAlist;
  5809. #define mutableweakalist_length ((sizeof(*(MutableWeakAlist)0)-offsetofa(record_,recdata))/sizeof(gcv_object_t))
  5810. /* weak hashed alist (rectype = Rectype_WeakHashedAlist_{Key,Value,Either,Both}) */
  5811. typedef struct {
  5812. LRECORD_HEADER
  5813. gcv_object_t wp_cdr _attribute_aligned_object_; /* active weak-pointers form a chained list */
  5814. gcv_object_t whal_itable _attribute_aligned_object_; /* index-vector */
  5815. gcv_object_t whal_count _attribute_aligned_object_; /* remaining pairs */
  5816. gcv_object_t whal_freelist _attribute_aligned_object_; /* start index of freelist */
  5817. gcv_object_t whal_data[unspecified] _attribute_aligned_object_; /* (key, value, next) triples */
  5818. } * WeakHashedAlist;
  5819. /* Finalizer */
  5820. typedef struct {
  5821. XRECORD_HEADER
  5822. gcv_object_t fin_alive _attribute_aligned_object_; /* only if this object is alive */
  5823. gcv_object_t fin_trigger _attribute_aligned_object_; /* wait for the death of this object */
  5824. gcv_object_t fin_function _attribute_aligned_object_; /* then this function is called */
  5825. gcv_object_t fin_cdr _attribute_aligned_object_;
  5826. } * Finalizer;
  5827. #define finalizer_length ((sizeof(*(Finalizer)0)-offsetofa(record_,recdata))/sizeof(gcv_object_t))
  5828. #ifdef SOCKET_STREAMS
  5829. /* Socket-Server */
  5830. typedef struct {
  5831. XRECORD_HEADER
  5832. gcv_object_t socket_handle _attribute_aligned_object_; /* socket handle */
  5833. gcv_object_t host _attribute_aligned_object_; /* host string */
  5834. gcv_object_t port _attribute_aligned_object_; /* port number */
  5835. } * Socket_server;
  5836. #define socket_server_length ((sizeof(*(Socket_server)0)-offsetofa(record_,recdata))/sizeof(gcv_object_t))
  5837. /* Information about any of the two ends of a socket connection. */
  5838. #ifndef MAXHOSTNAMELEN
  5839. #define MAXHOSTNAMELEN 64
  5840. #endif
  5841. typedef struct host_data_t {
  5842. char hostname[45+1]; /* IP address in presentable, printable format
  5843. (IPv4 max. 15 characters, IPv6 max. 45 characters) */
  5844. char truename[MAXHOSTNAMELEN+1]; /* hostname, with or without domain name */
  5845. unsigned int port;
  5846. } host_data_t;
  5847. #endif
  5848. #ifdef YET_ANOTHER_RECORD
  5849. /* Yet another record */
  5850. typedef struct {
  5851. XRECORD_HEADER
  5852. gcv_object_t yetanother_x _attribute_aligned_object_;
  5853. gcv_object_t yetanother_y _attribute_aligned_object_;
  5854. gcv_object_t yetanother_z _attribute_aligned_object_;
  5855. } * Yetanother;
  5856. #define yetanother_length ((sizeof(*(Yetanother)0)-offsetofa(record_,recdata))/sizeof(gcv_object_t))
  5857. #endif
  5858. /* Streams with metaclass BUILT-IN-CLASS */
  5859. typedef struct {
  5860. #ifdef case_stream
  5861. VAROBJECT_HEADER /* self-pointer for GC */
  5862. uintB strmtype; /* subtype (as sintB >=0 !) */
  5863. uintB strmflags; /* flags */
  5864. uintB reclength; /* length in object */
  5865. uintB recxlength; /* lengths of the extra-elements */
  5866. #else
  5867. /* Because of space requirements, I have to put strmflags and strmtype
  5868. into a fixnum in recdata[0]. */
  5869. #if !((oint_addr_len+oint_addr_shift>=24) && (8>=oint_addr_shift))
  5870. #error "No room for stream flags -- re-accommodate Stream-Flags!!"
  5871. #endif
  5872. XRECORD_HEADER
  5873. #if defined(WIDE) && BIG_ENDIAN_P
  5874. uintL strmfiller0;
  5875. #endif
  5876. uintB strmfiller1;
  5877. uintB strmflags; /* Flags */
  5878. uintB strmtype; /* Subtype */
  5879. uintB strmfiller2;
  5880. #if defined(WIDE) && !BIG_ENDIAN_P
  5881. uintL strmfiller0;
  5882. #endif
  5883. #endif
  5884. gcv_object_t strm_rd_by _attribute_aligned_object_;
  5885. gcv_object_t strm_rd_by_array _attribute_aligned_object_;
  5886. gcv_object_t strm_wr_by _attribute_aligned_object_;
  5887. gcv_object_t strm_wr_by_array _attribute_aligned_object_;
  5888. gcv_object_t strm_rd_ch _attribute_aligned_object_;
  5889. gcv_object_t strm_pk_ch _attribute_aligned_object_;
  5890. gcv_object_t strm_rd_ch_array _attribute_aligned_object_;
  5891. gcv_object_t strm_rd_ch_last _attribute_aligned_object_;
  5892. gcv_object_t strm_wr_ch _attribute_aligned_object_;
  5893. gcv_object_t strm_wr_ch_array _attribute_aligned_object_;
  5894. gcv_object_t strm_wr_ch_npnl _attribute_aligned_object_;
  5895. gcv_object_t strm_wr_ch_array_npnl _attribute_aligned_object_;
  5896. gcv_object_t strm_wr_ch_lpos _attribute_aligned_object_;
  5897. gcv_object_t strm_other[unspecified] _attribute_aligned_object_; /* type-specific components */
  5898. } * Stream;
  5899. /* The macro TheStream actually means TheBuiltinStream. */
  5900. #define strm_len ((sizeof(*(Stream)0)-offsetofa(record_,recdata))/sizeof(gcv_object_t)-unspecified)
  5901. #define stream_length(ptr) xrecord_length(ptr)
  5902. #define stream_xlength(ptr) xrecord_xlength(ptr)
  5903. #define Stream_length(obj) stream_length(TheStream(obj))
  5904. #define Stream_xlength(obj) stream_xlength(TheStream(obj))
  5905. /* Bit-masks in the Flags: */
  5906. #define strmflags_open_bit_B 0 /* set, if the Stream is open */
  5907. #define strmflags_immut_bit_B 1 /* set if read literals are immutable */
  5908. #define strmflags_fasl_bit_B 2 /* Read-Eval is permitted; \r=#\Return */
  5909. #define strmflags_rd_by_bit_B 4 /* set, if READ-BYTE is possible */
  5910. #define strmflags_wr_by_bit_B 5 /* set, if WRITE-BYTE is possible */
  5911. #define strmflags_rd_ch_bit_B 6 /* set, if READ-CHAR is possible */
  5912. #define strmflags_wr_ch_bit_B 7 /* set, if WRITE-CHAR is possible */
  5913. #define strmflags_open_B bit(strmflags_open_bit_B)
  5914. #define strmflags_rd_by_B bit(strmflags_rd_by_bit_B)
  5915. #define strmflags_wr_by_B bit(strmflags_wr_by_bit_B)
  5916. #define strmflags_rd_ch_B bit(strmflags_rd_ch_bit_B)
  5917. #define strmflags_wr_ch_B bit(strmflags_wr_ch_bit_B)
  5918. #define strmflags_rd_B (strmflags_rd_by_B | strmflags_rd_ch_B)
  5919. #define strmflags_wr_B (strmflags_wr_by_B | strmflags_wr_ch_B)
  5920. /* approach Typinfo: */
  5921. enum { /* The ordered values of this enumeration are 0,1,2,... */
  5922. /* First the OS independent streams. */
  5923. enum_strmtype_synonym,
  5924. #define strmtype_synonym (uintB)enum_strmtype_synonym
  5925. enum_strmtype_broad,
  5926. #define strmtype_broad (uintB)enum_strmtype_broad
  5927. enum_strmtype_concat,
  5928. #define strmtype_concat (uintB)enum_strmtype_concat
  5929. enum_strmtype_twoway,
  5930. #define strmtype_twoway (uintB)enum_strmtype_twoway
  5931. enum_strmtype_echo,
  5932. #define strmtype_echo (uintB)enum_strmtype_echo
  5933. enum_strmtype_str_in,
  5934. #define strmtype_str_in (uintB)enum_strmtype_str_in
  5935. enum_strmtype_str_out,
  5936. #define strmtype_str_out (uintB)enum_strmtype_str_out
  5937. enum_strmtype_str_push,
  5938. #define strmtype_str_push (uintB)enum_strmtype_str_push
  5939. enum_strmtype_pphelp,
  5940. #define strmtype_pphelp (uintB)enum_strmtype_pphelp
  5941. enum_strmtype_buff_in,
  5942. #define strmtype_buff_in (uintB)enum_strmtype_buff_in
  5943. enum_strmtype_buff_out,
  5944. #define strmtype_buff_out (uintB)enum_strmtype_buff_out
  5945. #ifdef GENERIC_STREAMS
  5946. enum_strmtype_generic,
  5947. #define strmtype_generic (uintB)enum_strmtype_generic
  5948. #endif
  5949. /* Then the OS dependent streams. */
  5950. enum_strmtype_file,
  5951. #define strmtype_file (uintB)enum_strmtype_file
  5952. #ifdef KEYBOARD
  5953. enum_strmtype_keyboard,
  5954. #define strmtype_keyboard (uintB)enum_strmtype_keyboard
  5955. #endif
  5956. enum_strmtype_terminal,
  5957. #define strmtype_terminal (uintB)enum_strmtype_terminal
  5958. #ifdef SCREEN
  5959. enum_strmtype_window,
  5960. #define strmtype_window (uintB)enum_strmtype_window
  5961. #endif
  5962. #ifdef PRINTER
  5963. enum_strmtype_printer,
  5964. #define strmtype_printer (uintB)enum_strmtype_printer
  5965. #endif
  5966. #ifdef PIPES
  5967. enum_strmtype_pipe_in,
  5968. #define strmtype_pipe_in (uintB)enum_strmtype_pipe_in
  5969. enum_strmtype_pipe_out,
  5970. #define strmtype_pipe_out (uintB)enum_strmtype_pipe_out
  5971. #endif
  5972. #ifdef X11SOCKETS
  5973. enum_strmtype_x11socket,
  5974. #define strmtype_x11socket (uintB)enum_strmtype_x11socket
  5975. #endif
  5976. #ifdef SOCKET_STREAMS
  5977. enum_strmtype_socket,
  5978. #define strmtype_socket (uintB)enum_strmtype_socket
  5979. enum_strmtype_twoway_socket,
  5980. #define strmtype_twoway_socket (uintB)enum_strmtype_twoway_socket
  5981. #endif
  5982. enum_strmtype_dummy
  5983. };
  5984. /* When this table is changed, also adapt
  5985. - the 12 jumptables for STREAM-ELEMENT-TYPE, SET-STREAM-ELEMENT-TYPE,
  5986. STREAM-EXTERNAL-FORMAT, SET-STREAM-EXTERNAL-FORMAT, INTERACTIVE-STREAM-P,
  5987. CLOSE, LISTEN-CHAR, CLEAR_INPUT, LISTEN-BYTE, FINISH_OUTPUT,
  5988. FORCE_OUTPUT, CLEAR_OUTPUT in STREAM.D and
  5989. - the name-table in CONSTOBJ.D and
  5990. - the jumptable for PR_STREAM in IO.D and
  5991. - the pseudo-function-table in PSEUDOFUN.D */
  5992. #
  5993. /* more type-specific components: */
  5994. #define strm_eltype strm_other[0] /* CHARACTER or ([UN]SIGNED-BYTE n) */
  5995. #define strm_encoding strm_other[1] /* an encoding */
  5996. #define strm_file_name strm_other[6] /* filename, a pathname or NIL */
  5997. #define strm_file_truename strm_other[7] /* truename, a non-logical pathname or NIL */
  5998. #define strm_buffered_channel strm_other[5] /* packed Handle */
  5999. #define strm_synonym_symbol strm_other[0]
  6000. #define strm_broad_list strm_other[0] /* list of Streams */
  6001. #define strm_concat_list strm_other[0] /* list of Streams */
  6002. #define strm_pphelp_lpos strm_wr_ch_lpos /* Line Position (Fixnum>=0) */
  6003. #define strm_pphelp_strings strm_other[0] /* Semi-Simple-Strings for Output */
  6004. #define strm_pphelp_modus strm_other[1] /* Mode (NIL=Single line, T=multiple lines) */
  6005. #define strm_pphelp_miserp strm_other[2] /* miser mode indicator */
  6006. #define strm_pphelp_offset strm_other[3] /* initial line offset (indent) */
  6007. #define strm_buff_in_fun strm_other[0] /* read function */
  6008. #define strm_buff_out_fun strm_other[0] /* output function */
  6009. #define strm_twoway_input strm_other[0] /* stream for input */
  6010. #define strm_twoway_output strm_other[1] /* stream for output */
  6011. #ifdef PIPES
  6012. #define strm_pipe_pid strm_other[6] /* process-Id, a Fixnum >=0 */
  6013. #endif
  6014. #ifdef X11SOCKETS
  6015. #define strm_x11socket_connect strm_other[6] /* List (host display) */
  6016. #endif
  6017. #ifdef SOCKET_STREAMS
  6018. #define strm_socket_port strm_other[6] /* port, a fixnum >=0 */
  6019. #define strm_socket_host strm_other[7] /* host, NIL or a string */
  6020. #define strm_twoway_socket_input strm_other[0] /* input side, a socket stream */
  6021. #endif
  6022. #ifdef GENERIC_STREAMS
  6023. #define strm_controller_object strm_other[0] /* Controller (usually a CLOS-instance) */
  6024. #endif
  6025. #define strm_buffered_bufflen 4096 /* buffer length, a power of 2, <2^16 */
  6026. /* is used by stream.d, pathname.d, io.d */
  6027. %% export_def(strm_buffered_bufflen);
  6028. /* Structures */
  6029. typedef Srecord Structure;
  6030. #define structure_types recdata[0]
  6031. #define structure_length(ptr) srecord_length(ptr)
  6032. #define Structure_length(obj) structure_length(TheStructure(obj))
  6033. %% emit_typedef("Srecord","Structure");
  6034. %% export_def(structure_types);
  6035. /* CLOS class-versions, see clos.lisp */
  6036. typedef struct {
  6037. VRECORD_HEADER
  6038. gcv_object_t cv_newest_class _attribute_aligned_object_; /* the CLASS object describing the newest available version */
  6039. gcv_object_t cv_class _attribute_aligned_object_; /* the CLASS object describing the slots */
  6040. gcv_object_t cv_shared_slots _attribute_aligned_object_; /* simple-vector with the values of all shared slots, or nil */
  6041. gcv_object_t cv_serial _attribute_aligned_object_; /* serial number of this class version */
  6042. gcv_object_t cv_next _attribute_aligned_object_; /* next class-version, or nil */
  6043. gcv_object_t cv_slotlists_valid_p _attribute_aligned_object_; /* true if the following fields are already computed */
  6044. gcv_object_t cv_kept_slot_locations _attribute_aligned_object_; /* plist of old and new slot locations of those slots that remain local or were shared and become local */
  6045. gcv_object_t cv_added_slots _attribute_aligned_object_; /* list of local slots that are added in the next version */
  6046. gcv_object_t cv_discarded_slots _attribute_aligned_object_; /* list of local slots that are removed or become shared in the next version */
  6047. gcv_object_t cv_discarded_slot_locations _attribute_aligned_object_; /* plist of local slots and their old slot locations that are removed or become shared in the next version */
  6048. } * ClassVersion;
  6049. #define classversion_length ((sizeof(*(ClassVersion)0)-offsetofa(svector_,data))/sizeof(gcv_object_t))
  6050. /* CLOS-instances */
  6051. typedef struct {
  6052. SRECORD_HEADER
  6053. gcv_object_t inst_class_version _attribute_aligned_object_; /* indirect pointer to a CLOS-class */
  6054. gcv_object_t other[unspecified] _attribute_aligned_object_;
  6055. } * Instance;
  6056. /* Bit masks in the flags: */
  6057. #define instflags_forwarded_B bit(0)
  6058. #define instflags_beingupdated_B bit(3)
  6059. /* The following are only used during garbage collection. */
  6060. #define instflags_backpointer_B bit(1)
  6061. #define instflags_relocated_B bit(2)
  6062. #define mark_inst_clean(ptr) \
  6063. record_flags_clr(ptr,instflags_backpointer_B|instflags_relocated_B)
  6064. %% sprintf(buf,"struct { SRECORD_HEADER gcv_object_t inst_class_version%s; gcv_object_t other[unspecified]%s; } *",attribute_aligned_object,attribute_aligned_object);
  6065. %% emit_typedef(buf,"Instance");
  6066. /* Structures that inherit from <structure-stablehash> */
  6067. typedef struct {
  6068. SRECORD_HEADER
  6069. gcv_object_t _structure_types _attribute_aligned_object_;
  6070. gcv_object_t stablehashcode _attribute_aligned_object_;
  6071. gcv_object_t other[unspecified] _attribute_aligned_object_;
  6072. } * StablehashStructure;
  6073. /* CLOS instances that inherit from <standard-stablehash> */
  6074. typedef struct {
  6075. SRECORD_HEADER
  6076. gcv_object_t inst_class_version _attribute_aligned_object_; /* indirect pointer to a CLOS-class */
  6077. gcv_object_t stablehashcode _attribute_aligned_object_;
  6078. gcv_object_t other[unspecified] _attribute_aligned_object_;
  6079. } * StablehashInstance;
  6080. /* Slot definitions (= instances of <slot-definition>, see clos-slotdef1.lisp */
  6081. typedef struct {
  6082. SRECORD_HEADER
  6083. gcv_object_t inst_class_version _attribute_aligned_object_;
  6084. gcv_object_t slotdef_name _attribute_aligned_object_;
  6085. gcv_object_t slotdef_initargs _attribute_aligned_object_;
  6086. gcv_object_t slotdef_type _attribute_aligned_object_;
  6087. gcv_object_t slotdef_allocation _attribute_aligned_object_;
  6088. gcv_object_t slotdef_inheritable_initer _attribute_aligned_object_;
  6089. gcv_object_t slotdef_inheritable_doc _attribute_aligned_object_;
  6090. /* from here on only for class ⊆ <effective-slot-definition> */
  6091. gcv_object_t slotdef_location _attribute_aligned_object_;
  6092. gcv_object_t slotdef_efm_svuc _attribute_aligned_object_;
  6093. gcv_object_t slotdef_efm_ssvuc _attribute_aligned_object_;
  6094. gcv_object_t slotdef_efm_sbuc _attribute_aligned_object_;
  6095. gcv_object_t slotdef_efm_smuc _attribute_aligned_object_;
  6096. } * SlotDefinition;
  6097. /* CLOS-Classes (= instances of <class>), see clos-class1.lisp */
  6098. typedef struct {
  6099. SRECORD_HEADER
  6100. gcv_object_t inst_class_version _attribute_aligned_object_; /* indirect pointer to a CLOS-class */
  6101. gcv_object_t hashcode _attribute_aligned_object_; /* GC invariant hash code */
  6102. gcv_object_t direct_methods _attribute_aligned_object_; /* set of methods that use this specializer */
  6103. gcv_object_t classname _attribute_aligned_object_; /* a symbol */
  6104. gcv_object_t direct_subclasses _attribute_aligned_object_; /* weak-list or weak-hash-table of all direct subclasses */
  6105. /* from here on only for metaclass ⊆ <defined-class> */
  6106. gcv_object_t direct_superclasses _attribute_aligned_object_; /* direct superclasses */
  6107. gcv_object_t all_superclasses _attribute_aligned_object_; /* all superclasses, including itself */
  6108. gcv_object_t precedence_list _attribute_aligned_object_; /* ordered list of all superclasses */
  6109. gcv_object_t direct_slots _attribute_aligned_object_;
  6110. gcv_object_t slots _attribute_aligned_object_;
  6111. gcv_object_t slot_location_table _attribute_aligned_object_; /* hashtable slotname -> where the slot is located */
  6112. gcv_object_t direct_default_initargs _attribute_aligned_object_;
  6113. gcv_object_t default_initargs _attribute_aligned_object_;
  6114. gcv_object_t documentation _attribute_aligned_object_; /* string or NIL */
  6115. gcv_object_t listeners _attribute_aligned_object_; /* list of objects to be notified upon a change */
  6116. gcv_object_t initialized _attribute_aligned_object_; /* describes which parts of the class are initialized */
  6117. /* from here on only for metaclass ⊆ <standard-class> or metaclass ⊆ <funcallable-standard-class> or metaclass ⊆ <structure-class> */
  6118. gcv_object_t subclass_of_stablehash_p _attribute_aligned_object_; /* true if <standard-stablehash> or <structure-stablehash> is among the superclasses */
  6119. gcv_object_t generic_accessors _attribute_aligned_object_;
  6120. gcv_object_t direct_accessors _attribute_aligned_object_;
  6121. gcv_object_t valid_initargs_from_slots _attribute_aligned_object_;
  6122. gcv_object_t instance_size _attribute_aligned_object_;
  6123. /* from here on only for metaclass ⊆ <standard-class> or metaclass ⊆ <funcallable-standard-class> */
  6124. gcv_object_t current_version _attribute_aligned_object_; /* most recent class-version, points back to this class */
  6125. gcv_object_t funcallablep _attribute_aligned_object_;
  6126. gcv_object_t fixed_slot_locations _attribute_aligned_object_;
  6127. gcv_object_t instantiated _attribute_aligned_object_;
  6128. gcv_object_t direct_instance_specializers _attribute_aligned_object_;
  6129. gcv_object_t finalized_direct_subclasses _attribute_aligned_object_; /* weak-list or weak-hash-table of all finalized direct subclasses */
  6130. gcv_object_t prototype _attribute_aligned_object_; /* class prototype - an instance or NIL */
  6131. /* from here on only for metaclass ⊆ <standard-class> */
  6132. gcv_object_t other[unspecified] _attribute_aligned_object_;
  6133. } * Class;
  6134. /* Length of a <defined-class>. */
  6135. #define defined_class_length ((((aint)&((Class)0)->initialized-offsetofa(record_,recdata))/sizeof(gcv_object_t))+1)
  6136. /* Length of a <built-in-class>. */
  6137. #define built_in_class_length (defined_class_length+1) /* = clos::*<built-in-class>-instance-size* */
  6138. /* Closures */
  6139. typedef struct {
  6140. SRECORD_HEADER
  6141. gcv_object_t clos_name_or_class_version _attribute_aligned_object_;
  6142. gcv_object_t clos_codevec _attribute_aligned_object_;
  6143. gcv_object_t other[unspecified] _attribute_aligned_object_;
  6144. } * Closure;
  6145. /* interpreted Closure: */
  6146. typedef struct {
  6147. SRECORD_HEADER
  6148. gcv_object_t clos_name _attribute_aligned_object_;
  6149. gcv_object_t clos_form _attribute_aligned_object_;
  6150. gcv_object_t clos_docstring _attribute_aligned_object_;
  6151. gcv_object_t clos_body _attribute_aligned_object_;
  6152. gcv_object_t clos_var_env _attribute_aligned_object_;
  6153. gcv_object_t clos_fun_env _attribute_aligned_object_;
  6154. gcv_object_t clos_block_env _attribute_aligned_object_;
  6155. gcv_object_t clos_go_env _attribute_aligned_object_;
  6156. gcv_object_t clos_decl_env _attribute_aligned_object_;
  6157. gcv_object_t clos_vars _attribute_aligned_object_;
  6158. gcv_object_t clos_varflags _attribute_aligned_object_;
  6159. gcv_object_t clos_spec_count _attribute_aligned_object_;
  6160. gcv_object_t clos_req_count _attribute_aligned_object_;
  6161. gcv_object_t clos_opt_count _attribute_aligned_object_;
  6162. gcv_object_t clos_opt_inits _attribute_aligned_object_;
  6163. gcv_object_t clos_key_count _attribute_aligned_object_;
  6164. gcv_object_t clos_keywords _attribute_aligned_object_;
  6165. gcv_object_t clos_key_inits _attribute_aligned_object_;
  6166. gcv_object_t clos_allow_flag _attribute_aligned_object_;
  6167. gcv_object_t clos_rest_flag _attribute_aligned_object_;
  6168. gcv_object_t clos_aux_count _attribute_aligned_object_;
  6169. gcv_object_t clos_aux_inits _attribute_aligned_object_;
  6170. } * Iclosure;
  6171. #define iclos_length ((sizeof(*(Iclosure)0)-offsetofa(record_,recdata))/sizeof(gcv_object_t))
  6172. /* compiled Closure: */
  6173. typedef struct {
  6174. SRECORD_HEADER
  6175. gcv_object_t clos_name_or_class_version _attribute_aligned_object_;
  6176. gcv_object_t clos_codevec _attribute_aligned_object_;
  6177. gcv_object_t clos_consts[unspecified] _attribute_aligned_object_; /* Closure-constants */
  6178. } * Cclosure;
  6179. #define cclosure_length(ptr) srecord_length(ptr)
  6180. #define Cclosure_length(obj) cclosure_length(TheCclosure(obj))
  6181. /* Flags in a closure. They must be disjoint from the instflags_* bits. */
  6182. #ifdef TYPECODES
  6183. #define closure_flags(ptr) ((ptr)->recflags)
  6184. #else
  6185. #define closure_flags(ptr) record_flags(ptr)
  6186. #endif
  6187. #define Closure_flags(obj) closure_flags(TheClosure(obj))
  6188. #define Cclosure_seclass(obj) ((Closure_flags(obj) >> 4) & 0x07)
  6189. #define Cclosure_set_seclass(obj,se) \
  6190. (record_flags_clr(TheCclosure(obj),0x07<<4), \
  6191. record_flags_set(TheCclosure(obj),(se)<<4))
  6192. #define closflags_instance_B bit(7)
  6193. #define closure_instancep(ptr) (closure_flags(ptr) & closflags_instance_B)
  6194. #define Closure_instancep(obj) closure_instancep(TheClosure(obj))
  6195. /* Closed-over environment, as a set of nested simple-vectors. */
  6196. #define clos_venv clos_consts[0]
  6197. /* The function's name. Depends on whether instancep or not. */
  6198. #define Closure_name(obj) \
  6199. (Closure_instancep(obj) \
  6200. ? TheCclosure(obj)->clos_consts[1] \
  6201. : TheClosure(obj)->clos_name_or_class_version)
  6202. typedef struct {
  6203. VRECORD_HEADER /* self-pointer for GC, length in bits */
  6204. /* Here: Content of the Bitvector. */
  6205. uintW ccv_spdepth_1; /* maximal SP-depth, 1-part */
  6206. uintW ccv_spdepth_jmpbufsize; /* maximal SP-depth, jmpbufsize-part */
  6207. uintW ccv_numreq; /* number of required parameters */
  6208. uintW ccv_numopt; /* number of optional parameters */
  6209. uintB ccv_flags; /* Flags: Bit 0: &REST - parameter given?
  6210. Bit 1: full lambda list at the end of const vec
  6211. Bit 2: docstring at the end of const vec
  6212. Bit 3: generic function with call-inhibition?
  6213. Bit 4: generic function?
  6214. Bit 5: JITC code at the end of const vec
  6215. Bit 6: &ALLOW-OTHER-KEYS-Flag
  6216. Bit 7: keyword-parameter given? */
  6217. uintB ccv_signature; /* abbreviated argument type, for faster FUNCALL */
  6218. /* If keyword-parameters are given: */
  6219. uintW ccv_numkey; /* Number of keyword-parameters */
  6220. uintW ccv_keyconsts; /* Offset in FUNC of the keywords */
  6221. } * Codevec;
  6222. #define CCV_SPDEPTH_1 0
  6223. #define CCV_SPDEPTH_JMPBUFSIZE 2
  6224. #define CCV_NUMREQ 4
  6225. #define CCV_NUMOPT 6
  6226. #define CCV_FLAGS 8
  6227. #define CCV_SIGNATURE 9
  6228. #define CCV_NUMKEY 10
  6229. #define CCV_KEYCONSTS 12
  6230. #define CCV_START_NONKEY 10
  6231. #define CCV_START_KEY 14
  6232. /* Compiled closures, where Bit 4 has been set in the flags of clos_codevec
  6233. are generic functions. */
  6234. %% export_def(closure_flags(ptr));
  6235. %% export_def(closure_instancep(ptr));
  6236. %% export_def(Closure_instancep(obj));
  6237. /* the position of the last const (or doc or lalist!) */
  6238. #define Cclosure_last_const(obj) (Cclosure_length(obj) - 1 - \
  6239. (sizeof(*(Cclosure)0) - offsetofa(srecord_,recdata))/sizeof(gcv_object_t))
  6240. #define ccv_flags_lambda_list_p(ccv_flags) (((ccv_flags) & bit(1)) != 0)
  6241. #define ccv_flags_documentation_p(ccv_flags) (((ccv_flags) & bit(2)) != 0)
  6242. #define ccv_flags_jitc_p(ccv_flags) (((ccv_flags) & bit(5)) != 0)
  6243. #define cclosure_jitc(closure) TheCclosure(closure)->clos_consts[Cclosure_last_const(closure)]
  6244. #define cclosure_jitc_p(closure) ccv_flags_jitc_p(TheCodevec(TheCclosure(closure)->clos_codevec)->ccv_flags)
  6245. /* A compiled LISP-function gets its arguments on the STACK
  6246. and returns its values in MULTIPLE_VALUE_SPACE.
  6247. It does not return a value as a C-function. */
  6248. /* Return of multiple values is completely done through
  6249. MULTIPLE_VALUE_SPACE. As C-function: result-type Values. */
  6250. #ifndef Values
  6251. typedef void Values;
  6252. #endif
  6253. /* To pass a type of the value Values: return_Values(...); */
  6254. #define return_Values return_void
  6255. /* A Lisp-function is a pointer to a C-function without returned value. */
  6256. typedef Values (*lisp_function_t)();
  6257. /* If this is changed, every call of a C-function with the result type
  6258. 'Values' (especially 'funcall', 'apply', 'eval') is to be checked. */
  6259. %% puts("typedef void Values;"); /* emit_typedef useless: no sizeof(void) */
  6260. %% emit_typedef_f("Values (*%s)()","lisp_function_t");
  6261. /* FSUBRs
  6262. As C-functions: of type fsubr_function_t (no arguments, no value): */
  6263. typedef Values fsubr_function_t (void);
  6264. /* The addesses of these C-functions are jumped to directly
  6265. For SAVEMEM/LOADMEM there is a table containing all FSUBRs. */
  6266. typedef fsubr_function_t * fsubr_t;
  6267. /* Signature of FSUBRs in the Lisp-way:
  6268. argtype short for the argument type fsubr_argtype_t
  6269. req_count number of required parameters uintW
  6270. opt_count number of optional parameters uintW
  6271. body_flag Body-Flag fsubr_body_t
  6272. The component body_flag contains one uintW, but we mean: */
  6273. typedef enum {
  6274. fsubr_nobody,
  6275. fsubr_body
  6276. } fsubr_body_t;
  6277. /* The component argtype contains a Fixnum, but it's supposed to be: */
  6278. typedef enum {
  6279. fsubr_argtype_1_0_nobody,
  6280. fsubr_argtype_2_0_nobody,
  6281. fsubr_argtype_1_1_nobody,
  6282. fsubr_argtype_2_1_nobody,
  6283. fsubr_argtype_0_body,
  6284. fsubr_argtype_1_body,
  6285. fsubr_argtype_2_body
  6286. } fsubr_argtype_t;
  6287. /* conversion: see SPVW:
  6288. extern fsubr_argtype_t fsubr_argtype (uintW req_count, uintW opt_count, fsubr_body_t body_flag); */
  6289. /* SUBRs
  6290. SUBR table entry: */
  6291. typedef struct {
  6292. XRECORD_HEADER
  6293. gcv_object_t name _attribute_aligned_object_; /* name */
  6294. gcv_object_t keywords _attribute_aligned_object_; /* NIL or vector with the keywords */
  6295. lisp_function_t function; /* function */
  6296. uintW argtype; /* short for the argument-type */
  6297. uintW req_count; /* number of required parameters */
  6298. uintW opt_count; /* number of optional parameters */
  6299. uintB rest_flag; /* flag for arbitrary number of arguments */
  6300. uintB key_flag; /* flag for keywords */
  6301. uintW key_count; /* number of keyword parameter */
  6302. uintB seclass; /* side-effect class */
  6303. uintB fastcmp; /* fast comparison method */
  6304. /* If necessary, add fillers here to ensure sizeof(subr_t)
  6305. is a multiple of varobject_alignment. */
  6306. } subr_t
  6307. #if defined(HEAPCODES) && (alignment_long < 4) && defined(GNU)
  6308. /* Force all Subrs to be allocated with a 4-byte alignment. GC needs this. */
  6309. __attribute__ ((aligned (4)))
  6310. #endif
  6311. ;
  6312. typedef subr_t * Subr;
  6313. /* Compile-time check: sizeof(subr_t) is a multiple of varobject_alignment. */
  6314. typedef int subr_size_check[1 - 2 * (int)(sizeof(subr_t) % varobject_alignment)];
  6315. /* GC needs information where objects are in here: */
  6316. #define subr_length 2
  6317. #define subr_xlength (sizeof(*(Subr)0)-offsetofa(record_,recdata)-subr_length*sizeof(gcv_object_t))
  6318. /* the rest_flag component is a uintB, while we really mean: */
  6319. typedef enum {
  6320. subr_norest,
  6321. subr_rest
  6322. } subr_rest_t;
  6323. /* the key_flag component is a uintB, while we really mean: */
  6324. typedef enum {
  6325. subr_nokey,
  6326. subr_key,
  6327. subr_key_allow
  6328. } subr_key_t;
  6329. /* the argtype component is a uintW, while we really mean: */
  6330. typedef enum {
  6331. subr_argtype_0_0,
  6332. subr_argtype_1_0,
  6333. subr_argtype_2_0,
  6334. subr_argtype_3_0,
  6335. subr_argtype_4_0,
  6336. subr_argtype_5_0,
  6337. subr_argtype_6_0,
  6338. subr_argtype_0_1,
  6339. subr_argtype_1_1,
  6340. subr_argtype_2_1,
  6341. subr_argtype_3_1,
  6342. subr_argtype_4_1,
  6343. subr_argtype_0_2,
  6344. subr_argtype_1_2,
  6345. subr_argtype_2_2,
  6346. subr_argtype_3_2,
  6347. subr_argtype_0_3,
  6348. subr_argtype_1_3,
  6349. subr_argtype_2_3,
  6350. subr_argtype_0_4,
  6351. subr_argtype_0_5,
  6352. subr_argtype_0_0_rest,
  6353. subr_argtype_1_0_rest,
  6354. subr_argtype_2_0_rest,
  6355. subr_argtype_3_0_rest,
  6356. subr_argtype_0_0_key,
  6357. subr_argtype_1_0_key,
  6358. subr_argtype_2_0_key,
  6359. subr_argtype_3_0_key,
  6360. subr_argtype_4_0_key,
  6361. subr_argtype_0_1_key,
  6362. subr_argtype_1_1_key,
  6363. subr_argtype_1_2_key
  6364. } subr_argtype_t;
  6365. /* Conversion: see SPVW:
  6366. extern subr_argtype_t subr_argtype (uintW req_count, uintW opt_count, subr_rest_t rest_flag, subr_key_t key_flag); */
  6367. %% sprintf(buf,"struct { XRECORD_HEADER gcv_object_t name%s; gcv_object_t keywords%s; lisp_function_t function; uintW argtype; uintW req_count; uintW opt_count; uintB rest_flag; uintB key_flag; uintW key_count; uintB seclass; uintB fastcmp; } %%s",attribute_aligned_object,attribute_aligned_object);
  6368. %% #if defined(HEAPCODES) && (alignment_long < 4) && defined(GNU)
  6369. %% strcat(buf," __attribute__ ((aligned (4)))");
  6370. %% #endif
  6371. %% emit_typedef_f(buf,"subr_t");
  6372. %% emit_typedef("subr_t *","Subr");
  6373. %% emit_typedef("enum { subr_norest, subr_rest }","subr_rest_t");
  6374. %% emit_typedef("enum { subr_nokey, subr_key, subr_key_allow }","subr_key_t");
  6375. /* side-effect class is really seclass_t: */
  6376. typedef enum {
  6377. seclass_foldable, /* the function allows Constant-Folding:
  6378. two calls with identical arguments give the same result,
  6379. and calls with constant arguments can be evaluated at compile time.
  6380. In particular, no side effects, do not depend on global variables or such,
  6381. do not even look "inside" their arguments */
  6382. seclass_no_se, /* no side effects, do not depend on global variables or such,
  6383. do not even look "inside" their arguments, but not "foldable". */
  6384. seclass_read, /* no side effects, but depend on global variables
  6385. or look "inside" their arguments. */
  6386. seclass_write, /* only side effects: does not read anything,
  6387. just sets some global variables. */
  6388. seclass_default /* may do side effects */
  6389. } seclass_t;
  6390. %% puts("enum { seclass_foldable, seclass_no_se, seclass_read, seclass_write, seclass_default};");
  6391. /* fast comparison method is really fastcmp_t:
  6392. when you want to make another comparison function bypass FUNCALL in
  6393. :TEST/:TEST-NOT sequence functions, you need to
  6394. -- add fastcmp_FOO here and
  6395. -- augment funarg.d:check_test_args(), and
  6396. -- add call_test_FOO and call_test_not_FOO in funarg.d */
  6397. typedef enum {
  6398. fastcmp_none=0, /* no special tricks */
  6399. fastcmp_eq, /* EQ */
  6400. fastcmp_eql, /* EQL */
  6401. fastcmp_equal, /* EQUAL */
  6402. fastcmp_equalp, /* EQUALP */
  6403. fastcmp_for_broken_compilers_that_dont_like_trailing_commas
  6404. } fastcmp_t;
  6405. /* Small-Read-Label */
  6406. #ifdef TYPECODES
  6407. #define make_small_read_label(n) \
  6408. type_data_object(system_type, ((uintV)(n)<<1) + bit(0))
  6409. #define small_read_label_integer_p(obj) \
  6410. (posfixnump(obj) && (posfixnum_to_V(obj) < vbit(oint_data_len-2)))
  6411. #define small_read_label_value(obj) \
  6412. fixnum((as_oint(obj) >> (oint_data_shift+1)) & (vbit(oint_data_len-2)-1))
  6413. #else
  6414. #define make_small_read_label(n) \
  6415. type_data_object(small_read_label_type, (uintV)(n))
  6416. #define small_read_label_integer_p(obj) posfixnump(obj)
  6417. #define small_read_label_value(obj) \
  6418. fixnum((as_oint(obj) >> oint_data_shift) & (vbit(oint_data_len)-1))
  6419. #endif
  6420. /* Machine pointers:
  6421. make_machine(ptr) */
  6422. #ifdef TYPECODES
  6423. #define make_machine(ptr) type_pointer_object(machine_type,ptr)
  6424. #else
  6425. #if defined(WIDE_AUXI)
  6426. #define make_machine(ptr) as_object_with_auxi((aint)(ptr)+machine_bias)
  6427. #else
  6428. #define make_machine(ptr) as_object((oint)(ptr)+machine_bias)
  6429. #endif
  6430. #endif
  6431. %% export_def(make_machine(ptr));
  6432. #ifdef MULTITHREAD
  6433. typedef struct {
  6434. XRECORD_HEADER
  6435. gcv_object_t xth_name _attribute_aligned_object_; /* name */
  6436. gcv_object_t xth_next _attribute_aligned_object_; /* next thread */
  6437. gcv_object_t xth_prev _attribute_aligned_object_; /* previous thread */
  6438. gcv_object_t *xth_tlvs; /* thread-local values */
  6439. gcv_object_t *xth_stack; /* the thread stack */
  6440. struct backtrace_t *xth_bt; /* the backtrace */
  6441. xthread_t xth_system; /* OS object */
  6442. } * Thread;
  6443. #define thread_length 2
  6444. #define thread_xlength (sizeof(*(Thread)0)-offsetofa(record_,recdata)-thread_length*sizeof(gcv_object_t))
  6445. typedef struct {
  6446. XRECORD_HEADER
  6447. gcv_object_t xmu_name _attribute_aligned_object_; /* name */
  6448. xmutex_t xmu_system; /* OS object */
  6449. } * Mutex;
  6450. #define mutex_length 1
  6451. #define mutex_xlength (sizeof(*(Mutex)0)-offsetofa(record_,recdata)-mutex_length*sizeof(gcv_object_t))
  6452. typedef struct {
  6453. XRECORD_HEADER
  6454. gcv_object_t xco_name _attribute_aligned_object_; /* name */
  6455. xcondition_t xco_system; /* OS object */
  6456. } * Exemption;
  6457. #define exemption_length 1
  6458. #define exemption_xlength (sizeof(*(Exemption)0)-offsetofa(record_,recdata)-exemption_length*sizeof(gcv_object_t))
  6459. #endif
  6460. /* Pointer to machine code
  6461. make_machine_code(ptr) */
  6462. #if defined(TYPECODES) || (log2_C_CODE_ALIGNMENT >= 2)
  6463. #define make_machine_code(ptr) make_machine(ptr)
  6464. #elif defined(HPPA)
  6465. #define make_machine_code(ptr) make_machine((uintP)(ptr)&~(uintP)3)
  6466. #else
  6467. #define make_machine_code(ptr) make_machine((uintP)(ptr)<<(2-log2_C_CODE_ALIGNMENT))
  6468. #endif
  6469. /* System-Pointer */
  6470. #define make_system(data) \
  6471. type_data_object(system_type, vbit(oint_data_len-1) | bit(0) | ((vbitm(oint_data_len)-1) & (data)))
  6472. /* all such go into the special print routine io.d:pr_system() */
  6473. %% export_def(make_system(data));
  6474. /* missing value */
  6475. #define unbound make_system(0xFFFFFFUL)
  6476. %% export_def(unbound);
  6477. /* missing object (internal use only): */
  6478. #define nullobj make_machine(0) /* = as_object((oint)0) */
  6479. #ifdef DEBUG_GCSAFETY
  6480. #define gcv_nullobj (gcv_object_t)nullobj
  6481. #else
  6482. #define gcv_nullobj nullobj
  6483. #endif
  6484. %% export_def(nullobj);
  6485. %% export_def(gcv_nullobj);
  6486. /* cgci_pointable(obj) converts a certainly GC-invariant object to an aint.
  6487. pgci_pointable(obj) converts a possibly GC-invariant object to an aint.
  6488. ngci_pointable(obj) converts a not GC-invariant object to an aint. */
  6489. #if defined(DEBUG_GCSAFETY)
  6490. static inline aint cgci_pointable (object obj) {
  6491. return obj.one_o;
  6492. }
  6493. static inline aint cgci_pointable (gcv_object_t obj) {
  6494. return obj.one_o;
  6495. }
  6496. static inline aint pgci_pointable (object obj) {
  6497. if (!(gcinvariant_object_p(obj) || gcinvariant_symbol_p(obj)
  6498. || obj.allocstamp == alloccount || nonimmsubrp(obj)))
  6499. abort();
  6500. nonimmprobe(obj.one_o);
  6501. return obj.one_o;
  6502. }
  6503. static inline aint pgci_pointable (gcv_object_t obj) {
  6504. nonimmprobe(obj.one_o);
  6505. return obj.one_o;
  6506. }
  6507. static inline aint ngci_pointable (object obj) {
  6508. if (!(gcinvariant_symbol_p(obj)
  6509. || obj.allocstamp == alloccount || nonimmsubrp(obj)))
  6510. abort();
  6511. nonimmprobe(obj.one_o);
  6512. return obj.one_o;
  6513. }
  6514. static inline aint ngci_pointable (gcv_object_t obj) {
  6515. nonimmprobe(obj.one_o);
  6516. return obj.one_o;
  6517. }
  6518. #elif defined(WIDE_AUXI)
  6519. #define cgci_pointable(obj) (obj).one_o
  6520. #define pgci_pointable(obj) (obj).one_o
  6521. #define ngci_pointable(obj) (obj).one_o
  6522. #else
  6523. #define cgci_pointable(obj) as_oint(obj)
  6524. #define pgci_pointable(obj) as_oint(obj)
  6525. #define ngci_pointable(obj) as_oint(obj)
  6526. #endif
  6527. %% #if defined(DEBUG_GCSAFETY)
  6528. %% puts("static inline aint cgci_pointable (object obj) { return obj.one_o; }");
  6529. %% puts("static inline aint cgci_pointable (gcv_object_t obj) { return obj.one_o; }");
  6530. %% puts("static inline aint pgci_pointable (object obj) { if (!(gcinvariant_object_p(obj) || gcinvariant_symbol_p(obj) || obj.allocstamp == alloccount || nonimmsubrp(obj))) abort(); nonimmprobe(obj.one_o); return obj.one_o; }");
  6531. %% puts("static inline aint pgci_pointable (gcv_object_t obj) { nonimmprobe(obj.one_o); return obj.one_o; }");
  6532. %% puts("static inline aint ngci_pointable (object obj) { if (!(gcinvariant_symbol_p(obj) || obj.allocstamp == alloccount || nonimmsubrp(obj))) abort(); nonimmprobe(obj.one_o); return obj.one_o; }");
  6533. %% puts("static inline aint ngci_pointable (gcv_object_t obj) { nonimmprobe(obj.one_o); return obj.one_o; }");
  6534. %% #else
  6535. %% export_def(cgci_pointable(obj));
  6536. %% export_def(pgci_pointable(obj));
  6537. %% export_def(ngci_pointable(obj));
  6538. %% #endif
  6539. /* TheCons(object) yields the Cons that's equivalent to object.
  6540. The information that it is a Cons has to be put into it.
  6541. The other type conversions are similar. */
  6542. #ifdef TYPECODES
  6543. #ifdef DEBUG_GCSAFETY
  6544. #define cgci_types_pointable(ORed_types,obj) cgci_pointable(obj)
  6545. #define pgci_types_pointable(ORed_types,obj) pgci_pointable(obj)
  6546. #define ngci_types_pointable(ORed_types,obj) ngci_pointable(obj)
  6547. #else
  6548. #define cgci_types_pointable(ORed_types,obj) types_pointable(ORed_types,obj)
  6549. #define pgci_types_pointable(ORed_types,obj) types_pointable(ORed_types,obj)
  6550. #define ngci_types_pointable(ORed_types,obj) types_pointable(ORed_types,obj)
  6551. #endif
  6552. #define TheCons(obj) ((Cons)(ngci_types_pointable(cons_type,obj)))
  6553. #define TheRatio(obj) ((Ratio)(ngci_types_pointable(ratio_type|bit(sign_bit_t),obj)))
  6554. #define TheComplex(obj) ((Complex)(ngci_types_pointable(complex_type,obj)))
  6555. #define TheSymbol(obj) ((Symbol)(ngci_types_pointable(symbol_type,obj)))
  6556. #if (oint_symbolflags_shift==oint_type_shift)
  6557. #define TheSymbolflagged(obj) ((Symbol)(ngci_types_pointable(symbol_type|bit(active_bit)|bit(dynam_bit)|bit(svar_bit),obj)))
  6558. #else
  6559. #define TheSymbolflagged(obj) TheSymbol(symbol_without_flags(obj))
  6560. #endif
  6561. #define TheBignum(obj) ((Bignum)(ngci_types_pointable(bignum_type|bit(sign_bit_t),obj)))
  6562. #ifndef IMMEDIATE_FFLOAT
  6563. #define TheFfloat(obj) ((Ffloat)(ngci_types_pointable(ffloat_type|bit(sign_bit_t),obj)))
  6564. #endif
  6565. #define TheDfloat(obj) ((Dfloat)(ngci_types_pointable(dfloat_type|bit(sign_bit_t),obj)))
  6566. #define TheLfloat(obj) ((Lfloat)(ngci_types_pointable(lfloat_type|bit(sign_bit_t),obj)))
  6567. #define TheSarray(obj) ((Sarray)(ngci_types_pointable(sbvector_type|sb2vector_type|sb4vector_type|sb8vector_type|sb16vector_type|sb32vector_type|sstring_type|svector_type,obj)))
  6568. #define TheSbvector(obj) ((Sbvector)(ngci_types_pointable(sbvector_type|sb2vector_type|sb4vector_type|sb8vector_type|sb16vector_type|sb32vector_type,obj)))
  6569. #define TheCodevec(obj) ((Codevec)(ngci_types_pointable(sb8vector_type,obj)))
  6570. #define TheS8string(obj) ((S8string)(ngci_types_pointable(sstring_type,obj)))
  6571. #define TheS16string(obj) ((S16string)(ngci_types_pointable(sstring_type,obj)))
  6572. #define TheS32string(obj) ((S32string)(ngci_types_pointable(sstring_type,obj)))
  6573. #define TheSnstring(obj) ((Snstring)(ngci_types_pointable(sstring_type,obj)))
  6574. #define TheSistring(obj) ((Sistring)(ngci_types_pointable(sstring_type,obj)))
  6575. #define TheSstring(obj) ((Sstring)(ngci_types_pointable(sstring_type,obj)))
  6576. #define TheSvector(obj) ((Svector)(ngci_types_pointable(svector_type,obj)))
  6577. #define TheIarray(obj) ((Iarray)(ngci_types_pointable(mdarray_type|bvector_type|b2vector_type|b4vector_type|b8vector_type|b16vector_type|b32vector_type|string_type|vector_type,obj)))
  6578. #define TheRecord(obj) ((Record)(ngci_types_pointable(closure_type|structure_type|stream_type|orecord_type|instance_type|lrecord_type,obj)))
  6579. #define TheLrecord(obj) ((Lrecord)(ngci_types_pointable(lrecord_type,obj)))
  6580. #define TheSrecord(obj) ((Srecord)(ngci_types_pointable(closure_type|structure_type|orecord_type|instance_type,obj)))
  6581. #define TheXrecord(obj) ((Xrecord)(ngci_types_pointable(stream_type|orecord_type,obj)))
  6582. #define ThePackage(obj) ((Package)(ngci_types_pointable(orecord_type,obj)))
  6583. #define TheHashtable(obj) ((Hashtable)(ngci_types_pointable(orecord_type,obj)))
  6584. #define TheReadtable(obj) ((Readtable)(ngci_types_pointable(orecord_type,obj)))
  6585. #define ThePathname(obj) ((Pathname)(ngci_types_pointable(orecord_type,obj)))
  6586. #ifdef LOGICAL_PATHNAMES
  6587. #define TheLogpathname(obj) ((Logpathname)(ngci_types_pointable(orecord_type,obj)))
  6588. #endif
  6589. #define The_Random_state(obj) ((Random_state)(ngci_types_pointable(orecord_type,obj)))
  6590. #define TheByte(obj) ((Byte)(ngci_types_pointable(orecord_type,obj)))
  6591. #define TheFsubr(obj) ((Fsubr)(ngci_types_pointable(orecord_type,obj)))
  6592. #define TheLoadtimeeval(obj) ((Loadtimeeval)(ngci_types_pointable(orecord_type,obj)))
  6593. #define TheSymbolmacro(obj) ((Symbolmacro)(ngci_types_pointable(orecord_type,obj)))
  6594. #define TheGlobalSymbolmacro(obj) ((GlobalSymbolmacro)(ngci_types_pointable(orecord_type,obj)))
  6595. #define TheMacro(obj) ((Macro)(ngci_types_pointable(orecord_type,obj)))
  6596. #define TheFunctionMacro(obj) ((FunctionMacro)(ngci_types_pointable(orecord_type,obj)))
  6597. #define TheBigReadLabel(obj) ((BigReadLabel)(ngci_types_pointable(orecord_type,obj)))
  6598. #define TheEncoding(obj) ((Encoding)(ngci_types_pointable(orecord_type,obj)))
  6599. #ifdef FOREIGN
  6600. #define TheFpointer(obj) ((Fpointer)(ngci_types_pointable(orecord_type,obj)))
  6601. #endif
  6602. #ifdef DYNAMIC_FFI
  6603. #define TheFaddress(obj) ((Faddress)(ngci_types_pointable(orecord_type,obj)))
  6604. #define TheFvariable(obj) ((Fvariable)(ngci_types_pointable(orecord_type,obj)))
  6605. #define TheFfunction(obj) ((Ffunction)(ngci_types_pointable(orecord_type,obj)))
  6606. #endif
  6607. #define TheWeakpointer(obj) ((Weakpointer)(ngci_types_pointable(orecord_type,obj)))
  6608. #define TheMutableWeakList(obj) ((MutableWeakList)(ngci_types_pointable(orecord_type,obj)))
  6609. #define TheWeakList(obj) ((WeakList)(ngci_types_pointable(lrecord_type,obj)))
  6610. #define TheWeakAnd(obj) ((WeakAnd)(ngci_types_pointable(lrecord_type,obj)))
  6611. #define TheWeakOr(obj) ((WeakOr)(ngci_types_pointable(lrecord_type,obj)))
  6612. #define TheWeakmapping(obj) ((Weakmapping)(ngci_types_pointable(orecord_type,obj)))
  6613. #define TheWeakAndMapping(obj) ((WeakAndMapping)(ngci_types_pointable(lrecord_type,obj)))
  6614. #define TheWeakOrMapping(obj) ((WeakOrMapping)(ngci_types_pointable(lrecord_type,obj)))
  6615. #define TheMutableWeakAlist(obj) ((MutableWeakAlist)(ngci_types_pointable(orecord_type,obj)))
  6616. #define TheWeakAlist(obj) ((WeakAlist)(ngci_types_pointable(lrecord_type,obj)))
  6617. #define TheWeakHashedAlist(obj) ((WeakHashedAlist)(ngci_types_pointable(lrecord_type,obj)))
  6618. #define TheFinalizer(obj) ((Finalizer)(ngci_types_pointable(orecord_type,obj)))
  6619. #ifdef SOCKET_STREAMS
  6620. #define TheSocketServer(obj) ((Socket_server)(ngci_types_pointable(orecord_type,obj)))
  6621. #endif
  6622. #ifdef YET_ANOTHER_RECORD
  6623. #define TheYetanother(obj) ((Yetanother)(ngci_types_pointable(orecord_type,obj)))
  6624. #endif
  6625. #define TheStream(obj) ((Stream)(ngci_types_pointable(stream_type,obj)))
  6626. #define TheStructure(obj) ((Structure)(ngci_types_pointable(structure_type,obj)))
  6627. #define TheClosure(obj) ((Closure)(ngci_types_pointable(closure_type,obj)))
  6628. #define TheIclosure(obj) ((Iclosure)(ngci_types_pointable(closure_type,obj)))
  6629. #define TheCclosure(obj) ((Cclosure)(ngci_types_pointable(closure_type,obj)))
  6630. #define TheInstance(obj) ((Instance)(ngci_types_pointable(instance_type|closure_type,obj)))
  6631. #define TheSubr(obj) ((Subr)(cgci_types_pointable(subr_type,obj)))
  6632. #define TheFramepointer(obj) ((gcv_object_t*)(cgci_types_pointable(system_type,obj)))
  6633. #define TheMachine(obj) ((void*)(cgci_types_pointable(machine_type,obj)))
  6634. #define TheMachineCode(obj) TheMachine(obj)
  6635. #define ThePseudofun(obj) ((Pseudofun)TheMachineCode(obj))
  6636. #ifdef FOREIGN_HANDLE
  6637. /* pack Handle in Sbvector */
  6638. #define TheHandle(obj) (*(Handle*)(&TheSbvector(obj)->data[0]))
  6639. #else
  6640. /* pack Handle in Fixnum>=0 */
  6641. #define TheHandle(obj) ((Handle)posfixnum_to_V(obj))
  6642. #endif
  6643. /* variable length object: */
  6644. #define TheVarobject(obj) \
  6645. ((Varobject) \
  6646. (ngci_types_pointable \
  6647. (sbvector_type|sb2vector_type|sb4vector_type|sb8vector_type \
  6648. |sb16vector_type|sb32vector_type \
  6649. |sstring_type|svector_type \
  6650. |mdarray_type \
  6651. |bvector_type|b2vector_type|b4vector_type|b8vector_type \
  6652. |b16vector_type|b32vector_type \
  6653. |string_type|vector_type \
  6654. |closure_type|structure_type|stream_type|orecord_type \
  6655. |instance_type|lrecord_type|symbol_type \
  6656. |bignum_type|ffloat_type|dfloat_type|lfloat_type|bit(sign_bit_t), \
  6657. obj \
  6658. )))
  6659. /* Object that represents a pointer into the memory: */
  6660. #define ThePointer(obj) \
  6661. (pgci_types_pointable \
  6662. (sbvector_type|sb2vector_type|sb4vector_type|sb8vector_type \
  6663. |sb16vector_type|sb32vector_type \
  6664. |sstring_type|svector_type \
  6665. |mdarray_type \
  6666. |bvector_type|b2vector_type|b4vector_type|b8vector_type \
  6667. |b16vector_type|b32vector_type \
  6668. |string_type|vector_type \
  6669. |closure_type|structure_type|stream_type|orecord_type \
  6670. |instance_type|lrecord_type|symbol_type \
  6671. |cons_type \
  6672. |bignum_type|ffloat_type|dfloat_type|lfloat_type \
  6673. |ratio_type|complex_type|bit(sign_bit_t), \
  6674. obj \
  6675. ))
  6676. #ifdef MULTITHREAD
  6677. #define TheThread(obj) ((Thread)(ngci_types_pointable(orecord_type,obj)))
  6678. #define TheMutex(obj) ((Mutex)(ngci_types_pointable(orecord_type,obj)))
  6679. #define TheExemption(obj) ((Exemption)(ngci_types_pointable(orecord_type,obj)))
  6680. #endif
  6681. #else /* no TYPECODES */
  6682. #define TheCons(obj) ((Cons)(ngci_pointable(obj)-cons_bias))
  6683. #define TheRatio(obj) ((Ratio)(ngci_pointable(obj)-varobject_bias))
  6684. #define TheComplex(obj) ((Complex)(ngci_pointable(obj)-varobject_bias))
  6685. #define TheSymbol(obj) ((Symbol)(ngci_pointable(obj)-varobject_bias))
  6686. #define TheSymbolflagged(obj) TheSymbol(symbol_without_flags(obj))
  6687. #define TheBignum(obj) ((Bignum)(ngci_pointable(obj)-varobject_bias))
  6688. #define TheFfloat(obj) ((Ffloat)(ngci_pointable(obj)-varobject_bias))
  6689. #define TheDfloat(obj) ((Dfloat)(ngci_pointable(obj)-varobject_bias))
  6690. #define TheLfloat(obj) ((Lfloat)(ngci_pointable(obj)-varobject_bias))
  6691. #define TheSarray(obj) ((Sarray)(ngci_pointable(obj)-varobject_bias))
  6692. #define TheSbvector(obj) ((Sbvector)(ngci_pointable(obj)-varobject_bias))
  6693. #define TheCodevec(obj) ((Codevec)TheSbvector(obj))
  6694. #define TheS8string(obj) ((S8string)(ngci_pointable(obj)-varobject_bias))
  6695. #define TheS16string(obj) ((S16string)(ngci_pointable(obj)-varobject_bias))
  6696. #define TheS32string(obj) ((S32string)(ngci_pointable(obj)-varobject_bias))
  6697. #define TheSnstring(obj) ((Snstring)(ngci_pointable(obj)-varobject_bias))
  6698. #define TheSistring(obj) ((Sistring)(ngci_pointable(obj)-varobject_bias))
  6699. #define TheSstring(obj) ((Sstring)(ngci_pointable(obj)-varobject_bias))
  6700. #define TheSvector(obj) ((Svector)(ngci_pointable(obj)-varobject_bias))
  6701. #define TheIarray(obj) ((Iarray)(ngci_pointable(obj)-varobject_bias))
  6702. #define TheRecord(obj) ((Record)(ngci_pointable(obj)-varobject_bias))
  6703. #define TheLrecord(obj) ((Lrecord)(ngci_pointable(obj)-varobject_bias))
  6704. #define TheSrecord(obj) ((Srecord)(ngci_pointable(obj)-varobject_bias))
  6705. #define TheXrecord(obj) ((Xrecord)(ngci_pointable(obj)-varobject_bias))
  6706. #define ThePackage(obj) ((Package)(ngci_pointable(obj)-varobject_bias))
  6707. #define TheHashtable(obj) ((Hashtable)(ngci_pointable(obj)-varobject_bias))
  6708. #define TheReadtable(obj) ((Readtable)(ngci_pointable(obj)-varobject_bias))
  6709. #define ThePathname(obj) ((Pathname)(ngci_pointable(obj)-varobject_bias))
  6710. #ifdef LOGICAL_PATHNAMES
  6711. #define TheLogpathname(obj) ((Logpathname)(ngci_pointable(obj)-varobject_bias))
  6712. #endif
  6713. #define The_Random_state(obj) ((Random_state)(ngci_pointable(obj)-varobject_bias))
  6714. #define TheByte(obj) ((Byte)(ngci_pointable(obj)-varobject_bias))
  6715. #define TheFsubr(obj) ((Fsubr)(ngci_pointable(obj)-varobject_bias))
  6716. #define TheLoadtimeeval(obj) ((Loadtimeeval)(ngci_pointable(obj)-varobject_bias))
  6717. #define TheSymbolmacro(obj) ((Symbolmacro)(ngci_pointable(obj)-varobject_bias))
  6718. #define TheGlobalSymbolmacro(obj) ((GlobalSymbolmacro)(ngci_pointable(obj)-varobject_bias))
  6719. #define TheMacro(obj) ((Macro)(ngci_pointable(obj)-varobject_bias))
  6720. #define TheFunctionMacro(obj) ((FunctionMacro)(ngci_pointable(obj)-varobject_bias))
  6721. #define TheBigReadLabel(obj) ((BigReadLabel)(ngci_pointable(obj)-varobject_bias))
  6722. #define TheEncoding(obj) ((Encoding)(ngci_pointable(obj)-varobject_bias))
  6723. #ifdef FOREIGN
  6724. #define TheFpointer(obj) ((Fpointer)(ngci_pointable(obj)-varobject_bias))
  6725. #endif
  6726. #ifdef DYNAMIC_FFI
  6727. #define TheFaddress(obj) ((Faddress)(ngci_pointable(obj)-varobject_bias))
  6728. #define TheFvariable(obj) ((Fvariable)(ngci_pointable(obj)-varobject_bias))
  6729. #define TheFfunction(obj) ((Ffunction)(ngci_pointable(obj)-varobject_bias))
  6730. #endif
  6731. #define TheWeakpointer(obj) ((Weakpointer)(ngci_pointable(obj)-varobject_bias))
  6732. #define TheMutableWeakList(obj) ((MutableWeakList)(ngci_pointable(obj)-varobject_bias))
  6733. #define TheWeakList(obj) ((WeakList)(ngci_pointable(obj)-varobject_bias))
  6734. #define TheWeakAnd(obj) ((WeakAnd)(ngci_pointable(obj)-varobject_bias))
  6735. #define TheWeakOr(obj) ((WeakOr)(ngci_pointable(obj)-varobject_bias))
  6736. #define TheWeakmapping(obj) ((Weakmapping)(ngci_pointable(obj)-varobject_bias))
  6737. #define TheWeakAndMapping(obj) ((WeakAndMapping)(ngci_pointable(obj)-varobject_bias))
  6738. #define TheWeakOrMapping(obj) ((WeakOrMapping)(ngci_pointable(obj)-varobject_bias))
  6739. #define TheMutableWeakAlist(obj) ((MutableWeakAlist)(ngci_pointable(obj)-varobject_bias))
  6740. #define TheWeakAlist(obj) ((WeakAlist)(ngci_pointable(obj)-varobject_bias))
  6741. #define TheWeakHashedAlist(obj) ((WeakHashedAlist)(ngci_pointable(obj)-varobject_bias))
  6742. #define TheFinalizer(obj) ((Finalizer)(ngci_pointable(obj)-varobject_bias))
  6743. #ifdef SOCKET_STREAMS
  6744. #define TheSocketServer(obj) ((Socket_server)(ngci_pointable(obj)-varobject_bias))
  6745. #endif
  6746. #ifdef YET_ANOTHER_RECORD
  6747. #define TheYetanother(obj) ((Yetanother)(ngci_pointable(obj)-varobject_bias))
  6748. #endif
  6749. #define TheStream(obj) ((Stream)(ngci_pointable(obj)-varobject_bias))
  6750. #define TheStructure(obj) ((Structure)(ngci_pointable(obj)-varobject_bias))
  6751. #define TheClosure(obj) ((Closure)(ngci_pointable(obj)-varobject_bias))
  6752. #define TheIclosure(obj) ((Iclosure)(ngci_pointable(obj)-varobject_bias))
  6753. #define TheCclosure(obj) ((Cclosure)(ngci_pointable(obj)-varobject_bias))
  6754. #define TheInstance(obj) ((Instance)(ngci_pointable(obj)-varobject_bias))
  6755. #define TheSubr(obj) ((Subr)(cgci_pointable(obj)-subr_bias))
  6756. #define TheFramepointer(obj) ((gcv_object_t*)(cgci_pointable(obj)-machine_bias))
  6757. #define TheMachine(obj) ((void*)(cgci_pointable(obj)-machine_bias))
  6758. #if (log2_C_CODE_ALIGNMENT >= 2)
  6759. #define TheMachineCode(obj) TheMachine(obj)
  6760. #elif defined(HPPA)
  6761. #define TheMachineCode(obj) ((void*)((uintP)TheMachine(obj)+2))
  6762. #else
  6763. #define TheMachineCode(obj) ((void*)(((uintP)TheMachine(obj)>>(2-log2_C_CODE_ALIGNMENT))|(CODE_ADDRESS_RANGE&~((~(uintP)0)>>(2-log2_C_CODE_ALIGNMENT)))))
  6764. #endif
  6765. #define ThePseudofun(obj) ((Pseudofun)TheMachineCode(obj))
  6766. #ifdef FOREIGN_HANDLE
  6767. /* pack Handle in Sbvector */
  6768. #define TheHandle(obj) (*(Handle*)(&TheSbvector(obj)->data[0]))
  6769. #else
  6770. /* pack Handle in Fixnum>=0 */
  6771. #define TheHandle(obj) ((Handle)posfixnum_to_V(obj))
  6772. #endif
  6773. /* Object of variable length: */
  6774. #define TheVarobject(obj) ((Varobject)(ngci_pointable(obj)-varobject_bias))
  6775. /* Object, represents a pointer into the memory: */
  6776. #define ThePointer(obj) ((void*)(pgci_pointable(obj) & ~(aint)nonimmediate_bias_mask))
  6777. #ifdef MULTITHREAD
  6778. #define TheThread(obj) ((Thread)(ngci_pointable(obj)-varobject_bias))
  6779. #define TheMutex(obj) ((Mutex)(ngci_pointable(obj)-varobject_bias))
  6780. #define TheExemption(obj) ((Exemption)(ngci_pointable(obj)-varobject_bias))
  6781. #endif
  6782. #endif
  6783. #define TheClassVersion(obj) ((ClassVersion)TheSvector(obj))
  6784. #define TheSlotDefinition(obj) ((SlotDefinition)TheInstance(obj))
  6785. #define TheClass(obj) ((Class)TheInstance(obj))
  6786. %% export_def(TheCons(obj));
  6787. %% #if notused
  6788. %% export_def(TheRatio(obj));
  6789. %% export_def(TheComplex(obj));
  6790. %% #endif
  6791. %% export_def(TheSymbol(obj));
  6792. %% export_def(TheBignum(obj));
  6793. %% #if notused
  6794. %% export_def(TheSarray(obj));
  6795. %% #endif
  6796. %% export_def(TheSbvector(obj));
  6797. %% #ifdef HAVE_SMALL_SSTRING
  6798. %% export_def(TheS8string(obj));
  6799. %% export_def(TheS16string(obj));
  6800. %% export_def(TheS32string(obj));
  6801. %% #endif
  6802. %% export_def(TheSstring(obj));
  6803. %% export_def(TheSvector(obj));
  6804. %% export_def(TheRecord(obj));
  6805. %% export_def(TheSrecord(obj));
  6806. %% #if notused
  6807. %% export_def(TheXrecord(obj));
  6808. %% export_def(ThePackage(obj));
  6809. %% #endif
  6810. %% export_def(TheEncoding(obj));
  6811. %% #ifdef FOREIGN
  6812. %% export_def(TheFpointer(obj));
  6813. %% #endif
  6814. %% export_def(TheStructure(obj));
  6815. %% export_def(TheClosure(obj));
  6816. %% export_def(TheInstance(obj));
  6817. %% export_def(TheSubr(obj));
  6818. %% export_def(TheMachine(obj));
  6819. %% export_def(TheMachineCode(obj));
  6820. %% export_def(ThePseudofun(obj));
  6821. /* Some acronyms
  6822. Access to objects that are conses: */
  6823. #define Car(obj) (TheCons(obj)->car)
  6824. #define Cdr(obj) (TheCons(obj)->cdr)
  6825. /* Access to objects that are symbols: */
  6826. #define Symbol_value(obj) (TheSymbol(obj)->symvalue)
  6827. #define Symbol_function(obj) (TheSymbol(obj)->symfunction)
  6828. #define Symbol_plist(obj) (TheSymbol(obj)->proplist)
  6829. #define Symbol_name(obj) (TheSymbol(obj)->pname)
  6830. #define Symbol_package(obj) (TheSymbol(obj)->homepackage)
  6831. /* Length (number of objects) of a record, obj has to be a Srecord/Xrecord: */
  6832. #define SXrecord_length(obj) \
  6833. (Record_type(obj) < rectype_limit ? Srecord_length(obj) : Xrecord_length(obj))
  6834. /* Likewise, but ignoring weak pointers: */
  6835. #define SXrecord_nonweak_length(obj) \
  6836. (Record_type(obj) < rectype_limit \
  6837. ? Srecord_length(obj) \
  6838. : ((Record_type(obj)==Rectype_Weakpointer \
  6839. || Record_type(obj)==Rectype_Weakmapping) \
  6840. ? 0 \
  6841. : Xrecord_length(obj)))
  6842. /* Length of an Lrecord, ignoring weak pointers: */
  6843. #define Lrecord_nonweak_length(obj) \
  6844. ((Record_type(obj) >= Rectype_WeakList \
  6845. && Record_type(obj) <= Rectype_WeakHashedAlist_Both) \
  6846. ? 0 \
  6847. : Lrecord_length(obj))
  6848. /* Length (number of objects) of a record, obj has to be a Record: */
  6849. #define Record_length(obj) \
  6850. (Record_type(obj) >= rectype_longlimit \
  6851. ? Lrecord_length(obj) \
  6852. : SXrecord_length(obj))
  6853. /* Likewise, but ignoring weak pointers: */
  6854. #define Record_nonweak_length(obj) \
  6855. (Record_type(obj) >= rectype_longlimit \
  6856. ? Lrecord_nonweak_length(obj) \
  6857. : SXrecord_nonweak_length(obj))
  6858. %% export_def(Car(obj));
  6859. %% export_def(Cdr(obj));
  6860. %% export_def(Symbol_value(obj));
  6861. %% export_def(Symbol_function(obj));
  6862. %% export_def(Symbol_plist(obj));
  6863. %% export_def(Symbol_name(obj));
  6864. %% export_def(Symbol_package(obj));
  6865. /* ####################### type test predicates ########################### #
  6866. There are two kinds of predicates:
  6867. 1. ???p, query with 'if': if ???p(object)
  6868. 2. if_???p, called as
  6869. if_???p(object, statement1, statement2)
  6870. instead of
  6871. if ???p(object) statement1 else statement2
  6872. UP: tests for equality of pointers EQ
  6873. eq(obj1,obj2)
  6874. > obj1,obj2: Lisp-objects
  6875. < result: true, if objects are equal */
  6876. #if defined(DEBUG_GCSAFETY)
  6877. #define eq(obj1,obj2) (pgci_pointable(obj1) == pgci_pointable(obj2))
  6878. #elif defined(WIDE_STRUCT) || defined(OBJECT_STRUCT)
  6879. #define eq(obj1,obj2) (as_oint(obj1) == as_oint(obj2))
  6880. #elif defined(WIDE_AUXI)
  6881. #define eq(obj1,obj2) ((obj1).one_o == (obj2).one_o)
  6882. #else
  6883. #define eq(obj1,obj2) ((obj1) == (obj2))
  6884. #endif
  6885. %% export_def(eq(obj1,obj2));
  6886. /* Test for NIL */
  6887. #define nullp(obj) (eq(obj,NIL))
  6888. %% export_def(nullp(obj));
  6889. /* Shorthand: Test a fixed symbol's value for NIL */
  6890. #define nullpSv(sym) ( nullp(Symbol_value(S(sym))))
  6891. /* Test for an argument's value, whether the argument was provided. */
  6892. #define boundp(obj) (!eq(obj,unbound))
  6893. %% export_def(boundp(obj));
  6894. /* Test for an argument's value, whether the argument was not provided or NIL. */
  6895. #define missingp(obj) (!boundp(obj) || nullp(obj))
  6896. %% export_def(missingp(obj));
  6897. /* Test for Cons */
  6898. #ifdef TYPECODES
  6899. #if defined(cons_bit_o)
  6900. /* define consp(obj) (as_oint(obj) & wbit(cons_bit_o)) */
  6901. #define consp(obj) (wbit_test(as_oint(obj),cons_bit_o))
  6902. #ifdef fast_mtypecode
  6903. #ifdef WIDE_STRUCT
  6904. #undef consp
  6905. #define consp(obj) (typecode(obj) & bit(cons_bit_t))
  6906. #endif
  6907. #define mconsp(obj) (mtypecode(obj) & bit(cons_bit_t))
  6908. #else
  6909. #define mconsp(obj) consp(obj)
  6910. #endif
  6911. #else
  6912. #define consp(obj) (typecode(obj) == cons_type)
  6913. #define mconsp(obj) (mtypecode(obj) == cons_type)
  6914. #endif
  6915. #else
  6916. #define consp(obj) ((as_oint(obj) & 7) == (cons_bias+conses_misaligned))
  6917. #define mconsp(obj) consp(obj)
  6918. #endif
  6919. %% export_def(consp(obj));
  6920. %% export_def(mconsp(obj));
  6921. /* Test for Atom */
  6922. #ifdef TYPECODES
  6923. #if defined(cons_bit_o)
  6924. /* define atomp(obj) ((as_oint(obj) & wbit(cons_bit_o))==0) */
  6925. #define atomp(obj) (!wbit_test(as_oint(obj),cons_bit_o))
  6926. #ifdef fast_mtypecode
  6927. #ifdef WIDE_STRUCT
  6928. #undef atomp
  6929. #define atomp(obj) ((typecode(obj) & bit(cons_bit_t))==0)
  6930. #endif
  6931. #define matomp(obj) ((mtypecode(obj) & bit(cons_bit_t))==0)
  6932. #else
  6933. #define matomp(obj) atomp(obj)
  6934. #endif
  6935. #else
  6936. #define atomp(obj) (!(typecode(obj) == cons_type))
  6937. #define matomp(obj) (!(mtypecode(obj) == cons_type))
  6938. #endif
  6939. #else
  6940. #define atomp(obj) (!consp(obj))
  6941. #define matomp(obj) atomp(obj)
  6942. #endif
  6943. %% export_def(atomp(obj));
  6944. %% export_def(matomp(obj));
  6945. /* For all type tests below this line, the argument must be side-effect-free.
  6946. Ideally a variable, but a STACK_(n) reference works as well. */
  6947. /* Test for List */
  6948. #define listp(obj) (nullp(obj) || consp(obj))
  6949. %% export_def(listp(obj));
  6950. #ifndef TYPECODES
  6951. /* Test for Object with variable length */
  6952. #define varobjectp(obj) ((as_oint(obj) & nonimmediate_heapcode_mask) == (varobject_bias+varobjects_misaligned))
  6953. #endif
  6954. %% #ifndef TYPECODES
  6955. %% export_def(varobjectp(obj));
  6956. %% #endif
  6957. /* Test for Symbol */
  6958. #ifdef TYPECODES
  6959. #if defined(symbol_bit_o)
  6960. /* define symbolp(obj) (as_oint(obj) & wbit(symbol_bit_o)) */
  6961. #define symbolp(obj) (wbit_test(as_oint(obj),symbol_bit_o))
  6962. #ifdef WIDE_STRUCT
  6963. #undef symbolp
  6964. #define symbolp(obj) (typecode(obj) & bit(symbol_bit_t))
  6965. #endif
  6966. #else
  6967. #define symbolp(obj) (typecode(obj) == symbol_type)
  6968. #endif
  6969. #else
  6970. #define symbolp(obj) \
  6971. (varobjectp(obj) && (Record_type(obj) == Rectype_Symbol))
  6972. #endif
  6973. %% export_def(symbolp(obj));
  6974. /* Test for number */
  6975. #ifdef TYPECODES
  6976. /* define numberp(obj) (as_oint(obj) & wbit(number_bit_o)) */
  6977. #define numberp(obj) (wbit_test(as_oint(obj),number_bit_o))
  6978. #ifdef WIDE_STRUCT
  6979. #undef numberp
  6980. #define numberp(obj) (typecode(obj) & bit(number_bit_t))
  6981. #endif
  6982. #else
  6983. #define immediate_number_p(obj) \
  6984. ((as_oint(obj) & ((4 << imm_type_shift) | immediate_bias)) == (fixnum_type&sfloat_type))
  6985. #define numberp(obj) \
  6986. (immediate_number_p(obj) \
  6987. || (varobjectp(obj) \
  6988. && ((uintB)(Record_type(obj)-Rectype_Bignum) <= Rectype_Complex-Rectype_Bignum)))
  6989. #endif
  6990. %% #if notused
  6991. %% #ifdef TYPECODES
  6992. %% export_def(numberp(obj));
  6993. %% #else
  6994. %% export_def(immediate_number_p(obj));
  6995. %% #endif
  6996. %% #endif
  6997. /* Test for Vector (typebytes %001,%010,%011,%101,%110,%111) */
  6998. #ifdef TYPECODES
  6999. #define vectorp(obj) \
  7000. ((tint)(typecode(obj) - sbvector_type) <= (tint)(vector_type - sbvector_type))
  7001. #else
  7002. /* cases: Rectype_Sbvector, Rectype_Sb[2|4|8|16|32]vector, Rectype_Svector, Rectype_[Imm_]S[8|16|32]string,
  7003. Rectype_bvector, Rectype_b[2|4|8|16|32]vector, Rectype_vector, Rectype_reallocstring, Rectype_string */
  7004. #define vectorp(obj) \
  7005. (varobjectp(obj) && ((uintB)(Record_type(obj) - Rectype_vector) \
  7006. <= Rectype_string - Rectype_vector))
  7007. #endif
  7008. %% export_def(vectorp(obj));
  7009. /* Test for simple-vector or simple-bit-vector or simple-string */
  7010. #ifdef TYPECODES
  7011. #define simplep(obj) \
  7012. ((tint)(typecode(obj) - sbvector_type) <= (tint)(svector_type - sbvector_type))
  7013. #else
  7014. /* cases: Rectype_Sbvector, Rectype_Sb[2|4|8|16|32]vector, Rectype_Svector, Rectype_[Imm_]S[8|16|32]string,
  7015. Rectype_reallocstring */
  7016. #define simplep(obj) \
  7017. (varobjectp(obj) && ((uintB)(Record_type(obj) - Rectype_Svector) \
  7018. <= Rectype_reallocstring - Rectype_Svector))
  7019. #endif
  7020. /* Tests an Array for simple-vector or simple-bit-vector or simple-string */
  7021. #ifdef TYPECODES
  7022. #define array_simplep(obj) \
  7023. ((typecode(obj) & bit(notsimple_bit_t)) == 0)
  7024. #else
  7025. /* cases: Rectype_Sbvector, Rectype_Sb[2|4|8|16|32]vector, Rectype_Svector, Rectype_[Imm_]S[8|16|32]string,
  7026. Rectype_reallocstring */
  7027. #define array_simplep(obj) \
  7028. ((uintB)(Record_type(obj) - Rectype_Svector) \
  7029. <= Rectype_reallocstring - Rectype_Svector)
  7030. #endif
  7031. /* Test for simple-vector */
  7032. #ifdef TYPECODES
  7033. #define simple_vector_p(obj) \
  7034. (typecode(obj) == svector_type)
  7035. #else
  7036. /* cases: Rectype_Svector */
  7037. #define simple_vector_p(obj) \
  7038. (varobjectp(obj) && (Record_type(obj) == Rectype_Svector))
  7039. #endif
  7040. %% export_def(simple_vector_p(obj));
  7041. /* Test for general-vector=(vector t) */
  7042. #ifdef TYPECODES
  7043. #define general_vector_p(obj) \
  7044. ((typecode(obj) & ~bit(notsimple_bit_t)) == svector_type)
  7045. #else
  7046. /* cases: Rectype_Svector, Rectype_vector */
  7047. #define general_vector_p(obj) \
  7048. (varobjectp(obj) \
  7049. && ((Record_type(obj) & ~(Rectype_Svector ^ Rectype_vector)) == (Rectype_Svector & Rectype_vector)) \
  7050. )
  7051. #endif
  7052. %% export_def(general_vector_p(obj));
  7053. /* Test for simple-string */
  7054. #ifdef TYPECODES
  7055. #define simple_string_p(obj) \
  7056. (typecode(obj) == sstring_type)
  7057. #else
  7058. /* cases: Rectype_[Imm_]S[8|16|32]string, Rectype_reallocstring */
  7059. #define simple_string_p(obj) \
  7060. (varobjectp(obj) && ((uintB)(Record_type(obj) - Rectype_S8string) \
  7061. <= Rectype_reallocstring - Rectype_S8string))
  7062. #endif
  7063. %% export_def(simple_string_p(obj));
  7064. /* Test for string */
  7065. #ifdef TYPECODES
  7066. #define stringp(obj) \
  7067. ((typecode(obj) & ~bit(notsimple_bit_t)) == sstring_type)
  7068. #else
  7069. /* cases: Rectype_[Imm_]S[8|16|32]string, Rectype_reallocstring, Rectype_string */
  7070. #define stringp(obj) \
  7071. (varobjectp(obj) && ((uintB)(Record_type(obj) - Rectype_S8string) \
  7072. <= Rectype_string - Rectype_S8string))
  7073. #endif
  7074. %% export_def(stringp(obj));
  7075. /* test for (VECTOR NIL) */
  7076. #ifdef TYPECODES
  7077. #define nil_vector_p(obj) \
  7078. (typecode(obj) == vector_type \
  7079. && (Iarray_flags(obj) & arrayflags_atype_mask) == Atype_NIL \
  7080. )
  7081. #else
  7082. /* cases: Rectype_Svector, Rectype_vector */
  7083. #define nil_vector_p(obj) \
  7084. (varobjectp(obj) \
  7085. && (Record_type(obj) == Rectype_vector \
  7086. && (Iarray_flags(obj) & arrayflags_atype_mask) == Atype_NIL \
  7087. ) )
  7088. #endif
  7089. /* Test for simple-bit[n]-vector */
  7090. #ifdef TYPECODES
  7091. #define simple_bit_vector_p(atype,obj) \
  7092. (typecode(obj) == Array_type_simple_bit_vector(atype))
  7093. #else
  7094. /* cases: Rectype_Sb[2^n]vector */
  7095. #define simple_bit_vector_p(atype,obj) \
  7096. (varobjectp(obj) && (Record_type(obj) == Rectype_Sbvector+(atype)))
  7097. #endif
  7098. %% export_def(simple_bit_vector_p(atype,obj));
  7099. /* Test for bit[n]-vector */
  7100. #ifdef TYPECODES
  7101. #define bit_vector_p(atype,obj) \
  7102. ((typecode(obj) & ~bit(notsimple_bit_t)) == Array_type_simple_bit_vector(atype))
  7103. #else
  7104. /* cases: Rectype_Sb[2^n]vector, Rectype_b[2^n]vector */
  7105. #define bit_vector_p(atype,obj) \
  7106. (varobjectp(obj) \
  7107. && ((Record_type(obj) & ~(Rectype_Sbvector ^ Rectype_bvector)) == (Rectype_Sbvector & Rectype_bvector) + (atype)) \
  7108. )
  7109. #endif
  7110. %% export_def(bit_vector_p(atype,obj));
  7111. /* Test for Array (general) */
  7112. #ifdef TYPECODES
  7113. #define arrayp(obj) \
  7114. ((tint)(typecode(obj) - mdarray_type) <= (tint)(vector_type - mdarray_type))
  7115. #else
  7116. /* cases: Rectype_Sbvector, Rectype_Sb[2|4|8|16|32]vector, Rectype_Svector, Rectype_[Imm_]S[8|16|32]string,
  7117. Rectype_bvector, Rectype_b[2|4|8|16|32]vector, Rectype_vector, Rectype_reallocstring, Rectype_string,
  7118. Rectype_mdarray */
  7119. #define arrayp(obj) \
  7120. (varobjectp(obj) && ((uintB)(Record_type(obj) - Rectype_vector) \
  7121. <= Rectype_mdarray - Rectype_vector))
  7122. #endif
  7123. %% export_def(arrayp(obj));
  7124. /* Test for Array, that isn't a Vector (type byte %100) */
  7125. #ifdef TYPECODES
  7126. #define mdarrayp(obj) \
  7127. (typecode(obj) == mdarray_type)
  7128. #else
  7129. /* cases: Rectype_mdarray */
  7130. #define mdarrayp(obj) \
  7131. (varobjectp(obj) && (Record_type(obj) == Rectype_mdarray))
  7132. #endif
  7133. #ifdef TYPECODES
  7134. /* Test for Closure/Structure/Stream/Instance/OtherRecord/LongRecord */
  7135. #define if_recordp(obj,statement1,statement2) \
  7136. switch (typecode(obj)) { \
  7137. case_record: statement1; break; \
  7138. default: statement2; break; \
  7139. }
  7140. #else
  7141. /* Test for Lrecord/Srecord/Xrecord */
  7142. #define if_recordp(obj,statement1,statement2) \
  7143. if (orecordp(obj)) \
  7144. switch (Record_type(obj)) { \
  7145. case Rectype_Sbvector: \
  7146. case Rectype_S8string: case Rectype_Imm_S8string: \
  7147. case Rectype_S16string: case Rectype_Imm_S16string: \
  7148. case Rectype_S32string: case Rectype_Imm_S32string: \
  7149. case Rectype_Svector: \
  7150. case Rectype_mdarray: \
  7151. case Rectype_bvector: case Rectype_string: case Rectype_vector: \
  7152. case Rectype_reallocstring: \
  7153. case Rectype_Bignum: case Rectype_Lfloat: \
  7154. goto not_record; \
  7155. default: { statement1 } break; \
  7156. } \
  7157. else \
  7158. not_record: { statement2 }
  7159. #endif
  7160. /* Test for Closure */
  7161. #ifdef TYPECODES
  7162. #define closurep(obj) (typecode(obj)==closure_type)
  7163. #else
  7164. #define closurep(obj) \
  7165. (varobjectp(obj) && (Record_type(obj) == Rectype_Closure))
  7166. #endif
  7167. /* Test for compiled Closure
  7168. The second component of a closure is either a list
  7169. (the Lambdabody for interpreted Closures)
  7170. or a Simple-Bit-Vector (the code vector for compiled Closures). */
  7171. #define cclosurep(obj) \
  7172. (closurep(obj) \
  7173. && simple_bit_vector_p(Atype_8Bit,TheClosure(obj)->clos_codevec))
  7174. /* Test for a function with a code vector produced by %GENERIC-FUNCTION-LAMBDA. */
  7175. #define genericlambda_function_p(obj) \
  7176. (cclosurep(obj) \
  7177. && (TheCodevec(TheClosure(obj)->clos_codevec)->ccv_flags & bit(4)))
  7178. /* Test for CLOS-Instance */
  7179. #ifdef TYPECODES
  7180. #define instancep(obj) \
  7181. (typecode(obj)==instance_type \
  7182. || (typecode(obj)==closure_type && Closure_instancep(obj)))
  7183. #else
  7184. #define instancep(obj) \
  7185. (varobjectp(obj) \
  7186. && (Record_type(obj) == Rectype_Instance \
  7187. || (Record_type(obj) == Rectype_Closure && Closure_instancep(obj))))
  7188. #endif
  7189. /* Test for non-funcallable CLOS-Instance */
  7190. #ifdef TYPECODES
  7191. #define regular_instance_p(obj) (typecode(obj)==instance_type)
  7192. #else
  7193. #define regular_instance_p(obj) \
  7194. (varobjectp(obj) && (Record_type(obj) == Rectype_Instance))
  7195. #endif
  7196. /* Test for funcallable CLOS-Instance */
  7197. #define funcallable_instance_p(obj) \
  7198. (closurep(obj) && Closure_instancep(obj))
  7199. %% export_def(instancep(obj));
  7200. /* Test for CLOS-class or forward-reference.
  7201. Our CLOS implements all classes as instances of a
  7202. (not necessarily direct) subclass of <class>. */
  7203. #define if_potential_class_p(obj,statement1,statement2) \
  7204. if (instancep(obj)) { \
  7205. { \
  7206. var object obj_forwarded = obj; \
  7207. instance_un_realloc(obj_forwarded); \
  7208. /*instance_update(obj,obj_forwarded); - not needed since we don't access a slot */ \
  7209. {var object cv = TheInstance(obj_forwarded)->inst_class_version; \
  7210. /* Treat the most frequent cases first, for speed. */ \
  7211. if (eq(cv,O(class_version_standard_class))) /* direct instance of STANDARD-CLASS? */\
  7212. goto obj##_classp_yes; \
  7213. if (eq(cv,O(class_version_structure_class))) /* direct instance of STRUCTURE-CLASS? */\
  7214. goto obj##_classp_yes; \
  7215. if (eq(cv,O(class_version_built_in_class))) /* direct instance of BUILT-IN-CLASS? */\
  7216. goto obj##_classp_yes; \
  7217. /* Now a slow, but general instanceof test. */ \
  7218. {var object objclas = TheClassVersion(cv)->cv_newest_class; \
  7219. if (eq(gethash(O(class_potential_class),TheClass(objclas)->all_superclasses,false),nullobj)) \
  7220. goto obj##_classp_no; \
  7221. }}} \
  7222. obj##_classp_yes: statement1; \
  7223. } else { \
  7224. obj##_classp_no: statement2; \
  7225. }
  7226. /* Test for CLOS-class.
  7227. Our CLOS implements all classes as instances of a
  7228. (not necessarily direct) subclass of <defined-class>. */
  7229. #define if_defined_class_p(obj,statement1,statement2) \
  7230. if (instancep(obj)) { \
  7231. { \
  7232. var object obj_forwarded = obj; \
  7233. instance_un_realloc(obj_forwarded); \
  7234. /*instance_update(obj,obj_forwarded); - not needed since we don't access a slot */ \
  7235. {var object cv = TheInstance(obj_forwarded)->inst_class_version; \
  7236. /* Treat the most frequent cases first, for speed. */ \
  7237. if (eq(cv,O(class_version_standard_class))) /* direct instance of STANDARD-CLASS? */\
  7238. goto obj##_classp_yes; \
  7239. if (eq(cv,O(class_version_structure_class))) /* direct instance of STRUCTURE-CLASS? */\
  7240. goto obj##_classp_yes; \
  7241. if (eq(cv,O(class_version_built_in_class))) /* direct instance of BUILT-IN-CLASS? */\
  7242. goto obj##_classp_yes; \
  7243. /* Now a slow, but general instanceof test. */ \
  7244. {var object objclas = TheClassVersion(cv)->cv_newest_class; \
  7245. if (eq(gethash(O(class_defined_class),TheClass(objclas)->all_superclasses,false),nullobj)) \
  7246. goto obj##_classp_no; \
  7247. }}} \
  7248. obj##_classp_yes: statement1; \
  7249. } else { \
  7250. obj##_classp_no: statement2; \
  7251. }
  7252. /* Test for Other-Record
  7253. This is not really a type test (because there is no well-defined type
  7254. Other-Record). It's just a precondition for calling Record_type(obj). */
  7255. #ifdef TYPECODES
  7256. #define orecordp(obj) (typecode(obj)==orecord_type)
  7257. #else
  7258. #define orecordp(obj) varobjectp(obj)
  7259. #endif
  7260. %% export_def(orecordp(obj));
  7261. /* Test for Long-Record
  7262. This is not really a type test (because there is no well-defined type
  7263. Long-Record). It's just a precondition for calling Record_type(obj). */
  7264. #ifdef TYPECODES
  7265. #define lrecordp(obj) (typecode(obj)==lrecord_type)
  7266. #else
  7267. #define lrecordp(obj) varobjectp(obj)
  7268. #endif
  7269. /* Test for Structure */
  7270. #ifdef case_structure
  7271. #define structurep(obj) (typecode(obj)==structure_type)
  7272. #else
  7273. #define structurep(obj) \
  7274. (orecordp(obj) && (Record_type(obj) == Rectype_Structure))
  7275. #endif
  7276. %% export_def(structurep(obj));
  7277. /* Test for Builtin-Stream */
  7278. #ifdef case_stream
  7279. #define builtin_stream_p(obj) (typecode(obj)==stream_type)
  7280. #else
  7281. #define builtin_stream_p(obj) \
  7282. (orecordp(obj) && (Record_type(obj) == Rectype_Stream))
  7283. #endif
  7284. %% export_def(builtin_stream_p(obj));
  7285. /* Test for Stream */
  7286. #define streamp(obj) \
  7287. (builtin_stream_p(obj) || instanceof(obj,O(class_fundamental_stream)))
  7288. /* Test for Package */
  7289. #define packagep(obj) \
  7290. (orecordp(obj) && (Record_type(obj) == Rectype_Package))
  7291. %% #if notused
  7292. %% export_def(packagep(obj));
  7293. %% #endif
  7294. /* Test for Hash-Table */
  7295. #define hash_table_p(obj) \
  7296. (orecordp(obj) && (Record_type(obj) == Rectype_Hashtable))
  7297. /* Test for Readtable */
  7298. #define readtablep(obj) \
  7299. (orecordp(obj) && (Record_type(obj) == Rectype_Readtable))
  7300. /* Test for Pathname */
  7301. #define pathnamep(obj) \
  7302. (orecordp(obj) && (Record_type(obj) == Rectype_Pathname))
  7303. /* Test for Logical Pathname */
  7304. #ifdef LOGICAL_PATHNAMES
  7305. #define logpathnamep(obj) \
  7306. (orecordp(obj) && (Record_type(obj) == Rectype_Logpathname))
  7307. #else
  7308. #define logpathnamep(obj) false
  7309. #endif
  7310. /* Test for Extended Pathname (i.e., Pathname or Logical Pathname)
  7311. define xpathnamep(obj) (pathnamep(obj) || logpathnamep(obj)) */
  7312. #ifdef LOGICAL_PATHNAMES
  7313. #define xpathnamep(obj) \
  7314. (orecordp(obj) \
  7315. && ((Record_type(obj) == Rectype_Pathname) \
  7316. || (Record_type(obj) == Rectype_Logpathname)))
  7317. #else
  7318. #define xpathnamep(obj) pathnamep(obj)
  7319. #endif
  7320. /* Test for Random-State */
  7321. #define random_state_p(obj) \
  7322. (orecordp(obj) && (Record_type(obj) == Rectype_Random_State))
  7323. /* Test for Byte */
  7324. #define bytep(obj) \
  7325. (orecordp(obj) && (Record_type(obj) == Rectype_Byte))
  7326. /* Test for Fsubr */
  7327. #define fsubrp(obj) \
  7328. (orecordp(obj) && (Record_type(obj) == Rectype_Fsubr))
  7329. /* Test for Loadtimeeval */
  7330. #define loadtimeevalp(obj) \
  7331. (orecordp(obj) && (Record_type(obj) == Rectype_Loadtimeeval))
  7332. /* Test for Symbolmacro */
  7333. #define symbolmacrop(obj) \
  7334. (orecordp(obj) && (Record_type(obj) == Rectype_Symbolmacro))
  7335. /* Test for GlobalSymbolmacro */
  7336. #define globalsymbolmacrop(obj) \
  7337. (orecordp(obj) && (Record_type(obj) == Rectype_GlobalSymbolmacro))
  7338. /* Test for Macro */
  7339. #define macrop(obj) \
  7340. (orecordp(obj) && (Record_type(obj) == Rectype_Macro))
  7341. /* Test for FunctionMacro */
  7342. #define functionmacrop(obj) \
  7343. (orecordp(obj) && (Record_type(obj) == Rectype_FunctionMacro))
  7344. /* Test for BigReadLabel */
  7345. #define big_read_label_p(obj) \
  7346. (orecordp(obj) && (Record_type(obj) == Rectype_BigReadLabel))
  7347. /* Test for Encoding */
  7348. #define encodingp(obj) \
  7349. (orecordp(obj) && (Record_type(obj) == Rectype_Encoding))
  7350. /* Test for Fpointer */
  7351. #define fpointerp(obj) \
  7352. (orecordp(obj) && (Record_type(obj) == Rectype_Fpointer))
  7353. %% #ifdef FOREIGN
  7354. %% export_def(fpointerp(obj));
  7355. %% #endif
  7356. /* Test for Faddress */
  7357. #define faddressp(obj) \
  7358. (orecordp(obj) && (Record_type(obj) == Rectype_Faddress))
  7359. /* Test for Fvariable */
  7360. #define fvariablep(obj) \
  7361. (orecordp(obj) && (Record_type(obj) == Rectype_Fvariable))
  7362. /* Test for Ffunction */
  7363. #ifdef DYNAMIC_FFI
  7364. #define ffunctionp(obj) \
  7365. (orecordp(obj) && (Record_type(obj) == Rectype_Ffunction))
  7366. #else
  7367. #define ffunctionp(obj) ((void)(obj), 0)
  7368. #endif
  7369. /* Test for Function */
  7370. #define functionp(obj) (subrp(obj) || closurep(obj) || ffunctionp(obj))
  7371. /* Test for Weakpointer */
  7372. #define weakpointerp(obj) \
  7373. (orecordp(obj) && (Record_type(obj) == Rectype_Weakpointer))
  7374. /* test for socket-server and for socket-stream */
  7375. #ifdef SOCKET_STREAMS
  7376. #define socket_server_p(obj) \
  7377. (orecordp(obj) && (Record_type(obj) == Rectype_Socket_Server))
  7378. #define socket_stream_p(obj) \
  7379. (builtin_stream_p(obj) && (TheStream(obj)->strmtype==strmtype_socket))
  7380. #endif
  7381. #ifdef YET_ANOTHER_RECORD
  7382. /* Test for Yetanother */
  7383. #define yetanotherp(obj) \
  7384. (orecordp(obj) && (Record_type(obj) == Rectype_Yetanother))
  7385. #endif
  7386. /* Test for Character */
  7387. #ifdef TYPECODES
  7388. #define charp(obj) (typecode(obj)==char_type)
  7389. #else
  7390. #define charp(obj) ((as_oint(obj) & ((7 << imm_type_shift) | immediate_bias)) == char_type)
  7391. #endif
  7392. %% export_def(charp(obj));
  7393. #if (base_char_code_limit < char_code_limit)
  7394. /* Test for base character */
  7395. #define base_char_p(obj) \
  7396. ((as_oint(obj) & ~((oint)(bit(base_char_int_len)-1)<<oint_data_shift)) == type_zero_oint(char_type))
  7397. #endif
  7398. /* Test for SUBR (compiled functional object) */
  7399. #ifdef TYPECODES
  7400. #define subrp(obj) (typecode(obj)==subr_type)
  7401. #else
  7402. #ifdef STANDARD_HEAPCODES
  7403. #define subrp(obj) ((as_oint(obj) & 3) == subr_bias)
  7404. #define immsubrp(obj) subrp(obj)
  7405. #endif
  7406. #ifdef LINUX_NOEXEC_HEAPCODES
  7407. #define subrp(obj) (orecordp(obj) && (Record_type(obj) == Rectype_Subr))
  7408. #define immsubrp(obj) false
  7409. #ifdef DEBUG_GCSAFETY
  7410. /* This is used by pgci_pointable, so it cannot use pgci_pointable itself. */
  7411. static inline bool nonimmsubrp (object obj) {
  7412. return (varobjectp(obj)
  7413. && (inside_gc /* Avoid doing memory accesses during GC. */
  7414. || (varobject_type((Record)(cgci_pointable(obj)-varobject_bias)) == Rectype_Subr)));
  7415. }
  7416. #endif
  7417. #endif
  7418. #endif
  7419. %% #ifndef TYPECODES
  7420. %% #ifdef LINUX_NOEXEC_HEAPCODES
  7421. %% #ifdef DEBUG_GCSAFETY
  7422. %% printf2("static inline bool nonimmsubrp (object obj) { return (varobjectp(obj) && (varobject_type((Record)(cgci_pointable(obj)-%d)) == %d)); }\n",varobject_bias,Rectype_Subr);
  7423. %% #endif
  7424. %% #endif
  7425. %% #endif
  7426. /* Test for pointer into the STACK (usually at a frame) */
  7427. #ifdef TYPECODES
  7428. #define framepointerp(obj) (typecode(obj)==system_type) /* other cases?? */
  7429. #else
  7430. #define framepointerp(obj) ((as_oint(obj) & 3) == machine_bias) /* other cases?? */
  7431. #endif
  7432. #ifndef TYPECODES
  7433. /* Test for Machine-Pointer */
  7434. #ifdef STANDARD_HEAPCODES
  7435. #define machinep(obj) ((as_oint(obj) & 3) == machine_bias)
  7436. #endif
  7437. #ifdef LINUX_NOEXEC_HEAPCODES
  7438. #define machinep(obj) \
  7439. ((as_oint(obj) & 3) == machine_bias \
  7440. && (as_oint(obj) & 0xE0000000) != 0xC0000000)
  7441. #endif
  7442. /* Test for Small-Read-Label */
  7443. #define small_read_label_p(obj) ((as_oint(obj) & ((7 << imm_type_shift) | immediate_bias)) == small_read_label_type)
  7444. /* Test for System-Pointer */
  7445. #define systemp(obj) ((as_oint(obj) & ((7 << imm_type_shift) | immediate_bias)) == system_type)
  7446. #endif
  7447. /* Test for real number */
  7448. #ifdef TYPECODES
  7449. #define if_realp(obj,statement1,statement2) \
  7450. do { \
  7451. var object obj_from_if_realp = (obj); \
  7452. var tint type_from_if_realp = typecode(obj_from_if_realp); \
  7453. if ( (type_from_if_realp & bit(number_bit_t)) \
  7454. && !(type_from_if_realp==complex_type) ) \
  7455. { statement1 } else { statement2 } \
  7456. } while(0)
  7457. #else
  7458. #define if_realp(obj,statement1,statement2) \
  7459. do { if (((as_oint(obj) & ((4 << imm_type_shift) | immediate_bias)) \
  7460. == fixnum_type) \
  7461. || (varobjectp(obj) \
  7462. && ((uintB)(Record_type(obj)-Rectype_Bignum) <= \
  7463. Rectype_Ratio-Rectype_Bignum))) \
  7464. { statement1 } else { statement2 } \
  7465. } while(0)
  7466. #endif
  7467. /* Test for rational number */
  7468. #ifdef TYPECODES
  7469. #define if_rationalp(obj,statement1,statement2) \
  7470. do { \
  7471. var object obj_from_if_rationalp = (obj); \
  7472. var tint type_from_if_rationalp = typecode(obj_from_if_rationalp); \
  7473. if ((type_from_if_rationalp != complex_type) \
  7474. && ((type_from_if_rationalp & \
  7475. ~((fixnum_type|bignum_type|ratio_type|bit(sign_bit_t)) \
  7476. & ~(fixnum_type&bignum_type&ratio_type))) \
  7477. == (fixnum_type&bignum_type&ratio_type))) \
  7478. { statement1 } else { statement2 } \
  7479. } while(0)
  7480. #else
  7481. #define if_rationalp(obj,statement1,statement2) \
  7482. do { if (((as_oint(obj) & ((6 << imm_type_shift) | immediate_bias)) \
  7483. == fixnum_type) \
  7484. || (varobjectp(obj) \
  7485. && ((Record_type(obj) == Rectype_Bignum) \
  7486. || (Record_type(obj) == Rectype_Ratio)))) \
  7487. { statement1 } else { statement2 } \
  7488. } while(0)
  7489. #endif
  7490. /* Test for Integer */
  7491. #ifdef TYPECODES
  7492. #define integerp(obj) \
  7493. ((typecode(obj) & \
  7494. ~((fixnum_type|bignum_type|bit(sign_bit_t)) & ~(fixnum_type&bignum_type)) \
  7495. ) == (fixnum_type&bignum_type))
  7496. #else
  7497. #define integerp(obj) \
  7498. (((as_oint(obj) & ((6 << imm_type_shift) | immediate_bias)) == fixnum_type) \
  7499. || (varobjectp(obj) && (Record_type(obj) == Rectype_Bignum)))
  7500. #endif
  7501. %% export_def(integerp(obj));
  7502. /* Test for Fixnum */
  7503. #ifdef TYPECODES
  7504. #define fixnump(obj) ((typecode(obj) & ~bit(sign_bit_t)) == fixnum_type)
  7505. #else
  7506. #define fixnump(obj) ((as_oint(obj) & ((6 << imm_type_shift) | immediate_bias)) == fixnum_type)
  7507. #endif
  7508. %% export_def(fixnump(obj));
  7509. /* Test for Fixnum >=0 */
  7510. #ifdef TYPECODES
  7511. #define posfixnump(obj) (typecode(obj) == fixnum_type)
  7512. #else
  7513. #define posfixnump(obj) ((as_oint(obj) & ((7 << imm_type_shift) | immediate_bias)) == fixnum_type)
  7514. #endif
  7515. %% export_def(posfixnump(obj));
  7516. /* Test for Bignum */
  7517. #ifdef TYPECODES
  7518. #define bignump(obj) ((typecode(obj) & ~bit(sign_bit_t)) == bignum_type)
  7519. #else
  7520. #define bignump(obj) \
  7521. (varobjectp(obj) && (Record_type(obj) == Rectype_Bignum))
  7522. #endif
  7523. %% export_def(bignump(obj));
  7524. /* Test for Bignum >=0 */
  7525. #ifdef TYPECODES
  7526. #define posbignump(obj) (typecode(obj) == bignum_type)
  7527. #else
  7528. #define posbignump(obj) \
  7529. (varobjectp(obj) \
  7530. && (Record_type(obj) == Rectype_Bignum) \
  7531. && ((Record_flags(obj) & bit(7)) == 0))
  7532. #endif
  7533. %% export_def(posbignump(obj));
  7534. /* Test for Ratio */
  7535. #ifdef TYPECODES
  7536. #define ratiop(obj) ((typecode(obj) & ~bit(sign_bit_t)) == ratio_type)
  7537. #else
  7538. #define ratiop(obj) (varobjectp(obj) && (Record_type(obj) == Rectype_Ratio))
  7539. #endif
  7540. %% #if notused
  7541. %% export_def(ratiop(obj));
  7542. %% #endif
  7543. /* Test for Float */
  7544. #ifdef TYPECODES
  7545. #define floatp(obj) \
  7546. ((typecode(obj) & \
  7547. ~((sfloat_type|ffloat_type|dfloat_type|lfloat_type|bit(sign_bit_t)) & ~(sfloat_type&ffloat_type&dfloat_type&lfloat_type)) \
  7548. ) == (sfloat_type&ffloat_type&dfloat_type&lfloat_type))
  7549. #else
  7550. #define floatp(obj) \
  7551. (((as_oint(obj) & ((6 << imm_type_shift) | immediate_bias)) == sfloat_type) \
  7552. || (varobjectp(obj) \
  7553. && ((uintB)(Record_type(obj)-Rectype_Lfloat) <= Rectype_Ffloat-Rectype_Lfloat)))
  7554. #endif
  7555. %% #if notused
  7556. %% export_def(floatp(obj));
  7557. %% #endif
  7558. /* Test for Short-Float */
  7559. #ifdef TYPECODES
  7560. #define short_float_p(obj) ((typecode(obj) & ~bit(sign_bit_t)) == sfloat_type)
  7561. #else
  7562. #define short_float_p(obj) ((as_oint(obj) & ((6 << imm_type_shift) | immediate_bias)) == sfloat_type)
  7563. #endif
  7564. %% #if notused
  7565. %% export_def(short_float_p(obj));
  7566. %% #endif
  7567. /* Test for Single-Float */
  7568. #ifdef TYPECODES
  7569. #define single_float_p(obj) ((typecode(obj) & ~bit(sign_bit_t)) == ffloat_type)
  7570. #else
  7571. #define single_float_p(obj) (varobjectp(obj) && (Record_type(obj) == Rectype_Ffloat))
  7572. #endif
  7573. %% export_def(single_float_p(obj));
  7574. /* Test for Double-Float */
  7575. #ifdef TYPECODES
  7576. #define double_float_p(obj) ((typecode(obj) & ~bit(sign_bit_t)) == dfloat_type)
  7577. #else
  7578. #define double_float_p(obj) (varobjectp(obj) && (Record_type(obj) == Rectype_Dfloat))
  7579. #endif
  7580. %% export_def(double_float_p(obj));
  7581. /* Test for Long-Float */
  7582. #ifdef TYPECODES
  7583. #define long_float_p(obj) ((typecode(obj) & ~bit(sign_bit_t)) == lfloat_type)
  7584. #else
  7585. #define long_float_p(obj) (varobjectp(obj) && (Record_type(obj) == Rectype_Lfloat))
  7586. #endif
  7587. %% #if notused
  7588. %% export_def(long_float_p(obj));
  7589. %% #endif
  7590. /* Test for Complex */
  7591. #ifdef TYPECODES
  7592. #define complexp(obj) (typecode(obj) == complex_type)
  7593. #else
  7594. #define complexp(obj) (varobjectp(obj) && (Record_type(obj) == Rectype_Complex))
  7595. #endif
  7596. %% #if notused
  7597. %% export_def(complexp(obj));
  7598. %% #endif
  7599. /* Test if a real number is >=0: */
  7600. #ifdef TYPECODES
  7601. /* define positivep(obj) ((as_oint(obj) & wbit(sign_bit_o)) == 0) */
  7602. #define positivep(obj) (!wbit_test(as_oint(obj),sign_bit_o))
  7603. #ifdef WIDE_STRUCT
  7604. #undef positivep
  7605. #define positivep(obj) ((typecode(obj) & bit(sign_bit_t)) == 0)
  7606. #endif
  7607. #else
  7608. #define positivep(obj) \
  7609. (number_immediatep(obj) \
  7610. ? /* fixnum, sfloat */ (as_oint(obj) & wbit(sign_bit_o)) == 0 \
  7611. : /* bignum, [fdl]float */ (Record_flags(obj) & bit(7)) == 0)
  7612. #endif
  7613. %% export_def(positivep(obj));
  7614. /* switch with typcodes:
  7615. example:
  7616. switch (typecode(obj)) {
  7617. case_symbol: ....
  7618. case_orecord:
  7619. switch (Record_type(obj)) {
  7620. case_Rectype_Symbol_above;
  7621. ...
  7622. }
  7623. } */
  7624. #ifdef case_structure
  7625. #define case_Rectype_Structure_above
  7626. #else
  7627. #define case_Rectype_Structure_above \
  7628. case Rectype_Structure: goto case_structure;
  7629. #endif
  7630. #ifdef case_stream
  7631. #define case_Rectype_Stream_above
  7632. #else
  7633. #define case_Rectype_Stream_above \
  7634. case Rectype_Stream: goto case_stream;
  7635. #endif
  7636. #ifdef TYPECODES
  7637. #define case_Rectype_Closure_above
  7638. #define case_Rectype_Instance_above
  7639. #define case_Rectype_Sbvector_above
  7640. #define case_Rectype_Sb2vector_above
  7641. #define case_Rectype_Sb4vector_above
  7642. #define case_Rectype_Sb8vector_above
  7643. #define case_Rectype_Sb16vector_above
  7644. #define case_Rectype_Sb32vector_above
  7645. #define case_Rectype_Sstring_above
  7646. #define case_Rectype_Svector_above
  7647. #define case_Rectype_mdarray_above
  7648. #define case_Rectype_obvector_above
  7649. #define case_Rectype_ob2vector_above
  7650. #define case_Rectype_ob4vector_above
  7651. #define case_Rectype_ob8vector_above
  7652. #define case_Rectype_ob16vector_above
  7653. #define case_Rectype_ob32vector_above
  7654. #define case_Rectype_ostring_above
  7655. #define case_Rectype_ovector_above
  7656. #define case_Rectype_Bignum_above
  7657. #define case_Rectype_Lfloat_above
  7658. #define case_Rectype_Dfloat_above
  7659. #define case_Rectype_Ffloat_above
  7660. #define case_Rectype_Ratio_above
  7661. #define case_Rectype_Complex_above
  7662. #define case_Rectype_Symbol_above
  7663. /* Composite cases: */
  7664. #define case_Rectype_string_above
  7665. #define case_Rectype_bvector_above
  7666. #define case_Rectype_b2vector_above
  7667. #define case_Rectype_b4vector_above
  7668. #define case_Rectype_b8vector_above
  7669. #define case_Rectype_b16vector_above
  7670. #define case_Rectype_b32vector_above
  7671. #define case_Rectype_vector_above
  7672. #define case_Rectype_array_above
  7673. #define case_Rectype_number_above
  7674. #define case_Rectype_float_above
  7675. #define case_Rectype_integer_above
  7676. #else
  7677. #define case_Rectype_Closure_above \
  7678. case Rectype_Closure: goto case_closure;
  7679. #define case_Rectype_Instance_above \
  7680. case Rectype_Instance: goto case_instance;
  7681. #define case_Rectype_Sbvector_above \
  7682. case Rectype_Sbvector: goto case_sbvector;
  7683. #define case_Rectype_Sb2vector_above \
  7684. case Rectype_Sb2vector: goto case_sb2vector;
  7685. #define case_Rectype_Sb4vector_above \
  7686. case Rectype_Sb4vector: goto case_sb4vector;
  7687. #define case_Rectype_Sb8vector_above \
  7688. case Rectype_Sb8vector: goto case_sb8vector;
  7689. #define case_Rectype_Sb16vector_above \
  7690. case Rectype_Sb16vector: goto case_sb16vector;
  7691. #define case_Rectype_Sb32vector_above \
  7692. case Rectype_Sb32vector: goto case_sb32vector;
  7693. #define case_Rectype_Sstring_above \
  7694. case Rectype_S8string: case Rectype_Imm_S8string: case Rectype_S16string: case Rectype_Imm_S16string: case Rectype_S32string: case Rectype_Imm_S32string: case Rectype_reallocstring: goto case_sstring;
  7695. #define case_Rectype_Svector_above \
  7696. case Rectype_Svector: goto case_svector;
  7697. #define case_Rectype_mdarray_above \
  7698. case Rectype_mdarray: goto case_mdarray;
  7699. #define case_Rectype_obvector_above \
  7700. case Rectype_bvector: goto case_obvector;
  7701. #define case_Rectype_ob2vector_above \
  7702. case Rectype_b2vector: goto case_ob2vector;
  7703. #define case_Rectype_ob4vector_above \
  7704. case Rectype_b4vector: goto case_ob4vector;
  7705. #define case_Rectype_ob8vector_above \
  7706. case Rectype_b8vector: goto case_ob8vector;
  7707. #define case_Rectype_ob16vector_above \
  7708. case Rectype_b16vector: goto case_ob16vector;
  7709. #define case_Rectype_ob32vector_above \
  7710. case Rectype_b32vector: goto case_ob32vector;
  7711. #define case_Rectype_ostring_above \
  7712. case Rectype_string: goto case_ostring;
  7713. #define case_Rectype_ovector_above \
  7714. case Rectype_vector: goto case_ovector;
  7715. #define case_Rectype_Bignum_above \
  7716. case Rectype_Bignum: goto case_bignum;
  7717. #define case_Rectype_Lfloat_above \
  7718. case Rectype_Lfloat: goto case_lfloat;
  7719. #define case_Rectype_Dfloat_above \
  7720. case Rectype_Dfloat: goto case_dfloat;
  7721. #define case_Rectype_Ffloat_above \
  7722. case Rectype_Ffloat: goto case_ffloat;
  7723. #define case_Rectype_Ratio_above \
  7724. case Rectype_Ratio: goto case_ratio;
  7725. #define case_Rectype_Complex_above \
  7726. case Rectype_Complex: goto case_complex;
  7727. #define case_Rectype_Symbol_above \
  7728. case Rectype_Symbol: goto case_symbol;
  7729. /* Composite cases: */
  7730. #define case_Rectype_string_above \
  7731. case Rectype_S8string: case Rectype_Imm_S8string: case Rectype_S16string: case Rectype_Imm_S16string: case Rectype_S32string: case Rectype_Imm_S32string: case Rectype_reallocstring: case Rectype_string: goto case_string;
  7732. #define case_Rectype_bvector_above \
  7733. case Rectype_Sbvector: case Rectype_bvector: goto case_bvector;
  7734. #define case_Rectype_b2vector_above \
  7735. case Rectype_Sb2vector: case Rectype_b2vector: goto case_b2vector;
  7736. #define case_Rectype_b4vector_above \
  7737. case Rectype_Sb4vector: case Rectype_b4vector: goto case_b4vector;
  7738. #define case_Rectype_b8vector_above \
  7739. case Rectype_Sb8vector: case Rectype_b8vector: goto case_b8vector;
  7740. #define case_Rectype_b16vector_above \
  7741. case Rectype_Sb16vector: case Rectype_b16vector: goto case_b16vector;
  7742. #define case_Rectype_b32vector_above \
  7743. case Rectype_Sb32vector: case Rectype_b32vector: goto case_b32vector;
  7744. #define case_Rectype_vector_above \
  7745. case Rectype_Svector: case Rectype_vector: goto case_vector;
  7746. #define case_Rectype_array_above \
  7747. case Rectype_S8string: case Rectype_Imm_S8string: \
  7748. case Rectype_S16string: case Rectype_Imm_S16string: \
  7749. case Rectype_S32string: case Rectype_Imm_S32string: \
  7750. case Rectype_reallocstring: case Rectype_string: \
  7751. case Rectype_Sbvector: case Rectype_bvector: \
  7752. case Rectype_Sb2vector: case Rectype_b2vector: \
  7753. case Rectype_Sb4vector: case Rectype_b4vector: \
  7754. case Rectype_Sb8vector: case Rectype_b8vector: \
  7755. case Rectype_Sb16vector: case Rectype_b16vector: \
  7756. case Rectype_Sb32vector: case Rectype_b32vector: \
  7757. case Rectype_Svector: case Rectype_vector: \
  7758. case Rectype_mdarray: \
  7759. goto case_array;
  7760. #define case_Rectype_number_above /* don't forget immediate_number_p */ \
  7761. case Rectype_Complex: case Rectype_Ratio: \
  7762. case Rectype_Ffloat: case Rectype_Dfloat: case Rectype_Lfloat: \
  7763. case Rectype_Bignum: \
  7764. goto case_number;
  7765. #define case_Rectype_float_above /* don't forget short_float_p */ \
  7766. case Rectype_Ffloat: case Rectype_Dfloat: case Rectype_Lfloat: \
  7767. goto case_float;
  7768. #define case_Rectype_integer_above /* don't forget fixnump */ \
  7769. case Rectype_Bignum: goto case_integer;
  7770. #endif
  7771. #if defined(TYPECODES) || defined(STANDARD_HEAPCODES)
  7772. #define case_Rectype_Subr_above
  7773. #else /* LINUX_NOEXEC_HEAPCODES */
  7774. #define case_Rectype_Subr_above \
  7775. case Rectype_Subr: goto case_subr;
  7776. #endif
  7777. /* ################# Declarations for the arithmetics #######################
  7778. Type hierachy :
  7779. Number (N) =
  7780. Real (R) =
  7781. Float (F) =
  7782. Short float (SF)
  7783. Single float (FF)
  7784. Double float (DF)
  7785. Long float (LF)
  7786. Rational (RA) =
  7787. Integer (I) =
  7788. Fixnum (FN)
  7789. Bignum (BN)
  7790. Ratio (RT)
  7791. Complex (C)
  7792. Type field:
  7793. Bytes for testing whether it's that type (Bit set, is yes).
  7794. _bit_t to test in the type byte (tint)
  7795. _bit_o to test in the object (oint) */
  7796. #ifndef NUMBER_BITS_INVERTED
  7797. #define number_wbit_test wbit_test
  7798. #else
  7799. #define number_wbit_test !wbit_test
  7800. #endif
  7801. #ifdef TYPECODES
  7802. /* see above:
  7803. #define number_bit_t 4 -- set only for numbers
  7804. #define number_bit_o (number_bit_t+oint_type_shift) -- set only for numbers
  7805. float_bit:
  7806. in a number : Bit set, if it's a Float.
  7807. Bit unset, if it's a rational or complex number.
  7808. (For NUMBER_BITS_INVERTED it's exactly the other way around.)
  7809. #define float_bit_t 1
  7810. #define float_bit_o (float_bit_t+oint_type_shift)
  7811. float1_bit:
  7812. In a floating-point: discriminates further: */
  7813. #ifndef NUMBER_BITS_INVERTED
  7814. /* Float-Bit 1 2
  7815. 0 0 Short Float (SF)
  7816. 0 1 Single Float (FF)
  7817. 1 0 Double Float (DF)
  7818. 1 1 Long Float (LF) */
  7819. #else
  7820. /* Float-Bit 1 2
  7821. 0 0 Long Float (LF)
  7822. 0 1 Double Float (DF)
  7823. 1 0 Single Float (FF)
  7824. 1 1 Short Float (SF) */
  7825. #endif
  7826. /* #define float1_bit_t 3
  7827. #define float1_bit_o (float1_bit_t+oint_type_shift)
  7828. #define float2_bit_t 2
  7829. #define float2_bit_o (float2_bit_t+oint_type_shift) */
  7830. /* ratio_bit:
  7831. For rational numbers: Bit set , if it's a real fraction.
  7832. Bit unset, if it's an Integer.
  7833. (For NUMBER_BITS_INVERTED it's exactly the other way around..)
  7834. #define ratio_bit_t 3
  7835. #define ratio_bit_o (ratio_bit_t+oint_type_shift) */
  7836. /* bignum_bit:
  7837. For Integers: Bit set, if it's a Bignum.
  7838. Bit unset, if it's a Fixnum.
  7839. (For NUMBER_BITS_INVERTED it's exactly the other way around..)
  7840. #define bignum_bit_t 2
  7841. #define bignum_bit_o (bignum_bit_t+oint_type_shift) */
  7842. /* vorz_bit: (sign bit)
  7843. For Reals:
  7844. returns the sign of the number.
  7845. Bit set, if number < 0,
  7846. Bit unset, if number >=0. */
  7847. #define vorz_bit_t sign_bit_t
  7848. /* should be = 0, so the sign-extend
  7849. is easier for Fixnums. */
  7850. #define vorz_bit_o (vorz_bit_t+oint_type_shift)
  7851. #endif
  7852. /* return the sign of a real number (0 if >=0, -1 if <0) */
  7853. #ifdef TYPECODES
  7854. #if (vorz_bit_o<32) && !defined(WIDE_STRUCT)
  7855. #define R_sign(obj) ((signean)sign_of_sint32( (sint32)((uint32)as_oint(obj) << (31-vorz_bit_o)) ))
  7856. #else
  7857. /* define R_sign(obj) ((signean)sign_of_sint32( (sint32)(uint32)(as_oint(obj) >> (vorz_bit_o-31)) )) */
  7858. #define R_sign(obj) ((signean)sign_of_sint32( (sint32)((uint32)typecode(obj) << (31-vorz_bit_t)) ))
  7859. #endif
  7860. #else
  7861. #define R_sign(obj) ((signean)sign_of_sint32(_R_sign(obj)))
  7862. #define _R_sign(obj) \
  7863. (number_immediatep(obj) \
  7864. ? /* fixnum, sfloat */ (sint32)as_oint(obj) << (31-sign_bit_o) \
  7865. : /* [fdl]float */ (sint32)(sintB)Record_flags(obj))
  7866. #endif
  7867. /* Gives the sign of a Fixnum/Bignum/Ratio/
  7868. Short-/Single-/Double-/Long-Float. */
  7869. #ifdef TYPECODES
  7870. #define FN_sign(obj) R_sign(obj)
  7871. #define BN_sign(obj) R_sign(obj)
  7872. #define RT_sign(obj) R_sign(obj)
  7873. #define SF_sign(obj) R_sign(obj)
  7874. #define FF_sign(obj) R_sign(obj)
  7875. #define DF_sign(obj) R_sign(obj)
  7876. #define LF_sign(obj) R_sign(obj)
  7877. #else
  7878. #define FN_sign(obj) \
  7879. ((signean)sign_of_sint32((sint32)as_oint(obj) << (31-sign_bit_o)))
  7880. #define BN_sign(obj) \
  7881. ((signean)sign_of_sint32((sint32)(sintB)Record_flags(obj)))
  7882. #define RT_sign(obj) \
  7883. ((signean)sign_of_sint32((sint32)(sintB)Record_flags(obj)))
  7884. #define SF_sign(obj) \
  7885. ((signean)sign_of_sint32((sint32)as_oint(obj) << (31-sign_bit_o)))
  7886. #define FF_sign(obj) \
  7887. ((signean)sign_of_sint32((sint32)(sintB)Record_flags(obj)))
  7888. #define DF_sign(obj) \
  7889. ((signean)sign_of_sint32((sint32)(sintB)Record_flags(obj)))
  7890. #define LF_sign(obj) \
  7891. ((signean)sign_of_sint32((sint32)(sintB)Record_flags(obj)))
  7892. #endif
  7893. /* Checks whether two real numbers have the same sign: */
  7894. #ifdef TYPECODES
  7895. #define same_sign_p(obj1,obj2) \
  7896. (wbit_test(as_oint(obj1)^as_oint(obj2),vorz_bit_o)==0)
  7897. #else
  7898. #define same_sign_p(obj1,obj2) \
  7899. ((sint32)(_R_sign(obj1) ^ _R_sign(obj2)) >= 0)
  7900. #endif
  7901. /* Type test macros:
  7902. (Return /=0, if satisfied. Prefix 'm', if argument is in memory) */
  7903. /* Tests an objects whether it's a number: (see above)
  7904. define numberp(obj) ... */
  7905. /* Tests a number whether it's a Float. */
  7906. #ifdef TYPECODES
  7907. #ifndef NUMBER_BITS_INVERTED
  7908. /* define N_floatp(obj) ( as_oint(obj) & wbit(float_bit_o) ) */
  7909. #define N_floatp(obj) (wbit_test(as_oint(obj),float_bit_o))
  7910. #else
  7911. #define N_floatp(obj) (!wbit_test(as_oint(obj),float_bit_o))
  7912. #endif
  7913. #else
  7914. #define N_floatp(obj) floatp(obj)
  7915. #endif
  7916. /* Tests a number whether it's an Integer. */
  7917. #ifdef TYPECODES
  7918. #ifndef NUMBER_BITS_INVERTED
  7919. #define N_integerp(obj) (!( as_oint(obj) & (wbit(float_bit_o)|wbit(ratio_bit_o)) ))
  7920. #else
  7921. #define N_integerp(obj) (!( (wbit(float_bit_o)|wbit(ratio_bit_o)) & ~as_oint(obj) ))
  7922. #endif
  7923. #else
  7924. #define N_integerp(obj) integerp(obj)
  7925. #endif
  7926. /* Tests a real number whether it's rational. */
  7927. #ifdef TYPECODES
  7928. #ifndef NUMBER_BITS_INVERTED
  7929. /* define R_rationalp(obj) (!( as_oint(obj) & wbit(float_bit_o) )) */
  7930. #define R_rationalp(obj) (!wbit_test(as_oint(obj),float_bit_o))
  7931. #else
  7932. #define R_rationalp(obj) (wbit_test(as_oint(obj),float_bit_o))
  7933. #endif
  7934. #else
  7935. #define R_rationalp(obj) (!floatp(obj))
  7936. #endif
  7937. /* Tests a real number whether it's a Float. */
  7938. #ifdef TYPECODES
  7939. #ifndef NUMBER_BITS_INVERTED
  7940. /* define R_floatp(obj) ( as_oint(obj) & wbit(float_bit_o) ) */
  7941. #define R_floatp(obj) (wbit_test(as_oint(obj),float_bit_o))
  7942. #else
  7943. #define R_floatp(obj) (!wbit_test(as_oint(obj),float_bit_o))
  7944. #endif
  7945. #else
  7946. #define R_floatp(obj) floatp(obj)
  7947. #endif
  7948. /* Tests a real number whether it's <0. */
  7949. #ifdef TYPECODES
  7950. /* define R_minusp(obj) ( as_oint(obj) & wbit(vorz_bit_o) ) */
  7951. #define R_minusp(obj) (wbit_test(as_oint(obj),vorz_bit_o))
  7952. #else
  7953. #define R_minusp(obj) (!positivep(obj))
  7954. #endif
  7955. %% export_def(R_minusp(obj));
  7956. /* Tests a rational number whether it's an Integer. */
  7957. #ifdef TYPECODES
  7958. #ifndef NUMBER_BITS_INVERTED
  7959. /* define RA_integerp(obj) (!( as_oint(obj) & wbit(ratio_bit_o) )) */
  7960. #define RA_integerp(obj) (!wbit_test(as_oint(obj),ratio_bit_o))
  7961. #else
  7962. #define RA_integerp(obj) (wbit_test(as_oint(obj),ratio_bit_o))
  7963. #endif
  7964. #else
  7965. #define RA_integerp(obj) (!ratiop(obj))
  7966. #endif
  7967. /* Tests a rational number whether it's a fraction. */
  7968. #ifdef TYPECODES
  7969. #ifndef NUMBER_BITS_INVERTED
  7970. /* define RA_ratiop(obj) ( as_oint(obj) & wbit(ratio_bit_o) ) */
  7971. #define RA_ratiop(obj) (wbit_test(as_oint(obj),ratio_bit_o))
  7972. #else
  7973. #define RA_ratiop(obj) (!wbit_test(as_oint(obj),ratio_bit_o))
  7974. #endif
  7975. #else
  7976. #define RA_ratiop(obj) ratiop(obj)
  7977. #endif
  7978. /* Tests an Integer whether it's a Bignum. */
  7979. #ifndef NUMBER_BITS_INVERTED
  7980. /* define I_bignump(obj) ( as_oint(obj) & wbit(bignum_bit_o) ) */
  7981. #define I_bignump(obj) (wbit_test(as_oint(obj),bignum_bit_o))
  7982. #else
  7983. #define I_bignump(obj) (!wbit_test(as_oint(obj),bignum_bit_o))
  7984. #endif
  7985. /* Tests an Integer whether it's a Fixnum. */
  7986. #ifndef NUMBER_BITS_INVERTED
  7987. /* define I_fixnump(obj) (!( as_oint(obj) & wbit(bignum_bit_o) )) */
  7988. #define I_fixnump(obj) (!wbit_test(as_oint(obj),bignum_bit_o))
  7989. #else
  7990. #define I_fixnump(obj) (wbit_test(as_oint(obj),bignum_bit_o))
  7991. #endif
  7992. /* Tests a Fixnum whether it is >=0. */
  7993. #ifdef TYPECODES
  7994. #define FN_positivep(obj) positivep(obj)
  7995. #else
  7996. #define FN_positivep(obj) ((as_oint(obj) & wbit(sign_bit_o)) == 0)
  7997. #endif
  7998. %% export_def(FN_positivep(obj));
  7999. /* Tests a Bignum whether it is >=0. */
  8000. #ifdef TYPECODES
  8001. #define BN_positivep(obj) positivep(obj)
  8002. #else
  8003. #define BN_positivep(obj) ((Record_flags(obj) & bit(7)) == 0)
  8004. #endif
  8005. %% export_def(BN_positivep(obj));
  8006. /* Tests a number whether it's a real number */
  8007. #define N_realp(obj) (!complexp(obj))
  8008. /* Tests a number whether it's a complex number */
  8009. #define N_complexp(obj) complexp(obj)
  8010. /* Tests two Integers whether both are Bignum. */
  8011. #ifndef NUMBER_BITS_INVERTED
  8012. #define I_I_bignums_p(obj1,obj2) \
  8013. (wbit_test(as_oint(obj1)&as_oint(obj2),bignum_bit_o))
  8014. #else
  8015. #define I_I_bignums_p(obj1,obj2) \
  8016. (!wbit_test(as_oint(obj1)|as_oint(obj2),bignum_bit_o))
  8017. #endif
  8018. /* Tests for an Integer from a given range.
  8019. obj should be a variable */
  8020. #define uint1_p(obj) \
  8021. ((as_oint(obj) & ~((oint)0x01 << oint_data_shift)) == as_oint(Fixnum_0))
  8022. #define uint2_p(obj) \
  8023. ((as_oint(obj) & ~((oint)0x03 << oint_data_shift)) == as_oint(Fixnum_0))
  8024. #define uint4_p(obj) \
  8025. ((as_oint(obj) & ~((oint)0x0F << oint_data_shift)) == as_oint(Fixnum_0))
  8026. #define uint8_p(obj) \
  8027. ((as_oint(obj) & ~((oint)0xFF << oint_data_shift)) == as_oint(Fixnum_0))
  8028. #define sint8_p(obj) \
  8029. (((as_oint(obj) ^ (FN_positivep(obj) ? 0 : as_oint(Fixnum_minus1)^as_oint(Fixnum_0))) & ~((oint)0x7F << oint_data_shift)) == as_oint(Fixnum_0))
  8030. #define uint16_p(obj) \
  8031. ((as_oint(obj) & ~((oint)0xFFFF << oint_data_shift)) == as_oint(Fixnum_0))
  8032. #define sint16_p(obj) \
  8033. (((as_oint(obj) ^ (FN_positivep(obj) ? 0 : as_oint(Fixnum_minus1)^as_oint(Fixnum_0))) & ~((oint)0x7FFF << oint_data_shift)) == as_oint(Fixnum_0))
  8034. #if (oint_data_len>=32)
  8035. #define uint32_p(obj) \
  8036. ((as_oint(obj) & ~((oint)0xFFFFFFFFUL << oint_data_shift)) == as_oint(Fixnum_0))
  8037. #else
  8038. #define uint32_p(obj) \
  8039. (posfixnump(obj) \
  8040. || (posbignump(obj) \
  8041. && (Bignum_length(obj) <= ceiling(33,intDsize)) \
  8042. && ((Bignum_length(obj) < ceiling(33,intDsize)) \
  8043. || (TheBignum(obj)->data[0] < (uintD)bit(32%intDsize)))))
  8044. #endif
  8045. #if (oint_data_len>=31)
  8046. #define sint32_p(obj) \
  8047. (((as_oint(obj) ^ (FN_positivep(obj) ? 0 : as_oint(Fixnum_minus1)^as_oint(Fixnum_0))) & ~((oint)0x7FFFFFFFUL << oint_data_shift)) == as_oint(Fixnum_0))
  8048. #else
  8049. #define sint32_p(obj) \
  8050. (fixnump(obj) \
  8051. || (bignump(obj) \
  8052. && (Bignum_length(obj) <= ceiling(32,intDsize)) \
  8053. && ((Bignum_length(obj) < ceiling(32,intDsize)) \
  8054. || ((TheBignum(obj)->data[0] ^ (BN_positivep(obj) ? (uintD)0 : ~(uintD)0)) < (uintD)bit(31%intDsize)))))
  8055. #endif
  8056. #define uint64_p(obj) \
  8057. (posfixnump(obj) \
  8058. || (posbignump(obj) \
  8059. && (Bignum_length(obj) <= ceiling(65,intDsize)) \
  8060. && ((Bignum_length(obj) < ceiling(65,intDsize)) \
  8061. || (TheBignum(obj)->data[0] < (uintD)bit(64%intDsize)))))
  8062. #define sint64_p(obj) \
  8063. (fixnump(obj) \
  8064. || (bignump(obj) \
  8065. && (Bignum_length(obj) <= ceiling(64,intDsize)) \
  8066. && ((Bignum_length(obj) < ceiling(64,intDsize)) \
  8067. || ((TheBignum(obj)->data[0] ^ (BN_positivep(obj) ? (uintD)0 : ~(uintD)0)) < (uintD)bit(63%intDsize)))))
  8068. #if (int_bitsize==16)
  8069. #define uint_p uint16_p
  8070. #define sint_p sint16_p
  8071. #else /* (int_bitsize==32) */
  8072. #define uint_p uint32_p
  8073. #define sint_p sint32_p
  8074. #endif
  8075. #if (long_bitsize==32)
  8076. #define ulong_p uint32_p
  8077. #define slong_p sint32_p
  8078. #else /* (long_bitsize==64) */
  8079. #define ulong_p uint64_p
  8080. #define slong_p sint64_p
  8081. #endif
  8082. %% export_def(uint8_p(obj));
  8083. %% export_def(sint8_p(obj));
  8084. %% export_def(uint16_p(obj));
  8085. %% export_def(sint16_p(obj));
  8086. %% export_def(uint32_p(obj));
  8087. %% export_def(sint32_p(obj));
  8088. %% export_def(uint64_p(obj));
  8089. %% export_def(sint64_p(obj));
  8090. %% export_def(uint_p);
  8091. %% export_def(sint_p);
  8092. %% export_def(ulong_p);
  8093. %% export_def(slong_p);
  8094. /* ####################### TIMEBIBL in TIME.D #############################
  8095. (* 25567 24 60 60) => 2208988800
  8096. the number of seconds from 1900-01-01 to 1970-01-01 */
  8097. #define UNIX_LISP_TIME_DIFF 2208988800UL
  8098. %% export_def(UNIX_LISP_TIME_DIFF);
  8099. /* Type which is used for 'Internal Time': */
  8100. #if TIME_METHOD == 1
  8101. typedef uintL internal_time_t; /* measured value of the ticking counter */
  8102. #if defined(TIME_UNIX_TIMES)
  8103. #define ticks_per_second CLK_TCK
  8104. #endif
  8105. #define sub_internal_time(x,y, z) z = (x) - (y)
  8106. #define add_internal_time(x,y, z) z = (x) + (y)
  8107. #elif TIME_METHOD == 2
  8108. #ifdef TIME_UNIX
  8109. typedef struct {
  8110. uintL tv_sec; /* number of seconds since 1.1.1970 00:00 GMT,
  8111. 'uintL' for tv_sec is good for 136 years. */
  8112. uintL tv_usec; /* additional microseconds */
  8113. } internal_time_t;
  8114. #define ticks_per_second 1000000UL /* 1 Tick = 1 mu-sec */
  8115. #define sub_internal_time(x,y, z) /* z:=x-y */ \
  8116. do { (z).tv_sec = (x).tv_sec - (y).tv_sec; \
  8117. if ((x).tv_usec < (y).tv_usec) \
  8118. { (x).tv_usec += ticks_per_second; (z).tv_sec -= 1; } \
  8119. (z).tv_usec = (x).tv_usec - (y).tv_usec; \
  8120. } while(0)
  8121. #define add_internal_time(x,y, z) /* z:=x+y */ \
  8122. do { (z).tv_sec = (x).tv_sec + (y).tv_sec; \
  8123. (z).tv_usec = (x).tv_usec + (y).tv_usec; \
  8124. if ((z).tv_usec >= ticks_per_second) \
  8125. { (z).tv_usec -= ticks_per_second; (z).tv_sec += 1; } \
  8126. } while(0)
  8127. #endif
  8128. #ifdef TIME_WIN32
  8129. typedef /* struct _FILETIME { DWORD dwLowDateTime; DWORD dwHighDateTime; } */
  8130. FILETIME /* number of 0.1 mu-sec since 1.1.1601 00:00 GMT. */
  8131. internal_time_t;
  8132. #define ticks_per_second 10000000UL /* 1 Tick = 0.1 mu-sec */
  8133. #define sub_internal_time(x,y, z) /* z:=x-y */ \
  8134. do { (z).dwHighDateTime = (x).dwHighDateTime - (y).dwHighDateTime; \
  8135. if ((x).dwLowDateTime < (y).dwLowDateTime) { (z).dwHighDateTime -= 1;}\
  8136. (z).dwLowDateTime = (x).dwLowDateTime - (y).dwLowDateTime; \
  8137. } while(0)
  8138. #define add_internal_time(x,y, z) /* z:=x+y */ \
  8139. do { (z).dwHighDateTime = (x).dwHighDateTime + (y).dwHighDateTime; \
  8140. (z).dwLowDateTime = (x).dwLowDateTime + (y).dwLowDateTime; \
  8141. if ((z).dwLowDateTime < (x).dwLowDateTime) { (z).dwHighDateTime += 1;}\
  8142. } while(0)
  8143. #endif
  8144. #endif
  8145. #ifndef HAVE_RUN_TIME
  8146. /* UP: Stops the run-time timer
  8147. run_time_stop(); */
  8148. extern void run_time_stop (void);
  8149. /* is used by STREAM */
  8150. /* UP: restarts the run-time timer
  8151. run_time_restart(); */
  8152. extern void run_time_restart (void);
  8153. /* is used by STREAM */
  8154. #else
  8155. /* You don't need a run-time timer */
  8156. #define run_time_stop()
  8157. #define run_time_restart()
  8158. #endif
  8159. #if TIME_METHOD == 1
  8160. /* UP: Yields the real-time
  8161. get_real_time()
  8162. < uintL result: time since LISP-system-start (in 1/200 sec resp. in 1/50 sec resp. in 1/100 sec resp. in 1/CLK_TCK sec) */
  8163. extern uintL get_real_time (void);
  8164. /* is used by STREAM, LISPARIT */
  8165. #elif TIME_METHOD == 2
  8166. /* UP: yields the real-time
  8167. get_real_time()
  8168. < internal_time_t* result: absolute time */
  8169. extern void get_real_time (internal_time_t*);
  8170. /* is used by LISPARIT */
  8171. #endif
  8172. /* UP: Yields the run-time
  8173. get_running_times(&timescore);
  8174. < timescore.runtime: Run-time since LISP-system-start (in Ticks)
  8175. < timescore.realtime: Real-time since LISP-system-start (in Ticks)
  8176. < timescore.gctime: GC-Time since LISP-system-start (in Ticks)
  8177. < timescore.gccount: Number of GC's since LISP-system-start
  8178. < timescore.gcfreed: Size of the space reclaimed by the GC's so far */
  8179. typedef struct {
  8180. internal_time_t runtime;
  8181. internal_time_t realtime;
  8182. internal_time_t gctime;
  8183. uintL gccount;
  8184. uintL2 gcfreed;
  8185. } timescore_t;
  8186. extern void get_running_times (timescore_t*);
  8187. /* is used by TIME */
  8188. /* UP: yields the run-time
  8189. get_running_time(runtime);
  8190. < runtime: Run-time (in Ticks) */
  8191. #ifndef HAVE_RUN_TIME
  8192. #define get_running_time(runtime) runtime = get_time()
  8193. extern uintL get_time (void);
  8194. #endif
  8195. #if defined(TIME_UNIX) || defined(TIME_WIN32) || defined(TIME_UNIX_TIMES)
  8196. #define get_running_time(runtime) get_run_time(&runtime)
  8197. #if defined(TIME_UNIX) || defined(TIME_WIN32)
  8198. extern void get_run_time (internal_time_t* runtime);
  8199. #endif
  8200. #ifdef TIME_UNIX_TIMES
  8201. extern uintL get_run_time (internal_time_t* runtime);
  8202. #endif
  8203. #endif
  8204. /* is used by SPVW */
  8205. /* Time in decoded-time: */
  8206. typedef struct {
  8207. object seconds;
  8208. object minutes;
  8209. object hours;
  8210. object day;
  8211. object month;
  8212. object year;
  8213. } decoded_time_t;
  8214. #ifdef UNIX
  8215. /* UP: Converts the system-time-format into Decoded-Time.
  8216. convert_time(&time,&timepoint);
  8217. > time_t time: time in the system-time-format
  8218. < timepoint.seconds, timepoint.minutes, timepoint.hours,
  8219. timepoint.day, timepoint.month, timepoint.year, each a Fixnum */
  8220. extern void convert_time (const time_t* time, decoded_time_t* timepoint);
  8221. /* is used by PATHNAME */
  8222. #endif
  8223. #ifdef WIN32_NATIVE
  8224. /* UP: Converts the system-time-format into Decoded-Time.
  8225. convert_time(&time,&timepoint);
  8226. > FILETIME time: time in the system-time-format
  8227. < timepoint.seconds, timepoint.minutes, timepoint.hours,
  8228. timepoint.day, timepoint.month, timepoint.year, each a Fixnum */
  8229. extern void convert_time (const FILETIME* time, decoded_time_t* timepoint);
  8230. /* is used by PATHNAME */
  8231. #endif
  8232. #ifdef UNIX
  8233. /* UP: Converts the system time-format into Universal-Time.
  8234. convert_time_to_universal(&time)
  8235. > time_t time: time in the system time-format
  8236. < result: integer denoting the seconds since 1900-01-01 00:00 GMT
  8237. can trigger GC */
  8238. extern maygc object convert_time_to_universal (const time_t* time);
  8239. /* is used by PATHNAME */
  8240. #endif
  8241. #ifdef WIN32_NATIVE
  8242. /* UP: converts the system time-format into Universal-Time.
  8243. convert_time_to_universal(&time)
  8244. > FILETIME time: Time in the system-time-format
  8245. < result: integer denoting the seconds since 1900-01-01 00:00 GMT
  8246. can trigger GC */
  8247. extern maygc object convert_time_to_universal (const FILETIME* time);
  8248. /* is used by PATHNAME */
  8249. #endif
  8250. %% #ifdef UNIX
  8251. %% puts("extern object convert_time_to_universal (const time_t* time);");
  8252. %% #endif
  8253. %% #ifdef WIN32_NATIVE
  8254. %% puts("extern object convert_time_to_universal (const FILETIME* time);");
  8255. %% #endif
  8256. #ifdef UNIX
  8257. /* the inverse of convert_time_to_universal() */
  8258. extern void convert_time_from_universal (object universal, time_t* time);
  8259. #endif
  8260. #ifdef WIN32_NATIVE
  8261. /* the inverse of convert_time_to_universal() */
  8262. extern void convert_time_from_universal (object universal, FILETIME* time);
  8263. #endif
  8264. %% #ifdef UNIX
  8265. %% puts("extern void convert_time_from_universal (object universal, time_t* time);");
  8266. %% #endif
  8267. %% #ifdef WIN32_NATIVE
  8268. %% puts("extern void convert_time_from_universal (object universal, FILETIME* time);");
  8269. %% #endif
  8270. /* UP: Initializes the time variables upon the LISP-System-Start.
  8271. init_time(); */
  8272. extern void init_time (void);
  8273. /* is used by SPVW */
  8274. /* ####################### SPVWBIBL for SPVW.D #############################
  8275. The Stacks
  8276. ==========
  8277. Two Stacks are being used :
  8278. - the C-program stack (Stackpointer SP = Register A7),
  8279. - the LISP-Stack (Stackpointer STACK).
  8280. All calls of sub-programs are done through BSR/JSR via the program stack;
  8281. it's also used to temporarily store data, that is not a LISP-object.
  8282. The LISP-Stack is used to store frames and for the temporary storage
  8283. of LISP-objects.
  8284. For both stacks the limits of growth are controlled by the memory management
  8285. and the following macros:
  8286. check_SP(); tests the program stack for overflow
  8287. check_STACK(); tests the LISP-Stack for overflow
  8288. get_space_on_STACK(n); tests, whether there are still D0.L
  8289. Bytes free on the LISP-Stack
  8290. Basically only long words may be stored on the LISP-Stack.
  8291. If FRAME_BIT is set, it's the lower end of a frame;
  8292. this long word is a pointer above the Frame, together with a
  8293. Frame-type-Byte; if SKIP2_BIT is unset in it, the longword above
  8294. it is not a LISP-object.
  8295. All other long words on the LISP-Stack are LISP-objects.
  8296. machine stack: SP
  8297. SP() returns the current value of the SP.
  8298. setSP(adresse); sets the SP to a given value. Extremely dangerous!
  8299. FAST_SP defined, if SP-accesses are fast. */
  8300. #if defined(GNU) && !(__APPLE_CC__ > 1)
  8301. /* definition of the register, in which the SP resides. */
  8302. #ifdef MC680X0
  8303. #define SP_register "sp" /* %sp = %a7 */
  8304. #endif
  8305. #ifdef SPARC
  8306. #define SP_register "%sp" /* %sp = %o6 */
  8307. #endif
  8308. #ifdef HPPA
  8309. #define SP_register "%r30" /* %sp = %r30 */
  8310. #endif
  8311. #ifdef MIPS
  8312. #define SP_register "$sp" /* $sp = $29 */
  8313. #endif
  8314. #ifdef M88000
  8315. #define SP_register "%r31" /* %sp = %r31 */
  8316. #endif
  8317. #ifdef POWERPC
  8318. #define SP_register "r1"
  8319. #endif
  8320. #ifdef ARM
  8321. #define SP_register "%sp" /* %sp = %r13 */
  8322. #endif
  8323. #ifdef DECALPHA
  8324. #define SP_register "$30" /* $sp = $30 */
  8325. #endif
  8326. #ifdef I80386
  8327. #define SP_register "%esp"
  8328. #endif
  8329. #ifdef VAX
  8330. #define SP_register "sp"
  8331. #endif
  8332. #ifdef IA64
  8333. #define SP_register "r12"
  8334. #endif
  8335. #ifdef AMD64
  8336. #define SP_register "%rsp"
  8337. #endif
  8338. #ifdef S390
  8339. #define SP_register "15"
  8340. #endif
  8341. #endif
  8342. #if (defined(GNU) || defined(INTEL)) && !defined(NO_ASM)
  8343. /* Assembler-instruction that copies the SP-register into a variable. */
  8344. #ifdef MC680X0
  8345. #ifdef __REGISTER_PREFIX__ /* GNU C Version >= 2.4 has %/ and __REGISTER_PREFIX__ */
  8346. /* But the value of __REGISTER_PREFIX__ is useless, because we might be
  8347. cross-compiling. */
  8348. #define REGISTER_PREFIX "%/"
  8349. #else
  8350. #define REGISTER_PREFIX "" /* or "%%", depends on the assembler that's being used */
  8351. #endif
  8352. #define ASM_get_SP_register(resultvar) ("movel "REGISTER_PREFIX"sp,%0" : "=g" (resultvar) : )
  8353. #endif
  8354. #ifdef SPARC
  8355. #ifdef SPARC64
  8356. #define ASM_get_SP_register(resultvar) ("add %%sp,2048,%0" : "=r" (resultvar) : )
  8357. #else
  8358. #define ASM_get_SP_register(resultvar) ("mov %%sp,%0" : "=r" (resultvar) : )
  8359. #endif
  8360. #endif
  8361. #ifdef HPPA
  8362. #define ASM_get_SP_register(resultvar) ("copy %%r30,%0" : "=r" (resultvar) : )
  8363. #endif
  8364. #ifdef MIPS
  8365. #define ASM_get_SP_register(resultvar) ("move\t%0,$sp" : "=r" (resultvar) : )
  8366. #endif
  8367. #ifdef M88000
  8368. #define ASM_get_SP_register(resultvar) ("or %0,#r0,#r31" : "=r" (resultvar) : )
  8369. #endif
  8370. #ifdef POWERPC
  8371. #define ASM_get_SP_register(resultvar) ("mr %0,1" : "=r" (resultvar) : )
  8372. #endif
  8373. #ifdef ARM
  8374. #define ASM_get_SP_register(resultvar) ("mov\t%0, sp" : "=r" (resultvar) : )
  8375. #endif
  8376. #ifdef DECALPHA
  8377. #define ASM_get_SP_register(resultvar) ("bis $30,$30,%0" : "=r" (resultvar) : )
  8378. #endif
  8379. #ifdef I80386
  8380. #define ASM_get_SP_register(resultvar) ("movl %%esp,%0" : "=g" (resultvar) : )
  8381. #endif
  8382. #ifdef IA64
  8383. #define ASM_get_SP_register(resultvar) ("mov %0 = r12" : "=r" (resultvar) : )
  8384. #endif
  8385. #ifdef AMD64
  8386. #define ASM_get_SP_register(resultvar) ("movq %%rsp,%0" : "=g" (resultvar) : )
  8387. #endif
  8388. #ifdef S390
  8389. #define ASM_get_SP_register(resultvar) ("lr %0,%%r15" : "=r" (resultvar) : )
  8390. #endif
  8391. #endif
  8392. #if defined(GNU) && defined(MC680X0) && !defined(NO_ASM)
  8393. /* Access to a global register-"variable" SP */
  8394. #define SP() \
  8395. ({var aint __SP; \
  8396. __asm__ __volatile__ ("movel "REGISTER_PREFIX"sp,%0" : "=g" (__SP) : ); \
  8397. __SP; \
  8398. })
  8399. #define setSP(adresse) \
  8400. ({ __asm__ __volatile__ ("movel %0,"REGISTER_PREFIX"sp" : : "g" ((aint)(adresse)) : "sp" ); })
  8401. #define FAST_SP
  8402. #elif (defined(GNU) || defined(INTEL)) && defined(I80386) && !defined(NO_ASM)
  8403. /* Access to a register-"variable" %esp */
  8404. #define SP() \
  8405. ({var aint __SP; \
  8406. __asm__ __volatile__ ("movl %%esp,%0" : "=g" (__SP) : ); \
  8407. __SP; \
  8408. })
  8409. /* Doesn't work with gcc 3.1 any more. */
  8410. #if (__GNUC__ < 3) || (__GNUC__ == 3 && __GNUC_MINOR__ < 1)
  8411. #define setSP(adresse) \
  8412. ({ __asm__ __volatile__ ("movl %0,%%esp" : : "g" ((aint)(adresse)) : "sp" ); })
  8413. #define FAST_SP
  8414. #endif
  8415. #elif defined(GNU) && defined(SP_register)
  8416. register __volatile__ aint __SP __asm__(SP_register);
  8417. #ifdef SPARC64
  8418. #define SP() (__SP+2048)
  8419. #else
  8420. #define SP() __SP
  8421. #endif
  8422. #if defined(SPARC)
  8423. /* We must not do a setSP() here without taking care that
  8424. 1. %sp has to pay attention to an alignment of 8 Bytes,
  8425. 2. above %sp 92 Bytes have to be kept free (that's where the
  8426. register contents are saved, if a 'register window overflow trap'
  8427. is triggered by a 'save' in a sub-program). */
  8428. #endif
  8429. #elif defined(MICROSOFT) && defined(I80386) && !defined(NO_ASM)
  8430. /* access the register %esp */
  8431. #define SP getSP
  8432. static __inline aint getSP () { __asm mov eax,esp }
  8433. static __inline aint setSP (aint address) { __asm mov esp,address }
  8434. #elif defined(MC680X0) || defined(SPARC) || defined(MIPS) || defined(I80386)
  8435. /* access functions extern, in assembler */
  8436. #define SP getSP
  8437. extern_C void* SP (void);
  8438. extern_C void setSP (void* adresse);
  8439. #else
  8440. /* access function portable in C */
  8441. #define SP() getSP()
  8442. extern void* getSP (void);
  8443. #define NEED_OWN_GETSP
  8444. #endif
  8445. #if defined(stack_grows_down) /* defined(MC680X0) || defined(I80386) || defined(SPARC) || defined(MIPS) || defined(M88000) || defined(DECALPHA) || defined(IA64) || defined(AMD64) || defined(S390) || ... */
  8446. #define SP_DOWN /* SP grows downward */
  8447. #define SPoffset 0 /* top-of-SP ist *(SP+SPoffset) */
  8448. #endif
  8449. #if defined(stack_grows_up) /* defined(HPPA) || ... */
  8450. #define SP_UP /* SP grows upward */
  8451. #define SPoffset -1 /* top-of-SP ist *(SP+SPoffset) */
  8452. #endif
  8453. #if (defined(SP_DOWN) && defined(SP_UP)) || (!defined(SP_DOWN) && !defined(SP_UP))
  8454. #error "Unknown SP direction -- readjust SP_DOWN/SP_UP!"
  8455. #endif
  8456. /* Derived from that:
  8457. SPint is the type of the elements on the SP, an Integer type at least as
  8458. wide as uintL and at least as wide as aint resp. void*.
  8459. SP_(n) = (n+1)th longword on the SP.
  8460. _SP_(n) = &SP_(n).
  8461. pushSP(item) puts a longword on the SP. Synonym: -(SP).
  8462. popSP(item=) returns item=SP_(0) and takes it off the SP.
  8463. skipSP(n); takes n long words of the SP. */
  8464. #if (oint_addr_len <= intLsize)
  8465. typedef uintL SPint;
  8466. #else
  8467. typedef aint SPint;
  8468. #endif
  8469. #ifdef SP_DOWN
  8470. #define skipSPop +=
  8471. #define SPop +
  8472. #endif
  8473. #ifdef SP_UP
  8474. #define skipSPop -=
  8475. #define SPop -
  8476. #endif
  8477. #define _SP_(n) (((SPint*)SP()) + SPoffset SPop (uintP)(n))
  8478. #if !(defined(GNU) && (defined(MC680X0)) && !defined(NO_ASM)) /* generally */
  8479. #define SP_(n) (((SPint*)SP())[SPoffset SPop (uintP)(n)])
  8480. #define skipSP(n) \
  8481. do { var register SPint* sp = (SPint*)SP(); \
  8482. sp skipSPop (uintP)(n); \
  8483. setSP(sp); \
  8484. } while(0)
  8485. #define pushSP(item) \
  8486. do { var register SPint* sp = (SPint*)SP(); \
  8487. sp skipSPop -1; \
  8488. setSP(sp); /* First decrease SP (because of a possible interrupt!) */\
  8489. sp[SPoffset] = (item); /* then insert item as top-of-SP */ \
  8490. } while(0)
  8491. #define popSP(item_assignment) \
  8492. do { var register SPint* sp = (SPint*)SP(); \
  8493. item_assignment sp[SPoffset]; /* First fetch top-of-SP */\
  8494. sp skipSPop 1; \
  8495. setSP(sp); /* then (danger of interrupt!) increase SP */\
  8496. } while(0)
  8497. #endif
  8498. #if defined(GNU) && defined(MC680X0) && !defined(NO_ASM)
  8499. /* With GNU on as 680X0 SP is in a register. Thus access and
  8500. modification of SP are a unit that cannot be interrupted.
  8501. And SP_DOWN as well as SPoffset=0 hold. */
  8502. #define SP_(n) \
  8503. ({var register uintL __n = sizeof(SPint) * (n); \
  8504. var register SPint __item; \
  8505. __asm__ __volatile__ ("movel "REGISTER_PREFIX"sp@(%1:l),%0" : "=g" (__item) : "r" (__n) ); \
  8506. __item; \
  8507. })
  8508. #define skipSP(n) \
  8509. do { var register uintL __n = sizeof(SPint) * (n); \
  8510. __asm__ __volatile__ ("addl %0,"REGISTER_PREFIX"sp" : : "g" (__n) : "sp" ); \
  8511. } while(0)
  8512. #define pushSP(item) \
  8513. do { var register SPint __item = (item); \
  8514. __asm__ __volatile__ ("movel %0,"REGISTER_PREFIX"sp@-" : : "g" (__item) : "sp" ); \
  8515. } while(0)
  8516. #define popSP(item_assignment) \
  8517. do { var register SPint __item; \
  8518. __asm__ __volatile__ ("movel "REGISTER_PREFIX"sp@+,%0" : "=r" (__item) : : "sp" ); \
  8519. item_assignment __item; \
  8520. } while(0)
  8521. #endif
  8522. /* An sp_jmp_buf is exactly the same as a jmp_buf,
  8523. except that on Irix 6.5 in 32-bit mode, a jmp_buf has alignment 8,
  8524. whereas an SPint only has alignment 4.
  8525. Need to add some padding.
  8526. Then jmpbufsize = sizeof(sp_jmp_buf)/sizeof(SPint). */
  8527. #define sp_jmp_buf_incr (alignof(jmp_buf)>alignof(SPint)?alignof(jmp_buf)-alignof(SPint):0)
  8528. #define sp_jmp_buf_to_jmp_buf(x) (*(jmp_buf*)(((long)&(x)+(long)sp_jmp_buf_incr)&-(long)(alignof(jmp_buf)>alignof(SPint)?alignof(jmp_buf):1)))
  8529. #define setjmpspl(x) setjmpl(sp_jmp_buf_to_jmp_buf(x))
  8530. #define longjmpspl(x,y) longjmpl(sp_jmp_buf_to_jmp_buf(x),y)
  8531. #define jmpbufsize ceiling(sizeof(jmp_buf)+sp_jmp_buf_incr,sizeof(SPint))
  8532. typedef SPint sp_jmp_buf[jmpbufsize];
  8533. /* The initial value of SP() during main(). */
  8534. extern void* SP_anchor;
  8535. %% #if (defined(GNU) || defined(INTEL)) && defined(I80386) && !defined(NO_ASM)
  8536. %% printf("%s\n","#define SP() ({aint __SP; __asm__ __volatile__ (\"movl %%esp,%0\" : \"=g\" (__SP) : ); __SP; })");
  8537. %% #endif
  8538. /* LISP-Stack: STACK */
  8539. #if !defined(STACK_register)
  8540. /* a global variable */
  8541. extern per_thread gcv_object_t* STACK;
  8542. #else
  8543. /* a global register variable */
  8544. register gcv_object_t* STACK __asm__(STACK_register);
  8545. #endif
  8546. #if defined(SPARC) && !defined(GNU) && !defined(__SUNPRO_C) && !defined(MULTITHREAD) && (SAFETY < 2)
  8547. /* a global register variable, but access functions externally in assembler */
  8548. #define STACK _getSTACK()
  8549. extern_C gcv_object_t* _getSTACK (void);
  8550. #define setSTACK(allocation) /* hem, yuck! */ \
  8551. do { var gcv_object_t* tempSTACK; _setSTACK(temp##allocation); } while(0)
  8552. extern_C void _setSTACK (void* new_STACK);
  8553. #else
  8554. #define setSTACK(allocation) allocation
  8555. #endif
  8556. #if defined(UNIX) || defined(WIN32) || defined(HYPERSTONE)
  8557. #define STACK_UP /* STACK grows upward */
  8558. #endif
  8559. #if (defined(STACK_DOWN) && defined(STACK_UP)) || (!defined(STACK_DOWN) && !defined(STACK_UP))
  8560. #error "Unknown STACK direction -- readjust STACK_DOWN/STACK_UP!"
  8561. #endif
  8562. %% #if !defined(STACK_register)
  8563. %% puts("extern gcv_object_t* STACK;");
  8564. %% #else
  8565. %% puts("#ifndef IN_MODULE_CC");
  8566. %% printf("register gcv_object_t* STACK __asm__(\"%s\");\n",STACK_register);
  8567. %% puts("#endif");
  8568. %% #endif
  8569. /* A singly-linked list of all currently active function calls.
  8570. Resides in the C stack. */
  8571. struct backtrace_t {
  8572. const struct backtrace_t* bt_next; /* Link to the caller */
  8573. gcv_object_t bt_function; /* Function or FSUBR being called */
  8574. gcv_object_t *bt_stack; /* STACK value where the frame area begins */
  8575. int bt_num_arg; /* Number of arguments, if known, or -1 */
  8576. };
  8577. extern void back_trace_check (const struct backtrace_t *bt,
  8578. const char* label, const char* file, int line);
  8579. #ifdef DEBUG_BACKTRACE
  8580. #define BT_CHECK(b,l) back_trace_check(b,l,__FILE__,__LINE__)
  8581. #else
  8582. #define BT_CHECK(b,l)
  8583. #endif
  8584. #define BT_CHECK1(l) BT_CHECK(back_trace,l)
  8585. %% puts("struct backtrace_t {\n struct backtrace_t* bt_next;\n gcv_object_t bt_function;\n gcv_object_t *bt_stack;\n int bt_num_arg;\n};");
  8586. #if defined(DEBUG_BACKTRACE) && defined(__cplusplus)
  8587. struct p_backtrace_t {
  8588. const struct backtrace_t * ba_tr_p;
  8589. p_backtrace_t (void* bt) { ba_tr_p = (struct backtrace_t*)bt; }
  8590. /* assignment should check for circularities */
  8591. p_backtrace_t& operator= (const struct backtrace_t *bt) {
  8592. if (this->ba_tr_p != bt) {
  8593. BT_CHECK(bt,"=: new value");
  8594. BT_CHECK(ba_tr_p,"=: current value");
  8595. this->ba_tr_p = bt;
  8596. }
  8597. return *this;
  8598. };
  8599. /* back_trace->foo means back_trace.ba_tr_p->foo */
  8600. const struct backtrace_t* operator-> () {
  8601. BT_CHECK(ba_tr_p,"->");
  8602. return this->ba_tr_p;
  8603. };
  8604. /* cast p_backtrace_t to struct backtrace_t* */
  8605. operator const struct backtrace_t* () const {
  8606. BT_CHECK(ba_tr_p,"(struct backtrace_t*)");
  8607. return ba_tr_p;
  8608. }
  8609. };
  8610. #else
  8611. typedef const struct backtrace_t* p_backtrace_t;
  8612. #endif
  8613. %% emit_typedef("struct backtrace_t *","p_backtrace_t");
  8614. /* Returns the top-of-frame of a back_trace element. */
  8615. extern gcv_object_t* top_of_back_trace_frame (const struct backtrace_t *bt);
  8616. #define bt_beyond_stack_p(bt,st) \
  8617. ((bt) != NULL && !((aint)(st) cmpSTACKop (aint)top_of_back_trace_frame(bt)))
  8618. /* unwind backtrace to the stack location */
  8619. #define unwind_back_trace(bt,st) \
  8620. do { BT_CHECK(bt,"unwind_back_trace"); \
  8621. while (bt_beyond_stack_p(bt,st)) \
  8622. bt = bt->bt_next; \
  8623. } while(0)
  8624. /* Evaluate statement, augmenting back_trace with an activation record for
  8625. the given function.
  8626. stack permits to locate the top-of-frame, namely
  8627. - for FSUBRs:
  8628. stack = top-of-frame - (req + opt + (body-flag ? 1 : 0))
  8629. - for SUBRs:
  8630. stack = top-of-frame - (req + opt + length(keyword-list))
  8631. - for compiled closures:
  8632. stack = top-of-frame - (req + opt + (rest-flag ? 1 : 0) + length(keyword-list))
  8633. - for interpreted closures:
  8634. stack = top-of-frame
  8635. */
  8636. #if STACKCHECKS || STACKCHECKC
  8637. #define with_saved_back_trace(fun,stack,num_arg,statement) \
  8638. do { \
  8639. p_backtrace_t bt_save = back_trace; \
  8640. struct backtrace_t bt_here; \
  8641. bt_here.bt_next = back_trace; \
  8642. bt_here.bt_function = (fun); \
  8643. bt_here.bt_stack = (stack); \
  8644. bt_here.bt_num_arg = (num_arg); \
  8645. BT_CHECK1("w/s/b/t: before"); \
  8646. back_trace = &bt_here; \
  8647. statement; \
  8648. if (back_trace != &bt_here) abort(); \
  8649. if (back_trace->bt_next != bt_save) abort(); \
  8650. BT_CHECK1("w/s/b/t: after"); \
  8651. back_trace = back_trace->bt_next; \
  8652. } while(0)
  8653. #else
  8654. #define with_saved_back_trace(fun,stack,num_arg,statement) \
  8655. do { \
  8656. struct backtrace_t bt_here; \
  8657. bt_here.bt_next = back_trace; \
  8658. bt_here.bt_function = (fun); \
  8659. bt_here.bt_stack = (stack); \
  8660. bt_here.bt_num_arg = (num_arg); \
  8661. back_trace = &bt_here; \
  8662. statement; \
  8663. back_trace = back_trace->bt_next; \
  8664. } while(0)
  8665. #endif
  8666. #define with_saved_back_trace_fsubr(fun,statement) \
  8667. with_saved_back_trace(fun,STACK,-1,statement)
  8668. #define with_saved_back_trace_subr(fun,stack,num_arg,statement) \
  8669. with_saved_back_trace(fun,stack,num_arg,statement)
  8670. #define with_saved_back_trace_cclosure(fun,statement) \
  8671. with_saved_back_trace(fun,STACK,-1,statement)
  8672. #define with_saved_back_trace_iclosure(fun,stack,num_arg,statement) \
  8673. with_saved_back_trace(fun,stack,num_arg,statement)
  8674. /* Every call of an external function (or a sequence of those) has to be framed
  8675. with
  8676. begin_call();
  8677. and
  8678. end_call();
  8679. Purpose: The stack, if it resides in a register,
  8680. should be brought to a halfway recent value
  8681. in case of an interrupt during the corresponding timespan. */
  8682. #
  8683. /* If you want to access the STACK while an external function run,
  8684. you have to frame the corresponding code with
  8685. begin_callback();
  8686. and
  8687. end_callback(); */
  8688. #ifdef HAVE_SAVED_mv_count
  8689. extern per_thread uintC saved_mv_count;
  8690. #define SAVE_mv_count() saved_mv_count = mv_count
  8691. #define RESTORE_mv_count() mv_count = saved_mv_count
  8692. #else
  8693. #define SAVE_mv_count()
  8694. #define RESTORE_mv_count()
  8695. #endif
  8696. #ifdef HAVE_SAVED_value1
  8697. extern per_thread object saved_value1;
  8698. #define SAVE_value1() saved_value1 = value1
  8699. #define RESTORE_value1() value1 = saved_value1
  8700. #else
  8701. #define SAVE_value1()
  8702. #define RESTORE_value1()
  8703. #endif
  8704. #ifdef HAVE_SAVED_back_trace
  8705. extern per_thread p_backtrace_t saved_back_trace;
  8706. #define SAVE_back_trace() saved_back_trace = back_trace
  8707. #define RESTORE_back_trace() back_trace = saved_back_trace
  8708. #else
  8709. #define SAVE_back_trace()
  8710. #define RESTORE_back_trace()
  8711. #endif
  8712. #define SAVE_GLOBALS() SAVE_mv_count(); SAVE_value1(); SAVE_back_trace();
  8713. #define RESTORE_GLOBALS() RESTORE_mv_count(); RESTORE_value1(); RESTORE_back_trace();
  8714. #if defined(HAVE_SAVED_STACK)
  8715. extern per_thread gcv_object_t* saved_STACK;
  8716. #define begin_call() SAVE_GLOBALS(); saved_STACK = STACK
  8717. #define end_call() RESTORE_GLOBALS(); saved_STACK = (gcv_object_t*)NULL
  8718. #define begin_callback() SAVE_REGISTERS( STACK = saved_STACK; ); end_call()
  8719. #define end_callback() SAVE_GLOBALS(); RESTORE_REGISTERS( saved_STACK = STACK; )
  8720. #else
  8721. #define begin_call() SAVE_GLOBALS()
  8722. #define end_call() RESTORE_GLOBALS()
  8723. #define begin_callback() SAVE_REGISTERS(;); end_call()
  8724. #define end_callback() SAVE_GLOBALS(); RESTORE_REGISTERS(;)
  8725. #endif
  8726. %% #ifdef HAVE_SAVED_mv_count
  8727. %% puts("extern uintC saved_mv_count;");
  8728. %% #endif
  8729. %% #ifdef HAVE_SAVED_value1
  8730. %% puts("extern object saved_value1;");
  8731. %% #endif
  8732. %% #ifdef HAVE_SAVED_back_trace
  8733. %% puts("extern p_backtrace_t saved_back_trace;");
  8734. %% #endif
  8735. %% #if defined(HAVE_SAVED_STACK)
  8736. %% puts("extern gcv_object_t* saved_STACK;");
  8737. %% #endif
  8738. %% export_def(begin_call());
  8739. %% export_def(end_call());
  8740. %% export_def(begin_callback());
  8741. %% export_def(end_callback());
  8742. /* Every OS-call (or a sequence thereof) has to be framed with
  8743. begin_system_call();
  8744. and
  8745. end_system_call();
  8746. Purpose: The STACK - if it resides in a register -
  8747. should be brought to a halfway recent value,
  8748. if an interrupt happens during the corresponding timespan. */
  8749. #
  8750. /* While a break-semaphore has been set, you don't have to use the macros
  8751. because of that. */
  8752. #ifdef NO_ASYNC_INTERRUPTS
  8753. /* NO_ASYNC_INTERRUPTS: if we don't react to asynchronous Interrupts,
  8754. the program can't be interruped.. */
  8755. #define begin_system_call()
  8756. #define end_system_call()
  8757. #else
  8758. #define begin_system_call() begin_call()
  8759. #define end_system_call() end_call()
  8760. #endif
  8761. /* The same holds for setjmp()/longjmp(). Here we avoid an unneeded overhead
  8762. if at all possible.
  8763. You don't have to use these macros when a break-semaphore has been
  8764. set. */
  8765. #if 0
  8766. /* Disassembly of setjmp() and longjmp() shows, that the STACK-register
  8767. isn't used arbitrarily. */
  8768. #define begin_setjmp_call()
  8769. #define end_setjmp_call()
  8770. #define begin_longjmp_call()
  8771. #define end_longjmp_call()
  8772. #elif defined(I80386) && (defined(UNIX_LINUX) || defined(UNIX_GNU))
  8773. /* Disassembly of setjmp() shows, that the STACK-register %ebx
  8774. isn't used arbitrarily. */
  8775. #define begin_setjmp_call()
  8776. #define end_setjmp_call()
  8777. #define begin_longjmp_call() begin_system_call()
  8778. #define end_longjmp_call() end_system_call()
  8779. #else
  8780. #define begin_setjmp_call() begin_system_call()
  8781. #define end_setjmp_call() end_system_call()
  8782. #define begin_longjmp_call() begin_system_call()
  8783. #define end_longjmp_call() end_system_call()
  8784. #endif
  8785. /* The same holds for arithmetics-functions that use the STACK_registers.
  8786. On I80386 (%ebx) these are SHIFT_LOOPS, MUL_LOOPS, DIV_LOOPS. */
  8787. #if defined(I80386) && !defined(NO_ARI_ASM) && defined(HAVE_SAVED_STACK)
  8788. #define begin_arith_call() begin_system_call()
  8789. #define end_arith_call() end_system_call()
  8790. #else
  8791. #define begin_arith_call()
  8792. #define end_arith_call()
  8793. #endif
  8794. %% export_def(begin_system_call());
  8795. %% export_def(end_system_call());
  8796. #if defined(HAVE_STACK_OVERFLOW_RECOVERY)
  8797. /* Detection of SP-overflow through a Guard-Page or other mechanisms. */
  8798. #define NOCOST_SP_CHECK
  8799. #else
  8800. /* The OS is responsible for the SP.
  8801. From where should we get a reasonable value for SP_bound? */
  8802. #define NO_SP_CHECK
  8803. #endif
  8804. /* Tests for SP-overflow.
  8805. check_SP(); tests for overflow
  8806. check_SP_notUNIX(); dito, except when a temporary overflow doesn't matter */
  8807. #define check_SP() if (SP_overflow()) SP_ueber()
  8808. #if !(defined(NO_SP_CHECK) || defined(NOCOST_SP_CHECK))
  8809. #ifdef SP_DOWN
  8810. #define SP_overflow() ( (aint)SP() < (aint)SP_bound )
  8811. #endif
  8812. #ifdef SP_UP
  8813. #define SP_overflow() ( (aint)SP() > (aint)SP_bound )
  8814. #endif
  8815. #else /* NO_SP_CHECK || NOCOST_SP_CHECK */
  8816. #define SP_overflow() false
  8817. #ifdef NOCOST_SP_CHECK
  8818. #ifdef WIN32_NATIVE
  8819. #ifdef SP_DOWN
  8820. #define near_SP_overflow() ( (aint)SP() < (aint)SP_bound+0x1000 )
  8821. #endif
  8822. #ifdef SP_UP
  8823. #define near_SP_overflow() ( (aint)SP() > (aint)SP_bound-0x1000 )
  8824. #endif
  8825. #else
  8826. extern bool near_SP_overflow (void);
  8827. #endif
  8828. #endif
  8829. #endif
  8830. extern per_thread void* SP_bound;
  8831. nonreturning_function(extern, SP_ueber, (void));
  8832. #ifdef UNIX
  8833. #define check_SP_notUNIX()
  8834. #else
  8835. #define check_SP_notUNIX() check_SP()
  8836. #endif
  8837. /* Tests for STACK-overflow.
  8838. check_STACK(); */
  8839. #define check_STACK() if (STACK_overflow()) STACK_ueber()
  8840. #ifdef STACK_DOWN
  8841. #define STACK_overflow() ( (aint)STACK < (aint)STACK_bound )
  8842. #endif
  8843. #ifdef STACK_UP
  8844. #define STACK_overflow() ( (aint)STACK > (aint)STACK_bound )
  8845. #endif
  8846. extern per_thread void* STACK_bound;
  8847. extern per_thread void* STACK_start;
  8848. nonreturning_function(extern, STACK_ueber, (void));
  8849. %% #if notused
  8850. %% export_def(check_STACK());
  8851. %% export_def(STACK_overflow());
  8852. %% export_def(get_space_on_STACK(n));
  8853. %% puts("extern void* STACK_bound;");
  8854. %% puts("nonreturning_function(extern, STACK_ueber, (void));");
  8855. %% #endif
  8856. /* Tests, if there are still n Bytes free on the STACK.
  8857. get_space_on_STACK(n); */
  8858. #ifdef STACK_DOWN
  8859. #define get_space_on_STACK(n) \
  8860. if ( (aint)STACK < (aint)STACK_bound + (aint)(n) ) STACK_ueber()
  8861. #else
  8862. #define get_space_on_STACK(n) \
  8863. if ( (aint)STACK + (aint)(n) > (aint)STACK_bound ) STACK_ueber()
  8864. #endif
  8865. /* Exit the LISP-Interpreter
  8866. quit();
  8867. > final_exitcode: 0 for a normal end, >0 for failure, -signum for a signal */
  8868. nonreturning_function(extern, quit, (void));
  8869. extern int final_exitcode;
  8870. /* is used by CONTROL */
  8871. /* Error message if an unreachable program part has been reached.
  8872. Does not return.
  8873. error_notreached(file,line);
  8874. > file: Filename (with quotation marks) as constant ASCIZ-String
  8875. > line: line number */
  8876. nonreturning_function(extern, error_notreached, (const char * file, uintL line));
  8877. /* used by all modules */
  8878. %% puts("nonreturning_function(extern, error_notreached, (const char * file, uintL line));");
  8879. /* Language that's used to communicate with the user: */
  8880. #ifdef LANGUAGE_STATIC
  8881. #if ENGLISH
  8882. #define GETTEXT(english) english
  8883. #define GETTEXTL(english) english
  8884. #endif
  8885. #else
  8886. #define language_english 0
  8887. #ifndef GNU_GETTEXT
  8888. /* Language is determined at runtime by the variable language. */
  8889. extern uintL language;
  8890. #define ENGLISH (language==language_english)
  8891. #define GETTEXT(english) english
  8892. #define GETTEXTL(english) english
  8893. #else /* GNU_GETTEXT */
  8894. #ifndef COMPILE_STANDALONE
  8895. #include <libintl.h>
  8896. #endif
  8897. /* Fetch the message translations from a message catalog. */
  8898. #ifndef gettext /* Sometimes `gettext' is a macro... */
  8899. extern char* gettext (const char * msgid);
  8900. #endif
  8901. extern const char * clgettext (const char * msgid);
  8902. extern const char * clgettextl (const char * msgid);
  8903. /* GETTEXT(english_message) fetches the translation of english_message
  8904. and returns it in UTF-8 (if UNICODE is defined).
  8905. GETTEXTL(english_message) fetches the translation of english_message
  8906. and returns it in the locale encoding.
  8907. GETTEXT and GETTEXTL are special tags recognized by clisp-xgettext. We
  8908. choose English because it's the only language understood by all CLISP
  8909. developers. */
  8910. #define GETTEXT clgettext
  8911. #define GETTEXTL clgettextl
  8912. #endif
  8913. /* init the language and the locale */
  8914. extern void init_language (const char*, const char*);
  8915. #endif
  8916. %% #if !defined(LANGUAGE_STATIC) && defined(GNU_GETTEXT)
  8917. %% puts("#define GNU_GETTEXT");
  8918. %% puts("#ifndef COMPILE_STANDALONE");
  8919. %% puts("#include <libintl.h>");
  8920. %% puts("#endif");
  8921. %% puts("extern const char * clgettext (const char * msgid);");
  8922. %% export_def(GETTEXT);
  8923. %% #else
  8924. %% export_def(GETTEXT(english));
  8925. %% #endif
  8926. /* Fetch the message translations of a string: "CL String getTEXT"
  8927. CLSTEXT(string)
  8928. > obj: C string
  8929. < result: String
  8930. can trigger GC */
  8931. extern maygc object CLSTEXT (const char*);
  8932. %% #ifndef LANGUAGE_STATIC
  8933. %% #ifndef GNU_GETTEXT
  8934. %% emit_define("CLSTEXT","ascii_to_string");
  8935. %% #else
  8936. %% puts("extern object CLSTEXT (const char* asciz);");
  8937. %% #endif
  8938. %% #endif
  8939. /* Fetch the "translation" of a Lisp object: "CL Object getTEXT"
  8940. CLOTEXT(string)
  8941. > obj: String
  8942. can trigger GC */
  8943. extern maygc object CLOTEXT (const char*);
  8944. /* Print a Lisp object in Lisp notation relatively directly
  8945. through the operating system:
  8946. object_out(obj);
  8947. can trigger GC */
  8948. extern maygc object object_out (object obj);
  8949. /* can trigger GC
  8950. print the object with label, file name and line number
  8951. this can trigger GC, but will save and restore OBJ */
  8952. #define OBJECT_OUT(obj,label) \
  8953. (printf("[%s:%d] %s: %s:\n",__FILE__,__LINE__,STRING(obj),label), \
  8954. obj=object_out(obj))
  8955. /* print the object to a C stream - not all objects can be handled yet!
  8956. non-consing, STACK non-modifying */
  8957. extern maygc object nobject_out (FILE* out, object obj);
  8958. #define NOBJECT_OUT(obj,label) \
  8959. (printf("[%s:%d] %s: %s: ",__FILE__,__LINE__,STRING(obj),label), \
  8960. nobject_out(stdout,obj), printf("\n"))
  8961. /* used for debugging purposes */
  8962. %% puts("extern object object_out (object obj);");
  8963. %% puts("#define OBJECT_OUT(obj,label) (printf(\"[%s:%d] %s: %s:\\n\",__FILE__,__LINE__,STRING(obj),label),obj=object_out(obj))");
  8964. /* After allocating memory for an object, add the type infos. */
  8965. #ifdef TYPECODES
  8966. #define bias_type_pointer_object(bias,type,ptr) type_pointer_object(type,ptr)
  8967. #else
  8968. #ifdef WIDE_AUXI
  8969. #define bias_type_pointer_object(bias,type,ptr) as_object_with_auxi((aint)(ptr)+(bias))
  8970. #else
  8971. #define bias_type_pointer_object(bias,type,ptr) as_object((oint)(ptr)+(bias))
  8972. #endif
  8973. #endif
  8974. /* used by SPVW, macros SP_allocate_bit_vector, SP_allocate_string */
  8975. /* UP: executes a Garbage Collection
  8976. gar_col(level);
  8977. > level: if 1, also drop all jitc code
  8978. can trigger GC */
  8979. extern maygc void gar_col (int level);
  8980. /* is used by DEBUG */
  8981. /* GC-statistics */
  8982. extern uintL gc_count;
  8983. extern uintL2 gc_space;
  8984. extern internal_time_t gc_time;
  8985. /* is used by TIME */
  8986. /* UP: allocates a Cons
  8987. allocate_cons()
  8988. < result: pointer to a new CONS, with CAR and CDR =NIL
  8989. can trigger GC */
  8990. extern maygc object allocate_cons (void);
  8991. /* is used by LIST, SEQUENCE, PACKAGE, EVAL, CONTROL, RECORD,
  8992. PREDTYPE, IO, STREAM, PATHNAME, SYMBOL, ARRAY, LISPARIT */
  8993. %% puts("extern object allocate_cons (void);");
  8994. /* UP: Returns a newly created uninterned symbol with a given Printname.
  8995. make_symbol(string)
  8996. > string: immutable Simple-String
  8997. < result: new symbol with this name, with Home-Package=NIL.
  8998. can trigger GC */
  8999. extern maygc object make_symbol (object string);
  9000. /* is used by PACKAGE, IO, SYMBOL */
  9001. %% #if notused
  9002. %% puts("extern object make_symbol (object string);");
  9003. %% #endif
  9004. /* UP: allocates a general vector
  9005. allocate_vector(len)
  9006. > len: length of the vector
  9007. < result: fresh simple general vector (elements are initialized with NIL)
  9008. can trigger GC */
  9009. extern maygc object allocate_vector (uintL len);
  9010. /* is used by ARRAY, IO, EVAL, PACKAGE, CONTROL, HASHTABL */
  9011. %% puts("extern object allocate_vector (uintL len);");
  9012. /* Function: Allocates a bit/byte vector.
  9013. allocate_bit_vector(atype,len)
  9014. > uintB atype: Atype_nBit
  9015. > uintL len: length (number of n-bit blocks)
  9016. < result: fresh simple bit/byte-vector of the given length
  9017. can trigger GC */
  9018. extern maygc object allocate_bit_vector (uintB atype, uintL len);
  9019. /* is used by ARRAY, IO, RECORD, LISPARIT, STREAM, CLX */
  9020. %% puts("extern object allocate_bit_vector (uintB atype, uintL len);");
  9021. /* Macro: Allocates a 8bit-vector on the stack, with dynamic extent.
  9022. { var DYNAMIC_8BIT_VECTOR(obj,len);
  9023. ...
  9024. FREE_DYNAMIC_8BIT_VECTOR(obj);
  9025. }
  9026. > uintL len: length (number of bytes)
  9027. < object obj: simple-8bit-vector with dynamic extent
  9028. (may or may not be heap-allocated, therefore not GC-invariant)
  9029. can trigger GC */
  9030. #if defined(SPVW_PURE) || ((((STACK_ADDRESS_RANGE << addr_shift) >> garcol_bit_o) & 1) != 0)
  9031. /* No way to allocate a Lisp object on the stack. */
  9032. #define DYNAMIC_8BIT_VECTOR(objvar,len) \
  9033. var uintL objvar##_len = (len); \
  9034. var object objvar = O(dynamic_8bit_vector); \
  9035. O(dynamic_8bit_vector) = NIL; \
  9036. if (!(simple_bit_vector_p(Atype_8Bit,objvar) && (Sbvector_length(objvar) >= objvar##_len))) \
  9037. objvar = allocate_bit_vector(Atype_8Bit,objvar##_len); \
  9038. GCTRIGGER1(objvar)
  9039. #define FREE_DYNAMIC_8BIT_VECTOR(objvar) \
  9040. O(dynamic_8bit_vector) = objvar
  9041. #else
  9042. /* Careful: Fill GCself with pointers to itself, so that GC will leave
  9043. pointers to this object untouched. */
  9044. #ifdef TYPECODES
  9045. #define DYNAMIC_8BIT_VECTOR(objvar,len) \
  9046. DYNAMIC_ARRAY(objvar##_storage,object,ceiling((uintL)(len)+offsetofa(sbvector_,data),sizeof(gcv_object_t))); \
  9047. var object objvar = ((Sbvector)objvar##_storage)->GCself = bias_type_pointer_object(varobject_bias,sb8vector_type,(Sbvector)objvar##_storage); \
  9048. ((Sbvector)objvar##_storage)->length = (len); \
  9049. GCTRIGGER1(objvar)
  9050. #else
  9051. #define DYNAMIC_8BIT_VECTOR(objvar,len) \
  9052. DYNAMIC_ARRAY(objvar##_storage,object,ceiling((uintL)(len)+offsetofa(sbvector_,data)+varobjects_misaligned,sizeof(gcv_object_t))); \
  9053. var object* objvar##_address = (object*)((uintP)objvar##_storage | varobjects_misaligned); \
  9054. var object objvar = ((Sbvector)objvar##_address)->GCself = bias_type_pointer_object(varobject_bias,sb8vector_type,(Sbvector)objvar##_address); \
  9055. ((Sbvector)objvar##_address)->tfl = vrecord_tfl(Rectype_Sb8vector,len); \
  9056. GCTRIGGER1(objvar)
  9057. #endif
  9058. #define FREE_DYNAMIC_8BIT_VECTOR(objvar) \
  9059. FREE_DYNAMIC_ARRAY(objvar##_storage)
  9060. #endif
  9061. /* used by STREAM, PATHNAME */
  9062. /* Macro: Wraps a GC-invariant uintB* pointer in a fake simple-8bit-vector.
  9063. FAKE_8BIT_VECTOR(ptr)
  9064. > uintB* ptr: pointer to GC-invariant data
  9065. < gcv_object_t obj: a fake simple-8bit-vector,
  9066. with TheSbvector(obj)->data == ptr,
  9067. that must *not* be stored in GC-visible locations */
  9068. #ifdef TYPECODES
  9069. #define FAKE_8BIT_VECTOR(ptr) \
  9070. type_pointer_object(0, (const char*)(ptr) - offsetofa(sbvector_,data))
  9071. #else
  9072. #define FAKE_8BIT_VECTOR(ptr) \
  9073. fake_gcv_object((aint)((const char*)(ptr) - offsetofa(sbvector_,data)) + varobject_bias)
  9074. #endif
  9075. #if !defined(UNICODE) || defined(HAVE_SMALL_SSTRING)
  9076. /* UP, provides 8-bit character string
  9077. allocate_s8string(len)
  9078. > len: length of the string (in characters), must be <= stringsize_limit_1
  9079. < result: new 8-bit character simple-string (LISP-object)
  9080. can trigger GC */
  9081. extern maygc object allocate_s8string (uintL len);
  9082. /* used by */
  9083. #endif
  9084. #if defined(UNICODE) && !defined(HAVE_SMALL_SSTRING)
  9085. #define allocate_s8string(len) allocate_s32string(len)
  9086. #endif
  9087. %% #if !defined(UNICODE)
  9088. %% puts("extern object allocate_s8string (uintL len);");
  9089. %% #endif
  9090. #if !defined(UNICODE) || defined(HAVE_SMALL_SSTRING)
  9091. /* UP, provides immutable 8-bit character string
  9092. allocate_imm_s8string(len)
  9093. > len: length of the string (in characters), must be <= stringsize_limit_1
  9094. < result: new immutable 8-bit character simple-string (LISP-object)
  9095. can trigger GC */
  9096. extern maygc object allocate_imm_s8string (uintL len);
  9097. /* used by */
  9098. #endif
  9099. #ifdef HAVE_SMALL_SSTRING
  9100. /* UP, provides 16-bit character string
  9101. allocate_s16string(len)
  9102. > len: length of the string (in characters), must be <= stringsize_limit_1
  9103. < result: new 16-bit character simple-string (LISP-object)
  9104. can trigger GC */
  9105. extern maygc object allocate_s16string (uintL len);
  9106. /* used by */
  9107. #endif
  9108. #if defined(UNICODE) && !defined(HAVE_SMALL_SSTRING)
  9109. #define allocate_s16string(len) allocate_s32string(len)
  9110. #endif
  9111. #ifdef HAVE_SMALL_SSTRING
  9112. /* UP, provides immutable 16-bit character string
  9113. allocate_imm_s16string(len)
  9114. > len: length of the string (in characters), must be <= stringsize_limit_1
  9115. < result: new immutable 16-bit character simple-string (LISP-object)
  9116. can trigger GC */
  9117. extern maygc object allocate_imm_s16string (uintL len);
  9118. /* used by */
  9119. #endif
  9120. #ifdef UNICODE
  9121. /* UP, provides 32-bit character string
  9122. allocate_s32string(len)
  9123. > len: length of the string (in characters), must be <= stringsize_limit_1
  9124. < result: new 32-bit character simple-string (LISP-object)
  9125. can trigger GC */
  9126. extern maygc object allocate_s32string (uintL len);
  9127. #endif
  9128. %% #ifdef UNICODE
  9129. %% puts("extern object allocate_s32string (uintL len);");
  9130. %% #endif
  9131. #ifdef UNICODE
  9132. /* UP, provides immutable 32-bit character string
  9133. allocate_imm_s32string(len)
  9134. > len: length of the string (in characters), must be <= stringsize_limit_1
  9135. < result: new immutable 32-bit character simple-string (LISP-object)
  9136. can trigger GC */
  9137. extern maygc object allocate_imm_s32string (uintL len);
  9138. #endif
  9139. /* UP: allocates String
  9140. allocate_string(len)
  9141. > len: length of the Strings (in Characters), must be <= stringsize_limit_1
  9142. < result: new Normal-Simple-String (LISP-object)
  9143. can trigger GC */
  9144. #ifdef UNICODE
  9145. #define allocate_string(len) allocate_s32string(len)
  9146. #else
  9147. #define allocate_string(len) allocate_s8string(len)
  9148. #endif
  9149. /* is used by ARRAY, CHARSTRG, STREAM, PATHNAME */
  9150. %% export_def(allocate_string(len));
  9151. /* Macro: Allocates a normal string on the stack, with dynamic extent.
  9152. { var DYNAMIC_STRING(obj,len);
  9153. ...
  9154. FREE_DYNAMIC_STRING(obj);
  9155. }
  9156. > uintL len: length (number of characters)
  9157. < object obj: normal-simple-string with dynamic extent
  9158. (may or may not be heap-allocated, therefore not GC-invariant)
  9159. can trigger GC */
  9160. #if defined(SPVW_PURE) || ((((STACK_ADDRESS_RANGE << addr_shift) >> garcol_bit_o) & 1) != 0)
  9161. /* No way to allocate a Lisp object on the stack. */
  9162. #define DYNAMIC_STRING(objvar,len) \
  9163. var uintL objvar##_len = (len); \
  9164. var object objvar = O(dynamic_string); \
  9165. O(dynamic_string) = NIL; \
  9166. if (!(simple_string_p(objvar) && (Sstring_length(objvar) >= objvar##_len))) { \
  9167. if (objvar##_len > stringsize_limit_1) \
  9168. error_stringsize(objvar##_len); \
  9169. objvar = allocate_string(objvar##_len); \
  9170. } \
  9171. GCTRIGGER1(objvar)
  9172. #define FREE_DYNAMIC_STRING(objvar) \
  9173. O(dynamic_string) = objvar;
  9174. #else
  9175. /* Careful: Fill GCself with pointers to itself, so that GC will leave
  9176. pointers to this object untouched. */
  9177. #ifdef UNICODE
  9178. #define DYNAMIC_STRING(objvar,len) \
  9179. DYNAMIC_ARRAY(objvar##_storage,object,ceiling((uintL)(len)*sizeof(chart)+offsetofa(s32string_,data)+varobjects_misaligned,sizeof(gcv_object_t))); \
  9180. var object* objvar##_address = (object*)((uintP)objvar##_storage | varobjects_misaligned); \
  9181. var object objvar = ((Sstring)objvar##_address)->GCself = bias_type_pointer_object(varobject_bias,sstring_type,(Sstring)objvar##_address); \
  9182. ((Sstring)objvar##_address)->tfl = sstring_tfl(Sstringtype_32Bit,0,0,len); \
  9183. GCTRIGGER1(objvar)
  9184. #else
  9185. #define DYNAMIC_STRING(objvar,len) \
  9186. DYNAMIC_ARRAY(objvar##_storage,object,ceiling((uintL)(len)*sizeof(chart)+offsetofa(s8string_,data)+varobjects_misaligned,sizeof(gcv_object_t))); \
  9187. var object* objvar##_address = (object*)((uintP)objvar##_storage | varobjects_misaligned); \
  9188. var object objvar = ((Sstring)objvar##_address)->GCself = bias_type_pointer_object(varobject_bias,sstring_type,(Sstring)objvar##_address); \
  9189. ((Sstring)objvar##_address)->tfl = sstring_tfl(Sstringtype_8Bit,0,0,len); \
  9190. GCTRIGGER1(objvar)
  9191. #endif
  9192. #define FREE_DYNAMIC_STRING(objvar) \
  9193. FREE_DYNAMIC_ARRAY(objvar##_storage)
  9194. #endif
  9195. /* used by LISPARIT */
  9196. /* UP: allocates an immutable String
  9197. allocate_imm_string(len)
  9198. > len: length of the String (in Characters)
  9199. < result: new immutable Normal-Simple-String (LISP-object)
  9200. can trigger GC */
  9201. #ifdef UNICODE
  9202. #define allocate_imm_string(len) allocate_imm_s32string(len)
  9203. #else
  9204. #define allocate_imm_string(len) allocate_imm_s8string(len)
  9205. #endif
  9206. /* is used by CHARSTRG */
  9207. #ifdef HAVE_SMALL_SSTRING
  9208. /* UP: Changes the allocation of a Small-String to an Sistring, while
  9209. copying the contents to a fresh normal string.
  9210. reallocate_small_string(string)
  9211. > string: a nonempty Small-String
  9212. > newtype: new wider string type, Sstringtype_16Bit or Sstringtype_32Bit
  9213. < result: an Sistring pointing to a wider String
  9214. can trigger GC */
  9215. extern maygc object reallocate_small_string (object string, uintB newtype);
  9216. /* is used by ARRAY */
  9217. #endif
  9218. /* Attempts to reallocate a simple-string, for debugging purposes.
  9219. DBGREALLOC(string); */
  9220. #if defined(DEBUG_SMALL_SSTRING) && defined(HAVE_SMALL_SSTRING)
  9221. #define DBGREALLOC(string) \
  9222. if (simple_string_p(string) && !sstring_reallocatedp(TheSstring(string)) \
  9223. && !sstring_immutable(TheSstring(string)) \
  9224. && sstring_eltype(TheSstring(string)) != Sstringtype_32Bit \
  9225. && sstring_length(TheSstring(string)) > 0) \
  9226. string = reallocate_small_string(string,sstring_eltype(TheSstring(string))+1)/*;*/
  9227. #else
  9228. #define DBGREALLOC(string) (void)0 /*nop*/
  9229. #endif
  9230. /* UP: allocates indirect array
  9231. allocate_iarray(flags,rank,type)
  9232. > uintB flags: Flags
  9233. > uintC (actually uintWC) rank: rank
  9234. > tint type: Typinfo
  9235. < result: LISP-object Array
  9236. can trigger GC */
  9237. extern maygc object allocate_iarray (uintB flags, uintC rank, tint type);
  9238. /* is used by ARRAY, IO */
  9239. /* UP: allocates Long-Record
  9240. allocate_lrecord(rectype,reclen,type)
  9241. > sintB rectype: further type-info
  9242. > uintL reclen: length
  9243. > tint type: type-info
  9244. < result: LISP-object Record (elements are initialized with NIL)
  9245. can trigger GC */
  9246. #ifdef TYPECODES
  9247. extern maygc object allocate_lrecord (uintB rectype, uintL reclen, tint type);
  9248. #else
  9249. #define allocate_lrecord(rectype,reclen,type) /* ignore type */ \
  9250. allocate_lrecord_(rectype,reclen)
  9251. extern object allocate_lrecord_ (uintB rectype, uintL reclen);
  9252. #endif
  9253. /* is used by WEAK */
  9254. /* UP: allocates Simple-Record
  9255. allocate_srecord(flags,rectype,reclen,type)
  9256. > uintB flags: Flags
  9257. > sintB rectype: further type-info
  9258. > uintC (actually uintW) reclen: length
  9259. > tint type: type-info
  9260. < result: LISP-object Record (elements are initialized with NIL)
  9261. can trigger GC */
  9262. #ifdef TYPECODES
  9263. #define allocate_srecord(flags,rectype,reclen,type) \
  9264. allocate_srecord_( \
  9265. (BIG_ENDIAN_P ? (uintW)(flags)+((uintW)(uintB)(rectype)<<intBsize) \
  9266. : ((uintW)(flags)<<intBsize)+(uintW)(uintB)(rectype)),\
  9267. reclen, \
  9268. type)
  9269. extern maygc object allocate_srecord_ (uintW flags_rectype, uintC reclen, tint type);
  9270. #else
  9271. #define allocate_srecord(flags,rectype,reclen,type) /* ignore type */ \
  9272. allocate_srecord_(((uintW)(flags)<<8)+(uintW)(uintB)(rectype),reclen)
  9273. extern maygc object allocate_srecord_ (uintW flags_rectype, uintC reclen);
  9274. #endif
  9275. /* is used by RECORD, EVAL */
  9276. /* UP: allocates Extended-Record
  9277. allocate_xrecord(flags,rectype,reclen,recxlen,type)
  9278. > uintB flags: Flags
  9279. > sintB rectype: further type-info
  9280. > uintC (actually uintB) reclen: length
  9281. > uintC (actually uintB) recxlen: extra-length
  9282. > tint type: Typinfo
  9283. < result: LISP-object Record (elements are initialized with NIL resp. 0)
  9284. can trigger GC */
  9285. #ifdef TYPECODES
  9286. #define allocate_xrecord(flags,rectype,reclen,recxlen,type) \
  9287. allocate_xrecord_( \
  9288. (BIG_ENDIAN_P ? (uintW)(flags)+((uintW)(uintB)(rectype)<<intBsize) \
  9289. : ((uintW)(flags)<<intBsize)+(uintW)(uintB)(rectype)),\
  9290. reclen, \
  9291. recxlen, \
  9292. type)
  9293. extern maygc object allocate_xrecord_ (uintW flags_rectype, uintC reclen, uintC recxlen, tint type);
  9294. #else
  9295. #define allocate_xrecord(flags,rectype,reclen,recxlen,type) \
  9296. allocate_xrecord_((((uintW)(flags)<<8)+(uintW)(uintB)(rectype)),reclen,recxlen)
  9297. extern maygc object allocate_xrecord_ (uintW flags_rectype, uintC reclen, uintC recxlen);
  9298. #endif
  9299. /* is used by */
  9300. /* UP: allocates Closure
  9301. allocate_closure(reclen)
  9302. > uintC reclen: length
  9303. < result: LISP-object Closure (elements are initialized with NIL) */
  9304. #define allocate_closure(reclen,flags) \
  9305. allocate_srecord(flags,Rectype_Closure,reclen,closure_type)
  9306. /* is used by EVAL, RECORD */
  9307. /* copy a section of memory */
  9308. #define copy_mem_b(dest,orig,len) /* bytes */ \
  9309. do { var char* newptr = (char*)(dest); \
  9310. var const char* oldptr = (const char*)(orig); \
  9311. var uintL count; \
  9312. var uintL leng = (len); \
  9313. dotimespL(count,leng,{ *newptr++ = *oldptr++; }); \
  9314. } while(0)
  9315. #define copy_mem_o(dest,orig,len) /* objects */ \
  9316. do { var gcv_object_t* newptr = (dest); \
  9317. var const gcv_object_t* oldptr = (orig); \
  9318. var uintC count; \
  9319. var uintC leng = (len); \
  9320. dotimespC(count,leng,{ *newptr++ = *oldptr++; }); \
  9321. } while(0)
  9322. #if 0 /* the libc alternative turns out to be ~3-5% slower */
  9323. #define copy_mem_b(dest,orig,len) \
  9324. do { begin_system_call(); memcpy(dest,orig,len); \
  9325. end_system_call(); } while(0)
  9326. #define copy_mem_o(dest,orig,len) \
  9327. do { begin_system_call(); memcpy(dest,orig,(len)*sizeof(gcv_object_t)); \
  9328. end_system_call(); } while(0)
  9329. #endif
  9330. /* Copying a compiled closure:
  9331. newclos = allocate_cclosure_copy(oldclos);
  9332. can trigger GC */
  9333. #define allocate_cclosure_copy(oldclos) \
  9334. allocate_closure(Cclosure_length(oldclos),Closure_flags(oldclos))
  9335. /* do_cclosure_copy(newclos,oldclos); */
  9336. #define do_cclosure_copy(newclos,oldclos) \
  9337. copy_mem_o(((Srecord)TheCclosure(newclos))->recdata, \
  9338. ((Srecord)TheCclosure(oldclos))->recdata, \
  9339. Cclosure_length(oldclos))
  9340. /* is used by EVAL, IO, RECORD */
  9341. /* UP: allocates Structure
  9342. allocate_structure(reclen)
  9343. > uintC reclen: length
  9344. < result: LISP-Object Structure (Elements are initialized with NIL)
  9345. can trigger GC */
  9346. #ifdef case_structure
  9347. #define allocate_structure(reclen) \
  9348. allocate_srecord(0,Rectype_Structure,reclen,structure_type)
  9349. #else
  9350. #define allocate_structure(reclen) \
  9351. allocate_srecord(0,Rectype_Structure,reclen,orecord_type)
  9352. #endif
  9353. /* is used by RECORD */
  9354. /* UP: allocates Stream
  9355. allocate_stream(strmflags,strmtype,reclen,recxlen)
  9356. > uintB strmflags: Flags
  9357. > uintB strmtype: further type-info
  9358. > uintC reclen: length in objects
  9359. > uintC recxlen: extra-length in bytes
  9360. < result: LISP-object Stream (elements are initialized with NIL)
  9361. can trigger GC */
  9362. #ifdef case_stream
  9363. #define allocate_stream(strmflags,strmtype,reclen,recxlen) \
  9364. allocate_xrecord(strmflags | strmflags_open_B,strmtype,reclen,recxlen,stream_type)
  9365. #else
  9366. extern maygc object allocate_stream (uintB strmflags, uintB strmtype, uintC reclen, uintC recxlen);
  9367. #endif
  9368. /* is used by STREAM */
  9369. /* UP: allocates Package
  9370. allocate_package()
  9371. < result: LISP-object Package
  9372. can trigger GC */
  9373. #define allocate_package() \
  9374. allocate_xrecord(0,Rectype_Package,package_length,0,orecord_type)
  9375. /* is used by PACKAGE */
  9376. /* UP: allocates Hash-Table
  9377. allocate_hash_table()
  9378. < result: LISP-object Hash-Table
  9379. can trigger GC */
  9380. #define allocate_hash_table() \
  9381. allocate_xrecord(0,Rectype_Hashtable,hashtable_length,hashtable_xlength, \
  9382. orecord_type)
  9383. /* is used by */
  9384. /* UP: allocates Readtable
  9385. allocate_readtable()
  9386. < result: LISP-object Readtable
  9387. can trigger GC */
  9388. #define allocate_readtable() \
  9389. allocate_xrecord(0,Rectype_Readtable,readtable_length,0,orecord_type)
  9390. /* is used by IO */
  9391. /* UP: allocates Pathname
  9392. allocate_pathname()
  9393. < result: LISP-object Pathname
  9394. can trigger GC */
  9395. #define allocate_pathname() \
  9396. allocate_xrecord(0,Rectype_Pathname,pathname_length,0,orecord_type)
  9397. /* is used by PATHNAME */
  9398. #ifdef LOGICAL_PATHNAMES
  9399. /* UP: allocates Logical Pathname
  9400. allocate_logpathname()
  9401. < result: LISP-object Logical Pathname
  9402. can trigger GC */
  9403. #define allocate_logpathname() \
  9404. allocate_xrecord(0,Rectype_Logpathname,logpathname_length,0,orecord_type)
  9405. /* is used by PATHNAME */
  9406. #endif
  9407. /* UP: allocates Random-State
  9408. allocate_random_state()
  9409. < result: LISP-object Random-State
  9410. can trigger GC */
  9411. #define allocate_random_state() \
  9412. allocate_xrecord(0,Rectype_Random_State,random_state_length,0,orecord_type)
  9413. /* is used by IO, LISPARIT */
  9414. /* UP: allocates Byte
  9415. allocate_byte()
  9416. < result: LISP-object Byte
  9417. can trigger GC */
  9418. #define allocate_byte() \
  9419. allocate_xrecord(0,Rectype_Byte,byte_length,0,orecord_type)
  9420. /* is used by LISPARIT */
  9421. /* UP: allocates Fsubr
  9422. allocate_fsubr()
  9423. < result: LISP-object Fsubr
  9424. can trigger GC */
  9425. #define allocate_fsubr() \
  9426. allocate_xrecord(0,Rectype_Fsubr,fsubr_length,fsubr_xlength,orecord_type)
  9427. /* is used by SPVW */
  9428. /* UP: allocates Load-time-Eval
  9429. allocate_loadtimeeval()
  9430. < result: LISP-object Load-time-Eval
  9431. can trigger GC */
  9432. #define allocate_loadtimeeval() \
  9433. allocate_xrecord(0,Rectype_Loadtimeeval,loadtimeeval_length,0,orecord_type)
  9434. /* is used by IO, RECORD */
  9435. /* UP: allocates Symbol-Macro
  9436. allocate_symbolmacro()
  9437. < result: LISP-object Symbol-Macro
  9438. can trigger GC */
  9439. #define allocate_symbolmacro() \
  9440. allocate_xrecord(0,Rectype_Symbolmacro,symbolmacro_length,0,orecord_type)
  9441. /* is used by CONTROL, RECORD */
  9442. /* UP: allocates Global-Symbol-Macro
  9443. allocate_globalsymbolmacro()
  9444. < result: LISP-object Global-Symbol-Macro
  9445. can trigger GC */
  9446. #define allocate_globalsymbolmacro() \
  9447. allocate_xrecord(0,Rectype_GlobalSymbolmacro,globalsymbolmacro_length,0,orecord_type)
  9448. /* is used by RECORD */
  9449. /* UP: allocates a Macro
  9450. allocate_macro()
  9451. < result: a fresh Macro
  9452. can trigger GC */
  9453. #define allocate_macro() \
  9454. allocate_xrecord(0,Rectype_Macro,macro_length,0,orecord_type)
  9455. /* is used by RECORD */
  9456. /* UP: allocates a FunctionMacro
  9457. allocate_functionmacro()
  9458. < result: a fresh FunctionMacro
  9459. can trigger GC */
  9460. #define allocate_functionmacro() \
  9461. allocate_xrecord(0,Rectype_FunctionMacro,functionmacro_length,0,orecord_type)
  9462. /* is used by RECORD */
  9463. /* UP: allocates a BigReadLabel
  9464. allocate_big_read_label()
  9465. < result: a fresh BigReadLabel
  9466. can trigger GC */
  9467. #define allocate_big_read_label() \
  9468. allocate_xrecord(0,Rectype_BigReadLabel,bigreadlabel_length,0,orecord_type)
  9469. /* is used by IO */
  9470. /* UP: allocates an Encoding
  9471. allocate_encoding()
  9472. < result: a fresh Encoding
  9473. can trigger GC */
  9474. #define allocate_encoding() \
  9475. allocate_xrecord(0,Rectype_Encoding,encoding_length,encoding_xlength,orecord_type)
  9476. /* is used by ENCODING */
  9477. #ifdef FOREIGN
  9478. /* UP: allocates a foreign-pointer packing
  9479. allocate_fpointer(foreign)
  9480. > foreign: of Type FOREIGN
  9481. < result: LISP-object, contains the foreign pointer
  9482. can trigger GC */
  9483. extern maygc object allocate_fpointer (FOREIGN foreign);
  9484. /* used by FFI & modules */
  9485. #endif
  9486. %% #ifdef FOREIGN
  9487. %% puts("extern object allocate_fpointer (FOREIGN foreign);");
  9488. %% #endif
  9489. /* UP: allocates foreign address
  9490. allocate_faddress()
  9491. < result: LISP-object foreign address
  9492. can trigger GC */
  9493. #define allocate_faddress() \
  9494. allocate_xrecord(0,Rectype_Faddress,faddress_length,faddress_xlength,orecord_type)
  9495. /* is used by FOREIGN */
  9496. /* UP: allocates foreign variable
  9497. allocate_fvariable()
  9498. < result: LISP-object foreign variable
  9499. can trigger GC */
  9500. #define allocate_fvariable() \
  9501. allocate_xrecord(0,Rectype_Fvariable,fvariable_length,0,orecord_type)
  9502. /* is used by FOREIGN */
  9503. /* UP: allocates foreign function
  9504. allocate_ffunction()
  9505. < result: LISP-object foreign function
  9506. can trigger GC */
  9507. #define allocate_ffunction() \
  9508. allocate_xrecord(0,Rectype_Ffunction,ffunction_length,0,orecord_type)
  9509. /* is used by FOREIGN */
  9510. /* UP: allocates finalizer
  9511. allocate_finalizer()
  9512. < result: LISP-object finalizer
  9513. can trigger GC */
  9514. #define allocate_finalizer() \
  9515. allocate_xrecord(0,Rectype_Finalizer,finalizer_length,0,orecord_type)
  9516. /* is used by RECORD */
  9517. /* UP: allocates Socket-Server
  9518. allocate_socket_server()
  9519. < result: LISP-object Socket-Server */
  9520. #ifdef SOCKET_STREAMS
  9521. #define allocate_socket_server() \
  9522. allocate_xrecord(0,Rectype_Socket_Server,socket_server_length,0,orecord_type)
  9523. #endif
  9524. #ifdef YET_ANOTHER_RECORD
  9525. /* UP: allocates Yetanother
  9526. allocate_yetanother()
  9527. < result: LISP-object Yetanother
  9528. can trigger GC */
  9529. #define allocate_yetanother() \
  9530. allocate_xrecord(0,Rectype_Yetanother,yetanother_length,0,orecord_type)
  9531. /* is used by */
  9532. #endif
  9533. /* UP: allocates handle
  9534. allocate_handle(handle)
  9535. < result: LISP-object, that contains handle
  9536. can trigger GC */
  9537. #ifdef FOREIGN_HANDLE
  9538. /* can trigger GC */
  9539. extern maygc object allocate_handle (Handle handle);
  9540. #else
  9541. #define allocate_handle(handle) fixnum((uintL)(handle))
  9542. #endif
  9543. %% #if defined(FOREIGN_HANDLE)
  9544. %% puts("extern object allocate_handle (Handle handle);");
  9545. %% #else
  9546. %% export_def(allocate_handle(handle));
  9547. %% #endif
  9548. /* UP: allocates Bignum
  9549. allocate_bignum(len,sign)
  9550. > uintC (actually uintWC) len: length of the number (in Digits)
  9551. > sintB sign: flag for sign (0 = +, -1 = -)
  9552. < result: new Bignum (LISP-object)
  9553. can trigger GC */
  9554. extern maygc object allocate_bignum (uintC len, sintB sign);
  9555. /* is used by LISPARIT, STREAM */
  9556. /* UP: allocates Single-Float
  9557. allocate_ffloat(value)
  9558. > ffloat value: value (Bit 31 = sign)
  9559. < result: new Single-Float (LISP-object)
  9560. can trigger GC */
  9561. extern maygc object allocate_ffloat (ffloat value);
  9562. /* is used by LISPARIT */
  9563. /* UP: allocates Double-Float */
  9564. #ifdef intQsize
  9565. /* allocate_dfloat(value)
  9566. > dfloat value: value (Bit 63 = sign)
  9567. < result: new Double-Float (LISP-object)
  9568. can trigger GC */
  9569. extern maygc object allocate_dfloat (dfloat value);
  9570. #else
  9571. /* allocate_dfloat(semhi,mlo)
  9572. > semhi,mlo: value (Bit 31 of semhi = sign )
  9573. < result: new Double-Float (LISP-object)
  9574. can trigger GC */
  9575. extern maygc object allocate_dfloat (uint32 semhi, uint32 mlo);
  9576. #endif
  9577. /* is used by LISPARIT */
  9578. /* UP: allocates Long-Float
  9579. allocate_lfloat(len,expo,sign)
  9580. > uintC (actually uintWC) len: length of the mantissa (in Digits)
  9581. > uintL expo: exponent
  9582. > signean sign: sign (0 = +, -1 = -)
  9583. < result: new Long-Float, without mantissa
  9584. It will only be a LISP-object when the mantissa has been entered!
  9585. can trigger GC */
  9586. extern maygc object allocate_lfloat (uintC len, uintL expo, signean sign);
  9587. /* is used by LISPARIT */
  9588. /* UP: makes a rational number
  9589. make_ratio(num,den)
  9590. > object num: numerator (has to be an integer /= 0, relatively prime to den)
  9591. > object den: denominator (has to be an Integer > 1)
  9592. < result: rational number
  9593. can trigger GC */
  9594. extern maygc object make_ratio (object num, object den);
  9595. /* is used by LISPARIT */
  9596. /* UP: makes a complex number
  9597. make_complex(real,imag)
  9598. > real: real part (has to be a real number)
  9599. > imag: imaginary part (has to be a real number /= Fixnum 0)
  9600. < result: complex number
  9601. can trigger GC */
  9602. extern maygc object make_complex (object real, object imag);
  9603. /* is used by LISPARIT */
  9604. #ifdef MULTITHREAD
  9605. /* allocate a thread object
  9606. allocate_thread()
  9607. > *name_ : thread name (usually a symbol)
  9608. < result : new thread object (not started)
  9609. can trigger GC */
  9610. global maygc object allocate_thread (gcv_object_t *name_);
  9611. /* used by ZTHREAD */
  9612. /* allocate a mutex object
  9613. allocate_mutex()
  9614. > *name_ : mutex name (usually a symbol)
  9615. < result : new mutex object (initialized)
  9616. can trigger GC */
  9617. global maygc object allocate_mutex (gcv_object_t *name_);
  9618. /* used by ZTHREAD */
  9619. /* allocate an exemption object
  9620. allocate_exemption()
  9621. > *name_ : exemption name (usually a symbol)
  9622. < result : new exemption object (initialized)
  9623. can trigger GC */
  9624. global maygc object allocate_exemption (gcv_object_t *name_);
  9625. /* used by ZTHREAD */
  9626. #endif
  9627. /* Adds a freshly allocated object to the list of weak pointers.
  9628. activate_weak(obj);
  9629. > obj: A fresh but filled object of type Rectype_Weak* */
  9630. extern void activate_weak (object obj);
  9631. /* is used by WEAK */
  9632. /* UP: return the length of the ASCIZ-String
  9633. asciz_length(asciz)
  9634. > char* asciz: ASCIZ-String
  9635. (added with a NULL byte determines the end of string)
  9636. < result: Length of the character sequence (without the NULL byte) */
  9637. extern uintL asciz_length (const char * asciz);
  9638. #if defined(GNU) && (SAFETY < 2)
  9639. #ifdef HAVE_BUILTIN_STRLEN
  9640. #define asciz_length(a) ((uintL)__builtin_strlen(a))
  9641. #endif
  9642. #endif
  9643. #ifndef asciz_length
  9644. #ifdef HAVE_SAVED_STACK
  9645. /* can not use strlen() instead of asciz_length() , because this would
  9646. require a begin_system_call()/end_system_call() . */
  9647. #else
  9648. /* let us presume, that strlen() is implemented efficiently. */
  9649. #ifdef STDC_HEADERS
  9650. #include <string.h> /* declares strlen() */
  9651. #endif
  9652. #define asciz_length(a) ((uintL)strlen(a))
  9653. #endif
  9654. #endif
  9655. /* is used by SPVW */
  9656. %% #ifdef asciz_length
  9657. %% export_def(asciz_length(a));
  9658. %% #else
  9659. %% puts("extern uintL asciz_length (const char * asciz);");
  9660. %% #endif
  9661. /* UP: Compares two ASCIZ-Strings.
  9662. asciz_equal(asciz1,asciz2)
  9663. > char* asciz1: first ASCIZ-String
  9664. > char* asciz2: second ASCIZ-String
  9665. < result: true if the number-sequences are equal */
  9666. extern bool asciz_equal (const char * asciz1, const char * asciz2);
  9667. /* is used by STREAM */
  9668. %% #if notused
  9669. %% #ifdef asciz_length
  9670. %% export_def(asciz_equal(a1,a2));
  9671. %% #else
  9672. %% puts("extern bool asciz_equal (const char * asciz1, const char * asciz2);");
  9673. %% #endif
  9674. %% #endif
  9675. /* allocate memory and check for success */
  9676. extern void* my_malloc (size_t size);
  9677. /* used by FOREIGN and modules */
  9678. %% puts("extern void* my_malloc (size_t size);");
  9679. /* reallocate memory and check for success */
  9680. extern void* my_realloc (void* ptr, size_t size);
  9681. /* used by modules */
  9682. %% puts("extern void* my_realloc (void *ptr, size_t size);");
  9683. /* UP: Returns a Table of all circularities within an Object.
  9684. (A circularity is a Sub-Object contained within this Object,
  9685. which has more than one access-path to it.)
  9686. get_circularities(obj,pr_array,pr_closure)
  9687. > object obj: Object
  9688. > bool pr_array: Flag, if Array-Elements recursively count as Sub-Objects
  9689. > bool pr_closure: Flag, if Closure-Components recursively count as Sub-Objects
  9690. < result: T if Stack-Overflow occurred,
  9691. NIL if no circularities available,
  9692. #(0 ...) an (n+1)-element Vector, that contains the number 0 and the n
  9693. circularities as Elements, n>0.
  9694. can trigger GC */
  9695. extern maygc object get_circularities (object obj, bool pr_array, bool pr_closure);
  9696. /* is used by IO */
  9697. /* UP: unentangles #n# - References in Object *ptr with help from Aliste alist.
  9698. > *ptr : Object
  9699. > alist : Alist (Read-Label --> Object, to be substituted)
  9700. < *ptr : Object with unentangled References
  9701. < result : erroneous Reference or nullobj if everything is OK */
  9702. extern object subst_circ (gcv_object_t* ptr, object alist);
  9703. /* is used by IO */
  9704. /* UP: Runs through the whole memory, and calls for each
  9705. Object obj: fun(arg,obj,bytelen) .
  9706. map_heap_objects(fun,arg);
  9707. > fun: C-Function
  9708. > arg: arbitrary given Argument */
  9709. typedef void map_heap_function_t (void* arg, object obj, uintM bytelen);
  9710. extern void map_heap_objects (map_heap_function_t* fun, void* arg);
  9711. /* is used by PREDTYPE */
  9712. /* UP: returns the size (in Bytes) of an object.
  9713. varobject_bytelength(obj)
  9714. > obj: Heap-object with variable length
  9715. < result; the number of bytes occupied by it (header included) */
  9716. extern uintM varobject_bytelength (object obj);
  9717. /* is used by PREDTYPE */
  9718. /* Break-Semaphores
  9719. As long as a Break-Semaphore is set, the Lisp-Program can not
  9720. be interrupted. Purpose:
  9721. - backup of Consistencies,
  9722. - Non-reentrant Data-Structures (like e.g. DTA_buffer) can not
  9723. be used recursively. */
  9724. typedef union {uintB einzeln[8]; uintL gesamt[2]; } break_sems_;
  9725. extern break_sems_ break_sems;
  9726. #define break_sem_0 break_sems.einzeln[0]
  9727. #define break_sem_1 break_sems.einzeln[1]
  9728. #define break_sem_2 break_sems.einzeln[2]
  9729. #define break_sem_3 break_sems.einzeln[3]
  9730. #define break_sem_4 break_sems.einzeln[4]
  9731. #define break_sem_5 break_sems.einzeln[5]
  9732. #define break_sem_6 break_sems.einzeln[6]
  9733. #define break_sem_7 break_sems.einzeln[7]
  9734. /* is used by SPVW, Macros set/clr_break_sem_0/1/2/3/4/5/6/7 */
  9735. /* Tests whether all break-semaphores have been cleared. */
  9736. #define break_sems_cleared() \
  9737. (break_sems.gesamt[0] == 0 && break_sems.gesamt[1] == 0)
  9738. /* is used by SPVW, WIN32AUX */
  9739. /* clears all break-semaphores. Very dangerous! */
  9740. #define clear_break_sems() \
  9741. (break_sems.gesamt[0] = 0, break_sems.gesamt[1] = 0)
  9742. /* is used by SPVW */
  9743. /* sets break-semaphore 0 and thus protects against interrupts
  9744. set_break_sem_0(); */
  9745. #define set_break_sem_0() (break_sem_0 = 1)
  9746. /* is used by SPVW */
  9747. /* clears the break-semaphore 0 and thus releases the interrupts
  9748. clr_break_sem_0(); */
  9749. #define clr_break_sem_0() (break_sem_0 = 0)
  9750. /* is used by SPVW */
  9751. /* sets break-semaphore 1 and thus protects against interrupts
  9752. set_break_sem_1(); */
  9753. #define set_break_sem_1() (break_sem_1 = 1)
  9754. /* is used by SPVW, ARRAY */
  9755. /* clears the break-semaphore 1 and thus releases the interrupts
  9756. clr_break_sem_1(); */
  9757. #define clr_break_sem_1() (break_sem_1 = 0)
  9758. /* is used by SPVW, ARRAY */
  9759. /* sets break-semaphore 2 and thus protects against interrupts
  9760. set_break_sem_2(); */
  9761. #define set_break_sem_2() (break_sem_2 = 1)
  9762. /* is used by PACKAGE, HASHTABL */
  9763. /* clears the break-semaphore 2 and thus releases the interrupts
  9764. clr_break_sem_2(); */
  9765. #define clr_break_sem_2() (break_sem_2 = 0)
  9766. /* is used by PACKAGE, HASHTABL */
  9767. /* sets break-semaphore 3 and thus protects against interrupts
  9768. set_break_sem_3(); */
  9769. #define set_break_sem_3() (break_sem_3 = 1)
  9770. /* is used by PACKAGE */
  9771. /* clears the break-semaphore 3 and thus releases the interrupts
  9772. clr_break_sem_3(); */
  9773. #define clr_break_sem_3() (break_sem_3 = 0)
  9774. /* is used by PACKAGE */
  9775. /* sets break-semaphore 4 and thus protects against interrupts
  9776. set_break_sem_4(); */
  9777. #define set_break_sem_4() (break_sem_4 = 1)
  9778. /* is used by STREAM, PATHNAME */
  9779. /* clears the break-semaphore 4 and thus releases the interrupts
  9780. clr_break_sem_4(); */
  9781. #define clr_break_sem_4() (break_sem_4 = 0)
  9782. /* is used by STREAM, PATHNAME */
  9783. /* increments break-semaphore 5 and thus protects against interrupts
  9784. inc_break_sem_5(); */
  9785. #define inc_break_sem_5() (break_sem_5++)
  9786. /* is used by SPVW */
  9787. /* decrements break-semaphore 5 and thus releases interrupts
  9788. dec_break_sem_5(); */
  9789. #define dec_break_sem_5() (break_sem_5--)
  9790. /* is used by SPVW */
  9791. /* clears the break-semaphore 5 and thus releases the interrupts
  9792. clr_break_sem_5(); */
  9793. #define clr_break_sem_5() (break_sem_5 = 0)
  9794. /* is used by SPVW */
  9795. /* Flag, whether SYS::READ-FORM should behave compatible to ILISP */
  9796. extern bool ilisp_mode;
  9797. /* returns the amount of space occupied by static LISP-objects */
  9798. extern uintM static_space (void);
  9799. /* is used by DEBUG */
  9800. /* returns the amount of space occupied by LISP-objects */
  9801. extern uintM used_space (void);
  9802. /* is used by TIME, DEBUG */
  9803. /* returns the amount of space still available for LISP-objects */
  9804. extern uintM free_space (void);
  9805. /* is used by DEBUG */
  9806. /* UP: saves memory image to disc
  9807. savemem(stream);
  9808. > object stream: open File-Output-Stream, will be closed
  9809. > bool exec_p: should the result include runtime?
  9810. < file length
  9811. can trigger GC */
  9812. extern maygc off_t savemem (object stream, bool exec_p);
  9813. /* used by PATHNAME */
  9814. #ifdef HAVE_SIGNALS
  9815. /* Temporarily do not ignore the status of subprocesses. */
  9816. extern void begin_want_sigcld (void);
  9817. extern void end_want_sigcld (void);
  9818. /* is used by PATHNAME */
  9819. #endif
  9820. #if defined(HAVE_SIGNALS) && defined(SIGPIPE)
  9821. /* Set ONLY during write() calls to pipes directed to subprocesses. */
  9822. extern bool writing_to_subprocess;
  9823. #endif
  9824. /* Declaration of the FSUBRs.
  9825. As C-functions: C_name, of the type fsubr_function_t (no arguments, no value) */
  9826. /* make C-functions visible: */
  9827. #define LISPSPECFORM LISPSPECFORM_A
  9828. #include "fsubr.c"
  9829. #undef LISPSPECFORM
  9830. /* is used by */
  9831. /* make Fsubr-table visible: */
  9832. #define LISPSPECFORM LISPSPECFORM_C
  9833. struct fsubr_tab_ {
  9834. #include "fsubr.c"
  9835. };
  9836. #undef LISPSPECFORM
  9837. extern const struct fsubr_tab_ fsubr_tab;
  9838. /* is used by CONTROL, SPVW */
  9839. /* Declaration of the SUBR-table:
  9840. As C-functions: C_name
  9841. of the type subr_norest_function_t (no arguments, no value)
  9842. resp. subr_rest_function_t (two arguments, no value): */
  9843. typedef Values subr_norest_function_t (void);
  9844. typedef Values subr_rest_function_t (uintC argcount, gcv_object_t* rest_args_pointer);
  9845. %% #if notused
  9846. %% emit_typedef_f("Values %s(void)","subr_norest_function_t");
  9847. %% emit_typedef_f("Values %s(uintC argcount, object* rest_args_pointer)","subr_rest_function_t");
  9848. %% #endif
  9849. /* As LISP-Subr: L(name) */
  9850. /* Make C-functions visible: */
  9851. #define LISPFUN LISPFUN_A
  9852. #include "subr.c"
  9853. #undef LISPFUN
  9854. /* is used by */
  9855. /* Make Subr-tables visible: */
  9856. #define LISPFUN LISPFUN_C
  9857. extern struct subr_tab_ {
  9858. VAROBJECTS_ALIGNMENT_DUMMY_DECL
  9859. #include "subr.c"
  9860. } subr_tab_data;
  9861. #undef LISPFUN
  9862. /* is used by Macro L */
  9863. %% puts("extern struct subr_tab_ {");
  9864. %% puts(" VAROBJECTS_ALIGNMENT_DUMMY_DECL");
  9865. %% #undef LISPFUN
  9866. %% #define LISPFUN(name,sec,req_count,opt_count,rest_flag,key_flag,key_count,keywords) \
  9867. %% printf(" subr_t %s;\n",STRING(D_##name));
  9868. %% #include "subr.c"
  9869. %% #undef LISPFUN
  9870. %% puts("} subr_tab_data;");
  9871. /* Abbreviation for LISP-Subr with a given name: L(name) */
  9872. #if !defined(MAP_MEMORY_TABLES)
  9873. #define subr_tab subr_tab_data
  9874. #ifdef TYPECODES
  9875. #define subr_tab_ptr_as_object(subr_addr) (type_constpointer_object(subr_type,subr_addr))
  9876. #else
  9877. #if defined(WIDE_AUXI)
  9878. #define subr_tab_ptr_as_object(subr_addr) as_object_with_auxi((aint)(subr_addr)+subr_bias)
  9879. #elif defined(OBJECT_STRUCT)
  9880. #define subr_tab_ptr_as_object(subr_addr) as_object((oint)(subr_addr)+subr_bias)
  9881. #else
  9882. #define subr_tab_ptr_as_object(subr_addr) objectplus(subr_addr,subr_bias)
  9883. #endif
  9884. #endif
  9885. #define L_help_(name) subr_tab_ptr_as_object(&subr_tab.name)
  9886. #else
  9887. /* define subr_tab_addr ((struct subr_tab_ *)type_constpointer_object(subr_type,0)) */
  9888. #define subr_tab_addr ((struct subr_tab_ *)type_zero_oint(subr_type))
  9889. #define subr_tab (*subr_tab_addr)
  9890. #define subr_tab_ptr_as_object(subr_addr) (as_object((oint)(subr_addr)))
  9891. #define L_help_(name) subr_tab_ptr_as_object(&subr_tab_addr->name)
  9892. #endif
  9893. #define L(name) L_help_(D_##name)
  9894. /* is used by all modules */
  9895. %% #if defined(MAP_MEMORY_TABLES)
  9896. %% export_def(subr_tab_addr);
  9897. %% #endif
  9898. %% export_def(subr_tab);
  9899. %% export_def(subr_tab_ptr_as_object(subr_addr));
  9900. %% export_def(L_help_(name));
  9901. %% emit_define("L(name)","L_help_(D_##name)");
  9902. /* Pseudofunctions are addresses of C functions (to be called directly, not via
  9903. FUNCALL) or constant C data.
  9904. For SAVEMEM/LOADMEM we have a table of all such pseudofunctions. */
  9905. typedef const void * Pseudofun; /* assume function pointers fit in a void* */
  9906. %% puts("typedef const void * Pseudofun;");
  9907. /* Declaration of the tables of relocatable pointers: */
  9908. #define PSEUDO PSEUDO_A
  9909. extern struct pseudocode_tab_ {
  9910. #include "pseudofun.c"
  9911. } pseudocode_tab;
  9912. #undef PSEUDO
  9913. #define PSEUDO PSEUDO_B
  9914. extern struct pseudodata_tab_ {
  9915. #include "pseudofun.c"
  9916. #if defined(MICROSOFT) && !defined(UNICODE)
  9917. Pseudofun dummy_pseudofun;
  9918. #endif
  9919. } pseudodata_tab;
  9920. #undef PSEUDO
  9921. /* is used by STREAM, SPVW */
  9922. /* Declaration of the functions that can be stored in Lisp objects. */
  9923. #define PSEUDO PSEUDO_C
  9924. #include "pseudofun.c"
  9925. #undef PSEUDO
  9926. /* is used by STREAM, and to avoid gcc -Wmissing-declarations warnings */
  9927. /* Return an ADDRESS object encapsulating a pseudofunction. */
  9928. #ifdef TYPECODES
  9929. #define P(fun) type_constpointer_object(machine_type,(Pseudofun)&(fun))
  9930. #else
  9931. #define P(fun) make_machine_code((Pseudofun)&(fun))
  9932. #endif
  9933. /* is used by STREAM, ENCODING */
  9934. /* Declaration if the Symbol-table: */
  9935. #define LISPSYM LISPSYM_A
  9936. extern struct symbol_tab_ {
  9937. VAROBJECTS_ALIGNMENT_DUMMY_DECL
  9938. #include "constsym.c"
  9939. } symbol_tab_data;
  9940. #undef LISPSYM
  9941. /* is used by Macro S, gcinvariant_symbol_p */
  9942. %% puts("extern struct symbol_tab_ {");
  9943. %% puts(" VAROBJECTS_ALIGNMENT_DUMMY_DECL");
  9944. %% #define LISPSYM(name,printname,package) \
  9945. %% printf(" symbol_ %s;\n",STRING(S_##name));
  9946. %% #include "constsym.c"
  9947. %% #undef LISPSYM
  9948. %% puts("} symbol_tab_data;");
  9949. /* Abbreviation for LISP-Symbol with a given name: S(name) */
  9950. #define S(name) S_help_(S_##name)
  9951. #if !defined(MAP_MEMORY_TABLES)
  9952. #define symbol_tab symbol_tab_data
  9953. #ifdef TYPECODES
  9954. #define S_help_(name) (type_constpointer_object(symbol_type,&symbol_tab.name))
  9955. #else
  9956. #if defined(WIDE_AUXI)
  9957. #define S_help_(name) as_object_with_auxi((aint)&symbol_tab.name+varobject_bias)
  9958. #elif defined(OBJECT_STRUCT)
  9959. #define S_help_(name) as_object((oint)&symbol_tab.name+varobject_bias)
  9960. #else
  9961. #define S_help_(name) objectplus(&symbol_tab.name,varobject_bias)
  9962. #endif
  9963. #endif
  9964. #else
  9965. /* define symbol_tab_addr ((struct symbol_tab_ *)type_constpointer_object(symbol_type,0)) */
  9966. #define symbol_tab_addr ((struct symbol_tab_ *)type_zero_oint(symbol_type))
  9967. #define symbol_tab (*symbol_tab_addr)
  9968. #define S_help_(name) (as_object((oint)(&symbol_tab_addr->name)))
  9969. #if 0 /* Some compilers do not allow the above expression */
  9970. /* - even though it's a 'constant expression' -
  9971. as initializer of static variables.
  9972. We have to assist: */
  9973. #undef S_help_
  9974. #define S_help_(name) (as_object( (char*)(&((struct symbol_tab_ *)0)->name) + (uintP)symbol_tab_addr ))
  9975. #endif
  9976. #endif
  9977. /* is used by all modules */
  9978. %% emit_define("S(name)","S_help_(S_##name)");
  9979. %% #if defined(MAP_MEMORY_TABLES)
  9980. %% export_def(symbol_tab_addr);
  9981. %% #endif
  9982. %% export_def(symbol_tab);
  9983. %% export_def(S_help_(name));
  9984. #define NIL S(nil)
  9985. #define T S(t)
  9986. %% export_def(NIL);
  9987. %% export_def(T);
  9988. #if defined(DEBUG_GCSAFETY)
  9989. /* gcinvariant_symbol_p(obj)
  9990. > obj: an object
  9991. < result: true if obj is a symbol in symbol_tab */
  9992. static inline bool gcinvariant_symbol_p (object obj) {
  9993. if (
  9994. #ifdef TYPECODES
  9995. symbolp(obj)
  9996. #else
  9997. varobjectp(obj)
  9998. #endif
  9999. &&
  10000. (
  10001. #if !defined(MAP_MEMORY_TABLES)
  10002. #ifdef TYPECODES
  10003. (as_oint(obj) >> (oint_addr_shift-addr_shift)) - ((aint)(tint)symbol_type<<oint_type_shift)
  10004. #else
  10005. as_oint(obj) - varobject_bias
  10006. #endif
  10007. #else
  10008. /* FIXME: MAP_MEMORY_TABLES possibly uses MULTIMAP_MEMORY_SYMBOL_TAB. */
  10009. as_oint(obj)
  10010. #endif
  10011. - (aint)&symbol_tab < sizeof(symbol_tab))
  10012. )
  10013. return true;
  10014. else
  10015. return false;
  10016. }
  10017. #endif
  10018. %% #if defined(DEBUG_GCSAFETY)
  10019. %% printf("static inline bool gcinvariant_symbol_p (object obj) { if (");
  10020. %% #ifdef TYPECODES
  10021. %% printf("symbolp(obj)");
  10022. %% #else
  10023. %% printf("varobjectp(obj)");
  10024. %% #endif
  10025. %% printf(" && (");
  10026. %% #if !defined(MAP_MEMORY_TABLES)
  10027. %% #ifdef TYPECODES
  10028. %% printf2("(as_oint(obj) >> %d) - %d", oint_addr_shift-addr_shift, (aint)(tint)symbol_type<<oint_type_shift);
  10029. %% #else
  10030. %% printf1("as_oint(obj) - %d", varobject_bias);
  10031. %% #endif
  10032. %% #else
  10033. %% printf("as_oint(obj)");
  10034. %% #endif
  10035. %% puts(" - (aint)&symbol_tab < sizeof(symbol_tab))) return true; else return false; }");
  10036. %% #endif
  10037. /* The macro NIL_IS_CONSTANT tells , whether NIL is recognized
  10038. as 'constant expression' by the C-Compiler. If so, tables can
  10039. already be initialized largely by the C-Compiler. */
  10040. #if (oint_addr_shift==0)
  10041. #define NIL_IS_CONSTANT true
  10042. #else
  10043. #define NIL_IS_CONSTANT false
  10044. #endif
  10045. /* Declaration of the table with the remaining constant objects: */
  10046. #define LISPOBJ LISPOBJ_A
  10047. extern struct object_tab_ {
  10048. #include "constobj.c"
  10049. } object_tab;
  10050. #undef LISPOBJ
  10051. /* is used by Macro O */
  10052. %% puts("extern struct object_tab_ {");
  10053. %% #define LISPOBJ(name,init) printf(" gcv_object_t %s;\n",STRING(name));
  10054. %% #include "constobj.c"
  10055. %% #undef LISPOBJ
  10056. %% puts("} object_tab;");
  10057. /* Abbreviation for other LISP-object with a given Name: */
  10058. #define O(name) (object_tab.name)
  10059. %% /* FIXME: Difference between lispbibl.d and clisp.h */
  10060. %% puts("#define GLO(name) (object_tab.name)");
  10061. #if defined(GENERATIONAL_GC) && defined(SPVW_MIXED)
  10062. /* handle_fault_range(PROT_READ,start,end) makes an address range readable.
  10063. handle_fault_range(PROT_READ_WRITE,start,end) makes an address range writable. */
  10064. extern bool handle_fault_range (int prot, aint start_address, aint end_address);
  10065. #endif
  10066. %% export_def(PROT_READ);
  10067. %% export_def(PROT_READ_WRITE);
  10068. %% #if defined(GENERATIONAL_GC) && defined(SPVW_MIXED)
  10069. %% puts("extern bool handle_fault_range (int prot, aint start_address, aint end_address);");
  10070. %% #else
  10071. %% puts("#define handle_fault_range(p,s,e)");
  10072. %% #endif
  10073. /* ###################### MODBIBL for MODULES.D ########################### */
  10074. #if defined(DYNAMIC_MODULES) && !defined(HAVE_DYNLOAD) && !defined(WIN32_NATIVE)
  10075. /* if you want DYNAMIC_MODULES to work on a non-WIN32_NATIVE platform
  10076. which does not HAVE_DYNLOAD (e.g., via ltdl), you will need to
  10077. implement libopen() and find_name() in spvw.d for your platform */
  10078. #error "Dynamic modules require dynamic loading!"
  10079. #endif
  10080. /* Number of external modules: */
  10081. extern uintC module_count;
  10082. %% puts("extern uintC module_count;");
  10083. /* Data for initialization of a module's subr_tab: */
  10084. typedef struct {
  10085. const char* packname; /* Name of the Home-Package of the Symbol or NULL */
  10086. const char* symname; /* Name of the Symbol */
  10087. } subr_initdata_t;
  10088. %% emit_typedef("struct { const char* packname; const char* symname; }","subr_initdata_t");
  10089. /* Data for initialization of a module's object_tab: */
  10090. typedef struct {
  10091. const char* initstring; /* Initialization-String */
  10092. } object_initdata_t;
  10093. %% emit_typedef("struct { const char* initstring; }","object_initdata_t");
  10094. /* Table resp. List of Modules: */
  10095. typedef struct module_t {
  10096. const char* name; /* Name */
  10097. subr_t* stab; const uintC* stab_size; /* a separate subr_tab */
  10098. gcv_object_t* otab; const uintC* otab_size; /* a separate object_tab */
  10099. bool initialized;
  10100. /* Data for Initialization: */
  10101. const subr_initdata_t* stab_initdata;
  10102. const object_initdata_t* otab_initdata;
  10103. /* Functions for Initialization */
  10104. void (*initfunction1) (struct module_t *); /* only once */
  10105. void (*initfunction2) (struct module_t *); /* always at start up */
  10106. void (*finifunction) (struct module_t *); /* before termination */
  10107. #ifdef DYNAMIC_MODULES
  10108. struct module_t * next; /* linked List */
  10109. #endif
  10110. } module_t;
  10111. #ifdef DYNAMIC_MODULES
  10112. extern module_t modules[]; /* List-Start */
  10113. BEGIN_DECLS
  10114. extern void add_module (module_t * new_module);
  10115. END_DECLS
  10116. #else
  10117. extern module_t modules[]; /* 1+module_count entries, then an empty entry */
  10118. #endif
  10119. %% strcpy(buf,"struct module_t { const char* name; subr_t* stab; const uintC* stab_size; gcv_object_t* otab; const uintC* otab_size; bool initialized; const subr_initdata_t* stab_initdata; const object_initdata_t* otab_initdata; void (*initfunction1) (struct module_t *); void (*initfunction2) (struct module_t *); void (*finifunction) (struct module_t *);");
  10120. %% #ifdef DYNAMIC_MODULES
  10121. %% strcat(buf," struct module_t * next;");
  10122. %% #endif
  10123. %% strcat(buf," }"); emit_typedef(buf,"module_t");
  10124. %% #ifdef DYNAMIC_MODULES
  10125. %% puts("BEGIN_DECLS");
  10126. %% puts("extern void add_module (module_t * new_module);");
  10127. %% puts("END_DECLS");
  10128. %% #else
  10129. %% puts("extern module_t modules[];");
  10130. %% #endif
  10131. #if defined(HAVE_DYNLOAD) || defined(WIN32_NATIVE)
  10132. /* open the dynamic library
  10133. libname is the name of the library
  10134. returns a handle suitable for find_name()
  10135. calls dlopen() or LoadLibrary() */
  10136. extern void * libopen (const char* libname);
  10137. /* used by FOREIGN and spvw.d:dynload_modules() */
  10138. /* find the name in the dynamic library handle
  10139. calls dlsym() or GetProcAddress()
  10140. handle is an object returned by libopen()
  10141. or NULL, which means emulate RTLD_DEFAULT on UNIX_FREEBSD
  10142. and WIN32_NATIVE by searching through all libraries
  10143. name is the name of the function (or variable) in the library */
  10144. extern void* find_name (void *handle, const char *name);
  10145. /* used by FOREIGN and spvw.d:dynload_modules() */
  10146. #endif
  10147. #if defined(DYNAMIC_MODULES)
  10148. /* Attaches a shared library to this process' memory, and attempts to load
  10149. a number of clisp modules from it. */
  10150. extern void dynload_modules (const char * library, uintC modcount,
  10151. const char * const * modnames);
  10152. #endif
  10153. /* find the module with the given name */
  10154. extern module_t* find_module (const char *name);
  10155. /* push all module names to STACK and return the number of modules pushed
  10156. can trigger GC */
  10157. extern maygc uintC modules_names_to_stack (void);
  10158. /* ####################### EVALBIBL for EVAL.D ############################# */
  10159. /*
  10160. Specifications for the Evaluator
  10161. ################################
  10162. SUBRs and FSUBRs
  10163. ================
  10164. They're constructed through
  10165. LISPFUN for general LISP-functions,
  10166. LISPFUNN for normal LISP-functions (only required parameters),
  10167. LISPSPECFORM for special forms (FSUBRs).
  10168. Note that SUBRs with KEY_COUNT=0 will be seen as SUBRs without keyword-
  10169. parameters by the evaluator (which in consequence means that in this case the
  10170. ALLOW_FLAG is meaningless and no keyword, not even :ALLOW-OTHER-KEYS,
  10171. will be accepted)!
  10172. Values
  10173. ======
  10174. The following format is used for the passing of multiple values:
  10175. value1 contains the first value (NIL if there aren't values).
  10176. mv_count contains the number of values..
  10177. If there is at least one value : value1 = first value.
  10178. If there are at least two values : value2 = second value.
  10179. If there are at least three values : value3 = third value .
  10180. All values are in mv_space .
  10181. Recommended commands for returning of values to the caller:
  10182. 0 values: VALUES0;
  10183. 1 value : VALUES1(...);
  10184. 2 values: value1=...; value2=...; mv_count=2;
  10185. 3 values: value1=...; value2=...; value3=...; mv_count=3;
  10186. more than 3 values:
  10187. if (number of values >= mv_limit) goto error_too_many_values;
  10188. Put the values one after another onto the STACK
  10189. STACK_to_mv(number of values);
  10190. Passing of parameters to SUBRs
  10191. ==============================
  10192. The arguments are passed on the LISP-stack, with the first one being on the
  10193. top. The required arguments come first, then the optional ones
  10194. (each #UNBOUND, if not specified), then come the
  10195. keyword-arguments (again, each #UNBOUND, if not specified).
  10196. The SUBR-object can be found in back_trace.
  10197. This is all if no &REST-argument is planned. But if a &REST-argument
  10198. is planned, all further arguments follow (the optional ones) on the stack
  10199. one by one, and this will be passed: the number of these arguments and a pointer
  10200. above the first of these arguments. (This means that the number of LISP-objects on
  10201. the stack is not always the same!)
  10202. All arguments have to be removed from the LISP-stack at the return jump.
  10203. (for example. for SUBRs with &REST: the stackpointer STACK has to have the value
  10204. args_pointer = rest_args_pointer STACKop (fixed number of arguments)
  10205. = pointer above the very first argument), and mv_count/mv_space
  10206. has to hold the values.
  10207. Passing of parameters to FSUBRs
  10208. ===============================
  10209. The parameters are passed on the LISP-stack with the first one being on top.
  10210. At first there are the required parametes, followed by the optional ones
  10211. (#UNBOUND, if not specifired), then - if body-flag true -
  10212. the whole rest of the body (most of the time a list).
  10213. So the number of objects on the LISP-stack is always the same, namely
  10214. numReqParameter + numOptParameter + (0 or 1 if body-flag).
  10215. At the call, back_trace holds the FSUBR-object, and the whole form is
  10216. in the EVAL-frame, directly above the parameters.
  10217. All parameters have to be removed from the LISP-stack at the return jump
  10218. (ie. the stackpointer STACK has to be incemented by the number of objects),
  10219. and mv_count/mv_space has to hold the values.
  10220. Environments
  10221. ============
  10222. General
  10223. -------
  10224. The lexical environment is separated into 5 components:
  10225. - the variables-environment (VAR_ENV),
  10226. - the functions- and macro-environment (FUN_ENV),
  10227. - the block-environment (BLOCK_ENV),
  10228. - the tagbody-environment (GO_ENV),
  10229. - the declarations-environment (DECL_ENV).
  10230. The environment is kept in 5 "global variables". They are dynamically bound
  10231. with special frames on change.
  10232. A single functions- and macro environment is passed to SYM_FUNCTION,
  10233. MACROEXP, MACROEXP0, PARSE_DD.
  10234. GET_CLOSURE expects a pointer to all environments en bloc: A3 with
  10235. VAR_(A3)=VAR_ENV, FUN_(A3)=FUN_ENV, BLOCK_(A3)=BLOCK_ENV, GO_(A3)=GO_ENV,
  10236. DECL_(A3)=DECL_ENV.
  10237. The variables-environment
  10238. -------------------------
  10239. It contains the local variable-bindings.
  10240. A variables-enviroment is given through a pointer to a
  10241. variable-binding frame, or NIL (which means an empty lexical
  10242. environment) or a vector that is built as follows:
  10243. The vector contains n bindings and has the length 2n+1. The elements are
  10244. n-times each variable (a symbol) and the value that belongs to it ("value" can
  10245. be #<SPECDECL> as well, and then the variable has to be referenced dynamically)
  10246. and as last element the predecessor environment.
  10247. The functions- and macro-environment
  10248. ------------------------------------
  10249. It contains the local function- and macro-definitions.
  10250. A functions- and macro-environment is given through a pointer to
  10251. a functions- or macrobindings-frame or NIL (which means an empty
  10252. lexical environment) or through a vector that is built as follows:
  10253. The vector contains n bindings and has length 2n+1. The elements are
  10254. n-time each function-name (a symbol) and the definiton that belongs to it (a
  10255. closure or NIL or a SYS::MACRO object) and as last element
  10256. the predecessor environment.
  10257. The block-environment
  10258. ---------------------
  10259. It contains the lexically visible block-exitpoints.
  10260. A block-environment is given through a pointer to a block-frame
  10261. or through an association-list, whose elements each have the block-name (a symbol)
  10262. as CAR and as CDR either the pointer to the appropriate
  10263. frame or #DISABLED, if the block has already been left.
  10264. The tagbody-environment
  10265. -----------------------
  10266. It contains the lexically visible Go-labels of the tagbodies.
  10267. A tagbody-environment is given through a pointer to a
  10268. tagbody-frame or an associations-list, whose elements have a vector (with the
  10269. Go-tags as elements) as CAR and as CDR either the pointer to the
  10270. related frame or #DISABLED, if the tagbody has already
  10271. been left.
  10272. The declarations-environment
  10273. ----------------------------
  10274. It contains the lexically visible declarations.
  10275. A declarations-environment is given through a list of declaration-
  10276. specifiers, whose CAR is each either OPTIMIZE or DECLARATION or
  10277. a user-specified declaration-type.
  10278. Passing of environtments to LISP-functions
  10279. ------------------------------------------
  10280. There are two data structures for this:
  10281. When it is passed as second argument to macro-expander-functions (CLTL p.
  10282. 145-146) and when it is receipted by MACROEXPAND and MACROEXPAND-1 (CLTL p. 151)
  10283. it is simply a Simple-Vector with 2 elements, consisting of a nested
  10284. variable-environment and a nested functions- and macro-environment.
  10285. The same for passing to SYSTEM::%EXPAND-LAMBDABODY-MAIN and the like.
  10286. If it is passed as second argument to the value of *EVALHOOK* or as third one
  10287. to the value of *APPLYHOOK* (CLTL p. 322) and on reception by
  10288. EVALHOOK and APPLYHOOK (CLTL p. 323) it is a Simple-Vector with
  10289. five elements with all five components nested.
  10290. Frames
  10291. ======
  10292. Frames are not used to call SUBRs, FSUBRs and compiled closures.
  10293. There are the following 14 kinds of frames:
  10294. - Environmentbinding-Frame (ENV_FRAME),
  10295. - APPLY-frame (APPLY_FRAME),
  10296. - EVAL-frame (EVAL_FRAME),
  10297. - dynamic variable-bindings-frame (DYNBIND_FRAME),
  10298. - Variable-bindings-frame (VAR_FRAME),
  10299. - Function- or Macrobindings-Frame (FUN_FRAME),
  10300. - interpreted block-frame (IBLOCK_FRAME),
  10301. - compiled block-frame (CBLOCK_FRAME),
  10302. - interpreted tagbody-frame (ITAGBODY_FRAME),
  10303. - compiled tagbody-frame (CTAGBODY_FRAME),
  10304. - Catch-Frame (CATCH_FRAME),
  10305. - Unwind-Protect-frame (UNWIND_PROTECT_FRAME),
  10306. - Handler-frame (HANDLER_FRAME),
  10307. - Driver-frame (DRIVER_FRAME).
  10308. Right at the bottom of a frame there is a long-word, that contains the
  10309. frame-type information and a pointer above the frame (= the value of the
  10310. STACK before and after the frame has been built).
  10311. In the frame-info there are the bits
  10312. SKIP2_BIT deleted, if another long-word comes above it,
  10313. that is not a LISP-object and thus has to be skipped
  10314. by the GC,
  10315. EXITPOINT_BIT set for all but VAR and FUN,
  10316. NESTED_BIT set for IBLOCK and ITAGBODY, if the exitpoint or
  10317. the Go-label has already been put into an Alist.
  10318. The default-values for the frame-type info-bytes are ENVxx_FRAME_INFO,
  10319. APPLY_FRAME_INFO, EVAL_FRAME_INFO, VAR_FRAME_INFO, FUN_FRAME_INFO,
  10320. IBLOCK_FRAME_INFO, CBLOCK_FRAME_INFO, ITAGBODY_FRAME_INFO, CTAGBODY_FRAME_INFO,
  10321. CATCH_FRAME_INFO, UNWIND_PROTECT_FRAME_INFO, DRIVER_FRAME_INFO.
  10322. The routine that is in (SP).L with SP=SP_(STACK) (for IBLOCK-, CBLOCK-,
  10323. ITAGBODY-, CTAGBODY-, CATCH-, UNWIND-PROTECT-frames), is being
  10324. jumped to by MOVE.L SP_(STACK),SP ! RTS .
  10325. For DRIVER-frames by MOVE.L SP_(STACK),SP ! MOVE.L (SP),-(SP) ! RTS .
  10326. In the portable C-version in SP_(STACK) there is a pointer to a
  10327. setjmp/longjmp-buffer.
  10328. Environmentbindings-frames
  10329. --------------------------
  10330. They contain dynamic bindings of a maximum of 5 environments.
  10331. ENVxx_FRAME_INFO is frame-info (xx depending on the environment that is
  10332. bound here). Structure:
  10333. Offset Stack-Contents
  10334. 20/16/12/8/4 [old value ofDECL_ENV]
  10335. 16/12/8/4 [old value ofGO_ENV]
  10336. 12/8/4 [old value ofBLOCK_ENV]
  10337. 8/4 [old value ofFUN_ENV]
  10338. 4 [old value ofVAR_ENV]
  10339. 0 Frame-Info; pointer above frame
  10340. ENV1V_frame for 1 VAR_ENV
  10341. ENV1F_frame for 1 FUN_ENV
  10342. ENV1B_frame for 1 BLOCK_ENV
  10343. ENV1G_frame for 1 GO_ENV
  10344. ENV1D_frame for 1 DECL_ENV
  10345. ENV2VD_frame for 1 VAR_ENV and 1 DECL_ENV
  10346. ENV5_frame for all 5 environments
  10347. APPLY-frames
  10348. ------------
  10349. They are created at every call (APPLY or FUNCALL) of an interpreted
  10350. closure.
  10351. Structure:
  10352. Offset Stack-contents
  10353. 4n+12
  10354. 4n+8 Argument 1
  10355. ...
  10356. 12 Argument n
  10357. 8 Function that is being called
  10358. 4 SP
  10359. 0 Frame-info; pointer above frame
  10360. SP is a pointer into the program-stack. Jumping back to (SP).L after dissolving
  10361. the APPLY-fame returns the contents of A0/... as values of the form.
  10362. The frame-info has the value APPLY_FRAME_INFO or TRAPPED_APPLY_FRAME_INFO.
  10363. EVAL-frames
  10364. -----------
  10365. They are created for every call of the EVAL-procedure.
  10366. Layout:
  10367. Offset Stack-content
  10368. 8 Form that is being evaluated
  10369. 4 SP
  10370. 0 Frame-info; pointer above frame
  10371. SP is a pointer into the program stack. Jumping back to (SP).L after dissolving
  10372. the EVAL-frame returns the contents of A0/... as values of the form.
  10373. The frame-info has the value EVAL_FRAME_INFO or TRAPPED_EVAL_FRAME_INFO.
  10374. Dynamic variable-bindings frames
  10375. -----------------------------------
  10376. They bind symbols to values dynamically.
  10377. The structure of such a frame with n bindings is as follows::
  10378. Offset stack contents
  10379. 8n+4
  10380. 8n value 1
  10381. 8n-4 symbol 1
  10382. ... ...
  10383. 8 value n
  10384. 4 symbol n
  10385. 0 frame-info; pointer above frame
  10386. The content of the frameinfo-byte is DYNBIND_FRAME_INFO.
  10387. Variable-bindings-frames
  10388. ------------------------
  10389. They are created when interpreted closures are being used (for the variable
  10390. bindings specified in the Lambda-list and in the dynamic references that might
  10391. be specified in the declarations) and by LET and LET*, as well as by all
  10392. constructs, that use LET or LET* implicitly (such as DO, DO*, PROG, PROG*,
  10393. DOLIST, DOTIMES, ...).
  10394. The structure of a variable-bindings-frame with n bindings is as follows:
  10395. #ifndef NO_symbolflags
  10396. Offset stack contents
  10397. 12+8n
  10398. 8+8n value 1
  10399. 4+8n symbol 1
  10400. ... ...
  10401. 16 value n
  10402. 12 symbol n
  10403. 8 NEXT_ENV
  10404. 4 m
  10405. 0 frame-info; pointer above frame
  10406. #else
  10407. Offset stack contents
  10408. 12+12n
  10409. 8+12n value 1
  10410. 4+12n symbol 1
  10411. 12n marker bits 1
  10412. ... ...
  10413. 20 value n
  10414. 16 symbol n
  10415. 12 marker bits n
  10416. 8 NEXT_ENV
  10417. 4 m
  10418. 0 frame-info; pointer above frame
  10419. #endif
  10420. The symbol/value-pairs are numbered and stored in the order in which the
  10421. bindings become active (i.e. for interpreted closures: at first the dynamic
  10422. references (SPECIAL-declarations), then the required-parameters, then the
  10423. optional parameters, then the remaining parameters, then the keyword
  10424. parameters, then the AUX-variables).
  10425. The symbols contain the following marker bits on the stack: ACTIVE_BIT, is
  10426. set, if the binding is active, DYNAM_BIT is set, if the binding is
  10427. dynamic. (Dynamic references are marked as lexical with
  10428. the special value #SPECDECL!).
  10429. NEXT_ENV is next upper variables-environment.
  10430. m is a long-word, 0 <= m <= n, and stands for the number of bindings that
  10431. have not yet been put into a vector by NEST-operations. Thus
  10432. the symbol/value-pairs 1,...,n-m have been active but been nested meanwhile
  10433. and thus inactive again on the stack (if the bindings were static).
  10434. Only some of the pairs n-m+1,...,n can be static and active.
  10435. The frameinfo-byte contains VAR_FRAME_INFO.
  10436. Function- and Macrobindings-Frames
  10437. -----------------------------------
  10438. They are created by FLET and MACROLET.
  10439. The structure of a variable-bindings-frame with n bindings is as follows:
  10440. Offset stack contents
  10441. 12+8n
  10442. 8+8n value 1
  10443. 4+8n symbol 1
  10444. ... ...
  10445. 16 value n
  10446. 12 symbol n
  10447. 8 NEXT_ENV
  10448. 4 m
  10449. 0 Frame-Info; pointer above frame
  10450. NEXT_ENV is the next higher function-environment.
  10451. m is a long word, 0 <= m <= n, and stands for the number of bindings, that
  10452. have not yet been put into a vector by NEST-operations. So the
  10453. symbol/value pais 1,...,n-m have been active, but nested meanwhile and thus
  10454. inactive on the stack again. Only the pairs n-m+1,...,n are active.
  10455. Marker bits are not needed here, as opposed to the variable-bindings frames
  10456. All values are closures or SYS::MACRO objects.
  10457. The content of the Frameinfo-bytes is FUN_FRAME_INFO.
  10458. Interpreted Block-Frames
  10459. ------------------------
  10460. They are created by BLOCK and all constructs that contain an implicit
  10461. BLOCK (e.g. DO, DO*, LOOP, PROG, PROG*, ...). The structure is as follows:
  10462. Offset stack contents
  10463. 16
  10464. 12 NAME
  10465. 8 NEXT_ENV
  10466. 4 SP
  10467. 0 Frame-Info; pointer above frame
  10468. NAME is the name of the block. NEXT_ENV is the next higher Block-Environment.
  10469. SP is a pointer into the program stack, (SP).L is a routine, that unwinds the
  10470. Block-Frame and leaves the block with the values A0-A2/...
  10471. Frame-Info is IBLOCK_FRAME_INFO, possibly with set NESTED_BIT (then NEXT_ENV
  10472. points to an Alist, whose first element is the pair (NAME . <Framepointer>),
  10473. because the block is not DISABLED yet).
  10474. Compiled Block-Frames
  10475. ---------------------
  10476. Structure:
  10477. Offset stack contents
  10478. 12
  10479. 8 Cons (NAME . <Framepointer>)
  10480. 4 SP
  10481. 0 Frame-Info; pointer above frame
  10482. NAME is the name of the block.
  10483. SP is a pointer into the program stack, (SP).L is a routine, that
  10484. unwinds the Block-Frame and leaves the block with the values A0-A2/...
  10485. Frame-Info is CBLOCK_FRAME_INFO.
  10486. Interpreted Tagbody-Frames
  10487. --------------------------
  10488. They are created by TAGBODY and all constructs that contain an implicit
  10489. TAGBODY (e.g. DO, DO*, PROG, PROG*, ...).
  10490. The structure of a Tagbody-Frames with n tags is as follows:
  10491. Offset stack contents
  10492. 12+8n
  10493. 8+8n BODY 1
  10494. 4+8n TAG 1
  10495. ... ...
  10496. 16 BODY n
  10497. 12 TAG n
  10498. 8 NEXT_ENV
  10499. 4 SP
  10500. 0 Frame-Info; pointer above frame
  10501. The tags are the jump destinations ; they are symbols and Integers, that are in
  10502. the Body. The corresponding "value" BODY i contains the part of the body
  10503. that follows TAG i. NEXT_ENV is the next higher Tagbody-Environment.
  10504. SP is a pointer into the program stack, (SP).L is a routine, that executes
  10505. the action (GO TAGi), if it is jumped to with BODYi in A0.
  10506. Frame-Info is ITAGBODY_FRAME_INFO, poss. with set NESTED_BIT (then
  10507. NEXT_ENV points to an Alist, whose first element has the form
  10508. (#(TAG1 ... TAGn) . <Framepointer>), because the Tagbody is not
  10509. DISABLED yet).
  10510. Compiled Tagbody-Frames
  10511. -----------------------
  10512. Structure:
  10513. Offset stack contents
  10514. 12
  10515. 8 Cons (#(TAG1 ... TAGn) . <Framepointer>)
  10516. 4 SP
  10517. 0 Frame-Info; above frame
  10518. TAG1, ..., TAGn are the names of the tags (actually only contained in
  10519. the compiled code to create error messages).
  10520. SP is a pointer into the program stack, (SP).L is a routine, that executes
  10521. the action (GO TAGi), if it has been jumped at with value1 = i (1 <= i <= n)
  10522. Frame-Info is CTAGBODY_FRAME_INFO.
  10523. Catch-Frames
  10524. ------------
  10525. They are created by the Special-Form CATCH. Its structure is as follows:
  10526. Offset stack contents
  10527. 12
  10528. 8 TAG
  10529. 4 SP
  10530. 0 Frame-Info; pointer above frame
  10531. TAG is the tag of the catcher.
  10532. SP is a pointer into the program stack, (SP).L is a routine, that unwinds
  10533. the Frame and returns the values A0-A2/...
  10534. Frame-Info is CATCH_FRAME_INFO.
  10535. Unwind-Protect-Frames
  10536. ---------------------
  10537. They are created by the Special-Form UNWIND-PROTECT and all constructs
  10538. that contain an implicit UNWIND-PROTECT (like WITH-OPEN-STREAM or
  10539. WITH-OPEN-FILE). Their structure is as follows:
  10540. Offset Stack-contents
  10541. 8
  10542. 4 SP
  10543. 0 Frame-Info; pointer above frame
  10544. SP is a pointer into the program stack. (SP).L a routine, that unwinds the
  10545. Frame,saves the current values A0-A2/... executes the cleanup,
  10546. writes the saved values back and finally jumps to the address
  10547. (with RTS), that has been entered into the program stack in place of their own
  10548. and leaves D6 unchanged.
  10549. Handler-Frames
  10550. --------------
  10551. They are created by the macro HANDLER-BIND. Their structure is as follows:
  10552. Offset Stack-contens
  10553. 16
  10554. 12 Cons (#(type1 label1 ... typem labelm) . SPdepth)
  10555. 8 Closure
  10556. 4 SP
  10557. 0 Frame-Info; pointer above frame
  10558. SP is a pointer into the program stack.
  10559. If there is a condition of the type typei
  10560. the closure starting at Bte labeli is interpreted as Handler, where at first
  10561. a piece of the program stack with the length SPdepth is duplicated.
  10562. One variant of Handler-Frames calls a C-Handler:
  10563. Offset Stack-contents
  10564. 16
  10565. 12 Cons (#(type1 label1 ... typem labelm))
  10566. 8 Handler-function
  10567. 4 SP
  10568. 0 Frame-Info; pointer above frame
  10569. SP is a pointer into the program stack.
  10570. If there is a condition of the type typei
  10571. the handler-function is called with the arguments SP
  10572. (arbitrary pointer into the C-Stack), frame (pointer above the frame),
  10573. labeli (arbitrary Lisp-object), condition.
  10574. If the Handler wants to yield control via unwind_upto(FRAME) by itself,
  10575. the Frame has to be created with finish_entry_frame.
  10576. Driver-Frames
  10577. -------------
  10578. They are created upon entry into a top-level loop (most of the time
  10579. a READ-EVAL-PRINT-loop) and are used to continue the previous top-level
  10580. loop after an error message. The structure is simple
  10581. Offset Stack-contens
  10582. 8
  10583. 4 SP
  10584. 0 Frame-Info; pointer above Frame
  10585. SP is a pointer into the program stack. (SP).L is a routine, that
  10586. re-enters the corresponding top-level loop.
  10587. STACK:
  10588. ------
  10589. STACK is the LISP-Stack.
  10590. STACK_0 is the first object on the STACK.
  10591. STACK_1 is the second object on the STACK.
  10592. etc., generally STACK_(n) = (n+1)th object on the STACK.
  10593. pushSTACK(object) puts an object onto the Stack. Synonym: -(STACK).
  10594. popSTACK() returns STACK_0 and removes it from the stack.
  10595. skipSTACK(n); removes n objects from the STACK.
  10596. If you want to save the value of the stack, you do this:
  10597. var gcv_object_t* temp = STACK; ... (no access through temp !) ... setSTACK(STACK = temp);
  10598. but: access through STACKpointable(temp) is possible.
  10599. If you want a pointer that can traverse through the Stack, you do this:
  10600. var gcv_object_t* ptr = &STACK_0; or = STACKpointable(STACK);
  10601. assert( *(ptr STACKop 0) == STACK_0 );
  10602. assert( *(ptr STACKop 1) == STACK_1 );
  10603. ...
  10604. ptr skipSTACKop n;
  10605. assert( *(ptr STACKop 0) == STACK_(n) );
  10606. ...
  10607. This pointer must not be assigned to the STACK again!
  10608. If you store blocks of objects on the STACK and want to get the (n+1)-th block,
  10609. you do this: STACKblock_(type,n). type should be a
  10610. struct-type with sizeof(type) a multiple of sizeof(gcv_object_t). */
  10611. #ifdef STACK_DOWN
  10612. #define STACK_(n) (STACK[(sintP)(n)])
  10613. #define STACKpointable(STACKvar) ((gcv_object_t*)(STACKvar))
  10614. #define skipSTACKop +=
  10615. #define STACKop +
  10616. #define cmpSTACKop <
  10617. #define STACKblock_(type,n) (((type*)STACK)[(sintP)(n)])
  10618. #endif
  10619. #ifdef STACK_UP
  10620. #define STACK_(n) (STACK[-1-(sintP)(n)])
  10621. #define STACKpointable(STACKvar) ((gcv_object_t*)(STACKvar)-1)
  10622. #define skipSTACKop -=
  10623. #define STACKop -
  10624. #define cmpSTACKop >
  10625. #define STACKblock_(type,n) (((type*)STACK)[-1-(sintP)(n)])
  10626. #endif
  10627. #define pushSTACK(obj) (STACK_(-1) = (obj), STACK skipSTACKop -1)
  10628. /* Almost equivalent with *--STACK = obj resp. *STACK++ = obj , but
  10629. Careful: first enter the object into STACK_(-1), THEN modify the STACK! */
  10630. #define popSTACK() (STACK skipSTACKop 1, STACK_(-1))
  10631. #define skipSTACK(n) (STACK skipSTACKop (sintP)(n))
  10632. #if defined(GNU) && defined(MC680X0) && !defined(NO_ASM) && !defined(WIDE) && defined(STACK_register)
  10633. /* With GNU and a 680X0 STACK is in a register. Access and
  10634. modification of the STACK are an atomic unit that cannot be interrupted. */
  10635. #undef pushSTACK
  10636. #undef popSTACK
  10637. #ifdef STACK_DOWN
  10638. /* define pushSTACK(obj) (*--STACK = (obj)) */
  10639. #define pushSTACK(obj) \
  10640. ({ __asm__ __volatile__ ("movel %0,"REGISTER_PREFIX""STACK_register"@-" : : "g" ((object)(obj)) : STACK_register ); })
  10641. /* define popSTACK() (*STACK++) */
  10642. #define popSTACK() \
  10643. ({var object __result; \
  10644. __asm__ __volatile__ ("movel "REGISTER_PREFIX""STACK_register"@+,%0" : "=g" (__result) : : STACK_register ); \
  10645. __result; \
  10646. })
  10647. #endif
  10648. #ifdef STACK_UP
  10649. /* define pushSTACK(obj) (*STACK++ = (obj)) */
  10650. #define pushSTACK(obj) \
  10651. ({ __asm__ __volatile__ ("movel %0,"REGISTER_PREFIX""STACK_register"@+" : : "g" ((object)(obj)) : STACK_register ); })
  10652. /* define popSTACK() (*--STACK) */
  10653. #define popSTACK() \
  10654. ({var object __result; \
  10655. __asm__ __volatile__ ("movel "REGISTER_PREFIX""STACK_register"@-,%0" : "=g" (__result) : : STACK_register ); \
  10656. __result; \
  10657. })
  10658. #endif
  10659. #endif
  10660. #if defined(SPARC) && !defined(GNU) && !defined(__SUNPRO_C) && !defined(MULTITHREAD) && (SAFETY < 2)
  10661. #undef pushSTACK
  10662. #undef popSTACK
  10663. #undef skipSTACK
  10664. #define pushSTACK(obj) (STACK_(-1) = (obj), _setSTACK(STACK STACKop -1))
  10665. #define popSTACK() (_setSTACK(STACK STACKop 1), STACK_(-1))
  10666. #define skipSTACK(n) (_setSTACK(STACK STACKop (sintP)(n)))
  10667. #endif
  10668. %% export_def(STACK_(n));
  10669. %% export_def(skipSTACKop);
  10670. %% export_def(STACKop);
  10671. %% export_def(pushSTACK(obj));
  10672. %% export_def(popSTACK());
  10673. %% export_def(skipSTACK(n));
  10674. #define STACK_0 (STACK_(0))
  10675. #define STACK_1 (STACK_(1))
  10676. #define STACK_2 (STACK_(2))
  10677. #define STACK_3 (STACK_(3))
  10678. #define STACK_4 (STACK_(4))
  10679. #define STACK_5 (STACK_(5))
  10680. #define STACK_6 (STACK_(6))
  10681. #define STACK_7 (STACK_(7))
  10682. #define STACK_8 (STACK_(8))
  10683. #define STACK_9 (STACK_(9))
  10684. #define STACK_10 (STACK_(10))
  10685. /* etc. */
  10686. %% { int i;
  10687. %% for (i=0; i<=10; i++)
  10688. %% printf("#define STACK_%d (STACK_(%d))\n",i,i);
  10689. %% }
  10690. /* Values:
  10691. Highest number of multiple values + 1 */
  10692. #define mv_limit 128
  10693. /* Values are always passed in the MULTIPLE_VALUE_SPACE mv_space:
  10694. uintC mv_count : number of values, >=0, <mv_limit
  10695. object mv_space [mv_limit-1] : the values.
  10696. For mv_count>0 the first mv_count elements are occupied.
  10697. For mv_count=0 the first value = NIL.
  10698. The values in mv_space are not subject to the Garbage Collection! */
  10699. #if !defined(mv_count_register)
  10700. /* a global Variable */
  10701. extern per_thread uintC mv_count;
  10702. #else
  10703. /* a global register */
  10704. register uintC mv_count __asm__(mv_count_register);
  10705. #endif
  10706. extern per_thread object mv_space [mv_limit-1];
  10707. /* Synonyms: */
  10708. #if !defined(value1_register)
  10709. #define value1 mv_space[0]
  10710. #define VALUE1_EXTRA /* and thus has to be treated extra every time... */
  10711. #else
  10712. /* The first value mv_space[0] is stored permanently in a register: */
  10713. register object value1 __asm__(value1_register);
  10714. #define VALUE1_EXTRA /* and thus has to be treated extra every time... */
  10715. #endif
  10716. #define value2 mv_space[1]
  10717. #define value3 mv_space[2]
  10718. #define value4 mv_space[3]
  10719. #define value5 mv_space[4]
  10720. #define value6 mv_space[5]
  10721. #define value7 mv_space[6]
  10722. #define value8 mv_space[7]
  10723. #define value9 mv_space[8]
  10724. /* You might need global variables to pass with setjmp/longjmp: */
  10725. #ifdef NEED_temp_mv_count
  10726. extern per_thread uintC temp_mv_count;
  10727. #define LONGJMP_SAVE_mv_count() temp_mv_count = mv_count
  10728. #define LONGJMP_RESTORE_mv_count() mv_count = temp_mv_count
  10729. #else
  10730. #define LONGJMP_SAVE_mv_count()
  10731. #define LONGJMP_RESTORE_mv_count()
  10732. #endif
  10733. #ifdef NEED_temp_value1
  10734. extern per_thread object temp_value1;
  10735. #define LONGJMP_SAVE_value1() temp_value1 = value1
  10736. #define LONGJMP_RESTORE_value1() value1 = temp_value1
  10737. #else
  10738. #define LONGJMP_SAVE_value1()
  10739. #define LONGJMP_RESTORE_value1()
  10740. #endif
  10741. /* is used by EVAL, CONTROL,
  10742. Macros LIST_TO_MV, MV_TO_LIST, STACK_TO_MV, MV_TO_STACK */
  10743. %% #if notused
  10744. %% export_def(mv_limit);
  10745. %% #endif
  10746. %% #if !defined(mv_count_register)
  10747. %% puts("extern uintC mv_count;");
  10748. %% #else
  10749. %% puts("#ifndef IN_MODULE_CC");
  10750. %% printf("register uintC mv_count __asm__(\"%s\");\n",mv_count_register);
  10751. %% puts("#endif");
  10752. %% #endif
  10753. %% printf("extern object mv_space [%d];\n",mv_limit-1);
  10754. %% #if !defined(value1_register)
  10755. %% emit_define("value1","mv_space[0]");
  10756. %% #else
  10757. %% puts("#ifndef IN_MODULE_CC");
  10758. %% printf("register object value1 __asm__(\"%s\");\n",value1_register);
  10759. %% puts("#endif");
  10760. %% #endif
  10761. %% { int i = 2;
  10762. %% for (; i <=9 ; i++)
  10763. %% printf("#define value%d mv_space[%d]\n",i,i-1);
  10764. %% }
  10765. #ifdef DEBUG_GCSAFETY
  10766. /* Add support for the 'mv_space' expression to the GCTRIGGER1/2/... macros. */
  10767. inline void inc_allocstamp (object (&mvsp)[mv_limit-1]) {
  10768. inc_allocstamp(value1);
  10769. var uintC count = mv_count;
  10770. if (count > 1) {
  10771. var object* mvp = &mv_space[1];
  10772. dotimespC(count,count-1, { inc_allocstamp(*mvp++); });
  10773. }
  10774. }
  10775. #endif
  10776. /* Returns the bottom objects from the STACK as multiple values.
  10777. STACK_to_mv(count)
  10778. count: number of objects, < mv_limit. */
  10779. #if !defined(VALUE1_EXTRA)
  10780. #define STACK_to_mv(countx) \
  10781. do { var uintC count = (countx); \
  10782. mv_count = count; \
  10783. if (count == 0) value1 = NIL; \
  10784. else { /* pointer behind space for last value */\
  10785. object* mvp = &mv_space[count]; \
  10786. dotimespC(count,count, { *--mvp = popSTACK(); } ); \
  10787. } } while(0)
  10788. #else
  10789. #define STACK_to_mv(countx) \
  10790. do { var uintC count = (countx); \
  10791. mv_count = count; \
  10792. if (count == 0) value1 = NIL; \
  10793. else { \
  10794. count--; \
  10795. if (count > 0) { /* pointer behind space for last value */\
  10796. object* mvp = &mv_space[1+count]; \
  10797. dotimespC(count,count, { *--mvp = popSTACK(); } ); \
  10798. } \
  10799. value1 = popSTACK(); \
  10800. } } while(0)
  10801. #endif
  10802. /* is used by EVAL, CONTROL */
  10803. %% export_def(STACK_to_mv(countx));
  10804. /* Puts all values onto the STACK.
  10805. mv_to_STACK()
  10806. > mv_count/mv_space : values
  10807. < values on the Stack (first value on top)
  10808. STACK-Overflow is checked.
  10809. modifies STACK */
  10810. #if !defined(VALUE1_EXTRA)
  10811. #define mv_to_STACK() \
  10812. do { var uintC count = mv_count; \
  10813. if (count!=0) { /* no values-> nothing onto the STACK */\
  10814. var object* mvp = &mv_space[0]; \
  10815. get_space_on_STACK(count); \
  10816. dotimespC(count,count, { pushSTACK(*mvp++); } ); \
  10817. } } while(0)
  10818. #else
  10819. #define mv_to_STACK() \
  10820. do { var uintC count = mv_count; \
  10821. if (count!=0) { /* no values -> nothing onto the STACK */\
  10822. get_space_on_STACK(count); \
  10823. pushSTACK(value1); \
  10824. count--; \
  10825. if (count > 0) { \
  10826. var object* mvp = &mv_space[1]; \
  10827. dotimespC(count,count, { pushSTACK(*mvp++); } ); \
  10828. } \
  10829. } } while(0)
  10830. #endif
  10831. /* is used by EVAL, CONTROL */
  10832. /* Returns the elements of a list as multiple values.
  10833. list_to_mv(list,error_statement)
  10834. error_statement: if there's an error (too many values). */
  10835. #define NEXT_MV *mvp++ = Car(l); l = Cdr(l); count++
  10836. #if !defined(VALUE1_EXTRA)
  10837. #define list_to_mv(lst,error_statement) \
  10838. do { var object l = (lst); \
  10839. var uintC count = 0; \
  10840. if (atomp(l)) value1 = NIL; \
  10841. else { \
  10842. var object* mvp = &mv_space[0]; \
  10843. NEXT_MV; if (atomp(l)) goto mv_done; \
  10844. NEXT_MV; if (atomp(l)) goto mv_done; \
  10845. NEXT_MV; if (atomp(l)) goto mv_done; \
  10846. do { if (count==mv_limit-1) { error_statement; } NEXT_MV; \
  10847. } while (consp(l)); \
  10848. } \
  10849. mv_done: \
  10850. if (!nullp(l)) error_proper_list_dotted(S(values_list),l); \
  10851. mv_count = count; \
  10852. } while(0)
  10853. #else
  10854. #define list_to_mv(lst,error_statement) \
  10855. do { var object l = (lst); \
  10856. var uintC count = 0; \
  10857. if (atomp(l)) value1 = NIL; \
  10858. else { \
  10859. value1 = Car(l); l = Cdr(l); count++; if (atomp(l)) goto mv_done; \
  10860. {var object* mvp = &mv_space[1]; \
  10861. NEXT_MV; if (atomp(l)) goto mv_done; \
  10862. NEXT_MV; if (atomp(l)) goto mv_done; \
  10863. do { if (count==mv_limit-1) { error_statement; } NEXT_MV; \
  10864. } while (consp(l)); \
  10865. }} \
  10866. mv_done: \
  10867. if (!nullp(l)) error_proper_list_dotted(S(values_list),l); \
  10868. mv_count = count; \
  10869. } while(0)
  10870. #endif
  10871. /* is used by EVAL, CONTROL */
  10872. /* Gives the list of the multiple values on -(STACK).
  10873. mv_to_list()
  10874. can trigger GC */
  10875. #define mv_to_list() \
  10876. do { \
  10877. mv_to_STACK(); /* at first all values onto the stack */\
  10878. GCTRIGGER(); \
  10879. pushSTACK(NIL); /* head of the list */\
  10880. { var uintC count; \
  10881. dotimesC(count,mv_count, { /* until all values have been used: */\
  10882. var object l = allocate_cons(); /* new cell */\
  10883. Cdr(l) = popSTACK(); /* list so far */\
  10884. Car(l) = STACK_0; /* next value */\
  10885. STACK_0 = l; /* save new cons */\
  10886. }); \
  10887. } } while(0)
  10888. /* is used by EVAL, CONTROL, DEBUG */
  10889. /* Error message if there are too many values
  10890. error_mv_toomany(caller);
  10891. > caller: caller, a Symbol */
  10892. nonreturning_function(extern, error_mv_toomany, (object caller));
  10893. /* is used by EVAL, CONTROL, LISPARIT */
  10894. %% #if notused
  10895. %% puts("nonreturning_function(extern, error_mv_toomany, (object caller));");
  10896. %% #endif
  10897. #if !defined(back_trace_register)
  10898. extern per_thread p_backtrace_t back_trace;
  10899. #else
  10900. register p_backtrace_t back_trace __asm__(back_trace_register);
  10901. #endif
  10902. #define subr_self back_trace->bt_function
  10903. %% #if !defined(back_trace_register)
  10904. %% puts("extern p_backtrace_t back_trace;");
  10905. %% #else
  10906. %% puts("#ifndef IN_MODULE_CC");
  10907. %% printf("register p_backtrace_t back_trace __asm__(\"%s\");\n",back_trace_register);
  10908. %% puts("#endif");
  10909. %% #endif
  10910. %% export_def(subr_self);
  10911. /* Within the body of a SUBR: Access to the arguments.
  10912. A SUBR with a fixed number of arguments can access them through the STACK:
  10913. STACK_0 = last argument, STACK_1 = second to last argument etc.
  10914. Clean STACK: with skipSTACK(number of arguments) .
  10915. A SUBR with arbitrarily many arguments (&REST-Parameter) gets passed:
  10916. uintC argcount the number of the remaining arguments
  10917. gcv_object_t* rest_args_pointer Pointer above the remaining arguments
  10918. Additionally:
  10919. gcv_object_t* args_end_pointer Pointer below all arguments, depends on the STACK
  10920. Additionally possible:
  10921. gcv_object_t* args_pointer = rest_args_pointer STACKop (fixed number of arguments);
  10922. Pointer above the first argument
  10923. Typical Loop-Processing:
  10924. from the front:
  10925. while (argcount != 0) {
  10926. var object arg = NEXT(rest_args_pointer); ...; argcount--;
  10927. }
  10928. while (rest_args_pointer != args_end_pointer) {
  10929. var object arg = NEXT(rest_args_pointer); ...;
  10930. }
  10931. from the back:
  10932. while (argcount != 0) {
  10933. var object arg = BEFORE(args_end_pointer); ...; argcount--;
  10934. }
  10935. while (rest_args_pointer != args_end_pointer) {
  10936. var object arg = BEFORE(args_end_pointer); ...;
  10937. }
  10938. The macros NEXT and BEFORE modify their arguments!
  10939. Clean STACK: with set_args_end_pointer(args_pointer)
  10940. or skipSTACK((fixed number of arguments) + (uintL) (number of remainung arguments)) . */
  10941. #define args_end_pointer STACK
  10942. #define set_args_end_pointer(new_args_end_pointer) \
  10943. setSTACK(STACK = (new_args_end_pointer))
  10944. #ifdef STACK_DOWN
  10945. #define NEXT(argpointer) (*(--(argpointer)))
  10946. #define BEFORE(argpointer) (*((argpointer)++))
  10947. #endif
  10948. #ifdef STACK_UP
  10949. #define NEXT(argpointer) (*((argpointer)++))
  10950. #define BEFORE(argpointer) (*(--(argpointer)))
  10951. #endif
  10952. /* Next(pointer) yields the same value as NEXT(pointer),
  10953. but without changing the value of pointer.
  10954. Before(pointer) yields the same value as BEFORE(pointer),
  10955. but without changing the value of pointer. */
  10956. #define Next(pointer) (*(STACKpointable(pointer) STACKop -1))
  10957. #define Before(pointer) (*(STACKpointable(pointer) STACKop 0))
  10958. %% emit_define("args_end_pointer","STACK");
  10959. %% #if notused
  10960. %% emit_define("set_args_end_pointer(new_args_end_pointer)","STACK = (new_args_end_pointer)");
  10961. %% export_def(NEXT(argpointer));
  10962. %% export_def(BEFORE(argpointer));
  10963. %% emit_define("Next(pointer)","(*(STACKpointable(pointer) STACKop -1))");
  10964. %% emit_define("Before(pointer)","(*(STACKpointable(pointer) STACKop 0))");
  10965. %% #endif
  10966. /* Environments: */
  10967. typedef struct {
  10968. object var_env; /* Variable-Bindings-Environment */
  10969. object fun_env; /* Function-Bindings-Environment */
  10970. object block_env; /* Block-Environment */
  10971. object go_env; /* Tagbody/Go-Environment */
  10972. object decl_env; /* Declarations-Environment */
  10973. } environment_t;
  10974. typedef struct {
  10975. gcv_object_t var_env; /* Variable-Bindings-Environment */
  10976. gcv_object_t fun_env; /* Function-Bindings-Environment */
  10977. gcv_object_t block_env; /* Block-Environment */
  10978. gcv_object_t go_env; /* Tagbody/Go-Environment */
  10979. gcv_object_t decl_env; /* Declarations-Environment */
  10980. } gcv_environment_t;
  10981. /* The current Environment: */
  10982. extern per_thread gcv_environment_t aktenv;
  10983. /* Macro: Puts five single Environments on the STACK
  10984. and makes a single Environment out of them.
  10985. make_STACK_env(venv,fenv,benv,genv,denv, env5 = );
  10986. > object venv,fenv,benv,genv,denv: 5 single Environments
  10987. < gcv_environment_t* env5: pointer to the Environment on the Stack */
  10988. #ifdef STACK_UP
  10989. #define make_STACK_env(venv,fenv,benv,genv,denv,env5_assignment) \
  10990. do { pushSTACK(venv); pushSTACK(fenv); pushSTACK(benv); \
  10991. pushSTACK(genv); pushSTACK(denv); \
  10992. env5_assignment &STACKblock_(gcv_environment_t,0); } while(0)
  10993. #endif
  10994. #ifdef STACK_DOWN
  10995. #define make_STACK_env(venv,fenv,benv,genv,denv,env5_assignment) \
  10996. do { pushSTACK(denv); pushSTACK(genv); pushSTACK(benv); \
  10997. pushSTACK(fenv); pushSTACK(venv); \
  10998. env5_assignment &STACKblock_(gcv_environment_t,0); } while(0)
  10999. #endif
  11000. /* Frameinfobits in Frames:
  11001. in the Frame-Info-Byte (tint): */
  11002. #if (oint_type_len>=7) && 0 /* provisionally?? */
  11003. /* Bit numbers in the Frame-Info-Byte:
  11004. occupy Bits 6..0 (resp. Bits 7,5..0 if garcol_bit_t=7). */
  11005. #ifdef TYPECODES
  11006. #define FB7 garcol_bit_t
  11007. #define FB6 (garcol_bit_t>TB5 ? TB5 : TB6)
  11008. #define FB5 (garcol_bit_t>TB4 ? TB4 : TB5)
  11009. #define FB4 (garcol_bit_t>TB3 ? TB3 : TB4)
  11010. #define FB3 (garcol_bit_t>TB2 ? TB2 : TB3)
  11011. #define FB2 (garcol_bit_t>TB1 ? TB1 : TB2)
  11012. #define FB1 (garcol_bit_t>TB0 ? TB0 : TB1)
  11013. #else
  11014. #define FB7 garcol_bit_o
  11015. #define FB6 30
  11016. #define FB5 29
  11017. #define FB4 28
  11018. #define FB3 27
  11019. #define FB2 26
  11020. #define FB1 25
  11021. #endif
  11022. /* depending on it: */
  11023. #define frame_bit_t FB7 /* garcol_bit as FRAME-identifier */
  11024. #define skip2_bit_t FB6 /* unset if GC has to skip two longwords */
  11025. #define unwind_bit_t FB5 /* set if there's something to do while */
  11026. /* unwinding the frame */
  11027. /* skip2-Bit=1 ==> unwind-Bit=1.
  11028. for further Information within the Frames with skip2-Bit=1: */
  11029. #define envbind_bit_t FB4 /* Bit set for ENV-Frames. */
  11030. /* Bit is unset for DYNBIND-Frames. */
  11031. /* for further identification of the ENV-Frames: */
  11032. #define envbind_case_mask_t (bit(FB3)|bit(FB2)|bit(FB1))
  11033. /* for further discrimination within the Frames with skip2-Bit=0: */
  11034. #define entrypoint_bit_t FB4 /* Bit is set, if FRAME contains */
  11035. /* a non-local entrypoint, with Offset SP_, SP is on the STACK.
  11036. Bit is unset for VAR/FUN-Frame and CALLBACK-Frame.
  11037. for further discrimination in BLOCK/TAGBODY/APPLY/EVAL/CATCH/UNWIND_PROTECT/HANDLER/DRIVER: */
  11038. #define blockgo_bit_t FB3 /* Bit set for BLOCK- and TAGBODY-FRAME */
  11039. /* for further discrimination in BLOCK/TAGBODY: */
  11040. #define cframe_bit_t FB1 /* set for compiled BLOCK/TAGBODY-Frames, */
  11041. /* unset for interpreted BLOCK/TAGBODY-Frames */
  11042. #define nested_bit_t unwind_bit_t /* set for IBLOCK and ITAGBODY, */
  11043. /* if Exitpoint resp. Tags were nested */
  11044. /* for further discrimination in APPLY/EVAL/CATCH/UNWIND_PROTECT/HANDLER/DRIVER: */
  11045. #define dynjump_bit_t FB2 /* unset for APPLY and EVAL, set */
  11046. /* for CATCH/UNWIND_PROTECT/DRIVER-Frames */
  11047. #define trapped_bit_t unwind_bit_t /* set for APPLY and EVAL, if */
  11048. /* interrupted while unwinding the Frame */
  11049. /* unwind-Bit set for UNWIND_PROTECT/DRIVER/TRAPPED_APPLY/TRAPPED_EVAL,
  11050. else unset. */
  11051. #define eval_bit_t FB1 /* set for EVAL-Frames, */
  11052. /* unset for APPLY-Frames */
  11053. #define driver_bit_t FB1 /* set for DRIVER-Frames, */
  11054. /* unset for UNWIND_PROTECT-Frames */
  11055. #define handler_bit_t FB1 /* set for HANDLER-Frames, */
  11056. /* unset for CATCH-Frames */
  11057. /* for further discrimination in VAR/FUN/CALLBACK: */
  11058. #define callback_bit_t FB3 /* Bit is unset for CALLBACK-Frames. */
  11059. /* Bit is set for VAR/FUN-Frames. */
  11060. /* for further discrimination in VAR/FUN: */
  11061. #define fun_bit_t FB2 /* set for FUN-Frame, unset for VAR-Frame */
  11062. /* on objects on the STACK (oint): */
  11063. #define frame_bit_o (frame_bit_t+oint_type_shift)
  11064. #define skip2_bit_o (skip2_bit_t+oint_type_shift)
  11065. #define unwind_bit_o (unwind_bit_t+oint_type_shift)
  11066. #define envbind_bit_o (envbind_bit_t+oint_type_shift)
  11067. #define callback_bit_o (callback_bit_t+oint_type_shift)
  11068. #define entrypoint_bit_o (entrypoint_bit_t+oint_type_shift)
  11069. #define blockgo_bit_o (blockgo_bit_t+oint_type_shift)
  11070. #define cframe_bit_o (cframe_bit_t+oint_type_shift)
  11071. #define nested_bit_o (nested_bit_t+oint_type_shift)
  11072. #define dynjump_bit_o (dynjump_bit_t+oint_type_shift)
  11073. #define trapped_bit_o (trapped_bit_t+oint_type_shift)
  11074. #define eval_bit_o (eval_bit_t+oint_type_shift)
  11075. #define driver_bit_o (driver_bit_t+oint_type_shift)
  11076. #define handler_bit_o (handler_bit_t+oint_type_shift)
  11077. #define fun_bit_o (fun_bit_t+oint_type_shift)
  11078. /* single Frame-Info-Bytes: */
  11079. #define DYNBIND_frame_info /* %1110... */ (bit(FB7)|bit(FB6)|bit(FB5))
  11080. #define ENV1V_frame_info /* %1111000 */ (bit(FB7)|bit(FB6)|bit(FB5)|bit(FB4))
  11081. #define ENV1F_frame_info /* %1111001 */ (bit(FB7)|bit(FB6)|bit(FB5)|bit(FB4)|bit(FB1))
  11082. #define ENV1B_frame_info /* %1111010 */ (bit(FB7)|bit(FB6)|bit(FB5)|bit(FB4)|bit(FB2))
  11083. #define ENV1G_frame_info /* %1111011 */ (bit(FB7)|bit(FB6)|bit(FB5)|bit(FB4)|bit(FB2)|bit(FB1))
  11084. #define ENV1D_frame_info /* %1111100 */ (bit(FB7)|bit(FB6)|bit(FB5)|bit(FB4)|bit(FB3))
  11085. #define ENV2VD_frame_info /* %1111101 */ (bit(FB7)|bit(FB6)|bit(FB5)|bit(FB4)|bit(FB3)|bit(FB1))
  11086. #define ENV5_frame_info /* %1111110 */ (bit(FB7)|bit(FB6)|bit(FB5)|bit(FB4)|bit(FB3)|bit(FB2))
  11087. #ifdef HAVE_SAVED_REGISTERS
  11088. #define CALLBACK_frame_info /* %10100.. */ (bit(FB7)|bit(FB5))
  11089. #endif
  11090. #define VAR_frame_info /* %101010. */ (bit(FB7)|bit(FB5)|bit(FB3))
  11091. #define FUN_frame_info /* %101011. */ (bit(FB7)|bit(FB5)|bit(FB3)|bit(FB2))
  11092. #define IBLOCK_frame_info /* %1001100 */ (bit(FB7)|bit(FB4)|bit(FB3))
  11093. #define NESTED_IBLOCK_frame_info /* %1011100 */ (bit(FB7)|bit(FB5)|bit(FB4)|bit(FB3))
  11094. #define ITAGBODY_frame_info /* %1001110 */ (bit(FB7)|bit(FB4)|bit(FB3)|bit(FB2))
  11095. #define NESTED_ITAGBODY_frame_info /* %1011110 */ (bit(FB7)|bit(FB5)|bit(FB4)|bit(FB3)|bit(FB2))
  11096. #define CBLOCK_CTAGBODY_frame_info /* %1011101 */ (bit(FB7)|bit(FB5)|bit(FB4)|bit(FB3)|bit(FB1))
  11097. #define APPLY_frame_info /* %1001000 */ (bit(FB7)|bit(FB4))
  11098. #define TRAPPED_APPLY_frame_info /* %1011000 */ (bit(FB7)|bit(FB5)|bit(FB4))
  11099. #define EVAL_frame_info /* %1001001 */ (bit(FB7)|bit(FB4)|bit(FB1))
  11100. #define TRAPPED_EVAL_frame_info /* %1011001 */ (bit(FB7)|bit(FB5)|bit(FB4)|bit(FB1))
  11101. #define CATCH_frame_info /* %1001010 */ (bit(FB7)|bit(FB4)|bit(FB2))
  11102. #define HANDLER_frame_info /* %1001011 */ (bit(FB7)|bit(FB4)|bit(FB2)|bit(FB1))
  11103. #define UNWIND_PROTECT_frame_info /* %1011010 */ (bit(FB7)|bit(FB5)|bit(FB4)|bit(FB2))
  11104. #define DRIVER_frame_info /* %1011011 */ (bit(FB7)|bit(FB5)|bit(FB4)|bit(FB2)|bit(FB1))
  11105. #endif
  11106. #if (oint_type_len==6) || 1 /* provisionally?? */
  11107. /* bit numbers in Frame-Info-Byte:
  11108. occupy Bits 5..0 (resp. Bits 7,4..0 if garcol_bit_t=7). */
  11109. #ifdef TYPECODES
  11110. #define FB6 garcol_bit_t
  11111. #define FB5 (garcol_bit_t>TB4 ? TB4 : TB5)
  11112. #define FB4 (garcol_bit_t>TB3 ? TB3 : TB4)
  11113. #define FB3 (garcol_bit_t>TB2 ? TB2 : TB3)
  11114. #define FB2 (garcol_bit_t>TB1 ? TB1 : TB2)
  11115. #define FB1 (garcol_bit_t>TB0 ? TB0 : TB1)
  11116. #else /* HEAPCODES */
  11117. #define FB6 garcol_bit_o
  11118. #ifdef STANDARD_HEAPCODES
  11119. #define FB5 (garcol_bit_o-1)
  11120. #define FB4 (garcol_bit_o-2)
  11121. #define FB3 (garcol_bit_o-3)
  11122. #define FB2 (garcol_bit_o-4)
  11123. #define FB1 (garcol_bit_o-5)
  11124. #endif
  11125. #ifdef LINUX_NOEXEC_HEAPCODES
  11126. #define FB5 5
  11127. #define FB4 4
  11128. #define FB3 3
  11129. #define FB2 2
  11130. #define FB1 1
  11131. #endif
  11132. #endif
  11133. /* depending on it: */
  11134. #define frame_bit_t FB6 /* garcol_bit as FRAME-indicator */
  11135. #define skip2_bit_t FB5 /* unset if the GC has to skip two long words */
  11136. /* define unwind_limit_t ... # above:
  11137. if there's something to be done while to unwind a Frame
  11138. skip2-Bit=1 ==> >= unwind-limit.
  11139. for further information within the Frames with skip2-Bit=1: */
  11140. #define envbind_bit_t FB4 /* Bit is set for ENV-Frames. */
  11141. /* Bit unset for DYNBIND-Frames. */
  11142. /* for further identification within the ENV-Frames: */
  11143. #define envbind_case_mask_t (bit(FB3)|bit(FB2)|bit(FB1))
  11144. /* for further discrimination with the Frames with skip2-Bit=0:
  11145. define entrypoint_limit_t ... # below:
  11146. if FRAME contains a non-local entry point
  11147. with Offset SP_ SP is on the STACK.
  11148. above: for VAR/FUN-Frame and CALLBACK-Frame.
  11149. for further discrimination in BLOCK/TAGBODY/APPLY/EVAL/CATCH/UNWIND_PROTECT/HANDLER/DRIVER: */
  11150. #define blockgo_bit_t FB3 /* Bit set for BLOCK- and TAGBODY-FRAME */
  11151. /* for further discrimination in BLOCK/TAGBODY: */
  11152. #define cframe_bit_t FB4 /* set for compiled, unset for */
  11153. /* interpreted BLOCK/TAGBODY-Frames */
  11154. #define nested_bit_t FB2 /* set for IBLOCK and ITAGBODY, */
  11155. /* if exit point or Tags have been nested */
  11156. /* for further discrimination in APPLY/EVAL/CATCH/UNWIND_PROTECT/HANDLER/DRIVER: */
  11157. #define dynjump_bit_t FB2 /* unset for APPLY and EVAL, set */
  11158. /* for CATCH/UNWIND_PROTECT/HANDLER/DRIVER-Frames */
  11159. #define trapped_bit_t FB4 /* set for APPLY and EVAL, if interruped while */
  11160. /* unwinding the Frames */
  11161. /* >= unwind_limit_t for UNWIND_PROTECT/DRIVER/TRAPPED_APPLY/TRAPPED_EVAL,
  11162. < unwind_limit_t else. */
  11163. #define eval_bit_t FB1 /* set for EVAL-Frames, */
  11164. /* unset for APPLY-Frames */
  11165. #define driver_bit_t FB1 /* set for DRIVER-Frames, */
  11166. /* unset for UNWIND_PROTECT-Frames */
  11167. #define handler_bit_t FB1 /* set for HANDLER-Frames, */
  11168. /* unset for CATCH-Frames */
  11169. /* for further discrimination in VAR/FUN/CALLBACK: */
  11170. #define callback_bit_t FB2 /* Bit is unset for CALLBACK-Frames. */
  11171. /* Bit is set for VAR/FUN-Frames. */
  11172. /* for further discrimination in VAR/FUN: */
  11173. #define fun_bit_t FB1 /* set for FUN-Frame, unset for VAR-Frame */
  11174. /* in Objects on the STACK (oint): */
  11175. #define frame_bit_o (frame_bit_t+oint_type_shift)
  11176. #define skip2_bit_o (skip2_bit_t+oint_type_shift)
  11177. #define envbind_bit_o (envbind_bit_t+oint_type_shift)
  11178. #define callback_bit_o (callback_bit_t+oint_type_shift)
  11179. #define blockgo_bit_o (blockgo_bit_t+oint_type_shift)
  11180. #define cframe_bit_o (cframe_bit_t+oint_type_shift)
  11181. #define nested_bit_o (nested_bit_t+oint_type_shift)
  11182. #define dynjump_bit_o (dynjump_bit_t+oint_type_shift)
  11183. #define trapped_bit_o (trapped_bit_t+oint_type_shift)
  11184. #define eval_bit_o (eval_bit_t+oint_type_shift)
  11185. #define driver_bit_o (driver_bit_t+oint_type_shift)
  11186. #define handler_bit_o (handler_bit_t+oint_type_shift)
  11187. #define fun_bit_o (fun_bit_t+oint_type_shift)
  11188. /* single Frame-Info-Bytes: */
  11189. #define APPLY_frame_info /* %100000 */ (bit(FB6))
  11190. #define EVAL_frame_info /* %100001 */ (bit(FB6)|bit(FB1))
  11191. #define CATCH_frame_info /* %100010 */ (bit(FB6)|bit(FB2))
  11192. #define HANDLER_frame_info /* %100011 */ (bit(FB6)|bit(FB2)|bit(FB1))
  11193. #define IBLOCK_frame_info /* %100100 */ (bit(FB6)|bit(FB3))
  11194. #define ITAGBODY_frame_info /* %100101 */ (bit(FB6)|bit(FB3)|bit(FB1))
  11195. #define unwind_limit_t (bit(FB6)|bit(FB3)|bit(FB2))
  11196. #define NESTED_IBLOCK_frame_info /* %100110 */ (bit(FB6)|bit(FB3)|bit(FB2))
  11197. #define NESTED_ITAGBODY_frame_info /* %100111 */ (bit(FB6)|bit(FB3)|bit(FB2)|bit(FB1))
  11198. #define TRAPPED_APPLY_frame_info /* %101000 */ (bit(FB6)|bit(FB4))
  11199. #define TRAPPED_EVAL_frame_info