From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Maxim Cournoyer Newsgroups: gmane.lisp.guile.devel Subject: [PATCH v9 06/18] Share features tested by cond-expand library declarations and expressions. Date: Tue, 12 Dec 2023 23:37:45 -0500 Message-ID: <20231213044217.14093-7-maxim.cournoyer@gmail.com> References: <20231213044217.14093-1-maxim.cournoyer@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26769"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Maxim Cournoyer To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Wed Dec 13 05:44:00 2023 Return-path: Envelope-to: guile-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rDH6G-0006ko-8v for guile-devel@m.gmane-mx.org; Wed, 13 Dec 2023 05:44:00 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rDH4z-0004JV-8H; Tue, 12 Dec 2023 23:42:41 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rDH4w-0004Ie-97 for guile-devel@gnu.org; Tue, 12 Dec 2023 23:42:38 -0500 Original-Received: from mail-qt1-x836.google.com ([2607:f8b0:4864:20::836]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rDH4q-00071i-Dv for guile-devel@gnu.org; Tue, 12 Dec 2023 23:42:38 -0500 Original-Received: by mail-qt1-x836.google.com with SMTP id d75a77b69052e-425a1e571f0so38240521cf.3 for ; Tue, 12 Dec 2023 20:42:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702442551; x=1703047351; darn=gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SrKaD4eg09pAk1IU3KnGcyKb7INZp9uUK1mI/bB9nUQ=; b=RpAtV5FAsAVqCoeNdoa2hDqdXwcQgRH71DBSD27Kc5yU1+yq832lRGEuD27xF+aMbe P76XjSEffpBn/pxYWURi58mxYNXA7do/9LJoErLe5W4BYkqAU77Jz45NReQc32pnuKvR AA0si2rscq/OTrIX7YtMLn1triGv97f3l/kX45PqMRzwQRpNJsjDrTcpLM9z8PJChvus vOQndBkAux7sW6sVuN03EB4P/4gGR844we6W3g0uFDmLqgIoyDIqiljNReFrT8zzFrp2 eT5r/sY2s1chWZ5z4z9eVF9q3VBY5jeaV2UofTyynTtwV8FW4S2jZx5pnvW9xgbQpL++ pz/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702442551; x=1703047351; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SrKaD4eg09pAk1IU3KnGcyKb7INZp9uUK1mI/bB9nUQ=; b=eM7fq0ggbBGf9S4nRDMKVTxR2oDLgRcpMfr4OWbwus3FD6eqNZJuV3CAxvzf7XeMQ9 JXoMuFM3w3Y7PjNPP1P3mv1eBXRBnZ2XJ/p1B9KfYsxaNkFVEN4H140UK5zKZWkDDn5A wirrzvOFy5EmgPOXF8dUPHXcbFFtRjGt3yvgf4yaoayWPgjlkU3jIZS4NddpRh79VyW9 gVU3e+gD3srBFpZ/w7ZSu8uXdzUr0VxrYk7UtwSjVCBnl0sreY+mGPGPZ4boyuRKEokP 3ttfejqi5meQX1w6kPDzyP48mi2RVSLMJg5iOl2ZMiRTEOMDDbZbZavcBS4ElTk/I9rj PpOA== X-Gm-Message-State: AOJu0YyUU36EtFGy3cZeRKQE2rbpX4pgUIqc/BVZOG7JMr/ap3SzS4zJ F/sJ3iNTTwsWjL4t0Aaaxm6m0An9BaFr9g== X-Google-Smtp-Source: AGHT+IHC0tHinCdUuKKfDiLXjQcj3YyCLi5PK3L82Ua9IJZrVEOeW43xYqx0CMkG7T6XanwZ7vn40Q== X-Received: by 2002:ac8:5bc4:0:b0:423:8e83:9525 with SMTP id b4-20020ac85bc4000000b004238e839525mr10348228qtb.44.1702442550923; Tue, 12 Dec 2023 20:42:30 -0800 (PST) Original-Received: from localhost.localdomain (dsl-157-186.b2b2c.ca. [66.158.157.186]) by smtp.gmail.com with ESMTPSA id s7-20020ac87587000000b004181138e0c0sm4621719qtq.31.2023.12.12.20.42.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 20:42:30 -0800 (PST) X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231213044217.14093-1-maxim.cournoyer@gmail.com> Received-SPF: pass client-ip=2607:f8b0:4864:20::836; envelope-from=maxim.cournoyer@gmail.com; helo=mail-qt1-x836.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.devel:22238 Archived-At: 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) : 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 () ** (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 +;;; . + +;;; Based on code from https://gitlab.com/akku/akku-scm, written +;;; 2018-2019 by Göran Weinholt , as well as +;;; https://github.com/okuoku/yuni, written 2014-2018 by OKUMURA Yuki +;;; . 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 , 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