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 */
20 #define Nullcop Null(COP*)
23 * Here we have some enormously heavy (or at least ponderous) wizardry.
26 /* subroutine context */
33 #endif /* USE_THREADS */
40 cx->blk_sub.cv = cv; \
41 cx->blk_sub.olddepth = CvDEPTH(cv); \
42 cx->blk_sub.hasargs = hasargs;
44 #define PUSHFORMAT(cx) \
45 cx->blk_sub.cv = cv; \
46 cx->blk_sub.gv = gv; \
47 cx->blk_sub.hasargs = 0; \
48 cx->blk_sub.dfoutgv = PL_defoutgv; \
49 (void)SvREFCNT_inc(cx->blk_sub.dfoutgv)
52 { struct block_sub cxsub; \
57 cxsub = cx->blk_sub; /* because DESTROY may clobber *cx */
60 #define POPSAVEARRAY() NOOP
62 #define POPSAVEARRAY() \
64 SvREFCNT_dec(GvAV(PL_defgv)); \
65 GvAV(PL_defgv) = cxsub.savearray; \
67 #endif /* USE_THREADS */
70 if (cxsub.hasargs) { \
72 /* destroy arg array */ \
73 av_clear(cxsub.argarray); \
74 AvREAL_off(cxsub.argarray); \
77 if (!(CvDEPTH(cxsub.cv) = cxsub.olddepth)) \
78 SvREFCNT_dec(cxsub.cv); \
81 #define POPFORMAT(cx) \
82 setdefout(cx->blk_sub.dfoutgv); \
83 SvREFCNT_dec(cx->blk_sub.dfoutgv);
94 #define PUSHEVAL(cx,n,fgv) \
95 cx->blk_eval.old_in_eval = PL_in_eval; \
96 cx->blk_eval.old_op_type = PL_op->op_type; \
97 cx->blk_eval.old_name = n; \
98 cx->blk_eval.old_eval_root = PL_eval_root; \
99 cx->blk_eval.cur_text = PL_linestr;
101 #define POPEVAL(cx) \
102 PL_in_eval = cx->blk_eval.old_in_eval; \
103 optype = cx->blk_eval.old_op_type; \
104 PL_eval_root = cx->blk_eval.old_eval_root;
121 #define PUSHLOOP(cx, ivar, s) \
122 cx->blk_loop.label = PL_curcop->cop_label; \
123 cx->blk_loop.resetsp = s - PL_stack_base; \
124 cx->blk_loop.redo_op = cLOOP->op_redoop; \
125 cx->blk_loop.next_op = cLOOP->op_nextop; \
126 cx->blk_loop.last_op = cLOOP->op_lastop; \
127 if (cx->blk_loop.itervar = (ivar)) \
128 cx->blk_loop.itersave = SvREFCNT_inc(*cx->blk_loop.itervar);\
129 cx->blk_loop.iterlval = Nullsv; \
130 cx->blk_loop.iterary = Nullav; \
131 cx->blk_loop.iterix = -1;
133 #define POPLOOP(cx) \
134 { struct block_loop cxloop; \
138 #define POPLOOP1(cx) \
139 cxloop = cx->blk_loop; /* because DESTROY may clobber *cx */ \
140 newsp = PL_stack_base + cxloop.resetsp;
143 SvREFCNT_dec(cxloop.iterlval); \
144 if (cxloop.itervar) { \
145 SvREFCNT_dec(*cxloop.itervar); \
146 *cxloop.itervar = cxloop.itersave; \
148 if (cxloop.iterary && cxloop.iterary != PL_curstack) \
149 SvREFCNT_dec(cxloop.iterary);
151 /* context common to subroutines, evals and loops */
153 I32 blku_oldsp; /* stack pointer to copy stuff down to */
154 COP * blku_oldcop; /* old curcop pointer */
155 I32 blku_oldretsp; /* return stack index */
156 I32 blku_oldmarksp; /* mark stack index */
157 I32 blku_oldscopesp; /* scope stack index */
158 PMOP * blku_oldpm; /* values of pattern match vars */
159 U8 blku_gimme; /* is this block running in list context? */
162 struct block_sub blku_sub;
163 struct block_eval blku_eval;
164 struct block_loop blku_loop;
167 #define blk_oldsp cx_u.cx_blk.blku_oldsp
168 #define blk_oldcop cx_u.cx_blk.blku_oldcop
169 #define blk_oldretsp cx_u.cx_blk.blku_oldretsp
170 #define blk_oldmarksp cx_u.cx_blk.blku_oldmarksp
171 #define blk_oldscopesp cx_u.cx_blk.blku_oldscopesp
172 #define blk_oldpm cx_u.cx_blk.blku_oldpm
173 #define blk_gimme cx_u.cx_blk.blku_gimme
174 #define blk_sub cx_u.cx_blk.blk_u.blku_sub
175 #define blk_eval cx_u.cx_blk.blk_u.blku_eval
176 #define blk_loop cx_u.cx_blk.blk_u.blku_loop
179 #define PUSHBLOCK(cx,t,sp) CXINC, cx = &cxstack[cxstack_ix], \
181 cx->blk_oldsp = sp - PL_stack_base, \
182 cx->blk_oldcop = PL_curcop, \
183 cx->blk_oldmarksp = PL_markstack_ptr - PL_markstack, \
184 cx->blk_oldscopesp = PL_scopestack_ix, \
185 cx->blk_oldretsp = PL_retstack_ix, \
186 cx->blk_oldpm = PL_curpm, \
187 cx->blk_gimme = gimme; \
188 DEBUG_l( PerlIO_printf(PerlIO_stderr(), "Entering block %ld, type %s\n", \
189 (long)cxstack_ix, block_type[t]); )
191 /* Exit a block (RETURN and LAST). */
192 #define POPBLOCK(cx,pm) cx = &cxstack[cxstack_ix--], \
193 newsp = PL_stack_base + cx->blk_oldsp, \
194 PL_curcop = cx->blk_oldcop, \
195 PL_markstack_ptr = PL_markstack + cx->blk_oldmarksp, \
196 PL_scopestack_ix = cx->blk_oldscopesp, \
197 PL_retstack_ix = cx->blk_oldretsp, \
198 pm = cx->blk_oldpm, \
199 gimme = cx->blk_gimme; \
200 DEBUG_l( PerlIO_printf(PerlIO_stderr(), "Leaving block %ld, type %s\n", \
201 (long)cxstack_ix+1,block_type[cx->cx_type]); )
203 /* Continue a block elsewhere (NEXT and REDO). */
204 #define TOPBLOCK(cx) cx = &cxstack[cxstack_ix], \
205 PL_stack_sp = PL_stack_base + cx->blk_oldsp, \
206 PL_markstack_ptr = PL_markstack + cx->blk_oldmarksp, \
207 PL_scopestack_ix = cx->blk_oldscopesp, \
208 PL_retstack_ix = cx->blk_oldretsp
210 /* substitution context */
227 #define sb_iters cx_u.cx_subst.sbu_iters
228 #define sb_maxiters cx_u.cx_subst.sbu_maxiters
229 #define sb_safebase cx_u.cx_subst.sbu_safebase
230 #define sb_oldsave cx_u.cx_subst.sbu_oldsave
231 #define sb_once cx_u.cx_subst.sbu_once
232 #define sb_rxtainted cx_u.cx_subst.sbu_rxtainted
233 #define sb_orig cx_u.cx_subst.sbu_orig
234 #define sb_dstr cx_u.cx_subst.sbu_dstr
235 #define sb_targ cx_u.cx_subst.sbu_targ
236 #define sb_s cx_u.cx_subst.sbu_s
237 #define sb_m cx_u.cx_subst.sbu_m
238 #define sb_strend cx_u.cx_subst.sbu_strend
239 #define sb_rxres cx_u.cx_subst.sbu_rxres
240 #define sb_rx cx_u.cx_subst.sbu_rx
242 #define PUSHSUBST(cx) CXINC, cx = &cxstack[cxstack_ix], \
243 cx->sb_iters = iters, \
244 cx->sb_maxiters = maxiters, \
245 cx->sb_safebase = safebase, \
246 cx->sb_oldsave = oldsave, \
247 cx->sb_once = once, \
248 cx->sb_rxtainted = rxtainted, \
249 cx->sb_orig = orig, \
250 cx->sb_dstr = dstr, \
251 cx->sb_targ = targ, \
254 cx->sb_strend = strend, \
255 cx->sb_rxres = Null(void*), \
257 cx->cx_type = CXt_SUBST; \
258 rxres_save(&cx->sb_rxres, rx)
260 #define POPSUBST(cx) cx = &cxstack[cxstack_ix--]; \
261 rxres_free(&cx->sb_rxres)
264 I32 cx_type; /* what kind of context this is */
267 struct subst cx_subst;
277 #define CXINC (cxstack_ix < cxstack_max ? ++cxstack_ix : (cxstack_ix = cxinc()))
282 #define G_VOID 128 /* skip this bit when adding flags below */
284 /* extra flags for perl_call_* routines */
285 #define G_DISCARD 2 /* Call FREETMPS. */
286 #define G_EVAL 4 /* Assume eval {} around subroutine call. */
287 #define G_NOARGS 8 /* Don't construct a @_ array. */
288 #define G_KEEPERR 16 /* Append errors to $@, don't overwrite it */
289 #define G_NODEBUG 32 /* Disable debugging at toplevel. */
291 /* Support for switching (stack and block) contexts.
292 * This ensures magic doesn't invalidate local stack and cx pointers.
295 #define PERLSI_UNKNOWN -1
296 #define PERLSI_UNDEF 0
297 #define PERLSI_MAIN 1
298 #define PERLSI_MAGIC 2
299 #define PERLSI_SORT 3
300 #define PERLSI_SIGNAL 4
301 #define PERLSI_OVERLOAD 5
302 #define PERLSI_DESTROY 6
303 #define PERLSI_WARNHOOK 7
304 #define PERLSI_DIEHOOK 8
305 #define PERLSI_REQUIRE 9
308 AV * si_stack; /* stack for current runlevel */
309 PERL_CONTEXT * si_cxstack; /* context stack for runlevel */
310 I32 si_cxix; /* current context index */
311 I32 si_cxmax; /* maximum allocated index */
312 I32 si_type; /* type of runlevel */
313 struct stackinfo * si_prev;
314 struct stackinfo * si_next;
315 I32 * si_markbase; /* where markstack begins for us.
316 * currently used only with DEBUGGING,
317 * but not #ifdef-ed for bincompat */
320 typedef struct stackinfo PERL_SI;
322 #define cxstack (PL_curstackinfo->si_cxstack)
323 #define cxstack_ix (PL_curstackinfo->si_cxix)
324 #define cxstack_max (PL_curstackinfo->si_cxmax)
327 # define SET_MARKBASE PL_curstackinfo->si_markbase = PL_markstack_ptr
329 # define SET_MARKBASE NOOP
332 #define PUSHSTACKi(type) \
334 PERL_SI *next = PL_curstackinfo->si_next; \
336 next = new_stackinfo(32, 2048/sizeof(PERL_CONTEXT) - 1); \
337 next->si_prev = PL_curstackinfo; \
338 PL_curstackinfo->si_next = next; \
340 next->si_type = type; \
341 next->si_cxix = -1; \
342 AvFILLp(next->si_stack) = 0; \
343 SWITCHSTACK(PL_curstack,next->si_stack); \
344 PL_curstackinfo = next; \
348 #define PUSHSTACK PUSHSTACKi(PERLSI_UNKNOWN)
352 PERL_SI *prev = PL_curstackinfo->si_prev; \
354 PerlIO_printf(PerlIO_stderr(), "panic: POPSTACK\n"); \
357 SWITCHSTACK(PL_curstack,prev->si_stack); \
358 /* don't free prev here, free them all at the END{} */ \
359 PL_curstackinfo = prev; \
362 #define POPSTACK_TO(s) \
364 while (PL_curstack != s) { \