cop.h revision 7c478bd95313f5f23a4c958a745db2134aa03244
/* cop.h
*
* Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
* 2000, 2001, 2002, 2003, 2004, by Larry Wall and others
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
* Control ops (cops) are one of the three ops OP_NEXTSTATE, OP_DBSTATE,
* and OP_SETSTATE that (loosely speaking) are separate statements.
* They hold information important for lexical state and error reporting.
* At run time, PL_curcop is set to point to the most recently executed cop,
* and thus can be used to determine our current state.
*/
struct cop {
char * cop_label; /* label for this construct */
#ifdef USE_ITHREADS
char * cop_stashpv; /* package line was compiled in */
char * cop_file; /* file name the following line # is from */
#else
#endif
};
#ifdef USE_ITHREADS
# ifdef NETWARE
# else
# endif
# define CopSTASHPV(c) ((c)->cop_stashpv)
# ifdef NETWARE
# else
# endif
# define CopSTASH(c) (CopSTASHPV(c) \
# ifdef NETWARE
# define CopSTASH_free(c) SAVECOPSTASH_FREE(c)
# else
# endif
# ifdef NETWARE
# define CopFILE_free(c) SAVECOPFILE_FREE(c)
# else
# endif
#else
# define CopFILEGV(c) ((c)->cop_filegv)
/* cop_stash is not refcounted */
# define CopSTASH_free(c)
#endif /* USE_ITHREADS */
#define CopLINE_inc(c) (++CopLINE(c))
#define CopLINE_dec(c) (--CopLINE(c))
#define CopLINE_set(c,l) (CopLINE(c) = (l))
/* OutCopFILE() is CopFILE for output (caller, die, warn, etc.) */
#ifdef MACOS_TRADITIONAL
#else
# define OutCopFILE(c) CopFILE(c)
#endif
/*
* Here we have some enormously heavy (or at least ponderous) wizardry.
*/
/* subroutine context */
struct block_sub {
#ifndef USE_5005THREADS
#endif /* USE_5005THREADS */
long olddepth;
};
/* base for the next two macros. Don't use directly.
* Note that the refcnt of the cv is incremented twice; The CX one is
* decremented by LEAVESUB, the other by LEAVE. */
#define PUSHSUB_BASE(cx) \
(void)SvREFCNT_inc(cv); \
(void)SvREFCNT_inc(cv); \
SAVEFREESV(cv); \
}
PUSHSUB_BASE(cx) \
/* variant for use by OP_DBSTATE, where op_private holds hint bits */
#define PUSHSUB_DB(cx) \
PUSHSUB_BASE(cx) \
#define PUSHFORMAT(cx) \
#ifdef USE_5005THREADS
# define POP_SAVEARRAY() NOOP
#else
# define POP_SAVEARRAY() \
STMT_START { \
} STMT_END
#endif /* USE_5005THREADS */
/* junk in @_ spells trouble when cloning CVs and in pp_caller(), so don't
* leave any (a fast av_clear(ary), basically) */
#define CLEAR_ARGARRAY(ary) \
STMT_START { \
} STMT_END
STMT_START { \
POP_SAVEARRAY(); \
/* abandon @_ if it got reified */ \
} \
else { \
} \
} \
} STMT_END
STMT_START { \
if (sv) \
SvREFCNT_dec(sv); \
} STMT_END
/* eval context */
struct block_eval {
SV * old_namesv;
OP * old_eval_root;
};
STMT_START { \
} STMT_END
STMT_START { \
} STMT_END
/* loop context */
struct block_loop {
char * label;
#ifdef USE_ITHREADS
void * iterdata;
#else
#endif
};
#ifdef USE_ITHREADS
# define CxITERVAR(c) \
? &CX_CURPAD_SV( (c)->blk_loop, \
else \
#else
else \
#endif
sv_2mortal(*s_v_p); \
} \
/* context common to subroutines, evals and loops */
struct block {
union {
struct block_eval blku_eval;
struct block_loop blku_loop;
} blk_u;
};
/* Enter a block. */
/* Exit a block (RETURN and LAST). */
DEBUG_SCOPE("POPBLOCK"); \
/* Continue a block elsewhere (NEXT and REDO). */
DEBUG_SCOPE("TOPBLOCK");
/* substitution context */
struct subst {
bool sbu_once;
bool sbu_rxtainted;
char * sbu_orig;
char * sbu_s;
char * sbu_m;
char * sbu_strend;
void * sbu_rxres;
};
struct context {
union {
} cx_u;
};
#define CXTYPEMASK 0xff
#define CXt_NULL 0
#define CXt_SUB 1
#define CXt_EVAL 2
#define CXt_LOOP 3
#define CXt_SUBST 4
#define CXt_BLOCK 5
#define CXt_FORMAT 6
/* private flags for CXt_EVAL */
#ifdef USE_ITHREADS
/* private flags for CXt_LOOP */
has pad offset; if not set,
iterdata holds GV* */
== (CXt_LOOP|CXp_PADVAR))
#endif
== (CXt_EVAL|CXp_TRYBLOCK))
/*
=head1 "Gimme" Values
*/
/*
=for apidoc AmU||G_SCALAR
Used to indicate scalar context. See C<GIMME_V>, C<GIMME>, and
L<perlcall>.
=for apidoc AmU||G_ARRAY
Used to indicate list context. See C<GIMME_V>, C<GIMME> and
L<perlcall>.
=for apidoc AmU||G_VOID
Used to indicate void context. See C<GIMME_V> and L<perlcall>.
=for apidoc AmU||G_DISCARD
Indicates that arguments returned from a callback should be discarded. See
L<perlcall>.
=for apidoc AmU||G_EVAL
Used to force a Perl C<eval> wrapper around a callback. See
L<perlcall>.
=for apidoc AmU||G_NOARGS
Indicates that no arguments are being sent to a callback. See
L<perlcall>.
=cut
*/
#define G_SCALAR 0
#define G_ARRAY 1
/* extra flags for Perl_call_* routines */
/* flag bits for PL_in_eval */
#define EVAL_NULL 0 /* not in an eval */
/* Support for switching (stack and block) contexts.
* This ensures magic doesn't invalidate local stack and cx pointers.
*/
#define PERLSI_UNKNOWN -1
#define PERLSI_UNDEF 0
#define PERLSI_MAIN 1
#define PERLSI_MAGIC 2
#define PERLSI_SORT 3
#define PERLSI_SIGNAL 4
#define PERLSI_OVERLOAD 5
#define PERLSI_DESTROY 6
#define PERLSI_WARNHOOK 7
#define PERLSI_DIEHOOK 8
#define PERLSI_REQUIRE 9
struct stackinfo {
* currently used only with DEBUGGING,
* but not #ifdef-ed for bincompat */
};
#ifdef DEBUGGING
# define SET_MARK_OFFSET \
#else
# define SET_MARK_OFFSET NOOP
#endif
#define PUSHSTACKi(type) \
STMT_START { \
if (!next) { \
} \
PL_curstackinfo = next; \
} STMT_END
/* POPSTACK works with PL_stack_sp, so it may need to be bracketed by
#define POPSTACK \
STMT_START { \
dSP; \
if (!prev) { \
my_exit(1); \
} \
/* don't free prev here, free them all at the END{} */ \
PL_curstackinfo = prev; \
} STMT_END
#define POPSTACK_TO(s) \
STMT_START { \
while (PL_curstack != s) { \
dounwind(-1); \
POPSTACK; \
} \
} STMT_END