From 878b9c3dca93ffda3e14353d2f59dea08fa236b3 Mon Sep 17 00:00:00 2001 From: Timothy Sample Date: Sun, 19 May 2019 19:33:05 -0400 Subject: [PATCH] Add support for Guile 2.0.9. * gash/compat.scm: New file. * gash/compat/hash-table.scm: New file. * Makefile.am: Add them. * .dir-locals.scm: Add indentation for 'if-guile-version-below'. * guix.scm (guile-2.0.9): New variable. * gash/built-ins/echo.scm (escape->control): Use '#\esc'. * gash/environment.scm: Use '(gash compat hash-table)'. * gash/built-ins/break.scm, gash/built-ins/cd.scm, gash/built-ins/command.scm, gash/built-ins/continue.scm, gash/built-ins/dot.scm, gash/built-ins/exec.scm, gash/built-ins/exit.scm, gash/built-ins/pwd.scm, gash/built-ins/return.scm, gash/built-ins/set.scm, gash/built-ins/shift.scm, gash/built-ins/trap.scm, gash/built-ins/type.scm, gash/built-ins/umask.scm, gash/eval.scm, tests/unit/automake.scm: Use '(gash compat)'. squash! Add support for Guile 2.0.9. --- .dir-locals.el | 1 + Makefile.am | 2 ++ gash/built-ins/break.scm | 1 + gash/built-ins/cd.scm | 1 + gash/built-ins/command.scm | 1 + gash/built-ins/continue.scm | 1 + gash/built-ins/dot.scm | 1 + gash/built-ins/echo.scm | 4 ++- gash/built-ins/exec.scm | 1 + gash/built-ins/exit.scm | 1 + gash/built-ins/pwd.scm | 1 + gash/built-ins/return.scm | 1 + gash/built-ins/set.scm | 1 + gash/built-ins/shift.scm | 1 + gash/built-ins/trap.scm | 1 + gash/built-ins/type.scm | 1 + gash/built-ins/umask.scm | 1 + gash/compat.scm | 58 +++++++++++++++++++++++++++++++++++++ gash/compat/hash-table.scm | 39 +++++++++++++++++++++++++ gash/environment.scm | 2 +- gash/eval.scm | 1 + guix.scm | 17 +++++++++++ tests/unit/automake.scm | 1 + 23 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 gash/compat.scm create mode 100644 gash/compat/hash-table.scm diff --git a/.dir-locals.el b/.dir-locals.el index f357b21..b400e62 100644 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -6,6 +6,7 @@ (let ((top (locate-dominating-file default-directory ".dir-locals.el"))) (add-to-list 'geiser-guile-load-path top)))) + (eval . (put 'if-guile-version-below 'scheme-indent-function 1)) (eval . (put ' 'scheme-indent-function 1)) (eval . (put ' 'scheme-indent-function 1)) (eval . (put ' 'scheme-indent-function 1)) diff --git a/Makefile.am b/Makefile.am index 108bfe7..6141451 100644 --- a/Makefile.am +++ b/Makefile.am @@ -37,6 +37,8 @@ GUILE_MODULES = \ gash/built-ins/unset.scm \ gash/built-ins/utils.scm \ gash/built-ins.scm \ + gash/compat/hash-table.scm \ + gash/compat.scm \ gash/config.scm \ gash/environment.scm \ gash/eval.scm \ diff --git a/gash/built-ins/break.scm b/gash/built-ins/break.scm index bdc0390..c4d8bf5 100644 --- a/gash/built-ins/break.scm +++ b/gash/built-ins/break.scm @@ -17,6 +17,7 @@ ;;; along with Gash. If not, see . (define-module (gash built-ins break) + #:use-module (gash compat) #:use-module (gash environment)) ;;; Commentary: diff --git a/gash/built-ins/cd.scm b/gash/built-ins/cd.scm index 57cab88..324122c 100644 --- a/gash/built-ins/cd.scm +++ b/gash/built-ins/cd.scm @@ -17,6 +17,7 @@ ;;; along with Gash. If not, see . (define-module (gash built-ins cd) + #:use-module (gash compat) #:use-module (gash environment) #:use-module (ice-9 match)) diff --git a/gash/built-ins/command.scm b/gash/built-ins/command.scm index 6c40a2d..035e2ce 100644 --- a/gash/built-ins/command.scm +++ b/gash/built-ins/command.scm @@ -20,6 +20,7 @@ (define-module (gash built-ins command) #:use-module (ice-9 getopt-long) #:use-module (gash built-ins utils) + #:use-module (gash compat) #:use-module (gash config)) ;;; Commentary: diff --git a/gash/built-ins/continue.scm b/gash/built-ins/continue.scm index a94deca..5a60529 100644 --- a/gash/built-ins/continue.scm +++ b/gash/built-ins/continue.scm @@ -17,6 +17,7 @@ ;;; along with Gash. If not, see . (define-module (gash built-ins continue) + #:use-module (gash compat) #:use-module (gash environment)) ;;; Commentary: diff --git a/gash/built-ins/dot.scm b/gash/built-ins/dot.scm index 5b00a93..fa478bc 100644 --- a/gash/built-ins/dot.scm +++ b/gash/built-ins/dot.scm @@ -18,6 +18,7 @@ (define-module (gash built-ins dot) #:use-module (gash built-ins utils) + #:use-module (gash compat) #:use-module (gash environment) #:use-module (gash parser) #:use-module (ice-9 match)) diff --git a/gash/built-ins/echo.scm b/gash/built-ins/echo.scm index de94fde..8148073 100644 --- a/gash/built-ins/echo.scm +++ b/gash/built-ins/echo.scm @@ -42,7 +42,9 @@ ((#\a) (cons #\alarm (loop (cdr lst)))) ((#\b) (cons #\backspace (loop (cdr lst)))) ((#\c) '()) - ((#\e) (cons #\escape (loop (cdr lst)))) + ;; Guile 2.0.9 does not understand '#\escape', + ;; so we use the older '#\esc'. + ((#\e) (cons #\esc (loop (cdr lst)))) ((#\f) (cons #\page (loop (cdr lst)))) ((#\n) (cons #\newline (loop (cdr lst)))) ((#\r) (cons #\return (loop (cdr lst)))) diff --git a/gash/built-ins/exec.scm b/gash/built-ins/exec.scm index 53d14d0..f19a77b 100644 --- a/gash/built-ins/exec.scm +++ b/gash/built-ins/exec.scm @@ -17,6 +17,7 @@ ;;; along with Gash. If not, see . (define-module (gash built-ins exec) + #:use-module (gash compat) #:use-module (gash environment) #:use-module (ice-9 match) #:use-module (srfi srfi-1)) diff --git a/gash/built-ins/exit.scm b/gash/built-ins/exit.scm index c97e31a..7209aa6 100644 --- a/gash/built-ins/exit.scm +++ b/gash/built-ins/exit.scm @@ -17,6 +17,7 @@ ;;; along with Gash. If not, see . (define-module (gash built-ins exit) + #:use-module (gash compat) #:use-module (gash environment)) ;;; Commentary: diff --git a/gash/built-ins/pwd.scm b/gash/built-ins/pwd.scm index a1abc32..ebfa3be 100644 --- a/gash/built-ins/pwd.scm +++ b/gash/built-ins/pwd.scm @@ -17,6 +17,7 @@ ;;; along with Gash. If not, see . (define-module (gash built-ins pwd) + #:use-module (gash compat) #:use-module (gash environment) #:use-module (ice-9 match)) diff --git a/gash/built-ins/return.scm b/gash/built-ins/return.scm index 819e8d5..e463ac4 100644 --- a/gash/built-ins/return.scm +++ b/gash/built-ins/return.scm @@ -17,6 +17,7 @@ ;;; along with Gash. If not, see . (define-module (gash built-ins return) + #:use-module (gash compat) #:use-module (gash environment)) ;;; Commentary: diff --git a/gash/built-ins/set.scm b/gash/built-ins/set.scm index f7b8515..89436fa 100644 --- a/gash/built-ins/set.scm +++ b/gash/built-ins/set.scm @@ -18,6 +18,7 @@ ;;; along with Gash. If not, see . (define-module (gash built-ins set) + #:use-module (gash compat) #:use-module (gash environment) #:use-module (srfi srfi-26) #:use-module (ice-9 match)) diff --git a/gash/built-ins/shift.scm b/gash/built-ins/shift.scm index b65ff7f..4f92afe 100644 --- a/gash/built-ins/shift.scm +++ b/gash/built-ins/shift.scm @@ -17,6 +17,7 @@ ;;; along with Gash. If not, see . (define-module (gash built-ins shift) + #:use-module (gash compat) #:use-module (gash environment) #:use-module (ice-9 match) #:use-module (srfi srfi-1)) diff --git a/gash/built-ins/trap.scm b/gash/built-ins/trap.scm index f4c19ae..5447ab4 100644 --- a/gash/built-ins/trap.scm +++ b/gash/built-ins/trap.scm @@ -17,6 +17,7 @@ ;;; along with Gash. If not, see . (define-module (gash built-ins trap) + #:use-module (gash compat) #:use-module (gash environment) #:use-module (ice-9 match)) diff --git a/gash/built-ins/type.scm b/gash/built-ins/type.scm index d80b4e0..98c3b9c 100644 --- a/gash/built-ins/type.scm +++ b/gash/built-ins/type.scm @@ -20,6 +20,7 @@ (define-module (gash built-ins type) #:use-module (ice-9 getopt-long) #:use-module (gash built-ins utils) + #:use-module (gash compat) #:use-module (gash config)) ;;; Commentary: diff --git a/gash/built-ins/umask.scm b/gash/built-ins/umask.scm index cb09f7d..2d6f210 100644 --- a/gash/built-ins/umask.scm +++ b/gash/built-ins/umask.scm @@ -17,6 +17,7 @@ ;;; along with Gash. If not, see . (define-module (gash built-ins umask) + #:use-module (gash compat) #:use-module (ice-9 match)) ;;; Commentary: diff --git a/gash/compat.scm b/gash/compat.scm new file mode 100644 index 0000000..fcd2a6b --- /dev/null +++ b/gash/compat.scm @@ -0,0 +1,58 @@ +;;; Gash -- Guile As SHell +;;; Copyright © 2019 Timothy Sample +;;; +;;; This file is part of Gash. +;;; +;;; Gash is free software: you can redistribute it and/or modify +;;; it under the terms of the GNU General Public License as published by +;;; the Free Software Foundation, either version 3 of the License, or +;;; (at your option) any later version. +;;; +;;; Gash 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 General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with Gash. If not, see . + +(define-module (gash compat) + #:export (if-guile-version-below)) + +;;; Commentary: +;;; +;;; This module fills in for features that are missing in older +;;; versions of the '(guile)' module. +;;; +;;; Code: + +(define-syntax if-guile-version-below + (lambda (x) + (define (guile-versionnumber (major-version))) + (g-minor (string->number (minor-version))) + (g-micro (string->number (micro-version)))) + (or (< g-major major) + (and (= g-major major) + (< g-minor minor)) + (and (= g-major major) + (= g-minor minor) + (< g-micro micro))))) + + (syntax-case x () + ((_ (maj min mic) consequent alternate) + (if (guile-versiondatum #'maj) + (syntax->datum #'min) + (syntax->datum #'mic)) + #'consequent + #'alternate))))) + +(if-guile-version-below (2 0 10) + (begin + (define-public EXIT_SUCCESS 0) + + (define-public EXIT_FAILURE 1) + + (define-public (exact-integer? x) + (and (integer? x) (exact? x)))) + #f) diff --git a/gash/compat/hash-table.scm b/gash/compat/hash-table.scm new file mode 100644 index 0000000..5c6a320 --- /dev/null +++ b/gash/compat/hash-table.scm @@ -0,0 +1,39 @@ +;;; Gash -- Guile As SHell +;;; Copyright © 2019 Timothy Sample +;;; +;;; This file is part of Gash. +;;; +;;; Gash is free software: you can redistribute it and/or modify +;;; it under the terms of the GNU General Public License as published by +;;; the Free Software Foundation, either version 3 of the License, or +;;; (at your option) any later version. +;;; +;;; Gash 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 General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with Gash. If not, see . + +(define-module (gash compat hash-table) + #:use-module (gash compat)) + +;;; Commentary: +;;; +;;; The '(ice-9 hash-table)' module was introduced into Guile in +;;; version 2.0.10, so we provide a shim. +;;; +;;; Code: + +(if-guile-version-below (2 0 10) + (begin + (define-public (alist->hash-table alist) + (let ((table (make-hash-table))) + (for-each (lambda (pair) + (hash-set! table (car pair) (cdr pair))) + (reverse alist)) + table))) + (begin + (use-modules (ice-9 hash-table)) + (re-export alist->hash-table))) diff --git a/gash/environment.scm b/gash/environment.scm index 6443d3f..a8338b8 100644 --- a/gash/environment.scm +++ b/gash/environment.scm @@ -18,7 +18,7 @@ ;;; along with Gash. If not, see . (define-module (gash environment) - #:use-module (ice-9 hash-table) + #:use-module (gash compat hash-table) #:use-module (ice-9 match) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) diff --git a/gash/eval.scm b/gash/eval.scm index 28ec5d3..daace06 100644 --- a/gash/eval.scm +++ b/gash/eval.scm @@ -18,6 +18,7 @@ ;;; along with Gash. If not, see . (define-module (gash eval) + #:use-module (gash compat) #:use-module (gash environment) #:use-module (gash shell) #:use-module (gash word) diff --git a/guix.scm b/guix.scm index 59484e5..b651828 100644 --- a/guix.scm +++ b/guix.scm @@ -7,6 +7,7 @@ (gnu packages texinfo) (guix build utils) (guix build-system gnu) + (guix download) (guix gexp) ((guix licenses) #:prefix license:) (guix packages) @@ -47,6 +48,22 @@ (or (eq? (stat:type stat) 'directory) (member relative paths))))) +(define guile-2.0.9 + (package + (inherit guile-2.0) + (version "2.0.9") + (source + (origin + (method url-fetch) + (uri (string-append "mirror://gnu/guile/guile-" version ".tar.xz")) + (sha256 + (base32 + "0nw9y8vjyz4r61v06p9msks5lm58pd91irmzg4k487vmv743h2pp")))) + (arguments + (substitute-keyword-arguments (package-arguments guile-2.0) + ;; XXX: There are some encoding and network test failures. + ((#:tests? _ #f) #f))))) + (package (name "gash") (version *version*) diff --git a/tests/unit/automake.scm b/tests/unit/automake.scm index 0669922..d772751 100644 --- a/tests/unit/automake.scm +++ b/tests/unit/automake.scm @@ -17,6 +17,7 @@ ;;; along with Gash. If not, see . (define-module (tests unit automake) + #:use-module (gash compat) #:use-module (srfi srfi-64)) ;;; Commentary: