-
Notifications
You must be signed in to change notification settings - Fork 0
/
chicken.h
3584 lines (3112 loc) · 139 KB
/
chicken.h
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
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* chicken.h - General headerfile for compiler generated executables
;
; Copyright (c) 2008-2021, The CHICKEN Team
; Copyright (c) 2000-2007, Felix L. Winkelmann
; All rights reserved.
;
; Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
; conditions are met:
;
; Redistributions of source code must retain the above copyright notice, this list of conditions and the following
; disclaimer.
; Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
; disclaimer in the documentation and/or other materials provided with the distribution.
; Neither the name of the author nor the names of its contributors may be used to endorse or promote
; products derived from this software without specific prior written permission.
;
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
; AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
; POSSIBILITY OF SUCH DAMAGE.
*/
/* Configuration: */
#ifndef ___CHICKEN
#define ___CHICKEN
#define C_MAJOR_VERSION 5
#define C_MINOR_VERSION 2
#ifndef _ISOC99_SOURCE
# define _ISOC99_SOURCE
#endif
#ifndef __C99FEATURES__
# define __C99FEATURES__
#endif
/*
* N.B. This file MUST not rely upon "chicken-config.h"
*/
#if defined(HAVE_CONFIG_H) || defined(HAVE_CHICKEN_CONFIG_H)
# include "chicken-config.h"
#endif
/* Some OSes really dislike feature macros for standard levels */
#ifdef C_USE_STD_FEATURE_MACROS
# ifndef _XOPEN_SOURCE
# define _XOPEN_SOURCE 700
# endif
# ifndef _BSD_SOURCE
# define _BSD_SOURCE
# endif
# ifndef _NETBSD_SOURCE
# define _NETBSD_SOURCE
# endif
# ifndef _SVID_SOURCE
# define _SVID_SOURCE
# endif
/*
* glibc >= 2.20 synonym for _BSD_SOURCE & _SVID_SOURCE.
*/
# ifndef _DEFAULT_SOURCE
# define _DEFAULT_SOURCE
# endif
#endif /* C_USE_STD_FEATURE_MACROS */
/* Kind of platform */
#if defined(__LP64__) || defined(_LP64) || defined(__MINGW64__) || defined(_WIN64)
# define C_SIXTY_FOUR
#endif
#if defined(__APPLE__) && defined(__MACH__)
# define C_MACOSX
#endif
#if defined(C_MACOSX) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__OpenBSD__)
# define C_XXXBSD
#endif
#if /*defined(__GNUC__) &&*/ (defined(__linux__) || defined(C_XXXBSD) || defined(__HAIKU__))
# define C_GNU_ENV
#endif
#if defined(__MINGW32__)
/*
* XXX This should probably be renamed or changed because it's misleading.
* For example, Haiku is not a Unix either, but this doesn't get defined there.
*/
# define C_NONUNIX
#endif
#if defined(__sun) && defined(__SVR4)
# define C_SOLARIS
#endif
#if defined(__MINGW64__) || defined(_WIN64)
# define C_LLP
#endif
/* Declare base Win32 version: we require Vista or later */
#ifdef __MINGW32__
# define _WIN32_WINNT 0x0600
#endif
/* Headers */
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
#include <limits.h>
#include <math.h>
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
/* Byteorder in machine word */
#if defined(__MINGW32__)
# include <sys/param.h>
#elif defined(__CYGWIN__)
# include <endian.h>
#elif defined(__linux__)
# include <endian.h>
#elif defined(C_XXXBSD)
# include <machine/endian.h>
#elif defined(__hpux__)
# include <arpa/nameser.h>
#elif defined(_AIX)
# include <sys/machine.h>
#elif defined(__sun)
# include <sys/isa_defs.h>
#elif defined(__SVR4)
# include <sys/byteorder.h>
#endif
#if defined(__MINGW32__)
# include <malloc.h>
#endif
/* Much better with stack allocation API */
#ifdef HAVE_ALLOCA_H
# include <alloca.h>
#elif !defined(alloca) /* predefined by HP cc +Olibcalls */
void *alloca ();
#endif
/* CHICKEN Core C API */
#if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN
# define C_BIG_ENDIAN
#elif defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN
# define C_BIG_ENDIAN
#elif defined(__BIG_ENDIAN__)
# define C_BIG_ENDIAN
#elif defined(__MIPSEL__) || defined(__MIPSEL)
# define C_LITTLE_ENDIAN
#elif defined(__sparc__) || defined(__POWERPC__) || defined(__MC68K__) || defined(__mips__)
# define C_BIG_ENDIAN
#endif
#if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && __BYTE_ORDER == __LITTLE_ENDIAN
# define C_LITTLE_ENDIAN
#elif defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && BYTE_ORDER == LITTLE_ENDIAN
# define C_LITTLE_ENDIAN
#elif defined(__LITTLE_ENDIAN__)
# define C_LITTLE_ENDIAN
#elif defined (__alpha__) || defined(_M_IX86) || defined(__i386__) || defined(__x86_64__) || defined(__ia64__)
# define C_LITTLE_ENDIAN
#endif
/* Make sure some common C identifiers are availble w/ Windows */
/* Could be used by C++ source */
#ifdef __cplusplus
# define C_extern extern "C"
# define C_BEGIN_C_DECLS extern "C" {
# define C_END_C_DECLS }
#else
# define C_extern extern
# define C_BEGIN_C_DECLS
# define C_END_C_DECLS
#endif
/* Function declaration modes */
/* Visibility */
#define C_varextern C_extern
#define C_fctimport
#define C_fctexport
#define C_externimport C_extern
#define C_externexport C_extern
#if defined(PIC)
# if defined(__CYGWIN__) || defined(__MINGW32__)
# ifndef C_BUILDING_LIBCHICKEN
# undef C_varextern
# define C_varextern C_extern __declspec(dllimport)
# endif
# endif
#endif
/* Language specifics: */
#if defined(__GNUC__) || defined(__INTEL_COMPILER)
#define HAVE_STATEMENT_EXPRESSIONS 1
#endif
#if !defined(__clang__) && !defined(__has_attribute)
/* Define so it won't error on other compilers with keywords like "noreturn" */
#define __has_attribute(x) 0
#endif
#if defined(__GNUC__) || defined(__INTEL_COMPILER)
# define C_unlikely(x) __builtin_expect((x), 0)
# define C_likely(x) __builtin_expect((x), 1)
# ifndef __cplusplus
# define C_cblock ({
# define C_cblockend })
# if defined(__clang__) && !__has_attribute(noreturn)
# define C_noret
# else
# define C_noret __attribute__ ((noreturn))
# endif
# define C_noret_decl(name)
# define C_aligned __attribute__ ((aligned))
# endif
# if defined(__i386__) && !defined(__clang__)
# define C_regparm __attribute__ ((regparm(3)))
# endif
#else
# define C_unlikely(x) (x)
# define C_likely(x) (x)
#endif
#ifndef C_cblock
# define C_cblock do{
# define C_cblockend }while(0)
# define C_noret
# define C_noret_decl(name)
#endif
#ifndef C_regparm
# define C_regparm
#endif
#ifndef C_fcall
# define C_fcall
#endif
#ifndef C_ccall
# define C_ccall
#endif
#ifndef C_aligned
# define C_aligned
#endif
/* Thread Local Storage */
#ifdef C_ENABLE_TLS
# if defined(__GNUC__)
# define C_TLS __thread
# endif
#endif
#ifndef C_TLS
# define C_TLS
#endif
/* Stack growth direction; used to compute stack addresses */
#ifndef C_STACK_GROWS_DOWNWARD
# ifdef __hppa__
# define C_STACK_GROWS_DOWNWARD 0
# else
# define C_STACK_GROWS_DOWNWARD 1
# endif
#endif
/* Have a GUI? */
#if defined(C_GUI) || defined(C_PRIVATE_REPOSITORY)
# ifdef _WIN32
# include <windows.h>
# ifndef WINAPI
# define WINAPI
# endif
# endif
#endif
/* Needed for pre-emptive threading */
#define C_TIMER_INTERRUPTS
/* Constants: */
#define C_STACK_RESERVE 0x10000
#define C_DEFAULT_MAX_PENDING_FINALIZERS 2048
#define C_IMMEDIATE_MARK_BITS 0x00000003
#define C_IMMEDIATE_TYPE_BITS 0x0000000f
#define C_BOOLEAN_BITS 0x00000006
#define C_CHARACTER_BITS 0x0000000a
#define C_SPECIAL_BITS 0x0000000e
#define C_SCHEME_FALSE ((C_word)(C_BOOLEAN_BITS | 0x00000000))
#define C_SCHEME_TRUE ((C_word)(C_BOOLEAN_BITS | 0x00000010))
#define C_SCHEME_END_OF_LIST ((C_word)(C_SPECIAL_BITS | 0x00000000))
#define C_SCHEME_UNDEFINED ((C_word)(C_SPECIAL_BITS | 0x00000010))
#define C_SCHEME_UNBOUND ((C_word)(C_SPECIAL_BITS | 0x00000020))
#define C_SCHEME_END_OF_FILE ((C_word)(C_SPECIAL_BITS | 0x00000030))
#define C_FIXNUM_BIT 0x00000001
#define C_FIXNUM_SHIFT 1
/* Character range is that of a UTF-8 codepoint, not representable range */
#define C_CHAR_BIT_MASK 0x1fffff
#define C_CHAR_SHIFT 8
#ifdef C_SIXTY_FOUR
# define C_MOST_POSITIVE_FIXNUM 0x3fffffffffffffffL
# define C_WORD_SIZE 64
# define C_HALF_WORD_SIZE 32
#else
# define C_MOST_POSITIVE_FIXNUM 0x3fffffff
# define C_WORD_SIZE 32
# define C_HALF_WORD_SIZE 16
#endif
/* Tunable performance-related constants */
#ifndef C_KARATSUBA_THRESHOLD
/* This defines when we'll switch from schoolbook to Karatsuba
* multiplication. The smallest of the two numbers determines the
* switch. It is pretty high right now because it generates a bit
* more garbage and GC overhead dominates the algorithmic performance
* gains. If the GC is improved, this can be readjusted.
*/
# define C_KARATSUBA_THRESHOLD 70
#endif
#ifndef C_BURNIKEL_ZIEGLER_THRESHOLD
/* This defines when to switch from schoolbook to Burnikel-Ziegler
* division. It creates even more garbage than Karatsuba :(
*/
# define C_BURNIKEL_ZIEGLER_THRESHOLD 300
#endif
#ifndef C_RECURSIVE_TO_STRING_THRESHOLD
/* This threshold is in terms of the expected string length. */
# define C_RECURSIVE_TO_STRING_THRESHOLD 750
#endif
/* These might fit better in runtime.c? */
#define C_fitsinbignumhalfdigitp(n) (C_BIGNUM_DIGIT_HI_HALF(n) == 0)
#define C_BIGNUM_DIGIT_LENGTH C_WORD_SIZE
#define C_BIGNUM_HALF_DIGIT_LENGTH C_HALF_WORD_SIZE
#define C_BIGNUM_BITS_TO_DIGITS(n) \
(((n) + (C_BIGNUM_DIGIT_LENGTH - 1)) / C_BIGNUM_DIGIT_LENGTH)
#define C_BIGNUM_DIGIT_LO_HALF(d) (C_uhword)(d)
#define C_BIGNUM_DIGIT_HI_HALF(d) (C_uhword)((d) >> C_BIGNUM_HALF_DIGIT_LENGTH)
#define C_BIGNUM_DIGIT_COMBINE(h,l) ((C_uword)(h) << C_BIGNUM_HALF_DIGIT_LENGTH|(C_uhword)(l))
#define C_MOST_POSITIVE_32_BIT_FIXNUM 0x3fffffff
#define C_MOST_NEGATIVE_FIXNUM (-C_MOST_POSITIVE_FIXNUM - 1)
#ifdef C_SIXTY_FOUR
# define C_INT_SIGN_BIT 0x8000000000000000L
# define C_INT_TOP_BIT 0x4000000000000000L
# define C_HEADER_BITS_MASK 0xff00000000000000L
# define C_HEADER_TYPE_BITS 0x0f00000000000000L
# define C_HEADER_SIZE_MASK 0x00ffffffffffffffL
# define C_GC_FORWARDING_BIT 0x8000000000000000L /* header contains forwarding pointer */
# define C_BYTEBLOCK_BIT 0x4000000000000000L /* block contains bytes instead of slots */
# define C_SPECIALBLOCK_BIT 0x2000000000000000L /* 1st item is a non-value */
# define C_8ALIGN_BIT 0x1000000000000000L /* data is aligned to 8-byte boundary */
# define C_SYMBOL_TYPE (0x0100000000000000L)
# define C_STRING_TYPE (0x0200000000000000L | C_BYTEBLOCK_BIT)
# define C_PAIR_TYPE (0x0300000000000000L)
# define C_CLOSURE_TYPE (0x0400000000000000L | C_SPECIALBLOCK_BIT)
# define C_FLONUM_TYPE (0x0500000000000000L | C_BYTEBLOCK_BIT | C_8ALIGN_BIT)
# define C_BIGNUM_TYPE (0x0600000000000000L) /* Just the wrapper */
# define C_PORT_TYPE (0x0700000000000000L | C_SPECIALBLOCK_BIT)
# define C_STRUCTURE_TYPE (0x0800000000000000L)
# define C_POINTER_TYPE (0x0900000000000000L | C_SPECIALBLOCK_BIT)
# define C_LOCATIVE_TYPE (0x0a00000000000000L | C_SPECIALBLOCK_BIT)
# define C_TAGGED_POINTER_TYPE (0x0b00000000000000L | C_SPECIALBLOCK_BIT)
# define C_RATNUM_TYPE (0x0c00000000000000L)
# define C_LAMBDA_INFO_TYPE (0x0d00000000000000L | C_BYTEBLOCK_BIT)
# define C_CPLXNUM_TYPE (0x0e00000000000000L)
/* unused (0x0f00000000000000L ...) */
#else
# define C_INT_SIGN_BIT 0x80000000
# define C_INT_TOP_BIT 0x40000000
# define C_HEADER_BITS_MASK 0xff000000
# define C_HEADER_TYPE_BITS 0x0f000000
# define C_HEADER_SIZE_MASK 0x00ffffff
# define C_GC_FORWARDING_BIT 0x80000000
# define C_BYTEBLOCK_BIT 0x40000000
# define C_SPECIALBLOCK_BIT 0x20000000
# define C_8ALIGN_BIT 0x10000000
# define C_SYMBOL_TYPE (0x01000000)
# define C_STRING_TYPE (0x02000000 | C_BYTEBLOCK_BIT)
# define C_PAIR_TYPE (0x03000000)
# define C_CLOSURE_TYPE (0x04000000 | C_SPECIALBLOCK_BIT)
# ifdef C_DOUBLE_IS_32_BITS
# define C_FLONUM_TYPE (0x05000000 | C_BYTEBLOCK_BIT)
# else
# define C_FLONUM_TYPE (0x05000000 | C_BYTEBLOCK_BIT | C_8ALIGN_BIT)
# endif
# define C_BIGNUM_TYPE (0x06000000) /* Just the wrapper */
# define C_PORT_TYPE (0x07000000 | C_SPECIALBLOCK_BIT)
# define C_STRUCTURE_TYPE (0x08000000)
# define C_POINTER_TYPE (0x09000000 | C_SPECIALBLOCK_BIT)
# define C_LOCATIVE_TYPE (0x0a000000 | C_SPECIALBLOCK_BIT)
# define C_TAGGED_POINTER_TYPE (0x0b000000 | C_SPECIALBLOCK_BIT)
# define C_RATNUM_TYPE (0x0c000000)
# define C_LAMBDA_INFO_TYPE (0x0d000000 | C_BYTEBLOCK_BIT)
# define C_CPLXNUM_TYPE (0x0e000000)
/* unused (0x0f000000 ...) */
#endif
#define C_VECTOR_TYPE 0x00000000
#define C_BYTEVECTOR_TYPE (C_VECTOR_TYPE | C_BYTEBLOCK_BIT | C_8ALIGN_BIT)
#define C_SIZEOF_LIST(n) ((n) * 3 + 1)
#define C_SIZEOF_PAIR 3
#define C_SIZEOF_STRING(n) (C_bytestowords(n) + 2)
#define C_SIZEOF_SYMBOL 4
#define C_SIZEOF_INTERNED_SYMBOL(n) (C_SIZEOF_SYMBOL + C_SIZEOF_PAIR + C_SIZEOF_STRING(n))
#ifdef C_DOUBLE_IS_32_BITS
# define C_SIZEOF_FLONUM 2
#else
# define C_SIZEOF_FLONUM 4
#endif
#define C_SIZEOF_POINTER 2
#define C_SIZEOF_TAGGED_POINTER 3
#define C_SIZEOF_VECTOR(n) ((n) + 1)
#define C_SIZEOF_LOCATIVE 5
#define C_SIZEOF_PORT 16
#define C_SIZEOF_RATNUM 3
#define C_SIZEOF_CPLXNUM 3
#define C_SIZEOF_STRUCTURE(n) ((n)+1)
#define C_SIZEOF_CLOSURE(n) ((n)+1)
#define C_SIZEOF_BYTEVECTOR C_SIZEOF_STRING
#define C_SIZEOF_INTERNAL_BIGNUM_VECTOR(n) (C_SIZEOF_VECTOR((n)+1))
#define C_internal_bignum_vector(b) (C_block_item(b,0))
/* This is for convenience and allows flexibility in representation */
#define C_SIZEOF_FIX_BIGNUM C_SIZEOF_BIGNUM(1)
#define C_SIZEOF_BIGNUM_WRAPPER 2
#define C_SIZEOF_BIGNUM(n) (C_SIZEOF_INTERNAL_BIGNUM_VECTOR(n)+C_SIZEOF_BIGNUM_WRAPPER)
/* Fixed size types have pre-computed header tags */
#define C_PAIR_TAG (C_PAIR_TYPE | (C_SIZEOF_PAIR - 1))
#define C_WEAK_PAIR_TAG (C_PAIR_TAG | C_SPECIALBLOCK_BIT)
#define C_POINTER_TAG (C_POINTER_TYPE | (C_SIZEOF_POINTER - 1))
#define C_LOCATIVE_TAG (C_LOCATIVE_TYPE | (C_SIZEOF_LOCATIVE - 1))
#define C_TAGGED_POINTER_TAG (C_TAGGED_POINTER_TYPE | (C_SIZEOF_TAGGED_POINTER - 1))
#define C_SYMBOL_TAG (C_SYMBOL_TYPE | (C_SIZEOF_SYMBOL - 1))
#define C_FLONUM_TAG (C_FLONUM_TYPE | sizeof(double))
#define C_BIGNUM_TAG (C_BIGNUM_TYPE | 1)
#define C_RATNUM_TAG (C_RATNUM_TYPE | 2)
#define C_CPLXNUM_TAG (C_CPLXNUM_TYPE | 2)
/* Locative subtypes */
#define C_SLOT_LOCATIVE 0
#define C_CHAR_LOCATIVE 1
#define C_U8_LOCATIVE 2
#define C_S8_LOCATIVE 3
#define C_U16_LOCATIVE 4
#define C_S16_LOCATIVE 5
#define C_U32_LOCATIVE 6
#define C_S32_LOCATIVE 7
#define C_U64_LOCATIVE 8
#define C_S64_LOCATIVE 9
#define C_F32_LOCATIVE 10
#define C_F64_LOCATIVE 11
#if defined (__MINGW32__)
# define C_s64 __int64
# define C_u64 unsigned __int64
#else
# define C_s64 int64_t
# define C_u64 uint64_t
#endif
#ifdef C_SIXTY_FOUR
# ifdef C_LLP
# define C_word C_s64
# define C_hword long
# else
# define C_word long
# define C_hword int
# endif
# define C_u32 uint32_t
# define C_s32 int32_t
#else
# define C_word int
# define C_hword short
# define C_u32 unsigned int
# define C_s32 int
#endif
#define C_char char
#define C_uchar unsigned C_char
#define C_byte char
#define C_uword unsigned C_word
#define C_uhword unsigned C_hword
#define C_header C_uword
/* if all else fails, use these:
#define UINT64_MAX (18446744073709551615ULL)
#define INT64_MAX (9223372036854775807LL)
#define INT64_MIN (-INT64_MAX - 1)
#define UINT32_MAX (4294967295U)
#define INT32_MAX (2147483647)
#define INT32_MIN (-INT32_MAX - 1)
#define UINT16_MAX (65535U)
#define INT16_MAX (32767)
#define INT16_MIN (-INT16_MAX - 1)
#define UINT8_MAX (255)
#define INT8_MAX (127)
#define INT8_MIN (-INT8_MAX - 1)
*/
#define C_U64_MAX UINT64_MAX
#define C_S64_MIN INT64_MIN
#define C_S64_MAX INT64_MAX
#if defined(C_LLP)
# define C_wabs llabs
# define C_long C_s64
# ifndef LONG_LONG_MAX
# define C_LONG_MAX LLONG_MAX
# define C_LONG_MIN LLONG_MIN
# else
# define C_LONG_MAX LONG_LONG_MAX
# define C_LONG_MIN LONG_LONG_MIN
# endif
#else
# define C_wabs labs
# define C_long long
# define C_LONG_MAX LONG_MAX
# define C_LONG_MIN LONG_MIN
#endif
#define C_ulong unsigned C_long
#ifdef __cplusplus
# define C_text(x) ((C_char *)(x))
#else
# define C_text(x) (x)
#endif
#define C_TIMER_INTERRUPT_NUMBER 255
#define C_BAD_ARGUMENT_COUNT_ERROR 1
#define C_BAD_MINIMUM_ARGUMENT_COUNT_ERROR 2
#define C_BAD_ARGUMENT_TYPE_ERROR 3
#define C_UNBOUND_VARIABLE_ERROR 4
#define C_BAD_ARGUMENT_TYPE_NO_KEYWORD_ERROR 5
#define C_OUT_OF_MEMORY_ERROR 6
#define C_DIVISION_BY_ZERO_ERROR 7
#define C_OUT_OF_RANGE_ERROR 8
#define C_NOT_A_CLOSURE_ERROR 9
#define C_CONTINUATION_CANT_RECEIVE_VALUES_ERROR 10
#define C_BAD_ARGUMENT_TYPE_CYCLIC_LIST_ERROR 11
#define C_TOO_DEEP_RECURSION_ERROR 12
#define C_CANT_REPRESENT_INEXACT_ERROR 13
#define C_NOT_A_PROPER_LIST_ERROR 14
#define C_BAD_ARGUMENT_TYPE_NO_FIXNUM_ERROR 15
#define C_BAD_ARGUMENT_TYPE_NO_NUMBER_ERROR 16
#define C_BAD_ARGUMENT_TYPE_NO_STRING_ERROR 17
#define C_BAD_ARGUMENT_TYPE_NO_PAIR_ERROR 18
#define C_BAD_ARGUMENT_TYPE_NO_LIST_ERROR 19
#define C_BAD_ARGUMENT_TYPE_NO_CHAR_ERROR 20
#define C_BAD_ARGUMENT_TYPE_NO_VECTOR_ERROR 21
#define C_BAD_ARGUMENT_TYPE_NO_SYMBOL_ERROR 22
#define C_STACK_OVERFLOW_ERROR 23
#define C_BAD_ARGUMENT_TYPE_BAD_STRUCT_ERROR 24
#define C_BAD_ARGUMENT_TYPE_NO_BYTEVECTOR_ERROR 25
#define C_LOST_LOCATIVE_ERROR 26
#define C_BAD_ARGUMENT_TYPE_NO_BLOCK_ERROR 27
#define C_BAD_ARGUMENT_TYPE_NO_NUMBER_VECTOR_ERROR 28
#define C_BAD_ARGUMENT_TYPE_NO_INTEGER_ERROR 29
#define C_BAD_ARGUMENT_TYPE_NO_UINTEGER_ERROR 30
#define C_BAD_ARGUMENT_TYPE_NO_POINTER_ERROR 31
#define C_BAD_ARGUMENT_TYPE_NO_TAGGED_POINTER_ERROR 32
#define C_BAD_ARGUMENT_TYPE_NO_FLONUM_ERROR 33
#define C_BAD_ARGUMENT_TYPE_NO_CLOSURE_ERROR 34
#define C_BAD_ARGUMENT_TYPE_BAD_BASE_ERROR 35
#define C_CIRCULAR_DATA_ERROR 36
#define C_BAD_ARGUMENT_TYPE_NO_BOOLEAN_ERROR 37
#define C_BAD_ARGUMENT_TYPE_NO_LOCATIVE_ERROR 38
#define C_BAD_ARGUMENT_TYPE_NO_PORT_ERROR 39
#define C_BAD_ARGUMENT_TYPE_PORT_DIRECTION_ERROR 40
#define C_BAD_ARGUMENT_TYPE_PORT_NO_INPUT_ERROR 41
#define C_BAD_ARGUMENT_TYPE_PORT_NO_OUTPUT_ERROR 42
#define C_PORT_CLOSED_ERROR 43
#define C_ASCIIZ_REPRESENTATION_ERROR 44
#define C_MEMORY_VIOLATION_ERROR 45
#define C_FLOATING_POINT_EXCEPTION_ERROR 46
#define C_ILLEGAL_INSTRUCTION_ERROR 47
#define C_BUS_ERROR 48
#define C_BAD_ARGUMENT_TYPE_NO_EXACT_ERROR 49
#define C_BAD_ARGUMENT_TYPE_NO_INEXACT_ERROR 50
#define C_BAD_ARGUMENT_TYPE_NO_REAL_ERROR 51
#define C_BAD_ARGUMENT_TYPE_COMPLEX_NO_ORDERING_ERROR 52
#define C_BAD_ARGUMENT_TYPE_NO_EXACT_INTEGER_ERROR 53
#define C_BAD_ARGUMENT_TYPE_FOREIGN_LIMITATION 54
#define C_BAD_ARGUMENT_TYPE_COMPLEX_ABS 55
#define C_REST_ARG_OUT_OF_BOUNDS_ERROR 56
/* Platform information */
#if defined(C_BIG_ENDIAN)
# define C_MACHINE_BYTE_ORDER "big-endian"
#elif defined(C_LITTLE_ENDIAN)
# define C_MACHINE_BYTE_ORDER "little-endian"
#endif
#if defined(__alpha__)
# define C_MACHINE_TYPE "alpha"
#elif defined(__mips__)
# define C_MACHINE_TYPE "mips"
#elif defined(__hppa__)
# define C_MACHINE_TYPE "hppa"
#elif defined(__sparc_v9__) || defined(__sparcv9)
# define C_MACHINE_TYPE "ultrasparc"
#elif defined(__sparc__)
# define C_MACHINE_TYPE "sparc"
#elif defined(__powerpc64__) || defined(_ARCH_PPC64)
# define C_MACHINE_TYPE "ppc64"
#elif defined(__ppc__) || defined(__powerpc__) || defined(_ARCH_PPC)
# define C_MACHINE_TYPE "ppc"
#elif defined(_M_IX86) || defined(__i386__)
# define C_MACHINE_TYPE "x86"
#elif defined(__ia64__)
# define C_MACHINE_TYPE "ia64"
#elif defined(__x86_64__)
# define C_MACHINE_TYPE "x86-64"
#elif defined(__arm64__) || defined(__aarch64__)
# define C_MACHINE_TYPE "arm64"
#elif defined(__arm__)
# define C_MACHINE_TYPE "arm"
#else
# define C_MACHINE_TYPE "unknown"
#endif
#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(_WIN32) || defined(__WINNT__)
# define C_SOFTWARE_TYPE "windows"
#elif defined(__ANDROID__)
# define C_SOFTWARE_TYPE "android"
#elif defined(__unix__) || defined(C_XXXBSD) || defined(_AIX)
# define C_SOFTWARE_TYPE "unix"
#elif defined(ECOS)
# define C_SOFTWARE_TYPE "ecos"
#else
# define C_SOFTWARE_TYPE "unknown"
#endif
#if defined(__SUNPRO_C)
# define C_BUILD_PLATFORM "sun"
#elif defined(__clang__)
# define C_BUILD_PLATFORM "clang"
#elif defined(_AIX)
# define C_BUILD_PLATFORM "aix"
#elif defined(__GNUC__)
# define C_BUILD_PLATFORM "gnu"
#elif defined(__INTEL_COMPILER)
# define C_BUILD_PLATFORM "intel"
#else
# define C_BUILD_PLATFORM "unknown"
#endif
#if defined(__linux__)
# define C_SOFTWARE_VERSION "linux"
#elif defined(__FreeBSD__)
# define C_SOFTWARE_VERSION "freebsd"
#elif defined(__NetBSD__)
# define C_SOFTWARE_VERSION "netbsd"
#elif defined(__OpenBSD__)
# define C_SOFTWARE_VERSION "openbsd"
#elif defined(C_MACOSX)
# define C_SOFTWARE_VERSION "macosx"
#elif defined(__hpux__)
# define C_SOFTWARE_VERSION "hpux"
#elif defined(__DragonFly__)
# define C_SOFTWARE_VERSION "dragonfly"
#elif defined(__HAIKU__)
# define C_SOFTWARE_VERSION "haiku"
#elif defined(__sun)
# if defined(__SVR4)
# define C_SOFTWARE_VERSION "solaris"
# else
# define C_SOFTWARE_VERSION "sunos"
# endif
#elif defined(_AIX)
# define C_SOFTWARE_VERSION "aix"
#elif defined(__GNU__)
# define C_SOFTWARE_VERSION "hurd"
#elif defined(__CYGWIN__)
# define C_SOFTWARE_VERSION "cygwin"
#elif defined(__MINGW32__)
# define C_SOFTWARE_VERSION "mingw32"
#else
# define C_SOFTWARE_VERSION "unknown"
#endif
/* There is no PATH_MAX in The Hurd. */
#ifdef PATH_MAX
# define C_MAX_PATH PATH_MAX
#else
# define C_MAX_PATH 1024
#endif
#define C_RANDOM_STATE_SIZE (16 * sizeof(C_uword))
/* Types: */
typedef struct C_block_struct
{
C_header header;
C_word data[];
} C_SCHEME_BLOCK;
typedef struct C_symbol_table_struct
{
char *name;
unsigned int size;
unsigned int rand;
C_word *table;
struct C_symbol_table_struct *next;
} C_SYMBOL_TABLE;
typedef struct C_gc_root_struct
{
C_word value;
struct C_gc_root_struct *next, *prev;
int finalizable;
} C_GC_ROOT;
typedef struct C_ptable_entry_struct
{
C_char *id;
void *ptr;
} C_PTABLE_ENTRY;
typedef void (C_ccall *C_proc)(C_word, C_word *) C_noret;
/* Macros: */
#define C_cpsproc(name) C_ccall void name(C_word c, C_word *av) C_noret
#define CHICKEN_gc_root_ref(root) (((C_GC_ROOT *)(root))->value)
#define CHICKEN_gc_root_set(root, x) C_mutate(&((C_GC_ROOT *)(root))->value, (x))
#define CHICKEN_global_ref(root) C_u_i_car(((C_GC_ROOT *)(root))->value)
#define CHICKEN_global_set(root, x) C_mutate(&C_u_i_car(((C_GC_ROOT *)(root))->value), (x))
#define CHICKEN_default_toplevel ((void *)C_default_5fstub_toplevel)
#define C__STR1(x) #x
#define C__STR2(x) C__STR1(x)
#define C_align4(n) (((n) + 3) & ~3)
#define C_align8(n) (((n) + 7) & ~7)
#define C_align16(n) (((n) + 15) & ~15)
#define C_aligned8(n) ((((C_word)(n)) & 7) == 0)
#define C_buf_end(b) ((C_word *)((C_byte *)(b) + sizeof(b)))
/* This is word-size dependent: */
#ifdef C_SIXTY_FOUR
# define C_align(n) C_align8(n)
# define C_wordstobytes(n) ((C_uword)(n) << 3)
# define C_bytestowords(n) (((n) + 7) >> 3)
# define C_wordsperdouble(n) (n)
# define C_WORD_MIN LONG_MIN
# define C_WORD_MAX LONG_MAX
# define C_UWORD_MAX ULONG_MAX
#else
# define C_align(n) C_align4(n)
# define C_wordstobytes(n) ((C_uword)(n) << 2)
# define C_bytestowords(n) (((n) + 3) >> 2)
# define C_wordsperdouble(n) ((C_uword)(n) << 1)
# define C_WORD_MIN INT_MIN
# define C_WORD_MAX INT_MAX
# define C_UWORD_MAX UINT_MAX
#endif
/* Clang and G++ support statement expressions, but only in a limited way */
#if DEBUGBUILD && HAVE_STATEMENT_EXPRESSIONS && !defined(__clang__) && !defined(__cplusplus)
/* These are wrappers around the following idiom:
* assert(SOME_PRED(obj));
* do_something_with(obj);
* This works around the fact obj may be an expression with side-effects.
*
* To make this work with nested expansions, we need semantics like
* (let ((x 1)) (let ((x x)) x)) => 1, but in C, int x = x; results in
* undefined behaviour because x refers to itself. As a workaround,
* we keep around a reference to the previous level (one scope up).
* After initialisation, "previous" is redefined to mean "current".
*/
# define C_VAL1(x) C__PREV_TMPST.n1
# define C_VAL2(x) C__PREV_TMPST.n2
# define C__CHECK_panic(a,s,f,l) \
((a) ? (void)0 : \
C_panic_hook(C_text("Low-level type assertion " s " failed at " f ":" C__STR1(l))))
# define C__CHECK_core(v,a,s,x) \
({ struct { \
typeof(v) n1; \
} C__TMPST = { .n1 = (v) }; \
typeof(C__TMPST) C__PREV_TMPST=C__TMPST; \
C__CHECK_panic(a,s,__FILE__,__LINE__); \
x; })
# define C__CHECK2_core(v1,v2,a,s,x) \
({ struct { \
typeof(v1) n1; \
typeof(v2) n2; \
} C__TMPST = { .n1 = (v1), .n2 = (v2) }; \
typeof(C__TMPST) C__PREV_TMPST=C__TMPST; \
C__CHECK_panic(a,s,__FILE__,__LINE__); \
x; })
# define C_CHECK(v,a,x) C__CHECK_core(v,a,#a,x)
# define C_CHECK2(v1,v2,a,x) C__CHECK2_core(v1,v2,a,#a,x)
/*
* Convenience for using Scheme-predicates.
*/
# define C_CHECKp(v,a,x) C__CHECK_core(v,C_truep(a),#a"=#t",x)
# define C_CHECK2p(v1,v2,a,x) C__CHECK2_core(v1,v2,C_truep(a),#a"=#t",x)
#else
# define C_VAL1(x) (x)
# define C_VAL2(x) (x)
# define C_CHECK(v,a,x) (x)
# define C_CHECK2(v1,v2,a,x) (x)
# define C_CHECKp(v,a,x) (x)
# define C_CHECK2p(v1,v2,a,x) (x)
#endif
#ifndef C_PROVIDE_LIBC_STUBS
# define C_FILEPTR FILE *
# define C_stdin stdin
# define C_stdout stdout
# define C_stderr stderr
# define C_memcpy memcpy
# define C_memcmp memcmp
# define C_strncpy strncpy
# define C_strcmp strcmp
# define C_strncmp strncmp
# define C_strlen strlen
# define C_memchr memchr
# define C_memset memset
# define C_memmove memmove
# define C_strncasecmp strncasecmp
# define C_malloc malloc
# define C_calloc calloc
# define C_free free
# define C_strchr strchr
# define C_realloc realloc
# define C_strdup strdup
# define C_strtol strtol
# define C_strtoll strtoll
# define C_strtod strtod
# define C_strtoul strtoul
# define C_fopen fopen
# define C_fclose fclose
# define C_strpbrk strpbrk
# define C_strcspn strcspn
# define C_snprintf snprintf
# define C_printf printf
# define C_fprintf fprintf
# define C_vfprintf vfprintf
# define C_fflush fflush
# define C_getchar getchar
# define C_exit exit
# define C__exit _exit
# define C_dlopen dlopen
# define C_dlclose dlclose
# define C_dlsym dlsym
# define C_fwrite fwrite
# define C_fread fread
# define C_fputs fputs
# define C_fputc fputc
# define C_putchar putchar
# if (defined getc_unlocked || _POSIX_C_SOURCE >= 199506L) && !defined(__MINGW32__)
# define C_getc getc_unlocked
# else
# define C_getc getc
# endif
# define C_fgetc fgetc
# define C_fgets fgets
# define C_ungetc ungetc
# define C_system system
# define C_isatty isatty
# define C_fileno fileno
# define C_select select
# if defined(HAVE_SIGACTION)
# define C_sigaction sigaction
# endif
# define C_signal signal
# define C_getrusage getrusage
# define C_tolower tolower
# define C_toupper toupper
# define C_gettimeofday gettimeofday
# define C_gmtime gmtime
# define C_localtime localtime
/*
* It is undefined whether regular setjmp/longjmp save/restore signal mask
* so try to use versions that we know won't try to save & restore.
*/
# if defined(HAVE_SIGSETJMP)
# define C_sigsetjmp sigsetjmp
# define C_siglongjmp siglongjmp
# endif
# ifdef HAVE_SIGPROCMASK
# define C_sigprocmask sigprocmask
# endif
# define C_setjmp setjmp
# define C_longjmp longjmp
# define C_alloca alloca
# define C_strerror strerror
# define C_isalpha isalpha
# define C_isdigit isdigit
# define C_isspace isspace
# define C_islower islower
# define C_isupper isupper
# define C_sin sin
# define C_cos cos
# define C_tan tan
# define C_asin asin
# define C_acos acos
# define C_atan atan
# define C_atan2 atan2
# define C_log log
# define C_exp exp
# define C_pow pow
# define C_sqrt sqrt
# define C_ceil ceil
# define C_floor floor
# define C_round round
# define C_trunc trunc
# define C_fabs fabs
# define C_modf modf
# define C_readlink readlink
# define C_getcwd getcwd
# define C_access access
# define C_getpid getpid
# define C_getenv getenv
#else
/* provide this file and define C_PROVIDE_LIBC_STUBS if you want to use
your own libc-replacements or -wrappers */
# include "chicken-libc-stubs.h"
#endif
#ifdef C_LLP
# define C_strtow C_strtoll
#else
# define C_strtow C_strtol
#endif
#define C_return(x) return(x)
#define C_resize_stack(n) C_do_resize_stack(n)
#define C_memcpy_slots(t, f, n) C_memcpy((t), (f), (n) * sizeof(C_word))
/* Without check: initialisation of a newly allocated header */
#define C_block_header_init(x,h) (((C_SCHEME_BLOCK *)(x))->header = (h))
/* These two must result in an lvalue, hence the (*foo(&bar)) faffery */
#define C_block_header(x) (*C_CHECKp(x,C_blockp((C_word)C_VAL1(x)),&(((C_SCHEME_BLOCK *)(C_VAL1(x)))->header)))
#define C_block_item(x,i) (*C_CHECK2(x,i,(C_header_size(C_VAL1(x))>(C_VAL2(i))),&(((C_SCHEME_BLOCK *)(C_VAL1(x)))->data [ C_VAL2(i) ])))
#define C_set_block_item(x,i,y) (C_block_item(x, i) = (y))
#define C_header_bits(bh) (C_block_header(bh) & C_HEADER_BITS_MASK)