Commit graph

1949 commits

Author SHA1 Message Date
Daniel Kochmański
a7c86c32d4 core: move defacto constants from cl_core structure to global space 2026-03-07 21:35:37 +01:00
Daniel Kochmański
ede2f0aaa1 cmp: define constant VM before it is first used in a produced header
When we've built ECL without dynamic VV, the preprocessor define VM was
referenced in the produced header before it was defined. That lead to an error.
2026-02-27 11:22:02 +01:00
Marius Gerbershagen
b1cf56806d clos: store class definitions in the compiler environment
According to the CLHS:

> If a DEFCLASS form appears as a top level form, [...] the compiler
  must make the class definition available to be returned by FIND-CLASS
  when its environment argument is a value received as the environment
  parameter of a macro.

We already store type definitions in the compiler environment, so we
can just reuse that.

While The metaobject protocol doesn't specify what happens when
compiling DEFCLASS, only what happens when executing it (see
https://franz.com/support/documentation/mop/concepts.html#compile-file),
real life software breaks when we try to create a full class object at
compile time. Therefore, we just create a dummy forward-referenced
class object which contains nothing more than a name.
2026-02-25 20:10:06 +01:00
Marius Gerbershagen
44b439135a cmp: fix some compile time type checks
We can't pass compound function types (i.e. function types which
include argument and return types) to TYPEP. At some places, this was
already handled but not everywhere. A new function CMP-TYPEP is
introduced to handle this. At any place where a user-supplied type is
checked at compile time, we need to use CMP-TYPEP instead of TYPEP.
2026-02-13 19:39:20 +01:00
Marius Gerbershagen
93aa909c84 cmp: don't emit style-warnings for dead code elimination
Dead code eliminiation often happens for automatically generated code,
so this leads to many false positives for code that doesn't have any
style issues.

Moreover, the combination of compiler-note and style-warning is
handled badly by asdf. By default, we don't display compiler-notes but
asdf catches style-warnings to display a notice that a style-warning
has been emitted which is confusing since no warning has been printed.
2026-02-13 19:00:48 +01:00
Marius Gerbershagen
411723aa95 cmp: fix inline expansion for ABS function 2025-12-13 19:51:53 +01:00
Marius Gerbershagen
cae32c08bc cmp: fix inline expansions for EXPT function
Floating point contagion rules and the special case (expt 0 0) were
not handled correctly.
2025-12-13 19:51:53 +01:00
Marius Gerbershagen
c6488fa1c1 cmp: fix type propagator for EXPT
There were a number of bugs here:
- REAL was returned even for complex exponents
- The special case of exponent=0 wasn't handled correctly
- In some cases, EXPT could return integer or rational results but the
  type propagator would always assume that coercion to floating point
  was happening.
2025-12-13 19:51:53 +01:00
Daniel Kochmański
9f9c9a8037 cmp: assign _ecl_debug_env to lcl_env (not lex_env) 2025-11-29 22:22:41 +01:00
Daniel Kochmański
e6ae6146a4 ihs/swank: make si_ihs_env return the local environment (not lexical)
We deprecate the function si_ihs_env in favor of more explicit si_ihs_lex and
si_ihs_lcl, but the former is left for backward compatibility with SLIME/SLYNK
because they call it to query the environment to add locals to the backtrace.
2025-11-28 11:57:09 +01:00
Daniel Kochmański
ed5471169e ihs: store locals and lexical environment in separate slots
Since ~recently we store local variables in the bytevm on the stack.  Also, the
native comipler under specified debug options, stores locals in ihs, but it has
nothing to do with the lexical environment. So it feels justified to push both
to a separate field.
2025-11-28 11:57:09 +01:00
Daniel Kochmański
3c4c1639c5 proclamations: fix an invalid proclamation for SI:IHS-ENV
It may seem like this proclamation is invalid sincd !346, but the divergence
happens much earlier. 8c0314022c introduces a
feature where c-compiled code can also add debug information, and in that case
the environment is a vector, so the proclamation back then should be:

  (proclamation si:ihs-env (si::index) (or list vector))

Later when we've changed the representation, it should be changed to

  (proclamation si:ihs-env (si::index) (or null vector))

Where NULL denotes "no lexical environment".
2025-11-28 11:57:09 +01:00
Daniel Kochmański
34afd9a6d3 compile-file: allow :LOAD T :SYSTEM-P T when cross-compiling
We don't need to load the compilation artifact, so there is no reason to error.
2025-11-24 14:47:53 +01:00
Daniel Kochmański
e09f0d9742 cmpdefs: fix builds for CC [dlopen host -> no-dlopen target]
(DEFCONFIG *LD-SHARED-FLAGS*) was called without a value when dlopen was not
defined, that lead to error when destructuring. We put there "" instead now.
2025-11-24 10:58:15 +01:00
Marius Gerbershagen
2279b78514 cmp: fix typos 2025-11-23 17:45:10 +01:00
Marius Gerbershagen
4734509f15 cmp: allow cross compiling to/from targets without shared library support 2025-11-22 16:25:42 +01:00
Marius Gerbershagen
0baa1290e6 cmp: fix constant folding for target dependent constants
Register these constants as symbol macros in the lexical environment.
Maybe not the cleanest solution, but it works.
2025-11-22 16:25:42 +01:00
Marius Gerbershagen
7a1bd96eb7 cmp: make sure COMPILE works during cross compilation
Previously, calling COMPILE during cross compilation always failed due
to trying to load a shared object compiled for the wrong architecture.
We now temporarily switch back to the host configuration, compile and
load our shared object, and then go on with the target config.
2025-11-22 16:25:42 +01:00
Marius Gerbershagen
7932ffb1be fix cross compilation to a Windows target
Cross compilation of ECL itself:

- The windres program comes with the usual cross compilation target
  prefixes, use AC_CHECK_TOOL to select the right one.
- For c::update-compiler-features, we need to check the features of the
  host system instead of the target because that determines the
  executable prefix of the ecl_min stub.

Cross compilation of user code: We just have to replace some read time
conditionals by runtime checks.

Further notes on Windows cross compilation using mingw:

- Our old copy of libgmp doesn't work, one needs to update that before
  compiling.
- ASDF fails to compile unless XDG_CACHE_HOME is set (it tries and
  fails to find a Windows cache directory if XDG_CACHE_HOME is empty).
- The `windres` program may be located in a separate package from the
  mingw compiler. On debian, I had to install binutils-mingw-w64 and
  gcc-mingw-w64.
2025-11-22 16:25:42 +01:00
Marius Gerbershagen
f099a9082a cmp: move proclamations from system-properties into a compiler specific storage
This allows us to switch out the proclamations when cross-compiling so
that target specific functions are declared correctly.

This was a problem for cross compilation with mismatching thread
support, so we can now allow that.
2025-11-22 16:25:42 +01:00
Marius Gerbershagen
c5f6cd0246 cmp: change handling of *cmp-env-root*
Due to the recent introduction of cross compilation features,
*cmp-env* has to contain type information throughout the entire
compilation (not only while we are compiling a form) so that (typep x
type *cmp-env*) works correctly. Therefore, we can't set *cmp-env* to
nil initially as we did previously. Instead, we set *cmp-env*
to *cmp-env-root* initially.
2025-11-22 16:25:42 +01:00
Marius Gerbershagen
79d33bdd83 cmp: fix typo 2025-11-22 16:25:42 +01:00
Marius Gerbershagen
ee60bffaf0 cmp: allow cross compiling to/from targets with complex float support
A host compiler without complex float support still needs to be able
to emit C instructions for complex float. In this case, the host
doesn't define si::complex-{single/double/long}-float types, so we
need to replace those by types which all variants of ECL understand.
Moreover, functions for emitting C code dealing with complex floats
must be present even if the host doesn't support complex floats
natively.

Deciding whether to emit these instructions is implemented either by
explicit checks for *complex-float* or automatically as the compiler
will not create :c{s/d/l}float locations for a target without complex
float support (this is decided at runtime based on the contents
of *machine*).
2025-11-21 19:08:14 +01:00
Marius Gerbershagen
deec67aa57 cmp: allow for cross compiling to/from targets with C compatible variadic dispatch 2025-11-21 19:08:14 +01:00
Marius Gerbershagen
02415a4008 cmp: warn for unsupported cross compilation configurations 2025-11-21 19:08:14 +01:00
Marius Gerbershagen
fb321885db cmp: easier cross-compilation of user code
The procedure works as follows. First, cross compile ECL itself. In
this step, we dump the configuration of the compiler. This
configuration can then be later restored to put the host compiler into
cross compilation mode using a new option to WITH-COMPILATION-UNIT.

The following changes to the public interface are introduced:

- WITH-COMPILATION-UNIT now takes a new :target keyword
- New functions C:WRITE-TARGET-INFO, C:READ-TARGET-INFO to dump and
  restore the config
- The environment parameters to TYPEP and SUBTYPEP are no longer
  unused. User macros can query type relationships in the target
  environment using these parameters.

Internal changes in the compiler include:

- Target dependent variables in the compiler are defined using a new
  DEFCONFIG macro. C:WRITE-TARGET-INFO simply writes the value of
  these variables to a file.
- The distinction between target types and host types already exists
  in the compiler. In this commit, we just register the target types in
  the compiler environment when we change the compiler configuration.
2025-11-21 19:08:14 +01:00
Daniel Kochmański
7c5471947d c2tagbody-body: fix a regression when processing intermediate tag
In 521e815158 I've introduced a regression where
we did not bind the destination and exit label for intermediate forms.

Fixes #802.
2025-11-17 10:39:45 +01:00
Marius Gerbershagen
b8bd5f4026 cmp: fix constant folding
Fixes a regression introduced in commit
816c08340b. After the changes in that
commit, c1forms of name variable can denote constants as well.

Since we are now more aggressive with inlining constant access, we
have to fix a bad defconstant definition in clos/boot.lsp as well (the
new definition makes sure that the compile-time and load-time
evaluations of the constant are eql).
2025-11-15 16:52:31 +01:00
Daniel Kochmański
cfe1dec177 subtypep: rebind type variables with a macro WITH-TYPE-DATABASE
It seems that some variables were rebound also in cmptype-arith.lsp -- to avoid
potential inconsistency we abstract away bindings as WITH-TYPE-DTABASE.
2025-08-27 10:46:58 +02:00
Daniel Kochmański
a8e57c60a5 streams: implement new interfaces for unreading and peeking bytes
ecl_file_ops has two new members:

  void (*unread_byte)(cl_object strm, cl_object byte);
  cl_object (*peek_byte)(cl_object strm);

C API additions:

  void ecl_unread_byte (cl_object byte, cl_object strm)
  cl_object ecl_peek_byte (cl_object strm)

  si_unread_byte(cl_object strm, cl_object byte)    [1]
  si_peek_byte(cl_object strm, cl_object byte)      [2]

Lisp API additions:

  (ext:unread-byte stream byte) :: integer          [1]
  (ext:peek-byte   stream byte) :: (or integer nil) [2]

  (gray:stream-unread-byte stream byte) :: null
  (gray:stream-peek-byte stream) :: (or integer :eof)

We implement a "generic" version of unread-byte by storing it in a new slot
last_byte.
2025-08-11 10:01:37 +02:00
Marius Gerbershagen
cd90ecfd55 cmp: signal internal error in wt-vv-value if we detect a programming error 2025-07-19 16:33:22 +02:00
Marius Gerbershagen
a1b1eee8b5 cmp: allow for storing type definitions in the compiler environment
Currently unused; will be used in the implementation of
cross-compilation.
2025-07-19 16:31:55 +02:00
Daniel Kochmański
9687a1d33a stacks: move frames stack to a separate structure 2025-05-26 07:43:41 +02:00
Daniel Kochmański
b08f1dc986 Merge branch 'fix-750' into 'develop'
deftype: implement &environment parameters

Closes #750

See merge request embeddable-common-lisp/ecl!344
2025-04-22 07:02:58 +00:00
Marius Gerbershagen
deefc21c9d deftype: implement &environment parameters
The deftype expansion functions now take two parameters, the type
argument and an environment. More precisely, for an atomic type 'x the
type argument for the expansion function is given by '(x) while for a
non-atomic type '(x y z) it is given by '(x y z). This also fixes the
value of &whole parameters in deftype lambda lists. The new behaviour
is consistent with SBCL and CCL.

Fixes #750
2025-04-08 21:57:53 +02:00
Marius Gerbershagen
72c83ac9b5 cmp: fix bug for calls to local functions with more arguments than c-arguments-limits
Closes #774.
2025-04-05 22:14:17 +02:00
Daniel Kochmański
92772b1afd bytecmp: implement flat closures
This commit replaces capturing whole LEX with an explicit vector of closed
variables. We introduce a set of additional opcodes that deal with closed
entities. Locals are referred as lcl and closed variables as lex.
2025-03-27 22:45:34 +01:00
Daniel Kochmański
85c6599d8d cmp: fix a bug in SET-CLOSURE-ENV wrt self-referncing objects
When we were compiling bytecodes with LABELS, the function SET-CLOSURE-ENV
exhibited infinite recursion by adding the record as FLET. C.f test "cmp.0100".
2025-03-27 22:45:34 +01:00
Daniel Kochmański
7e3dc96fa5 Merge branch 'improve-ensure-directories-exist' into 'develop'
ensure-directories-exist: minor improvements

See merge request embeddable-common-lisp/ecl!340
2025-03-17 20:23:42 +00:00
Marius Gerbershagen
270b3a4157 cmp: fix compiler-macro for make-array
Constant arguments for the dimensions were not handled correctly. The
valid-array-index function was lost in a refactor some time ago.
Moreover, we need to check all of the conditions on the
dimensions (limits on rank, dimension and total size) using an AND
statement instead of checking only the first condition using OR.
2025-03-02 19:36:06 +01:00
Marius Gerbershagen
a3d7036c36 ensure-directories-exist: minor improvements
Simply call mkdir and ignore EEXIST errors to prevent race conditions
when two processes try to create a directory at the same time. Also
avoids a redundant syscall since by not calling si::file-kind, so this
should be slightly faster.
2025-03-01 17:52:26 +01:00
Marius Gerbershagen
c0d0f2f891 restore ability to compile without --disable-shared on emscripten
SHARED_LDFLAGS, BUNDLE_LDFLAGS and PROGRAM_LDFLAGS are ignored with
--disable-shared.
2024-08-17 13:11:53 +02:00
Daniel Kochmański
f5e3de23fd Merge branch 'faster-function-calls-fix' into 'develop'
Fixes for the faster function call branch

Closes #737

See merge request embeddable-common-lisp/ecl!327
2024-06-18 05:59:16 +00:00
Daniel Kochmański
366a77a013 cmpopt-sequence: fix a regression with loop 2024-06-16 17:54:37 +02:00
Marius Gerbershagen
97b13d4712 cmp: don't generate variadic entrypoints for functions with variable number of arguments
These are badly optimized by C compilers (even single use static
functions are not inlined by both gcc and clang), so instead of
generating a separate variadic entrypoint just generate one single
entrypoint with C compatible signature.
2024-05-18 12:43:43 +02:00
Marius Gerbershagen
dd4687772d cmp: don't mark function arguments as volatile in variadic entrypoints
The presence of setjmp calls in function bodies means that some
function arguments have to be volatile. However, this doesn't apply to
variadic entrypoints which never include setjmp calls. Thus,
set *volatile* to be empty before writing out the header.
2024-05-18 12:43:17 +02:00
Marius Gerbershagen
9d99e2bd2a cmp: emit simpler code for variadic entrypoints for functions with no arguments
We don't need to do anything here other than check that we got the
right number of arguments.
2024-05-18 12:43:17 +02:00
Marius Gerbershagen
da4c49cd2f cmp: make sure that setf functions are found in the vv in the second pass
Only applies for COMPILE calls where the name of a setf function
definition will not be equal under the EQ test to the name of the same
function at a later call. Thus, we have to use EQUAL to find those
names in the vv array.
2024-03-24 18:08:49 +01:00
Marius Gerbershagen
3c75b5b4d8 cmp: fix typo
Introduced by the refactor in commit 2304da9a83.
2024-03-24 18:08:49 +01:00
Marius Gerbershagen
dc286efb66 cmp: faster function calls for C compatible variadic dispatch
For C compatible variadic dispatch, the compiler now generates two
entrypoints for variadic functions. An entrypoint with specialized
signature that is used for direct C calls from the same file and an
entrypoint with generic signature that implements the variadic to
variadic dispatch, i.e. checking the number of arguments and then
calling the specialized entrypoint.

This approach is faster than using the wrapper functions in
variadic_dispatch_table. The reasons are threefold: we save a call to
ecl_process_env(), we don't need a call through a function pointer but
instead use a direct call to the specialized entrypoint and we emit
better code to deal with required arguments since the number of those
are known.

Moreover, for functions with optional arguments the new approach is
less stack hungry since we can allocate an array of size smaller than
ECL_C_ARGUMENTS_LIMIT to store the arguments.
2024-03-24 18:08:34 +01:00