Skip to content

Commit c2408ed

Browse files
committed
feat(macros): play MORE
Signed-off-by: Kaiyang Wu <[email protected]>
1 parent b955afa commit c2408ed

File tree

3 files changed

+68
-12
lines changed

3 files changed

+68
-12
lines changed

aosc/private/defines.rkt

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#lang racket/base
2+
3+
(require racket/contract
4+
"macro.rkt")
5+
6+
; TODO: limit abtype and abhost to a set of valid values with contract
7+
(define-vars #f string? pkgname pkgsec abhost abtype)
8+
(define-vars #t string? pkgdes)
9+
(define-vars #f (listof string?)
10+
pkgdep builddep pkgrecom pkgbreak pkgsug pkgconfl pkgrep)
11+
(define-vars #f (listof string?)
12+
autotools-def cmake-def waf-def qtproj-def)
13+
(define-vars #t (listof string?)
14+
autotools-after cmake-after waf-after qtproj-after go-build-after
15+
cargo-after)
16+
(define-vars #f boolean?
17+
ab-flags-o3 ab-flags-specs ab-flags-ssp ab-flags-ftf ab-flags-rro
18+
nolto useclang ab-flags-pie ab-flags-pic abshadow abconfighack
19+
abclean noparallel abstrip absplitdbg)
20+
(define-vars #f boolean? reconf nopython2 nopython3)
21+
(define-vars #f exact-nonnegative-integer?
22+
abthreads)
23+
24+
(struct defines-type (opts) #:transparent)
25+
26+
(define/contract (defines opts)
27+
(-> (listof pair?) defines-type?)
28+
;; TODO: checks here
29+
(defines-type opts))
30+
31+
(define/contract (defines->string defines)
32+
(-> defines-type? string?)
33+
;; TODO: ->string here, apply ->string to each opt
34+
"")

aosc/private/macro.rkt

+33-11
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,49 @@
33
(require racket/contract
44
racket/format
55
racket/string
6+
"arch.rkt"
7+
"utils.rkt"
68
(for-syntax racket/base
79
racket/syntax))
810

911
(define-syntax (define-vars stx)
1012
(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)]
1419
[a? (format-id #'a "~a?" #'a)]
1520
[a->string (format-id #'a "~a->string" #'a)] )
1621
#`(begin
1722
(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?)
2025
(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))))])))
2749
))]
2850
[(_ array contract a b ...)
2951
#'(begin

aosc/private/utils.rkt

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
(->* (string? any/c) (boolean? arch?) string?)
2020
(string-append entry-name
2121
(if (equal? arch 'any)
22-
""
22+
""
2323
(string-append "__" (string-upcase (symbol->string arch))))
2424
(if quote? "=\"" "=")
2525
(~a value)

0 commit comments

Comments
 (0)