~ chicken-core (master) /chicken.h
Trap1/* chicken.h - General headerfile for compiler generated executables2;3; Copyright (c) 2008-2022, The CHICKEN Team4; Copyright (c) 2000-2007, Felix L. Winkelmann5; All rights reserved.6;7; Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following8; conditions are met:9;10; Redistributions of source code must retain the above copyright notice, this list of conditions and the following11; disclaimer.12; Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following13; disclaimer in the documentation and/or other materials provided with the distribution.14; Neither the name of the author nor the names of its contributors may be used to endorse or promote15; products derived from this software without specific prior written permission.16;17; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS18; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY19; AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR20; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR21; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR22; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY23; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR24; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE25; POSSIBILITY OF SUCH DAMAGE.26*/2728/* Configuration: */2930#ifndef ___CHICKEN31#define ___CHICKEN3233#define C_MAJOR_VERSION 634#define C_MINOR_VERSION 03536#ifndef _ISOC99_SOURCE37# define _ISOC99_SOURCE38#endif3940#ifndef __C99FEATURES__41# define __C99FEATURES__42#endif4344/*45 * N.B. This file MUST not rely upon "chicken-config.h"46 */47#if defined(HAVE_CHICKEN_CONFIG_H)48# include "chicken-config.h"49#endif5051/* Some OSes really dislike feature macros for standard levels */52#ifdef C_USE_STD_FEATURE_MACROS5354# ifndef _XOPEN_SOURCE55# define _XOPEN_SOURCE 70056# endif5758# ifndef _BSD_SOURCE59# define _BSD_SOURCE60# endif6162# ifndef _NETBSD_SOURCE63# define _NETBSD_SOURCE64# endif6566# ifndef _SVID_SOURCE67# define _SVID_SOURCE68# endif6970/*71 * glibc >= 2.20 synonym for _BSD_SOURCE & _SVID_SOURCE.72 */73# ifndef _DEFAULT_SOURCE74# define _DEFAULT_SOURCE75# endif7677#endif /* C_USE_STD_FEATURE_MACROS */7879/* Kind of platform */8081#if defined(__LP64__) || defined(_LP64) || defined(__MINGW64__) || defined(_WIN64)82# define C_SIXTY_FOUR83#endif8485#if defined(__APPLE__) && defined(__MACH__)86# define C_MACOSX87#endif8889#if defined(C_MACOSX) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__OpenBSD__)90# define C_XXXBSD91#endif9293#if /*defined(__GNUC__) &&*/ (defined(__linux__) || defined(C_XXXBSD) || defined(__HAIKU__))94# define C_GNU_ENV95#endif9697#if defined (__TINYC__)98# define __STDC_NO_COMPLEX__99#endif100101#if defined(__MINGW32__)102/*103 * XXX This should probably be renamed or changed because it's misleading.104 * For example, Haiku is not a Unix either, but this doesn't get defined there.105 */106# define C_NONUNIX107#endif108109#if defined(__sun) && defined(__SVR4)110# define C_SOLARIS111#endif112113#if defined(__MINGW64__) || defined(_WIN64)114# define C_LLP115#endif116117/* Declare base Win32 version: we require Vista or later */118119#ifdef __MINGW32__120# define _WIN32_WINNT 0x0600121#endif122123124/* Headers */125126#include <errno.h>127#include <inttypes.h>128#include <limits.h>129#include <math.h>130#include <setjmp.h>131#include <stdarg.h>132#include <stddef.h>133#include <stdio.h>134#include <stdlib.h>135#include <string.h>136#include <time.h>137#include <unistd.h>138#if !defined(__STDC_NO_COMPLEX__) && !defined(__cplusplus)139# include <complex.h>140# define C_complex complex141#else142# define C_complex143#endif144#include <sys/types.h>145#include <sys/stat.h>146147148/* Byteorder in machine word */149150#if defined(__MINGW32__)151# include <sys/param.h>152#elif defined(__CYGWIN__)153# include <endian.h>154#elif defined(__linux__)155# include <endian.h>156#elif defined(C_XXXBSD)157# include <machine/endian.h>158#elif defined(__hpux__)159# include <arpa/nameser.h>160#elif defined(_AIX)161# include <sys/machine.h>162#elif defined(__sun)163# include <sys/isa_defs.h>164#elif defined(__SVR4)165# include <sys/byteorder.h>166#endif167168#if defined(__MINGW32__)169# include <malloc.h>170#endif171172/* Much better with stack allocation API */173174#ifdef HAVE_ALLOCA_H175# include <alloca.h>176#elif !defined(alloca) /* predefined by HP cc +Olibcalls */177void *alloca ();178#endif179180181/* CHICKEN Core C API */182183#if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN184# define C_BIG_ENDIAN185#elif defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN186# define C_BIG_ENDIAN187#elif defined(__BIG_ENDIAN__)188# define C_BIG_ENDIAN189#elif defined(__MIPSEL__) || defined(__MIPSEL)190# define C_LITTLE_ENDIAN191#elif defined(__sparc__) || defined(__POWERPC__) || defined(__MC68K__) || defined(__mips__)192# define C_BIG_ENDIAN193#endif194195#if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && __BYTE_ORDER == __LITTLE_ENDIAN196# define C_LITTLE_ENDIAN197#elif defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && BYTE_ORDER == LITTLE_ENDIAN198# define C_LITTLE_ENDIAN199#elif defined(__LITTLE_ENDIAN__)200# define C_LITTLE_ENDIAN201#elif defined (__alpha__) || defined(_M_IX86) || defined(__i386__) || defined(__x86_64__) || defined(__ia64__)202# define C_LITTLE_ENDIAN203#endif204205/* Make sure some common C identifiers are availble w/ Windows */206207/* Could be used by C++ source */208209#ifdef __cplusplus210# define C_extern extern "C"211# define C_BEGIN_C_DECLS extern "C" {212# define C_END_C_DECLS }213#else214# define C_extern extern215# define C_BEGIN_C_DECLS216# define C_END_C_DECLS217#endif218219220/* Function declaration modes */221222/* Visibility */223#define C_varextern C_extern224#define C_fctimport225#define C_fctexport226#if defined(PIC)227# if defined(__CYGWIN__) || defined(__MINGW32__)228# ifndef C_BUILDING_LIBCHICKEN229# undef C_varextern230# define C_varextern C_extern __declspec(dllimport)231# endif232# endif233#endif234235/* Language specifics: */236#if defined(__GNUC__) || defined(__INTEL_COMPILER)237#define HAVE_STATEMENT_EXPRESSIONS 1238#endif239240#if !defined(__clang__) && !defined(__has_attribute)241/* Define so it won't error on other compilers with keywords like "noreturn" */242#define __has_attribute(x) 0243#endif244245#if defined(__GNUC__) || defined(__INTEL_COMPILER)246# define C_unlikely(x) __builtin_expect((x), 0)247# define C_likely(x) __builtin_expect((x), 1)248# ifndef __cplusplus249# define C_cblock ({250# define C_cblockend })251# if defined(__clang__) && !__has_attribute(noreturn)252# define C_noret253# else254# define C_noret __attribute__ ((noreturn))255# endif256# define C_noret_decl(name)257# define C_aligned __attribute__ ((aligned))258# endif259# if defined(__i386__) && !defined(__clang__)260# define C_regparm __attribute__ ((regparm(3)))261# endif262#else263# define C_unlikely(x) (x)264# define C_likely(x) (x)265#endif266267#ifndef C_cblock268# define C_cblock do{269# define C_cblockend }while(0)270# define C_noret271# define C_noret_decl(name)272#endif273274#ifndef C_regparm275# define C_regparm276#endif277278#ifndef C_ccall279# define C_ccall280#endif281282#ifndef C_aligned283# define C_aligned284#endif285286/* Stack growth direction; used to compute stack addresses */287#ifndef C_STACK_GROWS_DOWNWARD288# ifdef __hppa__289# define C_STACK_GROWS_DOWNWARD 0290# else291# define C_STACK_GROWS_DOWNWARD 1292# endif293#endif294295/* Have a GUI? */296297#if defined(C_GUI) || defined(C_PRIVATE_REPOSITORY)298# ifdef _WIN32299# include <windows.h>300# ifndef WINAPI301# define WINAPI302# endif303# endif304#endif305306/* Needed for pre-emptive threading */307308#define C_TIMER_INTERRUPTS309310311/* Constants: */312313#define C_STACK_RESERVE 0x10000314#define C_DEFAULT_MAX_PENDING_FINALIZERS 2048315316#define C_IMMEDIATE_MARK_BITS 0x00000003317#define C_IMMEDIATE_TYPE_BITS 0x0000000f318319#define C_BOOLEAN_BITS 0x00000006320#define C_CHARACTER_BITS 0x0000000a321#define C_SPECIAL_BITS 0x0000000e322323#define C_SCHEME_FALSE ((C_word)(C_BOOLEAN_BITS | 0x00000000))324#define C_SCHEME_TRUE ((C_word)(C_BOOLEAN_BITS | 0x00000010))325326#define C_SCHEME_END_OF_LIST ((C_word)(C_SPECIAL_BITS | 0x00000000))327#define C_SCHEME_UNDEFINED ((C_word)(C_SPECIAL_BITS | 0x00000010))328#define C_SCHEME_UNBOUND ((C_word)(C_SPECIAL_BITS | 0x00000020))329#define C_SCHEME_END_OF_FILE ((C_word)(C_SPECIAL_BITS | 0x00000030))330#define C_SCHEME_BROKEN_WEAK_PTR ((C_word)(C_SPECIAL_BITS | 0x00000040))331332#define C_FIXNUM_BIT 0x00000001333#define C_FIXNUM_SHIFT 1334335/* Character range is that of a UTF-8 codepoint, not representable range */336#define C_CHAR_BIT_MASK 0x1fffff337#define C_CHAR_SHIFT 8338339#ifdef C_SIXTY_FOUR340# define C_MOST_POSITIVE_FIXNUM 0x3fffffffffffffffL341# define C_WORD_SIZE 64342# define C_HALF_WORD_SIZE 32343#else344# define C_MOST_POSITIVE_FIXNUM 0x3fffffff345# define C_WORD_SIZE 32346# define C_HALF_WORD_SIZE 16347#endif348349/* Tunable performance-related constants */350#ifndef C_KARATSUBA_THRESHOLD351/* This defines when we'll switch from schoolbook to Karatsuba352 * multiplication. The smallest of the two numbers determines the353 * switch. It is pretty high right now because it generates a bit354 * more garbage and GC overhead dominates the algorithmic performance355 * gains. If the GC is improved, this can be readjusted.356 */357# define C_KARATSUBA_THRESHOLD 70358#endif359#ifndef C_BURNIKEL_ZIEGLER_THRESHOLD360/* This defines when to switch from schoolbook to Burnikel-Ziegler361 * division. It creates even more garbage than Karatsuba :(362 */363# define C_BURNIKEL_ZIEGLER_THRESHOLD 300364#endif365#ifndef C_RECURSIVE_TO_STRING_THRESHOLD366/* This threshold is in terms of the expected string length. */367# define C_RECURSIVE_TO_STRING_THRESHOLD 750368#endif369370/* These might fit better in runtime.c? */371#define C_fitsinbignumhalfdigitp(n) (C_BIGNUM_DIGIT_HI_HALF(n) == 0)372#define C_BIGNUM_DIGIT_LENGTH C_WORD_SIZE373#define C_BIGNUM_HALF_DIGIT_LENGTH C_HALF_WORD_SIZE374#define C_BIGNUM_BITS_TO_DIGITS(n) \375 (((n) + (C_BIGNUM_DIGIT_LENGTH - 1)) / C_BIGNUM_DIGIT_LENGTH)376#define C_BIGNUM_DIGIT_LO_HALF(d) (C_uhword)(d)377#define C_BIGNUM_DIGIT_HI_HALF(d) (C_uhword)((d) >> C_BIGNUM_HALF_DIGIT_LENGTH)378#define C_BIGNUM_DIGIT_COMBINE(h,l) ((C_uword)(h) << C_BIGNUM_HALF_DIGIT_LENGTH|(C_uhword)(l))379380#define C_MOST_POSITIVE_32_BIT_FIXNUM 0x3fffffff381#define C_MOST_NEGATIVE_FIXNUM (-C_MOST_POSITIVE_FIXNUM - 1)382383/* Block object layout:384385 Bits: B = BYTEBLOC_BIT386 S = SPECIALBLOCK_BIT387 A = 8ALIGN_BIT388389 Symbol = [ 1|3, Value, Name, Plist] Name = bytevector, 0-terminated390 String = [ 2|4, Name, Count, Offset, Index] Name = bytevector, 0-terminated391 Pair = [ 3|2, Car, Cdr]392 Closure = [ S4|1+N, Ptr, Slot, ...]393 Flonum = [AB5|8, IEEEDouble]394 Bignum = [ 6|1, Bits] Bits = bytevector395 Port = [ S7|15, Slots, ...]396 Structure = [ 8|1+N, Tag, Slots, ...]397 Pointer = [ S9|1, Ptr]398 Locative = [ S0a|4*N, Slots, ...]399 Taggedpointer = [ S0b|2, Ptr, Tag]400 Ratnum = [ 0c|2, Num, Den]401 Lambdainfo = [ B0d|N, Bytes, ...]402 Cplxnum = [ 0e|2, Imag, Real]403404*/405406#ifdef C_SIXTY_FOUR407# define C_INT_SIGN_BIT 0x8000000000000000L408# define C_INT_TOP_BIT 0x4000000000000000L409# define C_HEADER_BITS_MASK 0xff00000000000000L410# define C_HEADER_TYPE_BITS 0x0f00000000000000L411# define C_HEADER_SIZE_MASK 0x00ffffffffffffffL412# define C_GC_FORWARDING_BIT 0x8000000000000000L /* header contains forwarding pointer */413# define C_BYTEBLOCK_BIT 0x4000000000000000L /* block contains bytes instead of slots */414# define C_SPECIALBLOCK_BIT 0x2000000000000000L /* 1st item is a non-value */415# define C_8ALIGN_BIT 0x1000000000000000L /* data is aligned to 8-byte boundary */416417# define C_SYMBOL_TYPE (0x0100000000000000L)418# define C_STRING_TYPE (0x0200000000000000L)419# define C_PAIR_TYPE (0x0300000000000000L)420# define C_CLOSURE_TYPE (0x0400000000000000L | C_SPECIALBLOCK_BIT)421# define C_FLONUM_TYPE (0x0500000000000000L | C_BYTEBLOCK_BIT | C_8ALIGN_BIT)422# define C_BIGNUM_TYPE (0x0600000000000000L) /* Just the wrapper */423# define C_PORT_TYPE (0x0700000000000000L | C_SPECIALBLOCK_BIT)424# define C_STRUCTURE_TYPE (0x0800000000000000L)425# define C_POINTER_TYPE (0x0900000000000000L | C_SPECIALBLOCK_BIT)426# define C_LOCATIVE_TYPE (0x0a00000000000000L | C_SPECIALBLOCK_BIT)427# define C_TAGGED_POINTER_TYPE (0x0b00000000000000L | C_SPECIALBLOCK_BIT)428# define C_RATNUM_TYPE (0x0c00000000000000L)429# define C_LAMBDA_INFO_TYPE (0x0d00000000000000L | C_BYTEBLOCK_BIT)430# define C_CPLXNUM_TYPE (0x0e00000000000000L)431/* unused (0x0f00000000000000L ...) */432#else433# define C_INT_SIGN_BIT 0x80000000434# define C_INT_TOP_BIT 0x40000000435# define C_HEADER_BITS_MASK 0xff000000436# define C_HEADER_TYPE_BITS 0x0f000000437# define C_HEADER_SIZE_MASK 0x00ffffff438# define C_GC_FORWARDING_BIT 0x80000000439# define C_BYTEBLOCK_BIT 0x40000000440# define C_SPECIALBLOCK_BIT 0x20000000441# define C_8ALIGN_BIT 0x10000000442443# define C_SYMBOL_TYPE (0x01000000)444# define C_STRING_TYPE (0x02000000)445# define C_PAIR_TYPE (0x03000000)446# define C_CLOSURE_TYPE (0x04000000 | C_SPECIALBLOCK_BIT)447# ifdef C_DOUBLE_IS_32_BITS448# define C_FLONUM_TYPE (0x05000000 | C_BYTEBLOCK_BIT)449# else450# define C_FLONUM_TYPE (0x05000000 | C_BYTEBLOCK_BIT | C_8ALIGN_BIT)451# endif452# define C_BIGNUM_TYPE (0x06000000) /* Just the wrapper */453# define C_PORT_TYPE (0x07000000 | C_SPECIALBLOCK_BIT)454# define C_STRUCTURE_TYPE (0x08000000)455# define C_POINTER_TYPE (0x09000000 | C_SPECIALBLOCK_BIT)456# define C_LOCATIVE_TYPE (0x0a000000 | C_SPECIALBLOCK_BIT)457# define C_TAGGED_POINTER_TYPE (0x0b000000 | C_SPECIALBLOCK_BIT)458# define C_RATNUM_TYPE (0x0c000000)459# define C_LAMBDA_INFO_TYPE (0x0d000000 | C_BYTEBLOCK_BIT)460# define C_CPLXNUM_TYPE (0x0e000000)461/* unused (0x0f000000 ...) */462#endif463#define C_VECTOR_TYPE 0x00000000464#define C_BYTEVECTOR_TYPE (C_VECTOR_TYPE | C_BYTEBLOCK_BIT | C_8ALIGN_BIT)465466#define C_SIZEOF_LIST(n) ((n) * 3 + 1)467#define C_SIZEOF_PAIR 3468#define C_SIZEOF_STRING(n) (C_SIZEOF_BYTEVECTOR((n) * 4) + 1 + 5)469#define C_SIZEOF_SYMBOL 4470#define C_SIZEOF_INTERNED_SYMBOL(n) (C_SIZEOF_SYMBOL + C_SIZEOF_PAIR + C_SIZEOF_STRING(n))471#ifdef C_DOUBLE_IS_32_BITS472# define C_SIZEOF_FLONUM 2473#else474# define C_SIZEOF_FLONUM 4475#endif476#define C_SIZEOF_POINTER 2477#define C_SIZEOF_TAGGED_POINTER 3478#define C_SIZEOF_VECTOR(n) ((n) + 1)479#define C_SIZEOF_LOCATIVE 5480#define C_SIZEOF_PORT 17481#define C_SIZEOF_RATNUM 3482#define C_SIZEOF_CPLXNUM 3483#define C_SIZEOF_STRUCTURE(n) ((n)+1)484#define C_SIZEOF_CLOSURE(n) ((n)+1)485#define C_SIZEOF_BYTEVECTOR(n) (C_bytestowords(n) + 2)486#define C_SIZEOF_INTERNAL_BIGNUM_VECTOR(n) (C_SIZEOF_VECTOR((n)+1))487#define C_internal_bignum_vector(b) (C_block_item(b,0))488489/* This is for convenience and allows flexibility in representation */490#define C_SIZEOF_FIX_BIGNUM C_SIZEOF_BIGNUM(1)491#define C_SIZEOF_BIGNUM_WRAPPER 2492#define C_SIZEOF_BIGNUM(n) (C_SIZEOF_INTERNAL_BIGNUM_VECTOR(n)+C_SIZEOF_BIGNUM_WRAPPER)493494/* Fixed size types have pre-computed header tags */495#define C_STRING_TAG (C_STRING_TYPE | 4)496#define C_PAIR_TAG (C_PAIR_TYPE | (C_SIZEOF_PAIR - 1))497#define C_WEAK_PAIR_TAG (C_PAIR_TAG | C_SPECIALBLOCK_BIT)498#define C_POINTER_TAG (C_POINTER_TYPE | (C_SIZEOF_POINTER - 1))499#define C_LOCATIVE_TAG (C_LOCATIVE_TYPE | (C_SIZEOF_LOCATIVE - 1))500#define C_TAGGED_POINTER_TAG (C_TAGGED_POINTER_TYPE | (C_SIZEOF_TAGGED_POINTER - 1))501#define C_SYMBOL_TAG (C_SYMBOL_TYPE | (C_SIZEOF_SYMBOL - 1))502#define C_FLONUM_TAG (C_FLONUM_TYPE | sizeof(double))503#define C_BIGNUM_TAG (C_BIGNUM_TYPE | 1)504#define C_RATNUM_TAG (C_RATNUM_TYPE | 2)505#define C_CPLXNUM_TAG (C_CPLXNUM_TYPE | 2)506507/* Locative subtypes */508#define C_SLOT_LOCATIVE 0509#define C_CHAR_LOCATIVE 1510#define C_U8_LOCATIVE 2511#define C_S8_LOCATIVE 3512#define C_U16_LOCATIVE 4513#define C_S16_LOCATIVE 5514#define C_U32_LOCATIVE 6515#define C_S32_LOCATIVE 7516#define C_U64_LOCATIVE 8517#define C_S64_LOCATIVE 9518#define C_F32_LOCATIVE 10519#define C_F64_LOCATIVE 11520521#if defined (__MINGW32__)522# define C_s64 __int64523# define C_u64 unsigned __int64524#else525# define C_s64 int64_t526# define C_u64 uint64_t527#endif528529#ifdef C_SIXTY_FOUR530# ifdef C_LLP531# define C_word C_s64532# define C_hword long533# else534# define C_word long535# define C_hword int536# endif537# define C_u32 uint32_t538# define C_s32 int32_t539#else540# define C_word int541# define C_hword short542# define C_u32 unsigned int543# define C_s32 int544#endif545546#define C_char char547#define C_uchar unsigned C_char548#define C_byte char549#define C_uword unsigned C_word550#define C_uhword unsigned C_hword551#define C_header C_uword552553/* if all else fails, use these:554 #define UINT64_MAX (18446744073709551615ULL)555 #define INT64_MAX (9223372036854775807LL)556 #define INT64_MIN (-INT64_MAX - 1)557 #define UINT32_MAX (4294967295U)558 #define INT32_MAX (2147483647)559 #define INT32_MIN (-INT32_MAX - 1)560 #define UINT16_MAX (65535U)561 #define INT16_MAX (32767)562 #define INT16_MIN (-INT16_MAX - 1)563 #define UINT8_MAX (255)564 #define INT8_MAX (127)565 #define INT8_MIN (-INT8_MAX - 1)566*/567568#define C_U64_MAX UINT64_MAX569#define C_S64_MIN INT64_MIN570#define C_S64_MAX INT64_MAX571572#if defined(C_LLP)573# define C_wabs llabs574# define C_long C_s64575# ifndef LONG_LONG_MAX576# define C_LONG_MAX LLONG_MAX577# define C_LONG_MIN LLONG_MIN578# else579# define C_LONG_MAX LONG_LONG_MAX580# define C_LONG_MIN LONG_LONG_MIN581# endif582#else583# define C_wabs labs584# define C_long long585# define C_LONG_MAX LONG_MAX586# define C_LONG_MIN LONG_MIN587#endif588589#define C_ulong unsigned C_long590591#ifdef __cplusplus592# define C_text(x) ((C_char *)(x))593#else594# define C_text(x) (x)595#endif596597#define C_TIMER_INTERRUPT_NUMBER 255598599#define C_BAD_ARGUMENT_COUNT_ERROR 1600#define C_BAD_MINIMUM_ARGUMENT_COUNT_ERROR 2601#define C_BAD_ARGUMENT_TYPE_ERROR 3602#define C_UNBOUND_VARIABLE_ERROR 4603#define C_BAD_ARGUMENT_TYPE_NO_KEYWORD_ERROR 5604#define C_OUT_OF_MEMORY_ERROR 6605#define C_DIVISION_BY_ZERO_ERROR 7606#define C_OUT_OF_BOUNDS_ERROR 8607#define C_NOT_A_CLOSURE_ERROR 9608#define C_CONTINUATION_CANT_RECEIVE_VALUES_ERROR 10609#define C_BAD_ARGUMENT_TYPE_CYCLIC_LIST_ERROR 11610#define C_TOO_DEEP_RECURSION_ERROR 12611#define C_CANT_REPRESENT_INEXACT_ERROR 13612#define C_NOT_A_PROPER_LIST_ERROR 14613#define C_BAD_ARGUMENT_TYPE_NO_FIXNUM_ERROR 15614#define C_BAD_ARGUMENT_TYPE_NO_NUMBER_ERROR 16615#define C_BAD_ARGUMENT_TYPE_NO_STRING_ERROR 17616#define C_BAD_ARGUMENT_TYPE_NO_PAIR_ERROR 18617#define C_BAD_ARGUMENT_TYPE_NO_LIST_ERROR 19618#define C_BAD_ARGUMENT_TYPE_NO_CHAR_ERROR 20619#define C_BAD_ARGUMENT_TYPE_NO_VECTOR_ERROR 21620#define C_BAD_ARGUMENT_TYPE_NO_SYMBOL_ERROR 22621#define C_STACK_OVERFLOW_ERROR 23622#define C_BAD_ARGUMENT_TYPE_BAD_STRUCT_ERROR 24623#define C_BAD_ARGUMENT_TYPE_NO_BYTEVECTOR_ERROR 25624#define C_LOST_LOCATIVE_ERROR 26625#define C_BAD_ARGUMENT_TYPE_NO_BLOCK_ERROR 27626#define C_BAD_ARGUMENT_TYPE_NO_NUMBER_VECTOR_ERROR 28627#define C_BAD_ARGUMENT_TYPE_NO_INTEGER_ERROR 29628#define C_BAD_ARGUMENT_TYPE_NO_UINTEGER_ERROR 30629#define C_BAD_ARGUMENT_TYPE_NO_POINTER_ERROR 31630#define C_BAD_ARGUMENT_TYPE_NO_TAGGED_POINTER_ERROR 32631#define C_BAD_ARGUMENT_TYPE_NO_FLONUM_ERROR 33632#define C_BAD_ARGUMENT_TYPE_NO_CLOSURE_ERROR 34633#define C_BAD_ARGUMENT_TYPE_BAD_BASE_ERROR 35634#define C_CIRCULAR_DATA_ERROR 36635#define C_BAD_ARGUMENT_TYPE_NO_BOOLEAN_ERROR 37636#define C_BAD_ARGUMENT_TYPE_NO_LOCATIVE_ERROR 38637#define C_BAD_ARGUMENT_TYPE_NO_PORT_ERROR 39638#define C_BAD_ARGUMENT_TYPE_PORT_DIRECTION_ERROR 40639#define C_BAD_ARGUMENT_TYPE_PORT_NO_INPUT_ERROR 41640#define C_BAD_ARGUMENT_TYPE_PORT_NO_OUTPUT_ERROR 42641#define C_PORT_CLOSED_ERROR 43642#define C_ASCIIZ_REPRESENTATION_ERROR 44643#define C_MEMORY_VIOLATION_ERROR 45644#define C_FLOATING_POINT_EXCEPTION_ERROR 46645#define C_ILLEGAL_INSTRUCTION_ERROR 47646#define C_BUS_ERROR 48647#define C_BAD_ARGUMENT_TYPE_NO_EXACT_ERROR 49648#define C_BAD_ARGUMENT_TYPE_NO_INEXACT_ERROR 50649#define C_BAD_ARGUMENT_TYPE_NO_REAL_ERROR 51650#define C_BAD_ARGUMENT_TYPE_COMPLEX_NO_ORDERING_ERROR 52651#define C_BAD_ARGUMENT_TYPE_NO_EXACT_INTEGER_ERROR 53652#define C_BAD_ARGUMENT_TYPE_FOREIGN_LIMITATION 54653#define C_BAD_ARGUMENT_TYPE_COMPLEX_ABS 55654#define C_REST_ARG_OUT_OF_BOUNDS_ERROR 56655#define C_DECODING_ERROR 57656#define C_BAD_ARGUMENT_TYPE_NUMERIC_RANGE_ERROR 58657658/* Platform information */659#if defined(C_BIG_ENDIAN)660# define C_MACHINE_BYTE_ORDER "big-endian"661#elif defined(C_LITTLE_ENDIAN)662# define C_MACHINE_BYTE_ORDER "little-endian"663#endif664665#if defined(__alpha__)666# define C_MACHINE_TYPE "alpha"667#elif defined(__mips__)668# define C_MACHINE_TYPE "mips"669#elif defined(__hppa__)670# define C_MACHINE_TYPE "hppa"671#elif defined(__sparc_v9__) || defined(__sparcv9)672# define C_MACHINE_TYPE "ultrasparc"673#elif defined(__sparc__)674# define C_MACHINE_TYPE "sparc"675#elif defined(__powerpc64__) || defined(_ARCH_PPC64)676# define C_MACHINE_TYPE "ppc64"677#elif defined(__ppc__) || defined(__powerpc__) || defined(_ARCH_PPC)678# define C_MACHINE_TYPE "ppc"679#elif defined(_M_IX86) || defined(__i386__)680# define C_MACHINE_TYPE "x86"681#elif defined(__ia64__)682# define C_MACHINE_TYPE "ia64"683#elif defined(__x86_64__)684# define C_MACHINE_TYPE "x86-64"685#elif defined(__riscv)686# if defined(__LP64__) || defined(_LP64)687# define C_MACHINE_TYPE "riscv64"688# else689# define C_MACHINE_TYPE "riscv"690# endif691#elif defined(__arm64__) || defined(__aarch64__)692# define C_MACHINE_TYPE "arm64"693#elif defined(__arm__)694# define C_MACHINE_TYPE "arm"695#else696# define C_MACHINE_TYPE "unknown"697#endif698699#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(_WIN32) || defined(__WINNT__)700# define C_SOFTWARE_TYPE "windows"701#elif defined(__ANDROID__)702# define C_SOFTWARE_TYPE "android"703#elif defined(__unix__) || defined(C_XXXBSD) || defined(_AIX)704# define C_SOFTWARE_TYPE "unix"705#elif defined(ECOS)706# define C_SOFTWARE_TYPE "ecos"707#else708# define C_SOFTWARE_TYPE "unknown"709#endif710711#if defined(_WIN32) && !defined(__CYGWIN__)712# define C_WCHAR_FILENAMES713# define C_WCHAR wchar_t714#else715# define C_WCHAR C_char716#endif717718#if defined(__SUNPRO_C)719# define C_BUILD_PLATFORM "sun"720#elif defined(__clang__)721# define C_BUILD_PLATFORM "clang"722#elif defined(_AIX)723# define C_BUILD_PLATFORM "aix"724#elif defined(__GNUC__)725# define C_BUILD_PLATFORM "gnu"726#elif defined(__INTEL_COMPILER)727# define C_BUILD_PLATFORM "intel"728#else729# define C_BUILD_PLATFORM "unknown"730#endif731732#if defined(__linux__)733# define C_SOFTWARE_VERSION "linux"734#elif defined(__FreeBSD__)735# define C_SOFTWARE_VERSION "freebsd"736#elif defined(__NetBSD__)737# define C_SOFTWARE_VERSION "netbsd"738#elif defined(__OpenBSD__)739# define C_SOFTWARE_VERSION "openbsd"740#elif defined(C_MACOSX)741# define C_SOFTWARE_VERSION "macosx"742#elif defined(__hpux__)743# define C_SOFTWARE_VERSION "hpux"744#elif defined(__DragonFly__)745# define C_SOFTWARE_VERSION "dragonfly"746#elif defined(__HAIKU__)747# define C_SOFTWARE_VERSION "haiku"748#elif defined(__sun)749# if defined(__SVR4)750# define C_SOFTWARE_VERSION "solaris"751# else752# define C_SOFTWARE_VERSION "sunos"753# endif754#elif defined(_AIX)755# define C_SOFTWARE_VERSION "aix"756#elif defined(__GNU__)757# define C_SOFTWARE_VERSION "hurd"758#elif defined(__CYGWIN__)759# define C_SOFTWARE_VERSION "cygwin"760#elif defined(_WIN32) && !defined(__CYGWIN__)761# define C_SOFTWARE_VERSION "mingw"762#else763# define C_SOFTWARE_VERSION "unknown"764#endif765766/* There is no PATH_MAX in The Hurd. */767#ifdef PATH_MAX768# define C_MAX_PATH PATH_MAX769#else770# define C_MAX_PATH 1024771#endif772773#define C_RANDOM_STATE_SIZE (16 * sizeof(C_uword))774775/* Types: */776777typedef struct C_block_struct778{779 C_header header;780 C_word data[];781} C_SCHEME_BLOCK;782783typedef struct C_symbol_table_struct784{785 char *name;786 unsigned int size;787 unsigned int rand;788 C_word *table;789 struct C_symbol_table_struct *next;790} C_SYMBOL_TABLE;791792typedef struct C_gc_root_struct793{794 C_word value;795 struct C_gc_root_struct *next, *prev;796 int finalizable;797} C_GC_ROOT;798799typedef struct C_ptable_entry_struct800{801 C_char *id;802 void *ptr;803} C_PTABLE_ENTRY;804805typedef void (C_ccall *C_proc)(C_word, C_word *) C_noret;806807808/* Macros: */809810#define C_cpsproc(name) C_ccall void name(C_word c, C_word *av) C_noret811812#define CHICKEN_gc_root_ref(root) (((C_GC_ROOT *)(root))->value)813#define CHICKEN_gc_root_set(root, x) C_mutate(&((C_GC_ROOT *)(root))->value, (x))814815#define CHICKEN_global_ref(root) C_u_i_car(((C_GC_ROOT *)(root))->value)816#define CHICKEN_global_set(root, x) C_mutate(&C_u_i_car(((C_GC_ROOT *)(root))->value), (x))817818#define CHICKEN_default_toplevel ((void *)C_default_5fstub_toplevel)819820#define C__STR1(x) #x821#define C__STR2(x) C__STR1(x)822823#define C_align4(n) (((n) + 3) & ~3)824#define C_align8(n) (((n) + 7) & ~7)825#define C_align16(n) (((n) + 15) & ~15)826827#define C_aligned8(n) ((((C_word)(n)) & 7) == 0)828829#define C_buf_end(b) ((C_word *)((C_byte *)(b) + sizeof(b)))830831/* This is word-size dependent: */832#ifdef C_SIXTY_FOUR833# define C_align(n) C_align8(n)834# define C_wordstobytes(n) ((C_uword)(n) << 3)835# define C_bytestowords(n) (((n) + 7) >> 3)836# define C_wordsperdouble(n) (n)837# define C_WORD_MIN LONG_MIN838# define C_WORD_MAX LONG_MAX839# define C_UWORD_MAX ULONG_MAX840#else841# define C_align(n) C_align4(n)842# define C_wordstobytes(n) ((C_uword)(n) << 2)843# define C_bytestowords(n) (((n) + 3) >> 2)844# define C_wordsperdouble(n) ((C_uword)(n) << 1)845# define C_WORD_MIN INT_MIN846# define C_WORD_MAX INT_MAX847# define C_UWORD_MAX UINT_MAX848#endif849850/* Clang and G++ support statement expressions, but only in a limited way */851#if DEBUGBUILD && HAVE_STATEMENT_EXPRESSIONS && !defined(__cplusplus)852/* These are wrappers around the following idiom:853 * assert(SOME_PRED(obj));854 * do_something_with(obj);855 * This works around the fact obj may be an expression with side-effects.856 *857 * To make this work with nested expansions, we need semantics like858 * (let ((x 1)) (let ((x x)) x)) => 1, but in C, int x = x; results in859 * undefined behaviour because x refers to itself. As a workaround,860 * we keep around a reference to the previous level (one scope up).861 * After initialisation, "previous" is redefined to mean "current".862 */863# define C_VAL1(x) C__PREV_TMPST.n1864# define C_VAL2(x) C__PREV_TMPST.n2865# define C__CHECK_panic(a,s,f,l) \866 ((a) ? (void)0 : \867 C_panic_hook(C_text("Low-level type assertion " s " failed at " f ":" C__STR1(l))))868# define C__CHECK_core(v,a,s,x) \869 ({ struct { \870 typeof(v) n1; \871 } C__TMPST = { .n1 = (v) }; \872 typeof(C__TMPST) C__PREV_TMPST=C__TMPST; \873 C__CHECK_panic(a,s,__FILE__,__LINE__); \874 x; })875# define C__CHECK2_core(v1,v2,a,s,x) \876 ({ struct { \877 typeof(v1) n1; \878 typeof(v2) n2; \879 } C__TMPST = { .n1 = (v1), .n2 = (v2) }; \880 typeof(C__TMPST) C__PREV_TMPST=C__TMPST; \881 C__CHECK_panic(a,s,__FILE__,__LINE__); \882 x; })883# define C_CHECK(v,a,x) C__CHECK_core(v,a,#a,x)884# define C_CHECK2(v1,v2,a,x) C__CHECK2_core(v1,v2,a,#a,x)885/*886 * Convenience for using Scheme-predicates.887 */888# define C_CHECKp(v,a,x) C__CHECK_core(v,C_truep(a),#a"=#t",x)889# define C_CHECK2p(v1,v2,a,x) C__CHECK2_core(v1,v2,C_truep(a),#a"=#t",x)890#else891# define C_VAL1(x) (x)892# define C_VAL2(x) (x)893# define C_CHECK(v,a,x) (x)894# define C_CHECK2(v1,v2,a,x) (x)895# define C_CHECKp(v,a,x) (x)896# define C_CHECK2p(v1,v2,a,x) (x)897#endif898899#ifndef C_PROVIDE_LIBC_STUBS900# define C_FILEPTR FILE *901902# define C_stdin stdin903# define C_stdout stdout904# define C_stderr stderr905906# define C_memcpy memcpy907# define C_memcmp memcmp908# define C_strncpy strncpy909# define C_strcmp strcmp910# define C_strncmp strncmp911# define C_strlen strlen912# define C_memchr memchr913# define C_memset memset914# define C_memmove memmove915# define C_malloc malloc916# define C_calloc calloc917# define C_free free918# define C_strchr strchr919# define C_realloc realloc920# define C_strdup strdup921# define C_strtol strtol922# define C_strtoll strtoll923# define C_strtod strtod924# define C_strtoul strtoul925# ifdef C_WCHAR_FILENAMES926# define C_fopen _wfopen927# define C_system _wsystem928# define C_access _waccess929# else930# define C_fopen fopen931# define C_system system932# define C_access access933# endif934# define C_fclose fclose935# define C_strpbrk strpbrk936# define C_strcspn strcspn937# define C_snprintf snprintf938# define C_printf printf939# define C_fprintf fprintf940# define C_vfprintf vfprintf941# define C_fflush fflush942# define C_getchar getchar943# define C_exit exit944# define C__exit _exit945# define C_dlopen dlopen946# define C_dlclose dlclose947# define C_dlsym dlsym948# define C_fwrite fwrite949# define C_fread fread950# define C_fputs fputs951# define C_fputc fputc952# define C_putchar putchar953# if (defined getc_unlocked || _POSIX_C_SOURCE >= 199506L) && !defined(__MINGW32__)954# define C_getc getc_unlocked955# else956# define C_getc getc957# endif958# define C_fgetc fgetc959# define C_fgets fgets960# define C_ungetc ungetc961# define C_isatty isatty962# define C_fileno fileno963# define C_select select964# if defined(HAVE_SIGACTION)965# define C_sigaction sigaction966# endif967# define C_signal signal968# define C_getrusage getrusage969# define C_gettimeofday gettimeofday970# define C_gmtime gmtime971# define C_localtime localtime972/*973 * It is undefined whether regular setjmp/longjmp save/restore signal mask974 * so try to use versions that we know won't try to save & restore.975 */976# if defined(HAVE_SIGSETJMP)977# define C_sigsetjmp sigsetjmp978# define C_siglongjmp siglongjmp979# endif980# ifdef HAVE_SIGPROCMASK981# define C_sigprocmask sigprocmask982# endif983# define C_setjmp setjmp984# define C_longjmp longjmp985# define C_alloca alloca986# define C_strerror strerror987# define C_sin sin988# define C_cos cos989# define C_tan tan990# define C_asin asin991# define C_acos acos992# define C_atan atan993# define C_sinh sinh994# define C_cosh cosh995# define C_tanh tanh996# define C_asinh asinh997# define C_acosh acosh998# define C_atanh atanh999# define C_atan2 atan21000# define C_log log1001# define C_exp exp1002# define C_pow pow1003# define C_sqrt sqrt1004# define C_ceil ceil1005# define C_floor floor1006# define C_round round1007# define C_trunc trunc1008# define C_fabs fabs1009# define C_modf modf1010# define C_readlink readlink1011# define C_getcwd getcwd1012# define C_getpid getpid1013# define C_fma fma1014#else1015/* provide this file and define C_PROVIDE_LIBC_STUBS if you want to use1016 your own libc-replacements or -wrappers */1017# include "chicken-libc-stubs.h"1018#endif10191020#ifdef C_LLP1021# define C_strtow C_strtoll1022#else1023# define C_strtow C_strtol1024#endif10251026#define C_return(x) return(x)1027#define C_resize_stack(n) C_do_resize_stack(n)1028#define C_memcpy_slots(t, f, n) C_memcpy((t), (f), (n) * sizeof(C_word))1029/* Without check: initialisation of a newly allocated header */1030#define C_block_header_init(x,h) (((C_SCHEME_BLOCK *)(x))->header = (h))1031/* These two must result in an lvalue, hence the (*foo(&bar)) faffery */1032#define C_block_header(x) (*C_CHECKp(x,C_blockp((C_word)C_VAL1(x)),&(((C_SCHEME_BLOCK *)(C_VAL1(x)))->header)))1033#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) ])))1034#define C_set_block_item(x,i,y) (C_block_item(x, i) = (y))1035#define C_header_bits(bh) (C_block_header(bh) & C_HEADER_BITS_MASK)1036#define C_header_type(bh) (C_block_header(bh) & C_HEADER_TYPE_BITS)1037#define C_header_size(bh) (C_block_header(bh) & C_HEADER_SIZE_MASK)1038#define C_bignum_size(b) (C_bytestowords(C_header_size(C_internal_bignum_vector(b)))-1)1039#define C_make_header(type, size) ((C_header)(((type) & C_HEADER_BITS_MASK) | ((size) & C_HEADER_SIZE_MASK)))1040#define C_symbol_value(x) (C_block_item(x, 0))1041#define C_symbol_name(x) (C_block_item(x, 1))1042#define C_symbol_plist(x) (C_block_item(x, 2))1043#define C_save(x) (*(--C_temporary_stack) = (C_word)(x))1044#define C_rescue(x, i) (C_temporary_stack[ i ] = (x))1045#define C_restore (*(C_temporary_stack++))1046#define C_heaptop ((C_word **)(&C_fromspace_top))1047#define C_drop(n) (C_temporary_stack += (n))1048#define C_alloc(n) ((C_word *)C_alloca((n) * sizeof(C_word)))1049#if (defined (__llvm__) && defined (__GNUC__)) || defined (__TINYC__)1050# if defined (__i386__)1051# define C_stack_pointer ({C_word *sp; __asm__ __volatile__("movl %%esp,%0":"=r"(sp):);sp;})1052# elif defined (__x86_64__)1053# define C_stack_pointer ({C_word *sp; __asm__ __volatile__("movq %%rsp,%0":"=r"(sp):);sp;})1054# else1055/* Not alloca(0) because:1056 * - LLVM allocates anyways1057 * - TCC always returns NULL1058 */1059# define C_stack_pointer ((C_word *)C_alloca(1))1060# endif1061#else1062# define C_stack_pointer ((C_word *)C_alloca(0))1063#endif1064#define C_stack_pointer_test ((C_word *)C_alloca(1))1065#define C_demand_2(n) (((C_word *)C_fromspace_top + (n)) < (C_word *)C_fromspace_limit)1066#define C_calculate_demand(n,c,m) ((n) + (((c) > (m)) ? 0 : (m)))1067#define C_fix(n) ((C_word)((C_uword)(n) << C_FIXNUM_SHIFT) | C_FIXNUM_BIT)1068#define C_unfix(x) C_CHECKp(x,C_fixnump(C_VAL1(x)),((C_VAL1(x)) >> C_FIXNUM_SHIFT))1069#define C_make_character(c) (((((C_uword)(c)) & C_CHAR_BIT_MASK) << C_CHAR_SHIFT) | C_CHARACTER_BITS)1070#define C_character_code(x) C_CHECKp(x,C_charp(C_VAL1(x)),((C_word)(C_VAL1(x)) >> C_CHAR_SHIFT) & C_CHAR_BIT_MASK)1071#define C_flonum_magnitude(x) (*C_CHECKp(x,C_flonump(C_VAL1(x)),(double *)C_data_pointer(C_VAL1(x))))1072#define C_c_string(x) C_CHECK(x,(C_truep(C_bytevectorp(C_VAL1(x)))),(C_char *)C_data_pointer(C_VAL1(x)))10731074#define C_c_pointer(x) ((void *)(x))1075#define C_c_pointer_nn(x) ((void *)C_block_item(x, 0))1076#define C_truep(x) ((x) != C_SCHEME_FALSE)1077#define C_immediatep(x) ((x) & C_IMMEDIATE_MARK_BITS)1078#define C_mk_bool(x) ((x) ? C_SCHEME_TRUE : C_SCHEME_FALSE)1079#define C_mk_nbool(x) ((x) ? C_SCHEME_FALSE : C_SCHEME_TRUE)1080#define C_port_file(p) C_CHECKp(p,C_portp(C_VAL1(p)),(C_FILEPTR)C_block_item(C_VAL1(p), 0))1081#define C_port_fileno(p) C_fix(C_fileno(C_port_file(p)))1082#define C_data_pointer(b) C_CHECKp(b,C_blockp((C_word)C_VAL1(b)),(void *)(((C_SCHEME_BLOCK *)(C_VAL1(b)))->data))1083#define C_bignum_negativep(b) C_CHECKp(b,C_bignump(C_VAL1(b)),(C_block_item(C_internal_bignum_vector(C_VAL1(b)),0)!=0))1084#define C_bignum_digits(b) C_CHECKp(b,C_bignump(C_VAL1(b)),(((C_uword *)C_data_pointer(C_internal_bignum_vector(C_VAL1(b))))+1))1085#define C_fitsinbignumhalfdigitp(n)(C_BIGNUM_DIGIT_HI_HALF(n) == 0)1086#define C_bignum_negated_fitsinfixnump(b) (C_bignum_size(b) == 1 && (C_bignum_negativep(b) ? C_ufitsinfixnump(*C_bignum_digits(b)) : !(*C_bignum_digits(b) & C_INT_SIGN_BIT) && C_fitsinfixnump(-(C_word)*C_bignum_digits(b))))1087#define C_bignum_mutate_size(b, s) (C_block_header(C_internal_bignum_vector(b)) = (C_BYTEVECTOR_TYPE | C_wordstobytes((s)+1)))1088#define C_fitsinfixnump(n) (((n) & C_INT_SIGN_BIT) == (((C_uword)(n) & C_INT_TOP_BIT) << 1))1089#define C_ufitsinfixnump(n) (((n) & (C_INT_SIGN_BIT | (C_INT_SIGN_BIT >> 1))) == 0)1090#define C_and(x, y) (C_truep(x) ? (y) : C_SCHEME_FALSE)1091#define C_c_bytevector(x) ((unsigned char *)C_data_pointer(x))1092#define C_c_bytevector_or_null(x) ((unsigned char *)C_data_pointer_or_null(x))1093#define C_srfi_4_vector(x) C_data_pointer(C_block_item(x,1))1094#define C_c_s8vector(x) ((signed char *)C_srfi_4_vector(x))1095#define C_c_s8vector_or_null(x) ((signed char *)C_srfi_4_vector_or_null(x))1096#define C_c_u16vector(x) ((unsigned short *)C_srfi_4_vector(x))1097#define C_c_u16vector_or_null(x) ((unsigned short *)C_srfi_4_vector_or_null(x))1098#define C_c_s16vector(x) ((short *)C_srfi_4_vector(x))1099#define C_c_s16vector_or_null(x) ((short *)C_srfi_4_vector_or_null(x))1100#define C_c_u32vector(x) ((C_u32 *)C_srfi_4_vector(x))1101#define C_c_u32vector_or_null(x) ((C_u32 *)C_srfi_4_vector_or_null(x))1102#define C_c_s32vector(x) ((C_s32 *)C_srfi_4_vector(x))1103#define C_c_s32vector_or_null(x) ((C_s32 *)C_srfi_4_vector_or_null(x))1104#define C_c_u64vector(x) ((C_u64 *)C_srfi_4_vector(x))1105#define C_c_u64vector_or_null(x) ((C_u64 *)C_srfi_4_vector_or_null(x))1106#define C_c_s64vector(x) ((C_s64 *)C_srfi_4_vector(x))1107#define C_c_s64vector_or_null(x) ((C_s64 *)C_srfi_4_vector_or_null(x))1108#define C_c_f32vector(x) ((float *)C_srfi_4_vector(x))1109#define C_c_f32vector_or_null(x) ((float *)C_srfi_4_vector_or_null(x))1110#define C_c_f64vector(x) ((double *)C_srfi_4_vector(x))1111#define C_c_f64vector_or_null(x) ((double *)C_srfi_4_vector_or_null(x))1112#define C_c_pointer_vector(x) ((void **)C_data_pointer(C_block_item((x), 2)))11131114#define C_isnan(f) isnan(f)1115#define C_isinf(f) isinf(f)1116#define C_isfinite(f) isfinite(f)11171118#define C_stack_overflow_check C_stack_check1(C_stack_overflow(NULL))11191120/* TODO: The C_scratch_usage checks should probably be moved. Maybe1121 * we should add a core#allocate_scratch_inline which will insert1122 * C_demand/C_stack_probe-like checks to copy the result onto the1123 * stack or reclaim, but in a clever way so it's only done at the1124 * "end" of a C function.1125 */1126#if C_STACK_GROWS_DOWNWARD1127# define C_demand(n) ((C_word)(C_stack_pointer - C_stack_limit) > ((n)+C_scratch_usage))1128# define C_stack_check1(err) if(!C_disable_overflow_check) { \1129 do { C_byte *_sp = (C_byte*)(C_stack_pointer); \1130 if(_sp < (C_byte *)C_stack_hard_limit && \1131 ((C_byte *)C_stack_hard_limit - _sp) > C_STACK_RESERVE) \1132 err; } \1133 while(0);}11341135#else1136# define C_demand(n) ((C_word)(C_stack_limit - C_stack_pointer) > ((n)+C_scratch_usage))1137# define C_stack_check1(err) if(!C_disable_overflow_check) { \1138 do { C_byte *_sp = (C_byte*)(C_stack_pointer); \1139 if(_sp > (C_byte *)C_stack_hard_limit && \1140 (_sp - (C_byte *)C_stack_hard_limit) > C_STACK_RESERVE) \1141 err; } \1142 while(0);}11431144#endif11451146#define C_zero_length_p(x) C_mk_bool(C_header_size(x) == 0)1147#define C_boundp(x) C_mk_bool(C_block_item(x, 0) != C_SCHEME_UNBOUND)1148#define C_unboundvaluep(x) C_mk_bool((x) == C_SCHEME_UNBOUND)1149#define C_blockp(x) C_mk_bool(!C_immediatep(x))1150#define C_forwardedp(x) C_mk_bool((C_block_header(x) & C_GC_FORWARDING_BIT) != 0)1151#define C_immp(x) C_mk_bool(C_immediatep(x))1152#define C_flonump(x) C_mk_bool(C_block_header(x) == C_FLONUM_TAG)1153#define C_bignump(x) C_mk_bool(C_block_header(x) == C_BIGNUM_TAG)1154#define C_stringp(x) C_mk_bool(C_header_bits(x) == C_STRING_TYPE)1155#define C_symbolp(x) C_mk_bool(C_block_header(x) == C_SYMBOL_TAG)1156#define C_pairp(x) C_mk_bool(C_header_type(x) == C_PAIR_TYPE)1157#define C_weak_pairp(x) C_mk_bool(C_block_header(x) == C_WEAK_PAIR_TAG)1158#define C_closurep(x) C_mk_bool(C_header_bits(x) == C_CLOSURE_TYPE)1159#define C_vectorp(x) C_mk_bool(C_header_bits(x) == C_VECTOR_TYPE)1160#define C_bytevectorp(x) C_mk_bool(C_header_bits(x) == C_BYTEVECTOR_TYPE)1161#define C_portp(x) C_mk_bool(C_header_bits(x) == C_PORT_TYPE)1162#define C_structurep(x) C_mk_bool(C_header_bits(x) == C_STRUCTURE_TYPE)1163#define C_locativep(x) C_mk_bool(C_block_header(x) == C_LOCATIVE_TAG)1164#define C_charp(x) C_mk_bool(((x) & C_IMMEDIATE_TYPE_BITS) == C_CHARACTER_BITS)1165#define C_booleanp(x) C_mk_bool(((x) & C_IMMEDIATE_TYPE_BITS) == C_BOOLEAN_BITS)1166#define C_eofp(x) C_mk_bool((x) == C_SCHEME_END_OF_FILE)1167#define C_undefinedp(x) C_mk_bool((x) == C_SCHEME_UNDEFINED)1168#define C_bwpp(x) C_mk_bool((x) == C_SCHEME_BROKEN_WEAK_PTR)1169#define C_fixnump(x) C_mk_bool((x) & C_FIXNUM_BIT)1170#define C_nfixnump(x) C_mk_nbool((x) & C_FIXNUM_BIT)1171#define C_pointerp(x) C_mk_bool(C_block_header(x) == C_POINTER_TAG)1172#define C_taggedpointerp(x) C_mk_bool(C_block_header(x) == C_TAGGED_POINTER_TAG)1173#define C_lambdainfop(x) C_mk_bool(C_header_bits(x) == C_LAMBDA_INFO_TYPE)1174#define C_anypointerp(x) C_mk_bool(C_block_header(x) == C_POINTER_TAG || C_block_header(x) == C_TAGGED_POINTER_TAG)1175#define C_specialp(x) C_mk_bool(C_header_bits(x) & C_SPECIALBLOCK_BIT)1176#define C_byteblockp(x) C_mk_bool(C_header_bits(x) & C_BYTEBLOCK_BIT)1177#define C_sametypep(x, y) C_mk_bool(C_header_bits(x) == C_header_bits(y))1178#define C_eqp(x, y) C_mk_bool((x) == (y))1179#define C_vemptyp(x) C_mk_bool(C_header_size(x) == 0)1180#define C_notvemptyp(x) C_mk_bool(C_header_size(x) > 0)11811182#define C_port_typep(x, n) C_mk_bool((C_block_item(x, 1) & n) == n)1183#define C_input_portp(x) C_and(C_portp(x), C_port_typep(x, 0x2))1184#define C_output_portp(x) C_and(C_portp(x), C_port_typep(x, 0x4))11851186#define C_port_openp(port, n) C_mk_bool((C_block_item(port, 8) & n) == n)1187#define C_input_port_openp(port) C_port_openp(port, 0x2)1188#define C_output_port_openp(port) C_port_openp(port, 0x4)11891190#define C_slot(x, i) C_block_item(x, C_unfix(i))1191#define C_subbyte(x, i) C_fix(((C_byte *)C_data_pointer(x))[ C_unfix(i) ] & 0xff)1192#define C_setsubbyte(x, i, n) ((((C_byte *)C_data_pointer(x))[ C_unfix(i) ] = C_unfix(n) & 0xff), C_SCHEME_UNDEFINED)11931194#define C_fixnum_times(n1, n2) (C_fix(C_unfix(n1) * C_unfix(n2)))1195#define C_u_fixnum_plus(n1, n2) (((n1) - C_FIXNUM_BIT) + (n2))1196#define C_fixnum_plus(n1, n2) (C_u_fixnum_plus(n1, n2) | C_FIXNUM_BIT)1197#define C_u_fixnum_difference(n1, n2) ((n1) - (n2) + C_FIXNUM_BIT)1198#define C_fixnum_difference(n1, n2) (C_u_fixnum_difference(n1, n2) | C_FIXNUM_BIT)1199#define C_u_fixnum_divide(n1, n2) (C_fix(C_unfix(n1) / C_unfix(n2)))1200#define C_u_fixnum_and(n1, n2) ((n1) & (n2))1201#define C_fixnum_and(n1, n2) (C_u_fixnum_and(n1, n2) | C_FIXNUM_BIT)1202#define C_u_fixnum_or(n1, n2) ((n1) | (n2))1203#define C_fixnum_or(n1, n2) C_u_fixnum_or(n1, n2)1204#define C_fixnum_xor(n1, n2) (((n1) ^ (n2)) | C_FIXNUM_BIT)1205#define C_fixnum_not(n) ((~(n)) | C_FIXNUM_BIT)1206#define C_fixnum_shift_left(n1, n2) (C_fix(((C_uword)C_unfix(n1) << (C_uword)C_unfix(n2))))1207#define C_fixnum_shift_right(n1, n2) (((n1) >> (C_uword)C_unfix(n2)) | C_FIXNUM_BIT)1208#define C_u_fixnum_negate(n) (-(n) + 2 * C_FIXNUM_BIT)1209#define C_fixnum_negate(n) (C_u_fixnum_negate(n) | C_FIXNUM_BIT)1210#define C_fixnum_greaterp(n1, n2) (C_mk_bool((C_word)(n1) > (C_word)(n2)))1211#define C_fixnum_lessp(n1, n2) (C_mk_bool((C_word)(n1) < (C_word)(n2)))1212#define C_fixnum_greater_or_equal_p(n1, n2) (C_mk_bool((C_word)(n1) >= (C_word)(n2)))1213#define C_fixnum_less_or_equal_p(n1, n2)(C_mk_bool((C_word)(n1) <= (C_word)(n2)))1214#define C_u_fixnum_increase(n) ((n) + (1 << C_FIXNUM_SHIFT))1215#define C_fixnum_increase(n) (C_u_fixnum_increase(n) | C_FIXNUM_BIT)1216#define C_u_fixnum_decrease(n) ((n) - (1 << C_FIXNUM_SHIFT))1217#define C_fixnum_decrease(n) (C_u_fixnum_decrease(n) | C_FIXNUM_BIT)1218/* XXX TODO: This should probably be renamed C_u_fixnum_abs or something */1219#define C_fixnum_abs(n) C_fix(abs(C_unfix(n)))1220#define C_a_i_fixnum_abs(ptr, n, x) (((x) & C_INT_SIGN_BIT) ? C_a_i_fixnum_negate((ptr), (n), (x)) : (x))1221#define C_i_fixnum_signum(x) ((x) == C_fix(0) ? (x) : (((x) & C_INT_SIGN_BIT) ? C_fix(-1) : C_fix(1)))1222#define C_i_fixnum_length(x) C_fix(C_ilen(((x) & C_INT_SIGN_BIT) ? ~C_unfix(x) : C_unfix(x)))12231224#define C_flonum_equalp(n1, n2) C_mk_bool(C_flonum_magnitude(n1) == C_flonum_magnitude(n2))1225#define C_flonum_greaterp(n1, n2) C_mk_bool(C_flonum_magnitude(n1) > C_flonum_magnitude(n2))1226#define C_flonum_lessp(n1, n2) C_mk_bool(C_flonum_magnitude(n1) < C_flonum_magnitude(n2))1227#define C_flonum_greater_or_equal_p(n1, n2) C_mk_bool(C_flonum_magnitude(n1) >= C_flonum_magnitude(n2))1228#define C_flonum_less_or_equal_p(n1, n2) C_mk_bool(C_flonum_magnitude(n1) <= C_flonum_magnitude(n2))12291230#define C_a_i_flonum_plus(ptr, c, n1, n2) C_flonum(ptr, C_flonum_magnitude(n1) + C_flonum_magnitude(n2))1231#define C_a_i_flonum_difference(ptr, c, n1, n2) C_flonum(ptr, C_flonum_magnitude(n1) - C_flonum_magnitude(n2))1232#define C_a_i_flonum_times(ptr, c, n1, n2) C_flonum(ptr, C_flonum_magnitude(n1) * C_flonum_magnitude(n2))1233#define C_a_i_flonum_multiply_add(ptr, c, n1, n2, n3) C_flonum(ptr, fma(C_flonum_magnitude(n1), C_flonum_magnitude(n2), C_flonum_magnitude(n3)))1234#define C_a_i_flonum_quotient(ptr, c, n1, n2) C_flonum(ptr, C_flonum_magnitude(n1) / C_flonum_magnitude(n2))1235#define C_a_i_flonum_negate(ptr, c, n) C_flonum(ptr, -C_flonum_magnitude(n))1236#define C_a_u_i_flonum_signum(ptr, n, x) (C_flonum_magnitude(x) == 0.0 ? (x) : ((C_flonum_magnitude(x) < 0.0) ? C_flonum(ptr, -1.0) : C_flonum(ptr, 1.0)))12371238#define C_a_i_address_to_pointer(ptr, c, addr) C_mpointer(ptr, (void *)C_num_to_unsigned_int(addr))1239#define C_a_i_pointer_to_address(ptr, c, pptr) C_unsigned_int_to_num(ptr, (unsigned int)C_c_pointer_nn(pptr))12401241#define C_display_fixnum(p, n) (C_fprintf(C_port_file(p), C_text("%d"), C_unfix(n)), C_SCHEME_UNDEFINED)1242#define C_display_char(p, c) (C_utf_putc(C_character_code(c), C_port_file(p)), C_SCHEME_UNDEFINED)1243#define C_display_string(p, s, start, len) \1244 (C_fwrite(C_c_string(s) + C_unfix(start), sizeof(C_char), C_unfix(len), C_port_file(p)), C_SCHEME_UNDEFINED)1245#define C_flush_output(port) (C_fflush(C_port_file(port)), C_SCHEME_UNDEFINED)12461247#define C_fix_to_char(x) (C_make_character(C_unfix(x)))1248#define C_char_to_fix(x) (C_fix(C_character_code(x)))1249#define C_u_i_char_equalp(x, y) C_mk_bool(C_character_code(x) == C_character_code(y))1250#define C_u_i_char_greaterp(x, y) C_mk_bool(C_character_code(x) > C_character_code(y))1251#define C_u_i_char_lessp(x, y) C_mk_bool(C_character_code(x) < C_character_code(y))1252#define C_u_i_char_greater_or_equal_p(x, y) C_mk_bool(C_character_code(x) >= C_character_code(y))1253#define C_u_i_char_less_or_equal_p(x, y) C_mk_bool(C_character_code(x) <= C_character_code(y))12541255#define C_bv_compare(x, y, n) C_mk_bool(C_memcmp(C_data_pointer(x), C_data_pointer(y), C_unfix(n)) == 0)1256#define C_u_i_string_equal_p(x, y) C_utf_equal(x, y)1257#define C_u_i_string_ci_equal_p(x, y) C_utf_equal_ci(x, y)12581259#define C_u_i_substring_equal_p(x, y, s1, s2, len) \1260 C_mk_bool(C_utf_compare(x, y, s1, s2, len) == C_fix(0))1261#define C_u_i_substring_ci_equal_p(x, y, s1, s2, len) \1262 C_mk_bool(C_utf_compare_ci(x, y, s1, s2, len) == C_fix(0))12631264/* this does not use C_mutate: */1265#define C_copy_bytevector(b1, b2, len) (C_memcpy(C_data_pointer(b2), C_data_pointer(b1), C_unfix(len)), (b2))1266#define C_fill_bytevector(bv, code, start, len) \1267 (C_memset(C_data_pointer(bv) + C_unfix(start), C_unfix(code), C_unfix(len)), \1268 C_SCHEME_UNDEFINED)1269#define C_subvector_copy(v1, v2, start1, end1, start2) \1270 (C_memcpy_slots((C_char *)C_data_pointer(v2) + C_unfix(start2), \1271 (C_char *)C_data_pointer(v1) + C_unfix(start1), \1272 C_unfix(end1) - C_unfix(start1) ), C_SCHEME_UNDEFINED)1273#define C_words(n) C_fix(C_bytestowords(C_unfix(n)))1274#define C_bytes(n) C_fix(C_wordstobytes(C_unfix(n)))1275#define C_rand(n) C_fix((C_word)(((double)C_fast_rand())/(32767 + 1.0) * C_unfix(n)))1276#define C_block_size(x) C_fix(C_header_size(x))1277#define C_u_i_bignum_size(b) C_fix(C_bignum_size(b))1278#define C_a_u_i_big_to_flo(p, n, b) C_flonum(p, C_bignum_to_double(b))1279#define C_u_i_ratnum_num(r) C_block_item((r), 0)1280#define C_u_i_ratnum_denom(r) C_block_item((r), 1)1281#define C_u_i_cplxnum_real(c) C_block_item((c), 0)1282#define C_u_i_cplxnum_imag(c) C_block_item((c), 1)1283#define C_pointer_address(x) ((C_byte *)C_block_item((x), 0))1284#define C_block_address(ptr, n, x) C_a_unsigned_int_to_num(ptr, n, x)1285#define C_offset_pointer(x, y) (C_pointer_address(x) + (y))1286#define C_do_apply(c, av) ((C_proc)(void *)C_block_item((av)[0], 0))((c), (av))1287#define C_kontinue(k, r) do { C_word avk[ 2 ]; avk[ 0 ] = (k); avk[ 1 ] = (r); ((C_proc)(void *)C_block_item((k),0))(2, avk); } while(0)1288#define C_get_rest_arg(c, n, av, ka, cl)((n) >= (c) ? (C_rest_arg_out_of_bounds_error_2(C_fix(c), C_fix(n), C_fix(ka), (cl)), C_SCHEME_UNDEFINED) : (av)[(n)])1289#define C_rest_arg_out_of_bounds_error_value(c, n, ka) (C_rest_arg_out_of_bounds_error((c),(n),(ka)), C_SCHEME_UNDEFINED)1290#define C_rest_nullp(c, n) (C_mk_bool((n) >= (c)))1291#define C_fetch_byte(x, p) (((unsigned C_byte *)C_data_pointer(x))[ p ])1292#define C_poke_integer(x, i, n) (C_set_block_item(x, C_unfix(i), C_num_to_int(n)), C_SCHEME_UNDEFINED)1293#define C_pointer_to_block(p, x) (C_set_block_item(p, 0, (C_word)C_data_pointer(x)), C_SCHEME_UNDEFINED)1294#define C_null_pointerp(x) C_mk_bool((void *)C_block_item(x, 0) == NULL)1295#define C_update_pointer(p, ptr) (C_set_block_item(ptr, 0, C_num_to_unsigned_int(p)), C_SCHEME_UNDEFINED)1296#define C_copy_pointer(from, to) (C_set_block_item(to, 0, C_block_item(from, 0)), C_SCHEME_UNDEFINED)1297#define C_pointer_to_object(ptr) C_block_item(ptr, 0)12981299#ifdef C_SIXTY_FOUR1300# define C_poke_integer_32(x, i, n) (((C_s32 *)C_data_pointer(x))[ C_unfix(i) ] = C_unfix(n), C_SCHEME_UNDEFINED)1301#else1302# define C_poke_integer_32 C_poke_integer1303#endif13041305#define C_copy_memory(to, from, n) (C_memmove(C_data_pointer(to), C_data_pointer(from), C_unfix(n)), C_SCHEME_UNDEFINED)1306#define C_copy_memory_with_offset(to, from, start1, start2, n) \1307 (C_memmove(C_data_pointer(to) + C_unfix(start1), C_data_pointer(from) + C_unfix(start2), C_unfix(n)), C_SCHEME_UNDEFINED)1308#define C_copy_ptr_memory(to, from, n, toff, foff) \1309 (C_memmove(C_pointer_address(to) + C_unfix(toff), C_pointer_address(from) + C_unfix(foff), \1310 C_unfix(n)), C_SCHEME_UNDEFINED)1311#define C_poke_double(b, i, n) (((double *)C_data_pointer(b))[ C_unfix(i) ] = C_c_double(n), C_SCHEME_UNDEFINED)1312#define C_poke_c_string(b, i, from, s) (C_strlcpy((char *)C_block_item(b, C_unfix(i)), C_data_pointer(from), s), C_SCHEME_UNDEFINED)1313#define C_peek_fixnum(b, i) C_fix(C_block_item(b, C_unfix(i)))1314#define C_peek_byte(ptr, i) C_fix(((unsigned char *)C_u_i_car(ptr))[ C_unfix(i) ])1315#define C_dupstr(s) C_strdup(C_data_pointer(s))1316#define C_poke_pointer(b, i, x) (C_set_block_item(b, C_unfix(i), (C_word)C_data_pointer(x)), C_SCHEME_UNDEFINED)1317#define C_poke_pointer_or_null(b, i, x) (C_set_block_item(b, C_unfix(i), (C_word)C_data_pointer_or_null(x)), C_SCHEME_UNDEFINED)1318#define C_qfree(ptr) (C_free(C_c_pointer_nn(ptr)), C_SCHEME_UNDEFINED)13191320#define C_tty_portp(p) C_mk_bool(isatty(fileno(C_port_file(p))))13211322#define C_emit_trace_info(l, x, y, z) C_emit_trace_info2(NULL, l, x, y, z)1323#define C_emit_eval_trace_info(x, y, z) C_emit_trace_info2(C_text("<eval>"), C_SCHEME_FALSE, x, y, z)1324#define C_emit_syntax_trace_info(x, y, z) C_emit_trace_info2(C_text("<syntax>"), C_SCHEME_FALSE, x, y, z)13251326/* These expect C_VECTOR_TYPE to be 0: */1327#define C_vector_to_structure(v) (C_block_header(v) |= C_STRUCTURE_TYPE, C_SCHEME_UNDEFINED)1328#define C_vector_to_closure(v) (C_block_header(v) |= C_CLOSURE_TYPE, C_SCHEME_UNDEFINED)1329#define C_bytevector_to_lambdainfo(s) (C_block_header(s) = C_header_size(s) | C_LAMBDA_INFO_TYPE, C_SCHEME_UNDEFINED)13301331#ifdef C_TIMER_INTERRUPTS1332# define C_check_for_interrupt if(--C_timer_interrupt_counter <= 0) C_raise_interrupt(C_TIMER_INTERRUPT_NUMBER)1333#else1334# define C_check_for_interrupt1335#endif13361337#define C_set_initial_timer_interrupt_period(n) \1338 (C_initial_timer_interrupt_period = C_unfix(n), C_SCHEME_UNDEFINED)133913401341#ifdef HAVE_STATEMENT_EXPRESSIONS1342# define C_a_i(a, n) ({C_word *tmp = *a; *a += (n); tmp;})1343# define C_a_i_cons(a, n, car, cdr) ({C_word tmp = (C_word)(*a); (*a)[0] = C_PAIR_TAG; *a += C_SIZEOF_PAIR; \1344 C_set_block_item(tmp, 0, car); C_set_block_item(tmp, 1, cdr); tmp;})1345# define C_a_i_weak_cons(a, n, car, cdr) ({C_word tmp = (C_word)(*a); (*a)[0] = C_WEAK_PAIR_TAG; *a += C_SIZEOF_PAIR; \1346 C_set_block_item(tmp, 0, car); C_set_block_item(tmp, 1, cdr); tmp;})1347#else1348# define C_a_i_cons(a, n, car, cdr) C_a_pair(a, car, cdr)1349# define C_a_i_weak_cons(a, n, car, cdr) C_a_weak_pair(a, car, cdr)1350#endif /* HAVE_STATEMENT_EXPRESSIONS */13511352#define C_a_i_flonum(ptr, c, n) C_flonum(ptr, n)1353#define C_a_i_ratnum(ptr, c, n, d) C_ratnum(ptr, n, d)1354#define C_a_i_cplxnum(ptr, c, r, i) C_cplxnum(ptr, r, i)1355#define C_a_i_data_mpointer(ptr, n, x) C_mpointer(ptr, C_data_pointer(x))1356#define C_a_i_fix_to_flo(p, n, f) C_flonum(p, C_unfix(f))1357#define C_cast_to_flonum(n) ((double)(n))1358#define C_a_i_mpointer(ptr, n, x) C_mpointer(ptr, (x))1359#define C_a_u_i_pointer_inc(ptr, n, p, i) C_mpointer(ptr, (C_char *)(p) + C_unfix(i))1360#define C_pointer_eqp(x, y) C_mk_bool(C_c_pointer_nn(x) == C_c_pointer_nn(y))1361#define C_a_int_to_num(ptr, n, i) C_int_to_num(ptr, i)1362#define C_a_unsigned_int_to_num(ptr, n, i) C_unsigned_int_to_num(ptr, i)1363#define C_a_i_vector C_vector1364#define C_list C_a_i_list1365#define C_i_setslot(x, i, y) (C_mutate(&C_block_item(x, C_unfix(i)), y), C_SCHEME_UNDEFINED)1366#define C_i_set_i_slot(x, i, y) (C_set_block_item(x, C_unfix(i), y), C_SCHEME_UNDEFINED)1367#define C_u_i_set_car(p, x) (C_mutate(&C_u_i_car(p), x), C_SCHEME_UNDEFINED)1368#define C_u_i_set_cdr(p, x) (C_mutate(&C_u_i_cdr(p), x), C_SCHEME_UNDEFINED)1369#define C_a_i_putprop(p, c, x, y, z) C_putprop(p, x, y, z)13701371#define C_i_not(x) (C_truep(x) ? C_SCHEME_FALSE : C_SCHEME_TRUE)1372#define C_i_equalp(x, y) C_mk_bool(C_equalp((x), (y)))1373#define C_i_fixnumevenp(x) C_mk_nbool((x) & 0x00000002)1374#define C_i_fixnumoddp(x) C_mk_bool((x) & 0x00000002)1375#define C_i_fixnum_negativep(x) C_mk_bool((x) & C_INT_SIGN_BIT)1376#define C_i_fixnum_positivep(x) C_mk_bool(!((x) & C_INT_SIGN_BIT) && (x) != C_fix(0))1377#define C_i_nullp(x) C_mk_bool((x) == C_SCHEME_END_OF_LIST)1378#define C_i_structurep(x, s) C_mk_bool(!C_immediatep(x) && C_header_bits(x) == C_STRUCTURE_TYPE && C_block_item(x, 0) == (s))13791380#define C_u_i_char_alphabeticp(x) C_mk_bool(C_utf_isalpha(C_character_code(x)))1381#define C_u_i_char_numericp(x) C_mk_bool(C_utf_isdigit(C_character_code(x)))1382#define C_u_i_char_whitespacep(x) C_mk_bool(C_utf_isspace(C_character_code(x)))1383#define C_u_i_char_upper_casep(x) C_mk_bool(C_utf_isupper(C_character_code(x)))1384#define C_u_i_char_lower_casep(x) C_mk_bool(C_utf_islower(C_character_code(x)))1385#define C_u_i_digit_value(x) C_fix(C_utf_isdigit(C_character_code(x)))13861387#define C_u_i_char_upcase(x) C_make_character(C_utf_char_upcase(C_character_code(x)))1388#define C_u_i_char_downcase(x) C_make_character(C_utf_char_downcase(C_character_code(x)))1389#define C_utf_length(bv) C_fix(C_utf_count((C_char *)C_data_pointer(bv), C_header_size(bv) - 1))1390#define C_utf_range_length(bv, from, to) C_fix(C_utf_count((C_char *)C_data_pointer(bv) + C_unfix(from), C_unfix(to) - C_unfix(from)))1391#define C_utf_bytes_needed(b) C_fix(C_utf_expect(C_unfix(b)))13921393#define C_i_list_ref(lst, i) C_i_car(C_i_list_tail(lst, i))1394#define C_u_i_list_ref(lst, i) C_u_i_car(C_i_list_tail(lst, i))13951396#define C_u_i_car(x) (*C_CHECKp(x,C_pairp(C_VAL1(x)),&C_block_item(C_VAL1(x), 0)))1397#define C_u_i_cdr(x) (*C_CHECKp(x,C_pairp(C_VAL1(x)),&C_block_item(C_VAL1(x), 1)))1398#define C_u_i_caar(x) C_u_i_car( C_u_i_car( x ) )1399#define C_u_i_cadr(x) C_u_i_car( C_u_i_cdr( x ) )1400#define C_u_i_cdar(x) C_u_i_cdr( C_u_i_car( x ) )1401#define C_u_i_cddr(x) C_u_i_cdr( C_u_i_cdr( x ) )1402#define C_u_i_caaar(x) C_u_i_car( C_u_i_caar( x ) )1403#define C_u_i_caadr(x) C_u_i_car( C_u_i_cadr( x ) )1404#define C_u_i_cadar(x) C_u_i_car( C_u_i_cdar( x ) )1405#define C_u_i_caddr(x) C_u_i_car( C_u_i_cddr( x ) )1406#define C_u_i_cdaar(x) C_u_i_cdr( C_u_i_caar( x ) )1407#define C_u_i_cdadr(x) C_u_i_cdr( C_u_i_cadr( x ) )1408#define C_u_i_cddar(x) C_u_i_cdr( C_u_i_cdar( x ) )1409#define C_u_i_cdddr(x) C_u_i_cdr( C_u_i_cddr( x ) )1410#define C_u_i_caaaar(x) C_u_i_car( C_u_i_caaar( x ) )1411#define C_u_i_caaadr(x) C_u_i_car( C_u_i_caadr( x ) )1412#define C_u_i_caadar(x) C_u_i_car( C_u_i_cadar( x ) )1413#define C_u_i_caaddr(x) C_u_i_car( C_u_i_caddr( x ) )1414#define C_u_i_cadaar(x) C_u_i_car( C_u_i_cdaar( x ) )1415#define C_u_i_cadadr(x) C_u_i_car( C_u_i_cdadr( x ) )1416#define C_u_i_caddar(x) C_u_i_car( C_u_i_cddar( x ) )1417#define C_u_i_cadddr(x) C_u_i_car( C_u_i_cdddr( x ) )1418#define C_u_i_cdaaar(x) C_u_i_cdr( C_u_i_caaar( x ) )1419#define C_u_i_cdaadr(x) C_u_i_cdr( C_u_i_caadr( x ) )1420#define C_u_i_cdadar(x) C_u_i_cdr( C_u_i_cadar( x ) )1421#define C_u_i_cdaddr(x) C_u_i_cdr( C_u_i_caddr( x ) )1422#define C_u_i_cddaar(x) C_u_i_cdr( C_u_i_cdaar( x ) )1423#define C_u_i_cddadr(x) C_u_i_cdr( C_u_i_cdadr( x ) )1424#define C_u_i_cdddar(x) C_u_i_cdr( C_u_i_cddar( x ) )1425#define C_u_i_cddddr(x) C_u_i_cdr( C_u_i_cdddr( x ) )14261427#ifdef HAVE_STATEMENT_EXPRESSIONS1428# define C_i_not_pair_p(x) ({C_word tmp = (x); C_mk_bool(C_immediatep(tmp) || C_header_type(tmp) != C_PAIR_TYPE);})1429#else1430# define C_i_not_pair_p C_i_not_pair_p_21431#endif14321433#define C_i_check_closure(x) C_i_check_closure_2(x, C_SCHEME_FALSE)1434#define C_i_check_exact(x) C_i_check_exact_2(x, C_SCHEME_FALSE) /* DEPRECATED */1435#define C_i_check_fixnum(x) C_i_check_fixnum_2(x, C_SCHEME_FALSE)1436#define C_i_check_inexact(x) C_i_check_inexact_2(x, C_SCHEME_FALSE)1437#define C_i_check_number(x) C_i_check_number_2(x, C_SCHEME_FALSE)1438#define C_i_check_string(x) C_i_check_string_2(x, C_SCHEME_FALSE)1439#define C_i_check_bytevector(x) C_i_check_bytevector_2(x, C_SCHEME_FALSE)1440#define C_i_check_keyword(x) C_i_check_keyword_2(x, C_SCHEME_FALSE)1441#define C_i_check_symbol(x) C_i_check_symbol_2(x, C_SCHEME_FALSE)1442#define C_i_check_list(x) C_i_check_list_2(x, C_SCHEME_FALSE)1443#define C_i_check_pair(x) C_i_check_pair_2(x, C_SCHEME_FALSE)1444#define C_i_check_locative(x) C_i_check_locative_2(x, C_SCHEME_FALSE)1445#define C_i_check_boolean(x) C_i_check_boolean_2(x, C_SCHEME_FALSE)1446#define C_i_check_vector(x) C_i_check_vector_2(x, C_SCHEME_FALSE)1447#define C_i_check_structure(x, st) C_i_check_structure_2(x, (st), C_SCHEME_FALSE)1448#define C_i_check_char(x) C_i_check_char_2(x, C_SCHEME_FALSE)1449#define C_i_check_port(x, in, op) C_i_check_port_2(x, in, op, C_SCHEME_FALSE)1450#define C_i_check_range(i, f, t) C_i_check_range_2(i, f, t, C_SCHEME_FALSE)1451#define C_i_check_range_including(i, f, t) C_i_check_range_including_2(i, f, t, C_SCHEME_FALSE)14521453#define C_u_i_string_length(x) C_block_item((x), 1)1454#define C_u_i_bytevector_length(x) C_block_size(x)14551456#define C_u_i_8vector_length C_u_i_bytevector_length1457#define C_u_i_16vector_length(x) C_fix(C_header_size(C_block_item(x, 1)) >> 1)1458#define C_u_i_32vector_length(x) C_fix(C_header_size(C_block_item(x, 1)) >> 2)1459#define C_u_i_64vector_length(x) C_fix(C_header_size(C_block_item(x, 1)) >> 3)1460#define C_u_i_u8vector_length C_u_i_8vector_length1461#define C_u_i_s8vector_length(x) C_fix(C_header_size(C_block_item(x, 1)))1462#define C_u_i_u16vector_length C_u_i_16vector_length1463#define C_u_i_s16vector_length C_u_i_16vector_length1464#define C_u_i_u32vector_length C_u_i_32vector_length1465#define C_u_i_s32vector_length C_u_i_32vector_length1466#define C_u_i_u64vector_length C_u_i_64vector_length1467#define C_u_i_s64vector_length C_u_i_64vector_length1468#define C_u_i_f32vector_length C_u_i_32vector_length1469#define C_u_i_f64vector_length C_u_i_64vector_length14701471#define C_u_i_bytevector_ref(x, i) C_fix(((unsigned char *)C_data_pointer(x))[ C_unfix(i) ])1472#define C_u_i_u8vector_ref C_u_i_bytevector_ref1473#define C_u_i_s8vector_ref(x, i) C_fix(((signed char *)C_data_pointer(C_block_item((x), 1)))[ C_unfix(i) ])1474#define C_u_i_u16vector_ref(x, i) C_fix(((unsigned short *)C_data_pointer(C_block_item((x), 1)))[ C_unfix(i) ])1475#define C_u_i_s16vector_ref(x, i) C_fix(((short *)C_data_pointer(C_block_item((x), 1)))[ C_unfix(i) ])14761477/* these assume fixnum mode */1478#define C_u_i_u32vector_ref(x, i) C_fix(((C_u32 *)C_data_pointer(C_block_item((x), 1)))[ C_unfix(i) ])1479#define C_u_i_s32vector_ref(x, i) C_fix(((C_s32 *)C_data_pointer(C_block_item((x), 1)))[ C_unfix(i) ])14801481#define C_a_u_i_u32vector_ref(ptr, c, x, i) C_unsigned_int_to_num(ptr, ((C_u32 *)C_data_pointer(C_block_item((x), 1)))[ C_unfix(i) ])1482#define C_a_u_i_s32vector_ref(ptr, c, x, i) C_int_to_num(ptr, ((C_s32 *)C_data_pointer(C_block_item((x), 1)))[ C_unfix(i) ])14831484#define C_a_u_i_u64vector_ref(ptr, c, x, i) C_uint64_to_num(ptr, ((C_u64 *)C_data_pointer(C_block_item((x), 1)))[ C_unfix(i) ])1485#define C_a_u_i_s64vector_ref(ptr, c, x, i) C_int64_to_num(ptr, ((C_s64 *)C_data_pointer(C_block_item((x), 1)))[ C_unfix(i) ])14861487#define C_u_i_bytevector_set(x, i, v) ((((unsigned char *)C_data_pointer(x))[ C_unfix(i) ] = C_unfix(v)), C_SCHEME_UNDEFINED)1488#define C_u_i_u8vector_set C_u_i_bytevector_set1489#define C_i_u8vector_set C_i_bytevector_set1490#define C_u_i_s8vector_set(x, i, v) ((((signed char *)C_data_pointer(C_block_item((x), 1)))[ C_unfix(i) ] = C_unfix(v)), C_SCHEME_UNDEFINED)1491#define C_u_i_u16vector_set(x, i, v) ((((unsigned short *)C_data_pointer(C_block_item((x), 1)))[ C_unfix(i) ] = C_unfix(v)), C_SCHEME_UNDEFINED)1492#define C_u_i_s16vector_set(x, i, v) ((((short *)C_data_pointer(C_block_item((x), 1)))[ C_unfix(i) ] = C_unfix(v)), C_SCHEME_UNDEFINED)1493#define C_u_i_u32vector_set(x, i, v) ((((C_u32 *)C_data_pointer(C_block_item((x), 1)))[ C_unfix(i) ] = C_num_to_unsigned_int(v)), C_SCHEME_UNDEFINED)1494#define C_u_i_s32vector_set(x, i, v) ((((C_s32 *)C_data_pointer(C_block_item((x), 1)))[ C_unfix(i) ] = C_num_to_int(v)), C_SCHEME_UNDEFINED)1495#define C_u_i_u64vector_set(x, i, v) ((((C_u64 *)C_data_pointer(C_block_item((x), 1)))[ C_unfix(i) ] = C_num_to_uint64(v)), C_SCHEME_UNDEFINED)1496#define C_u_i_s64vector_set(x, i, v) ((((C_s64 *)C_data_pointer(C_block_item((x), 1)))[ C_unfix(i) ] = C_num_to_int64(v)), C_SCHEME_UNDEFINED)14971498/* DEPRECATED */1499#define C_u_i_bit_to_bool(x, i) C_mk_bool((C_unfix(x) & (1 << C_unfix(i))) != 0)15001501#define C_u_i_pointer_u8_ref(ptr) C_fix(*((unsigned char *)C_block_item(ptr, 0)))1502#define C_u_i_pointer_s8_ref(ptr) C_fix(*((signed char *)C_block_item(ptr, 0)))1503#define C_u_i_pointer_u16_ref(ptr) C_fix(*((unsigned short *)C_block_item(ptr, 0)))1504#define C_u_i_pointer_s16_ref(ptr) C_fix(*((short *)C_block_item(ptr, 0)))1505#define C_a_u_i_pointer_u32_ref(ap, n, ptr) \1506 C_unsigned_int_to_num(ap, *((C_u32 *)C_block_item(ptr, 0)))1507#define C_a_u_i_pointer_s32_ref(ap, n, ptr) \1508 C_int_to_num(ap, *((C_s32 *)C_block_item(ptr, 0)))1509#define C_a_u_i_pointer_u64_ref(ap, n, ptr) \1510 C_uint64_to_num(ap, *((C_u64 *)C_block_item(ptr, 0)))1511#define C_a_u_i_pointer_s64_ref(ap, n, ptr) \1512 C_int64_to_num(ap, *((C_s64 *)C_block_item(ptr, 0)))1513#define C_a_u_i_pointer_f32_ref(ap, n, ptr) C_flonum(ap, *((float *)C_block_item(ptr, 0)))1514#define C_a_u_i_pointer_f64_ref(ap, n, ptr) C_flonum(ap, *((double *)C_block_item(ptr, 0)))1515#define C_u_i_pointer_u8_set(ptr, x) \1516 (*((unsigned char *)C_block_item(ptr, 0)) = C_unfix(x), C_SCHEME_UNDEFINED)1517#define C_u_i_pointer_s8_set(ptr, x) \1518 (*((signed char *)C_block_item(ptr, 0)) = C_unfix(x), C_SCHEME_UNDEFINED)1519#define C_u_i_pointer_u16_set(ptr, x) \1520 (*((unsigned short *)C_block_item(ptr, 0)) = C_unfix(x), C_SCHEME_UNDEFINED)1521#define C_u_i_pointer_s16_set(ptr, x) \1522 (*((short *)C_block_item(ptr, 0)) = C_unfix(x), C_SCHEME_UNDEFINED)1523#define C_u_i_pointer_u32_set(ptr, x) \1524 (*((C_u32 *)C_block_item(ptr, 0)) = C_num_to_unsigned_int(x), C_SCHEME_UNDEFINED)1525#define C_u_i_pointer_s32_set(ptr, x) \1526 (*((C_s32 *)C_block_item(ptr, 0)) = C_num_to_int(x), C_SCHEME_UNDEFINED)1527#define C_u_i_pointer_u64_set(ptr, x) \1528 (*((C_u64 *)C_block_item(ptr, 0)) = C_num_to_uint64(x), C_SCHEME_UNDEFINED)1529#define C_u_i_pointer_s64_set(ptr, x) \1530 (*((C_s64 *)C_block_item(ptr, 0)) = C_num_to_int64(x), C_SCHEME_UNDEFINED)1531#define C_u_i_pointer_f32_set(ptr, x) \1532 (*((float *)C_block_item(ptr, 0)) = C_flonum_magnitude(x), C_SCHEME_UNDEFINED)1533#define C_u_i_pointer_f64_set(ptr, x) \1534 (*((double *)C_block_item(ptr, 0)) = C_flonum_magnitude(x), C_SCHEME_UNDEFINED)15351536#ifdef C_BIG_ENDIAN1537# ifdef C_SIXTY_FOUR1538# define C_lihdr(x, y, z) ((C_LAMBDA_INFO_TYPE >> 56) & 0xff), \1539 0, 0, 0, 0, (x), (y), ((C_char)(z))1540# else1541# define C_lihdr(x, y, z) ((C_LAMBDA_INFO_TYPE >> 24) & 0xff), \1542 (x), (y), ((C_char)(z))1543# endif1544#else1545# ifdef C_SIXTY_FOUR1546# define C_lihdr(x, y, z) ((C_char)(z)), (y), (x), 0, 0, 0, 0, \1547 ((C_LAMBDA_INFO_TYPE >> 56) & 0xff)1548# else1549# define C_lihdr(x, y, z) ((C_char)(z)), (y), (x), \1550 ((C_LAMBDA_INFO_TYPE >> 24) & 0xff)1551# endif1552#endif15531554#define C_ub_i_flonum_plus(x, y) ((x) + (y))1555#define C_ub_i_flonum_difference(x, y) ((x) - (y))1556#define C_ub_i_flonum_times(x, y) ((x) * (y))1557#define C_ub_i_flonum_quotient(x, y) ((x) / (y))1558#define C_ub_i_flonum_multiply_add(x, y, z) C_fma((x), (y), (z))15591560#define C_ub_i_flonum_equalp(n1, n2) C_mk_bool((n1) == (n2))1561#define C_ub_i_flonum_greaterp(n1, n2) C_mk_bool((n1) > (n2))1562#define C_ub_i_flonum_lessp(n1, n2) C_mk_bool((n1) < (n2))1563#define C_ub_i_flonum_greater_or_equal_p(n1, n2) C_mk_bool((n1) >= (n2))1564#define C_ub_i_flonum_less_or_equal_p(n1, n2) C_mk_bool((n1) <= (n2))15651566#define C_ub_i_flonum_nanp(x) C_mk_bool(C_isnan(x))1567#define C_ub_i_flonum_infinitep(x) C_mk_bool(C_isinf(x))1568#define C_ub_i_flonum_finitep(x) C_mk_bool(C_isfinite(x))15691570#define C_ub_i_pointer_inc(p, n) ((void *)((unsigned char *)(p) + (n)))1571#define C_ub_i_pointer_eqp(p1, p2) C_mk_bool((p1) == (p2))1572#define C_ub_i_null_pointerp(p) C_mk_bool((p) == NULL)15731574#define C_ub_i_pointer_u8_ref(p) (*((unsigned char *)(p)))1575#define C_ub_i_pointer_s8_ref(p) (*((signed char *)(p)))1576#define C_ub_i_pointer_u16_ref(p) (*((unsigned short *)(p)))1577#define C_ub_i_pointer_s16_ref(p) (*((short *)(p)))1578#define C_ub_i_pointer_u32_ref(p) (*((C_u32 *)(p)))1579#define C_ub_i_pointer_s32_ref(p) (*((C_s32 *)(p)))1580#define C_ub_i_pointer_u64_ref(p) (*((C_u64 *)(p)))1581#define C_ub_i_pointer_s64_ref(p) (*((C_s64 *)(p)))1582#define C_ub_i_pointer_f32_ref(p) (*((float *)(p)))1583#define C_ub_i_pointer_f64_ref(p) (*((double *)(p)))1584#define C_ub_i_pointer_u8_set(p, n) (*((unsigned char *)(p)) = (n))1585#define C_ub_i_pointer_s8_set(p, n) (*((signed char *)(p)) = (n))1586#define C_ub_i_pointer_u16_set(p, n) (*((unsigned short *)(p)) = (n))1587#define C_ub_i_pointer_s16_set(p, n) (*((short *)(p)) = (n))1588#define C_ub_i_pointer_u32_set(p, n) (*((C_u32 *)(p)) = (n))1589#define C_ub_i_pointer_s32_set(p, n) (*((C_s32 *)(p)) = (n))1590#define C_ub_i_pointer_u64_set(p, n) (*((C_u64 *)(p)) = (n))1591#define C_ub_i_pointer_s64_set(p, n) (*((C_s64 *)(p)) = (n))1592#define C_ub_i_pointer_f32_set(p, n) (*((float *)(p)) = (n))1593#define C_ub_i_pointer_f64_set(p, n) (*((double *)(p)) = (n))15941595#ifdef C_PRIVATE_REPOSITORY1596# define C_private_repository() C_use_private_repository(C_executable_dirname())1597#else1598# define C_private_repository()1599#endif16001601#ifdef C_GUI1602# define C_set_gui_mode C_gui_mode = 11603#else1604# define C_set_gui_mode1605#endif16061607/**1608 * SEARCH_EXE_PATH is defined on platforms on which we must search for1609 * the current executable. Because this search is sensitive to things1610 * like CWD, PATH, and so on, it's done once at startup and saved in1611 * `C_main_exe`.1612 *1613 * On platforms where it's not defined, there's a simple way to1614 * retrieve a path to the current executable (such as reading1615 * "/proc/<pid>/exe" or some similar trick).1616 */1617#ifdef SEARCH_EXE_PATH1618# define C_set_main_exe(fname) C_main_exe = C_resolve_executable_pathname(fname)1619#else1620# define C_set_main_exe(fname)1621#endif16221623#if !defined(C_EMBEDDED) && !defined(C_SHARED)1624# if defined(C_GUI) && defined(_WIN32)1625# define C_main_entry_point \1626 int WINAPI WinMain(HINSTANCE me, HINSTANCE you, LPSTR cmdline, int show) \1627 { \1628 C_gui_mode = 1; \1629 C_set_main_exe(argv[0]); \1630 C_private_repository(); \1631 return CHICKEN_main(0, NULL, (void *)C_toplevel); \1632 }1633# else1634# define C_main_entry_point \1635 int main(int argc, char *argv[]) \1636 { \1637 C_set_gui_mode; \1638 C_set_main_exe(argv[0]); \1639 C_private_repository(); \1640 return CHICKEN_main(argc, argv, (void*)C_toplevel); \1641 }1642# endif1643#else1644# define C_main_entry_point1645#endif16461647#define C_alloc_flonum C_word *___tmpflonum = C_alloc(WORDS_PER_FLONUM)1648#define C_kontinue_flonum(k, n) C_kontinue((k), C_flonum(&___tmpflonum, (n)))16491650#define C_a_i_flonum_truncate(ptr, n, x) C_flonum(ptr, C_trunc(C_flonum_magnitude(x)))1651#define C_a_i_flonum_ceiling(ptr, n, x) C_flonum(ptr, C_ceil(C_flonum_magnitude(x)))1652#define C_a_i_flonum_floor(ptr, n, x) C_flonum(ptr, C_floor(C_flonum_magnitude(x)))1653#define C_a_i_flonum_round(ptr, n, x) C_flonum(ptr, C_round(C_flonum_magnitude(x)))16541655#define C_a_u_i_f32vector_ref(ptr, n, b, i) C_flonum(ptr, ((float *)C_data_pointer(C_block_item((b), 1)))[ C_unfix(i) ])1656#define C_a_u_i_f64vector_ref(ptr, n, b, i) C_flonum(ptr, ((double *)C_data_pointer(C_block_item((b), 1)))[ C_unfix(i) ])1657#define C_u_i_f32vector_set(v, i, x) ((((float *)C_data_pointer(C_block_item((v), 1)))[ C_unfix(i) ] = C_flonum_magnitude(x)), C_SCHEME_UNDEFINED)1658#define C_u_i_f64vector_set(v, i, x) ((((double *)C_data_pointer(C_block_item((v), 1)))[ C_unfix(i) ] = C_flonum_magnitude(x)), C_SCHEME_UNDEFINED)16591660#define C_ub_i_f32vector_ref(b, i) (((float *)C_data_pointer(C_block_item((b), 1)))[ C_unfix(i) ])1661#define C_ub_i_f64vector_ref(b, i) (((double *)C_data_pointer(C_block_item((b), 1)))[ C_unfix(i) ])1662#define C_ub_i_f32vector_set(v, i, x) ((((float *)C_data_pointer(C_block_item((v), 1)))[ C_unfix(i) ] = (x)), 0)1663#define C_ub_i_f64vector_set(v, i, x) ((((double *)C_data_pointer(C_block_item((v), 1)))[ C_unfix(i) ] = (x)), 0)16641665#define C_a_i_flonum_sin(ptr, c, x) C_flonum(ptr, C_sin(C_flonum_magnitude(x)))1666#define C_a_i_flonum_cos(ptr, c, x) C_flonum(ptr, C_cos(C_flonum_magnitude(x)))1667#define C_a_i_flonum_tan(ptr, c, x) C_flonum(ptr, C_tan(C_flonum_magnitude(x)))1668#define C_a_i_flonum_asin(ptr, c, x) C_flonum(ptr, C_asin(C_flonum_magnitude(x)))1669#define C_a_i_flonum_acos(ptr, c, x) C_flonum(ptr, C_acos(C_flonum_magnitude(x)))1670#define C_a_i_flonum_atan(ptr, c, x) C_flonum(ptr, C_atan(C_flonum_magnitude(x)))1671#define C_a_i_flonum_atan2(ptr, c, x, y) C_flonum(ptr, C_atan2(C_flonum_magnitude(x), C_flonum_magnitude(y)))1672#define C_a_i_flonum_sinh(ptr, c, x) C_flonum(ptr, C_sinh(C_flonum_magnitude(x)))1673#define C_a_i_flonum_cosh(ptr, c, x) C_flonum(ptr, C_cosh(C_flonum_magnitude(x)))1674#define C_a_i_flonum_tanh(ptr, c, x) C_flonum(ptr, C_tanh(C_flonum_magnitude(x)))1675#define C_a_i_flonum_asinh(ptr, c, x) C_flonum(ptr, C_asinh(C_flonum_magnitude(x)))1676#define C_a_i_flonum_acosh(ptr, c, x) C_flonum(ptr, C_acosh(C_flonum_magnitude(x)))1677#define C_a_i_flonum_atanh(ptr, c, x) C_flonum(ptr, C_atanh(C_flonum_magnitude(x)))1678#define C_a_i_flonum_exp(ptr, c, x) C_flonum(ptr, C_exp(C_flonum_magnitude(x)))1679#define C_a_i_flonum_expt(ptr, c, x, y) C_flonum(ptr, C_pow(C_flonum_magnitude(x), C_flonum_magnitude(y)))1680#define C_a_i_flonum_log(ptr, c, x) C_flonum(ptr, C_log(C_flonum_magnitude(x)))1681#define C_a_i_flonum_sqrt(ptr, c, x) C_flonum(ptr, C_sqrt(C_flonum_magnitude(x)))1682#define C_a_i_flonum_abs(ptr, c, x) C_flonum(ptr, C_fabs(C_flonum_magnitude(x)))1683#define C_u_i_flonum_nanp(x) C_mk_bool(C_isnan(C_flonum_magnitude(x)))1684#define C_u_i_flonum_infinitep(x) C_mk_bool(C_isinf(C_flonum_magnitude(x)))1685#define C_u_i_flonum_finitep(x) C_mk_bool(C_isfinite(C_flonum_magnitude(x)))16861687#define C_a_i_current_process_milliseconds(ptr, c, dummy) C_uint64_to_num(ptr, C_current_process_milliseconds())16881689#define C_i_noop1(dummy) ((dummy), C_SCHEME_UNDEFINED)1690#define C_i_noop2(dummy1, dummy2) ((dummy1), (dummy2), C_SCHEME_UNDEFINED)1691#define C_i_noop3(dummy1, dummy2, dummy3) ((dummy1), (dummy2), (dummy3), C_SCHEME_UNDEFINED)1692#define C_i_true1(dummy) ((dummy), C_SCHEME_TRUE)1693#define C_i_true2(dummy1, dummy2) ((dummy1), (dummy2), C_SCHEME_TRUE)1694#define C_i_true3(dummy1, dummy2, dummy3) ((dummy1), (dummy2), (dummy3), C_SCHEME_TRUE)16951696/* struct/union wrapping */1697#define C_a_extract_struct(a, t, x) ({t _r = (x); C_a_extract_struct_2(a, sizeof(t), &_r);})1698#define C_build_struct(t, x) ({t _a;_a = *((t *)C_data_pointer(x));_a;})16991700/* debug client interface */17011702typedef struct C_DEBUG_INFO {1703 int event;1704 int enabled;1705 C_char *loc;1706 C_char *val;1707} C_DEBUG_INFO;17081709#define C_DEBUG_CALL 11710#define C_DEBUG_GLOBAL_ASSIGN 21711#define C_DEBUG_GC 31712#define C_DEBUG_ENTRY 41713#define C_DEBUG_SIGNAL 51714#define C_DEBUG_CONNECT 61715#define C_DEBUG_LISTEN 71716#define C_DEBUG_INTERRUPTED 817171718#define C_debugger(cell, c, av) (C_debugger_hook != NULL ? C_debugger_hook(cell, c, av, C_text(__FILE__ ":" C__STR2(__LINE__))) : C_SCHEME_UNDEFINED)17191720/* Variables: */17211722C_varextern time_t C_startup_time_seconds;1723C_varextern C_word1724 *C_temporary_stack,1725 *C_temporary_stack_bottom,1726 *C_temporary_stack_limit,1727 *C_stack_limit,1728 *C_stack_hard_limit,1729 *C_scratchspace_start,1730 *C_scratchspace_top,1731 *C_scratchspace_limit,1732 C_scratch_usage;1733C_varextern C_long1734 C_timer_interrupt_counter,1735 C_initial_timer_interrupt_period;1736C_varextern C_byte1737 *C_fromspace_top,1738 *C_fromspace_limit;1739#ifdef HAVE_SIGSETJMP1740C_varextern sigjmp_buf C_restart;1741#else1742C_varextern jmp_buf C_restart;1743#endif1744C_varextern void *C_restart_address;1745C_varextern int C_entry_point_status;1746C_varextern int C_gui_mode;17471748C_varextern void *C_restart_trampoline;1749C_varextern void (*C_pre_gc_hook)(int mode);1750C_varextern void (*C_post_gc_hook)(int mode, C_long ms);1751C_varextern void (*C_panic_hook)(C_char *msg);1752C_varextern C_word (*C_debugger_hook)(C_DEBUG_INFO *cell, C_word c, C_word *av, char *cloc);17531754C_varextern int1755 C_abort_on_thread_exceptions,1756 C_interrupts_enabled,1757 C_disable_overflow_check,1758 C_heap_size_is_fixed,1759 C_max_pending_finalizers,1760 C_trace_buffer_size,1761 C_debugging,1762 C_main_argc;1763C_varextern C_uword1764 C_heap_growth,1765 C_heap_shrinkage;1766C_varextern C_char1767 **C_main_argv,1768#ifdef SEARCH_EXE_PATH1769 *C_main_exe,1770#endif1771 *C_dlerror;1772C_varextern C_uword C_maximal_heap_size;1773C_varextern int (*C_gc_mutation_hook)(C_word *slot, C_word val);1774C_varextern void (*C_gc_trace_hook)(C_word *var, int mode);1775C_varextern C_word (*C_get_unbound_variable_value_hook)(C_word sym);177617771778/* Prototypes: */17791780C_BEGIN_C_DECLS17811782C_fctexport void C_register_debug_info(C_DEBUG_INFO *);1783C_fctexport int CHICKEN_main(int argc, C_char *argv[], void *toplevel);1784C_fctexport int CHICKEN_initialize(int heap, int stack, int symbols, void *toplevel);1785C_fctexport C_word CHICKEN_run(void *toplevel);1786C_fctexport C_word CHICKEN_continue(C_word k);1787C_fctexport void *CHICKEN_new_gc_root();1788C_fctexport void *CHICKEN_new_finalizable_gc_root();1789C_fctexport void *CHICKEN_new_gc_root_2(int finalizable);1790C_fctexport void CHICKEN_delete_gc_root(void *root);1791C_fctexport void *CHICKEN_global_lookup(char *name);1792C_fctexport int CHICKEN_is_running();1793C_fctexport void CHICKEN_interrupt();17941795C_fctexport void C_check_nursery_minimum(C_word size);1796C_fctexport int C_save_callback_continuation(C_word **ptr, C_word k);1797C_fctexport C_word C_restore_callback_continuation(void);1798C_fctexport C_word C_restore_callback_continuation2(int level);1799C_fctexport C_word C_callback(C_word closure, int argc);1800C_fctexport C_word C_callback_wrapper(void *proc, int argc);1801C_fctexport void C_callback_adjust_stack(C_word *base, int size);1802C_fctexport void CHICKEN_parse_command_line(int argc, char *argv[], C_word *heap, C_word *stack, C_word *symbols);1803C_fctexport void C_toplevel_entry(C_char *name) C_regparm;1804C_fctexport C_word C_a_i_provide(C_word **a, int c, C_word id) C_regparm;1805C_fctexport C_word C_i_providedp(C_word id) C_regparm;1806C_fctexport C_word C_enable_interrupts(void) C_regparm;1807C_fctexport C_word C_disable_interrupts(void) C_regparm;1808C_fctexport void C_set_or_change_heap_size(C_word heap, int reintern);1809C_fctexport void C_do_resize_stack(C_word stack);1810C_fctexport C_word C_resize_pending_finalizers(C_word size);1811C_fctexport void C_initialize_lf(C_word *lf, int count);1812C_fctexport void *C_register_lf(C_word *lf, int count);1813C_fctexport void *C_register_lf2(C_word *lf, int count, C_PTABLE_ENTRY *ptable);1814C_fctexport void C_unregister_lf(void *handle);1815C_fctexport C_char *C_dump_trace(int start);1816C_fctexport void C_clear_trace_buffer(void) C_regparm;1817C_fctexport C_word C_resize_trace_buffer(C_word size);1818C_fctexport C_word C_fetch_trace(C_word start, C_word buffer);1819C_fctexport C_word C_string(C_word **ptr, int len, C_char *str) C_regparm;1820C_fctexport C_word C_static_string(C_word **ptr, int len, C_char *str) C_regparm;1821C_fctexport C_word C_static_bignum(C_word **ptr, int len, C_char *str) C_regparm;1822C_fctexport C_word C_static_bytevector(C_word **ptr, int len, C_char *str) C_regparm;1823C_fctexport C_word C_static_lambda_info(C_word **ptr, int len, C_char *str) C_regparm;1824C_fctexport C_word C_bytevector(C_word **ptr, int len, C_char *str) C_regparm;1825C_fctexport C_word C_pbytevector(int len, C_char *str) C_regparm;1826C_fctexport C_word C_string2(C_word **ptr, C_char *str) C_regparm;1827C_fctexport C_word C_string2_safe(C_word **ptr, int max, C_char *str) C_regparm;1828C_fctexport C_word C_intern(C_word **ptr, int len, C_char *str) C_regparm;1829C_fctexport C_word C_intern_kw(C_word **ptr, int len, C_char *str) C_regparm;1830C_fctexport C_word C_intern_in(C_word **ptr, int len, C_char *str, C_SYMBOL_TABLE *stable) C_regparm;1831C_fctexport C_word C_h_intern(C_word *slot, int len, C_char *str) C_regparm;1832C_fctexport C_word C_h_intern_kw(C_word *slot, int len, C_char *str) C_regparm;1833C_fctexport C_word C_h_intern_in(C_word *slot, int len, C_char *str, C_SYMBOL_TABLE *stable) C_regparm;1834C_fctexport C_word C_intern2(C_word **ptr, C_char *str) C_regparm;1835C_fctexport C_word C_intern3(C_word **ptr, C_char *str, C_word value) C_regparm;1836C_fctexport C_word C_build_rest(C_word **ptr, C_word c, C_word n, C_word *av) C_regparm;1837C_fctexport void C_bad_memory(void) C_noret;1838C_fctexport void C_bad_memory_2(void) C_noret;1839C_fctexport void C_bad_argc(int c, int n) C_noret;1840C_fctexport void C_bad_min_argc(int c, int n) C_noret;1841C_fctexport void C_bad_argc_2(int c, int n, C_word closure) C_noret;1842C_fctexport void C_bad_min_argc_2(int c, int n, C_word closure) C_noret;1843C_fctexport void C_stack_overflow(C_char *loc) C_noret;1844C_fctexport void C_unbound_error(C_word sym) C_noret;1845C_fctexport void C_no_closure_error(C_word x) C_noret;1846C_fctexport void C_div_by_zero_error(C_char *loc) C_noret;1847C_fctexport void C_unimplemented(C_char *msg) C_noret;1848C_fctexport void C_not_an_integer_error(C_char *loc, C_word x) C_noret;1849C_fctexport void C_not_an_uinteger_error(C_char *loc, C_word x) C_noret;1850C_fctexport void C_rest_arg_out_of_bounds_error(C_word c, C_word n, C_word ka) C_noret;1851C_fctexport void C_rest_arg_out_of_bounds_error_2(C_word c, C_word n, C_word ka, C_word closure) C_noret;1852C_fctexport C_word C_closure(C_word **ptr, int cells, C_word proc, ...);1853C_fctexport C_word C_pair(C_word **ptr, C_word car, C_word cdr) C_regparm;1854C_fctexport C_word C_number(C_word **ptr, double n) C_regparm;1855C_fctexport C_word C_mpointer(C_word **ptr, void *mp) C_regparm;1856C_fctexport C_word C_mpointer_or_false(C_word **ptr, void *mp) C_regparm;1857C_fctexport C_word C_taggedmpointer(C_word **ptr, C_word tag, void *mp) C_regparm;1858C_fctexport C_word C_taggedmpointer_or_false(C_word **ptr, C_word tag, void *mp) C_regparm;1859C_fctexport C_word C_vector(C_word **ptr, int n, ...);1860C_fctexport C_word C_structure(C_word **ptr, int n, ...);1861C_fctexport C_word C_mutate_slot(C_word *slot, C_word val) C_regparm;1862C_fctexport C_word C_mutate_scratch_slot(C_word *slot, C_word val) C_regparm;1863C_fctexport C_word C_scratch_alloc(C_uword size) C_regparm;1864C_fctexport C_word C_migrate_buffer_object(C_word **ptr, C_word *start, C_word *end, C_word obj) C_regparm;1865C_fctexport void C_reclaim(void *trampoline, C_word c) C_regparm C_noret;1866C_fctexport void C_save_and_reclaim(void *trampoline, int n, C_word *av) C_noret;1867C_fctexport void C_save_and_reclaim_args(void *trampoline, int n, ...) C_noret;1868C_fctexport void C_rereclaim2(C_uword size, int relative_resize) C_regparm;1869C_fctexport void C_unbound_variable(C_word sym);1870C_fctexport void C_decoding_error(C_word str, C_word index);1871C_fctexport C_word C_retrieve2(C_word val, char *name) C_regparm;1872C_fctexport void *C_retrieve2_symbol_proc(C_word val, char *name) C_regparm;1873C_fctexport int C_in_stackp(C_word x) C_regparm;1874C_fctexport int C_in_heapp(C_word x) C_regparm;1875C_fctexport int C_in_fromspacep(C_word x) C_regparm;1876C_fctexport int C_in_scratchspacep(C_word x) C_regparm;1877C_fctexport void C_trace(C_char *name) C_regparm;1878C_fctexport C_word C_emit_trace_info2(char *raw, C_word l, C_word x, C_word y, C_word t) C_regparm;1879C_fctexport C_word C_u_i_bytevector_hash(C_word str, C_word start, C_word end, C_word rnd) C_regparm;1880C_fctexport C_word C_halt(C_word msg);1881C_fctexport C_word C_message(C_word msg);1882C_fctexport C_word C_equalp(C_word x, C_word y) C_regparm;1883C_fctexport C_word C_set_gc_report(C_word flag) C_regparm;1884C_fctexport C_word C_start_timer(void) C_regparm;1885C_fctexport C_word C_exit_runtime(C_word code) C_noret;1886C_fctexport C_word C_set_print_precision(C_word n) C_regparm;1887C_fctexport C_word C_get_print_precision(void) C_regparm;1888C_fctexport C_word C_read_char(C_word port) C_regparm;1889C_fctexport C_word C_execute_shell_command(C_word string) C_regparm;1890C_fctexport int C_check_fd_ready(int fd) C_regparm;1891C_fctexport C_word C_char_ready_p(C_word port) C_regparm;1892C_fctexport void C_raise_interrupt(int reason) C_regparm;1893C_fctexport C_word C_establish_signal_handler(C_word signum, C_word reason) C_regparm;1894C_fctexport C_word C_copy_block(C_word from, C_word to) C_regparm;1895C_fctexport C_word C_evict_block(C_word from, C_word ptr) C_regparm;1896C_fctexport void C_gc_protect(C_word **addr, int n) C_regparm;1897C_fctexport void C_gc_unprotect(int n) C_regparm;1898C_fctexport C_SYMBOL_TABLE *C_new_symbol_table(char *name, unsigned int size) C_regparm;1899C_fctexport C_SYMBOL_TABLE *C_find_symbol_table(char *name) C_regparm;1900C_fctexport C_word C_find_symbol(C_word str, C_SYMBOL_TABLE *stable) C_regparm;1901C_fctexport C_word C_find_keyword(C_word str, C_SYMBOL_TABLE *stable) C_regparm;1902C_fctexport C_word C_lookup_symbol(C_word sym) C_regparm;1903C_fctexport void C_do_register_finalizer(C_word x, C_word proc);1904C_fctexport int C_do_unregister_finalizer(C_word x);1905C_fctexport C_word C_dbg_hook(C_word x);1906C_fctexport void C_use_private_repository(C_char *path);1907C_fctexport C_char *C_private_repository_path();1908C_fctexport C_char *C_executable_dirname();1909C_fctexport C_char *C_executable_pathname();1910C_fctexport C_char *C_resolve_executable_pathname(C_char *fname);1911C_fctexport C_char *C_getenv(C_word var);1912C_fctexport C_char *C_getenventry(int i);19131914/* utf.c: */1915C_fctexport C_word C_utf_subchar(C_word s, C_word i) C_regparm;1916C_fctexport C_word C_utf_setsubchar(C_word s, C_word i, C_word c) C_regparm;1917C_fctexport C_word C_utf_compare(C_word s1, C_word s2, C_word start1, C_word start2, C_word len) C_regparm;1918C_fctexport C_word C_utf_compare_ci(C_word s1, C_word s2, C_word start1, C_word start2, C_word len) C_regparm;1919C_fctexport C_word C_utf_equal(C_word s1, C_word s2) C_regparm;1920C_fctexport C_word C_utf_equal_ci(C_word s1, C_word s2) C_regparm;1921C_fctexport C_word C_utf_copy(C_word from, C_word to, C_word start1, C_word end1, C_word start2) C_regparm;1922C_fctexport C_word C_utf_position(C_word str, C_word start) C_regparm;1923C_fctexport int C_utf_char_position(C_word bv, int pos) C_regparm;1924C_fctexport C_word C_utf_range(C_word str, C_word start, C_word end) C_regparm;1925C_fctexport int C_utf_count(C_char *str, int len) C_regparm;1926C_fctexport int C_utf_fast_count(C_char *str, int len) C_regparm;1927C_fctexport C_char * C_utf_encode(C_char *str, int chr) C_regparm;1928C_fctexport C_word C_utf_decode_ptr(C_char *bv) C_regparm;1929C_fctexport C_word C_utf_decode(C_word bv, C_word pos) C_regparm;1930C_fctexport int C_utf_char_downcase(int c) C_regparm;1931C_fctexport int C_utf_char_upcase(int c) C_regparm;1932C_fctexport C_word C_utf_advance(C_word bv, C_word pos) C_regparm;1933C_fctexport C_word C_utf_insert(C_word bv, C_word pos, C_word c) C_regparm;1934C_fctexport C_word C_utf_bytes(C_word chr) C_regparm;1935C_fctexport C_word C_utf_fill(C_word bv, C_word chr) C_regparm;1936C_fctexport int C_utf_expect(int byte) C_regparm;1937C_fctexport void C_utf_putc(int chr, C_FILEPTR fp) C_regparm;1938C_fctexport C_word C_utf_fragment_counts(C_word bv, C_word pos, C_word len) C_regparm;1939C_fctexport C_word C_utf_overwrite(C_word s, C_word i, C_word len, C_word bv, C_word c) C_regparm;1940C_fctexport C_word C_utf_list_size(C_word lst) C_regparm;1941C_fctexport int C_utf_isspace(int c) C_regparm;1942C_fctexport int C_utf_isdigit(int c) C_regparm;1943C_fctexport int C_utf_isalpha(int c) C_regparm;1944C_fctexport int C_utf_isupper(int c) C_regparm;1945C_fctexport int C_utf_islower(int c) C_regparm;1946C_fctexport C_word C_utf_validate(C_word bv, C_word blen) C_regparm;1947C_fctexport C_word C_latin_to_utf(C_word from, C_word to, C_word start, C_word len) C_regparm;1948C_fctexport C_word C_utf_to_latin(C_word from, C_word to, C_word start, C_word len) C_regparm;1949C_fctexport C_word C_utf_char_foldcase(C_word c) C_regparm;1950C_fctexport C_word C_utf_string_foldcase(C_word from, C_word to, C_word len) C_regparm;1951C_fctexport C_word C_utf_string_downcase(C_word from, C_word to, C_word len) C_regparm;1952C_fctexport C_word C_utf_string_upcase(C_word from, C_word to, C_word len) C_regparm;1953#ifdef C_WCHAR_FILENAMES1954C_fctexport C_WCHAR *C_utf16(C_word bv, int cont) C_regparm;1955C_fctexport C_char *C_utf8(C_WCHAR *str) C_regparm;1956# define C_OS_FILENAME(bv, f) C_utf16(bv, f)1957#else1958# define C_OS_FILENAME(bv, f) C_c_string(bv)1959#endif19601961C_fctimport C_cpsproc(C_toplevel) C_noret;1962C_fctimport C_cpsproc(C_invalid_procedure) C_noret;1963C_fctexport C_cpsproc(C_stop_timer) C_noret;1964C_fctexport C_cpsproc(C_signum) C_noret;1965C_fctexport C_cpsproc(C_apply) C_noret;1966C_fctexport C_cpsproc(C_call_cc) C_noret;1967C_fctexport C_cpsproc(C_continuation_graft) C_noret;1968C_fctexport C_cpsproc(C_values) C_noret;1969C_fctexport C_cpsproc(C_apply_values) C_noret;1970C_fctexport C_cpsproc(C_call_with_values) C_noret;1971C_fctexport C_cpsproc(C_u_call_with_values) C_noret;1972C_fctexport C_cpsproc(C_times) C_noret;1973C_fctexport C_cpsproc(C_plus) C_noret;1974C_fctexport C_cpsproc(C_minus) C_noret;1975C_fctexport C_cpsproc(C_quotient_and_remainder) C_noret;1976C_fctexport C_cpsproc(C_u_integer_quotient_and_remainder) C_noret;1977C_fctexport C_cpsproc(C_bitwise_and) C_noret;1978C_fctexport C_cpsproc(C_bitwise_ior) C_noret;1979C_fctexport C_cpsproc(C_bitwise_xor) C_noret;19801981C_fctexport C_cpsproc(C_nequalp) C_noret;1982C_fctexport C_cpsproc(C_greaterp) C_noret;1983C_fctexport C_cpsproc(C_lessp) C_noret;1984C_fctexport C_cpsproc(C_greater_or_equal_p) C_noret;1985C_fctexport C_cpsproc(C_less_or_equal_p) C_noret;1986C_fctexport C_cpsproc(C_gc) C_noret;1987C_fctexport C_cpsproc(C_open_file_port) C_noret;1988C_fctexport C_cpsproc(C_allocate_vector) C_noret;1989C_fctexport C_cpsproc(C_allocate_bytevector) C_noret;1990C_fctexport C_cpsproc(C_string_to_symbol) C_noret;1991C_fctexport C_cpsproc(C_string_to_keyword) C_noret;1992C_fctexport C_cpsproc(C_build_symbol) C_noret;1993C_fctexport C_cpsproc(C_number_to_string) C_noret;1994C_fctexport C_cpsproc(C_fixnum_to_string) C_noret;1995C_fctexport C_cpsproc(C_flonum_to_string) C_noret;1996C_fctexport C_cpsproc(C_integer_to_string) C_noret;1997C_fctexport C_cpsproc(C_make_structure) C_noret;1998C_fctexport C_cpsproc(C_make_symbol) C_noret;1999C_fctexport C_cpsproc(C_make_pointer) C_noret;2000C_fctexport C_cpsproc(C_make_tagged_pointer) C_noret;2001C_fctexport C_cpsproc(C_ensure_heap_reserve) C_noret;2002C_fctexport C_cpsproc(C_return_to_host) C_noret;2003C_fctexport C_cpsproc(C_get_symbol_table_info) C_noret;2004C_fctexport C_cpsproc(C_get_memory_info) C_noret;2005C_fctexport C_cpsproc(C_context_switch) C_noret;2006C_fctexport C_cpsproc(C_peek_signed_integer) C_noret;2007C_fctexport C_cpsproc(C_peek_unsigned_integer) C_noret;2008C_fctexport C_cpsproc(C_peek_int64) C_noret;2009C_fctexport C_cpsproc(C_peek_uint64) C_noret;2010C_fctexport C_cpsproc(C_decode_seconds) C_noret;2011C_fctexport C_cpsproc(C_software_type) C_noret;2012C_fctexport C_cpsproc(C_machine_type) C_noret;2013C_fctexport C_cpsproc(C_machine_byte_order) C_noret;2014C_fctexport C_cpsproc(C_software_version) C_noret;2015C_fctexport C_cpsproc(C_build_platform) C_noret;2016C_fctexport C_cpsproc(C_register_finalizer) C_noret;2017C_fctexport C_cpsproc(C_set_dlopen_flags) C_noret;2018C_fctexport C_cpsproc(C_dload) C_noret;2019C_fctexport C_cpsproc(C_become) C_noret;2020C_fctexport C_cpsproc(C_call_with_cthulhu) C_noret;2021C_fctexport C_cpsproc(C_copy_closure) C_noret;2022C_fctexport C_cpsproc(C_dump_heap_state) C_noret;2023C_fctexport C_cpsproc(C_filter_heap_objects) C_noret;20242025C_fctexport time_t C_seconds(C_long *ms) C_regparm;2026C_fctexport C_word C_bignum_simplify(C_word big) C_regparm;2027C_fctexport C_word C_allocate_scratch_bignum(C_word **ptr, C_word size, C_word negp, C_word initp) C_regparm;2028C_fctexport C_word C_bignum_rewrap(C_word **p, C_word big) C_regparm;2029C_fctexport C_word C_i_dump_statistical_profile();2030C_fctexport C_word C_a_i_list(C_word **a, int c, ...);2031C_fctexport C_word C_a_i_string(C_word **a, int c, ...);2032C_fctexport C_word C_a_i_record(C_word **a, int c, ...);2033C_fctexport C_word C_a_i_port(C_word **a, int c);2034C_fctexport C_word C_a_i_bytevector(C_word **a, int c, C_word x) C_regparm;2035C_fctexport C_word C_i_listp(C_word x) C_regparm;2036C_fctexport C_word C_i_s8vectorp(C_word x) C_regparm;2037C_fctexport C_word C_i_u16vectorp(C_word x) C_regparm;2038C_fctexport C_word C_i_s16vectorp(C_word x) C_regparm;2039C_fctexport C_word C_i_u32vectorp(C_word x) C_regparm;2040C_fctexport C_word C_i_s32vectorp(C_word x) C_regparm;2041C_fctexport C_word C_i_u64vectorp(C_word x) C_regparm;2042C_fctexport C_word C_i_s64vectorp(C_word x) C_regparm;2043C_fctexport C_word C_i_f32vectorp(C_word x) C_regparm;2044C_fctexport C_word C_i_f64vectorp(C_word x) C_regparm;2045C_fctexport C_word C_i_string_equal_p(C_word x, C_word y) C_regparm;2046C_fctexport C_word C_i_string_ci_equal_p(C_word x, C_word y) C_regparm;2047C_fctexport C_word C_i_set_car(C_word p, C_word x) C_regparm;2048C_fctexport C_word C_i_set_cdr(C_word p, C_word x) C_regparm;2049C_fctexport C_word C_i_vector_set(C_word v, C_word i, C_word x) C_regparm;2050C_fctexport C_word C_i_bytevector_set(C_word v, C_word i, C_word x) C_regparm;2051C_fctexport C_word C_i_s8vector_set(C_word v, C_word i, C_word x) C_regparm;2052C_fctexport C_word C_i_u16vector_set(C_word v, C_word i, C_word x) C_regparm;2053C_fctexport C_word C_i_s16vector_set(C_word v, C_word i, C_word x) C_regparm;2054C_fctexport C_word C_i_u32vector_set(C_word v, C_word i, C_word x) C_regparm;2055C_fctexport C_word C_i_s32vector_set(C_word v, C_word i, C_word x) C_regparm;2056C_fctexport C_word C_i_u64vector_set(C_word v, C_word i, C_word x) C_regparm;2057C_fctexport C_word C_i_s64vector_set(C_word v, C_word i, C_word x) C_regparm;2058C_fctexport C_word C_i_f32vector_set(C_word v, C_word i, C_word x) C_regparm;2059C_fctexport C_word C_i_f64vector_set(C_word v, C_word i, C_word x) C_regparm;2060C_fctexport C_word C_i_exactp(C_word x) C_regparm;2061C_fctexport C_word C_i_inexactp(C_word x) C_regparm;2062C_fctexport C_word C_i_nanp(C_word x) C_regparm;2063C_fctexport C_word C_i_finitep(C_word x) C_regparm;2064C_fctexport C_word C_i_infinitep(C_word x) C_regparm;2065C_fctexport C_word C_i_zerop(C_word x) C_regparm;2066C_fctexport C_word C_u_i_zerop(C_word x) C_regparm; /* DEPRECATED */2067C_fctexport C_word C_i_positivep(C_word x) C_regparm;2068C_fctexport C_word C_i_integer_positivep(C_word x) C_regparm;2069C_fctexport C_word C_i_negativep(C_word x) C_regparm;2070C_fctexport C_word C_i_integer_negativep(C_word x) C_regparm;2071C_fctexport C_word C_i_car(C_word x) C_regparm;2072C_fctexport C_word C_i_cdr(C_word x) C_regparm;2073C_fctexport C_word C_i_caar(C_word x) C_regparm;2074C_fctexport C_word C_i_cadr(C_word x) C_regparm;2075C_fctexport C_word C_i_cdar(C_word x) C_regparm;2076C_fctexport C_word C_i_cddr(C_word x) C_regparm;2077C_fctexport C_word C_i_caddr(C_word x) C_regparm;2078C_fctexport C_word C_i_cdddr(C_word x) C_regparm;2079C_fctexport C_word C_i_cadddr(C_word x) C_regparm;2080C_fctexport C_word C_i_cddddr(C_word x) C_regparm;2081C_fctexport C_word C_i_list_tail(C_word lst, C_word i) C_regparm;2082C_fctexport C_word C_i_evenp(C_word x) C_regparm;2083C_fctexport C_word C_i_integer_evenp(C_word x) C_regparm;2084C_fctexport C_word C_i_oddp(C_word x) C_regparm;2085C_fctexport C_word C_i_integer_oddp(C_word x) C_regparm;2086C_fctexport C_word C_i_vector_ref(C_word v, C_word i) C_regparm;2087C_fctexport C_word C_i_bytevector_ref(C_word v, C_word i) C_regparm;2088C_fctexport C_word C_i_s8vector_ref(C_word v, C_word i) C_regparm;2089C_fctexport C_word C_i_u16vector_ref(C_word v, C_word i) C_regparm;2090C_fctexport C_word C_i_s16vector_ref(C_word v, C_word i) C_regparm;2091C_fctexport C_word C_a_i_u32vector_ref(C_word **ptr, C_word c, C_word v, C_word i) C_regparm;2092C_fctexport C_word C_a_i_s32vector_ref(C_word **ptr, C_word c, C_word v, C_word i) C_regparm;2093C_fctexport C_word C_a_i_u64vector_ref(C_word **ptr, C_word c, C_word v, C_word i) C_regparm;2094C_fctexport C_word C_a_i_s64vector_ref(C_word **ptr, C_word c, C_word v, C_word i) C_regparm;2095C_fctexport C_word C_a_i_f32vector_ref(C_word **ptr, C_word c, C_word v, C_word i) C_regparm;2096C_fctexport C_word C_a_i_f64vector_ref(C_word **ptr, C_word c, C_word v, C_word i) C_regparm;2097C_fctexport C_word C_i_block_ref(C_word x, C_word i) C_regparm;2098C_fctexport C_word C_i_string_set(C_word s, C_word i, C_word c) C_regparm;2099C_fctexport C_word C_i_string_ref(C_word s, C_word i) C_regparm;2100C_fctexport C_word C_i_vector_length(C_word v) C_regparm;2101C_fctexport C_word C_i_bytevector_length(C_word v) C_regparm;2102C_fctexport C_word C_i_s8vector_length(C_word v) C_regparm;2103C_fctexport C_word C_i_u16vector_length(C_word v) C_regparm;2104C_fctexport C_word C_i_s16vector_length(C_word v) C_regparm;2105C_fctexport C_word C_i_u32vector_length(C_word v) C_regparm;2106C_fctexport C_word C_i_s32vector_length(C_word v) C_regparm;2107C_fctexport C_word C_i_u64vector_length(C_word v) C_regparm;2108C_fctexport C_word C_i_s64vector_length(C_word v) C_regparm;2109C_fctexport C_word C_i_f32vector_length(C_word v) C_regparm;2110C_fctexport C_word C_i_f64vector_length(C_word v) C_regparm;2111C_fctexport C_word C_i_string_length(C_word s) C_regparm;2112C_fctexport C_word C_i_assq(C_word x, C_word lst) C_regparm;2113C_fctexport C_word C_i_assv(C_word x, C_word lst) C_regparm;2114C_fctexport C_word C_i_assoc(C_word x, C_word lst) C_regparm;2115C_fctexport C_word C_i_memq(C_word x, C_word lst) C_regparm;2116C_fctexport C_word C_u_i_memq(C_word x, C_word lst) C_regparm;2117C_fctexport C_word C_i_memv(C_word x, C_word lst) C_regparm;2118C_fctexport C_word C_i_member(C_word x, C_word lst) C_regparm;2119C_fctexport C_word C_i_length(C_word lst) C_regparm;2120C_fctexport C_word C_u_i_length(C_word lst) C_regparm;2121C_fctexport C_word C_i_check_closure_2(C_word x, C_word loc) C_regparm;2122C_fctexport C_word C_i_check_fixnum_2(C_word x, C_word loc) C_regparm;2123C_fctexport C_word C_i_check_exact_2(C_word x, C_word loc) C_regparm; /* DEPRECATED */2124C_fctexport C_word C_i_check_inexact_2(C_word x, C_word loc) C_regparm;2125C_fctexport C_word C_i_check_number_2(C_word x, C_word loc) C_regparm;2126C_fctexport C_word C_i_check_string_2(C_word x, C_word loc) C_regparm;2127C_fctexport C_word C_i_check_bytevector_2(C_word x, C_word loc) C_regparm;2128C_fctexport C_word C_i_check_symbol_2(C_word x, C_word loc) C_regparm;2129C_fctexport C_word C_i_check_keyword_2(C_word x, C_word loc) C_regparm;2130C_fctexport C_word C_i_check_list_2(C_word x, C_word loc) C_regparm;2131C_fctexport C_word C_i_check_pair_2(C_word x, C_word loc) C_regparm;2132C_fctexport C_word C_i_check_boolean_2(C_word x, C_word loc) C_regparm;2133C_fctexport C_word C_i_check_locative_2(C_word x, C_word loc) C_regparm;2134C_fctexport C_word C_i_check_vector_2(C_word x, C_word loc) C_regparm;2135C_fctexport C_word C_i_check_structure_2(C_word x, C_word st, C_word loc) C_regparm;2136C_fctexport C_word C_i_check_char_2(C_word x, C_word loc) C_regparm;2137C_fctexport C_word C_i_check_port_2(C_word x, C_word in, C_word op, C_word loc) C_regparm;2138C_fctexport C_word C_i_check_range_2(C_word i, C_word f, C_word t, C_word loc) C_regparm;2139C_fctexport C_word C_i_check_range_including_2(C_word i, C_word f, C_word t, C_word loc) C_regparm;2140C_fctexport C_word C_i_bignum_cmp(C_word x, C_word y) C_regparm;2141C_fctexport C_word C_i_nequalp(C_word x, C_word y) C_regparm;2142C_fctexport C_word C_i_integer_equalp(C_word x, C_word y) C_regparm;2143C_fctexport C_word C_i_greaterp(C_word x, C_word y) C_regparm;2144C_fctexport C_word C_i_integer_greaterp(C_word x, C_word y) C_regparm;2145C_fctexport C_word C_i_lessp(C_word x, C_word y) C_regparm;2146C_fctexport C_word C_i_integer_lessp(C_word x, C_word y) C_regparm;2147C_fctexport C_word C_i_greater_or_equalp(C_word x, C_word y) C_regparm;2148C_fctexport C_word C_i_integer_greater_or_equalp(C_word x, C_word y) C_regparm;2149C_fctexport C_word C_i_less_or_equalp(C_word x, C_word y) C_regparm;2150C_fctexport C_word C_i_integer_less_or_equalp(C_word x, C_word y) C_regparm;2151C_fctexport C_word C_i_not_pair_p_2(C_word x) C_regparm;2152C_fctexport C_word C_i_null_list_p(C_word x) C_regparm;2153C_fctexport C_word C_i_string_null_p(C_word x) C_regparm;2154C_fctexport C_word C_i_null_pointerp(C_word x) C_regparm;2155C_fctexport C_word C_i_char_equalp(C_word x, C_word y) C_regparm;2156C_fctexport C_word C_i_char_greaterp(C_word x, C_word y) C_regparm;2157C_fctexport C_word C_i_char_lessp(C_word x, C_word y) C_regparm;2158C_fctexport C_word C_i_char_greater_or_equal_p(C_word x, C_word y) C_regparm;2159C_fctexport C_word C_i_char_less_or_equal_p(C_word x, C_word y) C_regparm;2160C_fctexport C_word C_a_i_locative_ref(C_word **a, int c, C_word loc) C_regparm;2161C_fctexport C_word C_i_locative_set(C_word loc, C_word x) C_regparm;2162C_fctexport C_word C_i_locative_to_object(C_word loc) C_regparm;2163C_fctexport C_word C_i_locative_index(C_word loc) C_regparm;2164C_fctexport C_word C_a_i_make_locative(C_word **a, int c, C_word type, C_word object, C_word index, C_word weak) C_regparm;2165C_fctexport C_word C_i_bit_to_bool(C_word n, C_word i) C_regparm; /* DEPRECATED */2166C_fctexport C_word C_i_integer_length(C_word x) C_regparm;2167C_fctexport C_word C_a_i_exp(C_word **a, int c, C_word n) C_regparm;2168C_fctexport C_word C_a_i_log(C_word **a, int c, C_word n) C_regparm;2169C_fctexport C_word C_a_i_sin(C_word **a, int c, C_word n) C_regparm;2170C_fctexport C_word C_a_i_cos(C_word **a, int c, C_word n) C_regparm;2171C_fctexport C_word C_a_i_tan(C_word **a, int c, C_word n) C_regparm;2172C_fctexport C_word C_a_i_asin(C_word **a, int c, C_word n) C_regparm;2173C_fctexport C_word C_a_i_acos(C_word **a, int c, C_word n) C_regparm;2174C_fctexport C_word C_a_i_atan(C_word **a, int c, C_word n) C_regparm;2175C_fctexport C_word C_a_i_atan2(C_word **a, int c, C_word n1, C_word n2) C_regparm;2176C_fctexport C_word C_a_i_sinh(C_word **a, int c, C_word n) C_regparm;2177C_fctexport C_word C_a_i_cosh(C_word **a, int c, C_word n) C_regparm;2178C_fctexport C_word C_a_i_tanh(C_word **a, int c, C_word n) C_regparm;2179C_fctexport C_word C_a_i_asinh(C_word **a, int c, C_word n) C_regparm;2180C_fctexport C_word C_a_i_acosh(C_word **a, int c, C_word n) C_regparm;2181C_fctexport C_word C_a_i_atanh(C_word **a, int c, C_word n) C_regparm;2182C_fctexport C_word C_a_i_sqrt(C_word **a, int c, C_word n) C_regparm;2183C_fctexport C_word C_i_o_fixnum_plus(C_word x, C_word y) C_regparm;2184C_fctexport C_word C_i_o_fixnum_difference(C_word x, C_word y) C_regparm;2185C_fctexport C_word C_i_o_fixnum_times(C_word x, C_word y) C_regparm;2186C_fctexport C_word C_i_o_fixnum_quotient(C_word x, C_word y) C_regparm;2187C_fctexport C_word C_i_o_fixnum_and(C_word x, C_word y) C_regparm;2188C_fctexport C_word C_i_o_fixnum_ior(C_word x, C_word y) C_regparm;2189C_fctexport C_word C_i_o_fixnum_xor(C_word x, C_word y) C_regparm;2190C_fctexport C_word C_a_i_flonum_round_proper(C_word **a, int c, C_word n) C_regparm;2191C_fctexport C_word C_a_i_flonum_gcd(C_word **p, C_word n, C_word x, C_word y) C_regparm;21922193C_fctexport C_word C_i_getprop(C_word sym, C_word prop, C_word def) C_regparm;2194C_fctexport C_word C_putprop(C_word **a, C_word sym, C_word prop, C_word val) C_regparm;2195C_fctexport C_word C_i_persist_symbol(C_word sym) C_regparm;2196C_fctexport C_word C_i_unpersist_symbol(C_word sym) C_regparm;2197C_fctexport C_word C_i_get_keyword(C_word key, C_word args, C_word def) C_regparm;2198C_fctexport C_word C_i_process_sleep(C_word n) C_regparm;2199C_fctexport C_u64 C_milliseconds(void) C_regparm; /* DEPRECATED */2200C_fctexport C_u64 C_current_process_milliseconds(void) C_regparm;2201C_fctexport C_u64 C_cpu_milliseconds(void) C_regparm;2202C_fctexport double C_bignum_to_double(C_word bignum) C_regparm;2203C_fctexport C_word C_i_debug_modep(void) C_regparm;2204C_fctexport C_word C_i_dump_heap_on_exitp(void) C_regparm;2205C_fctexport C_word C_i_accumulated_gc_time(void) C_regparm;2206C_fctexport C_word C_i_allocated_finalizer_count(void) C_regparm;2207C_fctexport C_word C_i_live_finalizer_count(void) C_regparm;2208C_fctexport C_word C_i_profilingp(void) C_regparm;2209C_fctexport C_word C_i_tty_forcedp(void) C_regparm;2210C_fctexport C_word C_i_setenv(C_word var, C_word val) C_regparm;2211C_fctexport C_long C_current_jiffy(void) C_regparm;2212C_fctexport C_long C_jiffies_per_second(void) C_regparm;22132214C_fctexport C_word C_a_i_cpu_time(C_word **a, int c, C_word buf) C_regparm;2215C_fctexport C_word C_a_i_exact_to_inexact(C_word **a, int c, C_word n) C_regparm;2216C_fctexport C_word C_i_file_exists_p(C_word name, C_word file, C_word dir) C_regparm;22172218C_fctexport C_word C_s_a_i_abs(C_word **ptr, C_word n, C_word x) C_regparm;2219C_fctexport C_word C_s_a_i_negate(C_word **ptr, C_word n, C_word x) C_regparm;2220C_fctexport C_word C_s_a_i_minus(C_word **ptr, C_word n, C_word x, C_word y) C_regparm;2221C_fctexport C_word C_s_a_u_i_integer_negate(C_word **ptr, C_word n, C_word x) C_regparm;2222C_fctexport C_word C_s_a_u_i_integer_minus(C_word **ptr, C_word n, C_word x, C_word y) C_regparm;2223C_fctexport C_word C_s_a_i_plus(C_word **ptr, C_word n, C_word x, C_word y) C_regparm;2224C_fctexport C_word C_s_a_u_i_integer_plus(C_word **ptr, C_word n, C_word x, C_word y) C_regparm;2225C_fctexport C_word C_s_a_i_times(C_word **ptr, C_word n, C_word x, C_word y) C_regparm;2226C_fctexport C_word C_s_a_u_i_integer_times(C_word **ptr, C_word n, C_word x, C_word y) C_regparm;2227C_fctexport C_word C_s_a_i_arithmetic_shift(C_word **ptr, C_word n, C_word x, C_word y) C_regparm;2228C_fctexport C_word C_s_a_u_i_integer_gcd(C_word **ptr, C_word n, C_word x, C_word y) C_regparm;2229C_fctexport C_word C_s_a_i_quotient(C_word **ptr, C_word n, C_word x, C_word y) C_regparm;2230C_fctexport C_word C_s_a_u_i_integer_quotient(C_word **ptr, C_word n, C_word x, C_word y) C_regparm;2231C_fctexport C_word C_s_a_i_remainder(C_word **ptr, C_word n, C_word x, C_word y) C_regparm;2232C_fctexport C_word C_s_a_u_i_integer_remainder(C_word **ptr, C_word n, C_word x, C_word y) C_regparm;2233C_fctexport C_word C_s_a_i_modulo(C_word **ptr, C_word n, C_word x, C_word y) C_regparm;2234C_fctexport C_word C_s_a_u_i_integer_modulo(C_word **ptr, C_word n, C_word x, C_word y) C_regparm;2235C_fctexport C_word C_s_a_i_bitwise_and(C_word **ptr, C_word n, C_word x, C_word y) C_regparm;2236C_fctexport C_word C_s_a_i_bitwise_ior(C_word **ptr, C_word n, C_word x, C_word y) C_regparm;2237C_fctexport C_word C_s_a_i_bitwise_xor(C_word **ptr, C_word n, C_word x, C_word y) C_regparm;2238C_fctexport C_word C_s_a_i_bitwise_not(C_word **ptr, C_word n, C_word x) C_regparm;2239C_fctexport C_word C_s_a_i_digits_to_integer(C_word **ptr, C_word n, C_word str, C_word start, C_word end, C_word radix, C_word negp) C_regparm;2240C_fctexport C_word C_s_a_u_i_flo_to_int(C_word **ptr, C_word n, C_word x) C_regparm;224122422243C_fctexport C_word C_i_foreign_char_argumentp(C_word x) C_regparm;2244C_fctexport C_word C_i_foreign_fixnum_argumentp(C_word x) C_regparm;2245C_fctexport C_word C_i_foreign_flonum_argumentp(C_word x) C_regparm;2246C_fctexport C_word C_i_foreign_cplxnum_argumentp(C_word x) C_regparm;2247C_fctexport C_word C_i_foreign_block_argumentp(C_word x) C_regparm;2248C_fctexport C_word C_i_foreign_struct_wrapper_argumentp(C_word t, C_word x) C_regparm;2249C_fctexport C_word C_i_foreign_string_argumentp(C_word x) C_regparm;2250C_fctexport C_word C_i_foreign_symbol_argumentp(C_word x) C_regparm;2251C_fctexport C_word C_i_foreign_tagged_pointer_argumentp(C_word x, C_word t) C_regparm;2252C_fctexport C_word C_i_foreign_pointer_argumentp(C_word x) C_regparm;2253C_fctexport C_word C_i_foreign_scheme_or_c_pointer_argumentp(C_word x) C_regparm;2254C_fctexport C_word C_i_foreign_ranged_integer_argumentp(C_word x, C_word bits) C_regparm;2255C_fctexport C_word C_i_foreign_unsigned_ranged_integer_argumentp(C_word x, C_word bits) C_regparm;22562257C_fctexport C_char *C_lookup_procedure_id(void *ptr);2258C_fctexport void *C_lookup_procedure_ptr(C_char *id);22592260C_fctexport int C_fast_rand(void);2261C_fctexport void C_fast_srand(int seed);2262C_fctexport C_word C_random_fixnum(C_word n) C_regparm;2263C_fctexport C_word C_s_a_u_i_random_int(C_word **ptr, C_word n, C_word rn) C_regparm;2264C_fctexport C_word C_a_i_random_real(C_word **ptr, C_word n) C_regparm;2265C_fctexport C_word C_random_bytes(C_word buf, C_word size);2266C_fctexport C_word C_set_random_seed(C_word buf, C_word n);22672268#ifdef C_SIXTY_FOUR2269C_fctexport C_cpsproc(C_peek_signed_integer_32);2270C_fctexport C_cpsproc(C_peek_unsigned_integer_32);2271#else2272# define C_peek_signed_integer_32 C_peek_signed_integer2273# define C_peek_unsigned_integer_32 C_peek_unsigned_integer2274#endif22752276C_fctexport C_word C_decode_literal(C_word **ptr, C_char *str) C_regparm;2277C_fctexport C_word C_i_pending_interrupt(C_word dummy) C_regparm;22782279C_fctexport void *C_get_statistics(void);22802281/* defined in eval.scm: */2282C_fctexport void CHICKEN_get_error_message(char *buf,int bufsize);2283C_fctexport int CHICKEN_load(char * filename);2284C_fctexport int CHICKEN_read(char * str,C_word *result);2285C_fctexport int CHICKEN_apply_to_string(C_word func,C_word args,char *buf,int bufsize);2286C_fctexport int CHICKEN_apply(C_word func,C_word args,C_word *result);2287C_fctexport int CHICKEN_eval_string_to_string(char *str,char *buf,int bufsize);2288C_fctexport int CHICKEN_eval_to_string(C_word exp,char *buf,int bufsize);2289C_fctexport int CHICKEN_eval_string(char * str,C_word *result);2290C_fctexport int CHICKEN_eval(C_word exp,C_word *result);2291C_fctexport int CHICKEN_yield();22922293C_fctexport C_cpsproc(C_default_5fstub_toplevel);22942295C_fctexport C_word C_a_extract_struct_2(C_word **ptr, size_t sz, void *sp);229622972298#ifndef HAVE_STATEMENT_EXPRESSIONS22992300inline static C_word *C_a_i(C_word **a, int n)2301{2302 C_word *p = *a;23032304 *a += n;2305 return p;2306}23072308#endif23092310inline static C_word2311C_chop_bv(C_word bv)2312{2313 ((C_SCHEME_BLOCK *)bv)->header = C_make_header(C_BYTEVECTOR_TYPE, C_header_size(bv) - 1);2314 return bv;2315}23162317inline static C_word2318C_mutate(C_word *slot, C_word val)2319{2320 if(!C_immediatep(val)) return C_mutate_slot(slot, val);2321 else return *slot = val;2322}23232324inline static C_word C_permanentp(C_word x)2325{2326 return C_mk_bool(!C_immediatep(x) &&2327 !C_in_stackp(x) &&2328 !C_in_heapp(x) &&2329 !C_in_scratchspacep(x));2330}23312332inline static C_word C_u_i_namespaced_symbolp(C_word x)2333{2334 C_word s = C_symbol_name(x);2335 return C_mk_bool(C_memchr(C_data_pointer(s), '#', C_header_size(s)));2336}23372338inline static C_word C_flonum(C_word **ptr, double n)2339{2340 C_word2341 *p = *ptr,2342 *p0;23432344#ifndef C_SIXTY_FOUR2345#ifndef C_DOUBLE_IS_32_BITS2346 /* Align double on 8-byte boundary: */2347 if(C_aligned8(p)) ++p;2348#endif2349#endif23502351 p0 = p;2352 *(p++) = C_FLONUM_TAG;2353 *((double *)p) = n;2354 *ptr = p + sizeof(double) / sizeof(C_word);2355 return (C_word)p0;2356}235723582359inline static C_word C_u_i_zerop2(C_word x)2360{2361 return C_mk_bool(x == C_fix(0) ||2362 (!C_immediatep(x) &&2363 C_block_header(x) == C_FLONUM_TAG &&2364 C_flonum_magnitude(x) == 0.0));2365}236623672368inline static C_word C_string_to_pbytevector(C_word s)2369{2370 return C_pbytevector(C_header_size(s), (C_char *)C_data_pointer(s));2371}237223732374inline static C_word C_a_i_record1(C_word **ptr, int n, C_word x1)2375{2376 C_word *p = *ptr, *p0 = p;23772378 *(p++) = C_STRUCTURE_TYPE | 1;2379 *(p++) = x1;2380 *ptr = p;2381 return (C_word)p0;2382}238323842385inline static C_word C_a_i_record2(C_word **ptr, int n, C_word x1, C_word x2)2386{2387 C_word *p = *ptr, *p0 = p;23882389 *(p++) = C_STRUCTURE_TYPE | 2;2390 *(p++) = x1;2391 *(p++) = x2;2392 *ptr = p;2393 return (C_word)p0;2394}239523962397inline static C_word C_a_i_record3(C_word **ptr, int n, C_word x1, C_word x2, C_word x3)2398{2399 C_word *p = *ptr, *p0 = p;24002401 *(p++) = C_STRUCTURE_TYPE | 3;2402 *(p++) = x1;2403 *(p++) = x2;2404 *(p++) = x3;2405 *ptr = p;2406 return (C_word)p0;2407}240824092410inline static C_word C_a_i_record4(C_word **ptr, int n, C_word x1, C_word x2, C_word x3, C_word x4)2411{2412 C_word *p = *ptr, *p0 = p;24132414 *(p++) = C_STRUCTURE_TYPE | 4;2415 *(p++) = x1;2416 *(p++) = x2;2417 *(p++) = x3;2418 *(p++) = x4;2419 *ptr = p;2420 return (C_word)p0;2421}242224232424inline static C_word C_a_i_record5(C_word **ptr, int n, C_word x1, C_word x2, C_word x3, C_word x4,2425 C_word x5)2426{2427 C_word *p = *ptr, *p0 = p;24282429 *(p++) = C_STRUCTURE_TYPE | 5;2430 *(p++) = x1;2431 *(p++) = x2;2432 *(p++) = x3;2433 *(p++) = x4;2434 *(p++) = x5;2435 *ptr = p;2436 return (C_word)p0;2437}243824392440inline static C_word C_a_i_record6(C_word **ptr, int n, C_word x1, C_word x2, C_word x3, C_word x4,2441 C_word x5, C_word x6)2442{2443 C_word *p = *ptr, *p0 = p;24442445 *(p++) = C_STRUCTURE_TYPE | 6;2446 *(p++) = x1;2447 *(p++) = x2;2448 *(p++) = x3;2449 *(p++) = x4;2450 *(p++) = x5;2451 *(p++) = x6;2452 *ptr = p;2453 return (C_word)p0;2454}245524562457inline static C_word C_a_i_record7(C_word **ptr, int n, C_word x1, C_word x2, C_word x3, C_word x4,2458 C_word x5, C_word x6, C_word x7)2459{2460 C_word *p = *ptr, *p0 = p;24612462 *(p++) = C_STRUCTURE_TYPE | 7;2463 *(p++) = x1;2464 *(p++) = x2;2465 *(p++) = x3;2466 *(p++) = x4;2467 *(p++) = x5;2468 *(p++) = x6;2469 *(p++) = x7;2470 *ptr = p;2471 return (C_word)p0;2472}247324742475inline static C_word C_a_i_record8(C_word **ptr, int n, C_word x1, C_word x2, C_word x3, C_word x4,2476 C_word x5, C_word x6, C_word x7, C_word x8)2477{2478 C_word *p = *ptr, *p0 = p;24792480 *(p++) = C_STRUCTURE_TYPE | 8;2481 *(p++) = x1;2482 *(p++) = x2;2483 *(p++) = x3;2484 *(p++) = x4;2485 *(p++) = x5;2486 *(p++) = x6;2487 *(p++) = x7;2488 *(p++) = x8;2489 *ptr = p;2490 return (C_word)p0;2491}24922493inline static C_word C_cplxnum(C_word **ptr, C_word r, C_word i)2494{2495 C_word *p = *ptr, *p0 = p;24962497 *(p++) = C_CPLXNUM_TAG;2498 *(p++) = r;2499 *(p++) = i;2500 *ptr = p;2501 return (C_word)p0;2502}25032504inline static C_word C_inexact_cplxnum(C_word **ptr, double C_complex n)2505{2506#if defined(__STDC_NO_COMPLEX__) || defined(__cplusplus)2507 C_unimplemented(C_text("native complex numbers"));2508 return 0;2509#else2510 C_word r = C_flonum(ptr, creal(n));2511 C_word i = C_flonum(ptr, cimag(n));2512 C_word *p = *ptr, *p0 = p;25132514 *(p++) = C_CPLXNUM_TAG;2515 *(p++) = r;2516 *(p++) = i;2517 *ptr = p;2518 return (C_word)p0;2519#endif2520}25212522inline static C_word C_ratnum(C_word **ptr, C_word n, C_word d)2523{2524 C_word *p = *ptr, *p0 = p;25252526 *(p++) = C_RATNUM_TAG;2527 *(p++) = n;2528 *(p++) = d;2529 *ptr = p;2530 return (C_word)p0;2531}25322533inline static C_word C_a_i_bignum_wrapper(C_word **ptr, C_word vec)2534{2535 C_word *p = *ptr, *p0 = p;25362537 *(p++) = C_BIGNUM_TAG;2538 *(p++) = vec;2539 *ptr = p;2540 return (C_word)p0;2541}25422543/* Silly (this is not normalized) but in some cases needed internally */2544inline static C_word C_bignum0(C_word **ptr)2545{2546 C_word *p = *ptr, p0 = (C_word)p;25472548 *(p++) = C_BYTEVECTOR_TYPE | C_wordstobytes(1);2549 *(p++) = 0; /* zero is always positive */2550 *ptr = p;25512552 return C_a_i_bignum_wrapper(ptr, p0);2553}25542555inline static C_word C_bignum1(C_word **ptr, int negp, C_uword d1)2556{2557 C_word *p = *ptr, p0 = (C_word)p;25582559 *(p++) = C_BYTEVECTOR_TYPE | C_wordstobytes(2);2560 *(p++) = negp;2561 *(p++) = d1;2562 *ptr = p;25632564 return C_a_i_bignum_wrapper(ptr, p0);2565}25662567/* Here d1, d2, ... are low to high (ie, little endian)! */2568inline static C_word C_bignum2(C_word **ptr, int negp, C_uword d1, C_uword d2)2569{2570 C_word *p = *ptr, p0 = (C_word)p;25712572 *(p++) = C_BYTEVECTOR_TYPE | C_wordstobytes(3);2573 *(p++) = negp;2574 *(p++) = d1;2575 *(p++) = d2;2576 *ptr = p;25772578 return C_a_i_bignum_wrapper(ptr, p0);2579}25802581inline static C_word C_i_bignump(C_word x)2582{2583 return C_mk_bool(!C_immediatep(x) && C_block_header(x) == C_BIGNUM_TAG);2584}25852586inline static double C_complex C_c_cplxnum(C_word x)2587{2588#if defined(__STDC_NO_COMPLEX__) || defined(__cplusplus)2589 C_unimplemented(C_text("native complex numbers"));2590 return 0;2591#else2592 if(x & C_FIXNUM_BIT) return (double)C_unfix(x);2593 else if(C_block_header(x) == C_CPLXNUM_TAG)2594 return C_flonum_magnitude(C_u_i_cplxnum_real(x)) + I *2595 C_flonum_magnitude(C_u_i_cplxnum_imag(x));2596 else return C_flonum_magnitude(x);2597#endif2598}25992600inline static double C_c_double(C_word x)2601{2602 if(x & C_FIXNUM_BIT) return (double)C_unfix(x);2603 else return C_flonum_magnitude(x);2604}26052606inline static C_word C_a_u_i_int_to_flo(C_word **ptr, int n, C_word x)2607{2608 if(x & C_FIXNUM_BIT) return C_a_i_fix_to_flo(ptr, n, x);2609 else return C_a_u_i_big_to_flo(ptr, n, x);2610}26112612inline static C_word C_num_to_int(C_word x)2613{2614 if(x & C_FIXNUM_BIT) {2615 return C_unfix(x);2616 } else {2617#if DEBUGBUILD /* removes a warning with clang */2618 (void)C_CHECKp(x,C_bignump(C_VAL1(x)),0);2619#endif2620 if (C_bignum_negativep(x)) return -(C_word)C_bignum_digits(x)[0];2621 else return (C_word)C_bignum_digits(x)[0]; /* should never be larger */2622 }2623}262426252626inline static C_s64 C_num_to_int64(C_word x)2627{2628 if(x & C_FIXNUM_BIT) {2629 return (C_s64)C_unfix(x);2630 } else {2631 C_s64 num = C_bignum_digits(x)[0];2632#ifndef C_SIXTY_FOUR2633 if (C_bignum_size(x) > 1) num |= (C_s64)(((C_u64)C_bignum_digits(x)[1]) << 32);2634#endif2635 if (C_bignum_negativep(x)) return -num;2636 else return num;2637 }2638}263926402641inline static C_u64 C_num_to_uint64(C_word x)2642{2643 if(x & C_FIXNUM_BIT) {2644 return (C_u64)C_unfix(x);2645 } else {2646 C_s64 num = C_bignum_digits(x)[0];2647#ifndef C_SIXTY_FOUR2648 if (C_bignum_size(x) > 1) num |= ((C_u64)C_bignum_digits(x)[1]) << 32;2649#endif2650 return num;2651 }2652}265326542655inline static C_uword C_num_to_unsigned_int(C_word x)2656{2657 if(x & C_FIXNUM_BIT) {2658 return (C_uword)C_unfix(x);2659 } else {2660 return C_bignum_digits(x)[0]; /* should never be larger */2661 }2662}266326642665inline static C_word C_int_to_num(C_word **ptr, C_word n)2666{2667 if(C_fitsinfixnump(n)) return C_fix(n);2668 else return C_bignum1(ptr, n < 0, C_wabs(n));2669}267026712672inline static C_word C_unsigned_int_to_num(C_word **ptr, C_uword n)2673{2674 if(C_ufitsinfixnump(n)) return C_fix(n);2675 else return C_bignum1(ptr, 0, n);2676}26772678inline static C_word C_int64_to_num(C_word **ptr, C_s64 n)2679{2680#ifdef C_SIXTY_FOUR2681 if(C_fitsinfixnump(n)) {2682 return C_fix(n);2683 } else {2684 C_u64 un = n < 0 ? -n : n;2685 return C_bignum1(ptr, n < 0, un);2686 }2687#else2688 C_u64 un = n < 0 ? -n : n;2689 C_word res = C_bignum2(ptr, n < 0, (C_uword)un, (C_uword)(un >> 32));2690 return C_bignum_simplify(res);2691#endif2692}26932694inline static C_word C_uint64_to_num(C_word **ptr, C_u64 n)2695{2696 if(C_ufitsinfixnump(n)) {2697 return C_fix(n);2698 } else {2699#ifdef C_SIXTY_FOUR2700 return C_bignum1(ptr, 0, n);2701#else2702 C_word res = C_bignum2(ptr, 0, (C_uword)n, (C_uword)(n >> 32));2703 return C_bignum_simplify(res);2704#endif2705 }2706}27072708inline static C_word C_long_to_num(C_word **ptr, C_long n)2709{2710 if(C_fitsinfixnump(n)) {2711 return C_fix(n);2712 } else {2713 return C_bignum1(ptr, n < 0, C_wabs(n));2714 }2715}27162717inline static C_word C_unsigned_long_to_num(C_word **ptr, C_ulong n)2718{2719 if(C_ufitsinfixnump(n)) {2720 return C_fix(n);2721 } else {2722 return C_bignum1(ptr, 0, n);2723 }2724}272527262727inline static char *C_string_or_null(C_word x)2728{2729 return C_truep(x) ? C_c_string(x) : NULL;2730}273127322733inline static void *C_data_pointer_or_null(C_word x)2734{2735 return C_truep(x) ? C_data_pointer(x) : NULL;2736}273727382739inline static void *C_srfi_4_vector_or_null(C_word x)2740{2741 return C_truep(x) ? C_srfi_4_vector(x) : NULL;2742}274327442745inline static void *C_c_pointer_vector_or_null(C_word x)2746{2747 return C_truep(x) ? C_data_pointer(C_block_item(x, 2)) : NULL;2748}274927502751inline static void *C_c_pointer_or_null(C_word x)2752{2753 return C_truep(x) ? (void *)C_block_item(x, 0) : NULL;2754}275527562757inline static void *C_scheme_or_c_pointer(C_word x)2758{2759 return C_anypointerp(x) ? (void *)C_block_item(x, 0) : C_data_pointer(x);2760}276127622763inline static C_long C_num_to_long(C_word x)2764{2765 if(x & C_FIXNUM_BIT) {2766 return (C_long)C_unfix(x);2767 } else {2768 if (C_bignum_negativep(x)) return -(C_long)C_bignum_digits(x)[0];2769 else return (C_long)C_bignum_digits(x)[0];2770 }2771}277227732774inline static C_ulong C_num_to_unsigned_long(C_word x)2775{2776 if(x & C_FIXNUM_BIT) {2777 return (C_ulong)C_unfix(x);2778 } else {2779 return (C_ulong)C_bignum_digits(x)[0];2780 }2781}278227832784inline static C_word C_ub_i_flonum_eqvp(double x, double y)2785{2786 /* This can distinguish between -0.0 and +0.0 */2787 return x == y && signbit(x) == signbit(y);2788}27892790inline static C_word basic_eqvp(C_word x, C_word y)2791{2792 return (x == y ||27932794 (!C_immediatep(x) && !C_immediatep(y) &&2795 C_block_header(x) == C_block_header(y) &&27962797 ((C_block_header(x) == C_FLONUM_TAG &&2798 C_ub_i_flonum_eqvp(C_flonum_magnitude(x),2799 C_flonum_magnitude(y))) ||28002801 (C_block_header(x) == C_BIGNUM_TAG &&2802 C_block_header(y) == C_BIGNUM_TAG &&2803 C_i_bignum_cmp(x, y) == C_fix(0)))));2804}28052806inline static C_word C_i_eqvp(C_word x, C_word y)2807{2808 return C_mk_bool(basic_eqvp(x, y) ||2809 (!C_immediatep(x) && !C_immediatep(y) &&2810 C_block_header(x) == C_block_header(y) &&2811 (C_block_header(x) == C_RATNUM_TAG ||2812 C_block_header(x) == C_CPLXNUM_TAG) &&2813 basic_eqvp(C_block_item(x, 0), C_block_item(y, 0)) &&2814 basic_eqvp(C_block_item(x, 1), C_block_item(y, 1))));2815}28162817inline static C_word C_i_symbolp(C_word x)2818{2819 return C_mk_bool(!C_immediatep(x) &&2820 C_block_header(x) == C_SYMBOL_TAG &&2821 C_symbol_plist(x) != C_SCHEME_FALSE);2822}28232824inline static C_word C_i_keywordp(C_word x)2825{2826 return C_mk_bool(!C_immediatep(x) &&2827 C_block_header(x) == C_SYMBOL_TAG &&2828 C_symbol_plist(x) == C_SCHEME_FALSE);2829}28302831inline static int C_persistable_symbol(C_word x)2832{2833 /* Symbol is bound, or has a non-empty plist (but is not a keyword) */2834 return ((C_truep(C_boundp(x)) ||2835 C_symbol_plist(x) != C_SCHEME_END_OF_LIST) &&2836 C_symbol_plist(x) != C_SCHEME_FALSE);2837}28382839inline static C_word C_i_pairp(C_word x)2840{2841 return C_mk_bool(!C_immediatep(x) && C_header_type(x) == C_PAIR_TYPE);2842}28432844inline static C_word C_i_weak_pairp(C_word x)2845{2846 return C_mk_bool(!C_immediatep(x) && C_block_header(x) == C_WEAK_PAIR_TAG);2847}28482849inline static C_word C_i_stringp(C_word x)2850{2851 return C_mk_bool(!C_immediatep(x) && C_header_bits(x) == C_STRING_TYPE);2852}285328542855inline static C_word C_i_locativep(C_word x)2856{2857 return C_mk_bool(!C_immediatep(x) && C_block_header(x) == C_LOCATIVE_TAG);2858}285928602861inline static C_word C_i_vectorp(C_word x)2862{2863 return C_mk_bool(!C_immediatep(x) && C_header_bits(x) == C_VECTOR_TYPE);2864}28652866inline static C_word C_i_srfi_4_vectorp(C_word x)2867{2868 return C_mk_bool(!C_immediatep(x) &&2869 C_header_bits(x) == C_STRUCTURE_TYPE &&2870 (C_truep(C_i_s8vectorp(x)) ||2871 C_truep(C_i_u16vectorp(x)) ||2872 C_truep(C_i_s16vectorp(x)) ||2873 C_truep(C_i_u32vectorp(x)) ||2874 C_truep(C_i_s32vectorp(x)) ||2875 C_truep(C_i_u64vectorp(x)) ||2876 C_truep(C_i_s64vectorp(x)) ||2877 C_truep(C_i_f32vectorp(x)) ||2878 C_truep(C_i_f64vectorp(x))));2879}28802881inline static C_word C_i_portp(C_word x)2882{2883 return C_mk_bool(!C_immediatep(x) && C_header_bits(x) == C_PORT_TYPE);2884}288528862887inline static C_word C_i_closurep(C_word x)2888{2889 return C_mk_bool(!C_immediatep(x) && C_header_bits(x) == C_CLOSURE_TYPE);2890}28912892inline static C_word C_i_numberp(C_word x)2893{2894 return C_mk_bool((x & C_FIXNUM_BIT) ||2895 (!C_immediatep(x) &&2896 (C_block_header(x) == C_FLONUM_TAG ||2897 C_block_header(x) == C_BIGNUM_TAG ||2898 C_block_header(x) == C_RATNUM_TAG ||2899 C_block_header(x) == C_CPLXNUM_TAG)));2900}29012902/* All numbers are real, except for cplxnums */2903inline static C_word C_i_realp(C_word x)2904{2905 return C_mk_bool((x & C_FIXNUM_BIT) ||2906 (!C_immediatep(x) &&2907 (C_block_header(x) == C_FLONUM_TAG ||2908 C_block_header(x) == C_BIGNUM_TAG ||2909 C_block_header(x) == C_RATNUM_TAG)));2910}29112912/* All finite real numbers are rational */2913inline static C_word C_i_rationalp(C_word x)2914{2915 if(x & C_FIXNUM_BIT) {2916 return C_SCHEME_TRUE;2917 } else if (C_immediatep(x)) {2918 return C_SCHEME_FALSE;2919 } else if(C_block_header(x) == C_FLONUM_TAG) {2920 double n = C_flonum_magnitude(x);2921 return C_mk_bool(!C_isinf(n) && !C_isnan(n));2922 } else {2923 return C_mk_bool(C_block_header(x) == C_BIGNUM_TAG ||2924 C_block_header(x) == C_RATNUM_TAG);2925 }2926}292729282929inline static C_word C_u_i_fpintegerp(C_word x)2930{2931 double dummy, val;29322933 val = C_flonum_magnitude(x);29342935 if(C_isnan(val) || C_isinf(val)) return C_SCHEME_FALSE;29362937 return C_mk_bool(C_modf(val, &dummy) == 0.0);2938}293929402941inline static int C_ub_i_fpintegerp(double x)2942{2943 double dummy;29442945 return C_modf(x, &dummy) == 0.0;2946}29472948inline static C_word C_i_exact_integerp(C_word x)2949{2950 return C_mk_bool((x) & C_FIXNUM_BIT || C_truep(C_i_bignump(x)));2951}29522953inline static C_word C_u_i_exactp(C_word x)2954{2955 if (C_truep(C_i_exact_integerp(x))) {2956 return C_SCHEME_TRUE;2957 } else if (C_block_header(x) == C_FLONUM_TAG) {2958 return C_SCHEME_FALSE;2959 } else if (C_block_header(x) == C_RATNUM_TAG) {2960 return C_SCHEME_TRUE;2961 } else if (C_block_header(x) == C_CPLXNUM_TAG) {2962 x = C_u_i_cplxnum_real(x);2963 /* r and i are always the same exactness, and we assume they2964 * always store a number.2965 */2966 return C_mk_bool(C_immediatep(x) || (C_block_header(x) != C_FLONUM_TAG));2967 } else {2968 return C_SCHEME_FALSE;2969 }2970}29712972inline static C_word C_u_i_inexactp(C_word x)2973{2974 if (C_immediatep(x)) {2975 return C_SCHEME_FALSE;2976 } else if (C_block_header(x) == C_FLONUM_TAG) {2977 return C_SCHEME_TRUE;2978 } else if (C_block_header(x) == C_CPLXNUM_TAG) {2979 x = C_u_i_cplxnum_real(x); /* r and i are always the same exactness */2980 return C_mk_bool(!C_immediatep(x) && (C_block_header(x) == C_FLONUM_TAG));2981 } else {2982 return C_SCHEME_FALSE;2983 }2984}29852986inline static C_word C_i_integerp(C_word x)2987{2988 double dummy, val;29892990 if (x & C_FIXNUM_BIT || C_truep(C_i_bignump(x)))2991 return C_SCHEME_TRUE;2992 if (C_immediatep(x) || C_block_header(x) != C_FLONUM_TAG)2993 return C_SCHEME_FALSE;29942995 val = C_flonum_magnitude(x);2996 if(C_isnan(val) || C_isinf(val)) return C_SCHEME_FALSE;29972998 return C_mk_bool(C_modf(val, &dummy) == 0.0);2999}300030013002inline static C_word C_i_flonump(C_word x)3003{3004 return C_mk_bool(!C_immediatep(x) && C_block_header(x) == C_FLONUM_TAG);3005}30063007inline static C_word C_i_cplxnump(C_word x)3008{3009 return C_mk_bool(!C_immediatep(x) && C_block_header(x) == C_CPLXNUM_TAG);3010}30113012inline static C_word C_i_ratnump(C_word x)3013{3014 return C_mk_bool(!C_immediatep(x) && C_block_header(x) == C_RATNUM_TAG);3015}30163017/* TODO: Is this correctly named? Shouldn't it accept an argcount? */3018inline static C_word C_a_u_i_fix_to_big(C_word **ptr, C_word x)3019{3020 x = C_unfix(x);3021 if (x < 0)3022 return C_bignum1(ptr, 1, -x);3023 else if (x == 0)3024 return C_bignum0(ptr);3025 else3026 return C_bignum1(ptr, 0, x);3027}30283029inline static C_word C_i_fixnum_min(C_word x, C_word y)3030{3031 return ((C_word)x < (C_word)y) ? x : y;3032}303330343035inline static C_word C_i_fixnum_max(C_word x, C_word y)3036{3037 return ((C_word)x > (C_word)y) ? x : y;3038}30393040inline static C_word C_i_fixnum_gcd(C_word x, C_word y)3041{3042 x = (x & C_INT_SIGN_BIT) ? -C_unfix(x) : C_unfix(x);3043 y = (y & C_INT_SIGN_BIT) ? -C_unfix(y) : C_unfix(y);30443045 while(y != 0) {3046 C_word r = x % y;3047 x = y;3048 y = r;3049 }3050 return C_fix(x);3051}30523053inline static C_word C_fixnum_divide(C_word x, C_word y)3054{3055 if(y == C_fix(0)) C_div_by_zero_error(C_text("fx/"));3056 return C_u_fixnum_divide(x, y);3057}305830593060inline static C_word C_u_fixnum_modulo(C_word x, C_word y)3061{3062 y = C_unfix(y);3063 x = C_unfix(x) % y;3064 if ((y < 0 && x > 0) || (y > 0 && x < 0)) x += y;3065 return C_fix(x);3066}306730683069inline static C_word C_fixnum_modulo(C_word x, C_word y)3070{3071 if(y == C_fix(0)) {3072 C_div_by_zero_error(C_text("fxmod"));3073 } else {3074 return C_u_fixnum_modulo(x,y);3075 }3076}30773078/* XXX: Naming convention is inconsistent! There's C_fixnum_divide()3079 * but also C_a_i_flonum_quotient_checked()3080 */3081inline static C_word3082C_a_i_fixnum_quotient_checked(C_word **ptr, int c, C_word x, C_word y)3083{3084 if (y == C_fix(0)) {3085 C_div_by_zero_error(C_text("fx/"));3086 } else if (x == C_fix(C_MOST_NEGATIVE_FIXNUM) && y == C_fix(-1)) {3087 return C_bignum1(ptr, 0, -C_MOST_NEGATIVE_FIXNUM); /* Special case */3088 } else {3089 return C_u_fixnum_divide(x, y); /* Inconsistent, too: missing _i_ */3090 }3091}30923093inline static C_word C_i_fixnum_remainder_checked(C_word x, C_word y)3094{3095 if (y == C_fix(0)) {3096 C_div_by_zero_error(C_text("fxrem"));3097 } else {3098 x = C_unfix(x);3099 y = C_unfix(y);3100 return C_fix(x - ((x / y) * y));3101 }3102}31033104inline static C_word C_i_fixnum_arithmetic_shift(C_word n, C_word c)3105{3106 if(C_unfix(c) < 0) return C_fixnum_shift_right(n, C_u_fixnum_negate(c));3107 else return C_fixnum_shift_left(n, c);3108}31093110inline static C_word C_a_i_fixnum_negate(C_word **ptr, C_word n, C_word x)3111{3112 /* Exceptional situation: this will cause an overflow to itself */3113 if (x == C_fix(C_MOST_NEGATIVE_FIXNUM)) /* C_fitsinfixnump(x) */3114 return C_bignum1(ptr, 0, -C_MOST_NEGATIVE_FIXNUM);3115 else3116 return C_fix(-C_unfix(x));3117}31183119inline static C_word C_s_a_u_i_integer_abs(C_word **ptr, C_word n, C_word x)3120{3121 if (x & C_FIXNUM_BIT) {3122 return C_a_i_fixnum_abs(ptr, 1, x);3123 } else if (C_bignum_negativep(x)) {3124 return C_s_a_u_i_integer_negate(ptr, n, x);3125 } else {3126 return x;3127 }3128}31293130/* DEPRECATED */3131inline static C_word C_i_fixnum_bit_to_bool(C_word n, C_word i)3132{3133 if (i & C_INT_SIGN_BIT) {3134 C_not_an_uinteger_error(C_text("bit->boolean"), i);3135 } else {3136 i = C_unfix(i);3137 if (i >= C_WORD_SIZE) return C_mk_bool(n & C_INT_SIGN_BIT);3138 else return C_mk_bool((C_unfix(n) & (C_word)((C_uword)1 << i)) != 0);3139 }3140}31413142inline static C_word C_a_i_fixnum_difference(C_word **ptr, C_word n, C_word x, C_word y)3143{3144 C_word z = C_unfix(x) - C_unfix(y);31453146 if(!C_fitsinfixnump(z)) {3147 return C_bignum1(ptr, z < 0, C_wabs(z));3148 } else {3149 return C_fix(z);3150 }3151}31523153inline static C_word C_a_i_fixnum_plus(C_word **ptr, C_word n, C_word x, C_word y)3154{3155 C_word z = C_unfix(x) + C_unfix(y);31563157 if(!C_fitsinfixnump(z)) {3158 return C_bignum1(ptr, z < 0, C_wabs(z));3159 } else {3160 return C_fix(z);3161 }3162}31633164inline static C_word C_a_i_fixnum_times(C_word **ptr, C_word n, C_word x, C_word y)3165{3166 C_uword negp, xhi, xlo, yhi, ylo, p, rhi, rlo;31673168 negp = ((x & C_INT_SIGN_BIT) ? !(y & C_INT_SIGN_BIT) : (y & C_INT_SIGN_BIT));3169 x = (x & C_INT_SIGN_BIT) ? -C_unfix(x) : C_unfix(x);3170 y = (y & C_INT_SIGN_BIT) ? -C_unfix(y) : C_unfix(y);31713172 xhi = C_BIGNUM_DIGIT_HI_HALF(x); xlo = C_BIGNUM_DIGIT_LO_HALF(x);3173 yhi = C_BIGNUM_DIGIT_HI_HALF(y); ylo = C_BIGNUM_DIGIT_LO_HALF(y);31743175 /* This is simply bignum_digits_multiply unrolled for 2x2 halfdigits */3176 p = xlo * ylo;3177 rlo = C_BIGNUM_DIGIT_LO_HALF(p);31783179 p = xhi * ylo + C_BIGNUM_DIGIT_HI_HALF(p);3180 rhi = C_BIGNUM_DIGIT_HI_HALF(p);31813182 p = xlo * yhi + C_BIGNUM_DIGIT_LO_HALF(p);3183 rlo = C_BIGNUM_DIGIT_COMBINE(C_BIGNUM_DIGIT_LO_HALF(p), rlo);31843185 rhi = xhi * yhi + C_BIGNUM_DIGIT_HI_HALF(p) + rhi;31863187 if (rhi) {3188 return C_bignum2(ptr, negp != 0, rlo, rhi);3189 } else if (negp ?3190 ((rlo & C_INT_SIGN_BIT) || !C_fitsinfixnump(-(C_word)rlo)) :3191 !C_ufitsinfixnump(rlo)) {3192 return C_bignum1(ptr, negp != 0, rlo);3193 } else {3194 return C_fix(negp ? -rlo : rlo);3195 }3196}31973198inline static C_word C_i_flonum_min(C_word x, C_word y)3199{3200 double3201 xf = C_flonum_magnitude(x),3202 yf = C_flonum_magnitude(y);32033204 return xf < yf ? x : y;3205}320632073208inline static C_word C_i_flonum_max(C_word x, C_word y)3209{3210 double3211 xf = C_flonum_magnitude(x),3212 yf = C_flonum_magnitude(y);32133214 return xf > yf ? x : y;3215}32163217inline static C_word C_u_i_integer_signum(C_word x)3218{3219 if (x & C_FIXNUM_BIT) return C_i_fixnum_signum(x);3220 else return (C_bignum_negativep(x) ? C_fix(-1) : C_fix(1));3221}32223223inline static C_word3224C_a_i_flonum_quotient_checked(C_word **ptr, int c, C_word n1, C_word n2)3225{3226 double n3 = C_flonum_magnitude(n2);32273228 if(n3 == 0.0) C_div_by_zero_error(C_text("fp/?"));3229 return C_flonum(ptr, C_flonum_magnitude(n1) / n3);3230}323132323233inline static double3234C_ub_i_flonum_quotient_checked(double n1, double n2)3235{3236 if(n2 == 0.0) C_div_by_zero_error(C_text("fp/?"));3237 return n1 / n2;3238}32393240/* More weirdness: the other flonum_quotient macros and inline functions3241 * do not compute the quotient but the "plain" division!3242 */3243inline static C_word3244C_a_i_flonum_actual_quotient_checked(C_word **ptr, int c, C_word x, C_word y)3245{3246 double dy = C_flonum_magnitude(y), r;32473248 if(dy == 0.0) {3249 C_div_by_zero_error(C_text("quotient"));3250 } else if (!C_truep(C_u_i_fpintegerp(x))) {3251 C_not_an_integer_error(C_text("quotient"), x);3252 } else if (!C_truep(C_u_i_fpintegerp(y))) {3253 C_not_an_integer_error(C_text("quotient"), y);3254 } else {3255 modf(C_flonum_magnitude(x) / dy, &r);3256 return C_flonum(ptr, r);3257 }3258}32593260inline static C_word3261C_a_i_flonum_remainder_checked(C_word **ptr, int c, C_word x, C_word y)3262{3263 double dx = C_flonum_magnitude(x),3264 dy = C_flonum_magnitude(y), r;32653266 if(dy == 0.0) {3267 C_div_by_zero_error(C_text("remainder"));3268 } else if (!C_truep(C_u_i_fpintegerp(x))) {3269 C_not_an_integer_error(C_text("remainder"), x);3270 } else if (!C_truep(C_u_i_fpintegerp(y))) {3271 C_not_an_integer_error(C_text("remainder"), y);3272 } else {3273 modf(dx / dy, &r);3274 return C_flonum(ptr, dx - r * dy);3275 }3276}32773278inline static C_word3279C_a_i_flonum_modulo_checked(C_word **ptr, int c, C_word x, C_word y)3280{3281 double dx = C_flonum_magnitude(x),3282 dy = C_flonum_magnitude(y), r;32833284 if(dy == 0.0) {3285 C_div_by_zero_error(C_text("modulo"));3286 } else if (!C_truep(C_u_i_fpintegerp(x))) {3287 C_not_an_integer_error(C_text("modulo"), x);3288 } else if (!C_truep(C_u_i_fpintegerp(y))) {3289 C_not_an_integer_error(C_text("modulo"), y);3290 } else {3291 modf(dx / dy, &r);3292 r = dx - r * dy;3293 if ((dy < 0 && r > 0) || (dy > 0 && r < 0)) r += y;3294 return C_flonum(ptr, r);3295 }3296}32973298inline static C_word C_i_safe_pointerp(C_word x)3299{3300 if(C_immediatep(x)) return C_SCHEME_FALSE;33013302 switch(C_block_header(x)) {3303 case C_POINTER_TAG:3304 case C_TAGGED_POINTER_TAG:3305 return C_SCHEME_TRUE;3306 }33073308 return C_SCHEME_FALSE;3309}331033113312inline static C_word C_u_i_assq(C_word x, C_word lst)3313{3314 C_word a;33153316 while(!C_immediatep(lst)) {3317 a = C_u_i_car(lst);33183319 if(C_u_i_car(a) == x) return a;3320 else lst = C_u_i_cdr(lst);3321 }33223323 return C_SCHEME_FALSE;3324}332533263327inline static C_word3328C_fast_retrieve(C_word sym)3329{3330 C_word val = C_block_item(sym, 0);33313332 if(val == C_SCHEME_UNBOUND)3333 C_unbound_variable(sym);33343335 return val;3336}33373338inline static void *3339C_fast_retrieve_proc(C_word closure)3340{3341 if(C_immediatep(closure) || C_header_bits(closure) != C_CLOSURE_TYPE)3342 return (void *)C_invalid_procedure;3343 else3344 return (void *)C_block_item(closure, 0);3345}334633473348inline static void *3349C_fast_retrieve_symbol_proc(C_word sym)3350{3351 return C_fast_retrieve_proc(C_fast_retrieve(sym));3352}335333543355inline static C_word C_a_i_vector1(C_word **ptr, int n, C_word x1)3356{3357 C_word *p = *ptr, *p0 = p;33583359 *(p++) = C_VECTOR_TYPE | 1;3360 *(p++) = x1;3361 *ptr = p;3362 return (C_word)p0;3363}336433653366inline static C_word C_a_i_vector2(C_word **ptr, int n, C_word x1, C_word x2)3367{3368 C_word *p = *ptr, *p0 = p;33693370 *(p++) = C_VECTOR_TYPE | 2;3371 *(p++) = x1;3372 *(p++) = x2;3373 *ptr = p;3374 return (C_word)p0;3375}337633773378inline static C_word C_a_i_vector3(C_word **ptr, int n, C_word x1, C_word x2, C_word x3)3379{3380 C_word *p = *ptr, *p0 = p;33813382 *(p++) = C_VECTOR_TYPE | 3;3383 *(p++) = x1;3384 *(p++) = x2;3385 *(p++) = x3;3386 *ptr = p;3387 return (C_word)p0;3388}338933903391inline static C_word C_a_i_vector4(C_word **ptr, int n, C_word x1, C_word x2, C_word x3, C_word x4)3392{3393 C_word *p = *ptr, *p0 = p;33943395 *(p++) = C_VECTOR_TYPE | 4;3396 *(p++) = x1;3397 *(p++) = x2;3398 *(p++) = x3;3399 *(p++) = x4;3400 *ptr = p;3401 return (C_word)p0;3402}340334043405inline static C_word C_a_i_vector5(C_word **ptr, int n, C_word x1, C_word x2, C_word x3, C_word x4,3406 C_word x5)3407{3408 C_word *p = *ptr, *p0 = p;34093410 *(p++) = C_VECTOR_TYPE | 5;3411 *(p++) = x1;3412 *(p++) = x2;3413 *(p++) = x3;3414 *(p++) = x4;3415 *(p++) = x5;3416 *ptr = p;3417 return (C_word)p0;3418}341934203421inline static C_word C_a_i_vector6(C_word **ptr, int n, C_word x1, C_word x2, C_word x3, C_word x4,3422 C_word x5, C_word x6)3423{3424 C_word *p = *ptr, *p0 = p;34253426 *(p++) = C_VECTOR_TYPE | 6;3427 *(p++) = x1;3428 *(p++) = x2;3429 *(p++) = x3;3430 *(p++) = x4;3431 *(p++) = x5;3432 *(p++) = x6;3433 *ptr = p;3434 return (C_word)p0;3435}343634373438inline static C_word C_a_i_vector7(C_word **ptr, int n, C_word x1, C_word x2, C_word x3, C_word x4,3439 C_word x5, C_word x6, C_word x7)3440{3441 C_word *p = *ptr, *p0 = p;34423443 *(p++) = C_VECTOR_TYPE | 7;3444 *(p++) = x1;3445 *(p++) = x2;3446 *(p++) = x3;3447 *(p++) = x4;3448 *(p++) = x5;3449 *(p++) = x6;3450 *(p++) = x7;3451 *ptr = p;3452 return (C_word)p0;3453}345434553456inline static C_word C_a_i_vector8(C_word **ptr, int n, C_word x1, C_word x2, C_word x3, C_word x4,3457 C_word x5, C_word x6, C_word x7, C_word x8)3458{3459 C_word *p = *ptr, *p0 = p;34603461 *(p++) = C_VECTOR_TYPE | 8;3462 *(p++) = x1;3463 *(p++) = x2;3464 *(p++) = x3;3465 *(p++) = x4;3466 *(p++) = x5;3467 *(p++) = x6;3468 *(p++) = x7;3469 *(p++) = x8;3470 *ptr = p;3471 return (C_word)p0;3472}347334743475inline static C_word C_a_ustring(C_word **ptr, int n, C_word bv, C_word c)3476{3477 C_word *p = *ptr, *p0 = p;34783479 *(p++) = C_STRING_TAG;3480 *(p++) = bv;3481 *(p++) = c;3482 *(p++) = C_fix(0);3483 *(p++) = C_fix(0);3484 *ptr = p;3485 return (C_word)p0;3486}348734883489inline static C_word C_a_pair(C_word **ptr, C_word car, C_word cdr)3490{3491 C_word *p = *ptr, *p0 = p;34923493 *(p++) = C_PAIR_TYPE | (C_SIZEOF_PAIR - 1);3494 *(p++) = car;3495 *(p++) = cdr;3496 *ptr = p;3497 return (C_word)p0;3498}34993500inline static C_word C_a_weak_pair(C_word **ptr, C_word head, C_word tail)3501{3502 C_word *p = *ptr, *p0 = p;35033504 *(p++) = C_WEAK_PAIR_TAG; /* Changes to strong if sym is persisted */3505 *(p++) = head;3506 *(p++) = tail;3507 *ptr = p;3508 return (C_word)p0;3509}351035113512inline static C_word C_a_i_list1(C_word **a, int n, C_word x1)3513{3514 return C_a_pair(a, x1, C_SCHEME_END_OF_LIST);3515}351635173518inline static C_word C_a_i_list2(C_word **a, int n, C_word x1, C_word x2)3519{3520 C_word x = C_a_pair(a, x2, C_SCHEME_END_OF_LIST);35213522 return C_a_pair(a, x1, x);3523}352435253526inline static C_word C_a_i_list3(C_word **a, int n, C_word x1, C_word x2, C_word x3)3527{3528 C_word x = C_a_pair(a, x3, C_SCHEME_END_OF_LIST);35293530 x = C_a_pair(a, x2, x);3531 return C_a_pair(a, x1, x);3532}353335343535inline static C_word C_a_i_list4(C_word **a, int n, C_word x1, C_word x2, C_word x3, C_word x4)3536{3537 C_word x = C_a_pair(a, x4, C_SCHEME_END_OF_LIST);35383539 x = C_a_pair(a, x3, x);3540 x = C_a_pair(a, x2, x);3541 return C_a_pair(a, x1, x);3542}354335443545inline static C_word C_a_i_list5(C_word **a, int n, C_word x1, C_word x2, C_word x3, C_word x4,3546 C_word x5)3547{3548 C_word x = C_a_pair(a, x5, C_SCHEME_END_OF_LIST);35493550 x = C_a_pair(a, x4, x);3551 x = C_a_pair(a, x3, x);3552 x = C_a_pair(a, x2, x);3553 return C_a_pair(a, x1, x);3554}355535563557inline static C_word C_a_i_list6(C_word **a, int n, C_word x1, C_word x2, C_word x3, C_word x4,3558 C_word x5, C_word x6)3559{3560 C_word x = C_a_pair(a, x6, C_SCHEME_END_OF_LIST);35613562 x = C_a_pair(a, x5, x);3563 x = C_a_pair(a, x4, x);3564 x = C_a_pair(a, x3, x);3565 x = C_a_pair(a, x2, x);3566 return C_a_pair(a, x1, x);3567}356835693570inline static C_word C_a_i_list7(C_word **a, int n, C_word x1, C_word x2, C_word x3, C_word x4,3571 C_word x5, C_word x6, C_word x7)3572{3573 C_word x = C_a_pair(a, x7, C_SCHEME_END_OF_LIST);35743575 x = C_a_pair(a, x6, x);3576 x = C_a_pair(a, x5, x);3577 x = C_a_pair(a, x4, x);3578 x = C_a_pair(a, x3, x);3579 x = C_a_pair(a, x2, x);3580 return C_a_pair(a, x1, x);3581}358235833584inline static C_word C_a_i_list8(C_word **a, int n, C_word x1, C_word x2, C_word x3, C_word x4,3585 C_word x5, C_word x6, C_word x7, C_word x8)3586{3587 C_word x = C_a_pair(a, x8, C_SCHEME_END_OF_LIST);35883589 x = C_a_pair(a, x7, x);3590 x = C_a_pair(a, x6, x);3591 x = C_a_pair(a, x5, x);3592 x = C_a_pair(a, x4, x);3593 x = C_a_pair(a, x3, x);3594 x = C_a_pair(a, x2, x);3595 return C_a_pair(a, x1, x);3596}359735983599/*3600 * From Hacker's Delight by Henry S. Warren3601 * based on a modified nlz() from section 5-3 (fig. 5-7)3602 */3603inline static int C_ilen(C_uword x)3604{3605 C_uword y;3606 C_word n = 0;36073608#ifdef C_SIXTY_FOUR3609 y = x >> 32; if (y != 0) { n += 32; x = y; }3610#endif3611 y = x >> 16; if (y != 0) { n += 16; x = y; }3612 y = x >> 8; if (y != 0) { n += 8; x = y; }3613 y = x >> 4; if (y != 0) { n += 4; x = y; }3614 y = x >> 2; if (y != 0) { n += 2; x = y; }3615 y = x >> 1; if (y != 0) return n + 2;3616 return n + x;3617}36183619/* These strl* functions are based on public domain code by C.B. Falconer */3620#ifdef HAVE_STRLCPY3621# define C_strlcpy strlcpy3622#else3623inline static size_t C_strlcpy(char *dst, const char *src, size_t sz)3624{3625 const char *start = src;36263627 if (sz--) {3628 while ((*dst++ = *src))3629 if (sz--) src++;3630 else {3631 *(--dst) = '\0';3632 break;3633 }3634 }3635 while (*src++) continue;3636 return src - start - 1;3637}3638#endif36393640#ifdef HAVE_STRLCAT3641# define C_strlcat strlcat3642#else3643inline static size_t C_strlcat(char *dst, const char *src, size_t sz)3644{3645 char *start = dst;36463647 while (*dst++) /* assumes sz >= strlen(dst) */3648 if (sz) sz--; /* i.e. well formed string */3649 dst--;3650 return dst - start + C_strlcpy(dst, src, sz);3651}3652#endif36533654/*3655 * MinGW's stat() is less than ideal in a couple of ways, so we provide a3656 * wrapper that:3657 *3658 * 1. Strips all trailing slashes and retries on failure, since stat() will3659 * yield ENOENT when given two (on MSYS) or more (on MinGW and MSYS2).3660 * 2. Fails with ENOTDIR when given a path to a non-directory file that ends3661 * in a slash, since in this case MinGW's stat() will succeed but return a3662 * non-directory mode in buf.st_mode.3663 */3664#if defined(__MINGW32__)3665inline static int C_stat(const C_WCHAR *path, struct _stat64i32 *buf)3666{3667 size_t len = wcslen(path);3668 C_WCHAR slash = len && wcschr(L"\\/", path[len - 1]), *str;36693670 if(_wstat(path, buf) == 0)3671 goto dircheck;36723673 if(slash && errno == ENOENT) {3674 C_memcpy((str = (C_WCHAR *)C_alloca((len + 1) * sizeof(C_WCHAR))), path,3675 (len + 1) * sizeof(C_WCHAR));3676 while(len > 1 && wcschr(L"\\/", path[--len]))3677 str[len] = '\0';3678 if(_wstat(str, buf) == 0)3679 goto dircheck;3680 }36813682 return -1;36833684dircheck:3685 if(slash && !S_ISDIR(buf->st_mode)) {3686 errno = ENOTDIR;3687 return -1;3688 }36893690 return 0;3691}3692/*3693 * Haiku's stat() has a similar issue, where it will gladly succeed3694 * when given a path to a filename with a trailing slash.3695 */3696#elif defined(__HAIKU__)3697inline static int C_stat(const char *path, struct stat *buf)3698{3699 size_t len = C_strlen(path);3700 char slash = len && path[len - 1] == '/';37013702 if(stat(path, buf) != 0) {3703 return -1;3704 }37053706 if (slash && !S_ISDIR(buf->st_mode)) {3707 errno = ENOTDIR;3708 return -1;3709 }37103711 return 0;3712}3713#else3714# define C_stat stat3715#endif37163717/* Safe realpath usage depends on a reliable PATH_MAX. */3718#ifdef PATH_MAX3719# define C_realpath realpath3720#else3721inline static char *C_realpath(const char *path, char *resolved)3722{3723# if _POSIX_C_SOURCE >= 200809L3724 char *p;3725 size_t n;3726 if((p = realpath(path, NULL)) == NULL)3727 return NULL;3728 n = C_strlcpy(resolved, p, C_MAX_PATH);3729 C_free(p);3730 if(n < C_MAX_PATH)3731 return resolved;3732# endif3733 return NULL;3734}3735#endif37363737C_END_C_DECLS37383739#endif /* ___CHICKEN */