2024-09-23 11:43:05 +00:00
|
|
|
(import (scheme)
|
|
|
|
(chicken base)
|
2024-09-28 00:46:33 +00:00
|
|
|
(chicken bitwise)
|
2024-09-24 14:55:41 +00:00
|
|
|
(chicken syntax)
|
|
|
|
(srfi 152))
|
2024-09-23 11:43:05 +00:00
|
|
|
|
|
|
|
(define (snake-upcase in)
|
|
|
|
(string-map (lambda (c)
|
|
|
|
(if (char=? #\- c)
|
|
|
|
#\_
|
2024-09-24 14:55:41 +00:00
|
|
|
(char-upcase c)))
|
|
|
|
in))
|
2024-09-23 11:43:05 +00:00
|
|
|
|
2024-09-28 00:46:33 +00:00
|
|
|
(define-syntax define-sdl-const-values
|
2024-09-23 11:43:05 +00:00
|
|
|
(er-macro-transformer
|
|
|
|
(lambda (exp rename compare)
|
|
|
|
(let ((prefix (cadr exp))
|
|
|
|
(type (caddr exp))
|
|
|
|
(enum-labels (cdddr exp)))
|
|
|
|
`(begin
|
|
|
|
,@(map (lambda (enum-label)
|
|
|
|
(let ((full-str (string-append (symbol->string prefix)
|
|
|
|
"-" (symbol->string enum-label))))
|
|
|
|
`(begin
|
|
|
|
(export ,(string->symbol full-str))
|
|
|
|
(define ,(string->symbol full-str)
|
|
|
|
(foreign-value
|
|
|
|
,(string-append "SDL_" (snake-upcase full-str))
|
|
|
|
,type)))))
|
|
|
|
enum-labels))))))
|
2024-09-28 00:46:33 +00:00
|
|
|
|
|
|
|
(define (foldl-uint-flags flags)
|
|
|
|
(foldl bitwise-ior (car flags) (cdr flags)))
|
2024-10-08 15:17:35 +00:00
|
|
|
|
|
|
|
(define-syntax call-c*
|
|
|
|
(er-macro-transformer
|
|
|
|
(lambda (exp rename compare)
|
|
|
|
(let ((return-type (list-ref exp 1))
|
|
|
|
(proc (list-ref exp 2))
|
|
|
|
(args (list-ref exp 3))
|
|
|
|
(callbody (list-ref exp 4))
|
|
|
|
(callbody-args (list-ref exp 5)))
|
|
|
|
`((foreign-lambda* ,return-type
|
|
|
|
,args
|
|
|
|
,(apply format #f callbody
|
|
|
|
(symbol->string proc)
|
|
|
|
(map (compose symbol->string cadr) args)
|
|
|
|
callbody-args))
|
|
|
|
,@(map cadr args))))))
|
|
|
|
|
|
|
|
(define-syntax call-c
|
|
|
|
(syntax-rules (void)
|
|
|
|
|
|
|
|
((_ void proc (args ...))
|
|
|
|
(call-c* void proc (args ...)
|
|
|
|
"~A(~{~^, ~};" ()))
|
|
|
|
((_ return-type proc (args ...))
|
|
|
|
(call-c* return-type proc (args ...)
|
|
|
|
"C_return(~A(~{~^, ~}));"))))
|