summaryrefslogtreecommitdiff
path: root/libguile
AgeCommit message (Collapse)AuthorFilesLines
2022-01-13Implement gcd with new integer libAndy Wingo3-81/+86
* libguile/integers.c (scm_integer_gcd_ii) (scm_integer_gcd_zi, scm_integer_gcd_zz): New internal functions. * libguile/integers.h: Declare internal functions. * libguile/numbers.c (scm_gcd): Use the new functions.
2022-01-13Implement round-divide with new integer libAndy Wingo3-123/+140
* libguile/integers.c (scm_integer_round_divide_ii) (scm_integer_round_divide_iz, scm_integer_round_divide_zi) (scm_integer_round_divide_zz): New internal functions. (integer_round_divide_zz): New helper. * libguile/integers.h: Declare internal functions. * libguile/numbers.c (scm_round_divide): Use the new functions. (scm_i_bigint_round_divide): Remove unused helper.
2022-01-13Implement round-remainder with new integer libAndy Wingo3-114/+130
* libguile/integers.c (scm_integer_round_remainder_ii) (scm_integer_round_remainder_iz, scm_integer_round_remainder_zi) (scm_integer_round_remainder_zz): New internal functions. (integer_round_remainder_zz): New helper. (long_sign, bignum_cmp_long): New helpers. * libguile/integers.h: Declare internal functions. * libguile/numbers.c (scm_round_remainder): Use the new functions. (scm_i_bigint_round_remainder): Remove unused helper.
2022-01-13Implement round-quotient with new integer libAndy Wingo3-119/+154
* libguile/integers.c (scm_integer_round_quotient_ii) (scm_integer_round_quotient_iz, scm_integer_round_quotient_zi) (scm_integer_round_quotient_zz): New internal functions. (integer_round_quotient_zz): New helper. (long_sign, bignum_cmp_long): New helpers. * libguile/integers.h: Declare internal functions. * libguile/numbers.c (scm_round_quotient): Use the new functions. (scm_i_bigint_round_quotient): Remove unused helper.
2022-01-13Implement centered-divide with new integer libAndy Wingo3-143/+151
* libguile/integers.c (scm_integer_centered_divide_ii) (scm_integer_centered_divide_iz, scm_integer_centered_divide_zi) (scm_integer_centered_divide_zz): New internal functions. (integer_centered_divide_zz): New helper. * libguile/integers.h: Declare internal functions. * libguile/numbers.c (scm_centered_divide): Use the new functions. (scm_i_bigint_centered_divide): Remove unused helper.
2022-01-13Implement centered-remainder with new integer libAndy Wingo3-117/+127
* libguile/integers.c (scm_integer_centered_remainder_ii) (scm_integer_centered_remainder_iz, scm_integer_centered_remainder_zi) (scm_integer_centered_remainder_zz): New internal functions. * libguile/integers.h: Declare internal functions. * libguile/numbers.c (scm_centered_remainder): Use the new functions. (scm_i_bigint_centered_remainder): Remove helper.
2022-01-13Implement centered-quotient with new integer libAndy Wingo3-138/+144
* libguile/integers.c (scm_integer_centered_quotient_ii) (scm_integer_centered_quotient_iz, scm_integer_centered_quotient_zi) (scm_integer_centered_quotient_zz): New internal functions. * libguile/integers.h: Declare internal functions. * libguile/numbers.c (scm_centered_quotient): Use the new functions. (scm_i_bigint_centered_quotient): Remove unused helper.
2022-01-13Implement truncate-divide with new integer libAndy Wingo3-68/+90
* libguile/integers.c (scm_integer_truncate_divide_ii) (scm_integer_truncate_divide_iz, scm_integer_truncate_divide_zi) (scm_integer_truncate_divide_zz): New internal functions. * libguile/integers.h: Declare internal functions. * libguile/numbers.c (scm_truncate_divide): Use the new functions.
2022-01-13Implement truncate-remainder with new integer libAndy Wingo3-45/+68
* libguile/integers.c (scm_integer_truncate_remainder_ii) (scm_integer_truncate_remainder_iz, scm_integer_truncate_remainder_zi) (scm_integer_truncate_remainder_zz): New internal functions. * libguile/integers.h: Declare internal functions. * libguile/numbers.c (scm_truncate_remainder): Use the new functions.
2022-01-13Implement truncate-quotient with new integer libAndy Wingo3-58/+77
* libguile/integers.c (scm_integer_truncate_quotient_ii) (scm_integer_truncate_quotient_iz, scm_integer_truncate_quotient_zi) (scm_integer_truncate_quotient_zz): New internal functions. * libguile/integers.h: Declare internal functions. * libguile/numbers.c (scm_truncate_quotient): Use the new functions.
2022-01-13Implement ceiling-divide with new integer libAndy Wingo3-124/+146
* libguile/integers.c (scm_integer_ceiling_divide_ii) (scm_integer_ceiling_divide_iz, scm_integer_ceiling_divide_zi) (scm_integer_ceiling_divide_zz): New internal functions. * libguile/integers.h: Declare internal functions. * libguile/numbers.c (scm_ceiling_divide): Use the new functions.
2022-01-13Implement ceiling-remainder with new integer libAndy Wingo3-85/+108
* libguile/integers.c (scm_integer_ceiling_remainder_ii) (scm_integer_ceiling_remainder_iz, scm_integer_ceiling_remainder_zi) (scm_integer_ceiling_remainder_zz): New internal functions. (bignum_is_positive): New helper. * libguile/integers.h: Declare internal functions. * libguile/numbers.c (scm_ceiling_remainder): Use the new functions.
2022-01-13Implement ceiling-quotient with new integer libAndy Wingo3-97/+138
* libguile/integers.c (scm_integer_ceiling_quotient_ii) (scm_integer_ceiling_quotient_iz, scm_integer_ceiling_quotient_zi) (scm_integer_ceiling_quotient_zz): New internal functions. (take_bignum_from_mpz): Change to also normalize the mpz, as all callers required. (long_sign, bignum_cmp_long): New helpers. * libguile/integers.h: Declare internal functions. * libguile/numbers.c (scm_ceiling_quotient): Use the new functions.
2022-01-13Implement floor-divide with new integer libAndy Wingo3-97/+111
* libguile/integers.c (scm_integer_floor_divide_ii) (scm_integer_floor_divide_iz, scm_integer_floor_divide_zi) (scm_integer_floor_divide_zz): New internal functions. * libguile/integers.h: Declare internal functions. * libguile/numbers.c (scm_floor_divide): Use the new functions.
2022-01-13Implement floor-remainder with new integer libAndy Wingo3-71/+86
* libguile/integers.c (scm_integer_floor_remainder_ii) (scm_integer_floor_remainder_iz, scm_integer_floor_remainder_zi) (scm_integer_floor_remainder_zz): New internal functions. * libguile/integers.h: Declare internal functions. * libguile/numbers.c (scm_floor_remainder): Use the new functions.
2022-01-13Implement floor-quotient with new integer libAndy Wingo3-67/+92
* libguile/integers.c (scm_integer_floor_quotient_ii) (scm_integer_floor_quotient_iz, scm_integer_floor_quotient_zi) (scm_integer_floor_quotient_zz): New internal functions. (long_to_scm, ulong_to_scm, take_bignum_from_mpz): New helpers. * libguile/integers.h: Declare internal functions. * libguile/numbers.c (scm_floor_quotient): Use the new functions.
2022-01-13Implement abs with new integer libAndy Wingo3-16/+27
* libguile/integers.c (scm_integer_abs_i, scm_integer_abs_z): New internal functions. * libguile/integers.h: Declare internal functions. * libguile/numbers.c (scm_abs): Use the new functions.
2022-01-13Implement odd? and even? with new integer libAndy Wingo3-19/+220
* libguile/integers.c (scm_is_integer_odd_i): (scm_is_integer_odd_z): New internal functions. Add a number of internal support routines. * libguile/integers.h: Declare internal functions. * libguile/numbers.c (scm_odd_p, scm_even_p): Use the new functions.
2022-01-13Add new integers.[ch]Andy Wingo3-1/+66
The goal is to factor out some fixnum/bignum code here from numbers.[ch]. * libguile/Makefile.am: Add new files. * libguile/integers.c: * libguile/integers.h: New files
2022-01-07Fix type confusion in heap-numbers-equal? calls from VMAndy Wingo1-1/+8
When heap-numbers-equal? is called from eqv?, we have already ensured that the both objects have the same heap type. However when called by the VM, the precondition is just that both are heap numbers -- not necessarily of the same type. Fix to add an additional check in heap-numbers-equal?. Could cause crashers! * libguile/eq.c (scm_i_heap_numbers_equal_p): Add additional check.
2022-01-04New function bitvector-copy (scm_bitvector_copy)Daniel Llorens2-0/+48
* libguile/bitvectors.h: * libguile/bitvectors.c: As stated. * test-suite/tests/bitvectors.test: Tests. * doc/ref/api-data.texi: Update "Bit vectors" section. * NEWS: Update.
2021-12-06New function srfi-4-vector-type-size in (srfi srfi-4 gnu)Daniel Llorens3-2/+27
This patch removes the undocumented function make-srfi-4-vector from (guile). That function is still exported from (srfi srfi-4 gnu). * libguile/srfi-4.h (scm_init_srfi_4): Split into scm_bootstrap_srfi_4() and scm_init_srfi_4(), after the pattern of scm_init_bytevectors() and scm_bootstrap_bytevectors(). * libguile/init.c: Replace scm_init_srfi_4() call by scm_bootstrap_srfi_4(). * module/srfi/srfi-4.scm: Load newly defined srfi-4 extension. This provides undocumented make-srfi-4-vector. * module/srfi/srfi-4/gnu.scm: Export srfi-4-vector-type-size. * doc/ref/srfi-modules.texi: Document srfi-4-vector-type-size.
2021-11-15Support C99 complex types in (system foreign)Daniel Llorens2-0/+77
* libguile/foreign.h (SCM_FOREIGN_TYPE_COMPLEX_FLOAT, SCM_FOREIGN_TYPE_COMPLEX_DOUBLE): New enums. * module/system/foreign.scm (complex-float, complex-double): Export new types. (make-c-struct, parse-c-struct): Support the new types. * libguile/foreign.c (complex-float, complex-double): Define new types. (alignof, sizeof, pack, unpack): Support the new types. * test-suite/tests/foreign.test: Test.
2021-11-05Fix brace style for bf9d30f3c3fd03cb37d604f1927e9ce5c699338bDaniel Llorens1-22/+26
2021-11-05Limit the range of ash, round-ash count argument to INT32Daniel Llorens1-55/+41
This avoids gmp aborting e.g. with (ash 1 (expt 2 37)). The new limit is such that (ash 1 (expt 30)) is accepted but (ash 1 (expt 31)) throws. Fixes https://bugs.gnu.org/48150 * libguile/numbers.c (ash, round-ash): As stated. * test-suite/tests/numbers.test: Test a case known to make gmp abort before.
2021-11-03Fix bounds check in recvfrom!d4ryus1-7/+10
Closes https://debbugs.gnu.org/cgi/bugreport.cgi?bug=45595. NB: Amended by the committer to allow an empty range. * libguile/socket.c: As stated.
2021-11-03Const qualify return of strerrorPhilipp Klaus Krause1-2/+2
Closes https://debbugs.gnu.org/cgi/bugreport.cgi?bug=43987
2021-10-21Provide xxvector-copy and xxvector-copy! for srfi-4 vectorsDaniel Llorens2-6/+9
These use the argument conventions of vector-copy!, string-copy!, etc. and not that of bytevector-copy! (which is from r6rs). * module/srfi/srfi-4/gnu.scm: As stated. * test-suite/tests/srfi-4.test: Tests. * doc/ref/srfi-modules.texi: Documentation. * libguile/bytevectors.c (bytevector-copy!): Add overlap note to docstring. * libguile/vectors.c (vector-copy!): Reuse text for the overlap note.
2021-10-01Add frame-local-ref / frame-local-set! support for type 'ptrAndy Wingo1-2/+9
* libguile/frames.c (enum stack_item_representation): (scm_to_stack_item_representation): (scm_frame_local_ref): (scm_frame_local_set_x): Add support for "ptr" representations.
2021-09-17Revert shift of ndim in array tag from 3df3ba1a2c956bba122328e1fc4be614171a4f42Daniel Llorens1-2/+2
To avoid breaking ABI. * libguile/arrays.h (SCM_I_ARRAY_DIM, scm_i_raw_array): As stated. * module/system/vm/assembler.scm: As stated.
2021-08-17Extend bytevector-fill! to handle a partial fillDaniel Llorens2-24/+35
* libguile/bytevectors.c (bytevector-fill!): As stated. (scm_bytevector_fill_x): Stub to avoid changing the C API. * doc/ref/api-data.texi: Documentation. * libguile/vectors.c (vector-fill!): Less confusing variable names. * test-suite/tests/bytevectors.test: Test partial fill cases for bytevector-fill!.
2021-08-17Refactor srfi-4 declarationsDaniel Llorens1-246/+31
2021-08-16Remove array contp flagDaniel Llorens5-54/+20
This flag was set, but never used in Guile, and there was no documented API to access it. To check if an array is contiguous, use (array-contents <> #t). * libguile/arrays.h (scm_i_raw_array): New function. SCM_I_ARRAY_CONTIGUOUS, SCM_SET_ARRAY_CONTIGUOUS_FLAG, SCM_CLR_ARRAY_CONTIGUOUS_FLAG, SCM_I_ARRAY_CONTP: Remove. scm_t_array_dim: Declare here, not in array-handle.h. SCM_I_ARRAY_NDIM: Shift by one bit since the contp flag isn't there anymore. * module/syste/vm/assembler.scm: Match removal of contp flag. * libguile/arrays.c (scm_i_make_array): Reuse scm_i_raw_array. (scm_i_ra_set_contp): Remove. (scm_transpose_array): Don't set or clear the contp flag. (scm_make_shared_array): Don't set or clear the contp flag. (scm_make_typed_array): Don't set the contp flag. * libguile/array-map.c (scm_i_array_rebase): Reuse scm_i_raw_array.
2021-08-16Deprecate scm_from_contiguous_typed_arrayDaniel Llorens4-60/+71
This was never documented and it's not used in Guile itself, either.
2021-08-16Remove the 'simple vector' conceptDaniel Llorens5-17/+20
* Deprecate scm_is_simple_vector. * libguile/vectors.c (scm_vector_elements, scm_vector_writable_elements): These functions take an array; reword to make this clear. * libguile/print.h: Remove reference to 'simple vector'. * doc/ref/api-data.texi: Remove documentation for scm_is_simple_vector. Remove references to 'simple vector'. Fix documentation for scm_vector_elements, scm_vector_writable_elements. * test-suite/tests/arrays.test: * test-suite/tests/vectors.test: Remove references to 'simple vector'.
2021-08-06Add function vector-copy! to coreDaniel Llorens2-3/+45
This is up to 20%-30% faster than the previous versions in (scheme base) or (srfi srfi-43) that used vector-move-left!/vector-move-right!. * libguile/vectors.h: * libguile/vectors.c: As stated. * doc/ref/api-data.texi (vector-copy!): Document the new function. (vector-fill!): Document optional arguments. (vector-copy): Document optional arguments. * module/scheme/base.scm: Reuse core vector-copy!. * module/srfi/srfi-43.scm: Reuse core vector-copy!.
2021-08-06Extend core vector-copy to r7rs vector-copyDaniel Llorens2-7/+35
* libguile/vectors.h: Declare scm_vector_copy_partial. * libguile/vectors.c (scm_vector_copy_partial): As stated. (scm_vector_copy): Reuse scm_vector_copy_partial. * module/scheme/base.scm: Reuse core vector-copy. * module/srfi/srfi-43: Reuse core vector-copy. * test-suite/tests/vectors.test: Test vector-copy.
2021-08-06Deprecate use of vector-move-left! and vector-move-right! on non-vector arraysDaniel Llorens1-53/+104
These functions weren't advertised to work on non-vector arrays. They did try to, but only incorrectly. For example: (define a (vector 1 2 3 4 5)) (define b (make-array 0 '(1 5))) (vector-move-right! a 0 2 b 2) b => #1@1(0 0 1 2 0) instead of the correct result #1@1(0 1 2 0 0). * libguile/vectors.c (vector-move-left!, vector-move-right!): As stated.
2021-08-05Deprecate using vector->list, vector-copy on arraysDaniel Llorens1-32/+60
* libguile/vectors.c (vector-copy, vector->list): As stated. Provide array free implementation for the supported case.
2021-08-03Merge libguile/generalized-arrays.* into libguile/arrays.*Daniel Llorens10-713/+614
* libguile/arrays.h: * libguile/arrays.c: As stated. * libguile/init.c: Remove call to scm_init_generalized_arrays(). Elsewhere fix references to generalized-arrays.*.
2021-05-11Bump objcode versionAndy Wingo1-1/+1
* libguile/loader.h (SCM_OBJCODE_MINOR_VERSION): * module/system/vm/assembler.scm (*bytecode-minor-version*): Bump, as we're going to start adding inlinable exports.
2021-05-08'primitive-fork' closes and recreates the current thread's 'sleep_pipe'.Ludovic Courtès1-1/+28
Partly fixes <https://bugs.gnu.org/41948>. Previously, the child process could end up using the same 'sleep_pipe' as its parent, leading to a race condition handling signals. * libguile/posix.c (do_fork): New function. (scm_fork): Call 'do_fork' via 'scm_without_guile'. * test-suite/standalone/test-signal-fork: New test. * test-suite/standalone/Makefile.am (check_SCRIPTS, TESTS): Add it.
2021-05-08Close the finalization pipe before forking.Andrew Whatson1-17/+28
Partly fixes <https://bugs.gnu.org/41948>. Reported by Mathieu Othacehe <othacehe@gnu.org>. Previously, after 'fork', the child process could end up sharing the finalization thread with its parent. * libguile/finalizers.c (finalization_pipe): Initialize. (reset_finalization_pipe): Factored out. (start_finalization_thread): Create the pipe immediately before launching the thread. Ensure the pipe is cleaned up if thread creation fails. Update the finalizer callback if thread creation succeeds. (stop_finalization_thread): Clean up the pipe after stopping the thread. (spawn_finalizer_thread): Remove finalizer callback logic. (scm_set_automatic_finalization_enabled): Remove pipe management. (scm_init_finalizer_thread): Remove pipe management. Co-authored-by: Ludovic Courtès <ludo@gnu.org>
2021-05-07Define `O_NOFOLLOW' and various other flags when supported.Maxime Devos1-0/+36
* libguile/filesys.c (scm_init_filesys): Define ‘O_IGNORE_CTTY’, ‘O_NOLINK’, ‘O_NOFOLLOW’, ‘O_PATH’, ‘O_TMPFILE’, ‘O_SHLOCK’, ‘O_EXLOCK’, ‘O_ASYNC’, ‘O_NOATIME’, ‘O_DIRECTORY’, ‘O_CLOEXEC’ and ‘O_DIRECT’ when available. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2021-05-01Include config.h in mini-gmp.c, if presentAndy Wingo1-0/+4
* libguile/mini-gmp.c: Add config.h include. Handles the case in which gnulib provides some part of the standard library of mini-gmp, as is apparently the case on FreeBSD for example. Thanks to RhodiumToad for the report and fix.
2021-04-27Add GUILE_INSTALL_GMP_MEMORY_FUNCTIONS to NEWS; use at build-timeAndy Wingo1-0/+1
* NEWS (GUILE_INSTALL_GMP_MEMORY_FUNCTIONS): Update * libguile/numbers.c: Add needed include. * meta/build-env.in (GUILE_INSTALL_GMP_MEMORY_FUNCTIONS): Set when building Guile.
2021-04-26Allow users to force gmp to use libgcAndy Wingo1-0/+9
* doc/ref/guile-invoke.texi (Environment Variables): Document GUILE_INSTALL_GMP_MEMORY_FUNCTIONS. * libguile/numbers.c (scm_init_numbers): Use environment variable.
2021-04-26Bump minor objcode version for new intrinsicsAndy Wingo1-2/+2
* libguile/loader.h (SCM_OBJCODE_MINOR_VERSION): Bump. * module/system/vm/assembler.scm (*bytecode-minor-version*): Bump.
2021-04-26Fix error when argument to < not a realAndy Wingo1-1/+2
* libguile/intrinsics.c (less_p): scm_nan_p raises an error if arg is not a real; guard.
2021-04-26Simplify module variable lookup slow-pathAndy Wingo4-4/+96
* libguile/intrinsics.h: * libguile/intrinsics.c (lookup_bound_public, lookup_bound_private): Two new intrinsics. (scm_bootstrap_intrinsics): Wire them up. * libguile/jit.c (compile_call_scm_from_scmn_scmn): (compile_call_scm_from_scmn_scmn_slow): (COMPILE_X8_S24__N32__N32__C32): Add JIT support for new instruction kind. * libguile/vm-engine.c (call-scm<-scmn-scmn): New instruction, takes arguments as non-immediate offsets, to avoid needless loads and register pressure. * module/language/cps/effects-analysis.scm: Add cases for new primcalls. * module/language/cps/compile-bytecode.scm (compile-function): Add new primcalls. * module/language/cps/reify-primitives.scm (cached-module-box): If the variable is bound, call lookup-bound-public / lookup-bound-private as appropriate instead of separately resolving the module, name, and doing the bound check. * module/language/tree-il/compile-bytecode.scm (emit-cached-module-box): Use new instructions. * module/system/vm/assembler.scm (define-scm<-scmn-scmn-intrinsic): (lookup-bound-public, lookup-bound-private): Add assembler support.