From 39fd5a954a40eb80995705cb0055757e540d5d74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kochma=C5=84ski?= Date: Thu, 24 Nov 2022 22:50:31 +0100 Subject: [PATCH] boot: add a file boot.d for booting the core Currently it contains only option setters. --- src/c/Makefile.in | 2 +- src/c/boot.d | 87 +++++++++++++++++++++++++++++++++++++++++++++++ src/c/main.d | 76 ----------------------------------------- src/h/external.h | 2 +- 4 files changed, 89 insertions(+), 78 deletions(-) create mode 100644 src/c/boot.d diff --git a/src/c/Makefile.in b/src/c/Makefile.in index a9dd458c6..b42bc7a6f 100644 --- a/src/c/Makefile.in +++ b/src/c/Makefile.in @@ -50,7 +50,7 @@ HFILES = $(HDIR)/config.h $(HDIR)/ecl.h $(HDIR)/ecl-cmp.h $(HDIR)/object.h $(HDIR)/impl/math_dispatch.h $(HDIR)/impl/math_fenv.h \ $(HDIR)/impl/math_fenv_msvc.h $(HDIR)/nucleus.h -BOOT_OBJS = escape.o +BOOT_OBJS = boot.o escape.o CLOS_OBJS = clos/cache.o clos/accessor.o clos/instance.o clos/gfun.o diff --git a/src/c/boot.d b/src/c/boot.d new file mode 100644 index 000000000..15684066e --- /dev/null +++ b/src/c/boot.d @@ -0,0 +1,87 @@ +/* -*- Mode: C; c-basic-offset: 2; indent-tabs-mode: nil -*- */ +/* vim: set filetype=c tabstop=2 shiftwidth=2 expandtab: */ + +/* boot.c - initializing ecl internal data */ + +/* -- imports ------------------------------------------------------- */ + +#include +#include + +/* -- implementation------------------------------------------------- */ + +#if ECL_FIXNUM_BITS <= 32 +/* 1GB */ +#define ECL_DEFAULT_HEAP_SIZE 1073741824L +#else +/* 4GB */ +#define ECL_DEFAULT_HEAP_SIZE 4294967296L +#endif + +#ifndef ECL_DEFAULT_C_STACK_SIZE +#define ECL_DEFAULT_C_STACK_SIZE 0 +#endif + +#ifdef GBC_BOEHM_GENGC +#define ECL_INCREMENTAL_GC 1 +#else +#define ECL_INCREMENTAL_GC 0 +#endif + +#if defined(ECL_THREADS) && defined(HAVE_SIGPROCMASK) +#define ECL_SIGNAL_HANDLING_THREAD 1 +#else +#define ECL_SIGNAL_HANDLING_THREAD 0 +#endif + +/* INV: see ecl_option enum in external.h */ +cl_fixnum ecl_option_values[ECL_OPT_LIMIT+1] = { + /* ---------------------------------------------------------------- */ + ECL_INCREMENTAL_GC, /* ECL_OPT_INCREMENTAL_GC */ + 1, /* ECL_OPT_TRAP_SIGSEGV */ + 1, /* ECL_OPT_TRAP_SIGFPE */ + 1, /* ECL_OPT_TRAP_SIGINT */ + 1, /* ECL_OPT_TRAP_SIGILL */ + 1, /* ECL_OPT_TRAP_SIGBUS */ + 1, /* ECL_OPT_TRAP_SIGPIPE */ + 1, /* ECL_OPT_TRAP_INTERRUPT_SIGNAL */ + ECL_SIGNAL_HANDLING_THREAD, /* ECL_OPT_SIGNAL_HANDLING_THREAD */ + 16, /* ECL_OPT_SIGNAL_QUEUE_SIZE */ + 0, /* ECL_OPT_BOOTED */ + /* ---------------------------------------------------------------- */ + 8192, /* ECL_OPT_BIND_STACK_SIZE */ + 1024, /* ECL_OPT_BIND_STACK_SAFETY_AREA */ + 2048, /* ECL_OPT_FRAME_STACK_SIZE */ + 128, /* ECL_OPT_FRAME_STACK_SAFETY_AREA */ + 32768, /* ECL_OPT_LISP_STACK_SIZE */ + 128, /* ECL_OPT_LISP_STACK_SAFETY_AREA */ + ECL_DEFAULT_C_STACK_SIZE, /* ECL_OPT_C_STACK_SIZE */ + 4*sizeof(cl_index)*1024, /* ECL_OPT_C_STACK_SAFETY_AREA */ + ECL_DEFAULT_HEAP_SIZE, /* ECL_OPT_HEAP_SIZE */ + 1024*1024, /* ECL_OPT_HEAP_SAFETY_AREA */ + 0, /* ECL_OPT_THREAD_INTERRUPT_SIGNAL */ + 1, /* ECL_OPT_SET_GMP_MEMORY_FUNCTIONS */ + 1, /* ECL_OPT_USE_SETMODE_ON_FILES */ + /* ---------------------------------------------------------------- */ + 0}; + +cl_fixnum +ecl_get_option(int option) +{ + if (option >= ECL_OPT_LIMIT || option < 0) { + return -1; + } + return ecl_option_values[option]; +} + +cl_fixnum +ecl_set_option(int option, cl_fixnum value) +{ + if (option > ECL_OPT_LIMIT || option < 0) { + return -1; + } + if (option >= ECL_OPT_BOOTED || !ecl_option_values[ECL_OPT_BOOTED]) { + ecl_option_values[option] = value; + } + return ecl_option_values[option]; +} diff --git a/src/c/main.d b/src/c/main.d index 4889a0926..0da0f993f 100644 --- a/src/c/main.d +++ b/src/c/main.d @@ -136,84 +136,8 @@ ecl_def_ct_token(ecl_ct_dummy_tag ,ecl_stp_constant,ecl_ct_dtag_string,ECL_NIL, /************************ GLOBAL INITIALIZATION ***********************/ - -/* HEAP */ - -#if ECL_FIXNUM_BITS <= 32 -/* 1GB */ -#define HEAP_SIZE_DEFAULT 1073741824L -#else -/* 4GB */ -#define HEAP_SIZE_DEFAULT 4294967296L -#endif - - static int ARGC; static char **ARGV; -/* INV: see ecl_option enum in external.h */ -cl_fixnum ecl_option_values[ECL_OPT_LIMIT+1] = { -#ifdef GBC_BOEHM_GENGC - 1, /* ECL_OPT_INCREMENTAL_GC */ -#else - 0, /* ECL_OPT_INCREMENTAL_GC */ -#endif - 1, /* ECL_OPT_TRAP_SIGSEGV */ - 1, /* ECL_OPT_TRAP_SIGFPE */ - 1, /* ECL_OPT_TRAP_SIGINT */ - 1, /* ECL_OPT_TRAP_SIGILL */ - 1, /* ECL_OPT_TRAP_SIGBUS */ - 1, /* ECL_OPT_TRAP_SIGPIPE */ - 1, /* ECL_OPT_TRAP_INTERRUPT_SIGNAL */ -#if defined(ECL_THREADS) && defined(HAVE_SIGPROCMASK) - 1, /* ECL_OPT_SIGNAL_HANDLING_THREAD */ -#else - 0, /* ECL_OPT_SIGNAL_HANDLING_THREAD */ -#endif - 16, /* ECL_OPT_SIGNAL_QUEUE_SIZE */ - 0, /* ECL_OPT_BOOTED */ - 8192, /* ECL_OPT_BIND_STACK_SIZE */ - 1024, /* ECL_OPT_BIND_STACK_SAFETY_AREA */ - 2048, /* ECL_OPT_FRAME_STACK_SIZE */ - 128, /* ECL_OPT_FRAME_STACK_SAFETY_AREA */ - 32768, /* ECL_OPT_LISP_STACK_SIZE */ - 128, /* ECL_OPT_LISP_STACK_SAFETY_AREA */ - ECL_DEFAULT_C_STACK_SIZE, /* ECL_OPT_C_STACK_SIZE */ - 4*sizeof(cl_index)*1024, /* ECL_OPT_C_STACK_SAFETY_AREA */ - HEAP_SIZE_DEFAULT, /* ECL_OPT_HEAP_SIZE */ - 1024*1024, /* ECL_OPT_HEAP_SAFETY_AREA */ - 0, /* ECL_OPT_THREAD_INTERRUPT_SIGNAL */ - 1, /* ECL_OPT_SET_GMP_MEMORY_FUNCTIONS */ - 1, /* ECL_OPT_USE_SETMODE_ON_FILES */ - 0}; - -#if !defined(GBC_BOEHM) -static char stdin_buf[BUFSIZ]; -static char stdout_buf[BUFSIZ]; -#endif - -cl_fixnum -ecl_get_option(int option) -{ - if (option >= ECL_OPT_LIMIT || option < 0) { - FEerror("Invalid boot option ~D", 1, ecl_make_fixnum(option)); - } - return ecl_option_values[option]; -} - -void -ecl_set_option(int option, cl_fixnum value) -{ - if (option > ECL_OPT_LIMIT || option < 0) { - FEerror("Invalid boot option ~D", 1, ecl_make_fixnum(option)); - } else { - if (option < ECL_OPT_BOOTED && - ecl_option_values[ECL_OPT_BOOTED]) { - FEerror("Cannot change option ~D while ECL is running", - 1, ecl_make_fixnum(option)); - } - ecl_option_values[option] = value; - } -} static void init_env_mp(cl_env_ptr env) diff --git a/src/h/external.h b/src/h/external.h index 809f0f54a..89ec08a5d 100755 --- a/src/h/external.h +++ b/src/h/external.h @@ -1012,7 +1012,7 @@ typedef enum { } ecl_option; extern ECL_API const char *ecl_self; -extern ECL_API void ecl_set_option(int option, cl_fixnum value); +extern ECL_API cl_fixnum ecl_set_option(int option, cl_fixnum value); extern ECL_API cl_fixnum ecl_get_option(int option); extern ECL_API int cl_boot(int argc, char **argv); extern ECL_API void cl_shutdown(void);