| 1 |
|
| #pragma once |
| 2 |
|
| #include "base.h" |
| 3 |
|
| #include <panda/expected.h> |
| 4 |
|
| #include <panda/excepted.h> |
| 5 |
|
| |
| 6 |
|
| #define XSRETURN_EXPECTED(val) do { xs::expected_to_stack(val, MARK, ax); return; } while (0) |
| 7 |
|
| |
| 8 |
|
| #ifndef PERL_STACK_OFFSET_DEFINED |
| 9 |
|
| typedef I32 Stack_off_t; |
| 10 |
|
| # define Stack_off_t_MAX I32_MAX |
| 11 |
|
| # define PERL_STACK_OFFSET_DEFINED |
| 12 |
|
| #endif |
| 13 |
|
| |
| 14 |
|
| namespace xs { |
| 15 |
|
| |
| 16 |
|
| template <class T> |
| 17 |
16 |
| void _expected_to_stack (const T& ret, SV**& sp, Stack_off_t& ax, std::false_type) { |
| 18 |
16 |
| auto wcnt = Sub::want_count(); |
| 19 |
16 |
▶ | if (ret) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (ret) { |
4 |
4 |
8 |
| if (ret) { |
4 |
4 |
8 |
|
| 20 |
8 |
▶ | mXPUSHs(xs::out(ret.value()).detach()); |
Branch: 8 branches
| Branch | True | False | Total |
| mXPUSHs(xs::out(ret.value()).detach()); |
0 |
4 |
4 |
| mXPUSHs(xs::out(ret.value()).detach()); |
4 |
0 |
4 |
| mXPUSHs(xs::out(ret.value()).detach()); |
4 |
0 |
4 |
| mXPUSHs(xs::out(ret.value()).detach()); |
4 |
0 |
4 |
| mXPUSHs(xs::out(ret.value()).detach()); |
0 |
4 |
4 |
| mXPUSHs(xs::out(ret.value()).detach()); |
4 |
0 |
4 |
| mXPUSHs(xs::out(ret.value()).detach()); |
4 |
0 |
4 |
| mXPUSHs(xs::out(ret.value()).detach()); |
4 |
0 |
4 |
|
| 21 |
8 |
▶ | if (wcnt == 2) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (wcnt == 2) { |
1 |
3 |
4 |
| if (wcnt == 2) { |
1 |
3 |
4 |
|
| 22 |
2 |
▶ | XPUSHs(&PL_sv_undef); |
Branch: 2 branches
| Branch | True | False | Total |
| XPUSHs(&PL_sv_undef); |
0 |
1 |
1 |
| XPUSHs(&PL_sv_undef); |
0 |
1 |
1 |
|
| 23 |
2 |
| XSRETURN(2); |
| 24 |
|
| } |
| 25 |
6 |
| XSRETURN(1); |
| 26 |
|
| } |
| 27 |
8 |
▶ | if (wcnt != 2) throw ret.error(); |
Branch: 2 branches
| Branch | True | False | Total |
| if (wcnt != 2) throw ret.error(); |
3 |
1 |
4 |
| if (wcnt != 2) throw ret.error(); |
3 |
1 |
4 |
|
| 28 |
2 |
▶ | XPUSHs(&PL_sv_undef); |
Branch: 2 branches
| Branch | True | False | Total |
| XPUSHs(&PL_sv_undef); |
0 |
1 |
1 |
| XPUSHs(&PL_sv_undef); |
0 |
1 |
1 |
|
| 29 |
2 |
▶ | mXPUSHs(xs::out(ret.error()).detach()); |
Branch: 6 branches
| Branch | True | False | Total |
| mXPUSHs(xs::out(ret.error()).detach()); |
0 |
1 |
1 |
| mXPUSHs(xs::out(ret.error()).detach()); |
1 |
0 |
1 |
| mXPUSHs(xs::out(ret.error()).detach()); |
1 |
0 |
1 |
| mXPUSHs(xs::out(ret.error()).detach()); |
0 |
1 |
1 |
| mXPUSHs(xs::out(ret.error()).detach()); |
1 |
0 |
1 |
| mXPUSHs(xs::out(ret.error()).detach()); |
1 |
0 |
1 |
|
| 30 |
2 |
| XSRETURN(2); |
| 31 |
|
| } |
| 32 |
|
| |
| 33 |
|
| template <class T> |
| 34 |
16 |
| void _expected_to_stack (const T& ret, SV**& sp, Stack_off_t& ax, std::true_type) { |
| 35 |
16 |
| auto wcnt = Sub::want_count(); |
| 36 |
16 |
▶ | if (wcnt == 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (wcnt == 0) { |
2 |
6 |
8 |
| if (wcnt == 0) { |
2 |
6 |
8 |
|
| 37 |
4 |
▶ | if (!ret) throw ret.error(); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!ret) throw ret.error(); |
1 |
1 |
2 |
| if (!ret) throw ret.error(); |
1 |
1 |
2 |
|
| 38 |
2 |
| XSRETURN_EMPTY; |
| 39 |
|
| } |
| 40 |
12 |
▶ | XPUSHs(boolSV(ret)); |
Branch: 4 branches
| Branch | True | False | Total |
| XPUSHs(boolSV(ret)); |
0 |
6 |
6 |
| XPUSHs(boolSV(ret)); |
3 |
3 |
6 |
| XPUSHs(boolSV(ret)); |
0 |
6 |
6 |
| XPUSHs(boolSV(ret)); |
3 |
3 |
6 |
|
| 41 |
12 |
▶ | if (wcnt == 2) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (wcnt == 2) { |
2 |
4 |
6 |
| if (wcnt == 2) { |
2 |
4 |
6 |
|
| 42 |
4 |
▶ | if (ret) XPUSHs(&PL_sv_undef); |
Branch: 4 branches
| Branch | True | False | Total |
| if (ret) XPUSHs(&PL_sv_undef); |
1 |
1 |
2 |
| if (ret) XPUSHs(&PL_sv_undef); |
0 |
1 |
1 |
| if (ret) XPUSHs(&PL_sv_undef); |
1 |
1 |
2 |
| if (ret) XPUSHs(&PL_sv_undef); |
0 |
1 |
1 |
|
| 43 |
2 |
▶ | else mXPUSHs(xs::out(ret.error()).detach()); |
Branch: 6 branches
| Branch | True | False | Total |
| else mXPUSHs(xs::out(ret.error()).detach()); |
0 |
1 |
1 |
| else mXPUSHs(xs::out(ret.error()).detach()); |
1 |
0 |
1 |
| else mXPUSHs(xs::out(ret.error()).detach()); |
1 |
0 |
1 |
| else mXPUSHs(xs::out(ret.error()).detach()); |
0 |
1 |
1 |
| else mXPUSHs(xs::out(ret.error()).detach()); |
1 |
0 |
1 |
| else mXPUSHs(xs::out(ret.error()).detach()); |
1 |
0 |
1 |
|
| 44 |
4 |
| XSRETURN(2); |
| 45 |
|
| } |
| 46 |
8 |
| XSRETURN(1); |
| 47 |
|
| } |
| 48 |
|
| |
| 49 |
|
| template <class TYPE, class ERROR> |
| 50 |
16 |
| void expected_to_stack (const panda::excepted<TYPE,ERROR>& ret, SV**& sp, Stack_off_t& ax) { |
| 51 |
16 |
▶ | return _expected_to_stack(ret, sp, ax, std::is_same<void,TYPE>()); |
Branch: 2 branches
| Branch | True | False | Total |
| return _expected_to_stack(ret, sp, ax, std::is_same<void,TYPE>()); |
5 |
3 |
8 |
| return _expected_to_stack(ret, sp, ax, std::is_same<void,TYPE>()); |
7 |
1 |
8 |
|
| 52 |
|
| } |
| 53 |
|
| |
| 54 |
|
| template <class TYPE, class ERROR> |
| 55 |
16 |
| void expected_to_stack (const panda::expected<TYPE,ERROR>& ret, SV**& sp, Stack_off_t& ax) { |
| 56 |
16 |
| return _expected_to_stack(ret, sp, ax, std::is_same<void,TYPE>()); |
| 57 |
|
| } |
| 58 |
|
| |
| 59 |
|
| } |