File: explicit-endianness.scm

package info (click to toggle)
scheme-bytestructures 2.0.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 480 kB
  • sloc: lisp: 2,168; makefile: 73; sh: 8
file content (85 lines) | stat: -rw-r--r-- 3,407 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
;;; explicit-endianness.scm --- Auxiliary bytevector operations.

;; Copyright © 2015 Taylan Kammer <taylan.kammer@gmail.com>

;; This program 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.

;; This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; The numeric module requires top-level bindings to bytevector procedures with
;; an explicit endianness, instead of the ones that take an endianness
;; argument.  This library provides them.


;;; Code:

(define-syntax define-explicit-endianness-getters
  (syntax-rules ()
    ((_ (original le-name be-name) ...)
     (begin
       (begin
         (define (le-name bytevector index)
           (original bytevector index (endianness little)))
         (define (be-name bytevector index)
           (original bytevector index (endianness big))))
       ...))))

(define-explicit-endianness-getters
  (bytevector-ieee-single-ref bytevector-ieee-single-le-ref
                              bytevector-ieee-single-be-ref)
  (bytevector-ieee-double-ref bytevector-ieee-double-le-ref
                              bytevector-ieee-double-be-ref)
  (bytevector-s16-ref bytevector-s16le-ref
                      bytevector-s16be-ref)
  (bytevector-u16-ref bytevector-u16le-ref
                      bytevector-u16be-ref)
  (bytevector-s32-ref bytevector-s32le-ref
                      bytevector-s32be-ref)
  (bytevector-u32-ref bytevector-u32le-ref
                      bytevector-u32be-ref)
  (bytevector-s64-ref bytevector-s64le-ref
                      bytevector-s64be-ref)
  (bytevector-u64-ref bytevector-u64le-ref
                      bytevector-u64be-ref))

(define-syntax define-explicit-endianness-setters
  (syntax-rules ()
    ((_ (original le-name be-name) ...)
     (begin
       (begin
         (define (le-name bytevector index value)
           (original bytevector index value (endianness little)))
         (define (be-name bytevector index value)
           (original bytevector index value (endianness big))))
       ...))))

(define-explicit-endianness-setters
  (bytevector-ieee-single-set! bytevector-ieee-single-le-set!
                               bytevector-ieee-single-be-set!)
  (bytevector-ieee-double-set! bytevector-ieee-double-le-set!
                               bytevector-ieee-double-be-set!)
  (bytevector-s16-set! bytevector-s16le-set!
                       bytevector-s16be-set!)
  (bytevector-u16-set! bytevector-u16le-set!
                       bytevector-u16be-set!)
  (bytevector-s32-set! bytevector-s32le-set!
                       bytevector-s32be-set!)
  (bytevector-u32-set! bytevector-u32le-set!
                       bytevector-u32be-set!)
  (bytevector-s64-set! bytevector-s64le-set!
                       bytevector-s64be-set!)
  (bytevector-u64-set! bytevector-u64le-set!
                       bytevector-u64be-set!))

;;; explicit-endianness.scm ends here