Commit graph

8938 commits

Author SHA1 Message Date
Daniel Kochmański
d358777747 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 15:33:50 +02:00
Daniel Kochmański
c515363a16 exceptions: dispatch signals exceptions (not conditions) 2025-05-14 15:33:50 +02:00
Daniel Kochmański
169c440866 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 15:33:50 +02:00
Daniel Kochmański
137c1ab625 exceptions: interpreter signals exceptions (not conditions) 2025-05-14 15:33:50 +02:00
Daniel Kochmański
f6321ed5e3 exceptions: introduce the concept of an exception
The exception in CL is resignaled as a condition.
2025-05-14 15:33:50 +02:00
Daniel Kochmański
8e5ae5d398 exceptions: introduce signals to the early environment 2025-05-14 15:33:50 +02:00
Daniel Kochmański
aa631ac76e 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 15:33:50 +02:00
Daniel Kochmański
26c51461d5 nucleus: move ecl_core_struct to nucleus 2025-05-14 15:33:50 +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
Daniel Kochmański
815e0daa05 stacks: make runtime stack accessors inline functions
Also remove an unused operator FEstack_advance.
2025-05-14 10:53:59 +02:00
Daniel Kochmański
ad81ee8f42 stacks: move runtime stack to a separate structure 2025-05-14 10:53:59 +02:00
Daniel Kochmański
3c86211051 stacks: move C shadow stack to a separate structure 2025-05-14 10:53:59 +02:00
Daniel Kochmański
5260cbc7de stacks: move invocation history stack to a separate structure 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
a624a946b8 stacks: clean up inlined versions for bds operators
We remove defines in favor of 'static inline' that is available in all c99
compilers. Previously it was specialcased only for GNUC.
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
9d8394f0cd bytevm: when unbinding locals don't keep the unbound reference
Since the stack frame is always marked fully, decrementing the pointer keeps a
reference to the unbound object effectively preventing its garbage collection
until it is overwritten by another binding or the stack is closed.
2025-05-14 10:52:45 +02:00
Daniel Kochmański
62c8f3f714 threads: get rid of an annoying warning stemming from xopen
We've defined _XOPEN_SOURCE 600 but glibc defines it as 700 or more.
2025-05-13 14:18:10 +02:00
Marius Gerbershagen
a01603a04a Merge branch 'bytevm-locals-on-stack' into 'develop'
ByteVM locals are stored on the lisp stack

See merge request embeddable-common-lisp/ecl!346
2025-05-10 17:31:24 +00:00
Daniel Kochmański
1b5a03ffca tests: disable a test on bytecmp that uses compiler-cc 2025-05-09 13:55:59 +02:00
Daniel Kochmański
db9f22c190 lisp stack: deallocate the old stack after resizing
Just like with other stacks we call ecl_dealloc on the old stack. Previously
we had stack frames that could have referenced it, but we can treat it like
other stacks, because there are not lingering references.
2025-05-09 13:55:59 +02:00
Daniel Kochmański
2f9ce70e8f stack frames: dereference directly to env->stack
Previously we've cached the stack base and dereferenced from there, but when the
stack is resized, this reference is invalidated and there is no good fix it in
all frames (we don't store back references).

This commit replaces pointers with indexes, so the stack frame is always
displaced onto the current lisp stack.
2025-05-09 13:55:59 +02:00
Daniel Kochmański
293f93b425 stack frames: don't displace onto env->values vector
ad6f1f7f10 (2008-05-12) allowed for displacing
stack frames onto the values vector. This commit seems to be before we've stored
them on lisp stack.

As for the rationale why we revert that change:

1. There may be a slight performance improvement because the standard gf
dispatch won't be forced to copy the stack frame

2. Stack frame operators assume that they are displaced onto env->stack*, for
example ecl_stack_frame_push increments env->stack_top

3. If we fully buy into assumption that the stack frame is displaced onto
env->stack* then we may replace pointers with indexes and protect the user from
accessing invalidated memory when the stack grows

The last point will be implemented in the next commit. It is worth noting, that
frames auto-heal themselves if their own operation is the cause of the stack
growth, but all other stack frames are left invalid after the operation.
2025-05-09 13:55:59 +02:00
Daniel Kochmański
aefcd77e02 tests: add a regression test for an encountered issue
This issue was never manifestable in develop branch.
2025-05-09 13:55:59 +02:00
Daniel Kochmański
fdf7c77909 bytevm: faster closure creation and less consing
OP_FLET previously had to first create functions referencing the env "before"
and then add these functions to the env "after". This is because we were
addressing from the stack top:

  env: bottom[0:var]top
  fn1: ref(top-1)
  fn2: ref(top-1)
  env: bottom[0:var, 1:fn1, 2:f2n]top

Otherwise fn2 referencing top-1 would point to fn1 instead of var.

Now that locals are addressed from the stack bottom we can add functions eagerly
to locals without consing intermediate sequence of functions:

  env: bottom[0:var]top
  fn1: ref(bottom+0)
  env: bottom[0:var, 1:fn1]top
  fn2: ref(bottom+0)
  env: bottom[0:var, 1:fn1, 2:f2n]top

That saves us one loop (nfun iterations).

A similar observation applies to LABELS, although we still need the closure
fixup because earlier function may reference a function defined later, so we
still need a second loop. That said we don't have to cons a separate sequence of
functions, because we may iterate over locals vector instead.

Both changes save us from an operator that adds a collection to the lcl_env, so
we remove tack_lcl macro and its expansion function foot_lcl.
2025-05-09 13:55:59 +02:00
Daniel Kochmański
0bf83ad30c bytevm: allocate locals on the stack
This should speed things up as well as reduce consing. To be verified.
2025-05-09 13:55:59 +02:00
Daniel Kochmański
2382fa41ab bytecmp: track the maximal size of the locals environment
After the function is compiled we assign the width to nlcl. This will be used to
determine the necessary size of the stack frame for locals.
2025-05-09 13:55:59 +02:00
Daniel Kochmański
512a31301d bytecmp: [unbug] remove assertions that are now not necessary 2025-05-09 13:55:59 +02:00
Daniel Kochmański
16996f8d38 bytevm: treat blocks and tags as normal local bindings
Previously when unbinding we've skipped blocks and tags and let the frame exit
to collect the frame variable. This commit simplifies managing the environment
in the compiler.
2025-05-09 13:55:59 +02:00