+struct block_hooks {
+ U32 bhk_flags;
+ void (*bhk_start) (pTHX_ int full);
+ void (*bhk_pre_end) (pTHX_ OP **seq);
+ void (*bhk_post_end) (pTHX_ OP **seq);
+ void (*bhk_eval) (pTHX_ OP *const saveop);
+};
+
+/*
+=head1 Compile-time scope hooks
+
+=for apidoc mx|U32|BhkFLAGS|BHK *hk
+Return the BHK's flags.
+
+=for apidoc mx|void *|BhkENTRY|BHK *hk|which
+Return an entry from the BHK structure. I<which> is a preprocessor token
+indicating which entry to return. If the appropriate flag is not set
+this will return NULL. The type of the return value depends on which
+entry you ask for.
+
+=for apidoc Amx|void|BhkENTRY_set|BHK *hk|which|void *ptr
+Set an entry in the BHK structure, and set the flags to indicate it is
+valid. I<which> is a preprocessing token indicating which entry to set.
+The type of I<ptr> depends on the entry.
+
+=for apidoc Amx|void|BhkDISABLE|BHK *hk|which
+Temporarily disable an entry in this BHK structure, by clearing the
+appropriate flag. I<which> is a preprocessor token indicating which
+entry to disable.
+
+=for apidoc Amx|void|BhkENABLE|BHK *hk|which
+Re-enable an entry in this BHK structure, by setting the appropriate
+flag. I<which> is a preprocessor token indicating which entry to enable.
+This will assert (under -DDEBUGGING) if the entry doesn't contain a valid
+pointer.
+
+=for apidoc mx|void|CALL_BLOCK_HOOKS|which|arg
+Call all the registered block hooks for type I<which>. I<which> is a
+preprocessing token; the type of I<arg> depends on I<which>.
+
+=cut
+*/
+
+#define BhkFLAGS(hk) ((hk)->bhk_flags)
+
+#define BHKf_bhk_start 0x01
+#define BHKf_bhk_pre_end 0x02
+#define BHKf_bhk_post_end 0x04
+#define BHKf_bhk_eval 0x08
+
+#define BhkENTRY(hk, which) \
+ ((BhkFLAGS(hk) & BHKf_ ## which) ? ((hk)->which) : NULL)
+
+#define BhkENABLE(hk, which) \
+ STMT_START { \
+ BhkFLAGS(hk) |= BHKf_ ## which; \
+ assert(BhkENTRY(hk, which)); \
+ } STMT_END
+
+#define BhkDISABLE(hk, which) \
+ STMT_START { \
+ BhkFLAGS(hk) &= ~(BHKf_ ## which); \
+ } STMT_END
+
+#define BhkENTRY_set(hk, which, ptr) \
+ STMT_START { \
+ (hk)->which = ptr; \
+ BhkENABLE(hk, which); \
+ } STMT_END
+
+#define CALL_BLOCK_HOOKS(which, arg) \
+ STMT_START { \
+ if (PL_blockhooks) { \
+ I32 i; \
+ for (i = av_len(PL_blockhooks); i >= 0; i--) { \
+ SV *sv = AvARRAY(PL_blockhooks)[i]; \
+ BHK *hk; \
+ \
+ assert(SvIOK(sv)); \
+ if (SvUOK(sv)) \
+ hk = INT2PTR(BHK *, SvUVX(sv)); \
+ else \
+ hk = INT2PTR(BHK *, SvIVX(sv)); \
+ \
+ if (BhkENTRY(hk, which)) \
+ BhkENTRY(hk, which)(aTHX_ arg); \
+ } \
+ } \
+ } STMT_END
+
+/* flags for rv2cv_op_cv */
+
+#define RV2CVOPCV_MARK_EARLY 0x00000001
+#define RV2CVOPCV_RETURN_NAME_GV 0x00000002
+
+/*
+=head1 Custom Operators
+
+=for apidoc Am|U32|XopFLAGS|XOP *xop
+Return the XOP's flags.
+
+=for apidoc Am||XopENTRY|XOP *xop|which
+Return a member of the XOP structure. I<which> is a cpp token indicating
+which entry to return. If the member is not set this will return a
+default value. The return type depends on I<which>.
+
+=for apidoc Am|void|XopENTRY_set|XOP *xop|which|value
+Set a member of the XOP structure. I<which> is a cpp token indicating
+which entry to set. See L<perlguts/"Custom Operators"> for details about
+the available members and how they are used.
+
+=for apidoc Am|void|XopDISABLE|XOP *xop|which
+Temporarily disable a member of the XOP, by clearing the appropriate flag.
+
+=for apidoc Am|void|XopENABLE|XOP *xop|which
+Reenable a member of the XOP which has been disabled.
+
+=cut
+*/
+
+struct custom_op {
+ U32 xop_flags;
+ const char *xop_name;
+ const char *xop_desc;
+ U32 xop_class;
+ void (*xop_peep)(pTHX_ OP *o, OP *oldop);
+};
+
+#define XopFLAGS(xop) ((xop)->xop_flags)
+
+#define XOPf_xop_name 0x01
+#define XOPf_xop_desc 0x02
+#define XOPf_xop_class 0x04
+#define XOPf_xop_peep 0x08
+
+#define XOPd_xop_name PL_op_name[OP_CUSTOM]
+#define XOPd_xop_desc PL_op_desc[OP_CUSTOM]
+#define XOPd_xop_class OA_BASEOP
+#define XOPd_xop_peep ((Perl_cpeep_t)0)
+
+#define XopENTRY_set(xop, which, to) \
+ STMT_START { \
+ (xop)->which = (to); \
+ (xop)->xop_flags |= XOPf_ ## which; \
+ } STMT_END
+
+#define XopENTRY(xop, which) \
+ ((XopFLAGS(xop) & XOPf_ ## which) ? (xop)->which : XOPd_ ## which)
+
+#define XopDISABLE(xop, which) ((xop)->xop_flags &= ~XOPf_ ## which)
+#define XopENABLE(xop, which) \
+ STMT_START { \
+ (xop)->xop_flags |= XOPf_ ## which; \
+ assert(XopENTRY(xop, which)); \
+ } STMT_END
+
+/*
+=head1 Optree Manipulation Functions
+
+=for apidoc Am|const char *|OP_NAME|OP *o
+Return the name of the provided OP. For core ops this looks up the name
+from the op_type; for custom ops from the op_ppaddr.
+
+=for apidoc Am|const char *|OP_DESC|OP *o
+Return a short description of the provided OP.
+
+=for apidoc Am|U32|OP_CLASS|OP *o
+Return the class of the provided OP: that is, which of the *OP
+structures it uses. For core ops this currently gets the information out
+of PL_opargs, which does not always accurately reflect the type used.
+For custom ops the type is returned from the registration, and it is up
+to the registree to ensure it is accurate. The value returned will be
+one of the OA_* constants from op.h.
+
+=cut
+*/
+
+#define OP_NAME(o) ((o)->op_type == OP_CUSTOM \
+ ? XopENTRY(Perl_custom_op_xop(aTHX_ o), xop_name) \
+ : PL_op_name[(o)->op_type])
+#define OP_DESC(o) ((o)->op_type == OP_CUSTOM \
+ ? XopENTRY(Perl_custom_op_xop(aTHX_ o), xop_desc) \
+ : PL_op_desc[(o)->op_type])
+#define OP_CLASS(o) ((o)->op_type == OP_CUSTOM \
+ ? XopENTRY(Perl_custom_op_xop(aTHX_ o), xop_class) \
+ : (PL_opargs[(o)->op_type] & OA_CLASS_MASK))
+
+#define newSUB(f, o, p, b) Perl_newATTRSUB(aTHX_ (f), (o), (p), NULL, (b))
+