Commit graph

1926 commits

Author SHA1 Message Date
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
Marius Gerbershagen
bbc8b30478 cmp: faster function calls for functions with fixed number of arguments
We now generate entrypoints for both fixed and variable number of
arguments. The entrypoint with fixed number of arguments is used for
direct C calls from the same file while the one with variable number
of arguments for indirect calls from other files or via funcall.

This approach is faster than using the wrapper functions in
fixed_dispatch_table as we did previously for two reasons. First, it
does not require a call to ecl_process_env() and second, it can use a
direct jump to the fixed entrypoint once the number of arguments have
been checked instead of an indirect call through a function pointer.
2024-03-24 14:39:38 +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
3b4aeb6e2b cmp: don't create an unnecessary function object for local calls
This prevents further optimizations down the line. By processing
`(function ,fname) with C1EXPR we treat the function as having been
referenced via a function object. Among other things this will prevent
the function from being a lexical closure as the compiler doesn't know
that this function object is unused.
2024-03-03 18:25:28 +01:00
Daniel Kochmański
38a2e31e45 Merge branch 'emscripten-shared-library-build' into 'develop'
Improvements for emscripten target

See merge request embeddable-common-lisp/ecl!321
2024-02-25 10:19:15 +00:00
Marius Gerbershagen
693761a9f6 support shared libraries for the emscripten target 2024-02-24 22:30:16 +01:00
Daniel Kochmański
076d0d07ae cmp: set-loc: explain how values are handled and remove INLINE-ARG0 2024-01-26 13:20:14 +01:00
Daniel Kochmański
3ae6fadac7 cmp: small changes to c1form-*-p
c1form-movable-p uses c1form-pure-p

  The predicate opencoded the exact body of the latter.

c1form-unmodified-p does not explicitly check for global-var-p

  The function VAR-CHANGED-IN-FORM-LIST takes care of special and global
  variables, so there is no need for an explicit check. When the variable is
  global and no form has sp-change, then it is still unmodified.
2024-01-26 12:07:20 +01:00
Daniel Kochmański
63ca129a79 cmp: cleanup: use with-c1form-env in applicable places
c2expr, t2expr, t3function all uses the macro now. That yields gives better
introspection environment and more regular handling.

Additionally bind a new variable *CURRENT-C1FORM*.
2024-01-26 12:07:20 +01:00
Daniel Kochmański
c69963f47c cmp: add a function coerce-loc and don't call directly wt-coerce-loc
This allows to inline coerce-loc inside a wt statement:

    (wt "value0=" (coerce-loc loc :object) ";")
2024-01-26 12:07:20 +01:00
Daniel Kochmański
2690dde0d3 cmp: inl: tighter type bounds for inlined arguments
Also improve PRECISE-LOC-LISP-TYPE to AND both types instead of picking the "new
type".
2024-01-26 12:07:20 +01:00
Daniel Kochmański
e97d3c6219 cmp: rework loc types and rename functions
loc-type -> loc-lisp-type (mirrors loc-host-type)
precise-loc-type -> precise-loc-lisp-type (consistency)

Introduce a new WT element in the table FRAME++, with this we don't need to
consider raw strings as locations.

LOC-LISP-TYPE and LOC-HOST-TYPE has tighter checks for types that bark on
unknown location types. When the location is a symbol, we check against all
known atomic locations (cons checks are more lax at the moment).
2024-01-26 12:07:20 +01:00
Daniel Kochmański
73605c9ba9 cmp: inl: rewrite c2psetq for consistency
This function is now written in the same spirit as EMIT-INLINE-FORM and uses
WITH-INLINE-BLOCKS.
2024-01-26 12:07:20 +01:00
Daniel Kochmański
cae5241a8b cmp: inl: add a new function coerce-args derived from coerce-locs
COERCE-LOCS optional parameters were used only by produce-inline-loc. All other
uses were much simpler, so we've spinned a separate function and removed
optionality of arguments in coerce-locs.
2024-01-26 12:07:20 +01:00
Daniel Kochmański
44088b8886 cmp: inl: use the most specific location type for argument inlining
This commit effectively retires the function MAKE-INLINE-ARG in favor of more
specific location `(THE ...).
2024-01-26 12:07:20 +01:00
Daniel Kochmański
b1bebbdb2c cmp: inl: remove the friction between inlined args and locations
Previously inlined args were not treated as locations (they were CONS, and later
INLINED-ARG). This commit makes inlined args VV instances with an appropriate
type assigned. Thanks to that we may use location operations directly on
arguments.
2024-01-26 12:07:20 +01:00
Daniel Kochmański
c7da5bc919 cmp: inl: remove dead code
SI:STRUCTURE-REF, SI:STRUCTURE-SET, SI:INSTANCE-REF, SI:CALL-GLOBAL were all
removed or merged with other operators.

SI:CALL-GLOBAL was incorporated recently to FCALL. In upcoming commits we will
sort this out in a more regular way (by introducing an FCALL-ARG destination).
2024-01-26 12:07:20 +01:00
Daniel Kochmański
2f8f7c0ada cmp: inl: fix a braino in emit-inlined-call-global 2024-01-26 12:07:20 +01:00
Daniel Kochmański
f68c911ece cmp: allow specifying the type of vv
This will be useful for inline locations where we don't know the real value, but
we can infer the type.
2024-01-26 12:07:20 +01:00
Daniel Kochmański
7dc7bda980 cmp: rename predicates to conform to the common style
local   -> local-var-p
unboxed -> unboxed-var-p
2024-01-26 12:07:20 +01:00
Daniel Kochmański
a07b39ad65 cmp: cleanup: rename REP-TYPE to HOST-TYPE
The name HOST-TYPE is less ambiguous.
2024-01-26 12:07:20 +01:00
Daniel Kochmański
ba45731c19 Merge branch 'gray-path' into 'develop'
Add generic PATHNAME and TRUENAME

See merge request embeddable-common-lisp/ecl!320
2024-01-26 08:15:53 +00:00
Daniel Kochmański
e851458058 Merge branch 'type-check-init-forms' into 'develop'
cmp: check that the type of init-forms for optional and keyword arguments matches their proclaimed types

See merge request embeddable-common-lisp/ecl!316
2024-01-26 08:14:20 +00:00
Tarn W. Burton
bc6e31f926
Add generic pathname/truename 2024-01-25 14:05:27 -05:00