-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCxx-Types.rkt
31 lines (27 loc) · 1.02 KB
/
Cxx-Types.rkt
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
#lang racket
(require "FFI-Bindings.rkt"
(for-syntax
json
syntax/location))
(define-for-syntax known-cxx-types null)
(define-syntax (emit-type-table stx)
(syntax-case stx ()
[(_ json-datafile)
(call-with-input-file
(build-path (syntax-source-directory stx)
(syntax->datum #'json-datafile))
(lambda (json-port)
(letrec ([data (read-json json-port)]
[symbolize
(lambda (maybe-l)
(cond
[(list? maybe-l) (map symbolize maybe-l)]
[(string? maybe-l) (string->symbol maybe-l)]
[else maybe-l]))])
(with-syntax
([((cxx-types (cxx-bases ...)) ...) (map (lambda (datum)
(datum->syntax stx datum)) (symbolize data))])
#`(begin
(define-c++pointer-type cxx-types cxx-bases ...) ...)))))]))
(emit-type-table "casts_table.json")
(provide (all-defined-out))