Commit graph

1590 commits

Author SHA1 Message Date
Marius Gerbershagen
c8003c2fc4 cmp: quote arguments when invoking C compiler
Now we can compile files with spaces in their paths on windows.
2020-01-26 21:33:45 +01:00
Daniel Kochmański
3743c85d4d cmp: unoptimized long call: evaluate the function first
Fixes #550.
2020-01-12 11:18:46 +01:00
Marius Gerbershagen
d908394007 cmp: don't return nil in compile if compilation failed
The ansi standard states that compile has to return a compiled
function. Fixes various errors in the ansi-test suite.
2019-12-29 23:02:40 +01:00
Marius Gerbershagen
a4e93f7b61 cmp: fix compiler macro for sequence functions with :end argument
The :end argument was ignored previously.
2019-12-22 20:31:48 +01:00
Marius Gerbershagen
35e4a9160f cmp: fix proclamations for formatter functions
Some of the argument type proclamations were wrong.
2019-12-22 15:08:26 +01:00
Marius Gerbershagen
93e9c3b4ad cmp: add missing proclamations for formatter functions
All functions declared with si::c-export-fname must be either in
symbols_list.h or have a proclamation so that the compiler knows the
number of arguments that the function takes.
2019-12-22 00:14:19 +01:00
Marius Gerbershagen
7e381828f1 cmp: fix segmentation faults from coerce compiler macro
si::coerce-to-vector assumed that the to be coerced object had the
same length as that specified by the type. This lead to segmentation
faults even in safe code, for example in

(coerce '(a b c) '(vector * 4))

(coerce.error.3 test in ansi-tests)

Actually, si::coerce-to-vector had some checks for a correct length
previously, but they did not work correctly and were removed in commit
baaab01841.
2019-12-21 23:03:07 +01:00
Daniel Kochmański
69af894224 cmp: remove dynamic variable *compiler-input*
*compiler-input* was only passed to the first-pass, there is no need
for a dynamic binding.
2019-12-16 10:20:47 +01:00
Daniel Kochmański
05cc54a75e cmp: remove global entries machinery
This is a dead code which is not used in the compiler. It was meant
for providing entry points from Common Lisp code to ECL functions
written in C, but it was replaced by more robust machinery.
2019-12-16 10:20:47 +01:00
Daniel Kochmański
01e49c845a cmp: cmpc-machine: cosmetic: put tables in columns
It is easier to read this code this way. It goes well beyond 80
character limit but the alternative is not readable for human.
2019-12-16 10:20:47 +01:00
Daniel Kochmański
7dbde99b7c ffi: defcallback: unify behavior of dffi and compiled versions
- normalize return-type from NIL to :void, ARRAY and '* in interpreted
  dffi implementation -- it is already normalized in sffi

- remove invalid path where argument type was not a valid elementary
  FFI type

  when it was not c1-defcallback pushed result of add-object to
  arg-type-constants and tried to pass the data as opaque
  pointers. That said it could never work, because:

  1. add-object could return a string (i.e for known symbols expanding
     to ECL_SYM) and they were fed as elementary FFI type leading to
     errors during compilation by C compiler (invalid enum type)

  2. when ecl_make_foreign_data was called to pass opaque objects a
     function FFI:SIZE-OF-FOREIGN-TYPE was called which resulted in
     error (because return type is not a valid elementary FFI type
     what this code path was meant to be)

Moreover we validate both return type and argument types during the
first compiler to fail as early as possible (previously only argument
types were validated early).

- some cosmetic fixes like indentation or redundant PROGN
2019-12-16 10:20:42 +01:00
Daniel Kochmański
83ec2c86c7 cmpcbk: improve +foreign-elt-type-codes+
- move the constant and a function foreign-elt-type-code to the top
- re-align the constant data
- fix the feature reader conditionals (they were misplaced)
- add reader conditionals for complex floats
2019-12-11 16:13:34 +01:00
Daniel Kochmański
241f3ed172 cmp: remove unused variables: *compile-time-too*, *not-compile-time*
First one is never bound to T and second one is not referenced at
all. *compilation-time-too* when T was interpreted to evaluate forms
before compiling them (independent of eval-when).
2019-12-11 16:13:34 +01:00
Daniel Kochmański
57e09c89b1 cmp: t1expr*: expand symbol macros
They were silently ignored before in compiled files. The were not
ignored in files which were just loaded.

  (define-symbol-macro foo (error "HI"))
  foo ; ignored
2019-12-11 16:13:34 +01:00
Daniel Kochmański
cab4917d86 cmp: cmpmain first pass: put the pass in a separate function
Function behaves differently for streams and for other objects. This
makes the code more consistent.
2019-12-11 16:13:31 +01:00
Daniel Kochmański
02f30c68b7 cmp: improve notes 2019-12-08 11:05:15 +01:00
Marius Gerbershagen
bc9f75871e cmp: complain when the number of arguments of an exported function is not known
When we don't know how many arguments an exported function takes, we
can't create a correct declaration for the C function in the .eclh
file. To avoid having too many proclamations, we extract this
information from symbols_list.h for ECL core functions defined in
Lisp.
2019-12-08 10:26:52 +01:00
Marius Gerbershagen
fbdb0a32a8 cmp: check that number of arguments matches the declaration in symbols_list.h
We also use the *in-all-symbols-functions* variable only for
determining which functions are to be exported during the build of ECL
itself. Otherwise, instead of specifying manually, which Lisp
functions are exported and in the core, we use the information from
symbols_list.h (i.e. we let all_symbols.d initialize all core
functions).
2019-12-08 10:26:52 +01:00
Marius Gerbershagen
18cb1b3552 fix for calling conventions treating fixed and variadic arguments differently
Previously, we assumed that the fixed and variadic arguments of a
variadic function were passed to the function in the same way. The
arm64 calling convention used by iOS breaks this assumption by passing
fixed arguments in registers or on the stack, depending on the
position, while variadic arguments are always passed on the stack.

Solving this problem while still allowing function redefinition at
runtime requires introducing additional dispatch functions. These
dispatch functions take no fixed arguments and pass all their
arguments to the actual function. This dispatch is enabled by passing
-DECL_C_COMPATIBLE_VARIADIC_DISPATCH to the C compiler.

This problem was originally identified and a solution provided by
thewhimer@gmail.com. This commit based on his work with minor
improvements.
2019-12-08 10:26:52 +01:00
Marius Gerbershagen
b067063c94 cmp: prevent inline information from getting lost while compiling ECL itself
C inline information is saved in +default-machine+, which was
previously a constant. However, the value assigned to
+default-machine+ is recomputed during load and compile
time. Technically, assigning a constant a new value which is not eql
to the old one is undefined behaviour in the ANSI standard. What ECL
did was simply to reassign the constant when compiling
cmpc-machine.lsp. However, this meant that the inline information
which was added to +default-machine+ when loading sysfun.lsp was
lost. Thus, all ECL source files compiled after cmpc-machine.lsp were
compiled without inline information. We prevent this by using an
ordinary variable *default-machine* instead of a constant.
2019-11-17 19:58:53 +01:00
Marius Gerbershagen
25d8bf63ef cmp: fix linker-cc for msvc
linker-cc for other compilers includes the libpath in the linker
options, therefore for consistency we need it here too.
2019-08-20 19:52:25 +02:00
Daniel Kochmański
df339485eb Merge branch 'infinity-NaN-numeric-functions' into 'develop'
Make all numeric functions return sensible values for infinity/NaN

Closes #477

See merge request embeddable-common-lisp/ecl!160
2019-08-16 18:52:23 +00:00
Daniel Kochmański
8b82c98cac Merge branch 'alt-fix-513' into 'develop'
Fix 513 2nd try

Closes #514

See merge request embeddable-common-lisp/ecl!159
2019-08-16 18:44:23 +00:00
Marius Gerbershagen
5c7aecc15f ieee-fp: fix min/max for NaN
As for the C functions fmin/fmax, we ignore NaNs
2019-08-14 20:51:40 +02:00
Marius Gerbershagen
046c6b9f32 number_compare.d: fix number comparison for NaN
All comparisons with NaN should return NIL for consistency with the
IEEE standard.
2019-08-14 20:51:40 +02:00
Marius Gerbershagen
61e799074d cmp: fix type propagation for / with one argument
Fixes #522.
2019-08-06 19:38:47 +02:00
Daniel Kochmański
adace6ba08 cmp: replace magic number with a defined constant
The magic number was wrong anyway.
2019-07-20 09:22:01 +02:00
Daniel Kochmański
f3c6e4ccef cmp: remove unused interface *linking-calls*
Variable is always nil so blocks of code are never executed. Remove
it. TRAMPOLINK was used only in such bodies.
2019-07-19 14:30:53 +02:00
Daniel Kochmański
0e7ef61b69 cmp: t3local-fun-declaration: do not call next-lcl more than needed
When we process required arguments their amount may exceed maximum
number of arguments which are allowed to be passed on C stack. In this
case the remainder is shifted to optionals *but* we have called
next-lcl for all arguments what lead to a situation where all
arguments were passed on the list. Fixes #514.
2019-07-19 14:30:53 +02:00
Marius Gerbershagen
1334eb1765 cmp: prevent deadlock if the C compiler output is too large
The pipe from which we read the output of the C compiler could fill up
when a large number of warnings were printed leading to a deadlock
because we waited for the C compiler to finish before reading the
output.
2019-07-15 21:32:36 +02:00
Daniel Kochmański
fcdb1b0657 cmp: c1body: do not error when unknown declaration is encountered
it is hinted in the spec, that compiler issues a warning on unknown
declarations:

http://www.lispworks.com/documentation/HyperSpec/Body/d_declar.htm#declaration

also in other parts of compiler code we warn as well.
2019-05-25 09:56:08 +02:00
Daniel Kochmański
ea87100a06 long-float: remove conditionalization
Many parts of the source code were bent backward to support builds
without long floats which are always present given we depend expect
c99 compiler.

The corresponding C macros (ECL_LONG_FLOAT) and the *feature*
entry (:long-float) are marked as deprecated in the documentation.
2019-05-24 21:04:59 +00:00
Marius Gerbershagen
9dedfe95e5 complex-float: add inline definitions for si::complex-*-float-p 2019-05-20 21:54:05 +02:00
Daniel Kochmański
b8c328b558 coerce: allow coercing to si:complex-*-float
Previously coerce didn't understand these atomic specifiers.
2019-05-15 16:35:16 +02:00
Daniel Kochmański
19526d4032 cmpffi: produce-inline-loc: do not return uninitialized variable
For functions without returned value we did return cl_object value0
which was not initialized. That could lead to segmentation faults if
we have used result of calling a function defined as such location.

SFFI definition like this:

(ffi:def-function ("my_test_function3" sffi-test-3)
    ((x :float) (y :double))
  :returning :void)

was previously compiled to

/*      function definition for SFFI-TEST-3                     */
/*      optimize speed 3, debug 0, space 0, safety 2            */
static cl_object L6sffi_test_3(cl_object v1x, cl_object v2y)
{
 cl_object env0 = ECL_NIL;
 const cl_env_ptr cl_env_copy = ecl_process_env();
 cl_object value0;
 ecl_cs_check(cl_env_copy,value0);
 {
TTL:
  my_test_function3(ecl_to_float(v1x),ecl_to_double(v2y));
  cl_env_copy->nvalues = 0;
  return value0;
 }
}

and now it is compiled to

/*      function definition for SFFI-TEST-3                       */
/*      optimize speed 3, debug 0, space 0, safety 2              */
static cl_object L6sffi_test_3(cl_object v1x, cl_object v2y)
{
 cl_object env0 = ECL_NIL;
 const cl_env_ptr cl_env_copy = ecl_process_env();
 cl_object value0;
 ecl_cs_check(cl_env_copy,value0);
 {
TTL:
  my_test_function3(ecl_to_float(v1x),ecl_to_double(v2y));
  value0 = ECL_NIL;
  cl_env_copy->nvalues = 0;
  return value0;
 }
}

void functions are treated the same as when *destionation* is 'RETURN
in cmpmulti.lsp.
2019-05-15 16:35:16 +02:00
Daniel Kochmański
07ebf7dfc6 complex-float: add inline definitions to the compiler 2019-05-15 16:35:16 +02:00
Daniel Kochmański
8cc0ae7222 complex float: add compiler optimizations and ffi definitions
- add ffi implementation for long-float
- add ffi implementation for (complex float) types
- add compiler optimizations and definitions for complex float

We do not add c?float common constants (long-float i.e has optimizer
for 0.0 and -0.0), because we don't know if they are common at all and
if we think about it each would have four entries counting signed
zeros).

Also add informative comment about global-entries.
2019-05-15 16:35:16 +02:00
Daniel Kochmański
a0a92dc2af complex float: add a new types and builtin classes
What has changed:

- new types si:complex-float, si:complex-single-float,
  si:complex-double-float and si:complex-long-float
- new builtin classes long-float (for completness) and
  si:complex-float
- new internal function si:complex-float and si:complex-float-p for
  constructing complex floats (both arguments must be of the same
  float type) and a type predicate
- printer for new types (right now it conses, see below)
- a new feature :complex-float
- a new type is recognized as a type disjoint of complex and real

- cleanup: +built-in-type-list+: remove some redundancy
  For instance instread of saying
    (real (or integer single-float double-float ratio))
  We say
    (real (or integer float ratio))
  etc.

Flaws which will be fixed in upcoming commits:

- complex-float hierarchy is independent of the complex hierarchy
- ecl_make_complex_float could be replaced by _ecl_make_complex_*float
- write_complex_float allocates new objects for printing
- write_complex_float does print unreadable object
- math dispatchers doesn't recognize the object

Testing things out:

> (si:complex-float 0.0d0 0.0d0)
; #<CF(0.0d0 0.0d0)>
> (si:complex-float 0.0d0 0.0s0)       ; signals type error
> (+ (si:complex-float 0.0d0 0.0d0) 1) ; signals type error

lisp runtime: make si_complex-float a subtype of a number.
2019-05-13 19:48:54 +02:00
Daniel Kochmański
0033f24be2 constant folding: fix regression for single and multiple values
Closes #497.
2019-05-05 10:38:02 +02:00
Daniel Kochmański
097fa96ae0 cmp: coerce: resolve fixme for atomic complex specifier
it is not true, that

  (type= '(complex) '(complex double-float)) == T

so we may put complex in +coercion-table+.
2019-04-20 17:14:14 +02:00
Daniel Kochmański
d7c351c76a predlib: type= doesn't yield T for complex types
TYPE= is only used from cmpopt's typep compiler macro which optimizes
atomic complex types by other means. Compound complex types are
handled differently for subtypep and typep (the first relies on
upgraded type and the second relies on the actual types), so we can't
rely in this case on SAFE-CANONICAL-TYPE.
2019-04-20 17:13:17 +02:00
Marius Gerbershagen
209434f91a cmp: fix constant folding for functions that return multiple values 2019-03-23 18:51:18 +01:00
Marius Gerbershagen
60870ae9b0 use correct unnormalized values for minimum float constants
Fixes #470.
2019-02-13 20:24:26 +01:00
Marius Gerbershagen
19c6635ff0 expt: use pow function for floating point numbers
Improves speed and accurracy.
2019-02-12 22:37:23 +01:00
Marius Gerbershagen
dff91be38c sysfun.lsp: clean up inline expansions for floating point numbers
Define all expansions also for long floats if available, use
    single float C functions when given a single float.
2019-02-12 22:30:57 +01:00
Daniel Kochmanski
13a42249e2 cas: add remcas operation for an expansion removal
It is a (fmakunbound (setf foo)) counterpart.
2019-02-07 13:29:03 +01:00
Daniel Kochmanski
9096514cff extensions: put ext:package-locked-p in core module. 2019-02-07 13:27:12 +01:00
Marius Gerbershagen
24dcb778cf clean up functions creating base strings from C strings
Make functions behave as documented, remove use of legacy names.
    Fixes #462.
2019-01-07 18:43:55 +01:00
Marius Gerbershagen
76941e25dc fix the broken serialization functions for externalizable objects 2018-12-10 18:14:01 +01:00
Marius Gerbershagen
9f4a5d4dd4 disassemble: display generated C source code instead of bytecodes
This behaviour makes more sense, since the ANSI standard mandates
    that disassemble should compile an interpreted function before
    displaying the output (our own documentation even says so).

    Also fixes disassemble for closures.
2018-11-24 19:20:06 +01:00