3 * Copyright (c) 1991-1997, 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 */
14 GV * cop_filegv; /* file the following line # is from */
15 U32 cop_seq; /* parse sequence number */
16 I32 cop_arybase; /* array base this line was compiled with */
17 line_t cop_line; /* line # of this command */
18 SV * cop_warnings; /* lexical warnings bitmask */
21 #define Nullcop Null(COP*)
24 * Here we have some enormously heavy (or at least ponderous) wizardry.
27 /* subroutine context */
34 #endif /* USE_THREADS */
41 cx->blk_sub.cv = cv; \
42 cx->blk_sub.olddepth = CvDEPTH(cv); \
43 cx->blk_sub.hasargs = hasargs;
45 #define PUSHFORMAT(cx) \
46 cx->blk_sub.cv = cv; \
47 cx->blk_sub.gv = gv; \
48 cx->blk_sub.hasargs = 0; \
49 cx->blk_sub.dfoutgv = PL_defoutgv; \
50 (void)SvREFCNT_inc(cx->blk_sub.dfoutgv)
53 { struct block_sub cxsub; \
58 cxsub = cx->blk_sub; /* because DESTROY may clobber *cx */
61 #define POPSAVEARRAY() NOOP
63 #define POPSAVEARRAY() \
65 SvREFCNT_dec(GvAV(PL_defgv)); \
66 GvAV(PL_defgv) = cxsub.savearray; \
68 #endif /* USE_THREADS */
71 if (cxsub.hasargs) { \
73 /* destroy arg array */ \
74 av_clear(cxsub.argarray); \
75 AvREAL_off(cxsub.argarray); \
78 if (!(CvDEPTH(cxsub.cv) = cxsub.olddepth)) \
79 SvREFCNT_dec(cxsub.cv); \
82 #define POPFORMAT(cx) \
83 setdefout(cx->blk_sub.dfoutgv); \
84 SvREFCNT_dec(cx->blk_sub.dfoutgv);
95 #define PUSHEVAL(cx,n,fgv) \
96 cx->blk_eval.old_in_eval = PL_in_eval; \
97 cx->blk_eval.old_op_type = PL_op->op_type; \
98 cx->blk_eval.old_name = n; \
99 cx->blk_eval.old_eval_root = PL_eval_root; \
100 cx->blk_eval.cur_text = PL_linestr;
102 #define POPEVAL(cx) \
103 PL_in_eval = cx->blk_eval.old_in_eval; \
104 optype = cx->blk_eval.old_op_type; \
105 PL_eval_root = cx->blk_eval.old_eval_root;
122 #define PUSHLOOP(cx, ivar, s) \
123 cx->blk_loop.label = PL_curcop->cop_label; \
124 cx->blk_loop.resetsp = s - PL_stack_base; \
125 cx->blk_loop.redo_op = cLOOP->op_redoop; \
126 cx->blk_loop.next_op = cLOOP->op_nextop; \
127 cx->blk_loop.last_op = cLOOP->op_lastop; \
128 if (cx->blk_loop.itervar = (ivar)) \
129 cx->blk_loop.itersave = SvREFCNT_inc(*cx->blk_loop.itervar);\
130 cx->blk_loop.iterlval = Nullsv; \
131 cx->blk_loop.iterary = Nullav; \
132 cx->blk_loop.iterix = -1;
134 #define POPLOOP(cx) \
135 { struct block_loop cxloop; \
139 #define POPLOOP1(cx) \
140 cxloop = cx->blk_loop; /* because DESTROY may clobber *cx */ \
141 newsp = PL_stack_base + cxloop.resetsp;
144 SvREFCNT_dec(cxloop.iterlval); \
145 if (cxloop.itervar) { \
146 sv_2mortal(*cxloop.itervar); \
147 *cxloop.itervar = cxloop.itersave; \
149 if (cxloop.iterary && cxloop.iterary != PL_curstack) \
150 SvREFCNT_dec(cxloop.iterary);
152 /* context common to subroutines, evals and loops */
154 I32 blku_oldsp; /* stack pointer to copy stuff down to */
155 COP * blku_oldcop; /* old curcop pointer */
156 I32 blku_oldretsp; /* return stack index */
157 I32 blku_oldmarksp; /* mark stack index */
158 I32 blku_oldscopesp; /* scope stack index */
159 PMOP * blku_oldpm; /* values of pattern match vars */
160 U8 blku_gimme; /* is this block running in list context? */
163 struct block_sub blku_sub;
164 struct block_eval blku_eval;
165 struct block_loop blku_loop;
168 #define blk_oldsp cx_u.cx_blk.blku_oldsp
169 #define blk_oldcop cx_u.cx_blk.blku_oldcop
170 #define blk_oldretsp cx_u.cx_blk.blku_oldretsp
171 #define blk_oldmarksp cx_u.cx_blk.blku_oldmarksp
172 #define blk_oldscopesp cx_u.cx_blk.blku_oldscopesp
173 #define blk_oldpm cx_u.cx_blk.blku_oldpm
174 #define blk_gimme cx_u.cx_blk.blku_gimme
175 #define blk_sub cx_u.cx_blk.blk_u.blku_sub
176 #define blk_eval cx_u.cx_blk.blk_u.blku_eval
177 #define blk_loop cx_u.cx_blk.blk_u.blku_loop
180 #define PUSHBLOCK(cx,t,sp) CXINC, cx = &cxstack[cxstack_ix], \
182 cx->blk_oldsp = sp - PL_stack_base, \
183 cx->blk_oldcop = PL_curcop, \
184 cx->blk_oldmarksp = PL_markstack_ptr - PL_markstack, \
185 cx->blk_oldscopesp = PL_scopestack_ix, \
186 cx->blk_oldretsp = PL_retstack_ix, \
187 cx->blk_oldpm = PL_curpm, \
188 cx->blk_gimme = gimme; \
189 DEBUG_l( PerlIO_printf(PerlIO_stderr(), "Entering block %ld, type %s\n", \
190 (long)cxstack_ix, PL_block_type[t]); )
192 /* Exit a block (RETURN and LAST). */
193 #define POPBLOCK(cx,pm) cx = &cxstack[cxstack_ix--], \
194 newsp = PL_stack_base + cx->blk_oldsp, \
195 PL_curcop = cx->blk_oldcop, \
196 PL_markstack_ptr = PL_markstack + cx->blk_oldmarksp, \
197 PL_scopestack_ix = cx->blk_oldscopesp, \
198 PL_retstack_ix = cx->blk_oldretsp, \
199 pm = cx->blk_oldpm, \
200 gimme = cx->blk_gimme; \
201 DEBUG_l( PerlIO_printf(PerlIO_stderr(), "Leaving block %ld, type %s\n", \
202 (long)cxstack_ix+1,PL_block_type[CxTYPE(cx)]); )
204 /* Continue a block elsewhere (NEXT and REDO). */
205 #define TOPBLOCK(cx) cx = &cxstack[cxstack_ix], \
206 PL_stack_sp = PL_stack_base + cx->blk_oldsp, \
207 PL_markstack_ptr = PL_markstack + cx->blk_oldmarksp, \
208 PL_scopestack_ix = cx->blk_oldscopesp, \
209 PL_retstack_ix = cx->blk_oldretsp, \
210 PL_curpm = cx->blk_oldpm
212 /* substitution context */
229 #define sb_iters cx_u.cx_subst.sbu_iters
230 #define sb_maxiters cx_u.cx_subst.sbu_maxiters
231 #define sb_rflags cx_u.cx_subst.sbu_rflags
232 #define sb_oldsave cx_u.cx_subst.sbu_oldsave
233 #define sb_once cx_u.cx_subst.sbu_once
234 #define sb_rxtainted cx_u.cx_subst.sbu_rxtainted
235 #define sb_orig cx_u.cx_subst.sbu_orig
236 #define sb_dstr cx_u.cx_subst.sbu_dstr
237 #define sb_targ cx_u.cx_subst.sbu_targ
238 #define sb_s cx_u.cx_subst.sbu_s
239 #define sb_m cx_u.cx_subst.sbu_m
240 #define sb_strend cx_u.cx_subst.sbu_strend
241 #define sb_rxres cx_u.cx_subst.sbu_rxres
242 #define sb_rx cx_u.cx_subst.sbu_rx
244 #define PUSHSUBST(cx) CXINC, cx = &cxstack[cxstack_ix], \
245 cx->sb_iters = iters, \
246 cx->sb_maxiters = maxiters, \
247 cx->sb_rflags = r_flags, \
248 cx->sb_oldsave = oldsave, \
249 cx->sb_once = once, \
250 cx->sb_rxtainted = rxtainted, \
251 cx->sb_orig = orig, \
252 cx->sb_dstr = dstr, \
253 cx->sb_targ = targ, \
256 cx->sb_strend = strend, \
257 cx->sb_rxres = Null(void*), \
259 cx->cx_type = CXt_SUBST; \
260 rxres_save(&cx->sb_rxres, rx)
262 #define POPSUBST(cx) cx = &cxstack[cxstack_ix--]; \
263 rxres_free(&cx->sb_rxres)
266 U32 cx_type; /* what kind of context this is */
269 struct subst cx_subst;
273 #define CXTYPEMASK 0xff
281 /* private flags for CXt_EVAL */
282 #define CXp_REAL 0x00000100 /* truly eval'', not a lookalike */
284 #define CxTYPE(c) ((c)->cx_type & CXTYPEMASK)
285 #define CxREALEVAL(c) (((c)->cx_type & (CXt_EVAL|CXp_REAL)) == (CXt_EVAL|CXp_REAL))
287 #define CXINC (cxstack_ix < cxstack_max ? ++cxstack_ix : (cxstack_ix = cxinc()))
292 #define G_VOID 128 /* skip this bit when adding flags below */
294 /* extra flags for perl_call_* routines */
295 #define G_DISCARD 2 /* Call FREETMPS. */
296 #define G_EVAL 4 /* Assume eval {} around subroutine call. */
297 #define G_NOARGS 8 /* Don't construct a @_ array. */
298 #define G_KEEPERR 16 /* Append errors to $@, don't overwrite it */
299 #define G_NODEBUG 32 /* Disable debugging at toplevel. */
301 /* Support for switching (stack and block) contexts.
302 * This ensures magic doesn't invalidate local stack and cx pointers.
305 #define PERLSI_UNKNOWN -1
306 #define PERLSI_UNDEF 0
307 #define PERLSI_MAIN 1
308 #define PERLSI_MAGIC 2
309 #define PERLSI_SORT 3
310 #define PERLSI_SIGNAL 4
311 #define PERLSI_OVERLOAD 5
312 #define PERLSI_DESTROY 6
313 #define PERLSI_WARNHOOK 7
314 #define PERLSI_DIEHOOK 8
315 #define PERLSI_REQUIRE 9
318 AV * si_stack; /* stack for current runlevel */
319 PERL_CONTEXT * si_cxstack; /* context stack for runlevel */
320 I32 si_cxix; /* current context index */
321 I32 si_cxmax; /* maximum allocated index */
322 I32 si_type; /* type of runlevel */
323 struct stackinfo * si_prev;
324 struct stackinfo * si_next;
325 I32 * si_markbase; /* where markstack begins for us.
326 * currently used only with DEBUGGING,
327 * but not #ifdef-ed for bincompat */
330 typedef struct stackinfo PERL_SI;
332 #define cxstack (PL_curstackinfo->si_cxstack)
333 #define cxstack_ix (PL_curstackinfo->si_cxix)
334 #define cxstack_max (PL_curstackinfo->si_cxmax)
337 # define SET_MARKBASE PL_curstackinfo->si_markbase = PL_markstack_ptr
339 # define SET_MARKBASE NOOP
342 #define PUSHSTACKi(type) \
344 PERL_SI *next = PL_curstackinfo->si_next; \
346 next = new_stackinfo(32, 2048/sizeof(PERL_CONTEXT) - 1); \
347 next->si_prev = PL_curstackinfo; \
348 PL_curstackinfo->si_next = next; \
350 next->si_type = type; \
351 next->si_cxix = -1; \
352 AvFILLp(next->si_stack) = 0; \
353 SWITCHSTACK(PL_curstack,next->si_stack); \
354 PL_curstackinfo = next; \
358 #define PUSHSTACK PUSHSTACKi(PERLSI_UNKNOWN)
360 /* POPSTACK works with PL_stack_sp, so it may need to be bracketed by
361 * PUTBACK/SPAGAIN to flush/refresh any local SP that may be active */
365 PERL_SI *prev = PL_curstackinfo->si_prev; \
367 PerlIO_printf(PerlIO_stderr(), "panic: POPSTACK\n"); \
370 SWITCHSTACK(PL_curstack,prev->si_stack); \
371 /* don't free prev here, free them all at the END{} */ \
372 PL_curstackinfo = prev; \
375 #define POPSTACK_TO(s) \
377 while (PL_curstack != s) { \