-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathdefinitions.jl
51 lines (46 loc) · 1.77 KB
/
definitions.jl
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# TODO: https://github.com/JuliaLang/julia/issues/29420
const DEFAULT_EXTRA_DEFINITIONS = Dict{Symbol,AbstractJuliaType}(
:ssize_t => JuliaCssize_t(),
:size_t => JuliaCsize_t(),
:ptrdiff_t => JuliaCptrdiff_t(),
:uint64_t => JuliaCuint64_t(),
:uint32_t => JuliaCuint32_t(),
:uint16_t => JuliaCuint16_t(),
:uint8_t => JuliaCuint8_t(),
:int64_t => JuliaCint64_t(),
:int32_t => JuliaCint32_t(),
:int16_t => JuliaCint16_t(),
:int8_t => JuliaCint8_t(),
:uintptr_t => JuliaCuintptr_t(),
:wchar_t => JuliaCwchar_t(),
:va_list => JuliaUnsupported(),
:FILE => JuliaCFILE(),
:__uint64_t => JuliaCuint64_t(),
:__uint32_t => JuliaCuint32_t(),
:__uint16_t => JuliaCuint16_t(),
:__uint8_t => JuliaCuint8_t(),
:__int64_t => JuliaCint64_t(),
:__int32_t => JuliaCint32_t(),
:__int16_t => JuliaCint16_t(),
:__int8_t => JuliaCint8_t(),
)
const EXTRA_DEFINITIONS = Dict{Symbol,AbstractJuliaType}()
add_definition(x::Dict{Symbol,<:AbstractJuliaType}) = merge!(EXTRA_DEFINITIONS, x)
add_definition(x::Pair{Symbol,<:AbstractJuliaType}) = push!(EXTRA_DEFINITIONS, x)
get_definition() = EXTRA_DEFINITIONS
function reset_definition()
empty!(EXTRA_DEFINITIONS)
merge!(EXTRA_DEFINITIONS, DEFAULT_EXTRA_DEFINITIONS)
end
macro add_def(c_symbol::Symbol, type::Symbol=:AbstractJuliaSIT, typename::Symbol=c_symbol, translated::Symbol=c_symbol)
arg1 = Expr(:(::), typename)
arg2 = Expr(:kw, :options, :(Dict()))
sig = Expr(:call, Expr(:., :Generators, QuoteNode(:translate)), arg1, arg2)
func = Expr(:(=), sig, Expr(:block, QuoteNode(:($translated))))
ret = quote
struct $typename <: $type end
add_definition($(QuoteNode(c_symbol)) => $(esc(typename))())
$(esc(func))
end
return ret
end