1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-29 19:30:36 +02:00
Commit graph

168 commits

Author SHA1 Message Date
Mike Gran
9b357bace3 Presume ISO C90 headers are always available
This includes <assert.h>, <ctype.h>, <errno.h>, <float.h>, <iso646.h>,
<limits.h>, <locale.h>, <math.h>, <setjmp.h>, <signal.h>, <stdarg.h>,
<stddef.h>, <stdio.h>, <stdlib.h>, <string.h>, <time.h>, <wchar.h>,
and <wctype.h>.

* configure.ac: don't check for <limits.h>, <string.h>, <time.h>, <assert.h>.
   Remove AC_INCLUDES_DEFAULT macro
* libguile/bytevectors.c: include <limits.h>, remove HAVE_LIMITS_H
* libguile/filesys.c: include <string.h>, remove HAVE_STRING_H
* libguile/fports.c: include <string.h>, remove HAVE_STRING_H
* libguile/gen-scmconfig.c: remove HAVE_LIMITS_H, HAVE_TIME_H, STDC_HEADERS
    Remove SCM_HAVE_STDC_HEADERS
* libguile/hash.c: include <wchar.h>, remove HAVE_WCHAR_H
* libguile/net_db.c: include <string.h>, remove HAVE_STRING_H
* libguile/numbers.h: remove SCM_HAVE_STDC_HEADERS
* libguile/regex-posix.c: include <wchar.h>, remove HAVE_WCHAR_H
  (fixup_multibyte_match): always defined
  (scm_regexp_exec): use fixup_multibyte_match
* libguile/scmsigs.c: remove STDC_HEADERS
* libguile/socket.c: include <string.h>, remove HAVE_STRING_H
* test-suite/standalone/test-unwind.c: include <string.h>, remove HAVE_STRING_H
2022-10-14 08:40:23 -07:00
Andy Wingo
aa5455ea98 Bignums avoid both custom GMP allocator and finalizers
* libguile/deprecated.c (make_bignum): Move here from numbers.c, to
support scm_i_long2big etc.
(scm_i_big2dbl):
(scm_i_long2big):
(scm_i_ulong2big):
(scm_i_clonebig):
(scm_i_normbig): Deprecate.
(scm_install_gmp_memory_functions): Deprecate, happily!  SCM bignums now
have digits allocated inline with the bignum itself, so they are
completely transparent to the GC already.  The price is that if GMP ever
allocates digits via the MPZ API, those digits then have to be copied
back into managed memory.  But we avoid having to install finalizers and
we avoid having to muck with GMP's allocator.
* libguile/numbers.c (scm_from_mpz): Use scm_integer_from_mpz.
(scm_init_numbers): Never muck with GMP's allocators.
* doc/ref/guile-invoke.texi (Environment Variables): Remove note about
GUILE_INSTALL_GMP_MEMORY_FUNCTIONS.
* meta/build-env.in: No need to set GUILE_INSTALL_GMP_MEMORY_FUNCTIONS.
2022-01-13 09:37:17 +01:00
Andy Wingo
bdddef3cfd Avoid scm_i_mkbig outside numbers.c.
* libguile/random.c (scm_c_random_bignum):
* libguile/socket.c (scm_from_ipv6): Avoid scm_i_mkbig.
* libguile/numbers.h:
* libguile/numbers.c (scm_i_mkbig): Remove.
2022-01-13 09:37:17 +01:00
Andy Wingo
7c53325c31 Fix scm_integer_to_double_z to always round; clean ups
* libguile/integers.c (scm_integer_to_double_z): Doubles that can't be
exactly represented as integers should round.
(bignum_frexp_z): New helper.
(scm_integer_from_mpz, scm_integer_from_double): New internal functions.
* libguile/numbers.h:
* libguile/numbers.c (scm_i_bigcmp, scm_i_dbl2big, scm_i_dbl2num):
Remove unused internal functions.
(scm_inexact_to_exact): Rework to avoid scm_i_dbl2big.
(scm_bigequal): Move here, from eq.c.
(scm_integer_to_double_z): Use the new helper.
(scm_i_big2dbl): Use scm_integer_to_double_z.
2022-01-13 09:37:16 +01:00
Andy Wingo
f46477f6f5 Don't expose mini-gmp to users
* libguile.h: Don't import anything GMP-related.
* libguile/numbers.h: Import GMP here instead.  If we are using
mini-GMP, only import it when building Guile.
(scm_to_mpz, scm_from_mpz): Don't define when mini-gmp is enabled.
2021-03-08 22:16:15 +01:00
Michael Gran
6ca3ab621c don't presume availability of gmp.pc
This suggests moving the conditional that determines if mini-gmp is used
into scmconfig.h.

* configure.ac: replace PKG_CHECK_MODULES for gmp with AC_LIB_HAVE_LINKFLAGS
    Remove ENABLE_MINI_GMP define.  Also don't run mpz_inits test for
    --enable-mini-gmp.
* libguile/gen-scmconfig.c (main) [ENABLE_MINI_GMP]: replace ENABLE_MINI_GMP
    with SCM_I_GSC_ENABLE_MINI_GMP
* libguile/bytevectors.c [ENABLE_MINI_GMP]: replace ENABLE_MINI_GMP
    with SCM_ENABLE_MINI_GMP
* libguile/init.c [ENABLE_MINI_GMP]: replace ENABLE_MINI_GMP
    with SCM_ENABLE_MINI_GMP
* libguile/numbers.c: include scm.h
    [SCM_ENABLE_MINI_GMP]: provide mpz_inits and mpz_clears
    [ENABLE_MINI_GMP]: prefer SCM_ENABLE_MINI_GMP to ENABLE_MINI_GMP
* libguile/numbers.h: include scm.h
* libguile/random.c [ENABLE_MINI_GMP]: replace ENABLE_MINI_GMP
    with SCM_ENABLE_MINI_GMP
* libguile/socket.c [ENABLE_MINI_GMP]: replace ENABLE_MINI_GMP
    with SCM_ENABLE_MINI_GMP
2021-03-03 14:06:29 -08:00
Michael Gran
54adbd6f0f improve autoconfigury for minigmp
* configure.ac: add SCM_I_GSC_ENABLE_MINI_GMP var and rename
    GUILE_MINI_GMP to ENABLE_MINI_GMP
* libguile/bytevectors (GUILE_MINI_GMP): rename to ENABLE_MINI_GMP
* libguile/gen-scmconfig.c: renamed GUILE_MINI_GMP to ENABLE_MINI_GMP.
    rename GUILE_MINI_GMP to SCM_ENABLE_MINI_GMP
* libguile/gen-scmconfig.h: add SCM_I_GSC_ENABLE_MINI_GMP
* libguile/init.c [GUILE_MINI_GMP]: prefer ENABLE_MINI_GMP
* libguile/numbers.c [GUILE_MINI_GMP]: prefer ENABLE_MINI_GMP
* libguile/numbers.h: include scmconfig.h
    rename GUILE_MINI_GMP to SCM_ENABLE_MINI_GMP
* libguile/random.c [GUILE_MINI_GMP]: prefer ENABLE_MINI_GMP
* libguile/socket.c [GUILE_MINI_GMP]: prefer ENABLE_MINI_GMP
* libguile.h [GUILE_MINI_GMP]: prefer SCM_ENABLE_MINI_GMP
2021-03-02 06:18:32 -08:00
Michael Gran
eb1bd8050e Enable option to prefer mini-gmp over libgmp
* configure.ac: rework gmp library detection. Add new flag.
* libguile.h: modify gmp header inclusion
* libguile/Makefile.am: add mini-gmp.[ch] files
* libguile/bytevectors.c: add mini-gmp headers
* libguile/gen-scmconfig.c: new #include variable GUILE_MINI_GMP
* libguile/init.c: add mini-gmp header
* libguile/mini-gmp.c: new file
* libguile/mini-gmp.h: new file
* libguile/numbers.c: add fallback for missing mpz_get_d_2exp
* libguile/numbers.h: yse mini-gmp header
* libguile/random.c: use mini-gmp header
* libguile/socket.c: use mini-gmp header
2021-03-02 06:18:32 -08:00
Andy Wingo
8ecc82959a Merge from stable-2.2 2019-08-02 15:03:18 +02:00
Mark H Weaver
3ec7afb2c6 Refresh a stale comment.
* libguile/numbers.h: In a comment, update the count of number subtypes.
2019-06-18 03:05:05 -04:00
Andy Wingo
6ad1fc9ce0 Use ptrdiff_t instead of scm_t_ptrdiff
* libguile/continuations.h:
* libguile/control.c:
* libguile/control.h:
* libguile/dynstack.c:
* libguile/dynstack.h:
* libguile/eval.c:
* libguile/foreign.c:
* libguile/frames.h:
* libguile/gen-scmconfig.c:
* libguile/gsubr.c:
* libguile/gsubr.h:
* libguile/loader.c:
* libguile/numbers.h:
* libguile/stacks.c:
* libguile/throw.c:
* libguile/vm-engine.c:
* libguile/vm.c:
* libguile/vm.h: Use ptrdiff_t from stddef.h.
2018-06-21 20:20:01 +02:00
Andy Wingo
16879cabed Replace uses of scm_t_int8, scm_t_uintmax, etc with stdint types
* libguile/bitvectors.c:
* libguile/bitvectors.h:
* libguile/bytevectors.c:
* libguile/bytevectors.h:
* libguile/chars.c:
* libguile/continuations.c:
* libguile/control.c:
* libguile/conv-integer.i.c:
* libguile/conv-uinteger.i.c:
* libguile/dynstack.c:
* libguile/dynstack.h:
* libguile/foreign.c:
* libguile/frames.c:
* libguile/frames.h:
* libguile/gc-inline.h:
* libguile/gc.h:
* libguile/gsubr.c:
* libguile/gsubr.h:
* libguile/hash.c:
* libguile/i18n.c:
* libguile/instructions.c:
* libguile/intrinsics.c:
* libguile/intrinsics.h:
* libguile/loader.c:
* libguile/loader.h:
* libguile/numbers.c:
* libguile/numbers.h:
* libguile/pairs.c:
* libguile/ports-internal.h:
* libguile/ports.c:
* libguile/ports.h:
* libguile/posix.c:
* libguile/print.c:
* libguile/print.h:
* libguile/programs.c:
* libguile/programs.h:
* libguile/r6rs-ports.c:
* libguile/random.c:
* libguile/random.h:
* libguile/scm.h:
* libguile/socket.c:
* libguile/srfi-4.c:
* libguile/srfi-4.h:
* libguile/stacks.c:
* libguile/stime.c:
* libguile/strings.c:
* libguile/struct.c:
* libguile/struct.h:
* libguile/symbols.c:
* libguile/threads.c:
* libguile/threads.h:
* libguile/uniform.c:
* libguile/vm-engine.c:
* libguile/vm.c:
* libguile/vm.h:
* libguile/vports.c:
* test-suite/standalone/test-conversion.c:
* test-suite/standalone/test-ffi-lib.c:
* test-suite/standalone/test-scm-take-u8vector.c:
* test-suite/standalone/test-srfi-4.c: Replace e.g. scm_t_uint8 with
  uint8_t.
2018-06-21 20:18:54 +02:00
Andy Wingo
1234bb1850 Update license notices in all C files
Update to newest recommended license notices from the FSF.  Everything
stays LGPLv3+ except guile-readline which is GPLv3+.
2018-06-20 20:07:34 +02:00
Andy Wingo
c836c28496 libguile header files have uniform format for copyright declarations 2018-06-20 19:44:45 +02:00
Andy Wingo
791eb0c01a Remove (C) from copyright statements
As the FSF advises, 'There is no legal significance to using the
three-character sequence “(C)”, but it does no harm.'  It does take up
space though!  For that reason, we remove it here from our C files.
2018-06-20 19:17:06 +02:00
Andy Wingo
97cc65fee4 Rename __scm.h to scm.h
* libguile/scm.h: Rename.  Update all includers.
2018-06-20 16:33:33 +02:00
Andy Wingo
c495b44714 Remove Emacs local variables comments in Guile source
The .dir-locals.el file in the repository is sufficient for Emacs
users.

* libguile/__scm.h:
* libguile/alist.c:
* libguile/alist.h:
* libguile/array-handle.c:
* libguile/array-handle.h:
* libguile/array-map.c:
* libguile/array-map.h:
* libguile/arrays.c:
* libguile/arrays.h:
* libguile/async.c:
* libguile/async.h:
* libguile/backtrace.c:
* libguile/backtrace.h:
* libguile/bitvectors.c:
* libguile/bitvectors.h:
* libguile/boolean.c:
* libguile/boolean.h:
* libguile/chars.c:
* libguile/chars.h:
* libguile/chooks.c:
* libguile/chooks.h:
* libguile/continuations.c:
* libguile/continuations.h:
* libguile/control.c:
* libguile/conv-integer.i.c:
* libguile/debug-malloc.h:
* libguile/debug.c:
* libguile/debug.h:
* libguile/deprecation.c:
* libguile/deprecation.h:
* libguile/dynl.c:
* libguile/dynl.h:
* libguile/dynstack.c:
* libguile/dynstack.h:
* libguile/dynwind.c:
* libguile/dynwind.h:
* libguile/eq.c:
* libguile/eq.h:
* libguile/error.c:
* libguile/error.h:
* libguile/eval.c:
* libguile/eval.h:
* libguile/evalext.c:
* libguile/evalext.h:
* libguile/expand.c:
* libguile/expand.h:
* libguile/extensions.c:
* libguile/extensions.h:
* libguile/feature.c:
* libguile/feature.h:
* libguile/filesys.c:
* libguile/filesys.h:
* libguile/fluids.c:
* libguile/fluids.h:
* libguile/foreign.c:
* libguile/fports.c:
* libguile/fports.h:
* libguile/frames.c:
* libguile/frames.h:
* libguile/gc-inline.h:
* libguile/gc.c:
* libguile/gc.h:
* libguile/generalized-arrays.c:
* libguile/generalized-arrays.h:
* libguile/generalized-vectors.c:
* libguile/generalized-vectors.h:
* libguile/gettext.c:
* libguile/gettext.h:
* libguile/goops.c:
* libguile/goops.h:
* libguile/gsubr.c:
* libguile/gsubr.h:
* libguile/guardians.c:
* libguile/guardians.h:
* libguile/guile.c:
* libguile/hash.c:
* libguile/hash.h:
* libguile/hashtab.c:
* libguile/hashtab.h:
* libguile/hooks.c:
* libguile/hooks.h:
* libguile/i18n.c:
* libguile/i18n.h:
* libguile/init.c:
* libguile/init.h:
* libguile/instructions.c:
* libguile/instructions.h:
* libguile/intrinsics.c:
* libguile/intrinsics.h:
* libguile/ioext.c:
* libguile/ioext.h:
* libguile/iselect.h:
* libguile/keywords.c:
* libguile/keywords.h:
* libguile/list.c:
* libguile/list.h:
* libguile/load.c:
* libguile/load.h:
* libguile/loader.c:
* libguile/loader.h:
* libguile/macros.c:
* libguile/macros.h:
* libguile/mallocs.c:
* libguile/mallocs.h:
* libguile/memmove.c:
* libguile/memoize.c:
* libguile/memoize.h:
* libguile/modules.c:
* libguile/modules.h:
* libguile/net_db.c:
* libguile/net_db.h:
* libguile/null-threads.c:
* libguile/null-threads.h:
* libguile/numbers.c:
* libguile/numbers.h:
* libguile/objprop.c:
* libguile/objprop.h:
* libguile/options.c:
* libguile/options.h:
* libguile/pairs.c:
* libguile/pairs.h:
* libguile/poll.c:
* libguile/poll.h:
* libguile/ports.c:
* libguile/ports.h:
* libguile/posix.c:
* libguile/posix.h:
* libguile/print.c:
* libguile/print.h:
* libguile/procprop.c:
* libguile/procprop.h:
* libguile/procs.c:
* libguile/procs.h:
* libguile/programs.c:
* libguile/programs.h:
* libguile/promises.c:
* libguile/promises.h:
* libguile/pthread-threads.h:
* libguile/random.c:
* libguile/random.h:
* libguile/rdelim.c:
* libguile/rdelim.h:
* libguile/read.c:
* libguile/read.h:
* libguile/regex-posix.c:
* libguile/regex-posix.h:
* libguile/rw.c:
* libguile/rw.h:
* libguile/scmsigs.c:
* libguile/scmsigs.h:
* libguile/script.c:
* libguile/script.h:
* libguile/simpos.c:
* libguile/simpos.h:
* libguile/smob.c:
* libguile/smob.h:
* libguile/snarf.h:
* libguile/socket.c:
* libguile/socket.h:
* libguile/sort.c:
* libguile/sort.h:
* libguile/srcprop.c:
* libguile/srcprop.h:
* libguile/stackchk.c:
* libguile/stackchk.h:
* libguile/stacks.c:
* libguile/stacks.h:
* libguile/stime.c:
* libguile/stime.h:
* libguile/strerror.c:
* libguile/strings.c:
* libguile/strings.h:
* libguile/strorder.c:
* libguile/strorder.h:
* libguile/strports.c:
* libguile/strports.h:
* libguile/struct.c:
* libguile/struct.h:
* libguile/symbols.c:
* libguile/symbols.h:
* libguile/syntax.c:
* libguile/syscalls.h:
* libguile/tags.h:
* libguile/threads.c:
* libguile/threads.h:
* libguile/throw.c:
* libguile/throw.h:
* libguile/trees.h:
* libguile/unicode.c:
* libguile/unicode.h:
* libguile/uniform.c:
* libguile/uniform.h:
* libguile/values.c:
* libguile/values.h:
* libguile/variable.c:
* libguile/variable.h:
* libguile/vectors.c:
* libguile/vectors.h:
* libguile/version.c:
* libguile/vm-engine.c:
* libguile/vm-expand.h:
* libguile/vm.c:
* libguile/vm.h:
* libguile/vports.c:
* libguile/vports.h:
* libguile/weak-list.h:
* libguile/weak-set.c:
* libguile/weak-set.h:
* libguile/weak-table.c:
* libguile/weak-table.h:
* libguile/weak-vector.c:
* libguile/weak-vector.h: Remove needless trailing comments.
2018-06-20 14:32:28 +02:00
Andy Wingo
5534c2817e Remove useless "classes: h_files" from Guile headers.
* libguile/__scm.h:
* libguile/alist.h:
* libguile/array-handle.h:
* libguile/array-map.h:
* libguile/arrays.h:
* libguile/async.h:
* libguile/backtrace.h:
* libguile/bitvectors.h:
* libguile/boolean.h:
* libguile/chars.h:
* libguile/chooks.h:
* libguile/continuations.h:
* libguile/debug-malloc.h:
* libguile/debug.h:
* libguile/deprecation.h:
* libguile/dynl.h:
* libguile/dynstack.h:
* libguile/dynwind.h:
* libguile/eq.h:
* libguile/error.h:
* libguile/eval.h:
* libguile/evalext.h:
* libguile/expand.h:
* libguile/extensions.h:
* libguile/feature.h:
* libguile/filesys.h:
* libguile/fluids.h:
* libguile/fports.h:
* libguile/gc-inline.h:
* libguile/gc.h:
* libguile/generalized-arrays.h:
* libguile/generalized-vectors.h:
* libguile/gettext.h:
* libguile/goops.h:
* libguile/gsubr.h:
* libguile/guardians.h:
* libguile/hash.h:
* libguile/hashtab.h:
* libguile/hooks.h:
* libguile/i18n.h:
* libguile/init.h:
* libguile/inline.h:
* libguile/ioext.h:
* libguile/iselect.h:
* libguile/keywords.h:
* libguile/list.h:
* libguile/load.h:
* libguile/macros.h:
* libguile/mallocs.c:
* libguile/mallocs.h:
* libguile/memoize.h:
* libguile/modules.h:
* libguile/net_db.h:
* libguile/null-threads.h:
* libguile/numbers.h:
* libguile/objprop.h:
* libguile/options.h:
* libguile/pairs.h:
* libguile/poll.h:
* libguile/ports.h:
* libguile/posix-w32.h:
* libguile/posix.h:
* libguile/print.h:
* libguile/procprop.h:
* libguile/procs.h:
* libguile/promises.h:
* libguile/pthread-threads.h:
* libguile/random.h:
* libguile/rdelim.h:
* libguile/read.h:
* libguile/regex-posix.h:
* libguile/rw.h:
* libguile/scmsigs.h:
* libguile/script.h:
* libguile/simpos.h:
* libguile/smob.h:
* libguile/snarf.h:
* libguile/socket.h:
* libguile/sort.h:
* libguile/srcprop.h:
* libguile/stackchk.h:
* libguile/stacks.h:
* libguile/stime.h:
* libguile/strings.h:
* libguile/strorder.h:
* libguile/strports.h:
* libguile/struct.h:
* libguile/symbols.h:
* libguile/syscalls.h:
* libguile/tags.h:
* libguile/threads.h:
* libguile/throw.h:
* libguile/trees.h:
* libguile/unicode.h:
* libguile/uniform.h:
* libguile/values.h:
* libguile/variable.h:
* libguile/vectors.h:
* libguile/vports.h:
* libguile/weak-list.h:
* libguile/weak-set.h:
* libguile/weak-table.h:
* libguile/weak-vector.h: Remove "classes: h_files".  Reformat
  copyrights if needed.
2018-06-20 14:26:16 +02:00
Andy Wingo
b64941f5af Define scm_t_wchar in one place
* libguile/__scm.h (scm_t_wchar): Move definition here, closer to
  scm_t_int32 definition (pulled in by scmconfig.h).
* libguile/numbers.h:
* libguile/chars.h: Remove weird maybe-definitions.
2018-06-20 11:38:08 +02:00
Andy Wingo
2b95d6faa4 Devolve gc.h
* libguile/_scm.h: Remove gc.h.
* libguile/arrays.h:
* libguile/bytevectors.h:
* libguile/foreign.h:
* libguile/fports.h:
* libguile/frames.h:
* libguile/hashtab.h:
* libguile/modules.h:
* libguile/numbers.h:
* libguile/print.h:
* libguile/programs.h:
* libguile/smob.h:
* libguile/snarf.h:
* libguile/strports.h:
* libguile/struct.h:
* libguile/symbols.h:
* libguile/variable.h:
* libguile/vectors.h:
* libguile/vm.h: Add gc.h to users of scm_cell_* interfaces.  Not really
  visible right now given that e.g. numbers.h is already included in
  _scm.h.
2018-06-18 22:27:29 +02:00
Andy Wingo
bdd66fdd24 Move more number validators to numbers.h.
* libguile/validate.h:
* libguile/numbers.h (SCM_OUT_OF_RANGE, SCM_ASSERT_RANGE)
  SCM_VALIDATE_REAL, SCM_VALIDATE_NUMBER, SCM_VALIDATE_USHORT_COPY)
  SCM_VALIDATE_SHORT_COPY, SCM_VALIDATE_UINT_COPY)
  SCM_VALIDATE_INT_COPY, SCM_VALIDATE_ULONG_COPY)
  SCM_VALIDATE_LONG_COPY, SCM_VALIDATE_SIZE_COPY)
  SCM_VALIDATE_FLOAT_COPY, SCM_VALIDATE_DOUBLE_COPY)
  SCM_VALIDATE_DOUBLE_DEF_COPY): Move here, from validate.h.
2018-06-17 22:32:08 +02:00
Andy Wingo
d10c3aa3cd Move number validators to numbers.h.
* libguile/validate.h:
* libguile/numbers.h (SCM_NUM2SIZE, SCM_NUM2SIZE_DEF, SCM_NUM2PTRDIFF)
  SCM_NUM2PTRDIFF_DEF, SCM_NUM2SHORT, SCM_NUM2SHORT_DEF, SCM_NUM2USHORT)
  SCM_NUM2USHORT_DEF, SCM_NUM2INT, SCM_NUM2INT_DEF, SCM_NUM2UINT)
  SCM_NUM2UINT_DEF, SCM_NUM2ULONG, SCM_NUM2ULONG_DEF, SCM_NUM2LONG)
  SCM_NUM2LONG_DEF, SCM_NUM2LONG_LONG, SCM_NUM2LONG_LONG_DEF)
  SCM_NUM2ULONG_LONG, SCM_NUM2ULONG_LONG_DEF, SCM_NUM2FLOAT)
  SCM_NUM2DOUBLE): Move these here, from validate.h.
2018-06-17 22:28:13 +02:00
Andy Wingo
41bc98985f VM calls out to heap-numbers-equal? through intrinsics
* libguile/numbers.h:
* libguile/eq.c (scm_i_heap_numbers_equal_p): Change to return boolean
  directly instead of tagged Scheme value.
  (scm_eqv_p): Adapt caller of scm_i_heap_numbers_equal_p.
* libguile/intrinsics.c (scm_bootstrap_intrinsics):
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): Declare
  heap-numbers-equal? intrinsic.
* libguile/vm-engine.c (heap-numbers-equal?): Call out through the
  intrinsics table.
2018-05-08 11:49:46 +02:00
Andy Wingo
41689edfc3 Slim heap-allocated flonums
* libguile/numbers.h (struct scm_t_double, struct scm_t_complex): Avoid
  adding an extra padding word on systems with 8-byte pointers.
* module/system/base/types.scm (cell->object): Update to compute correct
  offset of embedded double.
2018-04-10 20:01:52 +02:00
Andy Wingo
73d1502630 Lower eqv? and equal? to new instructions.
* libguile/numbers.h:
* libguile/eq.c (scm_i_heap_numbers_equal_p): New helper, factored out
  of scm_eqv_p.
  (scm_eqv_p): Use new helper.
* libguile/vm-engine.c (heap-numbers-equal?): New op.
* module/language/cps/compile-bytecode.scm (compile-function): Add
  support for heap-number? and heap-numbers-equal?.  Remove case for
  eqv?.
* module/language/cps/effects-analysis.scm: Add heap-numbers-equal?.
* module/language/cps/primitives.scm (*comparisons*): Add
  heap-numbers-equal?.
* module/language/cps/type-fold.scm (heap-numbers-equal?): Update.
* module/language/cps/types.scm (heap-numbers-equal?): Update.
* module/language/tree-il/compile-cps.scm (canonicalize): Completely
  inline eqv?, and partially inline equal?.
* module/system/vm/assembler.scm (system): Export emit-heap-numbers-equal?.
2017-10-29 15:47:25 +01:00
Mark H Weaver
1d257c27f0 Do not assume that sizeof (long) == sizeof (void *) == sizeof (SCM).
This assumption does not hold on systems that use the LLP64 data model.

Partially fixes <https://debbugs.gnu.org/22406>.
Reported by Peter TB Brett <peter@peter-b.co.uk>.

* libguile/numbers.h (scm_t_inum): Move here from numbers.c, and change
  to be equivalent to 'long' (formerly 'scm_t_signed_bits').
  (SCM_MOST_POSITIVE_FIXNUM, SCM_MOST_NEGATIVE_FIXNUM): Define based on
  SCM_I_FIXNUM_BIT instead of SCM_T_SIGNED_BITS_MAX.
  (SCM_I_INUM): Adjust definitions to return a 'scm_t_inum', and avoiding
  the assumption that SCM_UNPACK returns a 'long'.
* libguile/numbers.c (scm_t_inum): Move definition to numbers.h.
  Verify that 'scm_t_inum' fits within a SCM value.
  (scm_i_inum2big): Remove preprocessor code that forced a compile error
  unless sizeof (long) == sizeof (void *).
2017-03-01 19:08:42 +01:00
Mark H Weaver
475772ea57 Merge branch 'stable-2.0'
Conflicts:
	GUILE-VERSION
	NEWS
	guile-readline/ice-9/readline.scm
	libguile/async.c
	libguile/backtrace.c
	libguile/deprecated.h
	libguile/gc-malloc.c
	libguile/gdbint.c
	libguile/init.c
	libguile/ioext.c
	libguile/mallocs.c
	libguile/print.c
	libguile/rw.c
	libguile/scmsigs.c
	libguile/script.c
	libguile/simpos.c
	libguile/snarf.h
	libguile/strports.c
	libguile/threads.c
	libguile/vm-i-scheme.c
	libguile/vm-i-system.c
	module/srfi/srfi-18.scm
	test-suite/Makefile.am
	test-suite/standalone/test-num2integral.c
2014-04-25 02:06:01 -04:00
Mark H Weaver
3aecd36464 SCM_I_INUM: Rewrite to avoid unspecified behavior when not using GNU C.
* libguile/numbers.h (SCM_I_INUM): Unless using GNU C, use a portable
  implementation that avoids unspecified behavior.
2014-03-11 21:39:36 -04:00
Mark H Weaver
e293c94c65 SCM_SRS: Improve fallback implemention to avoid unspecified behavior.
* libguile/numbers.h (SCM_SRS): Rewrite preprocessor test to avoid
  left-shifting negative integers, and to test more comprehensively for
  the behavior we need.  Rewrite fallback implementation to avoid
  unspecified behavior.
2014-03-11 21:39:31 -04:00
Mark H Weaver
de7aa61ac4 Improve compliance with C standards regarding signed integer shifts.
* configure.ac: Add -fwrapv when using GCC (or compatible), if
  supported.

* libguile/numbers.h (SCM_I_MAKINUM): Cast to scm_t_bits (unsigned)
  before shifting, to avoid undefined behavior.
2014-03-07 04:34:27 -05:00
Mark H Weaver
1df515a077 Merge branch 'stable-2.0'
Conflicts:
	module/system/vm/traps.scm
	test-suite/tests/peval.test
2014-01-09 02:52:34 -05:00
Mark H Weaver
900a897cd3 Implement 'exact-integer?' and 'scm_is_exact_integer'.
* libguile/numbers.c (scm_exact_integer_p, scm_is_exact_integer):
  New procedures.
  (scm_integer_p): Improve docstring.

* libguile/numbers.h (scm_exact_integer_p, scm_is_exact_integer):
  New prototypes.

* doc/ref/api-data.texi (Integers): Add docs.

* test-suite/tests/numbers.test ("exact-integer?"): Add tests.
2014-01-08 21:42:16 -05:00
Andy Wingo
0b3b73698c add scm_{to,from}_{u,}intptr_t
* libguile/numbers.h (scm_to_intptr_t, scm_from_intptr_t)
  (scm_to_uintptr_t, scm_from_uintptr_t): New defines.

* libguile/foreign.c: Remove definitions here; adapt callers to use new
  names with _t suffixes.
2013-05-23 14:19:06 +02:00
Mark H Weaver
26d148066f Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
	configure.ac
	libguile/deprecated.c
	libguile/deprecated.h
	libguile/filesys.h
	libguile/fluids.c
	libguile/fports.c
	libguile/gc.c
	libguile/guile.c
	libguile/numbers.c
	libguile/objcodes.c
	libguile/r6rs-ports.c
	libguile/smob.c
	libguile/socket.c
	libguile/threads.h
	module/language/scheme/decompile-tree-il.scm
	module/language/tree-il/peval.scm
	test-suite/tests/syncase.test
2013-03-28 05:09:53 -04:00
Mark H Weaver
e08a12b535 Add 'round-ash', a rounding arithmetic shift operator
* libguile/numbers.c (left_shift_exact_integer,
  floor_right_shift_exact_integer, round_right_shift_exact_integer): New
  static functions.

  (scm_round_ash): New procedure.

  (scm_ash): Reimplement in terms of 'left_shift_exact_integer' and
  'floor_right_shift_exact_integer'.

* libguile/numbers.h: Add prototype for scm_round_ash.  Rename the
  second argument of 'scm_ash' from 'cnt' to 'count'.

* test-suite/tests/numbers.test (round-ash, ash): Add new unified
  testing framework for 'ash' and 'round-ash'.  Previously, the tests
  for 'ash' were not very comprehensive; for example, they did not
  include a single test where the number to be shifted was a bignum.

* doc/ref/api-data.texi (Bitwise Operations): Add documentation for
  'round-ash'.  Improve documentation for `ash'.
2013-03-12 15:39:20 -04:00
Andy Wingo
9b977c836b Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
	libguile/array-handle.c
	libguile/deprecated.h
	libguile/inline.c
	libguile/inline.h
	module/ice-9/deprecated.scm
	module/language/tree-il/peval.scm
2013-02-18 17:59:38 +01:00
Mark H Weaver
7facc08a80 Add scm_from_ptrdiff_t and scm_to_ptrdiff_t.
* libguile/numbers.h (scm_from_ptrdiff_t, scm_to_ptrdiff_t):
  New macros (function aliases).

* doc/ref/api-data.texi: Add docs.
2013-02-02 04:13:37 -05:00
Andy Wingo
0aed71aa51 Revert "add SCM_HEAP_OBJECT_BASE"
This reverts commit 47ed8656db.

Conflicts:

	libguile/foreign.c
2012-01-31 22:58:24 +01:00
Andy Wingo
ea0582c283 Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
	libguile/guile.c
	libguile/numbers.c
2011-12-02 12:00:33 +01:00
Andy Wingo
b57bf2724a install gmp memory functions that let libgc know about allocations
* libguile/numbers.c (custom_gmp_malloc, custom_gmp_realloc,
  custom_gmp_free): New static functions used by GMP for allocation.
  These are just wrappers for scm_malloc, scm_realloc, and free.

  (scm_init_numbers): If scm_install_gmp_memory_functions is nonzero,
  use mp_set_memory_functions to configure GMP to use
  custom_gmp_{malloc,realloc,free} for memory allocation.

  (scm_bigprint): Ask gmp for the function used to deallocate the string
  returned by mpz_get_str.

* libguile/numbers.h: Declare scm_install_gmp_memory_functions.

* libguile/guile.c: When running the Guile binary, install the
  gmp_memory_functions.

Based on a patch by Mark H Weaver <mhw@netris.org>.
2011-12-02 11:57:25 +01:00
Andy Wingo
47ed8656db add SCM_HEAP_OBJECT_BASE
* libguile/tags.h (SCM_HEAP_OBJECT_BASE): New macro.  Given a SCM,
  returns a pointer to the start of its memory area on the heap.

* libguile/bytevectors.c:
* libguile/fluids.c:
* libguile/foreign.c:
* libguile/gc.h:
* libguile/guardians.c:
* libguile/numbers.h:
* libguile/ports.c:
* libguile/smob.c:
* libguile/struct.c:
* libguile/weak-set.c:
* libguile/weak-table.c:
* libguile/weak-vector.c: Use it.
2011-10-24 18:59:35 +02:00
Andy Wingo
dc7da0be90 refactor tc7 and tc16 checks
* libguile/tags.h (SCM_HAS_TYP7, SCM_HAS_TYP7S, SCM_HAS_TYP16): New
  macros.

* libguile/bytevectors.h (SCM_BYTEVECTOR_P):
* libguile/control.h (SCM_PROMPT_P):
* libguile/filesys.h (SCM_DIRP):
* libguile/fluids.h (SCM_WITH_FLUIDS_P, SCM_FLUID_P)
  (SCM_I_DYNAMIC_STATE_P):
* libguile/foreign.h (SCM_POINTER_P):
* libguile/fports.h (SCM_FPORTP):
* libguile/frames.h (SCM_VM_FRAME_P):
* libguile/hashtab.h (SCM_HASHTABLE_P):
* libguile/inline.h (scm_get_byte_or_eof):
* libguile/numbers.h (SCM_REALP, SCM_BIGP, SCM_COMPLEXP, SCM_FRACTIONP):
* libguile/objcodes.h (SCM_OBJCODE_P):
* libguile/ports.h (SCM_OUTPUT_PORT_P):
* libguile/programs.h (SCM_PROGRAM_P):
* libguile/smob.h (SCM_SMOB_PREDICATE):
* libguile/srfi-14.h (SCM_CHARSETP):
* libguile/strings.c (IS_STRING):
* libguile/strports.h (SCM_STRPORTP):
* libguile/symbols.h (scm_is_symbol):
* libguile/variable.h (SCM_VARIABLEP):
* libguile/vectors.h (SCM_I_IS_VECTOR, SCM_I_IS_NONWEAK_VECTOR):
* libguile/vm-i-system.c (call, tail-call, mv-call)
* libguile/vm.h (SCM_VM_P, SCM_VM_CONT_P):
* libguile/weak-set.c (SCM_WEAK_SET_P):
* libguile/weak-table.c (SCM_WEAK_TABLE_P):
* libguile/weak-vector.h (SCM_I_WVECTP): Use them.
2011-10-24 18:54:01 +02:00
Mike Gran
022dda6901 New functions scm_is_exact and scm_is_inexact
* doc/ref/api-data.texi (Exact and Inexact Numbers): doc for scm_is_exact
  and scm_is_inexact
* libguile/numbers.c (scm_is_exact, scm_is_inexact): new functions
* libguile/numbers.h: declarations for scm_is_exact and scm_is_inexact
* test/suite/standalone/test-conversion.c (test_is_exact, test_is_inexact):
  new tests
2011-10-09 20:54:37 -07:00
Mark H Weaver
882c89636a Fix the R6RS exact-integer-sqrt and import into core guile
* libguile/numbers.c (scm_exact_integer_sqrt): New C procedure to
  compute exact integer square root and remainder.
  (scm_i_exact_integer_sqrt): New Scheme procedure `exact-integer-sqrt'
  from the R6RS, imported into core guile.

* libguile/numbers.h: Add prototypes.

* module/rnrs/base.scm: Remove broken stub implementation, which would
  fail badly when applied to large integers.

* doc/ref/api-data.texi: Add documentation.

* doc/ref/r6rs.texi: Change documentation for `exact-integer-sqrt' to a
  stub that xrefs the core docs, as is done for other operations
  available in core.

* test-suite/tests/numbers.test: Add tests.

* NEWS: Add news entries.
2011-04-09 16:11:49 -04:00
Mark H Weaver
5093e51839 Make SCM_NUMP and SCM_NUMBERP more extensible
* libguile/numbers.h (SCM_NUMP, SCM_NUMBERP): Mask out more bits in the
  cell type field when doing the comparison, in order to accept future
  numeric types that have not yet been implemented.  This should allow
  us to add more core numeric types without breaking ABI compatibility.
  As a bonus, these macros are now more efficient.
2011-02-14 20:32:54 +01:00
Mark H Weaver
8f9da3406b Add four new sets of fast quotient and remainder operators
* libguile/numbers.c (scm_floor_divide, scm_floor_quotient,
  scm_floor_remainder, scm_ceiling_divide, scm_ceiling_quotient,
  scm_ceiling_remainder, scm_truncate_divide, scm_truncate_quotient,
  scm_truncate_remainder, scm_round_divide, scm_round_quotient,
  scm_round_remainder): New extensible procedures `floor/',
  `floor-quotient', `floor-remainder', `ceiling/', `ceiling-quotient',
  `ceiling-remainder', `truncate/', `truncate-quotient',
  `truncate-remainder', `round/', `round-quotient', and
  `round-remainder'.

* libguile/numbers.h: Add function prototypes.

* test-suite/tests/numbers.test: Add tests.

* doc/ref/api-data.texi (Arithmetic): Add documentation.

* NEWS: Add NEWS entry.
2011-02-14 20:30:53 +01:00
Mark H Weaver
5fbf680be9 Make divide functions return values via (SCM *) output arguments
* libguile/numbers.c (scm_euclidean_divide, scm_centered_divide): Change
  API to return two values via output arguments of type (SCM *), instead
  of packing into a values object.

  (scm_i_euclidean_divide, scm_i_centered_divide): New internal wrappers
  that call the above functions and pack the result into a values
  object.

* libguile/numbers.h: Change prototypes to reflect new API.

* doc/ref/api-data.h (Arithmetic): Update manual.
2011-02-14 20:30:30 +01:00
Mark H Weaver
ac6ce16bc9 Rename {euclidean,centered}_quo_rem to {euclidean,centered}_divide
* libguile/numbers.c (euclidean_quo_rem): Rename to euclidean_divide.
  (centered_quo_rem): Rename to {euclidean,centered}_divide.

* libguile/numbers.h: Rename euclidean_quo_rem to euclidean_divide and
  centered_quo_rem to centered_divide.

* doc/ref/api-data.texi: Rename euclidean_quo_rem to euclidean_divide and
  centered_quo_rem to centered_divide.
2011-01-31 20:22:42 +01:00
Mark H Weaver
2519490c50 Improve extensibility of core numeric procedures
* libguile/numbers.c (scm_quotient, scm_remainder, scm_modulo,
  scm_zero_p, scm_positive_p, scm_negative_p, scm_real_part,
  scm_imag_part, scm_numerator, scm_denominator, scm_magnitude,
  scm_angle, scm_exact_to_inexact): Change from SCM_GPROC to
  SCM_PRIMITIVE_GENERIC.  As a side effect, all of these procedures now
  have documentation strings.

  (scm_exact_p, scm_inexact_p, scm_odd_p, scm_even_p, scm_finite_p,
  scm_inf_p, scm_nan_p, scm_expt, scm_inexact_to_exact, scm_log,
  scm_log10, scm_exp, scm_sqrt): Change from SCM_DEFINE to
  SCM_PRIMITIVE_GENERIC, and make sure the code allows these functions
  to be extended in practice.

  (scm_real_part, scm_imag_part, scm_numerator, scm_denominator,
  scm_inexact_to_exact): Simplify type dispatch code.

  (scm_sqrt): Rename formal argument from x to z, since complex numbers
  are supported.

  (scm_abs): Fix empty FUNC_NAME.

* libguile/numbers.h (scm_finite_p): Add missing prototype.

  (scm_inf_p, scm_nan_p): Rename formal parameter from n to x, since
  the domain is the real numbers.

* test-suite/tests/numbers.test: Test for documentation strings.  Change
  from `expect-fail' to `pass-if' for several of these, and add tests
  for others.  Also add other tests for `real-part' and `imag-part',
  which previously had none.
2011-01-30 23:06:07 +01:00
Mark H Weaver
ff62c16828 Add two new sets of fast quotient and remainder operators
* libguile/numbers.c (scm_euclidean_quo_and_rem, scm_euclidean_quotient,
  scm_euclidean_remainder, scm_centered_quo_and_rem,
  scm_centered_quotient, scm_centered_remainder): New extensible
  procedures `euclidean/', `euclidean-quotient', `euclidean-remainder',
  `centered/', `centered-quotient', `centered-remainder'.

* libguile/numbers.h: Add function prototypes.

* module/rnrs/base.scm: Remove incorrect stub implementations of `div',
  `mod', `div-and-mod', `div0', `mod0', and `div0-and-mod0'.  Instead do
  renaming imports of `euclidean-quotient', `euclidean-remainder',
  `euclidean/', `centered-quotient', `centered-remainder', and
  `centered/', which are equivalent to the R6RS operators.

* module/rnrs/arithmetic/fixnums.scm (fxdiv, fxmod, fxdiv-and-mod,
  fxdiv0, fxmod0, fxdiv0-and-mod0): Remove redundant checks for division
  by zero and unnecessary complexity.
  (fx+/carry): Remove unneeded calls to `inexact->exact'.

* module/rnrs/arithmetic/flonums.scm (fldiv, flmod, fldiv-and-mod,
  fldiv0, flmod0, fldiv0-and-mod0): Remove redundant checks for division
  by zero and unnecessary complexity.  Remove unneeded calls to
  `inexact->exact' and `exact->inexact'

* test-suite/tests/numbers.test: (test-eqv?): New internal predicate for
  comparing numerical outputs with expected values.

  Add extensive test code for `euclidean/', `euclidean-quotient',
  `euclidean-remainder', `centered/', `centered-quotient',
  `centered-remainder'.

* test-suite/tests/r6rs-arithmetic-fixnums.test: Fix some broken test
  cases, and remove `unresolved' test markers for `fxdiv', `fxmod',
  `fxdiv-and-mod', `fxdiv0', `fxmod0', and `fxdiv0-and-mod0'.

* test-suite/tests/r6rs-arithmetic-flonums.test: Remove `unresolved'
  test markers for `fldiv', `flmod', `fldiv-and-mod', `fldiv0',
  `flmod0', and `fldiv0-and-mod0'.

* doc/ref/api-data.texi (Arithmetic): Document `euclidean/',
  `euclidean-quotient', `euclidean-remainder', `centered/',
  `centered-quotient', and `centered-remainder'.

  (Operations on Integer Values): Add cross-references to `euclidean/'
  et al, from `quotient', `remainder', and `modulo'.

* doc/ref/r6rs.texi (rnrs base): Improve documentation for `div', `mod',
  `div-and-mod', `div0', `mod0', and `div0-and-mod0'.  Add
  cross-references to `euclidean/' et al.

* NEWS: Add NEWS entry.
2011-01-30 23:00:38 +01:00