|
3 | 3 | (require racket/contract
|
4 | 4 | racket/format
|
5 | 5 | racket/string
|
| 6 | + "arch.rkt" |
| 7 | + "utils.rkt" |
6 | 8 | (for-syntax racket/base
|
7 | 9 | racket/syntax))
|
8 | 10 |
|
9 | 11 | (define-syntax (define-vars stx)
|
10 | 12 | (syntax-case stx ()
|
11 |
| - [(_ array contract a) |
12 |
| - (with-syntax |
13 |
| - ([a-val (format-id #'a "~a-val" #'a)] |
| 13 | + [(_ array/quote contract a) |
| 14 | + (with-syntax* |
| 15 | + ([a (if (equal? (syntax->datum #'contract) 'boolean?) |
| 16 | + (format-id #'a "~a?" #'a) |
| 17 | + #'a)] |
| 18 | + [a-val (format-id #'a "~a-val" #'a)] |
14 | 19 | [a? (format-id #'a "~a?" #'a)]
|
15 | 20 | [a->string (format-id #'a "~a->string" #'a)] )
|
16 | 21 | #`(begin
|
17 | 22 | (struct a (val) #:transparent)
|
18 |
| - (define/contract (a->string val) |
19 |
| - (-> a? string?) |
| 23 | + (define/contract (a->string val [arch 'any]) |
| 24 | + (->* (a?) (arch?) string?) |
20 | 25 | (format "~a=~a"
|
21 |
| - 'a |
22 |
| - (if (equal? 'contract string?) |
23 |
| - (a-val val) |
24 |
| - (if 'array |
25 |
| - (format "(~a)" (string-join (map ~v (a-val val)))) |
26 |
| - (format "\"~a\"" (string-join (a-val val))))))) |
| 26 | + (string-upcase |
| 27 | + (format "~a~a" |
| 28 | + (string-replace |
| 29 | + (if (equal? 'contract 'boolean?) |
| 30 | + (string-trim (symbol->string 'a) "?" #:left? #f) |
| 31 | + (symbol->string 'a)) |
| 32 | + "-" "_") |
| 33 | + (if (equal? arch 'any) |
| 34 | + "" |
| 35 | + (string-append "__" (symbol->string arch))))) |
| 36 | + (cond |
| 37 | + [(equal? 'contract 'string?) |
| 38 | + (if 'array/quote |
| 39 | + (~v (a-val val)) |
| 40 | + (a-val val))] |
| 41 | + [(equal? 'contract 'boolean?) |
| 42 | + (boolean->exact-nonnegative-integer (a-val val))] |
| 43 | + [(equal? 'contract 'exact-nonnegative-integer?) |
| 44 | + (a-val val)] |
| 45 | + [(equal? 'contract '(listof string?)) |
| 46 | + (if 'array/quote |
| 47 | + (format "(~a)" (string-join (map ~v (a-val val)))) |
| 48 | + (format "\"~a\"" (string-join (a-val val))))]))) |
27 | 49 | ))]
|
28 | 50 | [(_ array contract a b ...)
|
29 | 51 | #'(begin
|
|
0 commit comments