This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
amigaos4: minimized config.sh
[perl5.git] / pp.h
CommitLineData
a0d0e21e 1/* pp.h
79072805 2 *
1129b882
NC
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
79072805 5 *
a0d0e21e
LW
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.
79072805 8 *
a0d0e21e 9 */
79072805 10
cea2e8a9 11#define PP(s) OP * Perl_##s(pTHX)
79072805 12
954c1994 13/*
ccfc67b7
JH
14=head1 Stack Manipulation Macros
15
954c1994 16=for apidoc AmU||SP
fbe13c60 17Stack pointer. This is usually handled by C<xsubpp>. See C<L</dSP>> and
954c1994
GS
18C<SPAGAIN>.
19
20=for apidoc AmU||MARK
fbe13c60 21Stack marker variable for the XSUB. See C<L</dMARK>>.
954c1994 22
c578083c 23=for apidoc Am|void|PUSHMARK|SP
fbe13c60 24Opening bracket for arguments on a callback. See C<L</PUTBACK>> and
954c1994
GS
25L<perlcall>.
26
27=for apidoc Ams||dSP
28Declares a local copy of perl's stack pointer for the XSUB, available via
fbe13c60 29the C<SP> macro. See C<L</SP>>.
954c1994 30
fac3506f
MS
31=for apidoc ms||djSP
32
154e47c8 33Declare Just C<SP>. This is actually identical to C<dSP>, and declares
fac3506f 34a local copy of perl's stack pointer, available via the C<SP> macro.
fbe13c60
KW
35See C<L<perlapi/SP>>. (Available for backward source code compatibility with
36the old (Perl 5.005) thread model.)
fac3506f 37
954c1994 38=for apidoc Ams||dMARK
fbe13c60
KW
39Declare a stack marker variable, C<mark>, for the XSUB. See C<L</MARK>> and
40C<L</dORIGMARK>>.
954c1994
GS
41
42=for apidoc Ams||dORIGMARK
fbe13c60 43Saves the original stack mark for the XSUB. See C<L</ORIGMARK>>.
954c1994
GS
44
45=for apidoc AmU||ORIGMARK
fbe13c60 46The original stack mark for the XSUB. See C<L</dORIGMARK>>.
954c1994
GS
47
48=for apidoc Ams||SPAGAIN
49Refetch the stack pointer. Used after a callback. See L<perlcall>.
50
fac3506f 51=cut */
954c1994 52
ac634a9a 53#undef SP /* Solaris 2.7 i386 has this in /usr/include/sys/reg.h */
79072805
LW
54#define SP sp
55#define MARK mark
56#define TARG targ
57
16e7e110
TH
58#define PUSHMARK(p) \
59 STMT_START { \
ba5248fc
DD
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); \
16e7e110 64 } STMT_END
a0d0e21e 65
3280af22
NIS
66#define TOPMARK (*PL_markstack_ptr)
67#define POPMARK (*PL_markstack_ptr--)
a0d0e21e 68
bc0d193f 69#define dSP SV **sp = PL_stack_sp
39644a26 70#define djSP dSP
5aaab254 71#define dMARK SV **mark = PL_stack_base + POPMARK
514696af 72#define dORIGMARK const I32 origmark = (I32)(mark - PL_stack_base)
3280af22 73#define ORIGMARK (PL_stack_base + origmark)
79072805 74
3280af22 75#define SPAGAIN sp = PL_stack_sp
16e7e110 76#define MSPAGAIN STMT_START { sp = PL_stack_sp; mark = ORIGMARK; } STMT_END
79072805 77
533c011a 78#define GETTARGETSTACKED targ = (PL_op->op_flags & OPf_STACKED ? POPs : PAD_SV(PL_op->op_targ))
79072805
LW
79#define dTARGETSTACKED SV * GETTARGETSTACKED
80
533c011a 81#define GETTARGET targ = PAD_SV(PL_op->op_targ)
79072805
LW
82#define dTARGET SV * GETTARGET
83
533c011a 84#define GETATARGET targ = (PL_op->op_flags & OPf_STACKED ? sp[-1] : PAD_SV(PL_op->op_targ))
79072805
LW
85#define dATARGET SV * GETATARGET
86
87#define dTARG SV *targ
88
533c011a 89#define NORMAL PL_op->op_next
9fed9930 90#define DIE return Perl_die
79072805 91
954c1994
GS
92/*
93=for apidoc Ams||PUTBACK
94Closing bracket for XSUB arguments. This is usually handled by C<xsubpp>.
fbe13c60 95See C<L</PUSHMARK>> and L<perlcall> for other uses.
954c1994
GS
96
97=for apidoc Amn|SV*|POPs
98Pops an SV off the stack.
99
100=for apidoc Amn|char*|POPp
4b7c0884 101Pops a string off the stack.
595ae481
NIS
102
103=for apidoc Amn|char*|POPpx
4b7c0884
FC
104Pops a string off the stack. Identical to POPp. There are two names for
105historical reasons.
595ae481
NIS
106
107=for apidoc Amn|char*|POPpbytex
108Pops a string off the stack which must consist of bytes i.e. characters < 256.
954c1994
GS
109
110=for apidoc Amn|NV|POPn
111Pops a double off the stack.
112
113=for apidoc Amn|IV|POPi
114Pops an integer off the stack.
115
d0554719
TC
116=for apidoc Amn|UV|POPu
117Pops an unsigned integer off the stack.
118
954c1994
GS
119=for apidoc Amn|long|POPl
120Pops a long off the stack.
121
d0554719
TC
122=for apidoc Amn|long|POPul
123Pops an unsigned long off the stack.
124
954c1994
GS
125=cut
126*/
127
3280af22 128#define PUTBACK PL_stack_sp = sp
8a67133a
NC
129#define RETURN return (PUTBACK, NORMAL)
130#define RETURNOP(o) return (PUTBACK, o)
131#define RETURNX(x) return (x, PUTBACK, NORMAL)
79072805
LW
132
133#define POPs (*sp--)
4b7c0884 134#define POPp POPpx
8c074e2a
NC
135#define POPpx (SvPVx_nolen(POPs))
136#define POPpconstx (SvPVx_nolen_const(POPs))
137#define POPpbytex (SvPVbytex_nolen(POPs))
463ee0b2 138#define POPn (SvNVx(POPs))
a0d0e21e 139#define POPi ((IV)SvIVx(POPs))
ff68c719 140#define POPu ((UV)SvUVx(POPs))
463ee0b2 141#define POPl ((long)SvIVx(POPs))
d9b3e12d 142#define POPul ((unsigned long)SvIVx(POPs))
79072805
LW
143
144#define TOPs (*sp)
56370e9f 145#define TOPm1s (*(sp-1))
7dca457a 146#define TOPp1s (*(sp+1))
4b7c0884 147#define TOPp TOPpx
95fad918 148#define TOPpx (SvPV_nolen(TOPs))
463ee0b2 149#define TOPn (SvNV(TOPs))
a0d0e21e 150#define TOPi ((IV)SvIV(TOPs))
ff68c719 151#define TOPu ((UV)SvUV(TOPs))
463ee0b2 152#define TOPl ((long)SvIV(TOPs))
c5a0f51a 153#define TOPul ((unsigned long)SvUV(TOPs))
79072805
LW
154
155/* Go to some pains in the rare event that we must extend the stack. */
954c1994
GS
156
157/*
fc16c392 158=for apidoc Am|void|EXTEND|SP|SSize_t nitems
72d33970 159Used to extend the argument stack for an XSUB's return values. Once
4375e838 160used, guarantees that there is room for at least C<nitems> to be pushed
954c1994
GS
161onto the stack.
162
163=for apidoc Am|void|PUSHs|SV* sv
aacdac46 164Push an SV onto the stack. The stack must have room for this element.
fbe13c60
KW
165Does not handle 'set' magic. Does not use C<TARG>. See also
166C<L</PUSHmortal>>, C<L</XPUSHs>>, and C<L</XPUSHmortal>>.
954c1994
GS
167
168=for apidoc Am|void|PUSHp|char* str|STRLEN len
169Push a string onto the stack. The stack must have room for this element.
d82b684c
SH
170The C<len> indicates the length of the string. Handles 'set' magic. Uses
171C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to declare it. Do not
172call multiple C<TARG>-oriented macros to return lists from XSUB's - see
fbe13c60 173C<L</mPUSHp>> instead. See also C<L</XPUSHp>> and C<L</mXPUSHp>>.
954c1994
GS
174
175=for apidoc Am|void|PUSHn|NV nv
176Push a double onto the stack. The stack must have room for this element.
d82b684c
SH
177Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be
178called to declare it. Do not call multiple C<TARG>-oriented macros to
fbe13c60
KW
179return lists from XSUB's - see C<L</mPUSHn>> instead. See also C<L</XPUSHn>>
180and C<L</mXPUSHn>>.
954c1994
GS
181
182=for apidoc Am|void|PUSHi|IV iv
183Push an integer onto the stack. The stack must have room for this element.
d82b684c
SH
184Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be
185called to declare it. Do not call multiple C<TARG>-oriented macros to
fbe13c60
KW
186return lists from XSUB's - see C<L</mPUSHi>> instead. See also C<L</XPUSHi>>
187and C<L</mXPUSHi>>.
954c1994
GS
188
189=for apidoc Am|void|PUSHu|UV uv
190Push an unsigned integer onto the stack. The stack must have room for this
d82b684c
SH
191element. Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG>
192should be called to declare it. Do not call multiple C<TARG>-oriented
fbe13c60
KW
193macros to return lists from XSUB's - see C<L</mPUSHu>> instead. See also
194C<L</XPUSHu>> and C<L</mXPUSHu>>.
954c1994
GS
195
196=for apidoc Am|void|XPUSHs|SV* sv
197Push an SV onto the stack, extending the stack if necessary. Does not
fbe13c60 198handle 'set' magic. Does not use C<TARG>. See also C<L</XPUSHmortal>>,
d82b684c 199C<PUSHs> and C<PUSHmortal>.
954c1994
GS
200
201=for apidoc Am|void|XPUSHp|char* str|STRLEN len
202Push a string onto the stack, extending the stack if necessary. The C<len>
d82b684c
SH
203indicates the length of the string. Handles 'set' magic. Uses C<TARG>, so
204C<dTARGET> or C<dXSTARG> should be called to declare it. Do not call
205multiple C<TARG>-oriented macros to return lists from XSUB's - see
fbe13c60 206C<L</mXPUSHp>> instead. See also C<L</PUSHp>> and C<L</mPUSHp>>.
954c1994
GS
207
208=for apidoc Am|void|XPUSHn|NV nv
209Push a double onto the stack, extending the stack if necessary. Handles
d82b684c
SH
210'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to
211declare it. Do not call multiple C<TARG>-oriented macros to return lists
fbe13c60
KW
212from XSUB's - see C<L</mXPUSHn>> instead. See also C<L</PUSHn>> and
213C<L</mPUSHn>>.
954c1994
GS
214
215=for apidoc Am|void|XPUSHi|IV iv
216Push an integer onto the stack, extending the stack if necessary. Handles
d82b684c
SH
217'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to
218declare it. Do not call multiple C<TARG>-oriented macros to return lists
fbe13c60
KW
219from XSUB's - see C<L</mXPUSHi>> instead. See also C<L</PUSHi>> and
220C<L</mPUSHi>>.
954c1994
GS
221
222=for apidoc Am|void|XPUSHu|UV uv
aacdac46 223Push an unsigned integer onto the stack, extending the stack if necessary.
d82b684c
SH
224Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be
225called to declare it. Do not call multiple C<TARG>-oriented macros to
fbe13c60
KW
226return lists from XSUB's - see C<L</mXPUSHu>> instead. See also C<L</PUSHu>> and
227C<L</mPUSHu>>.
d82b684c 228
6e449a3a
MHM
229=for apidoc Am|void|mPUSHs|SV* sv
230Push an SV onto the stack and mortalizes the SV. The stack must have room
fbe13c60
KW
231for this element. Does not use C<TARG>. See also C<L</PUSHs>> and
232C<L</mXPUSHs>>.
6e449a3a 233
d82b684c
SH
234=for apidoc Am|void|PUSHmortal
235Push a new mortal SV onto the stack. The stack must have room for this
fbe13c60
KW
236element. Does not use C<TARG>. See also C<L</PUSHs>>, C<L</XPUSHmortal>> and
237C<L</XPUSHs>>.
d82b684c
SH
238
239=for apidoc Am|void|mPUSHp|char* str|STRLEN len
240Push a string onto the stack. The stack must have room for this element.
121b7712 241The C<len> indicates the length of the string. Does not use C<TARG>.
fbe13c60 242See also C<L</PUSHp>>, C<L</mXPUSHp>> and C<L</XPUSHp>>.
d82b684c
SH
243
244=for apidoc Am|void|mPUSHn|NV nv
245Push a double onto the stack. The stack must have room for this element.
fbe13c60 246Does not use C<TARG>. See also C<L</PUSHn>>, C<L</mXPUSHn>> and C<L</XPUSHn>>.
d82b684c
SH
247
248=for apidoc Am|void|mPUSHi|IV iv
249Push an integer onto the stack. The stack must have room for this element.
fbe13c60 250Does not use C<TARG>. See also C<L</PUSHi>>, C<L</mXPUSHi>> and C<L</XPUSHi>>.
d82b684c
SH
251
252=for apidoc Am|void|mPUSHu|UV uv
253Push an unsigned integer onto the stack. The stack must have room for this
fbe13c60
KW
254element. Does not use C<TARG>. See also C<L</PUSHu>>, C<L</mXPUSHu>> and
255C<L</XPUSHu>>.
d82b684c 256
6e449a3a
MHM
257=for apidoc Am|void|mXPUSHs|SV* sv
258Push an SV onto the stack, extending the stack if necessary and mortalizes
fbe13c60 259the SV. Does not use C<TARG>. See also C<L</XPUSHs>> and C<L</mPUSHs>>.
6e449a3a 260
d82b684c 261=for apidoc Am|void|XPUSHmortal
121b7712 262Push a new mortal SV onto the stack, extending the stack if necessary.
fbe13c60
KW
263Does not use C<TARG>. See also C<L</XPUSHs>>, C<L</PUSHmortal>> and
264C<L</PUSHs>>.
d82b684c
SH
265
266=for apidoc Am|void|mXPUSHp|char* str|STRLEN len
267Push a string onto the stack, extending the stack if necessary. The C<len>
fbe13c60
KW
268indicates the length of the string. Does not use C<TARG>. See also
269C<L</XPUSHp>>, C<mPUSHp> and C<PUSHp>.
d82b684c
SH
270
271=for apidoc Am|void|mXPUSHn|NV nv
121b7712 272Push a double onto the stack, extending the stack if necessary.
fbe13c60 273Does not use C<TARG>. See also C<L</XPUSHn>>, C<L</mPUSHn>> and C<L</PUSHn>>.
d82b684c
SH
274
275=for apidoc Am|void|mXPUSHi|IV iv
121b7712 276Push an integer onto the stack, extending the stack if necessary.
fbe13c60 277Does not use C<TARG>. See also C<L</XPUSHi>>, C<L</mPUSHi>> and C<L</PUSHi>>.
d82b684c
SH
278
279=for apidoc Am|void|mXPUSHu|UV uv
280Push an unsigned integer onto the stack, extending the stack if necessary.
fbe13c60 281Does not use C<TARG>. See also C<L</XPUSHu>>, C<L</mPUSHu>> and C<L</PUSHu>>.
954c1994
GS
282
283=cut
284*/
285
865e3ae0 286#ifdef STRESS_REALLOC
aad79b33
JH
287# define EXTEND(p,n) STMT_START { \
288 sp = stack_grow(sp,p,(SSize_t) (n)); \
289 PERL_UNUSED_VAR(sp); \
8094bfa4 290 } STMT_END
865e3ae0 291/* Same thing, but update mark register too. */
aad79b33 292# define MEXTEND(p,n) STMT_START { \
ff36bb50 293 const SSize_t markoff = mark - PL_stack_base; \
8094bfa4 294 sp = stack_grow(sp,p,(SSize_t) (n)); \
aad79b33
JH
295 mark = PL_stack_base + markoff; \
296 PERL_UNUSED_VAR(sp); \
297 } STMT_END
865e3ae0 298#else
aad79b33 299# define EXTEND(p,n) STMT_START { \
ff36bb50 300 if (UNLIKELY(PL_stack_max - p < (SSize_t)(n))) { \
aad79b33
JH
301 sp = stack_grow(sp,p,(SSize_t) (n)); \
302 PERL_UNUSED_VAR(sp); \
303 } } STMT_END
79072805 304/* Same thing, but update mark register too. */
aad79b33 305# define MEXTEND(p,n) STMT_START { \
ff36bb50
HS
306 if (UNLIKELY(PL_stack_max - p < (SSize_t)(n))) { \
307 const SSize_t markoff = mark - PL_stack_base; \
aad79b33
JH
308 sp = stack_grow(sp,p,(SSize_t) (n)); \
309 mark = PL_stack_base + markoff; \
310 PERL_UNUSED_VAR(sp); \
311 } } STMT_END
865e3ae0 312#endif
79072805
LW
313
314#define PUSHs(s) (*++sp = (s))
86547924 315#define PUSHTARG STMT_START { SvSETMAGIC(TARG); PUSHs(TARG); } STMT_END
316#define PUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); PUSHTARG; } STMT_END
65202027 317#define PUSHn(n) STMT_START { sv_setnv(TARG, (NV)(n)); PUSHTARG; } STMT_END
86547924 318#define PUSHi(i) STMT_START { sv_setiv(TARG, (IV)(i)); PUSHTARG; } STMT_END
55497cff 319#define PUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); PUSHTARG; } STMT_END
79072805 320
0acfb02f 321#define XPUSHs(s) STMT_START { EXTEND(sp,1); *++sp = (s); } STMT_END
86547924 322#define XPUSHTARG STMT_START { SvSETMAGIC(TARG); XPUSHs(TARG); } STMT_END
323#define XPUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); XPUSHTARG; } STMT_END
65202027 324#define XPUSHn(n) STMT_START { sv_setnv(TARG, (NV)(n)); XPUSHTARG; } STMT_END
86547924 325#define XPUSHi(i) STMT_START { sv_setiv(TARG, (IV)(i)); XPUSHTARG; } STMT_END
55497cff 326#define XPUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); XPUSHTARG; } STMT_END
b162f9ea 327#define XPUSHundef STMT_START { SvOK_off(TARG); XPUSHs(TARG); } STMT_END
79072805 328
6e449a3a 329#define mPUSHs(s) PUSHs(sv_2mortal(s))
2cc7004b 330#define PUSHmortal PUSHs(sv_newmortal())
8f14ea01 331#define mPUSHp(p,l) PUSHs(newSVpvn_flags((p), (l), SVs_TEMP))
121b7712
MHM
332#define mPUSHn(n) sv_setnv(PUSHmortal, (NV)(n))
333#define mPUSHi(i) sv_setiv(PUSHmortal, (IV)(i))
334#define mPUSHu(u) sv_setuv(PUSHmortal, (UV)(u))
2cc7004b 335
6e449a3a 336#define mXPUSHs(s) XPUSHs(sv_2mortal(s))
2cc7004b 337#define XPUSHmortal XPUSHs(sv_newmortal())
8f14ea01 338#define mXPUSHp(p,l) STMT_START { EXTEND(sp,1); mPUSHp((p), (l)); } STMT_END
121b7712
MHM
339#define mXPUSHn(n) STMT_START { EXTEND(sp,1); sv_setnv(PUSHmortal, (NV)(n)); } STMT_END
340#define mXPUSHi(i) STMT_START { EXTEND(sp,1); sv_setiv(PUSHmortal, (IV)(i)); } STMT_END
341#define mXPUSHu(u) STMT_START { EXTEND(sp,1); sv_setuv(PUSHmortal, (UV)(u)); } STMT_END
d82b684c 342
79072805 343#define SETs(s) (*sp = s)
86547924 344#define SETTARG STMT_START { SvSETMAGIC(TARG); SETs(TARG); } STMT_END
345#define SETp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); SETTARG; } STMT_END
65202027 346#define SETn(n) STMT_START { sv_setnv(TARG, (NV)(n)); SETTARG; } STMT_END
86547924 347#define SETi(i) STMT_START { sv_setiv(TARG, (IV)(i)); SETTARG; } STMT_END
55497cff 348#define SETu(u) STMT_START { sv_setuv(TARG, (UV)(u)); SETTARG; } STMT_END
a0d0e21e 349
79072805
LW
350#define dTOPss SV *sv = TOPs
351#define dPOPss SV *sv = POPs
65202027
DS
352#define dTOPnv NV value = TOPn
353#define dPOPnv NV value = POPn
6f1401dc 354#define dPOPnv_nomg NV value = (sp--, SvNV_nomg(TOPp1s))
a0d0e21e
LW
355#define dTOPiv IV value = TOPi
356#define dPOPiv IV value = POPi
55497cff 357#define dTOPuv UV value = TOPu
358#define dPOPuv UV value = POPu
79072805 359
7a4c00b4 360#define dPOPXssrl(X) SV *right = POPs; SV *left = CAT2(X,s)
65202027 361#define dPOPXnnrl(X) NV right = POPn; NV left = CAT2(X,n)
7a4c00b4 362#define dPOPXiirl(X) IV right = POPi; IV left = CAT2(X,i)
363
364#define USE_LEFT(sv) \
6b349a5c 365 (SvOK(sv) || !(PL_op->op_flags & OPf_STACKED))
6f1401dc 366#define dPOPXiirl_ul_nomg(X) \
096c060c 367 IV right = (sp--, SvIV_nomg(TOPp1s)); \
6f1401dc 368 SV *leftsv = CAT2(X,s); \
096c060c 369 IV left = USE_LEFT(leftsv) ? SvIV_nomg(leftsv) : 0
7a4c00b4 370
371#define dPOPPOPssrl dPOPXssrl(POP)
372#define dPOPPOPnnrl dPOPXnnrl(POP)
7a4c00b4 373#define dPOPPOPiirl dPOPXiirl(POP)
7a4c00b4 374
375#define dPOPTOPssrl dPOPXssrl(TOP)
376#define dPOPTOPnnrl dPOPXnnrl(TOP)
6f1401dc
DM
377#define dPOPTOPnnrl_nomg \
378 NV right = SvNV_nomg(TOPs); NV left = (sp--, SvNV_nomg(TOPs))
7a4c00b4 379#define dPOPTOPiirl dPOPXiirl(TOP)
6f1401dc
DM
380#define dPOPTOPiirl_ul_nomg dPOPXiirl_ul_nomg(TOP)
381#define dPOPTOPiirl_nomg \
096c060c 382 IV right = SvIV_nomg(TOPs); IV left = (sp--, SvIV_nomg(TOPs))
79072805 383
3280af22
NIS
384#define RETPUSHYES RETURNX(PUSHs(&PL_sv_yes))
385#define RETPUSHNO RETURNX(PUSHs(&PL_sv_no))
386#define RETPUSHUNDEF RETURNX(PUSHs(&PL_sv_undef))
79072805 387
3280af22
NIS
388#define RETSETYES RETURNX(SETs(&PL_sv_yes))
389#define RETSETNO RETURNX(SETs(&PL_sv_no))
390#define RETSETUNDEF RETURNX(SETs(&PL_sv_undef))
5d01050a 391#define RETSETTARG STMT_START { SETTARG; RETURN; } STMT_END
79072805 392
533c011a 393#define ARGTARG PL_op->op_targ
b162f9ea 394
f3574cc6 395#define MAXARG (PL_op->op_private & OPpARG4_MASK)
79072805 396
e336de0d
GS
397#define SWITCHSTACK(f,t) \
398 STMT_START { \
677b06e3 399 AvFILLp(f) = sp - PL_stack_base; \
3280af22 400 PL_stack_base = AvARRAY(t); \
677b06e3 401 PL_stack_max = PL_stack_base + AvMAX(t); \
3280af22 402 sp = PL_stack_sp = PL_stack_base + AvFILLp(t); \
677b06e3 403 PL_curstack = t; \
e336de0d 404 } STMT_END
79072805 405
bbce6d69 406#define EXTEND_MORTAL(n) \
a953aca5
DD
407 STMT_START { \
408 SSize_t eMiX = PL_tmps_ix + (n); \
409 if (UNLIKELY(eMiX >= PL_tmps_max)) \
dc9a870f 410 (void)Perl_tmps_grow_p(aTHX_ eMiX); \
677b06e3 411 } STMT_END
bbce6d69 412
a0d0e21e
LW
413#define AMGf_noright 1
414#define AMGf_noleft 2
415#define AMGf_assign 4
416#define AMGf_unary 8
6f1401dc
DM
417#define AMGf_numeric 0x10 /* for Perl_try_amagic_bin */
418#define AMGf_set 0x20 /* for Perl_try_amagic_bin */
67288365 419#define AMGf_want_list 0x40
636ac8fc 420#define AMGf_numarg 0x80
6f1401dc
DM
421
422
423/* do SvGETMAGIC on the stack args before checking for overload */
424
425#define tryAMAGICun_MG(method, flags) STMT_START { \
5d9574c1 426 if ( UNLIKELY((SvFLAGS(TOPs) & (SVf_ROK|SVs_GMG))) \
6f1401dc
DM
427 && Perl_try_amagic_un(aTHX_ method, flags)) \
428 return NORMAL; \
429 } STMT_END
430#define tryAMAGICbin_MG(method, flags) STMT_START { \
5d9574c1 431 if ( UNLIKELY(((SvFLAGS(TOPm1s)|SvFLAGS(TOPs)) & (SVf_ROK|SVs_GMG))) \
6f1401dc
DM
432 && Perl_try_amagic_bin(aTHX_ method, flags)) \
433 return NORMAL; \
434 } STMT_END
435
31d632c3
DM
436#define AMG_CALLunary(sv,meth) \
437 amagic_call(sv,&PL_sv_undef, meth, AMGf_noright | AMGf_unary)
438
439/* No longer used in core. Use AMG_CALLunary instead */
440#define AMG_CALLun(sv,meth) AMG_CALLunary(sv, CAT2(meth,_amg))
a0d0e21e 441
fc99edcf 442#define tryAMAGICunTARGETlist(meth, jump) \
9f39b4f1 443 STMT_START { \
b5c08826
DM
444 dSP; \
445 SV *tmpsv; \
fc99edcf 446 SV *arg= *sp; \
67288365 447 int gimme = GIMME_V; \
5d9574c1 448 if (UNLIKELY(SvAMAGIC(arg) && \
b5c08826 449 (tmpsv = amagic_call(arg, &PL_sv_undef, meth, \
05fbd38d 450 AMGf_want_list | AMGf_noright \
5d9574c1
DM
451 |AMGf_unary)))) \
452 { \
b5c08826 453 SPAGAIN; \
67288365 454 if (gimme == G_VOID) { \
898c5644 455 NOOP; \
67288365 456 } \
05fbd38d 457 else if (gimme == G_ARRAY) { \
c70927a6
FC
458 SSize_t i; \
459 SSize_t len; \
67288365 460 assert(SvTYPE(tmpsv) == SVt_PVAV); \
b9f2b683 461 len = av_tindex((AV *)tmpsv) + 1; \
67288365
JL
462 (void)POPs; /* get rid of the arg */ \
463 EXTEND(sp, len); \
464 for (i = 0; i < len; ++i) \
465 PUSHs(av_shift((AV *)tmpsv)); \
466 } \
467 else { /* AMGf_want_scalar */ \
468 dATARGET; /* just use the arg's location */ \
469 sv_setsv(TARG, tmpsv); \
470 if (opASSIGN) \
471 sp--; \
472 SETTARG; \
473 } \
b5c08826
DM
474 PUTBACK; \
475 if (jump) { \
86e5639b
GG
476 OP *jump_o = NORMAL->op_next; \
477 while (jump_o->op_type == OP_NULL) \
478 jump_o = jump_o->op_next; \
479 assert(jump_o->op_type == OP_ENTERSUB); \
b5c08826 480 PL_markstack_ptr--; \
86e5639b 481 return jump_o->op_next; \
9f39b4f1 482 } \
b5c08826
DM
483 return NORMAL; \
484 } \
9f39b4f1
NC
485 } STMT_END
486
8897dcaa
NC
487/* This is no longer used anywhere in the core. You might wish to consider
488 calling amagic_deref_call() directly, as it has a cleaner interface. */
489#define tryAMAGICunDEREF(meth) \
9f39b4f1 490 STMT_START { \
e89bfaa6 491 sv = amagic_deref_call(*sp, CAT2(meth,_amg)); \
25a9ffce 492 SPAGAIN; \
16e7e110 493 } STMT_END
e8c20960 494
180b7b9b 495
533c011a 496#define opASSIGN (PL_op->op_flags & OPf_STACKED)
a0d0e21e 497
78f9721b
SM
498/*
499=for apidoc mU||LVRET
500True if this op will be the return value of an lvalue subroutine
501
502=cut */
9d96b2e7 503#define LVRET ((PL_op->op_private & OPpMAYBE_LVSUB) && is_lvalue_sub())
1b6737cc 504
d30e492c
VP
505#define SvCANEXISTDELETE(sv) \
506 (!SvRMAGICAL(sv) \
2c5f48c2
FC
507 || !(mg = mg_find((const SV *) sv, PERL_MAGIC_tied)) \
508 || ( (stash = SvSTASH(SvRV(SvTIED_obj(MUTABLE_SV(sv), mg)))) \
d30e492c
VP
509 && gv_fetchmethod_autoload(stash, "EXISTS", TRUE) \
510 && gv_fetchmethod_autoload(stash, "DELETE", TRUE) \
511 ) \
512 )
513
d682515d 514#ifdef PERL_CORE
557fbd17 515
d682515d
NC
516/* These are just for Perl_tied_method(), which is not part of the public API.
517 Use 0x04 rather than the next available bit, to help the compiler if the
518 architecture can generate more efficient instructions. */
519# define TIED_METHOD_MORTALIZE_NOT_NEEDED 0x04
520# define TIED_METHOD_ARGUMENTS_ON_STACK 0x08
94bc412f 521# define TIED_METHOD_SAY 0x10
557fbd17
FC
522
523/* Used in various places that need to dereference a glob or globref */
094a3eec 524# define MAYBE_DEREF_GV_flags(sv,phlags) \
557fbd17 525 ( \
094a3eec 526 (void)(phlags & SV_GMAGIC && (SvGETMAGIC(sv),0)), \
557fbd17 527 isGV_with_GP(sv) \
4e794a06 528 ? (GV *)(sv) \
f8afbfa6
FC
529 : SvROK(sv) && SvTYPE(SvRV(sv)) <= SVt_PVLV && \
530 (SvGETMAGIC(SvRV(sv)), isGV_with_GP(SvRV(sv))) \
557fbd17
FC
531 ? (GV *)SvRV(sv) \
532 : NULL \
533 )
094a3eec
FC
534# define MAYBE_DEREF_GV(sv) MAYBE_DEREF_GV_flags(sv,SV_GMAGIC)
535# define MAYBE_DEREF_GV_nomg(sv) MAYBE_DEREF_GV_flags(sv,0)
557fbd17 536
db4cf31d 537# define FIND_RUNCV_padid_eq 1
b4b0692a 538# define FIND_RUNCV_level_eq 2
70794f7b 539
d682515d
NC
540#endif
541
1b6737cc 542/*
14d04a33 543 * ex: set ts=8 sts=4 sw=4 et:
1b6737cc 544 */