nucleus: move ecl_core_struct to nucleus

This commit is contained in:
Daniel Kochmański 2025-05-14 11:05:02 +02:00
parent 6f07bed6c7
commit a2021f1afd
5 changed files with 110 additions and 101 deletions

View file

@ -3,11 +3,27 @@
/* boot.c - initializing ecl internal data */
/* -- imports ------------------------------------------------------- */
/* -- imports --------------------------------------------------------------- */
#include <limits.h>
#if defined(ECL_MS_WINDOWS_HOST)
# include <windows.h>
# include <shellapi.h>
# define MAXPATHLEN 512
#endif
#ifndef MAXPATHLEN
# ifdef PATH_MAX
# define MAXPATHLEN PATH_MAX
# else
# define MAXPATHLEN sysconf(_PC_PATH_MAX)
# include <unistd.h>
# endif
#endif
#include <ecl/ecl.h>
#include <ecl/ecl-inl.h>
#include <ecl/internal.h>
#include <ecl/external.h>
/* -- constants ----------------------------------------------------- */
@ -115,3 +131,65 @@ ecl_set_option(int option, cl_fixnum value)
}
return ecl_option_values[option];
}
/* -- core runtime ---------------------------------------------------------- */
/* The root environment is a default execution context. */
static struct cl_env_struct first_env;
struct ecl_core_struct ecl_core = {
.first_env = &first_env,
/* processes */
#ifdef ECL_THREADS
.processes = ECL_NIL,
.last_var_index = 0,
.reused_indices = ECL_NIL,
#endif
/* signals */
.default_sigmask_bytes = 0,
.known_signals = ECL_NIL,
/* allocation */
.max_heap_size = 0,
.bytes_consed = ECL_NIL,
.gc_counter = ECL_NIL,
.gc_stats = 0,
.safety_region = NULL,
/* pathnames */
.path_max = 0,
.pathname_translations = ECL_NIL,
/* LIBRARIES is a list of objects. It behaves as a sequence of weak pointers
thanks to the magic in the garbage collector. */
.libraries = ECL_NIL,
.library_pathname = ECL_NIL
};
/* note that this function does not create any environment */
int
ecl_boot(void)
{
int i;
i = ecl_option_values[ECL_OPT_BOOTED];
if (i) {
if (i < 0) {
/* We have called cl_shutdown and want to use ECL again. */
ecl_set_option(ECL_OPT_BOOTED, 1);
}
return 1;
}
init_process();
/* init_unixint(); */
/* init_garbage(); */
ecl_core.path_max = MAXPATHLEN;
return 0;
}
int
ecl_halt(void)
{
ecl_set_option(ECL_OPT_BOOTED, -1);
return 0;
}

View file

@ -15,20 +15,6 @@
/******************************** IMPORTS *****************************/
#include <ecl/ecl.h>
#include <limits.h>
#if defined(ECL_MS_WINDOWS_HOST)
# include <windows.h>
# include <shellapi.h>
# define MAXPATHLEN 512
#endif
#ifndef MAXPATHLEN
# ifdef PATH_MAX
# define MAXPATHLEN PATH_MAX
# else
# define NO_PATH_MAX
# include <unistd.h>
# endif
#endif
#ifdef ECL_USE_MPROTECT
# include <sys/mman.h>
# ifndef MAP_FAILED
@ -51,61 +37,6 @@
const char *ecl_self;
/* -- core runtime ---------------------------------------------------------- */
/* The root environment is a default execution context. */
static struct cl_env_struct first_env;
struct ecl_core_struct ecl_core = {
.first_env = &first_env,
/* processes */
#ifdef ECL_THREADS
.processes = ECL_NIL,
.last_var_index = 0,
.reused_indices = ECL_NIL,
#endif
/* signals */
.default_sigmask_bytes = 0,
.known_signals = ECL_NIL,
/* allocation */
.max_heap_size = 0,
.bytes_consed = ECL_NIL,
.gc_counter = ECL_NIL,
.gc_stats = 0,
.safety_region = NULL,
/* pathnames */
.path_max = 0,
.pathname_translations = ECL_NIL,
/* LIBRARIES is a list of objects. It behaves as a sequence of weak pointers
thanks to the magic in the garbage collector. */
.libraries = ECL_NIL,
.library_pathname = ECL_NIL
};
/* note that this function does not create any environment */
int
ecl_boot(void)
{
int i;
i = ecl_option_values[ECL_OPT_BOOTED];
if (i) {
if (i < 0) {
/* We have called cl_shutdown and want to use ECL again. */
ecl_set_option(ECL_OPT_BOOTED, 1);
}
return 1;
}
init_process();
/* init_unixint(); */
/* init_garbage(); */
ecl_core.path_max = MAXPATHLEN;
return 0;
}
/************************ GLOBAL INITIALIZATION ***********************/
static int ARGC;
@ -289,7 +220,7 @@ cl_shutdown(void)
ecl_tcp_close_all();
#endif
}
ecl_set_option(ECL_OPT_BOOTED, -1);
ecl_halt();
}
ecl_def_ct_base_string(str_common_lisp,"COMMON-LISP",11,static,const);

View file

@ -80,6 +80,7 @@
#endif
#include <ecl/object.h>
#include <ecl/nucleus.h>
#include <ecl/external.h>
#include <ecl/cons.h>
#include <ecl/stacks.h>

View file

@ -170,35 +170,6 @@ struct ecl_interrupt_struct {
extern ECL_API cl_env_ptr cl_env_p;
#endif
/* Core environment. */
struct ecl_core_struct {
cl_env_ptr first_env;
#ifdef ECL_THREADS
cl_object processes;
ecl_mutex_t processes_lock;
ecl_mutex_t global_lock;
ecl_mutex_t error_lock;
ecl_rwlock_t global_env_lock;
cl_index last_var_index;
cl_object reused_indices;
#endif
size_t max_heap_size;
cl_object bytes_consed;
cl_object gc_counter;
bool gc_stats;
char *safety_region;
cl_index default_sigmask_bytes;
cl_object known_signals;
int path_max;
cl_object pathname_translations;
cl_object libraries;
cl_object library_pathname;
};
/* Per-process data. Modify main.d accordingly. */
struct cl_core_struct {
@ -244,8 +215,9 @@ extern ECL_API void ecl_free(void *ptr);
extern ECL_API void ecl_copy(void *dst, void *src, cl_index ndx);
#define ecl_free_unsafe(x) ecl_free(x);
/* cold_boot.c */
/* boot.c */
extern ECL_API int ecl_boot(void);
extern ECL_API int ecl_halt(void);
extern ECL_API const cl_object ecl_ct_Jan1st1970UT;
extern ECL_API const cl_object ecl_ct_null_string;

View file

@ -6,4 +6,31 @@
#include "external.h"
struct ecl_core_struct {
cl_env_ptr first_env;
#ifdef ECL_THREADS
cl_object processes;
ecl_mutex_t processes_lock;
ecl_mutex_t global_lock;
ecl_mutex_t error_lock;
ecl_rwlock_t global_env_lock;
cl_index last_var_index;
cl_object reused_indices;
#endif
size_t max_heap_size;
cl_object bytes_consed;
cl_object gc_counter;
bool gc_stats;
char *safety_region;
cl_index default_sigmask_bytes;
cl_object known_signals;
int path_max;
cl_object pathname_translations;
cl_object libraries;
cl_object library_pathname;
};
#endif /* ECL_NUCLEUS_H */