Move version stuff from main.c into env.c

This commit is contained in:
Lassi Kortela 2019-10-17 19:25:49 +03:00
parent 66af12605b
commit 1108480bd6
4 changed files with 243 additions and 224 deletions

233
c/env.c Normal file
View File

@ -0,0 +1,233 @@
#include <sys/types.h>
#include <assert.h>
#include <limits.h>
#include <math.h>
#include <setjmp.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "scheme.h"
static value_t get_features_list(void)
{
static struct accum acc;
static int initialized;
if (!initialized) {
initialized = 1;
accum_init(&acc);
#ifdef BITS64
accum_elt(&acc, symbol("64-bit"));
#endif
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
accum_elt(&acc, symbol("big-endian"));
#endif
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
accum_elt(&acc, symbol("little-endian"));
#endif
accum_elt(&acc, symbol("r7rs"));
}
return acc.list;
}
static value_t build_c_type_bits_list(void)
{
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 build_stable_specs_list(void)
{
struct accum acc;
const int *p;
accum_init(&acc);
for (p = upscheme_stable_specs; *p; p++) {
accum_elt(&acc, fixnum(*p));
}
return acc.list;
}
static value_t build_platform_list(void)
{
struct accum acc;
const char *kernel;
const char *userland;
const char *computer;
const char *endian;
// <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 __sun
userland = kernel = "solaris";
#endif
#ifdef __minix
userland = kernel = "minix";
#endif
#ifdef __HAIKU__
userland = "beos";
kernel = "haiku";
#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;
}
value_t get_version_alist(void)
{
static struct accum acc;
static int initialized;
if (!initialized) {
initialized = 1;
accum_init(&acc);
accum_name_value1(&acc, "command", string_from_cstr("upscheme"));
accum_name_value1(&acc, "scheme-id", symbol("upscheme"));
accum_name_value(
&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", build_platform_list());
accum_name_value(&acc, "c-type-bits", build_c_type_bits_list());
accum_name_value1(&acc, "c-compiler-version",
string_from_cstr(SCHEME_C_COMPILER_NAME
" " SCHEME_C_COMPILER_VERSION));
accum_name_value1(&acc, "c-compiler-command",
string_from_cstr(env_build_cc));
accum_name_value1(&acc, "c-compiler-flags",
string_from_cstr(env_build_cflags));
accum_name_value1(&acc, "c-linker-flags",
string_from_cstr(env_build_lflags));
accum_name_value1(&acc, "revision",
string_from_cstr(env_build_revision));
accum_name_value1(&acc, "build-date",
string_from_cstr(env_build_date));
accum_name_value1(&acc, "release", string_from_cstr(env_release));
accum_name_value1(&acc, "release-date",
string_from_cstr(env_release_date));
accum_name_value(&acc, "upscheme/stable-specs",
build_stable_specs_list());
accum_name_value1(&acc, "upscheme/unstable-spec",
fixnum(upscheme_unstable_spec));
}
return acc.list;
}
value_t builtin_features(value_t *args, uint32_t nargs)
{
(void)args;
argcount("features", nargs, 0);
return get_features_list();
}
value_t builtin_version_alist(value_t *args, uint32_t nargs)
{
(void)args;
argcount("version-alist", nargs, 0);
return get_version_alist();
}

221
c/main.c
View File

@ -1,7 +1,6 @@
#include <sys/types.h>
#include <assert.h>
#include <limits.h>
#include <math.h>
#include <setjmp.h>
#include <stdarg.h>
@ -16,226 +15,6 @@
#define BOOT_ENV_R7RS 1
#define BOOT_ENV_UNSTABLE 2
static value_t get_features_list(void)
{
static struct accum acc;
static int initialized;
if (!initialized) {
initialized = 1;
accum_init(&acc);
#ifdef BITS64
accum_elt(&acc, symbol("64-bit"));
#endif
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
accum_elt(&acc, symbol("big-endian"));
#endif
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
accum_elt(&acc, symbol("little-endian"));
#endif
accum_elt(&acc, symbol("r7rs"));
}
return acc.list;
}
static value_t build_c_type_bits_list(void)
{
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 build_stable_specs_list(void)
{
struct accum acc;
const int *p;
accum_init(&acc);
for (p = upscheme_stable_specs; *p; p++) {
accum_elt(&acc, fixnum(*p));
}
return acc.list;
}
static value_t build_platform_list(void)
{
struct accum acc;
const char *kernel;
const char *userland;
const char *computer;
const char *endian;
// <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 __sun
userland = kernel = "solaris";
#endif
#ifdef __minix
userland = kernel = "minix";
#endif
#ifdef __HAIKU__
userland = "beos";
kernel = "haiku";
#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;
static int initialized;
if (!initialized) {
initialized = 1;
accum_init(&acc);
accum_name_value1(&acc, "command", string_from_cstr("upscheme"));
accum_name_value1(&acc, "scheme-id", symbol("upscheme"));
accum_name_value(
&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", build_platform_list());
accum_name_value(&acc, "c-type-bits", build_c_type_bits_list());
accum_name_value1(&acc, "c-compiler-version",
string_from_cstr(SCHEME_C_COMPILER_NAME
" " SCHEME_C_COMPILER_VERSION));
accum_name_value1(&acc, "c-compiler-command",
string_from_cstr(env_build_cc));
accum_name_value1(&acc, "c-compiler-flags",
string_from_cstr(env_build_cflags));
accum_name_value1(&acc, "c-linker-flags",
string_from_cstr(env_build_lflags));
accum_name_value1(&acc, "revision",
string_from_cstr(env_build_revision));
accum_name_value1(&acc, "build-date",
string_from_cstr(env_build_date));
accum_name_value1(&acc, "release", string_from_cstr(env_release));
accum_name_value1(&acc, "release-date",
string_from_cstr(env_release_date));
accum_name_value(&acc, "upscheme/stable-specs",
build_stable_specs_list());
accum_name_value1(&acc, "upscheme/unstable-spec",
fixnum(upscheme_unstable_spec));
}
return acc.list;
}
value_t builtin_features(value_t *args, uint32_t nargs)
{
(void)args;
argcount("features", nargs, 0);
return get_features_list();
}
value_t builtin_version_alist(value_t *args, uint32_t nargs)
{
(void)args;
argcount("version-alist", nargs, 0);
return get_version_alist();
}
static value_t argv_list(int argc, char *argv[])
{
int i;

View File

@ -1003,6 +1003,14 @@ void argcount(const char *fname, uint32_t nargs, uint32_t c);
const char *env_get_os_name(void);
// env.c
value_t get_version_alist(void);
value_t builtin_features(value_t *args, uint32_t nargs);
value_t builtin_version_alist(value_t *args, uint32_t nargs);
// env_*.c
value_t builtin_environment_stack(value_t *args, uint32_t nargs);
extern const char env_build_cc[];
@ -1023,9 +1031,6 @@ value_t builtin_import(value_t *args, uint32_t nargs);
//// #include "builtins.h"
value_t builtin_features(value_t *args, uint32_t nargs);
value_t builtin_version_alist(value_t *args, uint32_t nargs);
value_t builtin_pid(value_t *args, uint32_t nargs);
value_t builtin_parent_pid(value_t *args, uint32_t nargs);
value_t builtin_process_group(value_t *args, uint32_t nargs);

View File

@ -16,6 +16,7 @@ o_files="$o_files buf.o"
o_files="$o_files builtins.o"
o_files="$o_files char.o"
o_files="$o_files dump.o"
o_files="$o_files env.o"
o_files="$o_files env_build.o"
o_files="$o_files env_release.o"
o_files="$o_files env_unix.o"
@ -115,6 +116,7 @@ $CC $CFLAGS -c ../c/buf.c
$CC $CFLAGS -c ../c/builtins.c
$CC $CFLAGS -c ../c/char.c
$CC $CFLAGS -c ../c/dump.c
$CC $CFLAGS -c ../c/env.c
$CC $CFLAGS -c ../c/env_build.c
$CC $CFLAGS -c ../c/env_release.c
$CC $CFLAGS -c ../c/env_unix.c