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 3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999,
31ab2e0d 4 * 2000, 2001, 2002, 2003, 2004, 2005 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
db910c29
NC
66#define PUSHMARK(p) \
67 STMT_START { \
68 if (++PL_markstack_ptr == PL_markstack_max) \
69 markstack_grow(); \
70 *PL_markstack_ptr = (p) - PL_stack_base; \
71 } STMT_END
a0d0e21e 72
3280af22
NIS
73#define TOPMARK (*PL_markstack_ptr)
74#define POPMARK (*PL_markstack_ptr--)
a0d0e21e 75
39644a26
TJ
76#define dSP register SV **sp = PL_stack_sp
77#define djSP dSP
3280af22 78#define dMARK register SV **mark = PL_stack_base + POPMARK
8c18bf38 79#define dORIGMARK const I32 origmark = mark - PL_stack_base
3280af22 80#define ORIGMARK (PL_stack_base + origmark)
79072805 81
3280af22 82#define SPAGAIN sp = PL_stack_sp
db910c29 83#define MSPAGAIN STMT_START { sp = PL_stack_sp; mark = ORIGMARK; } STMT_END
79072805 84
533c011a 85#define GETTARGETSTACKED targ = (PL_op->op_flags & OPf_STACKED ? POPs : PAD_SV(PL_op->op_targ))
79072805
LW
86#define dTARGETSTACKED SV * GETTARGETSTACKED
87
533c011a 88#define GETTARGET targ = PAD_SV(PL_op->op_targ)
79072805
LW
89#define dTARGET SV * GETTARGET
90
533c011a 91#define GETATARGET targ = (PL_op->op_flags & OPf_STACKED ? sp[-1] : PAD_SV(PL_op->op_targ))
79072805
LW
92#define dATARGET SV * GETATARGET
93
94#define dTARG SV *targ
95
533c011a 96#define NORMAL PL_op->op_next
cea2e8a9 97#define DIE return Perl_die
f9af18b8
RB
98#ifndef PERL_CORE
99# define DIE_NULL return DieNull
100#endif
79072805 101
954c1994
GS
102/*
103=for apidoc Ams||PUTBACK
104Closing bracket for XSUB arguments. This is usually handled by C<xsubpp>.
105See C<PUSHMARK> and L<perlcall> for other uses.
106
107=for apidoc Amn|SV*|POPs
108Pops an SV off the stack.
109
110=for apidoc Amn|char*|POPp
291a7e74 111Pops a string off the stack. Deprecated. New code should use POPpx.
595ae481
NIS
112
113=for apidoc Amn|char*|POPpx
954c1994 114Pops a string off the stack.
595ae481
NIS
115
116=for apidoc Amn|char*|POPpbytex
117Pops a string off the stack which must consist of bytes i.e. characters < 256.
954c1994
GS
118
119=for apidoc Amn|NV|POPn
120Pops a double off the stack.
121
122=for apidoc Amn|IV|POPi
123Pops an integer off the stack.
124
125=for apidoc Amn|long|POPl
126Pops a long off the stack.
127
128=cut
129*/
130
3280af22 131#define PUTBACK PL_stack_sp = sp
c01caf97
NC
132#define RETURN return (PUTBACK, NORMAL)
133#define RETURNOP(o) return (PUTBACK, o)
134#define RETURNX(x) return (x, PUTBACK, NORMAL)
79072805
LW
135
136#define POPs (*sp--)
2d8e6c8d 137#define POPp (SvPVx(POPs, PL_na)) /* deprecated */
291a7e74
NC
138#define POPpx (SvPVx_nolen(POPs))
139#define POPpconstx (SvPVx_nolen_const(POPs))
140#define POPpbytex (SvPVbytex_nolen(POPs))
463ee0b2 141#define POPn (SvNVx(POPs))
a0d0e21e 142#define POPi ((IV)SvIVx(POPs))
ff68c719 143#define POPu ((UV)SvUVx(POPs))
463ee0b2 144#define POPl ((long)SvIVx(POPs))
d9b3e12d 145#define POPul ((unsigned long)SvIVx(POPs))
1b8cd678 146#ifdef HAS_QUAD
d9b3e12d 147#define POPq ((Quad_t)SvIVx(POPs))
c5a0f51a 148#define POPuq ((Uquad_t)SvUVx(POPs))
d9b3e12d 149#endif
79072805
LW
150
151#define TOPs (*sp)
56370e9f 152#define TOPm1s (*(sp-1))
7dca457a 153#define TOPp1s (*(sp+1))
2d8e6c8d 154#define TOPp (SvPV(TOPs, PL_na)) /* deprecated */
291a7e74 155#define TOPpx (SvPV_nolen(TOPs))
463ee0b2 156#define TOPn (SvNV(TOPs))
a0d0e21e 157#define TOPi ((IV)SvIV(TOPs))
ff68c719 158#define TOPu ((UV)SvUV(TOPs))
463ee0b2 159#define TOPl ((long)SvIV(TOPs))
c5a0f51a 160#define TOPul ((unsigned long)SvUV(TOPs))
1b8cd678 161#ifdef HAS_QUAD
d9b3e12d 162#define TOPq ((Quad_t)SvIV(TOPs))
c5a0f51a 163#define TOPuq ((Uquad_t)SvUV(TOPs))
d9b3e12d 164#endif
79072805
LW
165
166/* Go to some pains in the rare event that we must extend the stack. */
954c1994
GS
167
168/*
169=for apidoc Am|void|EXTEND|SP|int nitems
170Used to extend the argument stack for an XSUB's return values. Once
4375e838 171used, guarantees that there is room for at least C<nitems> to be pushed
954c1994
GS
172onto the stack.
173
174=for apidoc Am|void|PUSHs|SV* sv
aacdac46 175Push an SV onto the stack. The stack must have room for this element.
fb7377f8
NC
176Does not handle 'set' magic. Does not use C<TARG>. See also C<PUSHmortal>,
177C<XPUSHs> and C<XPUSHmortal>.
954c1994
GS
178
179=for apidoc Am|void|PUSHp|char* str|STRLEN len
180Push a string onto the stack. The stack must have room for this element.
fb7377f8
NC
181The C<len> indicates the length of the string. Handles 'set' magic. Uses
182C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to declare it. Do not
183call multiple C<TARG>-oriented macros to return lists from XSUB's - see
184C<mPUSHp> instead. See also C<XPUSHp> and C<mXPUSHp>.
954c1994
GS
185
186=for apidoc Am|void|PUSHn|NV nv
187Push a double onto the stack. The stack must have room for this element.
fb7377f8
NC
188Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be
189called to declare it. Do not call multiple C<TARG>-oriented macros to
190return lists from XSUB's - see C<mPUSHn> instead. See also C<XPUSHn> and
191C<mXPUSHn>.
954c1994
GS
192
193=for apidoc Am|void|PUSHi|IV iv
194Push an integer onto the stack. The stack must have room for this element.
fb7377f8
NC
195Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be
196called to declare it. Do not call multiple C<TARG>-oriented macros to
197return lists from XSUB's - see C<mPUSHi> instead. See also C<XPUSHi> and
198C<mXPUSHi>.
954c1994
GS
199
200=for apidoc Am|void|PUSHu|UV uv
201Push an unsigned integer onto the stack. The stack must have room for this
fb7377f8
NC
202element. Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG>
203should be called to declare it. Do not call multiple C<TARG>-oriented
204macros to return lists from XSUB's - see C<mPUSHu> instead. See also
205C<XPUSHu> and C<mXPUSHu>.
954c1994
GS
206
207=for apidoc Am|void|XPUSHs|SV* sv
208Push an SV onto the stack, extending the stack if necessary. Does not
fb7377f8
NC
209handle 'set' magic. Does not use C<TARG>. See also C<XPUSHmortal>,
210C<PUSHs> and C<PUSHmortal>.
954c1994
GS
211
212=for apidoc Am|void|XPUSHp|char* str|STRLEN len
213Push a string onto the stack, extending the stack if necessary. The C<len>
fb7377f8
NC
214indicates the length of the string. Handles 'set' magic. Uses C<TARG>, so
215C<dTARGET> or C<dXSTARG> should be called to declare it. Do not call
216multiple C<TARG>-oriented macros to return lists from XSUB's - see
217C<mXPUSHp> instead. See also C<PUSHp> and C<mPUSHp>.
954c1994
GS
218
219=for apidoc Am|void|XPUSHn|NV nv
220Push a double onto the stack, extending the stack if necessary. Handles
fb7377f8
NC
221'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to
222declare it. Do not call multiple C<TARG>-oriented macros to return lists
223from XSUB's - see C<mXPUSHn> instead. See also C<PUSHn> and C<mPUSHn>.
954c1994
GS
224
225=for apidoc Am|void|XPUSHi|IV iv
226Push an integer onto the stack, extending the stack if necessary. Handles
fb7377f8
NC
227'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to
228declare it. Do not call multiple C<TARG>-oriented macros to return lists
229from XSUB's - see C<mXPUSHi> instead. See also C<PUSHi> and C<mPUSHi>.
954c1994
GS
230
231=for apidoc Am|void|XPUSHu|UV uv
aacdac46 232Push an unsigned integer onto the stack, extending the stack if necessary.
fb7377f8
NC
233Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be
234called to declare it. Do not call multiple C<TARG>-oriented macros to
235return lists from XSUB's - see C<mXPUSHu> instead. See also C<PUSHu> and
236C<mPUSHu>.
237
238=for apidoc Am|void|PUSHmortal
239Push a new mortal SV onto the stack. The stack must have room for this
240element. Does not handle 'set' magic. Does not use C<TARG>. See also
241C<PUSHs>, C<XPUSHmortal> and C<XPUSHs>.
242
243=for apidoc Am|void|mPUSHp|char* str|STRLEN len
244Push a string onto the stack. The stack must have room for this element.
245The C<len> indicates the length of the string. Handles 'set' magic. Does
246not use C<TARG>. See also C<PUSHp>, C<mXPUSHp> and C<XPUSHp>.
247
248=for apidoc Am|void|mPUSHn|NV nv
249Push a double onto the stack. The stack must have room for this element.
250Handles 'set' magic. Does not use C<TARG>. See also C<PUSHn>, C<mXPUSHn>
251and C<XPUSHn>.
252
253=for apidoc Am|void|mPUSHi|IV iv
254Push an integer onto the stack. The stack must have room for this element.
255Handles 'set' magic. Does not use C<TARG>. See also C<PUSHi>, C<mXPUSHi>
256and C<XPUSHi>.
257
258=for apidoc Am|void|mPUSHu|UV uv
259Push an unsigned integer onto the stack. The stack must have room for this
260element. Handles 'set' magic. Does not use C<TARG>. See also C<PUSHu>,
261C<mXPUSHu> and C<XPUSHu>.
262
263=for apidoc Am|void|XPUSHmortal
264Push a new mortal SV onto the stack, extending the stack if necessary. Does
265not handle 'set' magic. Does not use C<TARG>. See also C<XPUSHs>,
266C<PUSHmortal> and C<PUSHs>.
267
268=for apidoc Am|void|mXPUSHp|char* str|STRLEN len
269Push a string onto the stack, extending the stack if necessary. The C<len>
270indicates the length of the string. Handles 'set' magic. Does not use
271C<TARG>. See also C<XPUSHp>, C<mPUSHp> and C<PUSHp>.
272
273=for apidoc Am|void|mXPUSHn|NV nv
274Push a double onto the stack, extending the stack if necessary. Handles
275'set' magic. Does not use C<TARG>. See also C<XPUSHn>, C<mPUSHn> and
276C<PUSHn>.
277
278=for apidoc Am|void|mXPUSHi|IV iv
279Push an integer onto the stack, extending the stack if necessary. Handles
280'set' magic. Does not use C<TARG>. See also C<XPUSHi>, C<mPUSHi> and
281C<PUSHi>.
282
283=for apidoc Am|void|mXPUSHu|UV uv
284Push an unsigned integer onto the stack, extending the stack if necessary.
285Handles 'set' magic. Does not use C<TARG>. See also C<XPUSHu>, C<mPUSHu>
286and C<PUSHu>.
954c1994
GS
287
288=cut
289*/
290
c43a4d73 291#define EXTEND(p,n) STMT_START { if (PL_stack_max - p < (int)(n)) { \
bbce6d69 292 sp = stack_grow(sp,p, (int) (n)); \
86547924 293 } } STMT_END
a0d0e21e 294
79072805 295/* Same thing, but update mark register too. */
ce7d4f40
AL
296#define MEXTEND(p,n) STMT_START {if (PL_stack_max - p < (int)(n)) { \
297 const int markoff = mark - PL_stack_base; \
bbce6d69 298 sp = stack_grow(sp,p,(int) (n)); \
3280af22 299 mark = PL_stack_base + markoff; \
86547924 300 } } STMT_END
79072805
LW
301
302#define PUSHs(s) (*++sp = (s))
86547924 303#define PUSHTARG STMT_START { SvSETMAGIC(TARG); PUSHs(TARG); } STMT_END
304#define PUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); PUSHTARG; } STMT_END
65202027 305#define PUSHn(n) STMT_START { sv_setnv(TARG, (NV)(n)); PUSHTARG; } STMT_END
86547924 306#define PUSHi(i) STMT_START { sv_setiv(TARG, (IV)(i)); PUSHTARG; } STMT_END
55497cff 307#define PUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); PUSHTARG; } STMT_END
79072805 308
86547924 309#define XPUSHs(s) STMT_START { EXTEND(sp,1); (*++sp = (s)); } STMT_END
310#define XPUSHTARG STMT_START { SvSETMAGIC(TARG); XPUSHs(TARG); } STMT_END
311#define XPUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); XPUSHTARG; } STMT_END
65202027 312#define XPUSHn(n) STMT_START { sv_setnv(TARG, (NV)(n)); XPUSHTARG; } STMT_END
86547924 313#define XPUSHi(i) STMT_START { sv_setiv(TARG, (IV)(i)); XPUSHTARG; } STMT_END
55497cff 314#define XPUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); XPUSHTARG; } STMT_END
b162f9ea 315#define XPUSHundef STMT_START { SvOK_off(TARG); XPUSHs(TARG); } STMT_END
79072805 316
fb7377f8
NC
317#define PUSHmortal PUSHs(sv_newmortal())
318#define mPUSHp(p,l) sv_setpvn_mg(PUSHmortal, (p), (l))
319#define mPUSHn(n) sv_setnv_mg(PUSHmortal, (NV)(n))
320#define mPUSHi(i) sv_setiv_mg(PUSHmortal, (IV)(i))
321#define mPUSHu(u) sv_setuv_mg(PUSHmortal, (UV)(u))
322
323#define XPUSHmortal XPUSHs(sv_newmortal())
324#define mXPUSHp(p,l) STMT_START { EXTEND(sp,1); sv_setpvn_mg(PUSHmortal, (p), (l)); } STMT_END
325#define mXPUSHn(n) STMT_START { EXTEND(sp,1); sv_setnv_mg(PUSHmortal, (NV)(n)); } STMT_END
326#define mXPUSHi(i) STMT_START { EXTEND(sp,1); sv_setiv_mg(PUSHmortal, (IV)(i)); } STMT_END
327#define mXPUSHu(u) STMT_START { EXTEND(sp,1); sv_setuv_mg(PUSHmortal, (UV)(u)); } STMT_END
328
79072805 329#define SETs(s) (*sp = s)
86547924 330#define SETTARG STMT_START { SvSETMAGIC(TARG); SETs(TARG); } STMT_END
331#define SETp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); SETTARG; } STMT_END
65202027 332#define SETn(n) STMT_START { sv_setnv(TARG, (NV)(n)); SETTARG; } STMT_END
86547924 333#define SETi(i) STMT_START { sv_setiv(TARG, (IV)(i)); SETTARG; } STMT_END
55497cff 334#define SETu(u) STMT_START { sv_setuv(TARG, (UV)(u)); SETTARG; } STMT_END
a0d0e21e 335
79072805
LW
336#define dTOPss SV *sv = TOPs
337#define dPOPss SV *sv = POPs
65202027
DS
338#define dTOPnv NV value = TOPn
339#define dPOPnv NV value = POPn
a0d0e21e
LW
340#define dTOPiv IV value = TOPi
341#define dPOPiv IV value = POPi
55497cff 342#define dTOPuv UV value = TOPu
343#define dPOPuv UV value = POPu
1b8cd678 344#ifdef HAS_QUAD
2d4389e4
JH
345#define dTOPqv Quad_t value = TOPu
346#define dPOPqv Quad_t value = POPu
347#define dTOPuqv Uquad_t value = TOPuq
348#define dPOPuqv Uquad_t value = POPuq
349#endif
79072805 350
7a4c00b4 351#define dPOPXssrl(X) SV *right = POPs; SV *left = CAT2(X,s)
65202027 352#define dPOPXnnrl(X) NV right = POPn; NV left = CAT2(X,n)
7a4c00b4 353#define dPOPXiirl(X) IV right = POPi; IV left = CAT2(X,i)
354
355#define USE_LEFT(sv) \
533c011a 356 (SvOK(sv) || SvGMAGICAL(sv) || !(PL_op->op_flags & OPf_STACKED))
7a4c00b4 357#define dPOPXnnrl_ul(X) \
65202027 358 NV right = POPn; \
7a4c00b4 359 SV *leftsv = CAT2(X,s); \
65202027 360 NV left = USE_LEFT(leftsv) ? SvNV(leftsv) : 0.0
7a4c00b4 361#define dPOPXiirl_ul(X) \
362 IV right = POPi; \
363 SV *leftsv = CAT2(X,s); \
364 IV left = USE_LEFT(leftsv) ? SvIV(leftsv) : 0
365
366#define dPOPPOPssrl dPOPXssrl(POP)
367#define dPOPPOPnnrl dPOPXnnrl(POP)
368#define dPOPPOPnnrl_ul dPOPXnnrl_ul(POP)
369#define dPOPPOPiirl dPOPXiirl(POP)
370#define dPOPPOPiirl_ul dPOPXiirl_ul(POP)
371
372#define dPOPTOPssrl dPOPXssrl(TOP)
373#define dPOPTOPnnrl dPOPXnnrl(TOP)
374#define dPOPTOPnnrl_ul dPOPXnnrl_ul(TOP)
375#define dPOPTOPiirl dPOPXiirl(TOP)
376#define dPOPTOPiirl_ul dPOPXiirl_ul(TOP)
79072805 377
3280af22
NIS
378#define RETPUSHYES RETURNX(PUSHs(&PL_sv_yes))
379#define RETPUSHNO RETURNX(PUSHs(&PL_sv_no))
380#define RETPUSHUNDEF RETURNX(PUSHs(&PL_sv_undef))
79072805 381
3280af22
NIS
382#define RETSETYES RETURNX(SETs(&PL_sv_yes))
383#define RETSETNO RETURNX(SETs(&PL_sv_no))
384#define RETSETUNDEF RETURNX(SETs(&PL_sv_undef))
79072805 385
533c011a 386#define ARGTARG PL_op->op_targ
b162f9ea
IZ
387
388 /* See OPpTARGET_MY: */
389#define MAXARG (PL_op->op_private & 15)
79072805 390
e336de0d
GS
391#define SWITCHSTACK(f,t) \
392 STMT_START { \
677b06e3 393 AvFILLp(f) = sp - PL_stack_base; \
3280af22 394 PL_stack_base = AvARRAY(t); \
677b06e3 395 PL_stack_max = PL_stack_base + AvMAX(t); \
3280af22 396 sp = PL_stack_sp = PL_stack_base + AvFILLp(t); \
677b06e3 397 PL_curstack = t; \
e336de0d 398 } STMT_END
79072805 399
bbce6d69 400#define EXTEND_MORTAL(n) \
677b06e3
GS
401 STMT_START { \
402 if (PL_tmps_ix + (n) >= PL_tmps_max) \
403 tmps_grow(n); \
404 } STMT_END
bbce6d69 405
a0d0e21e
LW
406#define AMGf_noright 1
407#define AMGf_noleft 2
408#define AMGf_assign 4
409#define AMGf_unary 8
410
c01caf97 411#define tryAMAGICbinW_var(meth_enum,assign,set) STMT_START { \
260c88e8
AL
412 if (PL_amagic_generation) { \
413 SV* const left = *(sp-1); \
414 SV* const right = *(sp); \
415 if ((SvAMAGIC(left)||SvAMAGIC(right))) {\
416 SV * const tmpsv = amagic_call(left, \
a0d0e21e 417 right, \
c01caf97 418 meth_enum, \
260c88e8
AL
419 (assign)? AMGf_assign: 0); \
420 if (tmpsv) { \
421 SPAGAIN; \
422 (void)POPs; set(tmpsv); RETURN; } \
423 } \
424 } \
86547924 425 } STMT_END
a0d0e21e 426
c01caf97
NC
427#define tryAMAGICbinW(meth,assign,set) \
428 tryAMAGICbinW_var(CAT2(meth,_amg),assign,set)
429
b21e3693
NC
430#define tryAMAGICbin_var(meth_enum,assign) \
431 tryAMAGICbinW_var(meth_enum,assign,SETsv)
432#define tryAMAGICbin(meth,assign) \
433 tryAMAGICbin_var(CAT2(meth,_amg),assign)
434
a0d0e21e
LW
435#define tryAMAGICbinSET(meth,assign) tryAMAGICbinW(meth,assign,SETs)
436
c01caf97
NC
437#define tryAMAGICbinSET_var(meth_enum,assign) \
438 tryAMAGICbinW_var(meth_enum,assign,SETs)
439
440#define AMG_CALLun_var(sv,meth_enum) amagic_call(sv,&PL_sv_undef, \
441 meth_enum,AMGf_noright | AMGf_unary)
442#define AMG_CALLun(sv,meth) AMG_CALLun_var(sv,CAT2(meth,_amg))
443
a0d0e21e
LW
444#define AMG_CALLbinL(left,right,meth) \
445 amagic_call(left,right,CAT2(meth,_amg),AMGf_noright)
446
c01caf97 447#define tryAMAGICunW_var(meth_enum,set,shift,ret) STMT_START { \
3280af22 448 if (PL_amagic_generation) { \
a0d0e21e 449 SV* tmpsv; \
f5284f61 450 SV* arg= sp[shift]; \
c4459e09 451 if(0) goto am_again; /* shut up unused warning */ \
f5284f61 452 am_again: \
a0d0e21e 453 if ((SvAMAGIC(arg))&&\
c01caf97 454 (tmpsv=AMG_CALLun_var(arg,meth_enum))) {\
f5284f61 455 SPAGAIN; if (shift) sp += shift; \
e8c20960 456 set(tmpsv); ret; } \
a0d0e21e 457 } \
86547924 458 } STMT_END
c01caf97
NC
459#define tryAMAGICunW(meth,set,shift,ret) \
460 tryAMAGICunW_var(CAT2(meth,_amg),set,shift,ret)
a0d0e21e 461
f5284f61
IZ
462#define FORCE_SETs(sv) STMT_START { sv_setsv(TARG, (sv)); SETTARG; } STMT_END
463
c01caf97
NC
464#define tryAMAGICun_var(meth_enum) tryAMAGICunW_var(meth_enum,SETsvUN,0,RETURN)
465#define tryAMAGICun(meth) tryAMAGICun_var(CAT2(meth,_amg))
b162f9ea 466#define tryAMAGICunSET(meth) tryAMAGICunW(meth,SETs,0,RETURN)
f5284f61 467#define tryAMAGICunTARGET(meth, shift) \
db910c29 468 STMT_START { dSP; sp--; /* get TARGET from below PL_stack_sp */ \
f5284f61 469 { dTARGETSTACKED; \
db910c29
NC
470 { dSP; tryAMAGICunW(meth,FORCE_SETs,shift,RETURN);}}} STMT_END
471
472#define setAGAIN(ref) \
473 STMT_START { \
474 sv = ref; \
475 if (!SvROK(ref)) \
476 Perl_croak(aTHX_ "Overloaded dereference did not return a reference"); \
477 if (ref != arg && SvRV(ref) != SvRV(arg)) { \
478 arg = ref; \
479 goto am_again; \
480 } \
481 } STMT_END
e8c20960 482
0f4592ef 483#define tryAMAGICunDEREF(meth) tryAMAGICunW(meth,setAGAIN,0,(void)0)
a0d0e21e 484
533c011a 485#define opASSIGN (PL_op->op_flags & OPf_STACKED)
e9905555 486#define SETsv(sv) STMT_START { \
b162f9ea
IZ
487 if (opASSIGN || (SvFLAGS(TARG) & SVs_PADMY)) \
488 { sv_setsv(TARG, (sv)); SETTARG; } \
489 else SETs(sv); } STMT_END
490
491#define SETsvUN(sv) STMT_START { \
492 if (SvFLAGS(TARG) & SVs_PADMY) \
493 { sv_setsv(TARG, (sv)); SETTARG; } \
e9905555 494 else SETs(sv); } STMT_END
a0d0e21e
LW
495
496/* newSVsv does not behave as advertised, so we copy missing
497 * information by hand */
498
76e3520e
GS
499/* SV* ref causes confusion with the member variable
500 changed SV* ref to SV* tmpRef */
501#define RvDEEPCP(rv) STMT_START { SV* tmpRef=SvRV(rv); \
502 if (SvREFCNT(tmpRef)>1) { \
a8dc4fe8 503 SvRV_set(rv, AMG_CALLun(rv,copy)); \
76e3520e 504 SvREFCNT_dec(tmpRef); \
86547924 505 } } STMT_END
78f9721b
SM
506
507/*
508=for apidoc mU||LVRET
509True if this op will be the return value of an lvalue subroutine
510
511=cut */
9d96b2e7 512#define LVRET ((PL_op->op_private & OPpMAYBE_LVSUB) && is_lvalue_sub())
ce7d4f40
AL
513
514/*
515 * Local variables:
516 * c-indentation-style: bsd
517 * c-basic-offset: 4
518 * indent-tabs-mode: t
519 * End:
520 *
521 * ex: set ts=8 sts=4 sw=4 noet:
522 */