summaryrefslogtreecommitdiff
path: root/ebus-racket/3rdparty/bzlib/base/version-case.ss
blob: a9f60d7a1d52c0899433d6df02b0794e275d2839 (plain)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#lang scheme/base
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; BASE.plt - common routines that are shared by all other bzlib modules 
;; 
;; in a way, base.plt is the most fundamental module of the whole bzlib stack
;; and as such it also is the lowest level code.  We are not likely to 
;; fix the code any time soon, and hence any of the functions here are 
;; explicitly likely to be obsoleted or moved elsewhere. 
;; 
;; Proceed with caution. 
;; 
;; 
;; Bonzai Lab, LLC.  All rights reserved.
;; 
;; Licensed under LGPL.
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; version-case.ss - version-based macros 
;; yc 1/18/2010 - first version 
(require (for-syntax scheme/base
                     "version.ss"
                     )
         "version.ss"
         )

(define-syntax (+:version stx)
  (syntax-case stx (between > >= < <= = != else)
    ((~) #'(void))
    ((~ (else exp)) #'exp)
    ((~ ((between min max) exp) rest ...)
     (version<=? (syntax->datum #'min) 
                 (version) 
                 (syntax->datum #'max))
     #'exp)
    ((~ ((between min max) exp) rest ...)
     #'(~ rest ...)) 
    ((~ ((> v) exp) rest ...)
     (version>? (version) (syntax->datum #'v))
     #'exp)
    ((~ ((> v) exp) rest ...)
     #'(~ rest ...)) 
    ((~ ((>= v) exp) rest ...)
     (version>=? (version) (syntax->datum #'v))
     #'exp)
    ((~ ((>= v) exp) rest ...)
     #'(~ rest ...)) 
    ((~ ((< v) exp) rest ...)
     (version<? (version) (syntax->datum #'v))
     #'exp)
    ((~ ((< v) exp) rest ...)
     #'(~ rest ...)) 
    ((~ ((<= v) exp) rest ...)
     (version<=? (version) (syntax->datum #'v))
     #'exp) 
    ((~ ((<= v) exp) rest ...)
     #'(~ rest ...)) 
    ((~ ((= v) exp) rest ...)
     (version=? (version) (syntax->datum #'v))
     #'exp) 
    ((~ ((= v) exp) rest ...)
     #'(~ rest ...)) 
    ((~ ((!= v) exp) rest ...)
     (version!=? (version) (syntax->datum #'v))
     #'exp)
    ((~ ((!= v) exp) rest ...)
     #'(~ rest ...)) 
    )) 

(define-syntax +:version-between
  (syntax-rules ()
    ((~ min max exp otherwise)
     (+:version ((between min max) exp) (else otherwise)))
    ))

(define-syntax define-version-if 
  (syntax-rules () 
    ((~ name comp)
     (define-syntax name 
       (syntax-rules () 
         ((~ v exp otherwise) 
          (+:version ((comp v) exp) (else otherwise))))))
    ))

(define-version-if +:version> >)

(define-version-if +:version>= >=)

(define-version-if +:version< <)

(define-version-if +:version<= <=)

(define-version-if +:version= =)

(define-version-if +:version!= !=)

(define-syntax require/v 
  (syntax-rules () 
    ((~ (test s1 ...) ...) 
     (+:version (test (require s1 ...)) ...))
    ))

(define-syntax provide/v
  (syntax-rules () 
    ((~ (test s1 ...) ...) 
     (+:version (test (provide s1 ...)) ...))
    ))

(provide +:version
         +:version-between
         +:version>
         +:version>=
         +:version<
         +:version<=
         +:version=
         +:version!=
         require/v 
         provide/v 
         )