3 * Copyright (c) 1991-1999, Larry Wall
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
12 char * cop_label; /* label for this construct */
13 HV * cop_stash; /* package line was compiled in */
15 char * cop_file; /* file name the following line # is from */
17 GV * cop_filegv; /* file the following line # is from */
19 U32 cop_seq; /* parse sequence number */
20 I32 cop_arybase; /* array base this line was compiled with */
21 line_t cop_line; /* line # of this command */
22 SV * cop_warnings; /* lexical warnings bitmask */
25 #define Nullcop Null(COP*)
28 # define CopFILE(c) ((c)->cop_file)
29 # define CopFILEGV(c) (CopFILE(c) \
30 ? gv_fetchfile(CopFILE(c)) : Nullgv)
31 # define CopFILE_set(c,pv) ((c)->cop_file = savepv(pv)) /* XXX */
32 # define CopFILESV(c) (CopFILE(c) \
33 ? GvSV(gv_fetchfile(CopFILE(c))) : Nullsv)
34 # define CopFILEAV(c) (CopFILE(c) \
35 ? GvAV(gv_fetchfile(CopFILE(c))) : Nullav)
36 # define CopSTASH(c) (CopSTASHPV(c) \
37 ? gv_fetchstash(CopSTASHPV(c)) : Nullhv)
38 # define CopSTASH_set(c,hv) ((c)->cop_stashpv = HvNAME(hv)) /* XXX */
39 # define CopSTASHPV_set(c,pv) ((c)->cop_stashpv = pv)
40 # define CopSTASHPV(c) ((c)->cop_stashpv)
42 # define CopFILEGV(c) ((c)->cop_filegv)
43 # define CopFILEGV_set(c,gv) ((c)->cop_filegv = gv)
44 # define CopFILE_set(c,pv) ((c)->cop_filegv = gv_fetchfile(pv))
45 # define CopFILESV(c) (CopFILEGV(c) ? GvSV(CopFILEGV(c)) : Nullsv)
46 # define CopFILEAV(c) (CopFILEGV(c) ? GvAV(CopFILEGV(c)) : Nullav)
47 # define CopFILE(c) (CopFILESV(c) ? SvPVX(CopFILESV(c)) : Nullch)
48 # define CopSTASH(c) ((c)->cop_stash)
49 # define CopSTASH_set(c,hv) ((c)->cop_stash = hv)
50 # define CopSTASHPV(c) (CopSTASH(c) ? HvNAME(CopSTASH(c)) : Nullch)
51 #endif /* USE_ITHREADS */
53 #define CopLINE(c) ((c)->cop_line)
54 #define CopLINE_inc(c) (++CopLINE(c))
55 #define CopLINE_dec(c) (--CopLINE(c))
56 #define CopLINE_set(c,l) (CopLINE(c) = (l))
59 * Here we have some enormously heavy (or at least ponderous) wizardry.
62 /* subroutine context */
69 #endif /* USE_THREADS */
73 U8 lval; /* XXX merge lval and hasargs? */
77 cx->blk_sub.cv = cv; \
78 cx->blk_sub.olddepth = CvDEPTH(cv); \
79 cx->blk_sub.hasargs = hasargs; \
80 cx->blk_sub.lval = PL_op->op_private & \
81 (OPpLVAL_INTRO|OPpENTERSUB_INARGS);
83 #define PUSHFORMAT(cx) \
84 cx->blk_sub.cv = cv; \
85 cx->blk_sub.gv = gv; \
86 cx->blk_sub.hasargs = 0; \
87 cx->blk_sub.dfoutgv = PL_defoutgv; \
88 (void)SvREFCNT_inc(cx->blk_sub.dfoutgv)
91 #define POPSAVEARRAY() NOOP
93 #define POPSAVEARRAY() \
95 SvREFCNT_dec(GvAV(PL_defgv)); \
96 GvAV(PL_defgv) = cx->blk_sub.savearray; \
98 #endif /* USE_THREADS */
100 #define POPSUB(cx,sv) \
102 if (cx->blk_sub.hasargs) { \
104 /* abandon @_ if it got reified */ \
105 if (AvREAL(cx->blk_sub.argarray)) { \
106 SSize_t fill = AvFILLp(cx->blk_sub.argarray); \
107 SvREFCNT_dec(cx->blk_sub.argarray); \
108 cx->blk_sub.argarray = newAV(); \
109 av_extend(cx->blk_sub.argarray, fill); \
110 AvFLAGS(cx->blk_sub.argarray) = AVf_REIFY; \
111 PL_curpad[0] = (SV*)cx->blk_sub.argarray; \
114 sv = (SV*)cx->blk_sub.cv; \
115 if (sv && (CvDEPTH((CV*)sv) = cx->blk_sub.olddepth)) \
119 #define LEAVESUB(sv) \
125 #define POPFORMAT(cx) \
126 setdefout(cx->blk_sub.dfoutgv); \
127 SvREFCNT_dec(cx->blk_sub.dfoutgv);
138 #define PUSHEVAL(cx,n,fgv) \
139 cx->blk_eval.old_in_eval = PL_in_eval; \
140 cx->blk_eval.old_op_type = PL_op->op_type; \
141 cx->blk_eval.old_name = n; \
142 cx->blk_eval.old_eval_root = PL_eval_root; \
143 cx->blk_eval.cur_text = PL_linestr;
145 #define POPEVAL(cx) \
146 PL_in_eval = cx->blk_eval.old_in_eval; \
147 optype = cx->blk_eval.old_op_type; \
148 PL_eval_root = cx->blk_eval.old_eval_root;
165 #define PUSHLOOP(cx, ivar, s) \
166 cx->blk_loop.label = PL_curcop->cop_label; \
167 cx->blk_loop.resetsp = s - PL_stack_base; \
168 cx->blk_loop.redo_op = cLOOP->op_redoop; \
169 cx->blk_loop.next_op = cLOOP->op_nextop; \
170 cx->blk_loop.last_op = cLOOP->op_lastop; \
171 if (cx->blk_loop.itervar = (ivar)) \
172 cx->blk_loop.itersave = SvREFCNT_inc(*cx->blk_loop.itervar);\
173 cx->blk_loop.iterlval = Nullsv; \
174 cx->blk_loop.iterary = Nullav; \
175 cx->blk_loop.iterix = -1;
177 #define POPLOOP(cx) \
178 SvREFCNT_dec(cx->blk_loop.iterlval); \
179 if (cx->blk_loop.itervar) { \
180 sv_2mortal(*(cx->blk_loop.itervar)); \
181 *(cx->blk_loop.itervar) = cx->blk_loop.itersave; \
183 if (cx->blk_loop.iterary && cx->blk_loop.iterary != PL_curstack)\
184 SvREFCNT_dec(cx->blk_loop.iterary);
186 /* context common to subroutines, evals and loops */
188 I32 blku_oldsp; /* stack pointer to copy stuff down to */
189 COP * blku_oldcop; /* old curcop pointer */
190 I32 blku_oldretsp; /* return stack index */
191 I32 blku_oldmarksp; /* mark stack index */
192 I32 blku_oldscopesp; /* scope stack index */
193 PMOP * blku_oldpm; /* values of pattern match vars */
194 U8 blku_gimme; /* is this block running in list context? */
197 struct block_sub blku_sub;
198 struct block_eval blku_eval;
199 struct block_loop blku_loop;
202 #define blk_oldsp cx_u.cx_blk.blku_oldsp
203 #define blk_oldcop cx_u.cx_blk.blku_oldcop
204 #define blk_oldretsp cx_u.cx_blk.blku_oldretsp
205 #define blk_oldmarksp cx_u.cx_blk.blku_oldmarksp
206 #define blk_oldscopesp cx_u.cx_blk.blku_oldscopesp
207 #define blk_oldpm cx_u.cx_blk.blku_oldpm
208 #define blk_gimme cx_u.cx_blk.blku_gimme
209 #define blk_sub cx_u.cx_blk.blk_u.blku_sub
210 #define blk_eval cx_u.cx_blk.blk_u.blku_eval
211 #define blk_loop cx_u.cx_blk.blk_u.blku_loop
214 #define PUSHBLOCK(cx,t,sp) CXINC, cx = &cxstack[cxstack_ix], \
216 cx->blk_oldsp = sp - PL_stack_base, \
217 cx->blk_oldcop = PL_curcop, \
218 cx->blk_oldmarksp = PL_markstack_ptr - PL_markstack, \
219 cx->blk_oldscopesp = PL_scopestack_ix, \
220 cx->blk_oldretsp = PL_retstack_ix, \
221 cx->blk_oldpm = PL_curpm, \
222 cx->blk_gimme = gimme; \
223 DEBUG_l( PerlIO_printf(Perl_debug_log, "Entering block %ld, type %s\n", \
224 (long)cxstack_ix, PL_block_type[CxTYPE(cx)]); )
226 /* Exit a block (RETURN and LAST). */
227 #define POPBLOCK(cx,pm) cx = &cxstack[cxstack_ix--], \
228 newsp = PL_stack_base + cx->blk_oldsp, \
229 PL_curcop = cx->blk_oldcop, \
230 PL_markstack_ptr = PL_markstack + cx->blk_oldmarksp, \
231 PL_scopestack_ix = cx->blk_oldscopesp, \
232 PL_retstack_ix = cx->blk_oldretsp, \
233 pm = cx->blk_oldpm, \
234 gimme = cx->blk_gimme; \
235 DEBUG_l( PerlIO_printf(Perl_debug_log, "Leaving block %ld, type %s\n", \
236 (long)cxstack_ix+1,PL_block_type[CxTYPE(cx)]); )
238 /* Continue a block elsewhere (NEXT and REDO). */
239 #define TOPBLOCK(cx) cx = &cxstack[cxstack_ix], \
240 PL_stack_sp = PL_stack_base + cx->blk_oldsp, \
241 PL_markstack_ptr = PL_markstack + cx->blk_oldmarksp, \
242 PL_scopestack_ix = cx->blk_oldscopesp, \
243 PL_retstack_ix = cx->blk_oldretsp, \
244 PL_curpm = cx->blk_oldpm
246 /* substitution context */
263 #define sb_iters cx_u.cx_subst.sbu_iters
264 #define sb_maxiters cx_u.cx_subst.sbu_maxiters
265 #define sb_rflags cx_u.cx_subst.sbu_rflags
266 #define sb_oldsave cx_u.cx_subst.sbu_oldsave
267 #define sb_once cx_u.cx_subst.sbu_once
268 #define sb_rxtainted cx_u.cx_subst.sbu_rxtainted
269 #define sb_orig cx_u.cx_subst.sbu_orig
270 #define sb_dstr cx_u.cx_subst.sbu_dstr
271 #define sb_targ cx_u.cx_subst.sbu_targ
272 #define sb_s cx_u.cx_subst.sbu_s
273 #define sb_m cx_u.cx_subst.sbu_m
274 #define sb_strend cx_u.cx_subst.sbu_strend
275 #define sb_rxres cx_u.cx_subst.sbu_rxres
276 #define sb_rx cx_u.cx_subst.sbu_rx
278 #define PUSHSUBST(cx) CXINC, cx = &cxstack[cxstack_ix], \
279 cx->sb_iters = iters, \
280 cx->sb_maxiters = maxiters, \
281 cx->sb_rflags = r_flags, \
282 cx->sb_oldsave = oldsave, \
283 cx->sb_once = once, \
284 cx->sb_rxtainted = rxtainted, \
285 cx->sb_orig = orig, \
286 cx->sb_dstr = dstr, \
287 cx->sb_targ = targ, \
290 cx->sb_strend = strend, \
291 cx->sb_rxres = Null(void*), \
293 cx->cx_type = CXt_SUBST; \
294 rxres_save(&cx->sb_rxres, rx)
296 #define POPSUBST(cx) cx = &cxstack[cxstack_ix--]; \
297 rxres_free(&cx->sb_rxres)
300 U32 cx_type; /* what kind of context this is */
303 struct subst cx_subst;
307 #define CXTYPEMASK 0xff
315 /* private flags for CXt_EVAL */
316 #define CXp_REAL 0x00000100 /* truly eval'', not a lookalike */
318 #define CxTYPE(c) ((c)->cx_type & CXTYPEMASK)
319 #define CxREALEVAL(c) (((c)->cx_type & (CXt_EVAL|CXp_REAL)) == (CXt_EVAL|CXp_REAL))
321 #define CXINC (cxstack_ix < cxstack_max ? ++cxstack_ix : (cxstack_ix = cxinc()))
326 #define G_VOID 128 /* skip this bit when adding flags below */
328 /* extra flags for Perl_call_* routines */
329 #define G_DISCARD 2 /* Call FREETMPS. */
330 #define G_EVAL 4 /* Assume eval {} around subroutine call. */
331 #define G_NOARGS 8 /* Don't construct a @_ array. */
332 #define G_KEEPERR 16 /* Append errors to $@, don't overwrite it */
333 #define G_NODEBUG 32 /* Disable debugging at toplevel. */
335 /* flag bits for PL_in_eval */
336 #define EVAL_NULL 0 /* not in an eval */
337 #define EVAL_INEVAL 1 /* some enclosing scope is an eval */
338 #define EVAL_WARNONLY 2 /* used by yywarn() when calling yyerror() */
339 #define EVAL_KEEPERR 4 /* set by Perl_call_sv if G_KEEPERR */
341 /* Support for switching (stack and block) contexts.
342 * This ensures magic doesn't invalidate local stack and cx pointers.
345 #define PERLSI_UNKNOWN -1
346 #define PERLSI_UNDEF 0
347 #define PERLSI_MAIN 1
348 #define PERLSI_MAGIC 2
349 #define PERLSI_SORT 3
350 #define PERLSI_SIGNAL 4
351 #define PERLSI_OVERLOAD 5
352 #define PERLSI_DESTROY 6
353 #define PERLSI_WARNHOOK 7
354 #define PERLSI_DIEHOOK 8
355 #define PERLSI_REQUIRE 9
358 AV * si_stack; /* stack for current runlevel */
359 PERL_CONTEXT * si_cxstack; /* context stack for runlevel */
360 I32 si_cxix; /* current context index */
361 I32 si_cxmax; /* maximum allocated index */
362 I32 si_type; /* type of runlevel */
363 struct stackinfo * si_prev;
364 struct stackinfo * si_next;
365 I32 * si_markbase; /* where markstack begins for us.
366 * currently used only with DEBUGGING,
367 * but not #ifdef-ed for bincompat */
370 typedef struct stackinfo PERL_SI;
372 #define cxstack (PL_curstackinfo->si_cxstack)
373 #define cxstack_ix (PL_curstackinfo->si_cxix)
374 #define cxstack_max (PL_curstackinfo->si_cxmax)
377 # define SET_MARKBASE PL_curstackinfo->si_markbase = PL_markstack_ptr
379 # define SET_MARKBASE NOOP
382 #define PUSHSTACKi(type) \
384 PERL_SI *next = PL_curstackinfo->si_next; \
386 next = new_stackinfo(32, 2048/sizeof(PERL_CONTEXT) - 1); \
387 next->si_prev = PL_curstackinfo; \
388 PL_curstackinfo->si_next = next; \
390 next->si_type = type; \
391 next->si_cxix = -1; \
392 AvFILLp(next->si_stack) = 0; \
393 SWITCHSTACK(PL_curstack,next->si_stack); \
394 PL_curstackinfo = next; \
398 #define PUSHSTACK PUSHSTACKi(PERLSI_UNKNOWN)
400 /* POPSTACK works with PL_stack_sp, so it may need to be bracketed by
401 * PUTBACK/SPAGAIN to flush/refresh any local SP that may be active */
405 PERL_SI *prev = PL_curstackinfo->si_prev; \
407 PerlIO_printf(Perl_error_log, "panic: POPSTACK\n"); \
410 SWITCHSTACK(PL_curstack,prev->si_stack); \
411 /* don't free prev here, free them all at the END{} */ \
412 PL_curstackinfo = prev; \
415 #define POPSTACK_TO(s) \
417 while (PL_curstack != s) { \