xref: /openbsd/gnu/usr.bin/perl/pp.h (revision e0680481)
1 /*    pp.h
2  *
3  *    Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
4  *    2002, 2003, 2004, 2005, 2006, 2007, 2008 by Larry Wall and others
5  *
6  *    You may distribute under the terms of either the GNU General Public
7  *    License or the Artistic License, as specified in the README file.
8  *
9  */
10 
11 #define PP(s) OP * Perl_##s(pTHX)
12 
13 /*
14 =for apidoc_section $stack
15 
16 =for apidoc AmnU||SP
17 Stack pointer.  This is usually handled by C<xsubpp>.  See C<L</dSP>> and
18 C<SPAGAIN>.
19 
20 =for apidoc AmnU||MARK
21 Stack marker variable for the XSUB.  See C<L</dMARK>>.
22 
23 =for apidoc Am|void|PUSHMARK|SP
24 Opening bracket for arguments on a callback.  See C<L</PUTBACK>> and
25 L<perlcall>.
26 
27 =for apidoc Amn;||dSP
28 Declares a local copy of perl's stack pointer for the XSUB, available via
29 the C<SP> macro.  See C<L</SP>>.
30 
31 =for apidoc m;||djSP
32 
33 Declare Just C<SP>.  This is actually identical to C<dSP>, and declares
34 a local copy of perl's stack pointer, available via the C<SP> macro.
35 See C<L<perlapi/SP>>.  (Available for backward source code compatibility with
36 the old (Perl 5.005) thread model.)
37 
38 =for apidoc Amn;||dMARK
39 Declare a stack marker variable, C<mark>, for the XSUB.  See C<L</MARK>> and
40 C<L</dORIGMARK>>.
41 
42 =for apidoc Amn;||dORIGMARK
43 Saves the original stack mark for the XSUB.  See C<L</ORIGMARK>>.
44 
45 =for apidoc AmnU||ORIGMARK
46 The original stack mark for the XSUB.  See C<L</dORIGMARK>>.
47 
48 =for apidoc Amn;||SPAGAIN
49 Refetch the stack pointer.  Used after a callback.  See L<perlcall>.
50 
51 =cut */
52 
53 #undef SP /* Solaris 2.7 i386 has this in /usr/include/sys/reg.h */
54 #define SP sp
55 #define MARK mark
56 
57 /*
58 =for apidoc Amn;||TARG
59 
60 C<TARG> is short for "target".  It is an entry in the pad that an OPs
61 C<op_targ> refers to.  It is scratchpad space, often used as a return
62 value for the OP, but some use it for other purposes.
63 
64 =cut
65 */
66 #define TARG targ
67 
68 #define PUSHMARK(p) \
69     STMT_START {                                                      \
70         I32 * mark_stack_entry;                                       \
71         if (UNLIKELY((mark_stack_entry = ++PL_markstack_ptr)          \
72                                            == PL_markstack_max))      \
73             mark_stack_entry = markstack_grow();                      \
74         *mark_stack_entry  = (I32)((p) - PL_stack_base);              \
75         DEBUG_s(DEBUG_v(PerlIO_printf(Perl_debug_log,                 \
76                 "MARK push %p %" IVdf "\n",                           \
77                 PL_markstack_ptr, (IV)*mark_stack_entry)));           \
78     } STMT_END
79 
80 #define TOPMARK Perl_TOPMARK(aTHX)
81 #define POPMARK Perl_POPMARK(aTHX)
82 
83 #define INCMARK \
84     STMT_START {                                                      \
85         DEBUG_s(DEBUG_v(PerlIO_printf(Perl_debug_log,                 \
86                 "MARK inc  %p %" IVdf "\n",                           \
87                 (PL_markstack_ptr+1), (IV)*(PL_markstack_ptr+1))));   \
88         PL_markstack_ptr++;                                           \
89     } STMT_END
90 
91 #define dSP		SV **sp = PL_stack_sp
92 #define djSP		dSP
93 #define dMARK		SV **mark = PL_stack_base + POPMARK
94 #define dORIGMARK	const I32 origmark = (I32)(mark - PL_stack_base)
95 #define ORIGMARK	(PL_stack_base + origmark)
96 
97 #define SPAGAIN		sp = PL_stack_sp
98 #define MSPAGAIN	STMT_START { sp = PL_stack_sp; mark = ORIGMARK; } STMT_END
99 
100 #define GETTARGETSTACKED targ = (PL_op->op_flags & OPf_STACKED ? POPs : PAD_SV(PL_op->op_targ))
101 #define dTARGETSTACKED SV * GETTARGETSTACKED
102 
103 #define GETTARGET targ = PAD_SV(PL_op->op_targ)
104 
105 /*
106 =for apidoc Amn;||dTARGET
107 Declare that this function uses C<TARG>, and initializes it
108 
109 =cut
110 */
111 #define dTARGET SV * GETTARGET
112 
113 #define GETATARGET targ = (PL_op->op_flags & OPf_STACKED ? sp[-1] : PAD_SV(PL_op->op_targ))
114 #define dATARGET SV * GETATARGET
115 
116 #define dTARG SV *targ
117 
118 #define NORMAL PL_op->op_next
119 #define DIE return Perl_die
120 
121 /*
122 =for apidoc Amn;||PUTBACK
123 Closing bracket for XSUB arguments.  This is usually handled by C<xsubpp>.
124 See C<L</PUSHMARK>> and L<perlcall> for other uses.
125 
126 =for apidoc Amn|SV*|POPs
127 Pops an SV off the stack.
128 
129 =for apidoc Amn|char*|POPp
130 Pops a string off the stack.
131 
132 =for apidoc Amn|char*|POPpx
133 Pops a string off the stack.  Identical to POPp.  There are two names for
134 historical reasons.
135 
136 =for apidoc Amn|char*|POPpbytex
137 Pops a string off the stack which must consist of bytes i.e. characters < 256.
138 
139 =for apidoc Amn|NV|POPn
140 Pops a double off the stack.
141 
142 =for apidoc Amn|IV|POPi
143 Pops an integer off the stack.
144 
145 =for apidoc Amn|UV|POPu
146 Pops an unsigned integer off the stack.
147 
148 =for apidoc Amn|long|POPl
149 Pops a long off the stack.
150 
151 =for apidoc Amn|long|POPul
152 Pops an unsigned long off the stack.
153 
154 =cut
155 */
156 
157 #define PUTBACK		PL_stack_sp = sp
158 #define RETURN		return (PUTBACK, NORMAL)
159 #define RETURNOP(o)	return (PUTBACK, o)
160 #define RETURNX(x)	return (x, PUTBACK, NORMAL)
161 
162 #define POPs		(*sp--)
163 #define POPp		POPpx
164 #define POPpx		(SvPVx_nolen(POPs))
165 #define POPpconstx	(SvPVx_nolen_const(POPs))
166 #define POPpbytex	(SvPVbytex_nolen(POPs))
167 #define POPn		(SvNVx(POPs))
168 #define POPi		((IV)SvIVx(POPs))
169 #define POPu		((UV)SvUVx(POPs))
170 #define POPl		((long)SvIVx(POPs))
171 #define POPul		((unsigned long)SvIVx(POPs))
172 
173 #define TOPs		(*sp)
174 #define TOPm1s		(*(sp-1))
175 #define TOPp1s		(*(sp+1))
176 #define TOPp		TOPpx
177 #define TOPpx		(SvPV_nolen(TOPs))
178 #define TOPn		(SvNV(TOPs))
179 #define TOPi		((IV)SvIV(TOPs))
180 #define TOPu		((UV)SvUV(TOPs))
181 #define TOPl		((long)SvIV(TOPs))
182 #define TOPul		((unsigned long)SvUV(TOPs))
183 
184 /* Go to some pains in the rare event that we must extend the stack. */
185 
186 /*
187 =for apidoc Am|void|EXTEND|SP|SSize_t nitems
188 Used to extend the argument stack for an XSUB's return values.  Once
189 used, guarantees that there is room for at least C<nitems> to be pushed
190 onto the stack.
191 
192 =for apidoc Am|void|PUSHs|SV* sv
193 Push an SV onto the stack.  The stack must have room for this element.
194 Does not handle 'set' magic.  Does not use C<TARG>.  See also
195 C<L</PUSHmortal>>, C<L</XPUSHs>>, and C<L</XPUSHmortal>>.
196 
197 =for apidoc Am|void|PUSHp|char* str|STRLEN len
198 Push a string onto the stack.  The stack must have room for this element.
199 The C<len> indicates the length of the string.  Handles 'set' magic.  Uses
200 C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to declare it.  Do not
201 call multiple C<TARG>-oriented macros to return lists from XSUB's - see
202 C<L</mPUSHp>> instead.  See also C<L</XPUSHp>> and C<L</mXPUSHp>>.
203 
204 =for apidoc Am|void|PUSHpvs|"literal string"
205 A variation on C<PUSHp> that takes a literal string and calculates its size
206 directly.
207 
208 =for apidoc Am|void|PUSHn|NV nv
209 Push a double onto the stack.  The stack must have room for this element.
210 Handles 'set' magic.  Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be
211 called to declare it.  Do not call multiple C<TARG>-oriented macros to
212 return lists from XSUB's - see C<L</mPUSHn>> instead.  See also C<L</XPUSHn>>
213 and C<L</mXPUSHn>>.
214 
215 =for apidoc Am|void|PUSHi|IV iv
216 Push an integer onto the stack.  The stack must have room for this element.
217 Handles 'set' magic.  Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be
218 called to declare it.  Do not call multiple C<TARG>-oriented macros to
219 return lists from XSUB's - see C<L</mPUSHi>> instead.  See also C<L</XPUSHi>>
220 and C<L</mXPUSHi>>.
221 
222 =for apidoc Am|void|PUSHu|UV uv
223 Push an unsigned integer onto the stack.  The stack must have room for this
224 element.  Handles 'set' magic.  Uses C<TARG>, so C<dTARGET> or C<dXSTARG>
225 should be called to declare it.  Do not call multiple C<TARG>-oriented
226 macros to return lists from XSUB's - see C<L</mPUSHu>> instead.  See also
227 C<L</XPUSHu>> and C<L</mXPUSHu>>.
228 
229 =for apidoc Am|void|XPUSHs|SV* sv
230 Push an SV onto the stack, extending the stack if necessary.  Does not
231 handle 'set' magic.  Does not use C<TARG>.  See also C<L</XPUSHmortal>>,
232 C<PUSHs> and C<PUSHmortal>.
233 
234 =for apidoc Am|void|XPUSHp|char* str|STRLEN len
235 Push a string onto the stack, extending the stack if necessary.  The C<len>
236 indicates the length of the string.  Handles 'set' magic.  Uses C<TARG>, so
237 C<dTARGET> or C<dXSTARG> should be called to declare it.  Do not call
238 multiple C<TARG>-oriented macros to return lists from XSUB's - see
239 C<L</mXPUSHp>> instead.  See also C<L</PUSHp>> and C<L</mPUSHp>>.
240 
241 =for apidoc Am|void|XPUSHpvs|"literal string"
242 A variation on C<XPUSHp> that takes a literal string and calculates its size
243 directly.
244 
245 =for apidoc Am|void|XPUSHn|NV nv
246 Push a double onto the stack, extending the stack if necessary.  Handles
247 'set' magic.  Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to
248 declare it.  Do not call multiple C<TARG>-oriented macros to return lists
249 from XSUB's - see C<L</mXPUSHn>> instead.  See also C<L</PUSHn>> and
250 C<L</mPUSHn>>.
251 
252 =for apidoc Am|void|XPUSHi|IV iv
253 Push an integer onto the stack, extending the stack if necessary.  Handles
254 'set' magic.  Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to
255 declare it.  Do not call multiple C<TARG>-oriented macros to return lists
256 from XSUB's - see C<L</mXPUSHi>> instead.  See also C<L</PUSHi>> and
257 C<L</mPUSHi>>.
258 
259 =for apidoc Am|void|XPUSHu|UV uv
260 Push an unsigned integer onto the stack, extending the stack if necessary.
261 Handles 'set' magic.  Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be
262 called to declare it.  Do not call multiple C<TARG>-oriented macros to
263 return lists from XSUB's - see C<L</mXPUSHu>> instead.  See also C<L</PUSHu>> and
264 C<L</mPUSHu>>.
265 
266 =for apidoc Am|void|mPUSHs|SV* sv
267 Push an SV onto the stack and mortalizes the SV.  The stack must have room
268 for this element.  Does not use C<TARG>.  See also C<L</PUSHs>> and
269 C<L</mXPUSHs>>.
270 
271 =for apidoc Amn|void|PUSHmortal
272 Push a new mortal SV onto the stack.  The stack must have room for this
273 element.  Does not use C<TARG>.  See also C<L</PUSHs>>, C<L</XPUSHmortal>> and
274 C<L</XPUSHs>>.
275 
276 =for apidoc Am|void|mPUSHp|char* str|STRLEN len
277 Push a string onto the stack.  The stack must have room for this element.
278 The C<len> indicates the length of the string.  Does not use C<TARG>.
279 See also C<L</PUSHp>>, C<L</mXPUSHp>> and C<L</XPUSHp>>.
280 
281 =for apidoc Am|void|mPUSHpvs|"literal string"
282 A variation on C<mPUSHp> that takes a literal string and calculates its size
283 directly.
284 
285 =for apidoc Am|void|mPUSHn|NV nv
286 Push a double onto the stack.  The stack must have room for this element.
287 Does not use C<TARG>.  See also C<L</PUSHn>>, C<L</mXPUSHn>> and C<L</XPUSHn>>.
288 
289 =for apidoc Am|void|mPUSHi|IV iv
290 Push an integer onto the stack.  The stack must have room for this element.
291 Does not use C<TARG>.  See also C<L</PUSHi>>, C<L</mXPUSHi>> and C<L</XPUSHi>>.
292 
293 =for apidoc Am|void|mPUSHu|UV uv
294 Push an unsigned integer onto the stack.  The stack must have room for this
295 element.  Does not use C<TARG>.  See also C<L</PUSHu>>, C<L</mXPUSHu>> and
296 C<L</XPUSHu>>.
297 
298 =for apidoc Am|void|mXPUSHs|SV* sv
299 Push an SV onto the stack, extending the stack if necessary and mortalizes
300 the SV.  Does not use C<TARG>.  See also C<L</XPUSHs>> and C<L</mPUSHs>>.
301 
302 =for apidoc Amn|void|XPUSHmortal
303 Push a new mortal SV onto the stack, extending the stack if necessary.
304 Does not use C<TARG>.  See also C<L</XPUSHs>>, C<L</PUSHmortal>> and
305 C<L</PUSHs>>.
306 
307 =for apidoc Am|void|mXPUSHp|char* str|STRLEN len
308 Push a string onto the stack, extending the stack if necessary.  The C<len>
309 indicates the length of the string.  Does not use C<TARG>.  See also
310 C<L</XPUSHp>>, C<mPUSHp> and C<PUSHp>.
311 
312 =for apidoc Am|void|mXPUSHpvs|"literal string"
313 A variation on C<mXPUSHp> that takes a literal string and calculates its size
314 directly.
315 
316 =for apidoc Am|void|mXPUSHn|NV nv
317 Push a double onto the stack, extending the stack if necessary.
318 Does not use C<TARG>.  See also C<L</XPUSHn>>, C<L</mPUSHn>> and C<L</PUSHn>>.
319 
320 =for apidoc Am|void|mXPUSHi|IV iv
321 Push an integer onto the stack, extending the stack if necessary.
322 Does not use C<TARG>.  See also C<L</XPUSHi>>, C<L</mPUSHi>> and C<L</PUSHi>>.
323 
324 =for apidoc Am|void|mXPUSHu|UV uv
325 Push an unsigned integer onto the stack, extending the stack if necessary.
326 Does not use C<TARG>.  See also C<L</XPUSHu>>, C<L</mPUSHu>> and C<L</PUSHu>>.
327 
328 =cut
329 */
330 
331 /* EXTEND_HWM_SET: note the high-water-mark to which the stack has been
332  * requested to be extended (which is likely to be less than PL_stack_max)
333  */
334 #if defined DEBUGGING && !defined DEBUGGING_RE_ONLY
335 #  define EXTEND_HWM_SET(p, n)                                     \
336         STMT_START {                                               \
337             SSize_t extend_hwm_set_ix = (p) - PL_stack_base + (n); \
338             if (extend_hwm_set_ix > PL_curstackinfo->si_stack_hwm) \
339                 PL_curstackinfo->si_stack_hwm = extend_hwm_set_ix; \
340         } STMT_END
341 #else
342 #  define EXTEND_HWM_SET(p, n) NOOP
343 #endif
344 
345 /* _EXTEND_SAFE_N(n): private helper macro for EXTEND().
346  * Tests whether the value of n would be truncated when implicitly cast to
347  * SSize_t as an arg to stack_grow(). If so, sets it to -1 instead to
348  * trigger a panic. It will be constant folded on platforms where this
349  * can't happen.
350  */
351 
352 #define _EXTEND_SAFE_N(n) \
353         (sizeof(n) > sizeof(SSize_t) && ((SSize_t)(n) != (n)) ? -1 : (n))
354 
355 #ifdef STRESS_REALLOC
356 # define EXTEND_SKIP(p, n) EXTEND_HWM_SET(p, n)
357 
358 # define EXTEND(p,n)   STMT_START {                                     \
359                            sp = stack_grow(sp,p,_EXTEND_SAFE_N(n));     \
360                            PERL_UNUSED_VAR(sp);                         \
361                        } STMT_END
362 /* Same thing, but update mark register too. */
363 # define MEXTEND(p,n)   STMT_START {                                    \
364                             const SSize_t markoff = mark - PL_stack_base; \
365                             sp = stack_grow(sp,p,_EXTEND_SAFE_N(n));    \
366                             mark = PL_stack_base + markoff;             \
367                             PERL_UNUSED_VAR(sp);                        \
368                         } STMT_END
369 #else
370 
371 /* _EXTEND_NEEDS_GROW(p,n): private helper macro for EXTEND().
372  * Tests to see whether n is too big and we need to grow the stack. Be
373  * very careful if modifying this. There are many ways to get things wrong
374  * (wrapping, truncating etc) that could cause a false negative and cause
375  * the call to stack_grow() to be skipped. On the other hand, false
376  * positives are safe.
377  * Bear in mind that sizeof(p) may be less than, equal to, or greater
378  * than sizeof(n), and while n is documented to be signed, someone might
379  * pass an unsigned value or expression. In general don't use casts to
380  * avoid warnings; instead expect the caller to fix their code.
381  * It is legal for p to be greater than PL_stack_max.
382  * If the allocated stack is already very large but current usage is
383  * small, then PL_stack_max - p might wrap round to a negative value, but
384  * this just gives a safe false positive
385  */
386 
387 #  define _EXTEND_NEEDS_GROW(p,n) ((n) < 0 || PL_stack_max - (p) < (n))
388 
389 
390 /* EXTEND_SKIP(): used for where you would normally call EXTEND(), but
391  * you know for sure that a previous op will have already extended the
392  * stack sufficiently.  For example pp_enteriter ensures that there
393  * is always at least 1 free slot, so pp_iter can return &PL_sv_yes/no
394  * without checking each time. Calling EXTEND_SKIP() defeats the HWM
395  * debugging mechanism which would otherwise whine
396  */
397 
398 #  define EXTEND_SKIP(p, n) STMT_START {                                \
399                                 EXTEND_HWM_SET(p, n);                   \
400                                 assert(!_EXTEND_NEEDS_GROW(p,n));       \
401                             } STMT_END
402 
403 
404 #  define EXTEND(p,n)   STMT_START {                                    \
405                          EXTEND_HWM_SET(p, n);                          \
406                          if (UNLIKELY(_EXTEND_NEEDS_GROW(p,n))) {       \
407                            sp = stack_grow(sp,p,_EXTEND_SAFE_N(n));     \
408                            PERL_UNUSED_VAR(sp);                         \
409                          }                                              \
410                         } STMT_END
411 /* Same thing, but update mark register too. */
412 #  define MEXTEND(p,n)  STMT_START {                                    \
413                          EXTEND_HWM_SET(p, n);                          \
414                          if (UNLIKELY(_EXTEND_NEEDS_GROW(p,n))) {       \
415                            const SSize_t markoff = mark - PL_stack_base;\
416                            sp = stack_grow(sp,p,_EXTEND_SAFE_N(n));     \
417                            mark = PL_stack_base + markoff;              \
418                            PERL_UNUSED_VAR(sp);                         \
419                          }                                              \
420                         } STMT_END
421 #endif
422 
423 
424 /* set TARG to the IV value i. If do_taint is false,
425  * assume that PL_tainted can never be true */
426 #define TARGi(i, do_taint) \
427     STMT_START {                                                        \
428         IV TARGi_iv = i;                                                \
429         if (LIKELY(                                                     \
430               ((SvFLAGS(TARG) & (SVTYPEMASK|SVf_THINKFIRST|SVf_IVisUV)) == SVt_IV) \
431             & (do_taint ? !TAINT_get : 1)))                             \
432         {                                                               \
433             /* Cheap SvIOK_only().                                      \
434              * Assert that flags which SvIOK_only() would test or       \
435              * clear can't be set, because we're SVt_IV */              \
436             assert(!(SvFLAGS(TARG) &                                    \
437                 (SVf_OOK|SVf_UTF8|(SVf_OK & ~(SVf_IOK|SVp_IOK)))));     \
438             SvFLAGS(TARG) |= (SVf_IOK|SVp_IOK);                         \
439             /* SvIV_set() where sv_any points to head */                \
440             TARG->sv_u.svu_iv = TARGi_iv;                               \
441         }                                                               \
442         else                                                            \
443             sv_setiv_mg(targ, TARGi_iv);                                \
444     } STMT_END
445 
446 /* set TARG to the UV value u. If do_taint is false,
447  * assume that PL_tainted can never be true */
448 #define TARGu(u, do_taint) \
449     STMT_START {                                                        \
450         UV TARGu_uv = u;                                                \
451         if (LIKELY(                                                     \
452               ((SvFLAGS(TARG) & (SVTYPEMASK|SVf_THINKFIRST|SVf_IVisUV)) == SVt_IV) \
453             & (do_taint ? !TAINT_get : 1)                               \
454             & (TARGu_uv <= (UV)IV_MAX)))                                \
455         {                                                               \
456             /* Cheap SvIOK_only().                                      \
457              * Assert that flags which SvIOK_only() would test or       \
458              * clear can't be set, because we're SVt_IV */              \
459             assert(!(SvFLAGS(TARG) &                                    \
460                 (SVf_OOK|SVf_UTF8|(SVf_OK & ~(SVf_IOK|SVp_IOK)))));     \
461             SvFLAGS(TARG) |= (SVf_IOK|SVp_IOK);                         \
462             /* SvIV_set() where sv_any points to head */                \
463             TARG->sv_u.svu_iv = TARGu_uv;                               \
464         }                                                               \
465         else                                                            \
466             sv_setuv_mg(targ, TARGu_uv);                                \
467     } STMT_END
468 
469 /* set TARG to the NV value n. If do_taint is false,
470  * assume that PL_tainted can never be true */
471 #define TARGn(n, do_taint) \
472     STMT_START {                                                        \
473         NV TARGn_nv = n;                                                \
474         if (LIKELY(                                                     \
475               ((SvFLAGS(TARG) & (SVTYPEMASK|SVf_THINKFIRST)) == SVt_NV) \
476             & (do_taint ? !TAINT_get : 1)))                             \
477         {                                                               \
478             /* Cheap SvNOK_only().                                      \
479              * Assert that flags which SvNOK_only() would test or       \
480              * clear can't be set, because we're SVt_NV */              \
481             assert(!(SvFLAGS(TARG) &                                    \
482                 (SVf_OOK|SVf_UTF8|(SVf_OK & ~(SVf_NOK|SVp_NOK)))));     \
483             SvFLAGS(TARG) |= (SVf_NOK|SVp_NOK);                         \
484             SvNV_set(TARG, TARGn_nv);                                   \
485         }                                                               \
486         else                                                            \
487             sv_setnv_mg(targ, TARGn_nv);                                \
488     } STMT_END
489 
490 #define PUSHs(s)	(*++sp = (s))
491 #define PUSHTARG	STMT_START { SvSETMAGIC(TARG); PUSHs(TARG); } STMT_END
492 #define PUSHp(p,l)	STMT_START { sv_setpvn(TARG, (p), (l)); PUSHTARG; } STMT_END
493 #define PUSHpvs(s)      PUSHp("" s "", sizeof(s)-1)
494 #define PUSHn(n)	STMT_START { TARGn(n,1); PUSHs(TARG); } STMT_END
495 #define PUSHi(i)	STMT_START { TARGi(i,1); PUSHs(TARG); } STMT_END
496 #define PUSHu(u)	STMT_START { TARGu(u,1); PUSHs(TARG); } STMT_END
497 
498 #define XPUSHs(s)	STMT_START { EXTEND(sp,1); *++sp = (s); } STMT_END
499 #define XPUSHTARG	STMT_START { SvSETMAGIC(TARG); XPUSHs(TARG); } STMT_END
500 #define XPUSHp(p,l)	STMT_START { sv_setpvn(TARG, (p), (l)); XPUSHTARG; } STMT_END
501 #define XPUSHpvs(s)     XPUSHp("" s "", sizeof(s)-1)
502 #define XPUSHn(n)	STMT_START { TARGn(n,1); XPUSHs(TARG); } STMT_END
503 #define XPUSHi(i)	STMT_START { TARGi(i,1); XPUSHs(TARG); } STMT_END
504 #define XPUSHu(u)	STMT_START { TARGu(u,1); XPUSHs(TARG); } STMT_END
505 #define XPUSHundef	STMT_START { SvOK_off(TARG); XPUSHs(TARG); } STMT_END
506 
507 #define mPUSHs(s)	PUSHs(sv_2mortal(s))
508 #define PUSHmortal	PUSHs(sv_newmortal())
509 #define mPUSHp(p,l)	PUSHs(newSVpvn_flags((p), (l), SVs_TEMP))
510 #define mPUSHpvs(s)     mPUSHp("" s "", sizeof(s)-1)
511 #define mPUSHn(n)	sv_setnv(PUSHmortal, (NV)(n))
512 #define mPUSHi(i)	sv_setiv(PUSHmortal, (IV)(i))
513 #define mPUSHu(u)	sv_setuv(PUSHmortal, (UV)(u))
514 
515 #define mXPUSHs(s)	XPUSHs(sv_2mortal(s))
516 #define XPUSHmortal	XPUSHs(sv_newmortal())
517 #define mXPUSHp(p,l)	STMT_START { EXTEND(sp,1); mPUSHp((p), (l)); } STMT_END
518 #define mXPUSHpvs(s)    mXPUSHp("" s "", sizeof(s)-1)
519 #define mXPUSHn(n)	STMT_START { EXTEND(sp,1); mPUSHn(n); } STMT_END
520 #define mXPUSHi(i)	STMT_START { EXTEND(sp,1); mPUSHi(i); } STMT_END
521 #define mXPUSHu(u)	STMT_START { EXTEND(sp,1); mPUSHu(u); } STMT_END
522 
523 #define SETs(s)		(*sp = s)
524 #define SETTARG		STMT_START { SvSETMAGIC(TARG); SETs(TARG); } STMT_END
525 #define SETp(p,l)	STMT_START { sv_setpvn(TARG, (p), (l)); SETTARG; } STMT_END
526 #define SETn(n)		STMT_START { TARGn(n,1); SETs(TARG); } STMT_END
527 #define SETi(i)		STMT_START { TARGi(i,1); SETs(TARG); } STMT_END
528 #define SETu(u)		STMT_START { TARGu(u,1); SETs(TARG); } STMT_END
529 
530 #define dTOPss		SV *sv = TOPs
531 #define dPOPss		SV *sv = POPs
532 #define dTOPnv		NV value = TOPn
533 #define dPOPnv		NV value = POPn
534 #define dPOPnv_nomg	NV value = (sp--, SvNV_nomg(TOPp1s))
535 #define dTOPiv		IV value = TOPi
536 #define dPOPiv		IV value = POPi
537 #define dTOPuv		UV value = TOPu
538 #define dPOPuv		UV value = POPu
539 
540 #define dPOPXssrl(X)	SV *right = POPs; SV *left = CAT2(X,s)
541 #define dPOPXnnrl(X)	NV right = POPn; NV left = CAT2(X,n)
542 #define dPOPXiirl(X)	IV right = POPi; IV left = CAT2(X,i)
543 
544 #define USE_LEFT(sv) \
545         (SvOK(sv) || !(PL_op->op_flags & OPf_STACKED))
546 #define dPOPXiirl_ul_nomg(X) \
547     IV right = (sp--, SvIV_nomg(TOPp1s));		\
548     SV *leftsv = CAT2(X,s);				\
549     IV left = USE_LEFT(leftsv) ? SvIV_nomg(leftsv) : 0
550 
551 #define dPOPPOPssrl	dPOPXssrl(POP)
552 #define dPOPPOPnnrl	dPOPXnnrl(POP)
553 #define dPOPPOPiirl	dPOPXiirl(POP)
554 
555 #define dPOPTOPssrl	dPOPXssrl(TOP)
556 #define dPOPTOPnnrl	dPOPXnnrl(TOP)
557 #define dPOPTOPnnrl_nomg \
558     NV right = SvNV_nomg(TOPs); NV left = (sp--, SvNV_nomg(TOPs))
559 #define dPOPTOPiirl	dPOPXiirl(TOP)
560 #define dPOPTOPiirl_ul_nomg dPOPXiirl_ul_nomg(TOP)
561 #define dPOPTOPiirl_nomg \
562     IV right = SvIV_nomg(TOPs); IV left = (sp--, SvIV_nomg(TOPs))
563 
564 #define RETPUSHYES	RETURNX(PUSHs(&PL_sv_yes))
565 #define RETPUSHNO	RETURNX(PUSHs(&PL_sv_no))
566 #define RETPUSHUNDEF	RETURNX(PUSHs(&PL_sv_undef))
567 
568 #define RETSETYES	RETURNX(SETs(&PL_sv_yes))
569 #define RETSETNO	RETURNX(SETs(&PL_sv_no))
570 #define RETSETUNDEF	RETURNX(SETs(&PL_sv_undef))
571 #define RETSETTARG	STMT_START { SETTARG; RETURN; } STMT_END
572 
573 #define ARGTARG		PL_op->op_targ
574 
575 #define MAXARG		(PL_op->op_private & OPpARG4_MASK)
576 
577 #define SWITCHSTACK(f,t) \
578     STMT_START {							\
579         AvFILLp(f) = sp - PL_stack_base;				\
580         PL_stack_base = AvARRAY(t);					\
581         PL_stack_max = PL_stack_base + AvMAX(t);			\
582         sp = PL_stack_sp = PL_stack_base + AvFILLp(t);			\
583         PL_curstack = t;						\
584     } STMT_END
585 
586 #define EXTEND_MORTAL(n) \
587     STMT_START {						\
588         SSize_t eMiX = PL_tmps_ix + (n);			\
589         if (UNLIKELY(eMiX >= PL_tmps_max))			\
590             (void)Perl_tmps_grow_p(aTHX_ eMiX);			\
591     } STMT_END
592 
593 #define AMGf_noright	1
594 #define AMGf_noleft	2
595 #define AMGf_assign	4       /* op supports mutator variant, e.g. $x += 1 */
596 #define AMGf_unary	8
597 #define AMGf_numeric	0x10	/* for Perl_try_amagic_bin */
598 
599 #define AMGf_want_list	0x40
600 #define AMGf_numarg	0x80
601 
602 
603 /* do SvGETMAGIC on the stack args before checking for overload */
604 
605 #define tryAMAGICun_MG(method, flags) STMT_START { \
606         if ( UNLIKELY((SvFLAGS(TOPs) & (SVf_ROK|SVs_GMG))) \
607                 && Perl_try_amagic_un(aTHX_ method, flags)) \
608             return NORMAL; \
609     } STMT_END
610 #define tryAMAGICbin_MG(method, flags) STMT_START { \
611         if ( UNLIKELY(((SvFLAGS(TOPm1s)|SvFLAGS(TOPs)) & (SVf_ROK|SVs_GMG))) \
612                 && Perl_try_amagic_bin(aTHX_ method, flags)) \
613             return NORMAL; \
614     } STMT_END
615 
616 #define AMG_CALLunary(sv,meth) \
617     amagic_call(sv,&PL_sv_undef, meth, AMGf_noright | AMGf_unary)
618 
619 /* No longer used in core. Use AMG_CALLunary instead */
620 #define AMG_CALLun(sv,meth) AMG_CALLunary(sv, CAT2(meth,_amg))
621 
622 #define tryAMAGICunTARGETlist(meth, jump)			\
623     STMT_START {						\
624         dSP;							\
625         SV *tmpsv;						\
626         SV *arg= *sp;						\
627         U8 gimme = GIMME_V;                                    \
628         if (UNLIKELY(SvAMAGIC(arg) &&				\
629             (tmpsv = amagic_call(arg, &PL_sv_undef, meth,	\
630                                  AMGf_want_list | AMGf_noright	\
631                                 |AMGf_unary))))                 \
632         {                                       		\
633             SPAGAIN;						\
634             if (gimme == G_VOID) {                              \
635                 NOOP;                                           \
636             }                                                   \
637             else if (gimme == G_LIST) {				\
638                 SSize_t i;                                      \
639                 SSize_t len;                                    \
640                 assert(SvTYPE(tmpsv) == SVt_PVAV);              \
641                 len = av_count((AV *)tmpsv);                    \
642                 (void)POPs; /* get rid of the arg */            \
643                 EXTEND(sp, len);                                \
644                 for (i = 0; i < len; ++i)                       \
645                     PUSHs(av_shift((AV *)tmpsv));               \
646             }                                                   \
647             else { /* AMGf_want_scalar */                       \
648                 dATARGET; /* just use the arg's location */     \
649                 sv_setsv(TARG, tmpsv);                          \
650                 if (PL_op->op_flags & OPf_STACKED)              \
651                     sp--;                                       \
652                 SETTARG;                                        \
653             }                                                   \
654             PUTBACK;						\
655             if (jump) {						\
656                 OP *jump_o = NORMAL->op_next;                   \
657                 while (jump_o->op_type == OP_NULL)		\
658                     jump_o = jump_o->op_next;			\
659                 assert(jump_o->op_type == OP_ENTERSUB);		\
660                 (void)POPMARK;                                        \
661                 return jump_o->op_next;				\
662             }							\
663             return NORMAL;					\
664         }							\
665     } STMT_END
666 
667 /* This is no longer used anywhere in the core. You might wish to consider
668    calling amagic_deref_call() directly, as it has a cleaner interface.  */
669 #define tryAMAGICunDEREF(meth)						\
670     STMT_START {							\
671         sv = amagic_deref_call(*sp, CAT2(meth,_amg));			\
672         SPAGAIN;							\
673     } STMT_END
674 
675 
676 /* 2019: no longer used in core */
677 #define opASSIGN (PL_op->op_flags & OPf_STACKED)
678 
679 /*
680 =for apidoc mnU||LVRET
681 True if this op will be the return value of an lvalue subroutine
682 
683 =cut */
684 #define LVRET ((PL_op->op_private & OPpMAYBE_LVSUB) && is_lvalue_sub())
685 
686 #define SvCANEXISTDELETE(sv) \
687  (!SvRMAGICAL(sv)            \
688   || !(mg = mg_find((const SV *) sv, PERL_MAGIC_tied))           \
689   || (   (stash = SvSTASH(SvRV(SvTIED_obj(MUTABLE_SV(sv), mg)))) \
690       && gv_fetchmethod_autoload(stash, "EXISTS", TRUE)          \
691       && gv_fetchmethod_autoload(stash, "DELETE", TRUE)          \
692      )                       \
693   )
694 
695 #ifdef PERL_CORE
696 
697 /* These are just for Perl_tied_method(), which is not part of the public API.
698    Use 0x04 rather than the next available bit, to help the compiler if the
699    architecture can generate more efficient instructions.  */
700 #  define TIED_METHOD_MORTALIZE_NOT_NEEDED	0x04
701 #  define TIED_METHOD_ARGUMENTS_ON_STACK	0x08
702 #  define TIED_METHOD_SAY			0x10
703 
704 /* Used in various places that need to dereference a glob or globref */
705 #  define MAYBE_DEREF_GV_flags(sv,phlags)                          \
706     (                                                               \
707         (void)(((phlags) & SV_GMAGIC) && (SvGETMAGIC(sv),0)),        \
708         isGV_with_GP(sv)                                              \
709           ? (GV *)(sv)                                                \
710           : SvROK(sv) && SvTYPE(SvRV(sv)) <= SVt_PVLV &&               \
711             (SvGETMAGIC(SvRV(sv)), isGV_with_GP(SvRV(sv)))              \
712              ? (GV *)SvRV(sv)                                            \
713              : NULL                                                       \
714     )
715 #  define MAYBE_DEREF_GV(sv)      MAYBE_DEREF_GV_flags(sv,SV_GMAGIC)
716 #  define MAYBE_DEREF_GV_nomg(sv) MAYBE_DEREF_GV_flags(sv,0)
717 
718 #  define FIND_RUNCV_padid_eq	1
719 #  define FIND_RUNCV_level_eq	2
720 
721 #endif
722 
723 /*
724  * ex: set ts=8 sts=4 sw=4 et:
725  */
726