Add platform and C types to version alist

This commit is contained in:
Lassi Kortela 2019-10-14 14:06:20 +03:00
parent 7da26c7170
commit d6086ba9e3
1 changed files with 125 additions and 0 deletions

125
c/main.c
View File

@ -1,6 +1,7 @@
#include <sys/types.h>
#include <assert.h>
#include <limits.h>
#include <math.h>
#include <setjmp.h>
#include <stdarg.h>
@ -37,6 +38,128 @@ static value_t get_features_list(void)
return acc.list;
}
static value_t get_c_type_bits_list(void)
{
static struct accum acc;
accum_init(&acc);
accum_name_value1(&acc, "int", fixnum(sizeof(int) * CHAR_BIT));
accum_name_value1(&acc, "long", fixnum(sizeof(long) * CHAR_BIT));
accum_name_value1(&acc, "float", fixnum(sizeof(float) * CHAR_BIT));
accum_name_value1(&acc, "double", fixnum(sizeof(double) * CHAR_BIT));
accum_name_value1(&acc, "pointer", fixnum(sizeof(void *) * CHAR_BIT));
accum_name_value1(&acc, "size_t", fixnum(sizeof(size_t) * CHAR_BIT));
accum_name_value1(&acc, "value_t", fixnum(sizeof(value_t) * CHAR_BIT));
return acc.list;
}
static value_t get_platform(void)
{
const char *kernel;
const char *userland;
const char *computer;
const char *endian;
static struct accum acc;
// <http://predef.sf.net/>
kernel = userland = computer = endian = "unknown";
#ifdef __FreeBSD__
kernel = userland = "freebsd";
#endif
#ifdef __FreeBSD_kernel__
kernel = "freebsd";
#endif
#ifdef __GLIBC__
userland = "gnu";
#endif
#ifdef __OpenBSD__
userland = kernel = "openbsd";
#endif
#ifdef __NetBSD__
userland = kernel = "netbsd";
#endif
#ifdef __DragonFly__
userland = kernel = "dragonfly";
#endif
#ifdef __APPLE__
userland = kernel = "darwin";
#endif
#ifdef _WIN32
kernel = userland = "windows-nt";
#endif
#ifdef __i386
computer = "x86";
#endif
#ifdef _M_IX86
computer = "x86";
#endif
#ifdef __X86__
computer = "x86";
#endif
#ifdef __I86__
computer = "x86";
#endif
#ifdef __amd64
computer = "x86-64";
#endif
#ifdef __x86_64
computer = "x86-64";
#endif
#ifdef _M_AMD64
computer = "x86-64";
#endif
#ifdef __ppc__
computer = "ppc";
#endif
#ifdef _M_PPC
computer = "ppc";
#endif
#ifdef __PPC64__
computer = "ppc-64";
#endif
#ifdef __mips64__
computer = "mips-64";
#endif
#ifdef __arm__
computer = "arm";
#endif
#ifdef __aarch64__
computer = "arm";
#endif
#ifdef __sparc
computer = "sparc";
#endif
#ifdef __sparc__
computer = "sparc";
#endif
#ifdef __sparc64__
computer = "sparc";
#endif
#ifdef __mips__
computer = "mips";
#endif
#ifdef __mips64__
computer = "mips";
#endif
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
endian = "big";
#endif
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
endian = "little";
#endif
accum_init(&acc);
accum_name_value1(&acc, "kernel", symbol(kernel));
accum_name_value1(&acc, "userland", symbol(userland));
accum_name_value1(&acc, "computer", symbol(computer));
accum_name_value1(&acc, "endian", symbol(endian));
return acc.list;
}
static value_t get_version_alist(void)
{
static struct accum acc;
@ -51,10 +174,12 @@ static value_t get_version_alist(void)
&acc, "language",
fl_cons(symbol("scheme"), fl_cons(symbol("r7rs"), FL_NIL)));
accum_name_value(&acc, "features", get_features_list());
accum_name_value(&acc, "platform", get_platform());
accum_name_value(
&acc, "c-compiler",
fl_list2(string_from_cstr(SCHEME_C_COMPILER_NAME),
string_from_cstr(SCHEME_C_COMPILER_VERSION)));
accum_name_value(&acc, "c-type-bits", get_c_type_bits_list());
}
return acc.list;
}