| 1 |
/* You may distribute under the terms of either the GNU General Public License |
| 2 |
* or the Artistic License (the same terms as Perl itself) |
| 3 |
* |
| 4 |
* (C) Paul Evans, 2021-2024 -- [email protected] |
| 5 |
*/ |
| 6 |
|
| 7 |
#define PERL_NO_GET_CONTEXT |
| 8 |
|
| 9 |
#include "EXTERN.h" |
| 10 |
#include "perl.h" |
| 11 |
#include "XSUB.h" |
| 12 |
|
| 13 |
#include "XSParseKeyword.h" |
| 14 |
#include "XSParseInfix.h" |
| 15 |
|
| 16 |
#include "keyword.h" |
| 17 |
#include "infix.h" |
| 18 |
|
| 19 |
/* v1 hooks.newop did not pass parsedata */ |
| 20 |
struct XSParseInfixHooks_v1 { |
| 21 |
U16 flags; |
| 22 |
U8 lhs_flags, rhs_flags; |
| 23 |
enum XSParseInfixClassification cls; |
| 24 |
|
| 25 |
const char *wrapper_func_name; |
| 26 |
|
| 27 |
const char *permit_hintkey; |
| 28 |
bool (*permit) (pTHX_ void *hookdata); |
| 29 |
|
| 30 |
OP *(*new_op)(pTHX_ U32 flags, OP *lhs, OP *rhs, void *hookdata); |
| 31 |
OP *(*ppaddr)(pTHX); |
| 32 |
|
| 33 |
OP *(*parse_rhs)(pTHX_ void *hookdata); |
| 34 |
}; |
| 35 |
|
| 36 |
static void XSParseInfix_register_v1(pTHX_ const char *opname, const struct XSParseInfixHooks_v1 *hooks_v1, void *hookdata) |
| 37 |
{ |
| 38 |
if(hooks_v1->rhs_flags & (1 << 7) /* was XPI_OPERAND_CUSTOM */) |
| 39 |
croak("XPI_OPERAND_CUSTOM is no longer supported"); |
| 40 |
if(hooks_v1->parse_rhs) |
| 41 |
croak("XSParseInfixHooks.parse_rhs is no longer supported"); |
| 42 |
|
| 43 |
struct XSParseInfixHooks *hooks; |
| 44 |
Newx(hooks, 1, struct XSParseInfixHooks); |
| 45 |
|
| 46 |
hooks->flags = hooks_v1->flags | (1<<15) /* NO_PARSEDATA */; |
| 47 |
hooks->lhs_flags = hooks_v1->lhs_flags; |
| 48 |
hooks->rhs_flags = hooks_v1->rhs_flags; |
| 49 |
hooks->cls = hooks_v1->cls; |
| 50 |
|
| 51 |
hooks->wrapper_func_name = hooks_v1->wrapper_func_name; |
| 52 |
|
| 53 |
hooks->permit_hintkey = hooks_v1->permit_hintkey; |
| 54 |
hooks->permit = hooks_v1->permit; |
| 55 |
hooks->new_op = (OP *(*)(pTHX_ U32, OP *, OP *, SV **, void *))hooks_v1->new_op; |
| 56 |
hooks->ppaddr = hooks_v1->ppaddr; |
| 57 |
hooks->parse = NULL; |
| 58 |
|
| 59 |
XSParseInfix_register(aTHX_ opname, hooks, hookdata); |
| 60 |
} |
| 61 |
|
| 62 |
MODULE = XS::Parse::Keyword PACKAGE = XS::Parse::Infix |
| 63 |
|
| 64 |
bool check_opname(SV *opname) |
| 65 |
CODE: |
| 66 |
{ |
| 67 |
STRLEN namelen; |
| 68 |
const char *namepv = SvPV(opname, namelen); |
| 69 |
RETVAL = XSParseInfix_check_opname(aTHX_ namepv, namelen); |
| 70 |
} |
| 71 |
OUTPUT: |
| 72 |
RETVAL |
| 73 |
|
| 74 |
MODULE = XS::Parse::Keyword PACKAGE = XS::Parse::Keyword |
| 75 |
|
| 76 |
BOOT: |
| 77 |
/* legacy version0 support */ |
| 78 |
sv_setiv(*hv_fetchs(PL_modglobal, "XS::Parse::Keyword/ABIVERSION", 1), XSPARSEKEYWORD_ABI_VERSION); |
| 79 |
|
| 80 |
/* newer versions */ |
| 81 |
sv_setiv(*hv_fetchs(PL_modglobal, "XS::Parse::Keyword/ABIVERSION_MIN", 1), 1); |
| 82 |
sv_setiv(*hv_fetchs(PL_modglobal, "XS::Parse::Keyword/ABIVERSION_MAX", 1), XSPARSEKEYWORD_ABI_VERSION); |
| 83 |
|
| 84 |
sv_setuv(*hv_fetchs(PL_modglobal, "XS::Parse::Keyword/register()@1", 1), PTR2UV(&XSParseKeyword_register_v1)); |
| 85 |
sv_setuv(*hv_fetchs(PL_modglobal, "XS::Parse::Keyword/register()@2", 1), PTR2UV(&XSParseKeyword_register_v2)); |
| 86 |
|
| 87 |
XSParseKeyword_boot(aTHX); |
| 88 |
|
| 89 |
|
| 90 |
sv_setiv(*hv_fetchs(PL_modglobal, "XS::Parse::Infix/ABIVERSION_MIN", 1), 1); |
| 91 |
sv_setiv(*hv_fetchs(PL_modglobal, "XS::Parse::Infix/ABIVERSION_MAX", 1), XSPARSEINFIX_ABI_VERSION); |
| 92 |
|
| 93 |
sv_setuv(*hv_fetchs(PL_modglobal, "XS::Parse::Infix/parse()@2", 1), PTR2UV(&XSParseInfix_parse)); |
| 94 |
sv_setuv(*hv_fetchs(PL_modglobal, "XS::Parse::Infix/new_op()@0", 1), PTR2UV(&XSParseInfix_new_op)); |
| 95 |
sv_setuv(*hv_fetchs(PL_modglobal, "XS::Parse::Infix/register()@1", 1), PTR2UV(&XSParseInfix_register_v1)); |
| 96 |
sv_setuv(*hv_fetchs(PL_modglobal, "XS::Parse::Infix/register()@2", 1), PTR2UV(&XSParseInfix_register)); |
| 97 |
|
| 98 |
XSParseInfix_boot(aTHX); |