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.bugs Subject: bug#67412: [PATCH 2/2] r7rs-libraries: Better support R7RS SRFI library names. Date: Fri, 24 Nov 2023 11:39:30 -0500 Message-ID: <20231124163953.11253-2-maxim.cournoyer@gmail.com> References: <20231124163953.11253-1-maxim.cournoyer@gmail.com> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35507"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Maxim Cournoyer To: 67412@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Fri Nov 24 17:41:22 2023 Return-path: Envelope-to: guile-bugs@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 1r6ZF4-0008zV-3w for guile-bugs@m.gmane-mx.org; Fri, 24 Nov 2023 17:41:22 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r6ZEh-0003tU-VK; Fri, 24 Nov 2023 11:40:59 -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 1r6ZEg-0003se-Do for bug-guile@gnu.org; Fri, 24 Nov 2023 11:40:58 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r6ZEg-0007sc-4w for bug-guile@gnu.org; Fri, 24 Nov 2023 11:40:58 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r6ZEk-0001IK-LL for bug-guile@gnu.org; Fri, 24 Nov 2023 11:41:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Fri, 24 Nov 2023 16:41:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67412 X-GNU-PR-Package: guile Original-Received: via spool by 67412-submit@debbugs.gnu.org id=B67412.17008440194908 (code B ref 67412); Fri, 24 Nov 2023 16:41:02 +0000 Original-Received: (at 67412) by debbugs.gnu.org; 24 Nov 2023 16:40:19 +0000 Original-Received: from localhost ([127.0.0.1]:37052 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r6ZE3-0001H6-9H for submit@debbugs.gnu.org; Fri, 24 Nov 2023 11:40:19 -0500 Original-Received: from mail-qt1-x830.google.com ([2607:f8b0:4864:20::830]:59613) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r6ZDw-0001GZ-P8 for 67412@debbugs.gnu.org; Fri, 24 Nov 2023 11:40:16 -0500 Original-Received: by mail-qt1-x830.google.com with SMTP id d75a77b69052e-423922b10ffso6942101cf.2 for <67412@debbugs.gnu.org>; Fri, 24 Nov 2023 08:40:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700844001; x=1701448801; darn=debbugs.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=knkl8CC+CAugGnEdbzq5HBePGYEzssZL063Km2fg3Yc=; b=bOHTMXSplJDY7me/FzYrHbTYFOiRlVRcpwQeY2efJcK7L8fMbNSS9vmPElyayeu2En AQKodN2HrnSkVPAr+TS9QysTL3iDDFPLXgPiLFT2BIb65Z0afLu64J1yREUBIDS+pjDW rqS40cmJZloM34aVHWzM/LMQcS7cSt2oy0ADdCvr3Xy1LcEtcDtZ3j4u+Lg9YssqQWi/ J8s/arBRTk1QVMK0/dzF+L8MO6B+c18jSA8ebqvM7EuuyloQIW+hgMoeCI9nvMefH0We WtwLt/ydlEny3zZU0PnnrevDaABMURNgsClMPo0+5sg0l9TMraUxfh1VoGetGbGF3/Sn LlVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700844001; x=1701448801; 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=knkl8CC+CAugGnEdbzq5HBePGYEzssZL063Km2fg3Yc=; b=Sbcm0Qbl7GGoRrr6aAWFQmdWa345FnBuMGcQMXpT68HzP7YA+eSX1PwXBJeMOSEaQ9 dn+mj9CtvJrLzhbDZ9Twj+SmwFCcy+TrDn3JpaxXVGaA6pRQXgGdLRga2+YvTPKpQfR2 wkfvs/F6mQB7E1XTADJj1RlSY0MCiQ9ArQMBHpL2uCMSuw980kw9snixQ+CxVykr20SF mR/A+1IVsqarGVPfgdAzLmiGmL3EyU4xhvAsEjcBuygS/Zal787r2S6pqSZhrZGxip5a GipmaXLasRbELw5lYnp9m3je3uiqOaVWHK8UhB+qknE+p4MUjl+AHFYQuVAn/qRMXdLt mNoQ== X-Gm-Message-State: AOJu0Yw+3ZLEq332FgRbZnFmKmbMYo5+5dD+RWCzXxI/zuumlZxkfpqM tekSyQfFuCarYpVVDuITP43sdgQ0NaY= X-Google-Smtp-Source: AGHT+IExssCmXLdmQliGvmsOF5XPxQTkQzopepKsPxUjSZf/93nzKuA8FLl4YWXQ+38sWnWYUEuqNQ== X-Received: by 2002:ac8:5a11:0:b0:412:1e0a:772a with SMTP id n17-20020ac85a11000000b004121e0a772amr4247114qta.17.1700844000715; Fri, 24 Nov 2023 08:40:00 -0800 (PST) Original-Received: from localhost.localdomain (dsl-158-42.b2b2c.ca. [66.158.158.42]) by smtp.gmail.com with ESMTPSA id ay30-20020a05622a229e00b00423a0d10d4csm128885qtb.62.2023.11.24.08.40.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Nov 2023 08:40:00 -0800 (PST) X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231124163953.11253-1-maxim.cournoyer@gmail.com> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.bugs:10718 Archived-At: * module/ice-9/r6rs-libraries.scm (resolve-r6rs-interface) (library): Move R7RS specifics to... * module/ice-9/r7rs-libraries.scm (define-library): ... here. r6rs-name, r7rs-import->r6rs-import>: New nested procedures, used to translate the library name and import sets. * test-suite/tests/rnrs-libraries.test ("import features"): Add a test. Fixes: https://bugs.gnu.org/67412 --- module/ice-9/r6rs-libraries.scm | 25 +++-------------- module/ice-9/r7rs-libraries.scm | 48 +++++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 23 deletions(-) diff --git a/module/ice-9/r6rs-libraries.scm b/module/ice-9/r6rs-libraries.scm index f27b07841..78b3dfcfb 100644 --- a/module/ice-9/r6rs-libraries.scm +++ b/module/ice-9/r6rs-libraries.scm @@ -27,11 +27,6 @@ (define (sym? stx) (symbol? (syntax->datum stx))) - (define (n? stx) - (let ((n (syntax->datum stx))) - (and (exact-integer? n) - (not (negative? n))))) - (define (colon-n? x) (let ((sym (syntax->datum x))) (and (symbol? sym) @@ -45,8 +40,7 @@ (syntax-case stx (srfi) ((srfi n rest ...) (and (and-map sym? #'(rest ...)) - (or (n? #'n) - (colon-n? #'n)))) + (colon-n? #'n))) (_ #f))) (define (module-name? stx) @@ -63,9 +57,7 @@ (string-append "srfi-" (let ((n (syntax->datum n))) - (if (symbol? n) - (substring (symbol->string n) 1) - (number->string n))))))) + (substring (symbol->string n) 1)))))) (define (make-custom-interface mod) (let ((iface (make-module))) @@ -86,7 +78,6 @@ (syntax-case import-spec (library only except prefix rename srfi) ;; (srfi :n ...) -> (srfi srfi-n ...) - ;; (srfi n ...) -> (srfi srfi-n ...) ((library (srfi n rest ... (version ...))) (srfi-name? #'(srfi n rest ...)) (let ((srfi-n (make-srfi-n #'srfi #'n))) @@ -196,11 +187,6 @@ (define (sym? stx) (symbol? (syntax->datum stx))) - (define (n? stx) - (let ((n (syntax->datum stx))) - (and (exact-integer? n) - (not (negative? n))))) - (define (colon-n? x) (let ((sym (syntax->datum x))) (and (symbol? sym) @@ -214,8 +200,7 @@ (syntax-case stx (srfi) ((srfi n rest ...) (and (and-map sym? #'(rest ...)) - (or (n? #'n) - (colon-n? #'n)))) + (colon-n? #'n))) (_ #f))) (define (module-name? stx) @@ -232,9 +217,7 @@ (string-append "srfi-" (let ((n (syntax->datum n))) - (if (symbol? n) - (substring (symbol->string n) 1) - (number->string n))))))) + (substring (symbol->string n) 1)))))) (define (compute-exports ifaces specs) (define (re-export? sym) diff --git a/module/ice-9/r7rs-libraries.scm b/module/ice-9/r7rs-libraries.scm index f8b6b4c59..f2692b833 100644 --- a/module/ice-9/r7rs-libraries.scm +++ b/module/ice-9/r7rs-libraries.scm @@ -102,12 +102,56 @@ ((rename internal external) #'(rename (internal external))) (_ export))) + (define (r7rs-name->r6rs-name name) + ;; This is a hack to support (srfi N x ...) modules in R7RS. The + ;; longer term solution would be to add support at the level of + ;; resolve-interface (bug #40371). + (define (n? stx) + (let ((n (syntax->datum stx))) + (and (exact-integer? n) + (not (negative? n))))) + + (define (srfi-name? stx) + (syntax-case stx (srfi) + ((srfi n rest ...) + (n? #'n)) + (_ #f))) + + (define (make-srfi-n context n) + (datum->syntax + context + (string->symbol + (string-append + "srfi-" + (let ((n (syntax->datum n))) + (number->string n)))))) + + (syntax-case name (srfi) + ;; (srfi n ...) -> (srfi srfi-n ...) + ((srfi n rest ...) (srfi-name? #'(srfi n rest ...)) + #`(srfi #,(make-srfi-n #'srfi #'n) rest ...)) + (_ name))) + + (define (r7rs-import->r6rs-import import-set) + ;; Normalize SRFI names. + (syntax-case import-set (only except prefix rename) + ((only import-set identifier ...) + #`(only #,(r7rs-import->r6rs-import #'import-set) identifier ...)) + ((except import-set identifier ...) + #`(except #,(r7rs-import->r6rs-import #'import-set) identifier ...)) + ((prefix import-set identifier ...) + #`(prefix #,(r7rs-import->r6rs-import #'import-set) identifier ...)) + ((rename import-set (from-identifier to-identifier) ...) + #`(rename #,(r7rs-import->r6rs-import #'import-set) + (from-identifier to-identifier) ...)) + (_ (r7rs-name->r6rs-name import-set)))) + (syntax-case stx () ((_ name decl ...) (call-with-values (lambda () (partition-decls #'(decl ...) '() '() '())) (lambda (exports imports code) - #`(library name + #`(library #,(r7rs-name->r6rs-name #'name) (export . #,(map r7rs-export->r6rs-export exports)) - (import . #,imports) + (import . #,(map r7rs-import->r6rs-import imports)) . #,code))))))) -- 2.41.0