gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet-scheme] 98/324: utils: Define module for defining platform-speci


From: gnunet
Subject: [gnunet-scheme] 98/324: utils: Define module for defining platform-specifing enumerations.
Date: Tue, 21 Sep 2021 13:22:18 +0200

This is an automated email from the git hooks/post-receive script.

maxime-devos pushed a commit to branch master
in repository gnunet-scheme.

commit c39e0113d477935d3552aadd5b0ecf1bbdec32bc
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Wed Mar 24 13:51:02 2021 +0100

    utils: Define module for defining platform-specifing enumerations.
    
    (gnu extractor enum) is not suitable as it assumes the enumeration
    values are the same on all target platforms.
    
    * gnu/gnunet/utils/platform-enum.scm
      (that-platform?): Define syntax for writing platform-specific code.
      (define-platform-enumeration): Define syntax for defining
      platform-specific C-style enumerations compactly.
    * Makefile.am (modules): Compile the new module.
    * README.org (modules): Note this module exists.
---
 Makefile.am                        |  1 +
 README.org                         |  2 ++
 gnu/gnunet/utils/platform-enum.scm | 48 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 51 insertions(+)

diff --git a/Makefile.am b/Makefile.am
index 1e20804..ea62015 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -46,6 +46,7 @@ modules = \
   gnu/gnunet/utils/bv-slice.scm \
   gnu/gnunet/utils/hat-let.scm \
   gnu/gnunet/utils/netstruct.scm \
+  gnu/gnunet/utils/platform-enum.scm \
   \
   gnu/gnunet/util/cmsg.scm \
   gnu/gnunet/icmp/struct.scm \
diff --git a/README.org b/README.org
index 0e54618..f67d273 100644
--- a/README.org
+++ b/README.org
@@ -50,6 +50,8 @@
   + gnu/gnunet/concurrency/update.scm: a box with a value,
     that can be updated, resulting in a new box.  Updates
     can be waited upon.
+  + gnu/gnunet/utils/platform-enum.scm: Platform-specific
+    C-style enum values.
 
 ** Message queues
    Message queues have three parts: the input queue, the output
diff --git a/gnu/gnunet/utils/platform-enum.scm 
b/gnu/gnunet/utils/platform-enum.scm
new file mode 100644
index 0000000..f3207ca
--- /dev/null
+++ b/gnu/gnunet/utils/platform-enum.scm
@@ -0,0 +1,48 @@
+;; This file is part of scheme-GNUnet.
+;; Copyright (C) 2021 Maxime Devos
+;;
+;; scheme-GNUnet is free software: you can redistribute it and/or modify it
+;; under the terms of the GNU Affero General Public License as published
+;; by the Free Software Foundation, either version 3 of the License,
+;; or (at your option) any later version.
+;;
+;; scheme-GNUnet 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
+;; Affero General Public License for more details.
+;;
+;; You should have received a copy of the GNU Affero General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+;;
+;; SPDX-License-Identifier: AGPL3.0-or-later
+
+;; Brief: C-style enumeration that are platform-specific.
+;; TODO: autoconfery
+
+(define-module (gnu gnunet utils platform-enum)
+  #:export (that-platform? define-platform-enumeration))
+
+;; Define an enumeration, with values depending
+;; on the platform.  If the value is not supported
+;; on the target platform, set it to #f instead.
+
+(define-syntax that-platform?
+  (syntax-rules (or and not)
+    ((_ #:hurd) (string-prefix? "gnu" (target-os)))
+    ((_ #:linux) (string-prefix? "linux" (target-os)))
+    ((_ (or a ...)) ((@ (guile) or) (that-platform? a) ...))
+    ((_ (and a ...)) ((@ (guile) and) (that-platform? a) ...))
+    ((_ (not a)) ((@ (guile) not) (that-platform? a)))
+    ((_ #t) #t)
+    ((_ #f) #f)
+    ((_ #nil) #f)))
+
+(define-syntax define-platform-enumeration
+  (syntax-rules ()
+    ((_ (name (platform value) ...) ...)
+     (begin
+       (define name
+        (cond ((that-platform? platform) value)
+              ...
+              (#t #f)))
+       ...))))

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]