Commit graph

8959 commits

Author SHA1 Message Date
Daniel Kochmański
0e1267f579 msvc: update the makefile and specify /std:c11 minimal standard
MSVC does not allow for specifying /std:c99 so we need c11. We don't rely on the
default standard because it does not allow for static struct initializers.
2025-05-15 16:25:17 +02:00
Daniel Kochmański
2e4b5184aa nucleus: introduce a table with early symbols ecl_symbols
This table contains symbols that are essential to the core runtime: ECL_T,
ECL_UNBOUND, ECL_SIGNAL_HANDLERS, ECL_RESTART_CLUSTERs, ECL_INTERRUPTS_ENABLED,
ECL_ALLOW_OTHER_KEYS and ECL_UNBOUND.

The table is initialized with constexpr, so it is possible to use its elements
in static elements. We also add ecl_def_function to ecl-inl to allow
appropriating C functions into Lisp world at top level.
2025-05-15 16:25:17 +02:00
Daniel Kochmański
4c0e5614db nucleus: move early stacks to a separate file
This is necessary if we want to link them into nucleus without CL env baggage.
2025-05-15 16:25:17 +02:00
Daniel Kochmański
b622ea1234 nucleus: move aux throw/go/tagbody implementations to jump.d 2025-05-15 16:25:17 +02:00
Daniel Kochmański
74b898f72a process: move process initialization to the process module hooks 2025-05-15 16:25:15 +02:00
Daniel Kochmański
43b92e3321 garbage: register and unregister GC threads manually from a module
This decouples thread primitives from the garbage collector and allows us to
build nucl once more.
2025-05-15 12:41:30 +02:00
Daniel Kochmański
fb80c72683 process: abstract away create thread, exit thread and sigmask
Previously we've opencoded calls to these functions, although they may be nicely
abstracted with static inline functions. This change improves code readibility
and portability.
2025-05-15 12:41:26 +02:00
Daniel Kochmański
608a361344 modules: [A/n] move the environment allocators to nucleus
Also clean up initialization code across different paths to have the same order.
2025-05-15 12:23:18 +02:00
Daniel Kochmański
802a1c152b modules: [9/n] introduce ecl_module_thread 2025-05-15 12:23:18 +02:00
Daniel Kochmański
f0c0e2f953 modules: [7/n] introduce ecl_module_stacks 2025-05-15 12:23:18 +02:00
Daniel Kochmański
ccd062f889 modules: [6/n] introduce ecl_module_aux 2025-05-15 12:23:18 +02:00
Daniel Kochmański
2a5c8a4598 modules: [5/n] introduce ecl_module_ffi 2025-05-15 12:23:18 +02:00
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
4ea1528b34 nucleus: [2/n] move processing unit managament to nucleus 2025-05-15 09:32:12 +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
0fe1887cb9 exceptions: dispatch signals exceptions (not conditions) 2025-05-14 21:30:16 +02:00
Daniel Kochmański
ffbdf6f203 exceptions: runtime stack error signals exceptions (not conditions)
Replace calls to CEstack_overflow with exceptions - this is a necessary step
before moving stacks into nucleus.
2025-05-14 21:30:16 +02:00
Daniel Kochmański
3e500d93a4 exceptions: interpreter signals exceptions (not conditions) 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
e83abf68c5 exceptions: introduce signals to the early environment 2025-05-14 21:30:16 +02:00
Daniel Kochmański
bde0bf2090 exceptions: rewrite signal handling to use functions and not lists
Instead of storing lists in *HANDLER-CLUSTERS*, we define functions that are
called unconditionally on the handler. HANDLER-BIND defines that function to be
a typecase that is dispatched based on the conditiont type, as specified by CL.

This change will aid further refactor.
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
3f89207537 nucleus: move files process.o and process.d from OBJS to NUCL_OBJS 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
e1d9726d4f nucleus: add a module for program control transfer
Currently it contains early errors and backtrace.
2025-05-14 15:33:50 +02:00
Daniel Kochmański
86d64b358a nucleus: move atomics from threads directory to core
Atomics are needed by stacks.

Replace ecl_atomic_push -> ecl_atomic_psh that takes as an argument a
preallocated cons. ecl_atomic_push is replaced by a macro.
2025-05-14 15:33:38 +02:00
Daniel Kochmański
09876a1672 nucleus: move function calling from apply.d and eval.d to call.d
The file apply.d is effectively removed.
2025-05-14 14:48:03 +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
2cc9a4d4ee c/makefile: group files in rough categories
We also introduce an empty form for NUCL_OBJS and nucleus.h header for a
minimized runtime. This runtime will be developed over next commits so that we
can separate runtime essentials from other dependencies.
2025-05-14 13:43:13 +02:00
Daniel Kochmański
13755d0bba cleanup: reorganize cl_env_struct 2025-05-14 10:53:59 +02:00
Daniel Kochmański
1551762a7b stacks: add a general purpose stack implementation based on vector 2025-05-14 10:53:59 +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
a14508cee4 stacks: merge stack overflow errors into a single handler
Replace calls to cl_error and cl_cerror with CEstack_overflow.
2025-05-14 10:53:59 +02:00
Daniel Kochmański
2f98265062 stacks: refactor the code in stacks.d
- {run,bds,frs}_set_size functions were very similar; I've updated them to
  follow the same naming convention and execution order to indicate that.
- these functions are now renamed to xxx_set_limit -that simplifies some code
- there were inconsistencies in how we've treated boot sizes (limit vs size)
- rename some more ecl_stack_* functions to ecl_vms_* for clarity
2025-05-14 10:53:59 +02:00
Daniel Kochmański
2d8331fca4 stacks: remove serror, stack-error-handler and reset-margin
All these operations were propagated up to the condition system in order to
reset the stack margin in the case of a non-local exit. We can do that easily
with open-coded unwind protect within stacks.
2025-05-14 10:53:59 +02:00
Daniel Kochmański
33b363915e stacks: rename bds and vms stack pointers stored in frs
They are named to follow the same convention hinting that it is an index, not a
pointer.
2025-05-14 10:53:59 +02:00
Daniel Kochmański
6dcff2267b stacks: rename env runtime stack operators ecl_vms_*
ecl_stack_* was not specific enough.
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