Skip to content

Commit

Permalink
Define a PL_infix_plugin hook, of a similar style to PL_keyword_plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
leonerd committed May 4, 2021
1 parent acd998d commit 146d413
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions embed.fnc
Expand Up @@ -3611,6 +3611,8 @@ Apxd |void|cop_store_label \

epo |int |keyword_plugin_standard|NN char* keyword_ptr|STRLEN keyword_len|NN OP** op_ptr

epo |int |infix_plugin_standard|NN char* operator_ptr|STRLEN operator_len|NN struct Perl_custom_infix** def

#if defined(USE_ITHREADS)
# if defined(PERL_IN_SV_C)
S |void |unreferenced_to_tmp_stack|NN AV *const unreferenced
Expand Down
7 changes: 7 additions & 0 deletions perl.h
Expand Up @@ -5599,10 +5599,17 @@ typedef void (*XSINIT_t) (pTHX);
typedef void (*ATEXIT_t) (pTHX_ void*);
typedef void (*XSUBADDR_t) (pTHX_ CV *);

/* TODO: find somewhere to store this */
struct Perl_custom_infix {
/* TODO: a precedence field. for now hardcoded to RELOP only */
OP *(*parse)(pTHX_ OP *lhs);
};

typedef OP* (*Perl_ppaddr_t)(pTHX);
typedef OP* (*Perl_check_t) (pTHX_ OP*);
typedef void(*Perl_ophook_t)(pTHX_ OP*);
typedef int (*Perl_keyword_plugin_t)(pTHX_ char*, STRLEN, OP**);
typedef int (*Perl_infix_plugin_t)(pTHX_ char*, STRLEN, struct Perl_custom_infix **);
typedef void(*Perl_cpeep_t)(pTHX_ OP *, OP *);

typedef void(*globhook_t)(pTHX);
Expand Down
3 changes: 3 additions & 0 deletions perlvars.h
Expand Up @@ -245,6 +245,9 @@ PERLVAR(G, keyword_plugin_mutex, perl_mutex) /* Mutex for PL_keyword_plugin */
#endif
PERLVARI(G, keyword_plugin, Perl_keyword_plugin_t, Perl_keyword_plugin_standard)

/* TODO: a mutex */
PERLVARI(G, infix_plugin, Perl_infix_plugin_t, Perl_infix_plugin_standard)

PERLVARI(G, op_sequence, HV *, NULL) /* dump.c */
PERLVARI(G, op_seq, UV, 0) /* dump.c */

Expand Down
3 changes: 3 additions & 0 deletions proto.h
Expand Up @@ -1581,6 +1581,9 @@ PERL_CALLCONV void Perl_hv_undef_flags(pTHX_ HV *hv, U32 flags);

/* PERL_CALLCONV I32 ibcmp_utf8(pTHX_ const char *s1, char **pe1, UV l1, bool u1, const char *s2, char **pe2, UV l2, bool u2); */
#define PERL_ARGS_ASSERT_IBCMP_UTF8
PERL_CALLCONV int Perl_infix_plugin_standard(pTHX_ char* operator_ptr, STRLEN operator_len, struct Perl_custom_infix** def);
#define PERL_ARGS_ASSERT_INFIX_PLUGIN_STANDARD \
assert(operator_ptr); assert(def)
PERL_CALLCONV void Perl_init_argv_symbols(pTHX_ int argc, char **argv);
#define PERL_ARGS_ASSERT_INIT_ARGV_SYMBOLS \
assert(argv)
Expand Down
12 changes: 12 additions & 0 deletions toke.c
Expand Up @@ -12801,6 +12801,18 @@ Perl_keyword_plugin_standard(pTHX_
return KEYWORD_PLUGIN_DECLINE;
}

int
Perl_infix_plugin_standard(pTHX_
char *operator_ptr, STRLEN operator_len, struct Perl_custom_infix **def)
{
PERL_ARGS_ASSERT_INFIX_PLUGIN_STANDARD;
PERL_UNUSED_CONTEXT;
PERL_UNUSED_ARG(operator_ptr);
PERL_UNUSED_ARG(operator_len);
PERL_UNUSED_ARG(def);
return 0;
}

/*
=for apidoc wrap_keyword_plugin
Expand Down

0 comments on commit 146d413

Please sign in to comment.