Commit graph

359 commits

Author SHA1 Message Date
Daniel Kochmański
dfd99e0e16 modules: [4/n] introduce ecl_module_bignum 2025-05-15 12:23:18 +02:00
Daniel Kochmański
f008aa1a4e modules: [3/n] introduce ecl_module_process 2025-05-15 12:23:18 +02:00
Daniel Kochmański
4351ba6371 modules: [2/n] introduce ecl_module_unixint 2025-05-15 12:23:18 +02:00
Daniel Kochmański
d94f976587 modules: [1/n] introduce ecl_module_gc
We also remove conditionalization for garbage collector inclusion in autotools.
When we propose an alternative gc, then we may decide to put them back, or to
add necessary ifdef statements directly in files.

Moreover untangle c-stack from the gc code and assign the stack base with a
rough guess only when it is not initialized yet (GC will always fill it).

Finally remove a kludge from ecl_adopt_cpu and disable colleciton until the cpu
is fully initialized.
2025-05-15 12:23:18 +02:00
Daniel Kochmański
7af29da33c modules: [0/n] introduce a new structure ecl_module in the system
This will allow us to decouple forward system initialization from the early
process code.
2025-05-15 12:23:15 +02:00
Daniel Kochmański
9ce19f55c2 process: move ecl_clear_bignum_registers to _dealloc_env
This resolves a fixme.
2025-05-15 09:32:14 +02:00
Daniel Kochmański
0375f9747c process: use GC_thread_is_registered() instead of the_env->cleanup
This allows us to remove unnecessary bookkeeping.
2025-05-15 09:32:14 +02:00
Daniel Kochmański
91f4fa8ec1 nucleus: [1/n] move processing unit managament to nucleus 2025-05-14 21:30:16 +02:00
Daniel Kochmański
4f62968697 exceptions: define *SIGNAL-HANDLERS* in cold_boot
I've also renamed *HANDLER-CLUSTERS* to a more appropriate *SIGNAL-HANDLERS*.
Currently this symbol is imported to the SYSTEM package, although this may be
revised in the future to cater to multiple global environments. Alternatively
the SYSTEM package may be common to all runtimes.
2025-05-14 21:30:16 +02:00
Daniel Kochmański
e422b1eedc exceptions: introduce the concept of an exception
The exception in CL is resignaled as a condition.
2025-05-14 21:30:16 +02:00
Daniel Kochmański
d840f10892 nucleus: move ecl_core_struct to nucleus 2025-05-14 21:30:13 +02:00
Daniel Kochmański
8d936ab248 nucleus: move protect and dummy tags to boot.d 2025-05-14 15:33:50 +02:00
Daniel Kochmański
ebdde0b631 nucleus: move early constants from main.d to boot.d 2025-05-14 15:33:50 +02:00
Daniel Kochmański
f1bcd3fa46 nucleus: add a module boot for booting the core
Currently it contains only option setters.
2025-05-14 15:33:50 +02:00
Daniel Kochmański
4a760a06dd core: split cl_core_struct in two structure cl_core and ecl_core
ecl_core contains early global environment that is meant to be shared by all
runtimes, while cl_core contains an environment relevant to common lisp.
2025-05-14 13:44:01 +02:00
Daniel Kochmański
b0d52e622d core: define protect and dummy tags as constants
Both tags have a special meaning to the low-level runtime (most notably the
frame stack). Extracting them from "all symbols" is a step towards multiple
runtimes.
2025-05-14 13:44:01 +02:00
Daniel Kochmański
0b473f57ef core: move defacto constants from cl_core structure to global space 2025-05-14 13:44:01 +02:00
Daniel Kochmański
f7633962d9 stacks: refactor file to separate low level and high level operators
With this it will possible to move low level primitives earlier in the bootstrap
process.
2025-05-14 10:53:59 +02:00
Daniel Kochmański
f2cc791c1b stacks: use a manual allocator for stacks
Objects have a well defind extent so there is no need to rely on GC for
them. This change allows us to move stack initialization before garbage
collector is introduced into the system (or even without any GC).
2025-05-14 10:53:59 +02:00
Daniel Kochmański
52ce2e8f5b stacks: manually allocate bindings table
This commit removes initial bindings array from the process and allocates it
only in the bds stack. To make fields in the structure less confusing we rename
initial_bindings slot to inherit_bindings_p.

On observable behavior change is that bindings are inherited when the process is
enabled, not when it is created. That was not specified in documentation so it
should be fine to change this behavior. Moreover it makes more sense from the
programmer perspective -- we want to inherit bindings of the process that starts
our thread, not the one that creates it.
2025-05-14 10:53:59 +02:00
Daniel Kochmański
b42b1532c0 stacks: move frames stack to a separate structure 2025-05-14 10:53:59 +02:00
Daniel Kochmański
3c75a98b24 stacks: rename thread_local_bindings{,_size} to tl_bindings{,_size}
This is strictly cosmetic change.
2025-05-14 10:53:59 +02:00
Daniel Kochmański
da3dc34241 stacks: move the binding stack to a separate structure 2025-05-14 10:53:59 +02:00
Daniel Kochmański
868c3e4d31 core: don't use gc allocator to allocate a runtime environment
When we don't use mprotect (nor guard page), we allocate the memory manually.
This simplifies some code and makes the booting process less intervened with GC.
2025-03-31 20:44:46 +02:00
Daniel Kochmański
72af2d38b0 core: move the first environment initialization before symbols
Also split init_alloc in two passes like init_unixint, so we don't invoke
directly GC_enable. The first pass leaves GC explicitly disabled.
2025-03-31 20:44:46 +02:00
Daniel Kochmański
0f4e9b1e17 core: factor out process managament from thread managament
This is a preliminary step towards coroutines and for switching global env in
single-threaded builds.
2025-03-31 20:44:46 +02:00
Daniel Kochmański
f49cc7f3fd core: the first environment is statically allocated
This is to avoid circularity between the first environment (and interrupts) and
the garbage collector.
2025-03-31 20:44:46 +02:00
Daniel Kochmański
99b37c8ab5 boot: initialize macfun of ECL_T and ECL_NIL_SYMBOL to ECL_NIL
Prevoiusly this slot was left uninitialized and that lead to a segmentation
fault under certain conditions when we did (copy-symbol t t).
2025-03-27 22:45:34 +01:00
Daniel Kochmański
1ff274bf08 bytevm: don't use ecl_fdefinition for OP_FUNCTION
The function ecl_fdefinition checks also for lamdbas and whatnot, while all we
need is a lookup in the global namespace for the function name.

This commit also changes how we store SETF function definition -- instead of
maintaining them in a global environment, it is stored along with the symbol.
That saves us from taking a global lock repeatedly.
2025-03-27 22:45:34 +01:00
Marius Gerbershagen
d336b3053d implement faster function calls
The previous function call sequence for ordinary global functions
looked as follows.

1. check whether the function is defined, i.e. whether
   symbol->symbol.gfdef is not NULL
2. set the_env->function to symbol->symbol.gfdef
3. call the function pointer symbol->symbol.gfdef->cfun.entry

This commit implements a performance optimization that enables us to
skip the first step. The basic idea is to replace symbol->symbol.gfdef
with a closure that signals an undefined-function condition.

However, straightforwardly implementing this would have the
disadvantage that it would consume a larger amount of memory for each
symbol without a function definition. To get around this, we reorder
the fields of the ecl_symbol struct such that the symbol can serve as
the function object itself, introducing an entry point that is only
used for undefined functions.

Benchmarking shows an improvement of about 10% in thight loops
compared to the old method.
2024-03-03 18:26:47 +01:00
Marius Gerbershagen
c402748333 Merge branch 'environ_legacy' into 'develop'
Fix access to environ on Darwin

See merge request embeddable-common-lisp/ecl!301
2023-09-20 18:27:37 +00:00
Kirill A. Korinsky
76ef3e8e8a Fix access to environ on Darwin 2023-09-20 18:27:37 +00:00
Daniel Kochmański
c3841dbb97 main: fix ECL_OPT_SIGNAL_HANDLING_THREAD to be adequate
unixint ignores the flag that enables the signal handling thread when it can't
create one.
2023-09-19 09:32:40 +02:00
Marius Gerbershagen
b049695ec0 ecl_musleep: get rid of unused alertable argument
Was always set to true.
2023-06-04 19:19:16 +02:00
Daniel Kochmański
80b74c890d cleanup: separate process managament from threads
Additionally:

- abstract platform specific functions with file-local macros
2022-12-05 00:34:25 +01:00
Daniel Kochmański
95d7f4691c cleanup: refactor ecl_init_env into smaller functions 2022-11-25 17:07:34 +01:00
Daniel Kochmański
1d5b8fd525 bignum: move ecl_init_bignum_registers to bignum.d 2022-11-25 13:49:43 +01:00
Daniel Kochmański
f9ad8de531 cl_core: remove unused slot .default_dispatch_macro 2022-11-25 10:47:10 +01:00
Daniel Kochmański
3ada3e96f7 stacks: initialize the lisp stack in init_stacks 2022-11-25 10:14:15 +01:00
Daniel Kochmański
6ad85b259f ecl_symbol: remove unused field
symbol.dynamic was only assigned, because we already encode this information
in a bitfield using the enum ecl_stype.
2022-11-24 19:47:27 +01:00
Daniel Kochmański
a886b04a9a cosmetic: remove +x flag from source files 2022-11-24 19:47:26 +01:00
Daniel Kochmański
6c2cca684a cleanup: remove lingering references to the old garbage collector 2022-11-24 19:47:26 +01:00
Daniel Kochmański
4366fac6ad portability: repair builds for --enable-threads=no
A few blocks were not guarded with

 #ifdef ECL_THREADS
 ...
 #endif
2022-11-24 18:32:45 +01:00
Marius Gerbershagen
220faae167 fix encoding for standard input/output/error streams that are not Windows console streams
In commit 892a34e66d, I forgot to set
the encoding to the default value after we start when we are not on a
Windows console.
2022-11-19 20:34:32 +01:00
Marius Gerbershagen
de5d56b4c6 multithreading: replace various synchronization objects by native mutexes
- Spinlocks have been replaced by ordinary locks. Without access to
  the underyling scheduler, spinlocks provide no performace benefit
  and may even be harmful in case of high contention.
- Synchronization of process creation and exiting has been simplified.
  Instead of a spinlock, a barrier and atomic operations we now use
  only a single lock protecting the shared process state and a
  condition variable for implementing process joins.
- Some locks which were implemented using Lisp objects now directly
  use a native mutex.
- Our own mutex implementation has been removed as it is now unused.
2021-08-29 17:23:20 +02:00
Marius Gerbershagen
ff8cf4d3c1 pathnames: handle unicode characters
On Unix, pathnames are converted into the default encoding specified
by ext:*default-external-format* and back. On Windows, the operating
system already gives us utf16 encoded pathnames, so we use those.

ecl_namestring with ECL_NAMESTRING_FORCE_BASE_STRING encodes with the
specified encoding. Decoding is handled individually in the filesystem
functions.

Includes a minor refactor of list_directory, changing the
PARSE_DIRECTORY_ENTRY macro into an inline function.

Closes #609, #549.
2021-08-19 14:00:28 +02:00
Marius Gerbershagen
36a9c95c80 tree-wide: use new dpp @"" specifier for constant base strings where appropriate 2021-03-12 19:53:33 +01:00
Pritam Baral
a1b2909b8a s/TCP/ECL_TCP/ among preprocessor defines 2020-11-22 21:04:16 +00:00
Marius Gerbershagen
892a34e66d fix encoding issues on windows console streams
Always use the byte sized input/output operations ReadConsoleA/WriteConsoleA
and do all the conversion to unicode by ourself.

Moreover, expand the set of known encodings for Windows codepages and print
a warning if we encounter an unsupported codepage.

Fixes #582.
2020-08-02 10:55:25 +02:00
Marius Gerbershagen
cc7c0d4386 multithreading: fix race condition on thread creation
Due to the fact that the thread local environment is allocated with
mmap, the garbage collector is only aware of it after the thread is
listed in cl_core.processes. Therefore, we have to list the thread
before we allocate any memory in its environment. We were doing this
previously, however a bit earlier than needed which had the
unfortunate side effect that not all threads listed in
cl_core.processes had valid environment associated to them. Now, we
delay the listing until immediately before allocating the contents of
environment, ensuring that all listed threads have valid environments.
2020-02-14 22:31:46 +01:00