Commit graph

8638 commits

Author SHA1 Message Date
Marius Gerbershagen
fdcbe9458d cmp: better dead code elimination
Eliminate dead branches in IF/AND/OR forms if the type of the object
returned by the test form is known to be null or non-null. Get rid of
unnecessary tests in AND/OR forms if we know that a clause cannot
short-circuit the evaluation. Replace NOT forms by T or NIL constants
if we know that the argument is null or non-null.
2023-12-30 13:31:55 +01:00
Marius Gerbershagen
b5dbba1f68 cmp: improvements for (c1nil) and (c1t)
Make the types more precise to improve type propagation. We will fall
back to using object-type as appropriate in later stages of the
compilation.

Also return a new copy for each invocation instead of the same *c1nil*
and *c1t* since we may later set the type of the c1form (e.g. in
enforce-types). This can happen for invalid code which can permanently
set the type of *c1nil* to NIL, leading to miscompilations later on
for unrelated valid code.
2023-12-30 12:39:49 +01:00
Marius Gerbershagen
c474f33fa9 cmp: object-type: nil should have type NULL instead of SYMBOL 2023-12-30 12:39:49 +01:00
Marius Gerbershagen
8cd985961c cmp: improve type propagation for (and), (or), (if) and (not)
Fix errors in handling values types for (and) and (or) (all forms but
the last form return only the primary value). Also be more precise if
branches are not taken or the evaluation is known to short circuit.
2023-12-30 12:39:48 +01:00
Marius Gerbershagen
e0cd45299d Merge branch 'cmpc-refactor-next' into 'develop'
Futher refactor of the compiler

See merge request embeddable-common-lisp/ecl!313
2023-12-28 13:31:03 +00:00
Daniel Kochmański
a230243c97 cmp: loc-refers-to-special-p: more precise check for BIND 2023-12-28 12:50:37 +01:00
Daniel Kochmański
6fb6c7790f cmp: variable holding function has gensym as a name
Previously we've named the function's variable with the function name. That
could lead to a varible named (SETF FOO), and that can break down the road
because variable names are assumed to be symbols.

Moreover this change will prevent a possible fail scenario where we inline a
constant value with a known name instead of the function with the same name.
2023-12-28 12:46:24 +01:00
Daniel Kochmański
5f0cd1acad cmp: inl: specify the value type in make-inline-temp-var 2023-12-28 12:46:24 +01:00
Daniel Kochmański
9e79ae1a09 cmp: rework c2call-global for readibility 2023-12-28 12:46:24 +01:00
Daniel Kochmański
cb0d8274ae cmp: cleanup in the file cmppass2-call 2023-12-28 12:46:24 +01:00
Daniel Kochmański
923d9706f1 cmp: inl: introduce a macro WITH-INLINE-BLOCKS
This macro captures a common invocation scheme.
2023-12-28 12:46:24 +01:00
Daniel Kochmański
9229976731 cmp: inl: remove dead (and invalid!) code
C inliners for arithmetic operations assumed that there may be more than two
arguments and worked similar to reduce:

    ARG_n+3 <- (inline-binop ARG_n+2 ARG_n+1) op ARG_n

that said ECL has compiler macros that simplify the arithmetic so there are
always at most two arguments, so it is enough to inline:

    (inline-binop ARG1 ARG2)

As for the incorrect code -- when there were remaining arguments, the result of
the previous operation was saved with save-inline-loc, but(!) save-inline-loc
expected an inlined argument, while inline-binop calls produce-inline-loc that
returns a "normal" location - that's probably some change from the past, because
produce-inline-loc seems to clearly indicate that it should return inlined value
- and save-inline-loc would always error because of the argument type mismatch.

This commit removes the dead code and now unused save-inline-loc function.
2023-12-28 12:46:24 +01:00
Daniel Kochmański
c6955e41c5 cmp: inl: move code around in the cxx backend inliners
After understanding better the code I've moved argument inlining and function
inlining close to each other, also negate-argument clearly belongs in there too.

INLINED-ARG is now a structure (not a naked list) - that helps with
understanding abstractions better.
2023-12-28 12:46:24 +01:00
Daniel Kochmański
48c39c8083 cmp: inl: remove maybe-save-value and introduce inline-arg0 instead
This function has very clear resemblence of inline-args so it is moved to
cmpc-opt-inl.
2023-12-28 12:46:24 +01:00
Daniel Kochmański
a12d24a8bf cmp: exit manager: implement branching directly in the module
Instead of open-coding branching manually in individual operators we introduce
separate unwinding operators.
2023-12-28 12:46:24 +01:00
Daniel Kochmański
bb42ed7194 cmp: compute-unwind: make all arguments explicit
Instead of relying on *UNWIND-PROTECT* we accept explicit arguments.
2023-12-28 12:46:24 +01:00
Daniel Kochmański
909e5693ab cmp: tagbody: move tag allocation before branching
This is a cosmetic change for readibility.
2023-12-28 12:46:24 +01:00
Daniel Kochmański
bc01ff1a3c cmp: unwind-cjump: avoid recursive call to unwind-exit
Previously our call for conditional jumps worked like:

  unwind-exit -> unwind-cjump -> unwind-exit -> unwind-{label,exit}

The roundtrip to unwind-exit makes tracking invocations harder. The new
invocation chain is:

  unwind-exit -> unwind-cjump -> unwind-{label,exit}
2023-12-28 12:46:24 +01:00
Daniel Kochmański
b9605fd3e4 cmp: exit manager: introduce operators UNWIND-FLEE and UNWIND-COND
The operator UNWIND-FLEE is used to perform a dynamic unwind. Previously we've
opencoded this type of exits in appropriate operators.

The operator UNWIND-COND is used to perform a conditional unwind. It is expected
to be called to produce the IF statement body. With this commit all every
transfer of control goes through the exit manager.

Ultimately we will want to include the if test directly in UNWIND-COND.
2023-12-28 12:46:24 +01:00
Daniel Kochmański
dfa02ba434 cmp: unwind-label: relax conditions for carrying the value
There is no need to carry the location value across the unwind when the
destination is not special, because then we may assign the destination before we
unwind the stack. That allows us to skip examining the unwind requirements.
2023-12-28 12:46:24 +01:00
Daniel Kochmański
d13d400654 cmp: move the variable *DESTINATION* to cmpc 2023-12-28 12:46:24 +01:00
Daniel Kochmański
c2ffcc5deb cmp: introduce a separate environment for functions
There is an environment for the backend, and there is a separate environment for
each function.
2023-12-28 12:46:21 +01:00
Daniel Kochmański
def52d9657 cmp: pull emit-toplevel-form into emit-entry-fun
Instead of mincing blocks form-by-form, we put them all in a single function
environment and make them share locals.
2023-12-28 12:42:39 +01:00
Daniel Kochmański
364deb0551 cmp: remove unused bindings
EMIT-TOPLEVEL-FORM bound *compile-file-truename* and *compile-file-position* to
be immedietely rebound in T2EXPR (to the same value!).

*COMPILE-TO-LINKING-CALL* is not used anywhere.
2023-12-28 12:42:39 +01:00
Daniel Kochmański
141231f2fe cmp: remove dead code 2023-12-28 12:42:39 +01:00
Daniel Kochmański
397dc995d4 cmp: cosmetic changes, elaborate in a comment 2023-12-28 12:42:39 +01:00
Daniel Kochmański
b4da521398 cmp: set-loc: fix a braino (don't access special variable)
set-loc saves the location to the destination, and while doing so it coerces the
former to the type of the latter. Our code used *destination* as the argument to
LOC-REPRESENTATION-TYPE, but DESTINATION and *DESTINATION* may not be the same.
2023-12-28 12:42:39 +01:00
Daniel Kochmański
b3e85f1014 cmp: move misplaced comment to cmpc-inl-sysfun 2023-12-28 12:42:39 +01:00
Daniel Kochmański
f074f1087b cmp: cleanup: remove unused function 2023-12-28 12:42:39 +01:00
Daniel Kochmański
125605b1d0 Merge branch 'read-line' into 'develop'
Fix stream-read-line return

See merge request embeddable-common-lisp/ecl!312
2023-12-28 10:52:08 +00:00
Daniel Kochmański
1be34217a8 seqmacros: do-sublist: fix an invalid declaration
ECL declared the argument %sublist as CONS while it may be either CONS or NIL.
Reported by Alex Wood from Clasp.
2023-12-16 19:23:36 +01:00
Daniel Kochmański
f4af0cc9e3 INSTALL: add an extra hint for emscripten re stack size
Fixes #726.
2023-12-09 09:24:58 +01:00
Daniel Kochmański
1615d72900 cmp: don't attempt to inline constant values with make-load forms
This recent regression caused issues when we try to inline values of constants
that are structures. Fixes #727.
2023-12-07 14:28:01 +01:00
Marius Gerbershagen
758ebc6230 Merge branch 'cmpc-refactor' into 'develop'
cmp: further refactor

See merge request embeddable-common-lisp/ecl!311
2023-12-05 20:26:02 +00:00
Tarn W. Burton
ac0f992296
Add tests for Gray read-line 2023-12-04 15:23:38 -05:00
Daniel Kochmański
5a5b327124 cmp: t1/c1expr: top-level symbol macro expansions remain top-level 2023-12-04 21:10:00 +01:00
Daniel Kochmański
6db9231366 cmp: t1epxr*: account for top level forms expanding to atoms 2023-12-04 20:59:29 +01:00
Tarn W. Burton
4ede355c26
Allow empty string for EOF in read-line 2023-12-04 13:01:40 -05:00
Daniel Kochmański
af9d9092c8 cmp: add a comment explaning slots in the structure LABEL 2023-11-25 18:50:13 +01:00
Daniel Kochmański
c2057879e4 cmp: utils: introduce a macro with-lexical-scope
This macro introduces a semantical demarcation of an inner lexical scope.
2023-11-25 18:50:13 +01:00
Daniel Kochmański
f57fa4fab3 cmp: set-loc: accept explicit destination argument
Most of the time when we've used SET-LOC we've rebound *DESTINATION* for that
particular operation. Instead of doing so right now the argument is explicit and
when we want to use the *DESTINATION* then we simply use it (literally 2 cases).
2023-11-25 18:50:13 +01:00
Daniel Kochmański
ef4ab04eda cmp: implement foreign data locations
Instead of directly opencoding them in t3-defcallback we take a more organized
approach where we work with locations. This is part of larger refactor.
2023-11-25 18:50:13 +01:00
Daniel Kochmański
ef36cf53e0 cmp: abstract away STACK emitter with a macro
We also get rid of (STACK <int>) exit in favor of an explicit frame. This was
used only by UNWIND-PROTECT for no apparent reason.
2023-11-25 18:50:13 +01:00
Daniel Kochmański
f72726a032 cmp: abstract away FRAME emitter with a macro 2023-11-25 18:50:13 +01:00
Daniel Kochmański
11aa544292 cmp: rewrite c2progn for readibility 2023-11-25 18:50:13 +01:00
Daniel Kochmański
521e815158 cmp: rewrite c2tagbody-body for readibility 2023-11-25 18:50:13 +01:00
Daniel Kochmański
938a757220 cmp: merge operators with-exit-label and with-optional-exit-label
Their core difference was that the latter coudl reuse the destination. We make
the exit argument explicit and optional in with-exit-label.
2023-11-25 18:50:13 +01:00
Daniel Kochmański
62c68c5bbc cmp: factor out emit-entry-fun from ctop-write 2023-11-25 18:50:13 +01:00
Daniel Kochmański
abd109c982 cmp: further rewrite the exit manager for clearity
This commit makes the exit type explicit and removes a need to test the result
of UNWIND-COND.
2023-11-25 18:50:13 +01:00
Daniel Kochmański
c03d856556 cmp: rewrite the exit manager for clearity
This commit rewrites UNWIND-EXIT to explicitly handle conditional jumps. We
remove misleading SET-JUMP-{TRUE,FALSE} and implement them locally.
2023-11-25 18:50:11 +01:00