line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#pragma once |
2
|
|
|
|
|
|
|
#include "base.h" |
3
|
|
|
|
|
|
|
#include "../Ref.h" |
4
|
|
|
|
|
|
|
#include "../Sub.h" |
5
|
|
|
|
|
|
|
#include "../Hash.h" |
6
|
|
|
|
|
|
|
#include "../Glob.h" |
7
|
|
|
|
|
|
|
#include "../Stash.h" |
8
|
|
|
|
|
|
|
#include "../Array.h" |
9
|
|
|
|
|
|
|
#include "../Object.h" |
10
|
|
|
|
|
|
|
#include "../Simple.h" |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
namespace xs { |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
template <> struct Typemap : TypemapBase { |
15
|
|
|
|
|
|
|
static inline AV* in (SV* arg) { |
16
|
|
|
|
|
|
|
if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVAV) return (AV*)SvRV(arg); |
17
|
|
|
|
|
|
|
else if (SvOK(arg)) throw "argument is not an ARRAY reference"; |
18
|
|
|
|
|
|
|
return nullptr; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
static inline Sv out (AV* var, const Sv& = Sv()) { |
21
|
|
|
|
|
|
|
if (!var) return &PL_sv_undef; |
22
|
|
|
|
|
|
|
return Sv::noinc(newRV_noinc((SV*)var)); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
}; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
template <> struct Typemap : TypemapBase { |
27
|
|
|
|
|
|
|
static inline HV* in (SV* arg) { |
28
|
|
|
|
|
|
|
if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVHV) return (HV*)SvRV(arg); |
29
|
|
|
|
|
|
|
else if (SvOK(arg)) throw "argument is not a HASH reference"; |
30
|
|
|
|
|
|
|
return nullptr; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
static inline Sv out (HV* var, const Sv& = Sv()) { |
33
|
|
|
|
|
|
|
if (!var) return &PL_sv_undef; |
34
|
|
|
|
|
|
|
return Sv::noinc(newRV_noinc((SV*)var)); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
}; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
template <> struct Typemap : TypemapBase { |
39
|
|
|
|
|
|
|
static inline CV* in (SV* arg) { |
40
|
|
|
|
|
|
|
if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVCV) return (CV*)SvRV(arg); |
41
|
|
|
|
|
|
|
else if (SvOK(arg)) throw "argument is not a CODE reference"; |
42
|
|
|
|
|
|
|
return nullptr; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
static inline Sv out (CV* var, const Sv& = Sv()) { |
45
|
|
|
|
|
|
|
if (!var) return &PL_sv_undef; |
46
|
|
|
|
|
|
|
return Sv::noinc(newRV_noinc((SV*)var)); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
}; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
template <> struct Typemap : TypemapBase { |
51
|
|
|
|
|
|
|
static inline IO* in (SV* arg) { |
52
|
|
|
|
|
|
|
if (SvROK(arg)) { |
53
|
|
|
|
|
|
|
SV* val = SvRV(arg); |
54
|
|
|
|
|
|
|
if (SvTYPE(val) == SVt_PVIO) return (IO*)val; |
55
|
|
|
|
|
|
|
if (SvTYPE(val) == SVt_PVGV && GvIOp(val)) return GvIOp(val); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
else if (SvTYPE(arg) == SVt_PVGV && GvIOp(arg)) return GvIOp(arg); |
58
|
|
|
|
|
|
|
if (!SvOK(arg)) return nullptr; |
59
|
|
|
|
|
|
|
throw "argument is neither IO reference, nor glob or reference to glob containing IO slot)"; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
static inline Sv out (IO* var, const Sv& = Sv()) { |
63
|
|
|
|
|
|
|
if (!var) return &PL_sv_undef; |
64
|
|
|
|
|
|
|
return Sv::noinc(newRV_noinc((SV*)var)); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
}; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
template <> struct Typemap : TypemapBase { |
69
|
|
|
|
|
|
|
static inline GV* in (SV* arg) { |
70
|
|
|
|
|
|
|
if (SvTYPE(arg) == SVt_PVGV) return (GV*)arg; |
71
|
|
|
|
|
|
|
else if (SvOK(arg)) throw "argument is not a GLOB"; |
72
|
|
|
|
|
|
|
return nullptr; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
static inline Sv out (GV* var, const Sv& = Sv()) { |
75
|
|
|
|
|
|
|
if (!var) return &PL_sv_undef; |
76
|
|
|
|
|
|
|
return Sv::noinc((SV*)var); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
}; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
template struct Typemap : TypemapBase { |
82
|
|
|
|
|
|
|
static inline TYPE in (SV* arg) { return arg; } |
83
|
|
|
|
|
|
|
static inline Sv out (const TYPE& var, const Sv& = Sv()) { |
84
|
|
|
|
|
|
|
if (!var) return &PL_sv_undef; |
85
|
|
|
|
|
|
|
return var; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
}; |
88
|
|
|
|
|
|
|
template <> struct Typemap : Typemap {}; |
89
|
|
|
|
|
|
|
template <> struct Typemap : Typemap {}; |
90
|
|
|
|
|
|
|
template <> struct Typemap[ : Typemap {}; ] |
91
|
|
|
|
|
|
|
template <> struct Typemap : Typemap {}; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
template struct Typemap : TypemapBase { |
94
|
14
|
|
|
|
|
|
static inline TYPE in (SV* arg) { return arg; } |
95
|
|
|
|
|
|
|
static inline Sv out (const TYPE& var, const Sv& = Sv()) { |
96
|
|
|
|
|
|
|
if (!var) return &PL_sv_undef; |
97
|
|
|
|
|
|
|
return Ref::create(var); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
}; |
100
|
|
|
|
|
|
|
template <> struct Typemap : Typemap {}; |
101
|
|
|
|
|
|
|
template <> struct Typemap : Typemap {}; |
102
|
|
|
|
|
|
|
template <> struct Typemap : Typemap {}; |
103
|
|
|
|
|
|
|
template <> struct Typemap : Typemap {}; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
template <> struct Typemap |
106
|
|
|
|
|
|
|
static inline Object in (SV* arg) { return arg; } |
107
|
|
|
|
|
|
|
static inline Sv out (const Object& var, const Sv& = Sv()) { |
108
|
|
|
|
|
|
|
if (!var) return &PL_sv_undef; |
109
|
|
|
|
|
|
|
return var.ref(); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
}; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
} |