81 lines
2.5 KiB
Racket
81 lines
2.5 KiB
Racket
(module utils racket/base
|
|
|
|
(require racket/path
|
|
racket/runtime-path
|
|
ffi/unsafe
|
|
setup/dirs
|
|
)
|
|
|
|
(provide while
|
|
until
|
|
build-lib-path
|
|
get-lib
|
|
do-for
|
|
)
|
|
|
|
(define-syntax while
|
|
(syntax-rules ()
|
|
((_ cond body ...)
|
|
(letrec ((while-f (lambda (last-result)
|
|
(if cond
|
|
(let ((last-result (begin
|
|
body
|
|
...)))
|
|
(while-f last-result))
|
|
last-result))))
|
|
(while-f #f))
|
|
)
|
|
))
|
|
|
|
(define-syntax until
|
|
(syntax-rules ()
|
|
((_ cond body ...)
|
|
(letrec ((until-f (lambda (last-result)
|
|
(if cond
|
|
last-result
|
|
(let ((last-reult (begin
|
|
body
|
|
...)))
|
|
(until-f last-result))))))
|
|
(until-f #f)))))
|
|
|
|
(define-syntax do-for
|
|
(syntax-rules ()
|
|
((_ (init cond next) body ...)
|
|
(begin
|
|
init
|
|
(letrec ((do-for-f (lamba ()
|
|
(if cond
|
|
(begin
|
|
(begin
|
|
body
|
|
...)
|
|
next
|
|
(do-for-f))))))
|
|
(do-for-f))))))
|
|
|
|
|
|
(define-runtime-path lib-path "..")
|
|
|
|
(define (build-lib-path)
|
|
(let ((os-type (system-type 'os*)))
|
|
(if (eq? os-type 'windows)
|
|
(build-path lib-path "lib" "dll")
|
|
(let* ((arch (symbol->string (system-type 'arch)))
|
|
(subdir (string-append (symbol->string os-type) "-" arch)))
|
|
(let ((path (build-path lib-path "lib" subdir)))
|
|
path)))))
|
|
|
|
(define (get-lib* libs-to-try orig-libs versions)
|
|
(if (null? libs-to-try)
|
|
(error (format "Cannot find library, tried ~a" orig-libs))
|
|
(ffi-lib (car libs-to-try) versions
|
|
#:get-lib-dirs (λ () (cons (build-lib-path) (get-lib-search-dirs)))
|
|
#:fail (λ () (get-lib* (cdr libs-to-try) orig-libs versions))
|
|
)))
|
|
|
|
(define (get-lib libs-to-try versions)
|
|
(get-lib* libs-to-try libs-to-try versions))
|
|
|
|
) ; end of module
|