This addresses a FIXME in r7rs-libraries.scm, which was about the cond-expand define-library declarations not using the same features as provided in (scheme base).
* .gitignore: Register /module/ice-9/endianness.scm. * am/bootstrap.am (NOCOMP_SOURCES): Register ice-9/endianness.scm and scheme/features.scm. * configure.ac: Define a NATIVE_ENDIANNESS output variable. * module/ice-9/endianness.scm.in: New file. * module/scheme/base.scm (features): Move to... * module/scheme/features.scm: ... here. Include this file in base.scm and... * module/ice-9/r7rs-libraries.scm: ... here. (define-library) <handle-cond-expand>: Adjust to match the definition of cond-expand found in (scheme base). * module/ice-9/boot-9.scm (%cond-expand-features): Move before where r7rs-libraries.scm is included. * NEWS: Update NEWS. --- (no changes since v5) Changes in v5: - Update NEWS .gitignore | 1 + NEWS | 1 + am/bootstrap.am | 2 ++ configure.ac | 7 +++- module/ice-9/boot-9.scm | 62 +++++++++++++++++---------------- module/ice-9/endianness.scm.in | 1 + module/ice-9/r7rs-libraries.scm | 6 ++-- module/scheme/base.scm | 10 ++---- module/scheme/features.scm | 44 +++++++++++++++++++++++ 9 files changed, 92 insertions(+), 42 deletions(-) create mode 100644 module/ice-9/endianness.scm.in create mode 100644 module/scheme/features.scm diff --git a/.gitignore b/.gitignore index 931ebf7c4..7903bee15 100644 --- a/.gitignore +++ b/.gitignore @@ -122,6 +122,7 @@ INSTALL /meta/guild /meta/guile-config /lib/locale.h +/module/ice-9/endianness.scm /module/ice-9/eval.go.stamp /doc/ref/standard-library.texi /doc/ref/standard-libraryscmfiles diff --git a/NEWS b/NEWS index 1de1fa8b4..e5cc3c7aa 100644 --- a/NEWS +++ b/NEWS @@ -56,6 +56,7 @@ other operations, given the internal use of those functions. ** R7RS define-library now properly supports 'rename' declarations (<https://bugs.gnu.org/67255>) ** (scheme base)'s cond-expand supports non-negative integer in modules names +** define-library's cond-expand declarations can now test complete features Changes in 3.0.9 (since 3.0.8) diff --git a/am/bootstrap.am b/am/bootstrap.am index a71946958..39f65f100 100644 --- a/am/bootstrap.am +++ b/am/bootstrap.am @@ -427,12 +427,14 @@ ELISP_SOURCES = \ language/elisp/boot.el NOCOMP_SOURCES = \ + ice-9/endianness.scm \ ice-9/match.upstream.scm \ ice-9/psyntax.scm \ ice-9/read.scm \ ice-9/r6rs-libraries.scm \ ice-9/r7rs-libraries.scm \ ice-9/quasisyntax.scm \ + scheme/features.scm \ srfi/srfi-42/ec.scm \ srfi/srfi-64/testing.scm \ srfi/srfi-67/compare.scm \ diff --git a/configure.ac b/configure.ac index d0a2dc79b..d049a5a1b 100644 --- a/configure.ac +++ b/configure.ac @@ -326,7 +326,12 @@ else fi AC_CHECK_LIB(uca, __uc_get_ar_bsp) -AC_C_BIGENDIAN +AC_C_BIGENDIAN( + [AC_DEFINE([WORDS_BIGENDIAN], 1) + AC_SUBST([NATIVE_ENDIANNESS], [big])], + [AC_SUBST([NATIVE_ENDIANNESS], [little])] +) +AC_CONFIG_FILES([module/ice-9/endianness.scm]) AC_C_LABELS_AS_VALUES diff --git a/module/ice-9/boot-9.scm b/module/ice-9/boot-9.scm index a79d49ae1..3da328b2a 100644 --- a/module/ice-9/boot-9.scm +++ b/module/ice-9/boot-9.scm @@ -4066,6 +4066,38 @@ but it fails to load." (process-use-modules (list quoted-args ...)) *unspecified*)))))) +;;; This is defined early because ice-9/r7rs-libraries makes use of +;;; the R7RS features, which requires it to be defined. +(define %cond-expand-features + ;; This should contain only features that are present in core Guile, + ;; before loading any modules. Modular features are handled by + ;; placing 'cond-expand-provide' in the relevant module. + '(guile + guile-2 + guile-2.2 + guile-3 + guile-3.0 + r5rs + r6rs + r7rs + exact-closed ieee-float full-unicode ratios ;; R7RS features. + srfi-0 ;; cond-expand itself + srfi-4 ;; homogeneous numeric vectors + srfi-6 ;; string ports + srfi-13 ;; string library + srfi-14 ;; character sets + srfi-16 ;; case-lambda + srfi-23 ;; `error` procedure + srfi-30 ;; nested multi-line comments + srfi-39 ;; parameterize + srfi-46 ;; basic syntax-rules extensions + srfi-55 ;; require-extension + srfi-61 ;; general cond clause + srfi-62 ;; s-expression comments + srfi-87 ;; => in case clauses + srfi-105 ;; curly infix expressions + )) + (include-from-path "ice-9/r6rs-libraries") (include-from-path "ice-9/r7rs-libraries") @@ -4535,36 +4567,6 @@ when none is available, reading FILE-NAME with READER." ;;; Remember to update the features list when adding more SRFIs. ;;; -(define %cond-expand-features - ;; This should contain only features that are present in core Guile, - ;; before loading any modules. Modular features are handled by - ;; placing 'cond-expand-provide' in the relevant module. - '(guile - guile-2 - guile-2.2 - guile-3 - guile-3.0 - r5rs - r6rs - r7rs - exact-closed ieee-float full-unicode ratios ;; R7RS features. - srfi-0 ;; cond-expand itself - srfi-4 ;; homogeneous numeric vectors - srfi-6 ;; string ports - srfi-13 ;; string library - srfi-14 ;; character sets - srfi-16 ;; case-lambda - srfi-23 ;; `error` procedure - srfi-30 ;; nested multi-line comments - srfi-39 ;; parameterize - srfi-46 ;; basic syntax-rules extensions - srfi-55 ;; require-extension - srfi-61 ;; general cond clause - srfi-62 ;; s-expression comments - srfi-87 ;; => in case clauses - srfi-105 ;; curly infix expressions - )) - ;; This table maps module public interfaces to the list of features. ;; (define %cond-expand-table (make-hash-table)) diff --git a/module/ice-9/endianness.scm.in b/module/ice-9/endianness.scm.in new file mode 100644 index 000000000..5d3f5dbaa --- /dev/null +++ b/module/ice-9/endianness.scm.in @@ -0,0 +1 @@ +(define %native-endianness '@NATIVE_ENDIANNESS@) diff --git a/module/ice-9/r7rs-libraries.scm b/module/ice-9/r7rs-libraries.scm index 773a9d47b..20692989d 100644 --- a/module/ice-9/r7rs-libraries.scm +++ b/module/ice-9/r7rs-libraries.scm @@ -29,6 +29,8 @@ (define-syntax-rule (include-ci filename) (include filename)) +(include-from-path "scheme/features.scm") + (define-syntax define-library (lambda (stx) (define (r7rs-module-name->r6rs-module-name name) @@ -91,9 +93,7 @@ (syntax->datum #'lib-name))))) (id (identifier? #'id) - ;; FIXME: R7RS (features) isn't quite the same as - ;; %cond-expand-features; see scheme/base.scm. - (memq (syntax->datum #'id) %cond-expand-features)))) + (memq (syntax->datum #'id) (features))))) (syntax-case clauses (else) (() #'()) ; R7RS says this is not specified :-/ (((else decl ...)) diff --git a/module/scheme/base.scm b/module/scheme/base.scm index 2bd1f0d89..1f47f8560 100644 --- a/module/scheme/base.scm +++ b/module/scheme/base.scm @@ -272,6 +272,8 @@ (make-exception exn (make-exception-with-irritants irritants)))))) +(include-from-path "scheme/features.scm") + (define-syntax r7:cond-expand (lambda (x) (define (has-req? req) @@ -551,14 +553,6 @@ (exact->inexact (expt x y)) (expt x y))) -(define (features) - (append - (case (native-endianness) - ((big) '(big-endian)) - ((little) '(little-endian)) - (else '())) - %cond-expand-features)) - (define (input-port-open? port) (and (not (port-closed? port)) (input-port? port))) diff --git a/module/scheme/features.scm b/module/scheme/features.scm new file mode 100644 index 000000000..7acbe332b --- /dev/null +++ b/module/scheme/features.scm @@ -0,0 +1,44 @@ +;;; R7RS compatibility libraries -- features +;;; Copyright (C) 2019-2023 Free Software Foundation, Inc. +;;; +;;; This library is free software: you can redistribute it and/or modify +;;; it under the terms of the GNU Lesser General Public License as +;;; published by the Free Software Foundation, either version 3 of the +;;; License, or (at your option) any later version. +;;; +;;; This library is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; Lesser General Public License for more details. +;;; +;;; You should have received a copy of the GNU Lesser General Public +;;; License along with this program. If not, see +;;; <http://www.gnu.org/licenses/>. + +;;; Based on code from https://gitlab.com/akku/akku-scm, written +;;; 2018-2019 by Göran Weinholt <go...@weinholt.se>, as well as +;;; https://github.com/okuoku/yuni, written 2014-2018 by OKUMURA Yuki +;;; <m...@cltn.org>. This code was originally released under the +;;; following terms: +;;; +;;; To the extent possible under law, the author(s) have dedicated +;;; all copyright and related and neighboring rights to this +;;; software to the public domain worldwide. This software is +;;; distributed without any warranty. +;;; +;;; See <http://creativecommons.org/publicdomain/zero/1.0/>, for a +;;; copy of the CC0 Public Domain Dedication. + +;;; This code is shared between (scheme base) and (ice-9 +;;; r7rs-libraries), which gets included in (ice-9 boot-9), to avoid +;;; having multiple copies 'features' to maintain. + +(include-from-path "ice-9/endianness.scm") + +(define (features) + (append + (case %native-endianness + ((big) '(big-endian)) + ((little) '(little-endian)) + (else '())) + %cond-expand-features)) -- 2.41.0