Commit graph

7695 commits

Author SHA1 Message Date
Daniel Kochmański
6e5016dcb8 hash-table: add extension for generic predicates
Added:
- implementation
- test
- documentaiton entries

Additionally:
- remove #if 0 code branches (unused clutter)
- bring up-to-date help.lsp file for hints in slime
- wrap synchronized access in unwind protect
- write_ugly did not carry extensions in the printer
2019-05-25 09:56:08 +02:00
Daniel Kochmański
aa985f566f make-load-form-saving-slots: structures: refrence slot by an offset
At least one library (adt) redefines structures with slot names being
uninterned symbols. That means that we lose slot offset if we
reference it by name what leads to load errors if
make-load-form-saving-slots was called. We fix that by handling
structure-object's separately.

allocate-instance is another oddball in the spec when taken with
structure-classes (and it is used in make-load-form-saving-slots). If
there are *some* slots saved then rest must be initialized so object
could be used - we put there NIL without checking for a type. SBCL
tries to find a constructor for a structure (custom protocol) or
errors while CCL initializes slots to NIL. We follow the latter.
2019-05-25 09:56:08 +02:00
Daniel Kochmański
372d340fe1 numbers: expt: add default clause to avoid compilation warnings
We simply call ecl_internal_error there.
2019-05-25 09:56:08 +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
f7ffa893a6 defstruct: redefine: relax requirement to have slot names eql
As explained in the comment: structure may be a result of code
generation which will likely use gensym. In this case name eql casues
compilation/load problems. I.e adt library dos that.
2019-05-25 09:56:08 +02:00
Daniel Kochmański
bc839d2a41 aclocal: fix typo in test for complex float 2019-05-25 09:55:50 +02:00
Daniel Kochmański
4d6cac7885 Merge branch 'cleanup-always-long-float' into 'develop'
long-float: remove conditionalization

See merge request embeddable-common-lisp/ecl!151
2019-05-24 21:04:59 +00: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
Daniel Kochmański
8c30d1a371 Merge branch 'float-complex-leftovers' into 'develop'
Various changes related to float complexes

See merge request embeddable-common-lisp/ecl!150
2019-05-21 17:53:52 +00:00
Marius Gerbershagen
9dedfe95e5 complex-float: add inline definitions for si::complex-*-float-p 2019-05-20 21:54:05 +02:00
Marius Gerbershagen
78dd8ecaad numlib.lsp: refactor inverse (hyperbolic) trigonometric functions
Most of the functionality has been abstracted into a macro. For
consistency and speed we now always use the C complex functions if
available.
2019-05-20 21:50:58 +02:00
Marius Gerbershagen
be9b6d35ae update changelog 2019-05-20 21:44:45 +02:00
Marius Gerbershagen
95b02061b8 legacy.h: replace all remaining occurences of type_of with ecl_t_of 2019-05-20 20:31:47 +02:00
Marius Gerbershagen
a420a378ac complex-float: detect floating point exceptions 2019-05-20 18:28:19 +02:00
Marius Gerbershagen
d70f0317ec Merge branch 'feature-float-complex' into 'develop'
Feature complex float

See merge request embeddable-common-lisp/ecl!149
2019-05-17 16:33:14 +00:00
Daniel Kochmański
6037070343 expt: rework the function
- extract functions for handling different kind of results
- add specialised code for floats and complex floats in integer case
- improve comments a little
- fix the regression where (expt -1.0 2) results in complex result
2019-05-15 18:02:28 +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
b2b6548af6 dffi: disable complex argument type
libffi is incapable of properly handling complex float argument types
yet. Commit disables complex types and adds a comment explaining
what's going on.

SFFI types which doesn't have counterpart in DFFI conversion table are
NULL and function ecl_type_to_libffi_type will signal a condition when
they are used.
2019-05-15 16:35:16 +02:00
Daniel Kochmański
05f94fc730 complex-float: add serializer definitions 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
db5e0937b3 complex-float: add a specialized array type for complex floats 2019-05-15 16:35:16 +02:00
Daniel Kochmański
c17f23f253 complex-float: add documentation bits 2019-05-15 16:35:16 +02:00
Daniel Kochmański
41afa2da35 complex-float: add some tests
Most of things is covered in ANSI-TESTS anway, these are just smoke
tests for some functionality and taking into account internal
implementation details.
2019-05-15 16:35:16 +02:00
Daniel Kochmański
044858cf23 complex-float: rework numlib functions (atanh and such)
numlib is similar to math operation definitions in core but these
functions are implemented in C.

- refactor functions for code clarity
- add definitions for complex float
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
51594b8037 complex-float: print like any other complex number
During printing we cons new floats for imag and real part. We could
opencode that but that would add a lot of code for a little gain. If
this proves to be a real bottleneck we will refactor float printing.
2019-05-15 16:35:16 +02:00
Daniel Kochmański
2bcba673f3 complex-float: implement hashing methods
- _Complex long double is first cast to _Complex double (just like
  long double) to avoid hashing non-meaningful bits

- We adhere to the "similarity" principle, that is sxhash -0.0 is the
  same as sxhash 0.0.
2019-05-15 16:35:16 +02:00
Daniel Kochmański
86f10de4a0 complex float: implement eql, equal and equalp
equalp is delegated to ecl_number_equalp. we do not treat signed zero,
infinity nor nan.

float_eql is not the same as ==, because we have signed zeros and nan
values which should be compared memory-wise.
2019-05-15 16:35:16 +02:00
Daniel Kochmański
d73b604fc8 complex float: implement expt 2019-05-15 16:35:16 +02:00
Daniel Kochmański
7323d05504 complex float: implement equalp 2019-05-15 16:35:16 +02:00
Daniel Kochmański
ba154a606a complex-float: implement divide and times operations 2019-05-15 16:35:16 +02:00
Daniel Kochmański
14156559e3 complex-float: implement minus operation 2019-05-15 16:35:16 +02:00
Daniel Kochmański
9e06e30660 complex float: implement plus operator
complex float: plus: fix contagion issue

also we expand into the same code path for c?float types disregarding
the argument order.
2019-05-15 16:35:16 +02:00
Daniel Kochmański
800ba8e319 complex float: implement unary math operators
- still missing: trig/hyper arcus variants
- unary < <= = >= = min max
2019-05-15 16:35:16 +02:00
Daniel Kochmański
e1adfd2794 numeric tower: merge <complex float> with <complex>
cl_type_of: give better results for (type-of <complex>)

Instead of simply returning complex we return:

  (complex real)

when code is built without complex float support, and otherwise

  (complex rational)
  (complex single-float)
  (complex double-float)
  (complex long-float)

New functions:
- ecl_to_csfloat
- ecl_to_cdfloat
- ecl_to_clfloat
2019-05-15 16:35:16 +02:00
Daniel Kochmański
fdc40520a2 complex float: extend math_dispatch macros and add appropriate stubs 2019-05-15 16:35:11 +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
20a7030277 complex float: add gc boilerplate 2019-05-06 08:17:33 +02:00
Daniel Kochmański
f78cb49def complex float: rename cl_lispunion member complex to gencomplex
Complex is a macro specified in complex.h for c99 to simplify using
_Complex type. This file also contains functions to work on complex
floats. To avoid conflicts we rename internal name complex to
gencomplex and update all references to it.
2019-05-06 08:17:33 +02:00
Daniel Kochmański
6ecd2473c4 complex float: add types and structures to core runtime
t_csfloat - ecl_csfloat,
t_cdfloat - ecl_cdfloat,
t_clfloat - ecl_clfloat.
2019-05-06 08:17:33 +02:00
Daniel Kochmański
e7725d4bcf abs: (abs -0.0) -> 0.0
example in clhs is not normative and this code is wrong. We use
fabs(f/l) to have a correct result.
2019-05-05 22:54:51 +02:00
Marius Gerbershagen
aa5ed8bc7b printer: ensure that we generate enough digits for floats
When the number of digits was not specified, we were sometimes
outputting a number that was exactly halfway between the exact value
and the next higher float. When reading that number in again, one
would get a different value due to rounding issues. Therefore, we now
always output enough digits, so that the number can be reconstructed
unambigously. Fixes #500.
2019-05-05 16:58:17 +02:00
Marius Gerbershagen
8a82b9fcfb numbers: fix coercion of ratios/bignums to floats
The function extracting the mantissa and exponent from a ratio has
been simplified and improved.
2019-05-05 16:58:17 +02:00
Marius Gerbershagen
a7c6820506 Merge branch 'clean-math-3' into 'develop'
Clean math 3 (without float conversion changes)

Closes #486 und #497

See merge request embeddable-common-lisp/ecl!147
2019-05-05 13:40:17 +00:00
Daniel Kochmański
0fcf21b4a7 tests: compiler: add regression test for constant folding. 2019-05-05 10:38:02 +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
5dd4174225 msvc: gmp: add mpq sources 2019-05-05 10:38:02 +02:00
Daniel Kochmański
1533824059 buildsystem: improve checks for floats
We do not check for c99-mandated functions for long float (we only
check for the type). We also check for complex numbers in a separate
function and define ECL_COMPLEX_FLOAT when found.
2019-05-05 10:38:02 +02:00
Daniel Kochmański
7c6de43e4c numbers: use fast dispatch in ecl_integer_divide (round) 2019-05-05 10:38:02 +02:00