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

253 commits

Author SHA1 Message Date
Ludovic Courtès
3ed7673ac0 srfi-35: Fix expansion of 'condition' for compound conditions.
* module/srfi/srfi-35.scm (condition): Use 'make-exception' instead of
'make-compound-condition', which is unbound in this module.
* test-suite/tests/srfi-35.test ("syntax")["compound condition,
hygienic macro expansion"]: New test.
2022-10-01 18:04:16 +02:00
Daniel Llorens
5759e37181 New function srfi-4-vector-type-size in (srfi srfi-4 gnu)
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-12-06 14:00:03 +01:00
Daniel Llorens
6be51f9bbf Provide xxvector-copy and xxvector-copy! for srfi-4 vectors
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-21 15:05:46 +02:00
Ludovic Courtès
e304773416 srfi-1: 'find-tail' passes 'check-arg' the right procedure name.
* module/srfi/srfi-1.scm (find-tail): Pass 'find-tail' as the 3rd
argument to 'check-arg'.
2021-09-20 17:00:19 +02:00
Daniel Llorens
5df5555d12 Add function vector-copy! to core
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-06 17:13:21 +02:00
Daniel Llorens
a34c762de0 Extend core vector-copy to r7rs vector-copy
* 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-06 13:06:51 +02:00
jakub-w
f10bc1a864 [srfi-64] Fix a bug with test-end removing globally installed test-runner
* testing.scm (%test-begin, %test-end): When (test-runner-current) is
not set, create a new one like before but also add a finalizer that
will remove it after the test is finished. Previously the test runner
was getting unset unconditionally.

See https://srfi-email.schemers.org/srfi-64/msg/16468240/
2021-05-05 12:29:47 +02:00
Ricardo G. Herdt
23042a1ef9 Fix hash-table-merge! bug.
* module/srfi/srfi-69.scm : fold over second hash table.
2021-03-12 22:31:00 +01:00
Daniel Llorens
de5d1a7f99 Fix bug #42713: srfi-64: Reset test-runner-current if done
Reported by Jérémy Korwin-Zmijowski
(https://lists.gnu.org/archive/html/bug-guile/2020-08/msg00010.html).

Fix from
7cf4c01039:

Apply fix from Per Bothner.

In Per's words:

  * testing.scm (%test-end): Reset test-runner-current if done.
  This fixes bug "Loading test source file multiple time without having
  report incrementing" reported to srfi-64 mailing list.

  * srfi-64-test.scm: Update due to recent srfi-64 implementation change.
2020-08-05 12:46:27 +02:00
Ludovic Courtès
a15acbb828 srfi-1: Rewrite 'assoc' in Scheme.
* libguile/srfi-1.c (scm_srfi1_assoc): Remove.
* libguile/srfi-1.h (scm_srfi1_assoc): Likewise.
* module/srfi/srfi-1.scm (assoc): New procedure.
2020-06-17 17:59:35 +02:00
Ludovic Courtès
cd4c747fb8 srfi-1: Rewrite 'find-tail' in Scheme.
* libguile/srfi-1.c (scm_srfi1_find_tail): Remove.
* libguile/srfi-1.h (scm_srfi1_find_tail): Likewise.
* module/srfi/srfi-1.scm (find-tail): New procedure.
2020-06-17 17:33:28 +02:00
Ludovic Courtès
0360843ace srfi-1: Rewrite 'find' in Scheme.
This halves the wall-clock time of:

  guile -c '(use-modules (srfi srfi-1)) (define lst (make-list 100000000 1)) (find zero? lst)'

and yields an 18% speedup on:

  guile -c '(use-modules (srfi srfi-1)) (define lst (make-list 100000000 1)) (find (lambda (x) (= 2 x)) lst)'

* libguile/srfi-1.c (scm_srfi1_find): Remove.
* libguile/srfi-1.h (scm_srfi1_find): Likewise.
* module/srfi/srfi-1.scm (find): New procedure.
* doc/ref/srfi-modules.texi (SRFI-1 Searching): Adjust docstring.
2020-06-17 17:25:23 +02:00
Andy Wingo
cae74359de Replace bit-count with bitvector-count
The old name was wonky and had bad argument order.

* NEWS: Add entry.
* doc/ref/api-data.texi (Bit Vectors): Update.
* libguile/bitvectors.h:
* libguile/bitvectors.c (VALIDATE_BITVECTOR): New helper.
  (scm_bitvector_count): New function.
* libguile/deprecated.h:
* libguile/deprecated.c (scm_bit_count): Deprecate.
* module/ice-9/sandbox.scm (bitvector-bindings): Replace bit-count with
  bitvector-count.
* module/srfi/srfi-60.scm: No need to #:replace bit-count.
* module/system/vm/frame.scm (available-bindings): Use bitvector-count.
* test-suite/tests/bitvectors.test ("bitvector-count"): Add test.
2020-04-12 22:17:22 +02:00
Daniel Llorens
2b4e45ca1b Add #:declarative? #f to (srfi srfi-64)
This is needed for test-log-to-file to work.
2020-04-09 16:58:17 +02:00
Linus Björnstam
5f60eb6bb5 Add SRFI-171 to guile
This adds SRFI-171 (transducers) to guile.

The two guile-specific additions are powerful transducers which can be
used to generalize transducers like tsegment. They are hard to get
right, but powerful and useful enough to warrant inclusion.

 * doc/ref/srfi-modules.texi: added srfi-171 section
 * module/Makefile.am (SOURCES):
 * module/srfi/srfi-171.scm:
 * module/srfi/srfi-171/meta.scm: Add SRFI-171
 * module/srfi/srfi-171/gnu.scm: Add 2 guile-specific extensions.
 * test-suite/Makefile.am (SCM_TESTS):
 * test-suite/tests/srfi-171.test: Add tests.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2020-03-25 22:44:27 +01:00
Tim Gesthuizen
1733efe236 srfi-11: Do not expose variables to later clauses
The current implementation of srfi-11s let-values allows later clauses
to access and modify variables bound in earlier clauses when the clause
is not a proper list.

* module/srfi/srfi-11.scm (let-values): Fix switched variable names.
* test-suite/tests/srfi-11.test (let-values): Add test checking that the
  variable cannot be changed in later clauses.
2020-01-12 22:18:41 +01:00
Andy Wingo
8068994ba8 Re-implement `guard'
* module/ice-9/exceptions.scm (guard): Add guard definition that
  re-propagates from original continuation, runs consequents in tail
  position in guard continuation, and doesn't rewind the stack.
* module/srfi/srfi-34.scm:
* module/rnrs/exceptions.scm (guard): Re-export from (ice-9
  exceptions).
2020-01-10 21:42:26 +01:00
Daniel Llorens
ddad8ae05a Extend core vector-fill! to handle a range
With this patch, these two lines

  (vector-fill! vec fill)
  (vector-fill! vec fill 0 end)

run at the same speed; before, the second one was much slower.

This patch also makes it an error to call vector-fill! with a non-vector
array. The previous implementation did not work correctly in this case.

* libguile/vectors.c (SCM_VALIDATE_MUTABLE_VECTOR): Better error message.
  (vector-fill!): Handle optional arguments start, end. Do not attempt
    to handle non-vector arrays. Rename the C binding to
    scm_vector_fill_partial_x.
  (scm_vector_fill_x): Reuse scm_vector_fill_partial_x.
* module/srfi/srfi-43.scm (vector-fill!): Remove & re-export the core
  version instead.
2020-01-03 13:01:04 +01:00
Ludovic Courtès
76e436c892 srfi-35: Generate a unique binding for the constructor.
Previously we'd get warnings like:

  t.scm:11:0: warning: shadows previous definition of `unused-constructor-51900bdce47d50c' at /tmp/t.scm:6:0

whenever 'define-condition-type' appeared more than once in a source
file.

* module/srfi/srfi-35.scm (define-condition-type): Rewrite as
'syntax-case' and generate UNUSED-CONSTRUCTOR as a function of TYPE.
2019-12-14 23:56:12 +01:00
Ludovic Courtès
0b2ae37094 srfi-35: Replace '&error'.
* module/srfi/srfi-35.scm: Move '&error' to new #:re-export-and-replace
clause.
2019-12-14 18:37:43 +01:00
Daniel Llorens
2b6083865a Single definition of (iota)
* module/ice-9/boot-9.scm (iota): Fix to be SRFI-1 compatible.
* module/srfi/srfi-1.scm: Re-export iota.
2019-12-06 14:14:30 +01:00
Andy Wingo
cf08dbdc18 Associate #:replace info with modules, not variables
* doc/ref/api-modules.texi (Creating Guile Modules): Document
  #:re-export-and-replace.
* module/ice-9/boot-9.scm (module-replacements): New module field.
  (make-module, make-autoload-interface): Initialize replacements to an
  empty hash table.
  (resolve-interface): Propagate replacement info when making custom
  interfaces.
  (define-module): Parse a #:re-export-and-replace keyword arg.
  (define-module*): Handle #:re-export-and-replace.
  (module-export!, module-re-export!): Add a keyword arg to indicate
  whether to replace or not.
  (module-replace!): Call module-export! with #:replace? #t.
  (duplicate-handlers): Update replace duplicate handler to look for
  replacement info on the interfaces.
* module/srfi/srfi-18.scm (srfi):
* module/srfi/srfi-34.scm (srfi): Update to #:re-export-and-replace
  raise-continuable as raise.
2019-11-29 11:51:29 +01:00
Andy Wingo
95efe14e44 SRFI-18 uses core exceptions
* module/ice-9/boot-9.scm (exception-kind, exception-args): Export.
* module/ice-9/exceptions.scm (exception-kind, exception-args):
  Re-export.
* module/srfi/srfi-18.scm: Rewrite exception support in terms of core
  exceptions, not SRFI-34/35.
* test-suite/tests/srfi-18.test: Since Guile doesn't expose the current
  exception handler as such, SRFI-18 captures it using delimited
  continuations.  This means that we can't compare the result
  of (current-exception-handler) with the installed handler using eq?,
  even though the procedures are indeed equivalent.  So, instead test
  handler behavior.
2019-11-14 16:33:10 +01:00
Andy Wingo
f4ca107f7f Rebase throw/catch on top of raise-exception/with-exception-handler
* libguile/exceptions.c:
* libguile/exceptions.h: New files.
* libguile.h: Add exceptions.h.
* libguile/Makefile.am (libguile_@GUILE_EFFECTIVE_VERSION@_la_SOURCES):
  (DOT_X_FILES, DOT_DOC_FILES, modinclude_HEADERS): Add exceptions.c and
  exceptions.h.
* libguile/init.c (scm_i_init_guile): Initialize exceptions.
* libguile/threads.c (scm_spawn_thread): Use new names for
  scm_i_make_catch_handler and scm_c_make_thunk.
* libguile/throw.c: Rewrite to be implemented in terms of
  with-exception-handler / raise-exception.
* libguile/throw.h: Use data types from exceptions.h.  Move
  scm_report_stack_overflow and scm_report_out_of_memory to
  exceptions.[ch].
* module/ice-9/boot-9.scm (&error, &programming-error)
  (&non-continuable, make-exception-from-throw, raise-exception)
  (with-exception-handler): New top-level definitions.
  (throw, catch, with-throw-handler): Rewrite in terms of
  with-exception-handler and raise-exception.
: New top-level definitions.
* module/ice-9/exceptions.scm: Adapt to re-export &error,
  &programming-error, &non-continuable, raise-exception, and
  with-exception-handler from boot-9.
  (make-quit-exception, guile-quit-exception-converter): New exception
  converters.
  (make-exception-from-throw): Override core binding.
* test-suite/tests/eval.test ("inner trim with prompt tag"): Adapt to
  "with-exception-handler" being the procedure on the stack.
  ("outer trim with prompt tag"): Likewise.
* test-suite/tests/exceptions.test (throw-test): Use pass-if-equal.
* module/srfi/srfi-34.scm: Reimplement in terms of core exceptions, and
  make "guard" actually re-raise continuations with the original "raise"
  continuation.
2019-11-13 22:24:19 +01:00
Andy Wingo
86bc3da9e0 Rebase SRFI-35 on top of (ice-9 exceptions)
* module/ice-9/exceptions.scm (exception-type?): New export.
* module/srfi/srfi-35.scm: Rewrite in terms of (ice-9 exceptions).
2019-11-04 15:18:57 +01:00
Andy Wingo
90d52a9e1d Add `record-type-has-parent?'.
* module/ice-9/boot-9.scm (record-type-has-parent?): New function.
* module/srfi/srfi-35.scm (condition-type?): Use it.
2019-11-03 21:36:39 +01:00
Andy Wingo
f963bdf02d Rename final? record type flag; add support for opaque?
* module/ice-9/boot-9.scm (record-type-extensible?): Rename from
  record-type-final?, with the opposite sense.
  (record-type-opaque?): New accessor.
  (make-record-type): Change #:final? to #:extensible?, with the
  opposite meaning.  Add #:opaque? arg.
* test-suite/tests/records.test ("records"): Add opaque tests; update
  extensible tests.
* doc/ref/api-data.texi (Records): Update.
* module/srfi/srfi-35.scm (&condition, make-condition-type): Update for
  make-record-type API change.
2019-10-27 21:31:18 +01:00
Andy Wingo
99a95383cf Rebase srfi-35 conditions on top of make-record-type
* module/srfi/srfi-35.scm: Import (ice-9 match), and remove now-unused
  srfi-1 import.
  (print-condition): Print more like records, as appears to be the
  intention.
  (&condition): Define using make-record-type.  Adapt all callers.
  Also, compound conditions are now a disjoint type, handled specially
  by condition-ref, condition?, and so on.
* test-suite/tests/srfi-35.test (v3): Fix an error in which a
  subcondition was initialized without initializers for all of its
  fields.
2019-10-23 14:42:35 +02:00
Andy Wingo
bebc46be14 SRFI-9 uses make-record-type
* module/srfi/srfi-9.scm (%define-record-type): Use make-record-type,
  instead of rolling our own vtable.  Shouldn't have any perf impact.
2019-10-23 12:04:58 +02:00
Andy Wingo
4bec125e63 Allow records to be subtyped
* module/ice-9/boot-9.scm (record-type-vtable): Add slots for "flags"
  and a parent vector.
  (record-type-name, record-type-fields): Move up in the file.
  (record-type-constructor, record-type-flags, record-type-parents): New
  accessors.
  (make-record-type): Take #:final? and #:parent keyword arguments.
  (record-constructor): Delegate to record-type-constructor.
  (record-predicate): For non-final types --types that can be extended
  by subtyping -- implement an O(1) type predicate.
  (define-record-type): Initialize the new fields.
* module/srfi/srfi-9.scm (%define-record-type): Initialize flags and
  parent fields.
2019-10-22 14:50:14 +02:00
Andy Wingo
cc7d394490 Deprecate passing a non-zero size to make-module
* module/ice-9/boot-9.scm (make-module): Issue a deprecation warning if
  users pass a non-zero size.
  (nested-define-module!, make-modules-in, beautify-user-module!)
  (resolve-interface, make-autoload-interface, %cond-expand-table):
* module/ice-9/popen.scm (port/pid-table):
* module/ice-9/session.scm (make-fold-modules):
* module/language/ecmascript/function.scm (*program-wrappers*):
* module/scripts/api-diff.scm (read-api-alist-file):
* module/srfi/srfi-10.scm (reader-ctors): Update callers.  Also remove
  some make-hash-table sizes.
2019-09-27 22:57:38 +02:00
Andy Wingo
7c5579909e Merge from stable-2.2 2019-08-02 15:04:42 +02:00
Mark H Weaver
2980b66f6f SRFI-19: Rename 'tai-epoch-in-jd' to 'utc-epoch-in-jd'.
* module/srfi/srfi-19.scm: Rename 'tai-epoch-in-jd' to
'utc-epoch-in-jd', to reflect its actual meaning and usage.
2019-06-18 05:15:07 -04:00
Daniel Llorens
347ec3f088 Support ~N in SRFI-19 string->date
* module/srfi/srfi-19.scm (fractional-integer-reader,
  make-fractional-integer-reader): From reference implementation.
  (reader-directives): Handle #\N, from reference implementation.
* test-suite/tests/srfi-19: Add tests for string->date ~N.
* doc/ref/srfi-modules.texi (string->date): Add line for ~N.
2019-05-23 17:14:27 +02:00
Mark H Weaver
f13e2cb8ad SRFI-19: Minor refactor of leap second table lookups.
* module/srfi/srfi-19.scm (leap-second-delta): Replace with ...
(utc->tai): ... this.
(leap-second-neg-delta): Replace with ...
(tai->utc): ... this.
(current-time-tai, priv:time-tai->time-utc!, priv:time-utc->time-tai!)
(time-tai->julian-day, time-monotonic->julian-day): Adapt accordingly.
2019-05-23 17:13:14 +02:00
Mark H Weaver
f9df551574 SRFI-19: time-utc->date: Support non-integer nanoseconds values.
* module/srfi/srfi-19.scm (time-utc->date): Use 'floor-remainder'
instead of 'modulo'.
2019-05-23 17:13:12 +02:00
Mark H Weaver
8e0dfaca19 SRFI-19: Check for incompatible types in time comparisons.
Fixes <https://bugs.gnu.org/26163>.
Reported by Zefram <zefram@fysh.org>.

* module/srfi/srfi-19.scm (time-compare-check): New procedure.
(time=?): Use 'time-compare-check' to check the arguments and raise an
error in case of mismatched types.  Previously, mismatched types would
cause time=? to return #f.
(time>?, time<?, time>=?, time<=?, time-difference!): Use
'time-compare-check' to check the arguments.
2019-05-23 17:13:11 +02:00
Mark H Weaver
0389c59bd4 SRFI-19: Fix normalization of seconds and nanoseconds in time records.
Fixes <https://bugs.gnu.org/26162>.
Reported by Zefram <zefram@fysh.org>.

* module/srfi/srfi-19.scm (time-normalize!): Rewrite.
* test-suite/tests/srfi-19.test: Add tests.
2019-05-23 17:13:09 +02:00
Mark H Weaver
db78033cc1 SRFI-19: Fix handling of negative years and negative julian days.
Fixes <https://bugs.gnu.org/21906>.
Mitigates <https://bugs.gnu.org/21903> and <https://bugs.gnu.org/21904>.
Reported by: Zefram <zefram@fysh.org>.

* module/srfi/srfi-19.scm (encode-julian-day-number)
(decode-julian-day-number, date-week-number): Use 'floor-quotient'
instead of 'quotient', and 'floor' instead of 'truncate', where
appropriate.
(time-utc->date): Ensure that the 'nanoseconds' field of the returned
date is non-negative.
(leap-year): Handle negative years properly, and reformulate the
computation.
(week-day): Handle negative years properly.  Use 'floor-quotient'
instead of 'quotient' where appropriate.
(directives): In the handler for '~Y' format escapes, improve the
handling of years outside of the range 0-9999.
(read-directives): Add a FIXME comment to fix the '~Y' reader to handle
years outside of the range 0-9999.
* test-suite/tests/srfi-19.test: Import (srfi srfi-1).  Use Guile's
modern keyword notation in the 'define-module' form.  Add more tests.
2019-05-23 17:13:05 +02:00
Mark H Weaver
e00563492a SRFI-19: Fix TAI->UTC conversions, leap second handling, etc.
Fixes <https://bugs.gnu.org/21911>.
Fixes <https://bugs.gnu.org/22034>.
Fixes <https://bugs.gnu.org/21902>.
Partially fixes <https://bugs.gnu.org/21904>.
Reported by Zefram <zefram@fysh.org>.

* doc/ref/srfi-modules.texi (SRFI-19 Introduction): Fix the definitions
of Julian Day and Modified Julian Day.  Give the correct full names of
UTC and TAI.
* module/srfi/srfi-19.scm: Import (srfi srfi-1).  Use modern Guile
keyword syntax in the 'define-module' form.
(leap-second-neg-delta): New procedure, derived from a similar procedure
in the latest upstream SRFI-19 reference implementation.
(priv:time-tai->time-utc!, time-tai->julian-day)
(time-monotonic->julian-day): Use 'leap-second-neg-delta'.
(local-tz-offset): Fix comment.
(leap-second?): Remove.
(tai-before-leap-second?): New procedure, derived from upstream SRFI-19.
(time-utc->date): Use 'define*' to handle the optional argument.  Remove
the leap second handling, following upstream SRFI-19.
(time-tai->date): Rewrite in terms of 'time-utc->date'.  Add special
leap second handling, following upstream SRFI-19.
(time-monotonic->date): Rewrite in terms of 'time-tai->date'.
(date->time-tai, date->time-monotonic): Add special leap second
handling, following upstream SRFI-19.
(directives): In the entry for the "~Y" escape in 'date->string', pad
the year field to 4 characters, following upstream SRFI-19.
* test-suite/tests/srfi-19.test: Add tests.
2019-05-23 17:13:03 +02:00
Mark H Weaver
a47a5e6828 Fix typos, indentation and error reporting in SRFI-19.
* module/srfi/srfi-19.scm: Fix typos in comments, indentation, and pass
the correct 'caller' name to 'time-error' in several places.
2019-05-23 16:09:53 +02:00
Mark H Weaver
d61da427e1 Update SRFI-19 leap second table.
* module/srfi/srfi-19.scm (leap-second-table): Update to include the
leap second on 1 January 2017.
2019-05-23 16:09:51 +02:00
Daniel Llorens
f74cfce4f1 Support ~N in SRFI-19 string->date
* module/srfi/srfi-19.scm (fractional-integer-reader,
  make-fractional-integer-reader): From reference implementation.
  (reader-directives): Handle #\N, from reference implementation.
* test-suite/tests/srfi-19: Add tests for string->date ~N.
* doc/ref/srfi-modules.texi (string->date): Add line for ~N.
2018-12-11 22:44:34 +01:00
Mark H Weaver
9f285187fe SRFI-19: Minor refactor of leap second table lookups.
* module/srfi/srfi-19.scm (leap-second-delta): Replace with ...
(utc->tai): ... this.
(leap-second-neg-delta): Replace with ...
(tai->utc): ... this.
(current-time-tai, priv:time-tai->time-utc!, priv:time-utc->time-tai!)
(time-tai->julian-day, time-monotonic->julian-day): Adapt accordingly.
2018-10-24 01:14:26 -04:00
Mark H Weaver
ac1fa8dba4 SRFI-19: time-utc->date: Support non-integer nanoseconds values.
* module/srfi/srfi-19.scm (time-utc->date): Use 'floor-remainder'
instead of 'modulo'.
2018-10-24 01:14:26 -04:00
Mark H Weaver
c9d903b6e4 SRFI-19: Check for incompatible types in time comparisons.
Fixes <https://bugs.gnu.org/26163>.
Reported by Zefram <zefram@fysh.org>.

* module/srfi/srfi-19.scm (time-compare-check): New procedure.
(time=?): Use 'time-compare-check' to check the arguments and raise an
error in case of mismatched types.  Previously, mismatched types would
cause time=? to return #f.
(time>?, time<?, time>=?, time<=?, time-difference!): Use
'time-compare-check' to check the arguments.
2018-10-21 19:42:38 -04:00
Mark H Weaver
437e1aa036 SRFI-19: Fix normalization of seconds and nanoseconds in time records.
Fixes <https://bugs.gnu.org/26162>.
Reported by Zefram <zefram@fysh.org>.

* module/srfi/srfi-19.scm (time-normalize!): Rewrite.
* test-suite/tests/srfi-19.test: Add tests.
2018-10-21 19:25:45 -04:00
Mark H Weaver
a58c7abd72 SRFI-19: Fix handling of negative years and negative julian days.
Fixes <https://bugs.gnu.org/21906>.
Mitigates <https://bugs.gnu.org/21903> and <https://bugs.gnu.org/21904>.
Reported by: Zefram <zefram@fysh.org>.

* module/srfi/srfi-19.scm (encode-julian-day-number)
(decode-julian-day-number, date-week-number): Use 'floor-quotient'
instead of 'quotient', and 'floor' instead of 'truncate', where
appropriate.
(time-utc->date): Ensure that the 'nanoseconds' field of the returned
date is non-negative.
(leap-year): Handle negative years properly, and reformulate the
computation.
(week-day): Handle negative years properly.  Use 'floor-quotient'
instead of 'quotient' where appropriate.
(directives): In the handler for '~Y' format escapes, improve the
handling of years outside of the range 0-9999.
(read-directives): Add a FIXME comment to fix the '~Y' reader to handle
years outside of the range 0-9999.
* test-suite/tests/srfi-19.test: Import (srfi srfi-1).  Use Guile's
modern keyword notation in the 'define-module' form.  Add more tests.
2018-10-20 23:15:51 -04:00
Mark H Weaver
5106377a34 SRFI-19: Fix TAI->UTC conversions, leap second handling, etc.
Fixes <https://bugs.gnu.org/21911>.
Fixes <https://bugs.gnu.org/22034>.
Fixes <https://bugs.gnu.org/21902>.
Partially fixes <https://bugs.gnu.org/21904>.
Reported by Zefram <zefram@fysh.org>.

* doc/ref/srfi-modules.texi (SRFI-19 Introduction): Fix the definitions
of Julian Day and Modified Julian Day.  Give the correct full names of
UTC and TAI.
* module/srfi/srfi-19.scm: Import (srfi srfi-1).  Use modern Guile
keyword syntax in the 'define-module' form.
(leap-second-neg-delta): New procedure, derived from a similar procedure
in the latest upstream SRFI-19 reference implementation.
(priv:time-tai->time-utc!, time-tai->julian-day)
(time-monotonic->julian-day): Use 'leap-second-neg-delta'.
(local-tz-offset): Fix comment.
(leap-second?): Remove.
(tai-before-leap-second?): New procedure, derived from upstream SRFI-19.
(time-utc->date): Use 'define*' to handle the optional argument.  Remove
the leap second handling, following upstream SRFI-19.
(time-tai->date): Rewrite in terms of 'time-utc->date'.  Add special
leap second handling, following upstream SRFI-19.
(time-monotonic->date): Rewrite in terms of 'time-tai->date'.
(date->time-tai, date->time-monotonic): Add special leap second
handling, following upstream SRFI-19.
(directives): In the entry for the "~Y" escape in 'date->string', pad
the year field to 4 characters, following upstream SRFI-19.
* test-suite/tests/srfi-19.test: Add tests.
2018-10-20 17:23:39 -04:00
Mark H Weaver
3845343cf3 Fix typos, indentation and error reporting in SRFI-19.
* module/srfi/srfi-19.scm: Fix typos in comments, indentation, and pass
the correct 'caller' name to 'time-error' in several places.
2018-10-16 04:20:47 -04:00