This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add 5.23.4 epigraph
[perl5.git] / pp.h
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 =head1 Stack Manipulation Macros
15
16 =for apidoc AmU||SP
17 Stack pointer.  This is usually handled by C<xsubpp>.  See C<L</dSP>> and
18 C<SPAGAIN>.
19
20 =for apidoc AmU||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 Ams||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 ms||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 Ams||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 Ams||dORIGMARK
43 Saves the original stack mark for the XSUB.  See C<L</ORIGMARK>>.
44
45 =for apidoc AmU||ORIGMARK
46 The original stack mark for the XSUB.  See C<L</dORIGMARK>>.
47
48 =for apidoc Ams||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 #define TARG targ
57
58 #define PUSHMARK(p)     \
59         STMT_START {                                    \
60             I32 * mark_stack_entry;                     \
61             if (UNLIKELY((mark_stack_entry = ++PL_markstack_ptr) == PL_markstack_max))  \
62             mark_stack_entry = markstack_grow();                                        \
63             *mark_stack_entry  = (I32)((p) - PL_stack_base);                            \
64         } STMT_END
65
66 #define TOPMARK         (*PL_markstack_ptr)
67 #define POPMARK         (*PL_markstack_ptr--)
68
69 #define dSP             SV **sp = PL_stack_sp
70 #define djSP            dSP
71 #define dMARK           SV **mark = PL_stack_base + POPMARK
72 #define dORIGMARK       const I32 origmark = (I32)(mark - PL_stack_base)
73 #define ORIGMARK        (PL_stack_base + origmark)
74
75 #define SPAGAIN         sp = PL_stack_sp
76 #define MSPAGAIN        STMT_START { sp = PL_stack_sp; mark = ORIGMARK; } STMT_END
77
78 #define GETTARGETSTACKED targ = (PL_op->op_flags & OPf_STACKED ? POPs : PAD_SV(PL_op->op_targ))
79 #define dTARGETSTACKED SV * GETTARGETSTACKED
80
81 #define GETTARGET targ = PAD_SV(PL_op->op_targ)
82 #define dTARGET SV * GETTARGET
83
84 #define GETATARGET targ = (PL_op->op_flags & OPf_STACKED ? sp[-1] : PAD_SV(PL_op->op_targ))
85 #define dATARGET SV * GETATARGET
86
87 #define dTARG SV *targ
88
89 #define NORMAL PL_op->op_next
90 #define DIE return Perl_die
91
92 /*
93 =for apidoc Ams||PUTBACK
94 Closing bracket for XSUB arguments.  This is usually handled by C<xsubpp>.
95 See C<L</PUSHMARK>> and L<perlcall> for other uses.
96
97 =for apidoc Amn|SV*|POPs
98 Pops an SV off the stack.
99
100 =for apidoc Amn|char*|POPp
101 Pops a string off the stack.
102
103 =for apidoc Amn|char*|POPpx
104 Pops a string off the stack.  Identical to POPp.  There are two names for
105 historical reasons.
106
107 =for apidoc Amn|char*|POPpbytex
108 Pops a string off the stack which must consist of bytes i.e. characters < 256.
109
110 =for apidoc Amn|NV|POPn
111 Pops a double off the stack.
112
113 =for apidoc Amn|IV|POPi
114 Pops an integer off the stack.
115
116 =for apidoc Amn|UV|POPu
117 Pops an unsigned integer off the stack.
118
119 =for apidoc Amn|long|POPl
120 Pops a long off the stack.
121
122 =for apidoc Amn|long|POPul
123 Pops an unsigned long off the stack.
124
125 =cut
126 */
127
128 #define PUTBACK         PL_stack_sp = sp
129 #define RETURN          return (PUTBACK, NORMAL)
130 #define RETURNOP(o)     return (PUTBACK, o)
131 #define RETURNX(x)      return (x, PUTBACK, NORMAL)
132
133 #define POPs            (*sp--)
134 #define POPp            POPpx
135 #define POPpx           (SvPVx_nolen(POPs))
136 #define POPpconstx      (SvPVx_nolen_const(POPs))
137 #define POPpbytex       (SvPVbytex_nolen(POPs))
138 #define POPn            (SvNVx(POPs))
139 #define POPi            ((IV)SvIVx(POPs))
140 #define POPu            ((UV)SvUVx(POPs))
141 #define POPl            ((long)SvIVx(POPs))
142 #define POPul           ((unsigned long)SvIVx(POPs))
143
144 #define TOPs            (*sp)
145 #define TOPm1s          (*(sp-1))
146 #define TOPp1s          (*(sp+1))
147 #define TOPp            TOPpx
148 #define TOPpx           (SvPV_nolen(TOPs))
149 #define TOPn            (SvNV(TOPs))
150 #define TOPi            ((IV)SvIV(TOPs))
151 #define TOPu            ((UV)SvUV(TOPs))
152 #define TOPl            ((long)SvIV(TOPs))
153 #define TOPul           ((unsigned long)SvUV(TOPs))
154
155 /* Go to some pains in the rare event that we must extend the stack. */
156
157 /*
158 =for apidoc Am|void|EXTEND|SP|SSize_t nitems
159 Used to extend the argument stack for an XSUB's return values.  Once
160 used, guarantees that there is room for at least C<nitems> to be pushed
161 onto the stack.
162
163 =for apidoc Am|void|PUSHs|SV* sv
164 Push an SV onto the stack.  The stack must have room for this element.
165 Does not handle 'set' magic.  Does not use C<TARG>.  See also
166 C<L</PUSHmortal>>, C<L</XPUSHs>>, and C<L</XPUSHmortal>>.
167
168 =for apidoc Am|void|PUSHp|char* str|STRLEN len
169 Push a string onto the stack.  The stack must have room for this element.
170 The C<len> indicates the length of the string.  Handles 'set' magic.  Uses
171 C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to declare it.  Do not
172 call multiple C<TARG>-oriented macros to return lists from XSUB's - see
173 C<L</mPUSHp>> instead.  See also C<L</XPUSHp>> and C<L</mXPUSHp>>.
174
175 =for apidoc Am|void|PUSHn|NV nv
176 Push a double onto the stack.  The stack must have room for this element.
177 Handles 'set' magic.  Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be
178 called to declare it.  Do not call multiple C<TARG>-oriented macros to
179 return lists from XSUB's - see C<L</mPUSHn>> instead.  See also C<L</XPUSHn>>
180 and C<L</mXPUSHn>>.
181
182 =for apidoc Am|void|PUSHi|IV iv
183 Push an integer onto the stack.  The stack must have room for this element.
184 Handles 'set' magic.  Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be
185 called to declare it.  Do not call multiple C<TARG>-oriented macros to 
186 return lists from XSUB's - see C<L</mPUSHi>> instead.  See also C<L</XPUSHi>>
187 and C<L</mXPUSHi>>.
188
189 =for apidoc Am|void|PUSHu|UV uv
190 Push an unsigned integer onto the stack.  The stack must have room for this
191 element.  Handles 'set' magic.  Uses C<TARG>, so C<dTARGET> or C<dXSTARG>
192 should be called to declare it.  Do not call multiple C<TARG>-oriented
193 macros to return lists from XSUB's - see C<L</mPUSHu>> instead.  See also
194 C<L</XPUSHu>> and C<L</mXPUSHu>>.
195
196 =for apidoc Am|void|XPUSHs|SV* sv
197 Push an SV onto the stack, extending the stack if necessary.  Does not
198 handle 'set' magic.  Does not use C<TARG>.  See also C<L</XPUSHmortal>>,
199 C<PUSHs> and C<PUSHmortal>.
200
201 =for apidoc Am|void|XPUSHp|char* str|STRLEN len
202 Push a string onto the stack, extending the stack if necessary.  The C<len>
203 indicates the length of the string.  Handles 'set' magic.  Uses C<TARG>, so
204 C<dTARGET> or C<dXSTARG> should be called to declare it.  Do not call
205 multiple C<TARG>-oriented macros to return lists from XSUB's - see
206 C<L</mXPUSHp>> instead.  See also C<L</PUSHp>> and C<L</mPUSHp>>.
207
208 =for apidoc Am|void|XPUSHn|NV nv
209 Push a double onto the stack, extending the stack if necessary.  Handles
210 'set' magic.  Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to
211 declare it.  Do not call multiple C<TARG>-oriented macros to return lists
212 from XSUB's - see C<L</mXPUSHn>> instead.  See also C<L</PUSHn>> and
213 C<L</mPUSHn>>.
214
215 =for apidoc Am|void|XPUSHi|IV iv
216 Push an integer onto the stack, extending the stack if necessary.  Handles
217 'set' magic.  Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to
218 declare it.  Do not call multiple C<TARG>-oriented macros to return lists
219 from XSUB's - see C<L</mXPUSHi>> instead.  See also C<L</PUSHi>> and
220 C<L</mPUSHi>>.
221
222 =for apidoc Am|void|XPUSHu|UV uv
223 Push an unsigned integer onto the stack, extending the stack if necessary.
224 Handles 'set' magic.  Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be
225 called to declare it.  Do not call multiple C<TARG>-oriented macros to
226 return lists from XSUB's - see C<L</mXPUSHu>> instead.  See also C<L</PUSHu>> and
227 C<L</mPUSHu>>.
228
229 =for apidoc Am|void|mPUSHs|SV* sv
230 Push an SV onto the stack and mortalizes the SV.  The stack must have room
231 for this element.  Does not use C<TARG>.  See also C<L</PUSHs>> and
232 C<L</mXPUSHs>>.
233
234 =for apidoc Am|void|PUSHmortal
235 Push a new mortal SV onto the stack.  The stack must have room for this
236 element.  Does not use C<TARG>.  See also C<L</PUSHs>>, C<L</XPUSHmortal>> and
237 C<L</XPUSHs>>.
238
239 =for apidoc Am|void|mPUSHp|char* str|STRLEN len
240 Push a string onto the stack.  The stack must have room for this element.
241 The C<len> indicates the length of the string.  Does not use C<TARG>.
242 See also C<L</PUSHp>>, C<L</mXPUSHp>> and C<L</XPUSHp>>.
243
244 =for apidoc Am|void|mPUSHn|NV nv
245 Push a double onto the stack.  The stack must have room for this element.
246 Does not use C<TARG>.  See also C<L</PUSHn>>, C<L</mXPUSHn>> and C<L</XPUSHn>>.
247
248 =for apidoc Am|void|mPUSHi|IV iv
249 Push an integer onto the stack.  The stack must have room for this element.
250 Does not use C<TARG>.  See also C<L</PUSHi>>, C<L</mXPUSHi>> and C<L</XPUSHi>>.
251
252 =for apidoc Am|void|mPUSHu|UV uv
253 Push an unsigned integer onto the stack.  The stack must have room for this
254 element.  Does not use C<TARG>.  See also C<L</PUSHu>>, C<L</mXPUSHu>> and
255 C<L</XPUSHu>>.
256
257 =for apidoc Am|void|mXPUSHs|SV* sv
258 Push an SV onto the stack, extending the stack if necessary and mortalizes
259 the SV.  Does not use C<TARG>.  See also C<L</XPUSHs>> and C<L</mPUSHs>>.
260
261 =for apidoc Am|void|XPUSHmortal
262 Push a new mortal SV onto the stack, extending the stack if necessary.
263 Does not use C<TARG>.  See also C<L</XPUSHs>>, C<L</PUSHmortal>> and
264 C<L</PUSHs>>.
265
266 =for apidoc Am|void|mXPUSHp|char* str|STRLEN len
267 Push a string onto the stack, extending the stack if necessary.  The C<len>
268 indicates the length of the string.  Does not use C<TARG>.  See also
269 C<L</XPUSHp>>, C<mPUSHp> and C<PUSHp>.
270
271 =for apidoc Am|void|mXPUSHn|NV nv
272 Push a double onto the stack, extending the stack if necessary.
273 Does not use C<TARG>.  See also C<L</XPUSHn>>, C<L</mPUSHn>> and C<L</PUSHn>>.
274
275 =for apidoc Am|void|mXPUSHi|IV iv
276 Push an integer onto the stack, extending the stack if necessary.
277 Does not use C<TARG>.  See also C<L</XPUSHi>>, C<L</mPUSHi>> and C<L</PUSHi>>.
278
279 =for apidoc Am|void|mXPUSHu|UV uv
280 Push an unsigned integer onto the stack, extending the stack if necessary.
281 Does not use C<TARG>.  See also C<L</XPUSHu>>, C<L</mPUSHu>> and C<L</PUSHu>>.
282
283 =cut
284 */
285
286 /* _EXTEND_SAFE_N(n): private helper macro for EXTEND().
287  * Tests whether the value of n would be truncated when implicitly cast to
288  * SSize_t as an arg to stack_grow(). If so, sets it to -1 instead to
289  * trigger a panic. It will be constant folded on platforms where this
290  * can't happen.
291  */
292
293 #define _EXTEND_SAFE_N(n) \
294         (sizeof(n) > sizeof(SSize_t) && ((SSize_t)(n) != (n)) ? -1 : (n))
295
296 #ifdef STRESS_REALLOC
297 # define EXTEND(p,n)   STMT_START {                                     \
298                            sp = stack_grow(sp,p,_EXTEND_SAFE_N(n));     \
299                            PERL_UNUSED_VAR(sp);                         \
300                        } STMT_END
301 /* Same thing, but update mark register too. */
302 # define MEXTEND(p,n)   STMT_START {                                    \
303                             const SSize_t markoff = mark - PL_stack_base; \
304                             sp = stack_grow(sp,p,_EXTEND_SAFE_N(n));    \
305                             mark = PL_stack_base + markoff;             \
306                             PERL_UNUSED_VAR(sp);                        \
307                         } STMT_END
308 #else
309
310 /* _EXTEND_NEEDS_GROW(p,n): private helper macro for EXTEND().
311  * Tests to see whether n is too big and we need to grow the stack. Be
312  * very careful if modifying this. There are many ways to get things wrong
313  * (wrapping, truncating etc) that could cause a false negative and cause
314  * the call to stack_grow() to be skipped. On the other hand, false
315  * positives are safe.
316  * Bear in mind that sizeof(p) may be less than, equal to, or greater
317  * than sizeof(n), and while n is documented to be signed, someone might
318  * pass an unsigned value or expression. In general don't use casts to
319  * avoid warnings; instead expect the caller to fix their code.
320  * It is legal for p to be greater than PL_stack_max.
321  * If the allocated stack is already very large but current usage is
322  * small, then PL_stack_max - p might wrap round to a negative value, but
323  * this just gives a safe false positive
324  */
325
326 #  define _EXTEND_NEEDS_GROW(p,n) ( (n) < 0 || PL_stack_max - p < (n))
327
328 #  define EXTEND(p,n)   STMT_START {                                    \
329                          if (UNLIKELY(_EXTEND_NEEDS_GROW(p,n))) {       \
330                            sp = stack_grow(sp,p,_EXTEND_SAFE_N(n));     \
331                            PERL_UNUSED_VAR(sp);                         \
332                          } } STMT_END
333 /* Same thing, but update mark register too. */
334 #  define MEXTEND(p,n)  STMT_START {                                    \
335                          if (UNLIKELY(_EXTEND_NEEDS_GROW(p,n))) {       \
336                            const SSize_t markoff = mark - PL_stack_base;\
337                            sp = stack_grow(sp,p,_EXTEND_SAFE_N(n));     \
338                            mark = PL_stack_base + markoff;              \
339                            PERL_UNUSED_VAR(sp);                         \
340                          } } STMT_END
341 #endif
342
343 #define PUSHs(s)        (*++sp = (s))
344 #define PUSHTARG        STMT_START { SvSETMAGIC(TARG); PUSHs(TARG); } STMT_END
345 #define PUSHp(p,l)      STMT_START { sv_setpvn(TARG, (p), (l)); PUSHTARG; } STMT_END
346 #define PUSHn(n)        STMT_START { sv_setnv(TARG, (NV)(n)); PUSHTARG; } STMT_END
347 #define PUSHi(i)        STMT_START { sv_setiv(TARG, (IV)(i)); PUSHTARG; } STMT_END
348 #define PUSHu(u)        STMT_START { sv_setuv(TARG, (UV)(u)); PUSHTARG; } STMT_END
349
350 #define XPUSHs(s)       STMT_START { EXTEND(sp,1); *++sp = (s); } STMT_END
351 #define XPUSHTARG       STMT_START { SvSETMAGIC(TARG); XPUSHs(TARG); } STMT_END
352 #define XPUSHp(p,l)     STMT_START { sv_setpvn(TARG, (p), (l)); XPUSHTARG; } STMT_END
353 #define XPUSHn(n)       STMT_START { sv_setnv(TARG, (NV)(n)); XPUSHTARG; } STMT_END
354 #define XPUSHi(i)       STMT_START { sv_setiv(TARG, (IV)(i)); XPUSHTARG; } STMT_END
355 #define XPUSHu(u)       STMT_START { sv_setuv(TARG, (UV)(u)); XPUSHTARG; } STMT_END
356 #define XPUSHundef      STMT_START { SvOK_off(TARG); XPUSHs(TARG); } STMT_END
357
358 #define mPUSHs(s)       PUSHs(sv_2mortal(s))
359 #define PUSHmortal      PUSHs(sv_newmortal())
360 #define mPUSHp(p,l)     PUSHs(newSVpvn_flags((p), (l), SVs_TEMP))
361 #define mPUSHn(n)       sv_setnv(PUSHmortal, (NV)(n))
362 #define mPUSHi(i)       sv_setiv(PUSHmortal, (IV)(i))
363 #define mPUSHu(u)       sv_setuv(PUSHmortal, (UV)(u))
364
365 #define mXPUSHs(s)      XPUSHs(sv_2mortal(s))
366 #define XPUSHmortal     XPUSHs(sv_newmortal())
367 #define mXPUSHp(p,l)    STMT_START { EXTEND(sp,1); mPUSHp((p), (l)); } STMT_END
368 #define mXPUSHn(n)      STMT_START { EXTEND(sp,1); sv_setnv(PUSHmortal, (NV)(n)); } STMT_END
369 #define mXPUSHi(i)      STMT_START { EXTEND(sp,1); sv_setiv(PUSHmortal, (IV)(i)); } STMT_END
370 #define mXPUSHu(u)      STMT_START { EXTEND(sp,1); sv_setuv(PUSHmortal, (UV)(u)); } STMT_END
371
372 #define SETs(s)         (*sp = s)
373 #define SETTARG         STMT_START { SvSETMAGIC(TARG); SETs(TARG); } STMT_END
374 #define SETp(p,l)       STMT_START { sv_setpvn(TARG, (p), (l)); SETTARG; } STMT_END
375 #define SETn(n)         STMT_START { sv_setnv(TARG, (NV)(n)); SETTARG; } STMT_END
376 #define SETi(i)         STMT_START { sv_setiv(TARG, (IV)(i)); SETTARG; } STMT_END
377 #define SETu(u)         STMT_START { sv_setuv(TARG, (UV)(u)); SETTARG; } STMT_END
378
379 #define dTOPss          SV *sv = TOPs
380 #define dPOPss          SV *sv = POPs
381 #define dTOPnv          NV value = TOPn
382 #define dPOPnv          NV value = POPn
383 #define dPOPnv_nomg     NV value = (sp--, SvNV_nomg(TOPp1s))
384 #define dTOPiv          IV value = TOPi
385 #define dPOPiv          IV value = POPi
386 #define dTOPuv          UV value = TOPu
387 #define dPOPuv          UV value = POPu
388
389 #define dPOPXssrl(X)    SV *right = POPs; SV *left = CAT2(X,s)
390 #define dPOPXnnrl(X)    NV right = POPn; NV left = CAT2(X,n)
391 #define dPOPXiirl(X)    IV right = POPi; IV left = CAT2(X,i)
392
393 #define USE_LEFT(sv) \
394         (SvOK(sv) || !(PL_op->op_flags & OPf_STACKED))
395 #define dPOPXiirl_ul_nomg(X) \
396     IV right = (sp--, SvIV_nomg(TOPp1s));               \
397     SV *leftsv = CAT2(X,s);                             \
398     IV left = USE_LEFT(leftsv) ? SvIV_nomg(leftsv) : 0
399
400 #define dPOPPOPssrl     dPOPXssrl(POP)
401 #define dPOPPOPnnrl     dPOPXnnrl(POP)
402 #define dPOPPOPiirl     dPOPXiirl(POP)
403
404 #define dPOPTOPssrl     dPOPXssrl(TOP)
405 #define dPOPTOPnnrl     dPOPXnnrl(TOP)
406 #define dPOPTOPnnrl_nomg \
407     NV right = SvNV_nomg(TOPs); NV left = (sp--, SvNV_nomg(TOPs))
408 #define dPOPTOPiirl     dPOPXiirl(TOP)
409 #define dPOPTOPiirl_ul_nomg dPOPXiirl_ul_nomg(TOP)
410 #define dPOPTOPiirl_nomg \
411     IV right = SvIV_nomg(TOPs); IV left = (sp--, SvIV_nomg(TOPs))
412
413 #define RETPUSHYES      RETURNX(PUSHs(&PL_sv_yes))
414 #define RETPUSHNO       RETURNX(PUSHs(&PL_sv_no))
415 #define RETPUSHUNDEF    RETURNX(PUSHs(&PL_sv_undef))
416
417 #define RETSETYES       RETURNX(SETs(&PL_sv_yes))
418 #define RETSETNO        RETURNX(SETs(&PL_sv_no))
419 #define RETSETUNDEF     RETURNX(SETs(&PL_sv_undef))
420 #define RETSETTARG      STMT_START { SETTARG; RETURN; } STMT_END
421
422 #define ARGTARG         PL_op->op_targ
423
424 #define MAXARG          (PL_op->op_private & OPpARG4_MASK)
425
426 #define SWITCHSTACK(f,t) \
427     STMT_START {                                                        \
428         AvFILLp(f) = sp - PL_stack_base;                                \
429         PL_stack_base = AvARRAY(t);                                     \
430         PL_stack_max = PL_stack_base + AvMAX(t);                        \
431         sp = PL_stack_sp = PL_stack_base + AvFILLp(t);                  \
432         PL_curstack = t;                                                \
433     } STMT_END
434
435 #define EXTEND_MORTAL(n) \
436     STMT_START {                                                \
437         SSize_t eMiX = PL_tmps_ix + (n);                        \
438         if (UNLIKELY(eMiX >= PL_tmps_max))                      \
439             (void)Perl_tmps_grow_p(aTHX_ eMiX);                 \
440     } STMT_END
441
442 #define AMGf_noright    1
443 #define AMGf_noleft     2
444 #define AMGf_assign     4
445 #define AMGf_unary      8
446 #define AMGf_numeric    0x10    /* for Perl_try_amagic_bin */
447 #define AMGf_set        0x20    /* for Perl_try_amagic_bin */
448 #define AMGf_want_list  0x40
449 #define AMGf_numarg     0x80
450
451
452 /* do SvGETMAGIC on the stack args before checking for overload */
453
454 #define tryAMAGICun_MG(method, flags) STMT_START { \
455         if ( UNLIKELY((SvFLAGS(TOPs) & (SVf_ROK|SVs_GMG))) \
456                 && Perl_try_amagic_un(aTHX_ method, flags)) \
457             return NORMAL; \
458     } STMT_END
459 #define tryAMAGICbin_MG(method, flags) STMT_START { \
460         if ( UNLIKELY(((SvFLAGS(TOPm1s)|SvFLAGS(TOPs)) & (SVf_ROK|SVs_GMG))) \
461                 && Perl_try_amagic_bin(aTHX_ method, flags)) \
462             return NORMAL; \
463     } STMT_END
464
465 #define AMG_CALLunary(sv,meth) \
466     amagic_call(sv,&PL_sv_undef, meth, AMGf_noright | AMGf_unary)
467
468 /* No longer used in core. Use AMG_CALLunary instead */
469 #define AMG_CALLun(sv,meth) AMG_CALLunary(sv, CAT2(meth,_amg))
470
471 #define tryAMAGICunTARGETlist(meth, jump)                       \
472     STMT_START {                                                \
473         dSP;                                                    \
474         SV *tmpsv;                                              \
475         SV *arg= *sp;                                           \
476         int gimme = GIMME_V;                                    \
477         if (UNLIKELY(SvAMAGIC(arg) &&                           \
478             (tmpsv = amagic_call(arg, &PL_sv_undef, meth,       \
479                                  AMGf_want_list | AMGf_noright  \
480                                 |AMGf_unary))))                 \
481         {                                                       \
482             SPAGAIN;                                            \
483             if (gimme == G_VOID) {                              \
484                 NOOP;                                           \
485             }                                                   \
486             else if (gimme == G_ARRAY) {                        \
487                 SSize_t i;                                      \
488                 SSize_t len;                                    \
489                 assert(SvTYPE(tmpsv) == SVt_PVAV);              \
490                 len = av_tindex((AV *)tmpsv) + 1;               \
491                 (void)POPs; /* get rid of the arg */            \
492                 EXTEND(sp, len);                                \
493                 for (i = 0; i < len; ++i)                       \
494                     PUSHs(av_shift((AV *)tmpsv));               \
495             }                                                   \
496             else { /* AMGf_want_scalar */                       \
497                 dATARGET; /* just use the arg's location */     \
498                 sv_setsv(TARG, tmpsv);                          \
499                 if (opASSIGN)                                   \
500                     sp--;                                       \
501                 SETTARG;                                        \
502             }                                                   \
503             PUTBACK;                                            \
504             if (jump) {                                         \
505                 OP *jump_o = NORMAL->op_next;                   \
506                 while (jump_o->op_type == OP_NULL)              \
507                     jump_o = jump_o->op_next;                   \
508                 assert(jump_o->op_type == OP_ENTERSUB);         \
509                 PL_markstack_ptr--;                             \
510                 return jump_o->op_next;                         \
511             }                                                   \
512             return NORMAL;                                      \
513         }                                                       \
514     } STMT_END
515
516 /* This is no longer used anywhere in the core. You might wish to consider
517    calling amagic_deref_call() directly, as it has a cleaner interface.  */
518 #define tryAMAGICunDEREF(meth)                                          \
519     STMT_START {                                                        \
520         sv = amagic_deref_call(*sp, CAT2(meth,_amg));                   \
521         SPAGAIN;                                                        \
522     } STMT_END
523
524
525 #define opASSIGN (PL_op->op_flags & OPf_STACKED)
526
527 /*
528 =for apidoc mU||LVRET
529 True if this op will be the return value of an lvalue subroutine
530
531 =cut */
532 #define LVRET ((PL_op->op_private & OPpMAYBE_LVSUB) && is_lvalue_sub())
533
534 #define SvCANEXISTDELETE(sv) \
535  (!SvRMAGICAL(sv)            \
536   || !(mg = mg_find((const SV *) sv, PERL_MAGIC_tied))           \
537   || (   (stash = SvSTASH(SvRV(SvTIED_obj(MUTABLE_SV(sv), mg)))) \
538       && gv_fetchmethod_autoload(stash, "EXISTS", TRUE)          \
539       && gv_fetchmethod_autoload(stash, "DELETE", TRUE)          \
540      )                       \
541   )
542
543 #ifdef PERL_CORE
544
545 /* These are just for Perl_tied_method(), which is not part of the public API.
546    Use 0x04 rather than the next available bit, to help the compiler if the
547    architecture can generate more efficient instructions.  */
548 #  define TIED_METHOD_MORTALIZE_NOT_NEEDED      0x04
549 #  define TIED_METHOD_ARGUMENTS_ON_STACK        0x08
550 #  define TIED_METHOD_SAY                       0x10
551
552 /* Used in various places that need to dereference a glob or globref */
553 #  define MAYBE_DEREF_GV_flags(sv,phlags)                          \
554     (                                                               \
555         (void)(phlags & SV_GMAGIC && (SvGETMAGIC(sv),0)),            \
556         isGV_with_GP(sv)                                              \
557           ? (GV *)(sv)                                                \
558           : SvROK(sv) && SvTYPE(SvRV(sv)) <= SVt_PVLV &&               \
559             (SvGETMAGIC(SvRV(sv)), isGV_with_GP(SvRV(sv)))              \
560              ? (GV *)SvRV(sv)                                            \
561              : NULL                                                       \
562     )
563 #  define MAYBE_DEREF_GV(sv)      MAYBE_DEREF_GV_flags(sv,SV_GMAGIC)
564 #  define MAYBE_DEREF_GV_nomg(sv) MAYBE_DEREF_GV_flags(sv,0)
565
566 #  define FIND_RUNCV_padid_eq   1
567 #  define FIND_RUNCV_level_eq   2
568
569 #endif
570
571 /*
572  * ex: set ts=8 sts=4 sw=4 et:
573  */