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