Commit graph

1676 commits

Author SHA1 Message Date
Daniel Kochmański
ee9e72e5aa cmp: use cmutil extensions by invoking them with prefix ext 2023-02-21 14:34:11 +01:00
Daniel Kochmański
acd1dd3c07 cmp: don't import symbols from the SYSTEM package
Use proper package accessors instead. This was mostly already done. Removal of
package imports make it easier to tell when symbols do not belong to cmp.
2023-02-21 14:34:11 +01:00
Daniel Kochmański
edb19dcf75 cmp: cleanup: remove unused special variables
It is worth noting that *active-protection* and *pending-actions* are generally
not used too (because *pending-actions* are never modified), but if we want to
add some useful semantics to with-compilation-unit one day then we'll need both.
2023-02-21 14:34:11 +01:00
Daniel Kochmański
7b56516679 cosmetic: improve cmpenv comments to include the qualifier :declare 2023-02-21 14:34:11 +01:00
Marius Gerbershagen
de89593216 fix typos 2023-02-18 17:30:30 +01:00
Daniel Kochmański
feff551c31 Merge branch 'inline-closure-global' into 'develop'
Fix compiler bug regarding inlining for global functions that are closures

See merge request embeddable-common-lisp/ecl!280
2023-02-14 21:05:19 +00:00
Daniel Kochmański
8ba1bb888a si_process_lambda_list: process all variables in an uniform manner
The comment mentioned that aux variables (the sixth value) are returned the
same way as requireds, optionals and keywords however factually that was not
the case - the number of variables was not the first element of the list. This
commit updates the function and all its callers.
2023-01-22 20:12:58 +01:00
Daniel Kochmański
26c8e18750 cmputil: fix invalid iteration
Instead of using the iteration variable we've used the same list repeatedly.
2023-01-22 20:12:58 +01:00
Marius Gerbershagen
02280203a4 cmp: fix typos 2022-12-30 16:15:24 +01:00
Marius Gerbershagen
fdcf5e7eff cmp: disable inlining for global functions that are closures
For functions already compiled and loaded, we simply check if the
definition is a closure. For functions defined in the same file, we
don't store their definition in the compiler environment but instead
use *global-funs*. The advantage is that this directly allows us to
determine whether a function is a closure or not and we don't have to
run the first compiler pass again each time we inline the function.

This commit also fixes some minor issues with the inline policy,
described in detail as follows:

1. The inline policy differed subtly between `proclaim` and `declaim`.
If a file like

(eval-when (:compile-toplevel)
  (proclaim '(inline f)))
(defun f ...)

was compiled (but not loaded), subsequent compilations would inline
`f` but for

(declaim (inline f))
(defun f ...)

the function `f` would only get inlined if the file was compiled _and_
loaded. We now use the latter approach for both cases. Thus, calling
`compile-file` without `load` has no side-effects regarding whether
functions are inlined or not.

2. We did not distinguish between functions which were declared inline
at a global versus local level such that e.g. in

(locally
    (declare (inline f))
  (defun f ...))

the function f would get inlined outside the scope of the `locally`
form. This is changed now such that local inline declarations only
apply to the scope in which they are made.

3. Inline declarations were made by expanding into statements like

(eval-when (:compile-toplevel)
  (c::declare-inline ...))

during the macroexpansion of `defun`. However this only works if the
`defun` appears at the toplevel and hence in code like

(declaim (inline f))
(let (...)
  (defun f ...))

the function `f` could not get inlined later on in the same file. This
is fixed now by calling the code which should run during compilation
directly when macro expanding defun.
2022-12-30 16:14:53 +01:00
Marius Gerbershagen
de15a85420 cosmetic: fix some compiler warnings 2022-10-22 19:58:24 +02:00
Daniel Kochmański
6d191760b3 cosmetic: cmp: rename a function guess-ld-flags to guess-ld-libs
... to better reflect what it returns.
2022-09-08 09:02:42 +02:00
Marius Gerbershagen
826cc92983 cmp: introduce new variables for linker flags
Split up the options into additional flags for the linker and
additional libraries.

Quoting from issue #636:

> Here's an example, attempting to link one object file named
  example.o into an executable named example. Libcrypto here is
  superfluous and should be removed by --as-needed:

```
LDFLAGS="-Wl,--as-needed"
LIBS="-lcrypto"
gcc ${LDFLAGS} ${LIBS} example.o -o example # doesn't link libcrypto!
gcc example.o ${LDFLAGS} ${LIBS} -o example # doesn't honor --as-needed!
gcc ${LDFLAGS} example.o ${LIBS} -o example # works great!
```

> In short, the placement of your -l<foo> flags differs from that of
  all the other linker flags. Since ECL is only providing one big
  variable ld-flags for all of the linker flags, there's no correct
  way to pass in options like --as-needed and -l<foo> at the same
  time.

Fixes #636.
2022-08-24 16:38:20 +02:00
Marius Gerbershagen
3db6ad91ff cmp: fix infinite loop for files containing lists with the same circular structure
Closes #630.
2022-08-14 17:17:57 +02:00
Daniel Kochmański
1ce4713804 floats: add operators to convert between floats and bits (integers)
The interface is in the system package (that is - not part of the official api).
2022-07-07 13:24:38 +02:00
Daniel Kochmański
fe27ab8600 core: add a new utility 'si_adjust_vector' to arrays.d
This function is added to avoid using in the core the f unction CL:ADJUST-ARRAY,
that is not defined during bootstrapping.
2022-04-27 13:50:17 +02:00
Daniel Kochmański
653cba539f clos: various bootstrap improvements
The most notable change applies to the file fixup.lsp. Functions destined to
be generic are converted to their final version.

Previously this conversion was done in a few steps in order to avoid issues
with infinite recursion in dispatch. We achieve this by assigning to these new
generic function a simplified discriminating function:

    (lamda (&rest args)
      (unless (or (null *clos-booted*)
                  (specializers-match-p args specializers))
        (apply #'no-applicable-method generic-function args))
      (apply old-function args))

The old function is also seeded as a primary method for the generic
function. This works correctly because functions have only one method so we
may directly call it (it is also a fine optimization strategy we do not
incorporate generally yet), and because the discriminating function will be
recomputed when other methods are added etc.

This way we may use these generic functions without issues directly with newly
redefined versions and the file is now ordered as follows:

- fixup early methods
- redefine functions to their final version
- convert functions to generics
- define missing methods
- implement the dependant maintenance protocol

After this file is loaded it is possible to use generic functions as usual.
2022-02-05 15:03:52 +01:00
Marius Gerbershagen
f873e8e653 cmp: check number of arguments when inlining funcall or apply of lambda expression
Closes #672.
2022-01-29 20:21:00 +01:00
Marius Gerbershagen
f3d4cf4b66 cmp: fix specification of integer suffixes for the C compiler
Fixes #667.
2022-01-15 18:11:26 +01:00
Daniel Kochmański
bf62cd9d40 mp: semaphores: add a new function semaphore-wait
This function offers a functionality similar to sbcl, namely allows
specifying the timeout and the resource count.
2021-12-23 12:09:57 +01:00
Yuguo Zhang
e279df5d77 cmpos-features: fix command line arguments for msvc 2021-12-01 15:20:07 +00:00
Daniel Kochmański
6aa02de4c4 compiler: better checking whether a variable may be introduced
Previously c1make-var checked whether the symbol NAME is CONSTANTP, but
ECL expands symbol macros in CONSTANTP so this returned false positives.
A similar concern applied to the CMP-ENV-REGISTER-SYMBOL-MACRO-FUNCTION.

C1EXPR-INNER when encountered a symbol tried to yield C1CONSTANT-VALUE
for if it iwas CONSTANTP - this was correct except for that we didn't
pass the environment to the predicate and symbols weren't shadowed.

In this commit one function is added to the core - si:constp (with
similar purpose to si:specialp) and one function to the compiler -
constant-variable-p (similar to special-variable-p) and they are
appropriately used when necessary. A regression test is added.

Fixes #662.
2021-11-19 11:56:23 +01: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
ed0c3843ba Merge branch 'compiler-improvements' into 'develop'
cmp: major cleanup, separate passes

See merge request embeddable-common-lisp/ecl!251
2021-07-17 09:25:26 +00:00
Tarn W. Burton
c0e56f23af Add ed hooks 2021-07-01 11:15:05 -04:00
Daniel Kochmański
eacc5a25fb cmp: cosmetic: remove the file notes.org
Information there is not up to date and may confuse a reader.
2021-07-01 14:14:53 +02:00
Daniel Kochmański
a70c2fa36c cmp: ctop-write: don't reverse *static-constants* twice
This was probably a braino. *static-constants* is always a list.
2021-07-01 14:14:53 +02:00
Daniel Kochmański
7efb01d7d1 cmp: separate type propagation pass
The type propagation is invoked with a function compiler-pass/propagate-types
before the compiler-pass2. Previously the type propagation was invoked in
ctop-write.
2021-07-01 14:14:36 +02:00
Daniel Kochmański
8716c62f6d cmp: p1fset type propagator returns FUNCTION
Previously the propagator incorrectly returned the type of the function lambda.
2021-07-01 14:11:33 +02:00
Daniel Kochmański
e4fca7e8e7 cmp: separate fun/var ir functions from passes
Also provide better load grouping.
2021-07-01 14:11:33 +02:00
Daniel Kochmański
c8c59167d0 cmp: major cleanup, separate passes
- separate passes

  The separation is not fine-grained but is a good starting point for further
  cleanup. This is a preliminary requirement for multiple backends.

- use uninternet symbol in the package definition

- remove "execute" permission from all files

- remove a few unused functions

- rearrange loaded files

- less verbose compiler

  Don't print "End of pass 1." message. This doesn't provide any valuable
  information to the programmer.
2021-07-01 14:11:33 +02:00
Marius Gerbershagen
cdeea489cb cmp: fix typo to make constant folding work again 2021-04-01 16:19:14 +02:00
Marius Gerbershagen
62d1bb1203 cmp: fix evaluation order of sequence compiler macros
Minor improvements to define-compiler-macro* (bail out if we detect
:allow-other-keys arguments, define a named block such that
return-from works as expected).

Major refactor of sequence compiler-macros: use define-compiler-macro*
which handles correct evaluation order, define new macro to handle
common stuff for all sequences compiler-macros (e.g. inline policy
checking, check that test and test-not are not both given). The main
expansion logic in the compiler macros is unchanged although the code
had to be slightly rewritten to accomodate the new macros.

Remove the now superfluous seq-opt-parse-args function.
2021-03-31 21:09:18 +02:00
Marius Gerbershagen
dd5c372ff8 cmp: fix let bindings with initforms which are lists with QUOTE symbol as first element
Example:

(let ((x '(quote ...))) ...)

We really have to quote the value in all cases, si::maybe-quote would
strip away one level of quotation leaving only the equivalent
of (let ((x (quote ...))) ...) which of course is incorrect.
2021-03-31 19:57:01 +02:00
Marius Gerbershagen
23dde9625d cmp: fix compiler macro for make-array
The previous version had several problems: argument evaluation order
was not handled correctly and the compiler-macro produced an error for
valid code like

(let ((etype :element-type))
  (make-array 10 etype 'character))

Introduce a new generally applicable macro define-compiler-macro*
which fixes these issues.
2021-03-29 22:07:06 +02:00
Marius Gerbershagen
d54c110361 cmp: fix bad warnings for type declarations inside locally
Also search lexical environment for variables instead of only the
list of variables being established by the current form (which is nil
anyway in the case of locally; only let or multiple-value-bind
statements create new variables).

The declaration is still ignored, but fixing that would require a much
larger refactor because currently variable types are associated to the
variable itself. Thus the type can only be set for the full scope in
which the variable is active and not locally in some subscope.
2021-03-25 22:06:00 +01:00
Marius Gerbershagen
977e2fab34 cmp: fix inlining of functions with &key and &aux arguments
&aux arguments come after &key ones.

Fixes #633.
2021-03-25 22:06:00 +01:00
Marius Gerbershagen
83ed2e1722 cmp: checked-value: don't omit type checks if we detect a type-error at compile time
We now warn at compile time and create a type assertion which errors
at runtime.
2021-03-21 17:33:06 +01:00
Marius Gerbershagen
1f57d7e20a cmp: add type checks to boole compiler macro 2021-03-21 17:33:06 +01:00
Marius Gerbershagen
9391a2bf67 cmp: fix inline expressions for elt
We can't use aref since aref ignores fill-pointers and ecl_fixnum can
be used only in unsafe code.
2021-03-21 17:33:06 +01:00
Marius Gerbershagen
eedbbc08c2 cmp: add type checks in mapl/maplist/mapcon compiler-macros
We are transforming these functions into (loop :on ...). This simply
stops when the objects which we are looping on is not a list, but we
need to signal a type-error because the mapping functions are
specified to take only lists.
2021-03-21 17:33:06 +01:00
Marius Gerbershagen
e0813bf42e cmp: fix typos 2021-03-21 17:33:06 +01:00
Marius Gerbershagen
59cc1f2df8 cmp: fix compiler macro for nth and nthcdr
We were doing no error checking that we got the right number of
arguments. Also remove the manual creation of forms with a backquote
for better readability.
2021-03-20 20:48:50 +01:00
Marius Gerbershagen
78ec5a2d92 cmp: fix type declarations for package functions
All of these functions take either a list of symbols or a single
symbol (except for shadow which uses string designators or lists
thereof).
2021-03-20 20:26:57 +01:00
Marius Gerbershagen
56a914b261 cmp: give more precise types for constant values
Improves error messages.
2021-03-20 20:01:40 +01:00
Marius Gerbershagen
b1ea49e1a0 cmp: fix evaluation order of multiple-value-setq with symbol-macrolet
If a variable which is set with multiple-value-setq is bound to a
symbol-macro, we need to handle the order of side-effects as in setf.

Previously, we were first evaluating the value generating form
of the multiple-value-setq before setting the places from the
symbol-macro. The correct order is to first evaluate the forms from
the symbol macro giving the places to set, then evaluate the value
generating form from the multiple-value-setq and then set the places
to the generated values.
2021-03-18 21:57:14 +01:00
Marius Gerbershagen
80c53f0e2b cmp: fix (values (values))
This must return nil as a single value while we were returning no
values.
2021-03-18 20:20:35 +01:00
Marius Gerbershagen
e466823ac6 cmp: be more strict with symbol-macrolet
The ansi standard specifies that declaring symbols bound with
symbol-macrolet to be special or binding symbols that are defined as
global variables must signal a program-error. Previously, we simply
ignored this issues.

Also fix an issue with cmp-env-search-variables which would wrongly
return variables when searching for symbol macros. This allows us to
remove another check in symbol-macro-declaration-p.
2021-03-11 20:51:17 +01:00
Marius Gerbershagen
69e9e1d46c cmp: fix inlining of functions with mutually dependent keyword arguments
If we inline a function which contains keyword arguments whose default
value depends on the presence of other keyword arguments as for
example in

(funcall (lambda (&key (a nil a-p) (b a-p)) ...))

where `b` depends on the presence of `a`, we need to set the
key-flag `a-p` immediately after scanning for the keyword and not at
the end after we have finished scanning all keywords as we did previously.
2021-03-04 20:19:36 +01:00
Marius Gerbershagen
e5f6606ba7 cmp: fix type propagation for atan function 2021-03-04 19:54:20 +01:00