This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate:
[perl5.git] / pp.h
CommitLineData
a0d0e21e 1/* pp.h
79072805 2 *
e6906430
JH
3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999,
4 * 2000, 2001, 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
4d1ff10f 11#ifdef USE_5005THREADS
11343788 12#define ARGS thr
52e1cb5e 13#define dARGS struct perl_thread *thr;
11343788 14#else
79072805 15#define ARGS
79072805 16#define dARGS
4d1ff10f 17#endif /* USE_5005THREADS */
22c35a8c 18
cea2e8a9 19#define PP(s) OP * Perl_##s(pTHX)
79072805 20
954c1994 21/*
ccfc67b7
JH
22=head1 Stack Manipulation Macros
23
954c1994
GS
24=for apidoc AmU||SP
25Stack pointer. This is usually handled by C<xsubpp>. See C<dSP> and
26C<SPAGAIN>.
27
28=for apidoc AmU||MARK
29Stack marker variable for the XSUB. See C<dMARK>.
30
611e9550 31=for apidoc Am|void|PUSHMARK|SP
954c1994
GS
32Opening bracket for arguments on a callback. See C<PUTBACK> and
33L<perlcall>.
34
35=for apidoc Ams||dSP
36Declares a local copy of perl's stack pointer for the XSUB, available via
37the C<SP> macro. See C<SP>.
38
fac3506f
MS
39=for apidoc ms||djSP
40
41Declare Just C<SP>. This is actually identical to C<dSP>, and declares
42a local copy of perl's stack pointer, available via the C<SP> macro.
43See C<SP>. (Available for backward source code compatibility with the
44old (Perl 5.005) thread model.)
45
954c1994
GS
46=for apidoc Ams||dMARK
47Declare a stack marker variable, C<mark>, for the XSUB. See C<MARK> and
48C<dORIGMARK>.
49
50=for apidoc Ams||dORIGMARK
51Saves the original stack mark for the XSUB. See C<ORIGMARK>.
52
53=for apidoc AmU||ORIGMARK
54The original stack mark for the XSUB. See C<dORIGMARK>.
55
56=for apidoc Ams||SPAGAIN
57Refetch the stack pointer. Used after a callback. See L<perlcall>.
58
fac3506f 59=cut */
954c1994 60
ac634a9a 61#undef SP /* Solaris 2.7 i386 has this in /usr/include/sys/reg.h */
79072805
LW
62#define SP sp
63#define MARK mark
64#define TARG targ
65
3280af22 66#define PUSHMARK(p) if (++PL_markstack_ptr == PL_markstack_max) \
a0d0e21e 67 markstack_grow(); \
3280af22 68 *PL_markstack_ptr = (p) - PL_stack_base
a0d0e21e 69
3280af22
NIS
70#define TOPMARK (*PL_markstack_ptr)
71#define POPMARK (*PL_markstack_ptr--)
a0d0e21e 72
39644a26
TJ
73#define dSP register SV **sp = PL_stack_sp
74#define djSP dSP
3280af22
NIS
75#define dMARK register SV **mark = PL_stack_base + POPMARK
76#define dORIGMARK I32 origmark = mark - PL_stack_base
77#define SETORIGMARK origmark = mark - PL_stack_base
78#define ORIGMARK (PL_stack_base + origmark)
79072805 79
3280af22
NIS
80#define SPAGAIN sp = PL_stack_sp
81#define MSPAGAIN sp = PL_stack_sp; mark = ORIGMARK
79072805 82
533c011a 83#define GETTARGETSTACKED targ = (PL_op->op_flags & OPf_STACKED ? POPs : PAD_SV(PL_op->op_targ))
79072805
LW
84#define dTARGETSTACKED SV * GETTARGETSTACKED
85
533c011a 86#define GETTARGET targ = PAD_SV(PL_op->op_targ)
79072805
LW
87#define dTARGET SV * GETTARGET
88
533c011a 89#define GETATARGET targ = (PL_op->op_flags & OPf_STACKED ? sp[-1] : PAD_SV(PL_op->op_targ))
79072805
LW
90#define dATARGET SV * GETATARGET
91
92#define dTARG SV *targ
93
533c011a 94#define NORMAL PL_op->op_next
cea2e8a9 95#define DIE return Perl_die
79072805 96
954c1994
GS
97/*
98=for apidoc Ams||PUTBACK
99Closing bracket for XSUB arguments. This is usually handled by C<xsubpp>.
100See C<PUSHMARK> and L<perlcall> for other uses.
101
102=for apidoc Amn|SV*|POPs
103Pops an SV off the stack.
104
105=for apidoc Amn|char*|POPp
595ae481
NIS
106Pops a string off the stack. Deprecated. New code should provide
107a STRLEN n_a and use POPpx.
108
109=for apidoc Amn|char*|POPpx
954c1994 110Pops a string off the stack.
595ae481
NIS
111Requires a variable STRLEN n_a in scope.
112
113=for apidoc Amn|char*|POPpbytex
114Pops a string off the stack which must consist of bytes i.e. characters < 256.
115Requires a variable STRLEN n_a in scope.
954c1994
GS
116
117=for apidoc Amn|NV|POPn
118Pops a double off the stack.
119
120=for apidoc Amn|IV|POPi
121Pops an integer off the stack.
122
123=for apidoc Amn|long|POPl
124Pops a long off the stack.
125
126=cut
127*/
128
3280af22 129#define PUTBACK PL_stack_sp = sp
79072805
LW
130#define RETURN return PUTBACK, NORMAL
131#define RETURNOP(o) return PUTBACK, o
132#define RETURNX(x) return x, PUTBACK, NORMAL
133
134#define POPs (*sp--)
2d8e6c8d
GS
135#define POPp (SvPVx(POPs, PL_na)) /* deprecated */
136#define POPpx (SvPVx(POPs, n_a))
595ae481 137#define POPpbytex (SvPVbytex(POPs, n_a))
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))
1b8cd678 143#ifdef HAS_QUAD
d9b3e12d 144#define POPq ((Quad_t)SvIVx(POPs))
c5a0f51a 145#define POPuq ((Uquad_t)SvUVx(POPs))
d9b3e12d 146#endif
79072805
LW
147
148#define TOPs (*sp)
56370e9f 149#define TOPm1s (*(sp-1))
7dca457a 150#define TOPp1s (*(sp+1))
2d8e6c8d
GS
151#define TOPp (SvPV(TOPs, PL_na)) /* deprecated */
152#define TOPpx (SvPV(TOPs, n_a))
463ee0b2 153#define TOPn (SvNV(TOPs))
a0d0e21e 154#define TOPi ((IV)SvIV(TOPs))
ff68c719 155#define TOPu ((UV)SvUV(TOPs))
463ee0b2 156#define TOPl ((long)SvIV(TOPs))
c5a0f51a 157#define TOPul ((unsigned long)SvUV(TOPs))
1b8cd678 158#ifdef HAS_QUAD
d9b3e12d 159#define TOPq ((Quad_t)SvIV(TOPs))
c5a0f51a 160#define TOPuq ((Uquad_t)SvUV(TOPs))
d9b3e12d 161#endif
79072805
LW
162
163/* Go to some pains in the rare event that we must extend the stack. */
954c1994
GS
164
165/*
166=for apidoc Am|void|EXTEND|SP|int nitems
167Used to extend the argument stack for an XSUB's return values. Once
4375e838 168used, guarantees that there is room for at least C<nitems> to be pushed
954c1994
GS
169onto the stack.
170
171=for apidoc Am|void|PUSHs|SV* sv
aacdac46 172Push an SV onto the stack. The stack must have room for this element.
fb7377f8
NC
173Does not handle 'set' magic. Does not use C<TARG>. See also C<PUSHmortal>,
174C<XPUSHs> and C<XPUSHmortal>.
954c1994
GS
175
176=for apidoc Am|void|PUSHp|char* str|STRLEN len
177Push a string onto the stack. The stack must have room for this element.
fb7377f8
NC
178The C<len> indicates the length of the string. Handles 'set' magic. Uses
179C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to declare it. Do not
180call multiple C<TARG>-oriented macros to return lists from XSUB's - see
181C<mPUSHp> instead. See also C<XPUSHp> and C<mXPUSHp>.
954c1994
GS
182
183=for apidoc Am|void|PUSHn|NV nv
184Push a double onto the stack. The stack must have room for this element.
fb7377f8
NC
185Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be
186called to declare it. Do not call multiple C<TARG>-oriented macros to
187return lists from XSUB's - see C<mPUSHn> instead. See also C<XPUSHn> and
188C<mXPUSHn>.
954c1994
GS
189
190=for apidoc Am|void|PUSHi|IV iv
191Push an integer onto the stack. The stack must have room for this element.
fb7377f8
NC
192Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be
193called to declare it. Do not call multiple C<TARG>-oriented macros to
194return lists from XSUB's - see C<mPUSHi> instead. See also C<XPUSHi> and
195C<mXPUSHi>.
954c1994
GS
196
197=for apidoc Am|void|PUSHu|UV uv
198Push an unsigned integer onto the stack. The stack must have room for this
fb7377f8
NC
199element. Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG>
200should be called to declare it. Do not call multiple C<TARG>-oriented
201macros to return lists from XSUB's - see C<mPUSHu> instead. See also
202C<XPUSHu> and C<mXPUSHu>.
954c1994
GS
203
204=for apidoc Am|void|XPUSHs|SV* sv
205Push an SV onto the stack, extending the stack if necessary. Does not
fb7377f8
NC
206handle 'set' magic. Does not use C<TARG>. See also C<XPUSHmortal>,
207C<PUSHs> and C<PUSHmortal>.
954c1994
GS
208
209=for apidoc Am|void|XPUSHp|char* str|STRLEN len
210Push a string onto the stack, extending the stack if necessary. The C<len>
fb7377f8
NC
211indicates the length of the string. Handles 'set' magic. Uses C<TARG>, so
212C<dTARGET> or C<dXSTARG> should be called to declare it. Do not call
213multiple C<TARG>-oriented macros to return lists from XSUB's - see
214C<mXPUSHp> instead. See also C<PUSHp> and C<mPUSHp>.
954c1994
GS
215
216=for apidoc Am|void|XPUSHn|NV nv
217Push a double onto the stack, extending the stack if necessary. Handles
fb7377f8
NC
218'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to
219declare it. Do not call multiple C<TARG>-oriented macros to return lists
220from XSUB's - see C<mXPUSHn> instead. See also C<PUSHn> and C<mPUSHn>.
954c1994
GS
221
222=for apidoc Am|void|XPUSHi|IV iv
223Push an integer onto the stack, extending the stack if necessary. Handles
fb7377f8
NC
224'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to
225declare it. Do not call multiple C<TARG>-oriented macros to return lists
226from XSUB's - see C<mXPUSHi> instead. See also C<PUSHi> and C<mPUSHi>.
954c1994
GS
227
228=for apidoc Am|void|XPUSHu|UV uv
aacdac46 229Push an unsigned integer onto the stack, extending the stack if necessary.
fb7377f8
NC
230Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be
231called to declare it. Do not call multiple C<TARG>-oriented macros to
232return lists from XSUB's - see C<mXPUSHu> instead. See also C<PUSHu> and
233C<mPUSHu>.
234
235=for apidoc Am|void|PUSHmortal
236Push a new mortal SV onto the stack. The stack must have room for this
237element. Does not handle 'set' magic. Does not use C<TARG>. See also
238C<PUSHs>, C<XPUSHmortal> and C<XPUSHs>.
239
240=for apidoc Am|void|mPUSHp|char* str|STRLEN len
241Push a string onto the stack. The stack must have room for this element.
242The C<len> indicates the length of the string. Handles 'set' magic. Does
243not use C<TARG>. See also C<PUSHp>, C<mXPUSHp> and C<XPUSHp>.
244
245=for apidoc Am|void|mPUSHn|NV nv
246Push a double onto the stack. The stack must have room for this element.
247Handles 'set' magic. Does not use C<TARG>. See also C<PUSHn>, C<mXPUSHn>
248and C<XPUSHn>.
249
250=for apidoc Am|void|mPUSHi|IV iv
251Push an integer onto the stack. The stack must have room for this element.
252Handles 'set' magic. Does not use C<TARG>. See also C<PUSHi>, C<mXPUSHi>
253and C<XPUSHi>.
254
255=for apidoc Am|void|mPUSHu|UV uv
256Push an unsigned integer onto the stack. The stack must have room for this
257element. Handles 'set' magic. Does not use C<TARG>. See also C<PUSHu>,
258C<mXPUSHu> and C<XPUSHu>.
259
260=for apidoc Am|void|XPUSHmortal
261Push a new mortal SV onto the stack, extending the stack if necessary. Does
262not handle 'set' magic. Does not use C<TARG>. See also C<XPUSHs>,
263C<PUSHmortal> and C<PUSHs>.
264
265=for apidoc Am|void|mXPUSHp|char* str|STRLEN len
266Push a string onto the stack, extending the stack if necessary. The C<len>
267indicates the length of the string. Handles 'set' magic. Does not use
268C<TARG>. See also C<XPUSHp>, C<mPUSHp> and C<PUSHp>.
269
270=for apidoc Am|void|mXPUSHn|NV nv
271Push a double onto the stack, extending the stack if necessary. Handles
272'set' magic. Does not use C<TARG>. See also C<XPUSHn>, C<mPUSHn> and
273C<PUSHn>.
274
275=for apidoc Am|void|mXPUSHi|IV iv
276Push an integer onto the stack, extending the stack if necessary. Handles
277'set' magic. Does not use C<TARG>. See also C<XPUSHi>, C<mPUSHi> and
278C<PUSHi>.
279
280=for apidoc Am|void|mXPUSHu|UV uv
281Push an unsigned integer onto the stack, extending the stack if necessary.
282Handles 'set' magic. Does not use C<TARG>. See also C<XPUSHu>, C<mPUSHu>
283and C<PUSHu>.
954c1994
GS
284
285=cut
286*/
287
c43a4d73 288#define EXTEND(p,n) STMT_START { if (PL_stack_max - p < (int)(n)) { \
bbce6d69 289 sp = stack_grow(sp,p, (int) (n)); \
86547924 290 } } STMT_END
a0d0e21e 291
79072805 292/* Same thing, but update mark register too. */
c43a4d73 293#define MEXTEND(p,n) STMT_START {if (PL_stack_max - p < (int)(n)) { \
3280af22 294 int markoff = mark - PL_stack_base; \
bbce6d69 295 sp = stack_grow(sp,p,(int) (n)); \
3280af22 296 mark = PL_stack_base + markoff; \
86547924 297 } } STMT_END
79072805
LW
298
299#define PUSHs(s) (*++sp = (s))
86547924 300#define PUSHTARG STMT_START { SvSETMAGIC(TARG); PUSHs(TARG); } STMT_END
301#define PUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); PUSHTARG; } STMT_END
65202027 302#define PUSHn(n) STMT_START { sv_setnv(TARG, (NV)(n)); PUSHTARG; } STMT_END
86547924 303#define PUSHi(i) STMT_START { sv_setiv(TARG, (IV)(i)); PUSHTARG; } STMT_END
55497cff 304#define PUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); PUSHTARG; } STMT_END
79072805 305
86547924 306#define XPUSHs(s) STMT_START { EXTEND(sp,1); (*++sp = (s)); } STMT_END
307#define XPUSHTARG STMT_START { SvSETMAGIC(TARG); XPUSHs(TARG); } STMT_END
308#define XPUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); XPUSHTARG; } STMT_END
65202027 309#define XPUSHn(n) STMT_START { sv_setnv(TARG, (NV)(n)); XPUSHTARG; } STMT_END
86547924 310#define XPUSHi(i) STMT_START { sv_setiv(TARG, (IV)(i)); XPUSHTARG; } STMT_END
55497cff 311#define XPUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); XPUSHTARG; } STMT_END
b162f9ea 312#define XPUSHundef STMT_START { SvOK_off(TARG); XPUSHs(TARG); } STMT_END
79072805 313
fb7377f8
NC
314#define PUSHmortal PUSHs(sv_newmortal())
315#define mPUSHp(p,l) sv_setpvn_mg(PUSHmortal, (p), (l))
316#define mPUSHn(n) sv_setnv_mg(PUSHmortal, (NV)(n))
317#define mPUSHi(i) sv_setiv_mg(PUSHmortal, (IV)(i))
318#define mPUSHu(u) sv_setuv_mg(PUSHmortal, (UV)(u))
319
320#define XPUSHmortal XPUSHs(sv_newmortal())
321#define mXPUSHp(p,l) STMT_START { EXTEND(sp,1); sv_setpvn_mg(PUSHmortal, (p), (l)); } STMT_END
322#define mXPUSHn(n) STMT_START { EXTEND(sp,1); sv_setnv_mg(PUSHmortal, (NV)(n)); } STMT_END
323#define mXPUSHi(i) STMT_START { EXTEND(sp,1); sv_setiv_mg(PUSHmortal, (IV)(i)); } STMT_END
324#define mXPUSHu(u) STMT_START { EXTEND(sp,1); sv_setuv_mg(PUSHmortal, (UV)(u)); } STMT_END
325
79072805 326#define SETs(s) (*sp = s)
86547924 327#define SETTARG STMT_START { SvSETMAGIC(TARG); SETs(TARG); } STMT_END
328#define SETp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); SETTARG; } STMT_END
65202027 329#define SETn(n) STMT_START { sv_setnv(TARG, (NV)(n)); SETTARG; } STMT_END
86547924 330#define SETi(i) STMT_START { sv_setiv(TARG, (IV)(i)); SETTARG; } STMT_END
55497cff 331#define SETu(u) STMT_START { sv_setuv(TARG, (UV)(u)); SETTARG; } STMT_END
a0d0e21e 332
79072805
LW
333#define dTOPss SV *sv = TOPs
334#define dPOPss SV *sv = POPs
65202027
DS
335#define dTOPnv NV value = TOPn
336#define dPOPnv NV value = POPn
a0d0e21e
LW
337#define dTOPiv IV value = TOPi
338#define dPOPiv IV value = POPi
55497cff 339#define dTOPuv UV value = TOPu
340#define dPOPuv UV value = POPu
1b8cd678 341#ifdef HAS_QUAD
2d4389e4
JH
342#define dTOPqv Quad_t value = TOPu
343#define dPOPqv Quad_t value = POPu
344#define dTOPuqv Uquad_t value = TOPuq
345#define dPOPuqv Uquad_t value = POPuq
346#endif
79072805 347
7a4c00b4 348#define dPOPXssrl(X) SV *right = POPs; SV *left = CAT2(X,s)
65202027 349#define dPOPXnnrl(X) NV right = POPn; NV left = CAT2(X,n)
7a4c00b4 350#define dPOPXiirl(X) IV right = POPi; IV left = CAT2(X,i)
351
352#define USE_LEFT(sv) \
533c011a 353 (SvOK(sv) || SvGMAGICAL(sv) || !(PL_op->op_flags & OPf_STACKED))
7a4c00b4 354#define dPOPXnnrl_ul(X) \
65202027 355 NV right = POPn; \
7a4c00b4 356 SV *leftsv = CAT2(X,s); \
65202027 357 NV left = USE_LEFT(leftsv) ? SvNV(leftsv) : 0.0
7a4c00b4 358#define dPOPXiirl_ul(X) \
359 IV right = POPi; \
360 SV *leftsv = CAT2(X,s); \
361 IV left = USE_LEFT(leftsv) ? SvIV(leftsv) : 0
362
363#define dPOPPOPssrl dPOPXssrl(POP)
364#define dPOPPOPnnrl dPOPXnnrl(POP)
365#define dPOPPOPnnrl_ul dPOPXnnrl_ul(POP)
366#define dPOPPOPiirl dPOPXiirl(POP)
367#define dPOPPOPiirl_ul dPOPXiirl_ul(POP)
368
369#define dPOPTOPssrl dPOPXssrl(TOP)
370#define dPOPTOPnnrl dPOPXnnrl(TOP)
371#define dPOPTOPnnrl_ul dPOPXnnrl_ul(TOP)
372#define dPOPTOPiirl dPOPXiirl(TOP)
373#define dPOPTOPiirl_ul dPOPXiirl_ul(TOP)
79072805 374
3280af22
NIS
375#define RETPUSHYES RETURNX(PUSHs(&PL_sv_yes))
376#define RETPUSHNO RETURNX(PUSHs(&PL_sv_no))
377#define RETPUSHUNDEF RETURNX(PUSHs(&PL_sv_undef))
79072805 378
3280af22
NIS
379#define RETSETYES RETURNX(SETs(&PL_sv_yes))
380#define RETSETNO RETURNX(SETs(&PL_sv_no))
381#define RETSETUNDEF RETURNX(SETs(&PL_sv_undef))
79072805 382
533c011a 383#define ARGTARG PL_op->op_targ
b162f9ea
IZ
384
385 /* See OPpTARGET_MY: */
386#define MAXARG (PL_op->op_private & 15)
79072805 387
e336de0d
GS
388#define SWITCHSTACK(f,t) \
389 STMT_START { \
677b06e3 390 AvFILLp(f) = sp - PL_stack_base; \
3280af22 391 PL_stack_base = AvARRAY(t); \
677b06e3 392 PL_stack_max = PL_stack_base + AvMAX(t); \
3280af22 393 sp = PL_stack_sp = PL_stack_base + AvFILLp(t); \
677b06e3 394 PL_curstack = t; \
e336de0d 395 } STMT_END
79072805 396
bbce6d69 397#define EXTEND_MORTAL(n) \
677b06e3
GS
398 STMT_START { \
399 if (PL_tmps_ix + (n) >= PL_tmps_max) \
400 tmps_grow(n); \
401 } STMT_END
bbce6d69 402
a0d0e21e
LW
403#define AMGf_noright 1
404#define AMGf_noleft 2
405#define AMGf_assign 4
406#define AMGf_unary 8
407
86547924 408#define tryAMAGICbinW(meth,assign,set) STMT_START { \
3280af22 409 if (PL_amagic_generation) { \
a0d0e21e
LW
410 SV* tmpsv; \
411 SV* right= *(sp); SV* left= *(sp-1);\
412 if ((SvAMAGIC(left)||SvAMAGIC(right))&&\
413 (tmpsv=amagic_call(left, \
414 right, \
415 CAT2(meth,_amg), \
416 (assign)? AMGf_assign: 0))) {\
417 SPAGAIN; \
418 (void)POPs; set(tmpsv); RETURN; } \
419 } \
86547924 420 } STMT_END
a0d0e21e
LW
421
422#define tryAMAGICbin(meth,assign) tryAMAGICbinW(meth,assign,SETsv)
423#define tryAMAGICbinSET(meth,assign) tryAMAGICbinW(meth,assign,SETs)
424
3280af22 425#define AMG_CALLun(sv,meth) amagic_call(sv,&PL_sv_undef, \
a0d0e21e
LW
426 CAT2(meth,_amg),AMGf_noright | AMGf_unary)
427#define AMG_CALLbinL(left,right,meth) \
428 amagic_call(left,right,CAT2(meth,_amg),AMGf_noright)
429
e8c20960 430#define tryAMAGICunW(meth,set,shift,ret) STMT_START { \
3280af22 431 if (PL_amagic_generation) { \
a0d0e21e 432 SV* tmpsv; \
f5284f61 433 SV* arg= sp[shift]; \
c4459e09 434 if(0) goto am_again; /* shut up unused warning */ \
f5284f61 435 am_again: \
a0d0e21e
LW
436 if ((SvAMAGIC(arg))&&\
437 (tmpsv=AMG_CALLun(arg,meth))) {\
f5284f61 438 SPAGAIN; if (shift) sp += shift; \
e8c20960 439 set(tmpsv); ret; } \
a0d0e21e 440 } \
86547924 441 } STMT_END
a0d0e21e 442
f5284f61
IZ
443#define FORCE_SETs(sv) STMT_START { sv_setsv(TARG, (sv)); SETTARG; } STMT_END
444
b162f9ea
IZ
445#define tryAMAGICun(meth) tryAMAGICunW(meth,SETsvUN,0,RETURN)
446#define tryAMAGICunSET(meth) tryAMAGICunW(meth,SETs,0,RETURN)
f5284f61
IZ
447#define tryAMAGICunTARGET(meth, shift) \
448 { dSP; sp--; /* get TARGET from below PL_stack_sp */ \
449 { dTARGETSTACKED; \
e8c20960
IZ
450 { dSP; tryAMAGICunW(meth,FORCE_SETs,shift,RETURN);}}}
451
aacdac46
NIS
452#define setAGAIN(ref) sv = ref; \
453 if (!SvROK(ref)) \
cea2e8a9 454 Perl_croak(aTHX_ "Overloaded dereference did not return a reference"); \
aacdac46
NIS
455 if (ref != arg && SvRV(ref) != SvRV(arg)) { \
456 arg = ref; \
457 goto am_again; \
458 }
e8c20960 459
0f4592ef 460#define tryAMAGICunDEREF(meth) tryAMAGICunW(meth,setAGAIN,0,(void)0)
a0d0e21e 461
533c011a 462#define opASSIGN (PL_op->op_flags & OPf_STACKED)
e9905555 463#define SETsv(sv) STMT_START { \
b162f9ea
IZ
464 if (opASSIGN || (SvFLAGS(TARG) & SVs_PADMY)) \
465 { sv_setsv(TARG, (sv)); SETTARG; } \
466 else SETs(sv); } STMT_END
467
468#define SETsvUN(sv) STMT_START { \
469 if (SvFLAGS(TARG) & SVs_PADMY) \
470 { sv_setsv(TARG, (sv)); SETTARG; } \
e9905555 471 else SETs(sv); } STMT_END
a0d0e21e
LW
472
473/* newSVsv does not behave as advertised, so we copy missing
474 * information by hand */
475
76e3520e
GS
476/* SV* ref causes confusion with the member variable
477 changed SV* ref to SV* tmpRef */
478#define RvDEEPCP(rv) STMT_START { SV* tmpRef=SvRV(rv); \
479 if (SvREFCNT(tmpRef)>1) { \
a9dd8465 480 SvRV(rv)=AMG_CALLun(rv,copy); \
76e3520e 481 SvREFCNT_dec(tmpRef); \
86547924 482 } } STMT_END
78f9721b
SM
483
484/*
485=for apidoc mU||LVRET
486True if this op will be the return value of an lvalue subroutine
487
488=cut */
9d96b2e7 489#define LVRET ((PL_op->op_private & OPpMAYBE_LVSUB) && is_lvalue_sub())