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

8347 commits

Author SHA1 Message Date
Daniel Llorens
f227a56991 Support typed arrays in some sort functions
* libguile/sort.c (sort!, sort, restricted-vector-sort!, sorted?):
  Support arrays of rank 1, whatever the type.

* libguile/quicksort.i.c: Fix accessors to handle typed arrays.

* test-suite/tests/sort.test: Test also with typed arrays.
2016-07-11 09:11:50 +02:00
Daniel Llorens
cbaa6cadcc Remove commented stack version of scm_array_for_each_cell()
* libguile/array-map.c: Ditto.
2016-07-11 09:11:50 +02:00
Daniel Llorens
4a361f2902 Fix pool version of scm_array_for_each_cell by aligning pointers
* libguile/array-map.c (scm_array_for_each_cell): Align all pointers to
  pointer size.
2016-07-11 09:11:50 +02:00
Daniel Llorens
79bf245c7e Fix a corner case with empty arrays in (array-for-each-cell)
* libguile/array-map.c (scm_array_for_each_cell): Bail out early if any
  of the sizes is zero. Pack ais at the end of the fake stack.

* test-suite/tests/array-map.test: Add regression test.
2016-07-11 09:11:50 +02:00
Daniel Llorens
f6003e8881 Clean up (array-for-each-cell)
* libguile/array-map.c (array-for-each-cell,
  array-for-each-cell-in-order): Moved from libguile/arrays.c. Fix
  argument names. Complete docstring.

* libguile/array-map.h (array-for-each-cell,
  array-for-each-cell-in-order): Declarations moved from
  libguile/arrays.h.

* test-suite/tests/array-map.test: Renamed from
  test-suite/tests/ramap.test, fix module name.

  Add tests for (array-for-each-cell).

* test-suite/Makefile.am: Apply rename array-map.test -> ramap.test.

* doc/ref/api-compound.texi: Minor documentation fixes.
2016-07-11 09:11:50 +02:00
Daniel Llorens
2ce48a3f46 Avoid variable stack use in scm_array_for_each_cell()
* libguile/arrays.c (scm_array_for_each_cell): Allocate all variable
  sized data at the top of the function using
  scm_gc_malloc_pointerless().
2016-07-11 09:11:50 +02:00
Daniel Llorens
b854d0f34a Special case for array-map! with three arguments
Benchmark:

(define type #t)
(define A (make-typed-array 's32 0 10000 1000))
(define B (make-typed-array 's32 0 10000 1000))
(define C (make-typed-array 's32 0 10000 1000))

before:

scheme@(guile-user)> ,time (array-map! C + A B)
;; 0.792653s real time, 0.790970s run time.  0.000000s spent in GC.

after:

scheme@(guile-user)> ,time (array-map! C + A B)
;; 0.598513s real time, 0.597146s run time.  0.000000s spent in GC.

* libguile/array-map.c (ramap): Add special case with 3 arguments.
2016-07-11 09:11:50 +02:00
Daniel Llorens
ffd949e597 New export (array-for-each-cell-in-order)
* libguile/arrays.h (array-for-each-cell-in-order): Declare.

* libguile/arrays.c (array-for-each-cell-in-order): Define.
2016-07-11 09:11:50 +02:00
Daniel Llorens
fb4d4d966c Draft of (array-for-each-cell)
* libguile/arrays.c (scm_i_array_rebase, scm_array_for_each_cell): new
  functions. Export scm_array_for_each_cell() as (array-for-each-cell).

* libguile/arrays.h (scm_i_array_rebase, scm_array_for_each_cell):
  prototypes.
2016-07-11 09:11:50 +02:00
Daniel Llorens
da81901c9a Do not use array handles in scm_vector
* libguile/vectors.c (scm_vector): Use SCM_I_VECTOR_WELTS on new vector
  instead of generic scm_vector_elements; cf. scm_vector_copy().

  (scm_vector_elements): Forward to scm_vector_writable_elements().

  (scm_vector_writable_elements): Remove special error message for weak
  vector arg.

* libguile/generalized-vectors.c (SCM_VALIDATE_VECTOR_WITH_HANDLE):
  Remove unused macro.

* libguile/array-handle.c (scm_array_handle_elements): Forward to
  scm_array_handle_writable_elements().
2016-07-11 09:11:50 +02:00
Daniel Llorens
cea5139e65 Remove deprecated and unused generalized-vector functions
* libguile/generalized-vectors.h, libguile/generalized-vectors.c
  (scm_is_generalized_vector, scm_c_generalized_vector_length,
  scm_c_generalized_vector_ref, scm_c_generalized_vector_set_x): These
  functions were deprecated in 2.0.9. Remove.
2016-07-11 09:11:50 +02:00
Daniel Llorens
c17799dda9 Speed up for multi-arg cases of scm_ramap functions
This patch results in a 20%-40% speedup in the > 1 argument cases of
the following microbenchmarks:

(define A (make-shared-array #0(1) (const '()) #e1e7))
; 1, 2, 3 arguments.
(define a 0) ,time (array-for-each (lambda (b) (set! a (+ a b))) A)
(define a 0) ,time (array-for-each (lambda (b c) (set! a (+ a b c))) A A)
(define a 0) ,time (array-for-each (lambda (b c d) (set! a (+ a b c d))) A A A)

(define A (make-shared-array (make-array 1) (const '()) #e1e7))
(define B (make-shared-array #0(1) (const '()) #e1e7))
; 1, 2, 3 arguments.
,time (array-map! A + B)
,time (array-map! A + B B)
,time (array-map! A + B B B)

* libguile/array-map.c (scm_ramap): note on cproc arguments.

  (rafill): assume that dst's lbnd is 0.

  (racp): assume that src's lbnd is 0.

  (ramap): assume that ra0's lbnd is 0. When there're more than two
  arguments, compute the array handles before the loop. Allocate the arg
  list once and reuse it in the loop.

  (rafe): like rafe, when there's more than one argument.

  (AREF, ASET): remove.
2016-07-11 09:11:50 +02:00
Daniel Llorens
348d8b46b0 Remove deprecated array functions
* libguile/array-map.c (scm_array_fill_int, scm_array_fill_int,
    scm_ra_eqp, scm_ra_lessp scm_ra_leqp, scm_ra_grp, scm_ra_greqp,
    scm_ra_sum, scm_ra_difference, scm_ra_product, scm_ra_divide,
    scm_array_identity): remove deprecated functions.

* libguile/array-map.h: remove declaration of deprecated functions.
2016-07-11 09:11:50 +02:00
Daniel Llorens
ed6c65507a Don't use array handles in scm_c_array_rank
* libguile/arrays.c (scm_c_array_rank): moved from
  libguile/generalized-arrays.c. Don't use array handles, but follow the
  same type check sequence as the other array functions
  (shared-array-root, etc).

  (scm_array_rank): moved from libguile/generalized-arrays.h.

* libguile/arrays.h: move prototypes here.
2016-07-11 09:11:50 +02:00
Daniel Llorens
3aafc2c857 Rename array-set-from!, scm_array_set_from_x to array-amend!, scm_array_amend_x 2016-07-11 09:11:50 +02:00
Daniel Llorens
7d7ada39d0 New functions array-from, array-from*, array-set-from!
* libguile/arrays.h (scm_array_from, scm_array_from_s,
  scm_array_set_from_x): new declarations.

* libguile/arrays.c (scm_array_from, scm_array_from_s,
  scm_array_set_from_x): new functions, export as array-from,
  array-from*, array-set-from!.
2016-07-11 09:11:50 +02:00
Daniel Llorens
b9cbf3b6de Reuse SCM_BYTEVECTOR_TYPED_LENGTH in scm_array_get_handle
* libguile/bytevectors.h (SCM_BYTEVECTOR_TYPE_SIZE,
  SCM_BYTEVECTOR_TYPED_LENGTH): moved from libguile/bytevectors.c.

* libguile/array-handle.c (scm_array_get_handle): reuse
  SCM_BYTEVECTOR_TYPED_LENGTH.
2016-07-11 09:11:50 +02:00
Daniel Llorens
212c5b0f29 Unuse array 'contiguous' flag
SCM_I_ARRAY_FLAG_CONTIGUOUS (arrays.h) was set by all array-creating
functions (make-typed-array, transpose-array, make-shared-array) but it
was only used by array-contents, which needed to traverse the dimensions
anyway.

* libguile/arrays.c (scm_make_typed_array,
  scm_from_contiguous_typed_array): don't set the contiguous flag.

  (scm_transpose_array, scm_make_shared_array): don't call
  scm_i_ra_set_contp.

  (scm_array_contents): inline scm_i_ra_set_contp() here. Adopt uniform
  type check order. Remove redundant comments.

  (scm_i_ra_set_contp): remove.

* libguile/arrays.h: note.

* test-suite/tests/arrays.test: test array-contents with rank 0 array.
2016-07-11 09:11:50 +02:00
Daniel Llorens
c557ff68ec Remove scm_from_contiguous_array
This function is undocumented, unused within Guile, and can be trivially
replaced by make-array + array-copy without requiring contiguity.

* libguile/arrays.h (scm_from_contiguous_array): remove declaration.

* libguile/arrays.c (scm_from_contiguous_array): remove.
2016-07-11 09:11:50 +02:00
Daniel Llorens
655494c65b Avoid unneeded internal use of array handles
* libguile/arrays.c (scm_shared_array_root): adopt uniform check order.

  (scm_shared_array_offset, scm_shared_array_increments): use the array
  fields directly just as scm_shared_array_root does.

* test-suite/tests/arrays.test: tests for shared-array-offset,
  shared-array-increments.
2016-07-11 09:11:50 +02:00
Andy Wingo
38f23e75a5 Add meta/build-env
* meta/build-env.in: New file which sets up an environment that does not
  inherit GUILE_LOAD_PATH / GUILE_LOAD_COMPILED_PATH (unless
  cross-compiling).
* doc/ref/Makefile.am (autoconf-macros.texi):
* libguile/Makefile.am (snarf2checkedtexi):
* module/Makefile.am (ice-9/psyntax-pp.go):
* test-suite/standalone/Makefile.am (GUILE_INSTALL_LOCALE):
* am/bootstrap.am (.scm.go):
* am/guilec (.scm.go): Use build-env.
* configure.ac: Create build-env.
2016-07-10 14:10:26 +02:00
Andy Wingo
6a5b44de68 Check for strtod_l before using it.
Based on a patch by Andy Stormont <astormont@racktopsystems.com>.

* configure.ac: Check for strtod_l.
* libguile/i18n.c (scm_locale_string_to_integer): Fix style.
  (scm_locale_string_to_inexact): Check for strtod_l.
2016-06-24 17:52:30 +02:00
Andy Wingo
d848af9a16 Parse bytecode to determine minimum arity
* libguile/programs.c (try_parse_arity): New helper, to parse bytecode
  to determine the minimum arity of a function in a cheaper way than
  grovelling through the debug info.  Should speed up all thunk? checks
  and similar.
  (scm_i_program_arity): Simplify.
* libguile/gsubr.h:
* libguile/gsubr.c (scm_i_primitive_arity):
* libguile/foreign.h:
* libguile/foreign.c (scm_i_foreign_arity):
2016-06-24 14:15:38 +02:00
Andy Wingo
7d550c4ea0 Fix ,profile in pure modules
* libguile/scmsigs.c (close_1): Make the async closure in an environment
  where `lambda' has its usual meaning.  Fixes #21013.
2016-06-24 09:50:23 +02:00
Andy Wingo
f23dfc0fb5 Locale is default port encoding
* libguile/ports.c (scm_init_ports): Use the locale as the default
  charset.  After the switch to default GUILE_INSTALL_LOCALE=1, this
  harmonizes the default port encoding with the installed locale.
2016-06-24 07:43:58 +02:00
Andy Wingo
2c8ea5a008 Fix memory leak in scm_from_{u,}int64 on 32-bit platforms
* libguile/conv-integer.i.c (SCM_FROM_TYPE_PROTO):
* libguile/conv-uinteger.i.c (SCM_FROM_TYPE_PROTO): Fix a big in which
  scm_from_int64 and scm_from_uint64 on a 32-bit platform leaked memory
  if they needed to allocate a bignum.  Fixes #20079.
2016-06-23 14:57:50 +02:00
Andy Wingo
c01a2a757e Fix race between SMOB marking and finalization
* libguile/smob.c (clear_smobnum): New helper.
  (finalize_smob): Re-set the smobnum to the "finalized smob" type
  before finalizing.  Fixes #19883.
  (scm_smob_prehistory): Pre-register a "finalized smob" type, which has
  no mark procedure.
* test-suite/standalone/test-smob-mark-race.c: New file.
* test-suite/standalone/Makefile.am: Arrange to build and run the new
  test.
2016-06-23 12:13:02 +02:00
Andy Wingo
9a95167871 Fix relative file name canonicalization on paths with "."
* libguile/filesys.c (scm_i_relativize_path): Canonicalize the file
  names elements that we will be using as prefixes.  Fixes the case
  where a load path contains a relative file name: #19540.
* test-suite/tests/ports.test ("%file-port-name-canonicalization"): Add
  tests that elements of the load path are canonicalized.
2016-06-23 10:17:57 +02:00
Andy Wingo
d84f25c271 Remove unused internal i18n functions
* libguile/i18n.c (str_upcase, str_downcase, str_upcase_l)
  (str_downcase_l): Remove unused inline functions.  Based on a patch by
  Pedro Aguilar <paguilar@paguilar.org>.  Fixes #19172.
2016-06-22 16:47:40 +02:00
Andy Wingo
0ef4b76221 Remove a stale variable use in libguile/Makefile.am
* libguile/Makefile.am (BUILT_SOURCES): Remove a use of a variable that
  doesn't exist in 2.2.
2016-06-22 16:47:40 +02:00
Andy Wingo
3abd8e1ac1 Fix SCM_DEBUG_TYPING_STRICTNESS bug
* libguile/ports.c (scm_setvbuf): Fix bad use of SCM as a test value.
  Actually all ports have read buffers, so we can remove the condition
  entirely.  Thanks Hydra for building in this way :)
2016-06-22 12:50:16 +02:00
Andy Wingo
f1c0434403 `define!' instruction returns the variable
* doc/ref/vm.texi (Top-Level Environment Instructions): Update
  documentation.
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump, sadly.
* module/system/vm/assembler.scm (*bytecode-minor-version*): Bump.
* libguile/vm-engine.c (define!): Change to store variable in dst slot.
* module/language/tree-il/compile-cps.scm (convert):
* module/language/cps/compile-bytecode.scm (compile-function): Adapt to
  define! change.
* module/language/cps/effects-analysis.scm (current-module): Fix define!
  effects.  Incidentally here was the bug: in Guile 2.2 you can't have
  effects on different object kinds in one instruction, without
  reverting to &unknown-memory-kinds.
* test-suite/tests/compiler.test ("regression tests"): Add a test.
2016-06-21 22:40:31 +02:00
Andy Wingo
dc7bc06f69 Fix size measurement in bytevector_large_set
* libguile/bytevectors.c (bytevector_large_set): Fix computation of
  value size in words.
* test-suite/tests/bytevectors.test: Add test.

Thanks to Ben Rocer <fleabyte@mail.com> for the bug report and fix.
2016-06-20 17:15:21 +02:00
Andy Wingo
0c1ee6eae6 Fix ports bug when size_t is 32 bits
* libguile/ports.c (scm_end_input): I am a complete idiot.  I had no
  idea that `- (uint32_t) x' is actually still a uint32_t.
2016-06-18 13:08:12 +02:00
Andy Wingo
7142005a05 Skip incompatible .go files
* libguile/load.c (load_thunk_from_path, try_load_thunk_from_file): New
  functions.
  (search_path): Simplify.
  (scm_primitive_load_path, scm_init_eval_in_scheme): Use the new
  functions to load compiled files.
* module/ice-9/boot-9.scm (load-in-vicinity): Skip invalid .go files.

Inspired by a patch from Jan Nieuwenhuizen <janneke@gnu.org>.
2016-06-12 10:32:45 +02:00
Andy Wingo
2cb7c4c4d7 Remove unused static definitions
* libguile/expand.c:
* libguile/vm.c: Remove unused static definitions.
2016-06-11 18:29:35 +02:00
Andy Wingo
be6194e32a Fix shuffling of unboxed stack elements on 32-bit systems
* libguile/vm-engine.c (SP_REF_SLOT, SP_SET_SLOT): New defines.
  (push, pop, mov, long-mov): Move full slots.  Fixes 32-bit with
  unboxed 64-bit stack values; before when shuffling these values
  around, we were only shuffling the lower 32 bits on 32-bit platforms.
2016-06-11 14:44:59 +02:00
Andy Wingo
100b048097 VM type checking refactor
* libguile/vm-engine.c (VM_VALIDATE): Refactor some type-related
  assertions to use a common macro.
  (vector-length, vector-set!/immediate): Fix the proc mentioned in the
  error message.
2016-06-11 13:03:20 +02:00
Andy Wingo
ddce05e819 vm: Make sure IP is stored before potentially GCing.
* libguile/vm-engine.c: Add a number of SYNC_IP calls that were missing
  before calls that could GC.
2016-06-11 12:26:26 +02:00
Andy Wingo
7e502d57e0 Fix bad backtraces
* libguile/vm-engine.c (BV_REF, BV_BOUNDED_SET, BV_SET, integer->char)
  (char->integer): Use VM_ASSERT so that we save the IP before erroring
  out.
2016-06-10 15:33:09 +02:00
Andy Wingo
d1b99ea2ae Minor VM fixes
* libguile/vm-engine.c (string-ref): Unpack the index into a 64-bit
  integer.
  (br-if-u64-<-scm): Tighten up the fast path.
2016-06-10 08:23:04 +02:00
Andy Wingo
69ea1fc45b Support `connect' on nonblocking sockets
* libguile/socket.c (scm_connect):
* doc/ref/posix.texi (Network Sockets and Communication): Support
  connect on nonblocking ports.
2016-06-09 10:59:08 +02:00
Andy Wingo
e6cc051f8c `accept' on nonblocking socket can return #f
* doc/ref/posix.texi (Network Sockets and Communication):
* libguile/socket.c (scm_accept): Return #f if the socket is nonblocking
  and no connection is ready.
2016-06-09 10:59:08 +02:00
Andy Wingo
d8067213dc put-char in Scheme
* libguile/ports.c (scm_port_encode_char): New function.
* module/ice-9/ports.scm (port-encode-char): Export port-encode-char to
  the internals module.
* module/ice-9/sports.scm (put-char): New function.
  (port-bindings): Add put-char and put-string.
2016-06-09 10:59:02 +02:00
Andy Wingo
4bceba876b put-char, put-string in (ice-9 ports internals)
* libguile/ports.h (scm_put_char):
* libguile/ports.c (scm_put_char): New function.
  (scm_put_string): Add docstrings, and expose to the internal ports
  module.
* module/ice-9/ports.scm (put-char, put-string): Expose these bindings
  only through the internals module.
2016-06-08 07:44:16 +02:00
Andy Wingo
d7f39a36b1 socket: TCP_CORK, TCP_NODELAY
* libguile/socket.c (scm_init_socket): Define TCP_NODELAY and TCP_CORK
  if they are available.
* doc/ref/posix.texi (Network Sockets and Communication): Add
  documentation.
* NEWS: Add entry.
2016-06-04 12:49:47 +02:00
Andy Wingo
5bec3261b4 Rework text encoding to be more Scheme-friendly
* libguile/ports.c (scm_port_clear_stream_start_for_bom_write): Instead
  of returning the BOM, take an optional buffer in which to write the
  BOM.  Return number of bytes written.
  (port_clear_stream_start_for_bom_write): Remove.
  (scm_i_write): Adapt scm_port_clear_stream_start_for_bom_write call.
  (try_encode_char_to_iconv_buf, encode_latin1_chars_to_latin1_buf):
  (encode_latin1_chars_to_utf8_buf, encode_latin1_chars_to_iconv_buf):
  (encode_latin1_chars, encode_utf32_chars_to_latin1_buf):
  (encode_utf32_chars_to_utf8_buf, encode_utf32_chars_to_iconv_buf):
  (encode_utf32_chars, port_encode_chars): New helpers.
  (scm_port_encode_chars): New procedure.
  (scm_c_put_latin1_chars, scm_c_put_utf32_chars): Rework to use new
  encoding helpers.
  (scm_lfwrite): Use scm_c_put_latin1_chars.
2016-06-01 12:07:20 +02:00
Andy Wingo
0e888cd00b Simplify string, symbol, char display/write impls
* libguile/print.h:
* libguile/print.c: Use the new routines from ports.[ch].
2016-05-30 18:49:25 +02:00
Andy Wingo
2affb9accf Add scm_c_put_escaped_char, scm_c_can_put_char
* libguile/ports.h:
* libguile/ports.c (scm_c_put_escaped_char, scm_c_can_put_char): New
  helpers.
2016-05-30 18:48:09 +02:00
Andy Wingo
934b6dc398 iprin1 uses scm_c_put_string
* libguile/print.c (iprin1): Use scm_c_put_string for strings.
* test-suite/test-suite/lib.scm (exception:encoding-error): Add an
  additional expected error string for `encoding-error'.
2016-05-30 15:07:23 +02:00