summaryrefslogtreecommitdiffstats
path: root/scmfig.h
blob: 3e4b531d51cf3aabeff75443b72c4a9aeb2a1252 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
/* Copyright (C) 1990-1999 Free Software Foundation, Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this software; see the file COPYING.  If not, write to
 * the Free Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111, USA.
 *
 * As a special exception, the Free Software Foundation gives permission
 * for additional uses of the text contained in its release of SCM.
 *
 * The exception is that, if you link the SCM library with other files
 * to produce an executable, this does not by itself cause the
 * resulting executable to be covered by the GNU General Public License.
 * Your use of that executable is in no way restricted on account of
 * linking the SCM library code into it.
 *
 * This exception does not however invalidate any other reasons why
 * the executable file might be covered by the GNU General Public License.
 *
 * This exception applies only to the code released by the
 * Free Software Foundation under the name SCM.  If you copy
 * code from other Free Software Foundation releases into a copy of
 * SCM, as the General Public License permits, the exception does
 * not apply to the code that you add in this way.  To avoid misleading
 * anyone as to the status of such modified files, you must delete
 * this exception notice from them.
 *
 * If you write modifications of your own for SCM, it is your choice
 * whether to permit this exception to apply to your modifications.
 * If you do not wish that, delete this exception notice.
 */

/* "scmfig.h" system-dependent configuration.
   Author: Aubrey Jaffer */

#ifdef sequent
# include <strings.h>
# define strchr index
# define strrchr rindex
#else
# ifndef PLAN9
#  include <string.h>
# endif
#endif

/* MS Windows signal handling hack added by Rainer Urian */
/* 
   SCM crashes on WindowsNT after hitting control-c.

   This is because signal handling in windows console applications is
   rather different from unix apps.  If control-c is hit on a console
   application Windows creates a new thread which executes the
   control-c signal handler.  Now, if the SCM handler does the longjmp
   back to the repl loop it does it via the stack of the signal
   handler thread which results always ever is an access violation.

   The solution to this problem is to let the signal handler thread
   raise a software interrupt in the main thread.

   This is done with the following  steps:

   1. contol-c is hit

   2. Windows creates the signal handler thread which in turn executes
   the routine win32_sigint as its signal handler.

   3. The handler suspends the main thread and gets the main threads
   register context.

   4. The handler simulates an interrupt call on the main thread by
   pointing Eip to the sigintstub stub function and also simulates a
   pushad , pushf of the main threads registers

   5. The handler resumes the main thread which when scheduled will
   execute sigintstub, which in turn calls the proper signal interupt
   (scamble_signal)
*/
#ifdef _WIN32
/* POCKETCONSOLE has the signal handler implemented in the  runtime */
# ifndef POCKETCONSOLE
#  define WINSIGNALS
# endif
#endif


#include "scmflags.h"		/* user specified, system independent flags */

/* IMPLINIT is the full pathname (surrounded by double quotes) of
   Init.scm, the Scheme initialization code.  This is best defined in
   the makefile.  If available, SCM uses the value of environment
   variable SCM_INIT_PATH instead of IMPLINIT. */

/* #define IMPLINIT "/usr/jaffer/scm/Init.scm" */

/* INITS is calls to initialization routines for any compiled
   libraries being linked into scm.  This is best done in the makefile.
File:	INITS line:		functions defined:

sc2.c	init_sc2();	substring-move-left!, substring-move-right!,
			substring-fill!, append!, and last-pair
rgx.c	init_rgx();	regcomp and regexec. */

/* #define INITS init_sc2(); */

/* #define SICP */

/* setbuf(0) needs to be done for tty ports in order for CHAR-READY?
   to work.  This can cause problems under MSDOS and other systems. */

/* #define NOSETBUF */

/* #define RECKLESS */

/* #define CAUTIOUS */

/* #define STACK_LIMIT (HEAP_SEG_SIZE/2) */

/* #define BIGNUMS */

/* #define ARRAYS */

/* #define FLOATS */

/* Define SINGLES if you want single precision floats and
   (sizeof(float)==sizeof(long)) */

#ifdef FLOATS
# ifndef _MSC_VER
#  define SINGLES
# endif
#endif

/* #define SINGLESONLY */

/* Define CDR_DOUBLES if (sizeof(double)==sizeof(long)), i.e.
   a `single' is really a double. */
#ifdef FLOATS
# ifdef __alpha
#  define CDR_DOUBLES
# endif

# ifdef _UNICOS		/* doubles are no better than singles on Cray. */
#  define SINGLESONLY
# endif

# ifdef CDR_DOUBLES
#  define SINGLES
#  define SINGLESONLY
# endif
#endif

/* #define ENGNOT */

/* Define SUN_DL to configure code in "dynl.c" so that dynamic linking
   is done using the SUN dynamic linking library "dl". */

/* #define SUN_DL */

/* Define DLD to configure code in "dynl.c" so that dynamic linking is
   done using the "dld" library.  DLD is ported to Linux, VAX
   (Ultrix), Sun 3 (SunOS 3.4 and 4.0), SPARCstation (SunOS 4.0),
   Sequent Symmetry (Dynix), and Atari ST.  See scm/README or
   scm/ANNOUNCE for ftp sites offering dld. */

/* #define DLD */

/* Define HAVE_DYNL if dynamic linking is available */

#ifdef DLD
# define HAVE_DYNL
#endif
#ifdef SUN_DL
# define HAVE_DYNL
#endif
#ifdef HP_SHL
# define HAVE_DYNL
#endif

#ifdef HAVE_DYNL
# define CCLO
#endif

/* Define GC_FREE_SEGMENTS if you want segments of unused heap to
   be freed up after garbage collection.  Don't define it if you
   never want the heap to shrink. */

#ifndef DONT_GC_FREE_SEGMENTS
# define GC_FREE_SEGMENTS
#endif

/* MEMOIZE_LOCALS means to convert references to local variables to ILOCs,
   (relative lexical addresses into the environment).  This memoization
   makes evaluated Scheme code harder to read, so you may want to undefine
   this flag for debugging -- but SCM will run 3 to 5 times slower */
#define MEMOIZE_LOCALS

/* #define CHEAP_CONTINUATIONS */

/* #define TICKS */

/* PROT386 should be defined on the compilation command line if the
   program is to be run on an intel 386 in protected mode.  `Huge'
   pointers common on MSDOS compilers do not work in protected mode.
   PROT386 is required if scm is to run as part of a Microsoft Windows
   application.  Added by Stephen Adams 8 May 92 */

/* #define PROT386 */

/* #define NON_PREEMPTIVE if you are using an non-preemptive operating
   system in which periodic polling for interrupts is necessary.
   Provide your own main procedure (e.g., WinMain, in Windows) or
   modify "scmmain.c".  Define and initialize unsigned int poll_count,
   and provide a procedure named poll_routine(), which POLL calls each
   time poll_count reaches zero.  poll_routine() must reinitialize
   poll_count.  It may also check for external actions, such as
   Windows messages.  The value assigned to poll_count can be quite
   large, e.g., 1000, while still maintaining good response time. */

/* #define CAREFUL_INTS */

/* Define MACRO if you want C level support for hygienic and referentially
   transparent macros. */

/* #define MACRO */

/* STDC_HEADERS indicates that the include file names are the same as
   ANSI C.  For most modern systems this is the case. */

/* added by Yasuaki Honda */
#ifdef THINK_C
# define __STDC__
# ifndef macintosh
#  define macintosh
# endif
#endif

/* added by Bob Schumaker, cobblers@netcom.com */
#ifdef __MWERKS__
# ifndef macintosh
#  define macintosh
# endif
# define bzero(p, n)	memset(p, 0, n)
# define bcopy			memcpy
#endif
/* added by Denys Duchier */
#ifndef SVR4
# ifdef __SVR4
#  define SVR4
# endif
#endif

#ifdef __STDC__
# ifndef __HIGHC__		/* overly fussy compiler */
#  define USE_ANSI_PROTOTYPES
# endif
# ifndef __GNUC__
#  define STDC_HEADERS
# else
#  ifdef sparc
#   ifdef SVR4
#    define STDC_HEADERS
#   endif
#  else
#   ifndef tahoe
#    ifndef sun
#     define STDC_HEADERS
#    endif
#   endif
#  endif
# endif
#endif
#ifdef __alpha
# define SHORT_INT
#endif
#ifdef __ia64
# define SHORT_INT
# define CDR_DOUBLES
#endif
#ifdef MSDOS			/* Microsoft C 5.10 and 6.00A */
# ifndef GO32
#  define SHORT_INT
#  define SHORT_SIZET
# endif
#endif
#ifdef _QC
# define SHORT_INT
# define SHORT_SIZET
#endif
#ifdef __TURBOC__
# define SHORT_INT
# define SHORT_SIZET
# define LACK_SBRK
# ifndef __TOS__
#  define MSDOS
# endif
#endif
#ifdef __HIGHC__
# define LACK_SBRK
#endif
#ifdef _WIN32
# define MSDOS
# define LACK_SBRK
# define LACK_TIMES
#endif
#ifdef _MSDOS
# define MSDOS
#endif
#ifdef MSDOS
# define STDC_HEADERS
#endif

#ifdef POCKETCONSOLE
# define NOSETBUF
# define LACK_FTIME
#endif

#ifdef vms
# define STDC_HEADERS
#endif

#ifdef nosve
# define STDC_HEADERS
#endif

#ifdef linux
# define HAVE_SELECT
# define HAVE_SYS_TIME_H
# define STDC_HEADERS
#endif

#ifdef _UNICOS
# define STDC_HEADERS
#endif

#ifdef _AIX
# define _POSIX_SOURCE
# define LACK_FTIME
#endif

#ifdef __sgi__
# define LACK_FTIME
# define STDC_HEADERS
# define USE_ANSI_PROTOTYPES
# define HAVE_SYS_TIME_H
# define __SVR4
#endif

#ifdef __SVR4
# define HAVE_SELECT
#endif

#ifdef PLAN9
# define STDC_HEADERS
#endif

#ifdef hpux
# define LACK_E_IDs
#endif

/* C-Set++ for OS/2 */
#ifdef __IBMC__
# define STDC_HEADERS
# define LACK_TIMES
# define LACK_SBRK
#endif

#ifdef __CYGWIN32__
# define LACK_FTIME
# define HAVE_SELECT
# define HAVE_SYS_TIME_H
# undef MSDOS
#endif

#ifdef __amigaos__
# define HAVE_SELECT
# define HAVE_SYS_TIME_H
# define LACK_SBRK
#endif

/* PROMPT is the prompt string printed at top level */

#ifndef PROMPT
# ifdef SICP
#  define PROMPT "==> "
# else
#  define PROMPT "> "
# endif
#endif

/* #define BRACKETS_AS_PARENS to have [ and ] be read as ( and ) in forms. */

/* #define BRACKETS_AS_PARENS */

/* LINE_INCREMENTORS are the characters which cause the line count to
   be incremented for the purposes of error reporting.  This feature
   is only used for scheme code loaded from files.

   WHITE_SPACES are other characters which should be treated like spaces
   in programs.  in both cases sparate characters with ":case " */

#define LINE_INCREMENTORS  '\n'
#ifdef MSDOS
# define WHITE_SPACES  ' ':case '\t':case '\r':case '\f':case 26
#else
# define WHITE_SPACES  ' ':case '\t':case '\r':case '\f'
#endif

/* Define BIGDIG to an integer type whose size is smaller than long if
   you want bignums.  BIGRAD is one greater than the biggest BIGDIG. */
/* Define DIGSTOOBIG if the digits equivalent to a long won't fit in a long. */
#ifdef BIGNUMS
# ifdef _UNICOS
#  define DIGSTOOBIG
#  if (1L << 31) <= USHRT_MAX
#   define BIGDIG unsigned short
#  else
#   define BIGDIG unsigned int
#  endif
#  define BITSPERDIG 32
# else
#  define BIGDIG unsigned short
#  define BITSPERDIG (sizeof(BIGDIG)*CHAR_BIT)
# endif
# define BIGRAD (1L << BITSPERDIG)
# define DIGSPERLONG ((sizet)((sizeof(long)*CHAR_BIT+BITSPERDIG-1)/BITSPERDIG))
# define BIGUP(x) ((unsigned long)(x) << BITSPERDIG)
# define BIGDN(x) ((x) >> BITSPERDIG)
# define BIGLO(x) ((x) & (BIGRAD-1))
/* NUMDIGS_MAX is the maximum number of digits for BIGNUMS */
# ifndef NUMDIGS_MAX
#  define NUMDIGS_MAX 1000
# endif
#endif

#ifndef BIGDIG
# ifndef FLOATS
#  define INUMS_ONLY
# endif
#endif

#ifdef __GNUC__
# define FENCE asm volatile ("")
#else
# define FENCE /**/
#endif

#ifdef NON_PREEMPTIVE
# define VERIFY_INTS(s1, s2) /**/
# define DEFER_INTS /**/
# ifdef TICKS
#  define POLL {if (0==poll_count--) poll_routine(); \
	      if (0==tick_count--) tick_signal();}
# else
#  define POLL {if (0==poll_count--) poll_routine();}
# endif
# define CHECK_INTS POLL
# define ALLOW_INTS POLL
# define DEFER_INTS_EGC /**/
# define ALLOW_INTS_EGC /**/
#else
# ifdef CAREFUL_INTS
typedef struct {char *fname; int linum;} ints_infot;
extern ints_infot *ints_info;
#  define VERIFY_INTS(s1, s2) {if (!ints_disabled)\
     ints_warn(s1, s2, __FILE__, __LINE__); }
#  define DEFER_INTS \
   {static ints_infot info = {__FILE__, __LINE__};\
     FENCE;if (1==ints_disabled) ints_viol(&info, 1);\
	   else {ints_info = &info; ints_disabled = 1;FENCE;}}
#  define ALLOW_INTS \
   {static ints_infot info = {__FILE__, __LINE__};\
    FENCE;if (1!=ints_disabled) ints_viol(&info, 0);\
	  else {ints_info = &info; ints_disabled = 0;FENCE;CHECK_INTS}}
#  define DEFER_INTS_EGC \
   {static ints_infot info = {__FILE__, __LINE__};\
    FENCE;if (1==ints_disabled) ints_viol(&info, 1);\
	  else {ints_info = &info; ints_disabled = 2;FENCE;}}
#  define ALLOW_INTS_EGC \
   {static ints_infot info = {__FILE__, __LINE__};\
    FENCE;if (1==ints_disabled) ints_viol(&info, 0);\
	  else {ints_info = &info; ints_disabled = 0;FENCE;CHECK_INTS}}
# else
#  define VERIFY_INTS(s1, s2) /**/
#  define DEFER_INTS {FENCE;ints_disabled = 1;FENCE;}
#  define ALLOW_INTS {FENCE;ints_disabled = 0;FENCE;CHECK_INTS}
#  define DEFER_INTS_EGC {FENCE;ints_disabled = 2;FENCE;}
#  define ALLOW_INTS_EGC {FENCE;ints_disabled = 0;FENCE;CHECK_INTS}
# endif
# ifdef TICKS
#  define CHECK_INTS {if (deferred_proc) (*deferred_proc)(); POLL;}
#  define POLL {if (0==tick_count--) tick_signal();}
# else
#  define CHECK_INTS {if (deferred_proc) (*deferred_proc)();}
#  define POLL /**/
# endif
#endif

#ifdef STACK_LIMIT
# define CHECK_STACK {stack_check();}
#else
# define CHECK_STACK /**/
#endif

/* Cray machines have pointers that are incremented once for each word,
   rather than each byte, the 3 most significant bits encode the byte
   within the word.  The following macros deal with this by storing the
   native Cray pointers like the ones that looks like scm expects.  This
   is done for any pointers that might appear in the car of a cell, pointers
   to vector elts, functions, &c are not munged.  */
#ifdef _UNICOS
# define SCM2PTR(x) ((int)(x) >> 3)
# define PTR2SCM(x) (((SCM)(x)) << 3)
# define POINTERS_MUNGED
#else
# ifdef TEST_SCM2PTR
#  define SCM2PTR(x) ((x) ^ 0xf0L)
#  define PTR2SCM(x) (((SCM)(x)) ^ 0xf0L)
#  define POINTERS_MUNGED
# else
#  define SCM2PTR(x) (x)
#  define PTR2SCM(x) ((SCM)(x))
# endif
#endif

/* FIXABLE is non-null if its long argument can be encoded in an INUM. */

#define POSFIXABLE(n) ((n) <= MOST_POSITIVE_FIXNUM)
#define NEGFIXABLE(n) ((n) >= MOST_NEGATIVE_FIXNUM)
#define UNEGFIXABLE(n) ((n) <= -MOST_NEGATIVE_FIXNUM)
#define FIXABLE(n) (POSFIXABLE(n) && NEGFIXABLE(n))

/* The following 8 definitions are defined automatically by the C
   pre-processor.  You will need to override these if you are
   cross-compiling or if the C pre-processor has different properties
   than the compiler. */

#if (((-1)%2==-1) && ((-1)%(-2)==-1) && (1%2==1) && (1%(-2)==1))
#else
# define BADIVSGNS
#endif

/* SRS is signed right shift */
/*--- Turbo C++ v1.0 has a bug with right shifts of signed longs!
      It is believed to be fixed in Turbo C++ v1.01		---*/
#if (-1==(((-1)<<2)+2)>>2) && (__TURBOC__ != 0x295)
# define SRS(x, y) ((x)>>y)
# ifdef __TURBOC__
#  define INUM(x) (((x)>>1)>>1)
# else
#  define INUM(x) SRS(x, 2)
# endif
#else
# define SRS(x, y) (((x)<0) ? ~((~(x))>>y) : (x)>>y)
# define INUM(x) SRS(x, 2)
#endif

#ifdef __TURBOC__
/* shifts of more than one are done by a library call, single shifts are
   performed in registers */
# define MAKINUM(x) ((((x)<<1)<<1)+2L)
#else
# define MAKINUM(x) (((x)<<2)+2L)
#endif

#ifdef _DCC
# define ASCII
#else
# if (('\n'=='\025') && (' '=='\100') && ('a'=='\201') && ('A'=='\301'))
#  define EBCDIC
# endif
# if (('\n'=='\012') && (' '=='\040') && ('a'=='\141') && ('A'=='\101'))
#  define ASCII
# endif
#endif

/* CHAR_CODE_LIMIT is the number of distinct characters represented by
   the unsigned char datatype. */
/* MOST_POSITIVE_FIXNUM is the INUM closest to positive infinity. */
/* MOST_NEGATIVE_FIXNUM is the INUM closest to negative infinity. */

#ifdef __STDC__
# define HAVE_LIMITSH
#endif
#ifdef MWC
# define HAVE_LIMITSH
#endif

#ifdef HAVE_LIMITSH
# include <limits.h>
# ifdef UCHAR_MAX
#  define CHAR_CODE_LIMIT (UCHAR_MAX+1L)
# else
#  define CHAR_CODE_LIMIT 256L
# endif
# define MOST_POSITIVE_FIXNUM (LONG_MAX>>2)
# ifdef _UNICOS			/* Stupid cray bug */
#  define MOST_NEGATIVE_FIXNUM ((long)LONG_MIN/4)
# else
#  define MOST_NEGATIVE_FIXNUM SRS((long)LONG_MIN, 2)
# endif				/* UNICOS */
#else
# define CHAR_CODE_LIMIT 256L
# define MOST_POSITIVE_FIXNUM ((long)((unsigned long)~0L>>3))
# if (0 != ~0)
#  define MOST_NEGATIVE_FIXNUM (-MOST_POSITIVE_FIXNUM-1)
# else
#  define MOST_NEGATIVE_FIXNUM (-MOST_POSITIVE_FIXNUM)
# endif
#endif

/* INTBUFLEN is the maximum number of characters neccessary for the
   printed or string representation of an exact number. */

#ifndef CHAR_BIT
# define CHAR_BIT 8
#endif
#ifndef LONG_BIT
# define LONG_BIT (CHAR_BIT*sizeof(long)/sizeof(char))
#endif
#define INTBUFLEN (5+LONG_BIT)

/* FLOBUFLEN is the maximum number of characters neccessary for the
   printed or string representation of an inexact number. */

#ifdef FLOATS
# define FLOBUFLEN (10+2*(sizeof(double)/sizeof(char)*CHAR_BIT*3+9)/10)
#endif /* FLOATS */

/* MAXEXP is the maximum double precision exponent */
/* FLTMAX is less than or equal the largest single precision float */

#ifdef FLOATS
# ifdef STDC_HEADERS
#  ifndef macintosh
#   ifndef PLAN9
#    include <float.h>
#   endif
#  endif
# endif
# ifdef DBL_MAX_10_EXP
#  define MAXEXP DBL_MAX_10_EXP
# else
#  define MAXEXP 308   /* IEEE doubles */
# endif
# ifndef DBL_DIG
#  define DBL_DIG 15
# endif
# ifndef DBL_MAX_EXP
#  define DBL_MAX_EXP 1024
# endif
# ifdef FLT_MAX
#  define FLTMAX FLT_MAX
# else
#  define FLTMAX 1e+23
# endif
#endif

#ifdef unix
# define HAVE_UNIX
#endif
#ifdef __unix__
# define HAVE_UNIX
#endif
#ifdef _IBMR2
# define HAVE_UNIX
# define STDC_HEADERS
#endif

/* Only some machines have pipes */
#ifdef HAVE_UNIX
  /* DJGPP (gcc for i386) defines unix! */
# define HAVE_PIPE
#endif

/* IS_INF tests its floating point number for infiniteness */

#ifndef IS_INF
# define IS_INF(x) ((x)==(x)/2)
#endif

#ifndef macintosh
# ifndef _M_ARM
#  ifndef _M_ARMT
#   ifdef __WINDOWS__		/* there should be a better flag for this. */
#    define PROT386
#   endif
#  endif
# endif
#endif

/* PTR_LT defines how to compare two CELLPTRs (which may not be in the
   same array).  CELLPTR is a pointer to a cons cell which may be
   compared or differenced.  SCMPTR is used for stack bounds. */

#if defined(__TURBOC__) && !defined(__TOS__)
# ifdef PROT386
typedef cell *CELLPTR;
typedef SCM *SCMPTR;
#  define PTR_LT(x, y) (((long)(x)) < ((long)(y)))
# else
typedef cell huge *CELLPTR;
typedef SCM  huge *SCMPTR;
#  define PTR_LT(x, y) ((x) < (y))
# endif
#else /* not __TURBOC__ */
typedef cell *CELLPTR;
typedef SCM  *SCMPTR;
# ifdef nosve
#  define PTR_MASK 0xffffffffffff
#  define PTR_LT(x, y) (((int)(x)&PTR_MASK) < ((int)(y)&PTR_MASK))
# else
#  define PTR_LT(x, y) ((x) < (y))
# endif
#endif

#define PTR_GT(x, y) PTR_LT(y, x)
#define PTR_LE(x, y) (!PTR_GT(x, y))
#define PTR_GE(x, y) (!PTR_LT(x, y))

#ifdef STDC_HEADERS
# ifdef PLAN9
#  define sizet long
# else
#  include <stdlib.h>
#  ifdef AMIGA
#   include <stddef.h>
#  endif
#  define sizet size_t
# endif
#else
# ifdef _SIZE_T
#  define sizet size_t
# else
#  define sizet unsigned int
# endif
#endif

#ifdef macintosh
# include <unistd.h>
#endif

/* On VMS, GNU C's errno.h contains a special hack to get link attributes
   for errno correct for linking with libc. */

#ifndef PLAN9
# include <errno.h>
#endif

/* SYSCALL retries system calls that have been interrupted (EINTR) */
#ifdef vms
# ifndef __GNUC__
#  include <ssdef.h>
#  define SCM_INTERRUPTED(errno) (EVMSERR==errno && \
				  (vaxc$errno>>3)==(SS$_CONTROLC>>3))
# endif
#endif

#ifndef SCM_INTERRUPTED
# ifdef EINTR
#  if (EINTR > 0)
#   define SCM_INTERRUPTED(errno) (EINTR==errno)
#  endif
# endif
#endif

#ifndef SCM_INTERRUPTED
# define SCM_INTERRUPTED(errno) (0)
#endif

#ifdef _WIN32
// Windows doesn't set errno = EINTR
# define SYSCALL(line) do{ line; while(GetLastError() == ERROR_OPERATION_ABORTED){SetLastError(0);Sleep(10);line};}while(0)
#else
# define SYSCALL(line) do{errno = 0;line}while(SCM_INTERRUPTED(errno))
#endif

#ifdef EMFILE
# ifdef ENFILE
#  define SCM_NEED_FDS(errno) (EMFILE==errno || ENFILE==errno)
# else
#  define SCM_NEED_FDS(errno) (EMFILE==errno)
# endif
#else
# define SCM_NEED_FDS(errno) (0)
#endif

#define SCM_OPENCALL(line) {int gcs = 0;\
			     while (!0) {errno = 0; if (line) break;\
			     if (0==gcs++ && SCM_NEED_FDS(errno)) \
			       gc_for_open_files();\
			      else if (!SCM_INTERRUPTED(errno)) break;}}

#ifndef MSDOS
# ifdef ARM_ULIB
    extern volatile int errno;
# else
    extern int errno;
# endif
#endif
#ifdef __TURBOC__
# if (__TURBOC__==1)
 /* Needed for TURBOC V1.0 */
 extern int errno;
# endif
#endif

/* EXIT_SUCCESS is the default code to return from SCM if no errors
   were encountered.  EXIT_FAILURE is the default code to return from
   SCM if errors were encountered.  The return code can be explicitly
   specified in a SCM program with (quit <n>). */

#ifndef EXIT_SUCCESS
# ifdef vms
#  define EXIT_SUCCESS 1
# else
#  define EXIT_SUCCESS 0
# endif
#endif
#ifndef EXIT_FAILURE
# ifdef vms
#  define EXIT_FAILURE 2
# else
#  define EXIT_FAILURE 1
# endif
#endif

/* Yasuaki Honda, Bob Schumaker */
/* Think C and Metrowerks lack isascii macro */
#ifdef macintosh
# define isascii(c) ((unsigned)(c) <= 0x7f)
#endif
#ifdef _DCC
# define isascii(c) ((unsigned)(c) <= 0x7f)
#endif

#ifdef __STDC__
# define VOLATILE volatile
#else
# define VOLATILE /**/
#endif

#ifdef _MSC_VER
				// Disable annoying warnings for:
# pragma warning (disable: 4102) // unreferenced label
# pragma warning (disable: 4018) // signed/unsigned mismatch
# pragma warning (disable: 4101) // unreferenced variables
# pragma warning (disable: 4244) // conversion from unsigned long to unsigned short
#endif

/* end of automatic C pre-processor definitions */