Commit | Line | Data |
---|---|---|
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 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 | ||
154e47c8 | 33 | Declare Just C<SP>. This is actually identical to C<dSP>, and declares |
fac3506f MS |
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 { \ | |
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 | |
94 | Closing bracket for XSUB arguments. This is usually handled by C<xsubpp>. | |
95 | See C<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 | |
4b7c0884 | 101 | Pops a string off the stack. |
595ae481 NIS |
102 | |
103 | =for apidoc Amn|char*|POPpx | |
4b7c0884 FC |
104 | Pops a string off the stack. Identical to POPp. There are two names for |
105 | historical reasons. | |
595ae481 NIS |
106 | |
107 | =for apidoc Amn|char*|POPpbytex | |
108 | Pops a string off the stack which must consist of bytes i.e. characters < 256. | |
954c1994 GS |
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|long|POPl | |
117 | Pops a long off the stack. | |
118 | ||
119 | =cut | |
120 | */ | |
121 | ||
3280af22 | 122 | #define PUTBACK PL_stack_sp = sp |
8a67133a NC |
123 | #define RETURN return (PUTBACK, NORMAL) |
124 | #define RETURNOP(o) return (PUTBACK, o) | |
125 | #define RETURNX(x) return (x, PUTBACK, NORMAL) | |
79072805 LW |
126 | |
127 | #define POPs (*sp--) | |
4b7c0884 | 128 | #define POPp POPpx |
8c074e2a NC |
129 | #define POPpx (SvPVx_nolen(POPs)) |
130 | #define POPpconstx (SvPVx_nolen_const(POPs)) | |
131 | #define POPpbytex (SvPVbytex_nolen(POPs)) | |
463ee0b2 | 132 | #define POPn (SvNVx(POPs)) |
a0d0e21e | 133 | #define POPi ((IV)SvIVx(POPs)) |
ff68c719 | 134 | #define POPu ((UV)SvUVx(POPs)) |
463ee0b2 | 135 | #define POPl ((long)SvIVx(POPs)) |
d9b3e12d | 136 | #define POPul ((unsigned long)SvIVx(POPs)) |
79072805 LW |
137 | |
138 | #define TOPs (*sp) | |
56370e9f | 139 | #define TOPm1s (*(sp-1)) |
7dca457a | 140 | #define TOPp1s (*(sp+1)) |
4b7c0884 | 141 | #define TOPp TOPpx |
95fad918 | 142 | #define TOPpx (SvPV_nolen(TOPs)) |
463ee0b2 | 143 | #define TOPn (SvNV(TOPs)) |
a0d0e21e | 144 | #define TOPi ((IV)SvIV(TOPs)) |
ff68c719 | 145 | #define TOPu ((UV)SvUV(TOPs)) |
463ee0b2 | 146 | #define TOPl ((long)SvIV(TOPs)) |
c5a0f51a | 147 | #define TOPul ((unsigned long)SvUV(TOPs)) |
79072805 LW |
148 | |
149 | /* Go to some pains in the rare event that we must extend the stack. */ | |
954c1994 GS |
150 | |
151 | /* | |
fc16c392 | 152 | =for apidoc Am|void|EXTEND|SP|SSize_t nitems |
72d33970 | 153 | Used to extend the argument stack for an XSUB's return values. Once |
4375e838 | 154 | used, guarantees that there is room for at least C<nitems> to be pushed |
954c1994 GS |
155 | onto the stack. |
156 | ||
157 | =for apidoc Am|void|PUSHs|SV* sv | |
aacdac46 | 158 | Push an SV onto the stack. The stack must have room for this element. |
d82b684c SH |
159 | Does not handle 'set' magic. Does not use C<TARG>. See also C<PUSHmortal>, |
160 | C<XPUSHs> and C<XPUSHmortal>. | |
954c1994 GS |
161 | |
162 | =for apidoc Am|void|PUSHp|char* str|STRLEN len | |
163 | Push a string onto the stack. The stack must have room for this element. | |
d82b684c SH |
164 | The C<len> indicates the length of the string. Handles 'set' magic. Uses |
165 | C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to declare it. Do not | |
166 | call multiple C<TARG>-oriented macros to return lists from XSUB's - see | |
167 | C<mPUSHp> instead. See also C<XPUSHp> and C<mXPUSHp>. | |
954c1994 GS |
168 | |
169 | =for apidoc Am|void|PUSHn|NV nv | |
170 | Push a double onto the stack. The stack must have room for this element. | |
d82b684c SH |
171 | Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be |
172 | called to declare it. Do not call multiple C<TARG>-oriented macros to | |
173 | return lists from XSUB's - see C<mPUSHn> instead. See also C<XPUSHn> and | |
174 | C<mXPUSHn>. | |
954c1994 GS |
175 | |
176 | =for apidoc Am|void|PUSHi|IV iv | |
177 | Push an integer onto the stack. The stack must have room for this element. | |
d82b684c SH |
178 | Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be |
179 | called to declare it. Do not call multiple C<TARG>-oriented macros to | |
180 | return lists from XSUB's - see C<mPUSHi> instead. See also C<XPUSHi> and | |
181 | C<mXPUSHi>. | |
954c1994 GS |
182 | |
183 | =for apidoc Am|void|PUSHu|UV uv | |
184 | Push an unsigned integer onto the stack. The stack must have room for this | |
d82b684c SH |
185 | element. Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> |
186 | should be called to declare it. Do not call multiple C<TARG>-oriented | |
187 | macros to return lists from XSUB's - see C<mPUSHu> instead. See also | |
188 | C<XPUSHu> and C<mXPUSHu>. | |
954c1994 GS |
189 | |
190 | =for apidoc Am|void|XPUSHs|SV* sv | |
191 | Push an SV onto the stack, extending the stack if necessary. Does not | |
d82b684c SH |
192 | handle 'set' magic. Does not use C<TARG>. See also C<XPUSHmortal>, |
193 | C<PUSHs> and C<PUSHmortal>. | |
954c1994 GS |
194 | |
195 | =for apidoc Am|void|XPUSHp|char* str|STRLEN len | |
196 | Push a string onto the stack, extending the stack if necessary. The C<len> | |
d82b684c SH |
197 | indicates the length of the string. Handles 'set' magic. Uses C<TARG>, so |
198 | C<dTARGET> or C<dXSTARG> should be called to declare it. Do not call | |
199 | multiple C<TARG>-oriented macros to return lists from XSUB's - see | |
200 | C<mXPUSHp> instead. See also C<PUSHp> and C<mPUSHp>. | |
954c1994 GS |
201 | |
202 | =for apidoc Am|void|XPUSHn|NV nv | |
203 | Push a double onto the stack, extending the stack if necessary. Handles | |
d82b684c SH |
204 | 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to |
205 | declare it. Do not call multiple C<TARG>-oriented macros to return lists | |
206 | from XSUB's - see C<mXPUSHn> instead. See also C<PUSHn> and C<mPUSHn>. | |
954c1994 GS |
207 | |
208 | =for apidoc Am|void|XPUSHi|IV iv | |
209 | Push an integer 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<mXPUSHi> instead. See also C<PUSHi> and C<mPUSHi>. | |
954c1994 GS |
213 | |
214 | =for apidoc Am|void|XPUSHu|UV uv | |
aacdac46 | 215 | Push an unsigned integer onto the stack, extending the stack if necessary. |
d82b684c SH |
216 | Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be |
217 | called to declare it. Do not call multiple C<TARG>-oriented macros to | |
218 | return lists from XSUB's - see C<mXPUSHu> instead. See also C<PUSHu> and | |
219 | C<mPUSHu>. | |
220 | ||
6e449a3a MHM |
221 | =for apidoc Am|void|mPUSHs|SV* sv |
222 | Push an SV onto the stack and mortalizes the SV. The stack must have room | |
121b7712 | 223 | for this element. Does not use C<TARG>. See also C<PUSHs> and C<mXPUSHs>. |
6e449a3a | 224 | |
d82b684c SH |
225 | =for apidoc Am|void|PUSHmortal |
226 | Push a new mortal SV onto the stack. The stack must have room for this | |
121b7712 | 227 | element. Does not use C<TARG>. See also C<PUSHs>, C<XPUSHmortal> and C<XPUSHs>. |
d82b684c SH |
228 | |
229 | =for apidoc Am|void|mPUSHp|char* str|STRLEN len | |
230 | Push a string onto the stack. The stack must have room for this element. | |
121b7712 MHM |
231 | The C<len> indicates the length of the string. Does not use C<TARG>. |
232 | See also C<PUSHp>, C<mXPUSHp> and C<XPUSHp>. | |
d82b684c SH |
233 | |
234 | =for apidoc Am|void|mPUSHn|NV nv | |
235 | Push a double onto the stack. The stack must have room for this element. | |
121b7712 | 236 | Does not use C<TARG>. See also C<PUSHn>, C<mXPUSHn> and C<XPUSHn>. |
d82b684c SH |
237 | |
238 | =for apidoc Am|void|mPUSHi|IV iv | |
239 | Push an integer onto the stack. The stack must have room for this element. | |
121b7712 | 240 | Does not use C<TARG>. See also C<PUSHi>, C<mXPUSHi> and C<XPUSHi>. |
d82b684c SH |
241 | |
242 | =for apidoc Am|void|mPUSHu|UV uv | |
243 | Push an unsigned integer onto the stack. The stack must have room for this | |
121b7712 | 244 | element. Does not use C<TARG>. See also C<PUSHu>, C<mXPUSHu> and C<XPUSHu>. |
d82b684c | 245 | |
6e449a3a MHM |
246 | =for apidoc Am|void|mXPUSHs|SV* sv |
247 | Push an SV onto the stack, extending the stack if necessary and mortalizes | |
121b7712 | 248 | the SV. Does not use C<TARG>. See also C<XPUSHs> and C<mPUSHs>. |
6e449a3a | 249 | |
d82b684c | 250 | =for apidoc Am|void|XPUSHmortal |
121b7712 MHM |
251 | Push a new mortal SV onto the stack, extending the stack if necessary. |
252 | Does not use C<TARG>. See also C<XPUSHs>, C<PUSHmortal> and C<PUSHs>. | |
d82b684c SH |
253 | |
254 | =for apidoc Am|void|mXPUSHp|char* str|STRLEN len | |
255 | Push a string onto the stack, extending the stack if necessary. The C<len> | |
121b7712 MHM |
256 | indicates the length of the string. Does not use C<TARG>. See also C<XPUSHp>, |
257 | C<mPUSHp> and C<PUSHp>. | |
d82b684c SH |
258 | |
259 | =for apidoc Am|void|mXPUSHn|NV nv | |
121b7712 MHM |
260 | Push a double onto the stack, extending the stack if necessary. |
261 | Does not use C<TARG>. See also C<XPUSHn>, C<mPUSHn> and C<PUSHn>. | |
d82b684c SH |
262 | |
263 | =for apidoc Am|void|mXPUSHi|IV iv | |
121b7712 MHM |
264 | Push an integer onto the stack, extending the stack if necessary. |
265 | Does not use C<TARG>. See also C<XPUSHi>, C<mPUSHi> and C<PUSHi>. | |
d82b684c SH |
266 | |
267 | =for apidoc Am|void|mXPUSHu|UV uv | |
268 | Push an unsigned integer onto the stack, extending the stack if necessary. | |
121b7712 | 269 | Does not use C<TARG>. See also C<XPUSHu>, C<mPUSHu> and C<PUSHu>. |
954c1994 GS |
270 | |
271 | =cut | |
272 | */ | |
273 | ||
865e3ae0 | 274 | #ifdef STRESS_REALLOC |
aad79b33 JH |
275 | # define EXTEND(p,n) STMT_START { \ |
276 | sp = stack_grow(sp,p,(SSize_t) (n)); \ | |
277 | PERL_UNUSED_VAR(sp); \ | |
8094bfa4 | 278 | } STMT_END |
865e3ae0 | 279 | /* Same thing, but update mark register too. */ |
aad79b33 JH |
280 | # define MEXTEND(p,n) STMT_START { \ |
281 | const int markoff = mark - PL_stack_base; \ | |
8094bfa4 | 282 | sp = stack_grow(sp,p,(SSize_t) (n)); \ |
aad79b33 JH |
283 | mark = PL_stack_base + markoff; \ |
284 | PERL_UNUSED_VAR(sp); \ | |
285 | } STMT_END | |
865e3ae0 | 286 | #else |
aad79b33 JH |
287 | # define EXTEND(p,n) STMT_START { \ |
288 | if (UNLIKELY(PL_stack_max - p < (int)(n))) { \ | |
289 | sp = stack_grow(sp,p,(SSize_t) (n)); \ | |
290 | PERL_UNUSED_VAR(sp); \ | |
291 | } } STMT_END | |
79072805 | 292 | /* Same thing, but update mark register too. */ |
aad79b33 JH |
293 | # define MEXTEND(p,n) STMT_START { \ |
294 | if (UNLIKELY(PL_stack_max - p < (int)(n))) { \ | |
295 | const int markoff = mark - PL_stack_base; \ | |
296 | sp = stack_grow(sp,p,(SSize_t) (n)); \ | |
297 | mark = PL_stack_base + markoff; \ | |
298 | PERL_UNUSED_VAR(sp); \ | |
299 | } } STMT_END | |
865e3ae0 | 300 | #endif |
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 | |
0acfb02f | 309 | #define XPUSHs(s) STMT_START { EXTEND(sp,1); *++sp = (s); } STMT_END |
86547924 | 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 | |
6e449a3a | 317 | #define mPUSHs(s) PUSHs(sv_2mortal(s)) |
2cc7004b | 318 | #define PUSHmortal PUSHs(sv_newmortal()) |
8f14ea01 | 319 | #define mPUSHp(p,l) PUSHs(newSVpvn_flags((p), (l), SVs_TEMP)) |
121b7712 MHM |
320 | #define mPUSHn(n) sv_setnv(PUSHmortal, (NV)(n)) |
321 | #define mPUSHi(i) sv_setiv(PUSHmortal, (IV)(i)) | |
322 | #define mPUSHu(u) sv_setuv(PUSHmortal, (UV)(u)) | |
2cc7004b | 323 | |
6e449a3a | 324 | #define mXPUSHs(s) XPUSHs(sv_2mortal(s)) |
2cc7004b | 325 | #define XPUSHmortal XPUSHs(sv_newmortal()) |
8f14ea01 | 326 | #define mXPUSHp(p,l) STMT_START { EXTEND(sp,1); mPUSHp((p), (l)); } STMT_END |
121b7712 MHM |
327 | #define mXPUSHn(n) STMT_START { EXTEND(sp,1); sv_setnv(PUSHmortal, (NV)(n)); } STMT_END |
328 | #define mXPUSHi(i) STMT_START { EXTEND(sp,1); sv_setiv(PUSHmortal, (IV)(i)); } STMT_END | |
329 | #define mXPUSHu(u) STMT_START { EXTEND(sp,1); sv_setuv(PUSHmortal, (UV)(u)); } STMT_END | |
d82b684c | 330 | |
79072805 | 331 | #define SETs(s) (*sp = s) |
86547924 | 332 | #define SETTARG STMT_START { SvSETMAGIC(TARG); SETs(TARG); } STMT_END |
333 | #define SETp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); SETTARG; } STMT_END | |
65202027 | 334 | #define SETn(n) STMT_START { sv_setnv(TARG, (NV)(n)); SETTARG; } STMT_END |
86547924 | 335 | #define SETi(i) STMT_START { sv_setiv(TARG, (IV)(i)); SETTARG; } STMT_END |
55497cff | 336 | #define SETu(u) STMT_START { sv_setuv(TARG, (UV)(u)); SETTARG; } STMT_END |
a0d0e21e | 337 | |
79072805 LW |
338 | #define dTOPss SV *sv = TOPs |
339 | #define dPOPss SV *sv = POPs | |
65202027 DS |
340 | #define dTOPnv NV value = TOPn |
341 | #define dPOPnv NV value = POPn | |
6f1401dc | 342 | #define dPOPnv_nomg NV value = (sp--, SvNV_nomg(TOPp1s)) |
a0d0e21e LW |
343 | #define dTOPiv IV value = TOPi |
344 | #define dPOPiv IV value = POPi | |
55497cff | 345 | #define dTOPuv UV value = TOPu |
346 | #define dPOPuv UV value = POPu | |
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) \ | |
6b349a5c | 353 | (SvOK(sv) || !(PL_op->op_flags & OPf_STACKED)) |
6f1401dc | 354 | #define dPOPXiirl_ul_nomg(X) \ |
096c060c | 355 | IV right = (sp--, SvIV_nomg(TOPp1s)); \ |
6f1401dc | 356 | SV *leftsv = CAT2(X,s); \ |
096c060c | 357 | IV left = USE_LEFT(leftsv) ? SvIV_nomg(leftsv) : 0 |
7a4c00b4 | 358 | |
359 | #define dPOPPOPssrl dPOPXssrl(POP) | |
360 | #define dPOPPOPnnrl dPOPXnnrl(POP) | |
7a4c00b4 | 361 | #define dPOPPOPiirl dPOPXiirl(POP) |
7a4c00b4 | 362 | |
363 | #define dPOPTOPssrl dPOPXssrl(TOP) | |
364 | #define dPOPTOPnnrl dPOPXnnrl(TOP) | |
6f1401dc DM |
365 | #define dPOPTOPnnrl_nomg \ |
366 | NV right = SvNV_nomg(TOPs); NV left = (sp--, SvNV_nomg(TOPs)) | |
7a4c00b4 | 367 | #define dPOPTOPiirl dPOPXiirl(TOP) |
6f1401dc DM |
368 | #define dPOPTOPiirl_ul_nomg dPOPXiirl_ul_nomg(TOP) |
369 | #define dPOPTOPiirl_nomg \ | |
096c060c | 370 | IV right = SvIV_nomg(TOPs); IV left = (sp--, SvIV_nomg(TOPs)) |
79072805 | 371 | |
3280af22 NIS |
372 | #define RETPUSHYES RETURNX(PUSHs(&PL_sv_yes)) |
373 | #define RETPUSHNO RETURNX(PUSHs(&PL_sv_no)) | |
374 | #define RETPUSHUNDEF RETURNX(PUSHs(&PL_sv_undef)) | |
79072805 | 375 | |
3280af22 NIS |
376 | #define RETSETYES RETURNX(SETs(&PL_sv_yes)) |
377 | #define RETSETNO RETURNX(SETs(&PL_sv_no)) | |
378 | #define RETSETUNDEF RETURNX(SETs(&PL_sv_undef)) | |
79072805 | 379 | |
533c011a | 380 | #define ARGTARG PL_op->op_targ |
b162f9ea IZ |
381 | |
382 | /* See OPpTARGET_MY: */ | |
383 | #define MAXARG (PL_op->op_private & 15) | |
79072805 | 384 | |
e336de0d GS |
385 | #define SWITCHSTACK(f,t) \ |
386 | STMT_START { \ | |
677b06e3 | 387 | AvFILLp(f) = sp - PL_stack_base; \ |
3280af22 | 388 | PL_stack_base = AvARRAY(t); \ |
677b06e3 | 389 | PL_stack_max = PL_stack_base + AvMAX(t); \ |
3280af22 | 390 | sp = PL_stack_sp = PL_stack_base + AvFILLp(t); \ |
677b06e3 | 391 | PL_curstack = t; \ |
e336de0d | 392 | } STMT_END |
79072805 | 393 | |
bbce6d69 | 394 | #define EXTEND_MORTAL(n) \ |
677b06e3 | 395 | STMT_START { \ |
2439e033 | 396 | if (UNLIKELY(PL_tmps_ix + (n) >= PL_tmps_max)) \ |
677b06e3 GS |
397 | tmps_grow(n); \ |
398 | } STMT_END | |
bbce6d69 | 399 | |
a0d0e21e LW |
400 | #define AMGf_noright 1 |
401 | #define AMGf_noleft 2 | |
402 | #define AMGf_assign 4 | |
403 | #define AMGf_unary 8 | |
6f1401dc DM |
404 | #define AMGf_numeric 0x10 /* for Perl_try_amagic_bin */ |
405 | #define AMGf_set 0x20 /* for Perl_try_amagic_bin */ | |
67288365 | 406 | #define AMGf_want_list 0x40 |
6f1401dc DM |
407 | |
408 | ||
409 | /* do SvGETMAGIC on the stack args before checking for overload */ | |
410 | ||
411 | #define tryAMAGICun_MG(method, flags) STMT_START { \ | |
5d9574c1 | 412 | if ( UNLIKELY((SvFLAGS(TOPs) & (SVf_ROK|SVs_GMG))) \ |
6f1401dc DM |
413 | && Perl_try_amagic_un(aTHX_ method, flags)) \ |
414 | return NORMAL; \ | |
415 | } STMT_END | |
416 | #define tryAMAGICbin_MG(method, flags) STMT_START { \ | |
5d9574c1 | 417 | if ( UNLIKELY(((SvFLAGS(TOPm1s)|SvFLAGS(TOPs)) & (SVf_ROK|SVs_GMG))) \ |
6f1401dc DM |
418 | && Perl_try_amagic_bin(aTHX_ method, flags)) \ |
419 | return NORMAL; \ | |
420 | } STMT_END | |
421 | ||
31d632c3 DM |
422 | #define AMG_CALLunary(sv,meth) \ |
423 | amagic_call(sv,&PL_sv_undef, meth, AMGf_noright | AMGf_unary) | |
424 | ||
425 | /* No longer used in core. Use AMG_CALLunary instead */ | |
426 | #define AMG_CALLun(sv,meth) AMG_CALLunary(sv, CAT2(meth,_amg)) | |
a0d0e21e | 427 | |
fc99edcf | 428 | #define tryAMAGICunTARGETlist(meth, jump) \ |
9f39b4f1 | 429 | STMT_START { \ |
b5c08826 DM |
430 | dSP; \ |
431 | SV *tmpsv; \ | |
fc99edcf | 432 | SV *arg= *sp; \ |
67288365 | 433 | int gimme = GIMME_V; \ |
5d9574c1 | 434 | if (UNLIKELY(SvAMAGIC(arg) && \ |
b5c08826 | 435 | (tmpsv = amagic_call(arg, &PL_sv_undef, meth, \ |
05fbd38d | 436 | AMGf_want_list | AMGf_noright \ |
5d9574c1 DM |
437 | |AMGf_unary)))) \ |
438 | { \ | |
b5c08826 | 439 | SPAGAIN; \ |
67288365 JL |
440 | if (gimme == G_VOID) { \ |
441 | (void)POPs; /* XXX ??? */ \ | |
442 | } \ | |
05fbd38d | 443 | else if (gimme == G_ARRAY) { \ |
c70927a6 FC |
444 | SSize_t i; \ |
445 | SSize_t len; \ | |
67288365 | 446 | assert(SvTYPE(tmpsv) == SVt_PVAV); \ |
b9f2b683 | 447 | len = av_tindex((AV *)tmpsv) + 1; \ |
67288365 JL |
448 | (void)POPs; /* get rid of the arg */ \ |
449 | EXTEND(sp, len); \ | |
450 | for (i = 0; i < len; ++i) \ | |
451 | PUSHs(av_shift((AV *)tmpsv)); \ | |
452 | } \ | |
453 | else { /* AMGf_want_scalar */ \ | |
454 | dATARGET; /* just use the arg's location */ \ | |
455 | sv_setsv(TARG, tmpsv); \ | |
456 | if (opASSIGN) \ | |
457 | sp--; \ | |
458 | SETTARG; \ | |
459 | } \ | |
b5c08826 DM |
460 | PUTBACK; \ |
461 | if (jump) { \ | |
86e5639b GG |
462 | OP *jump_o = NORMAL->op_next; \ |
463 | while (jump_o->op_type == OP_NULL) \ | |
464 | jump_o = jump_o->op_next; \ | |
465 | assert(jump_o->op_type == OP_ENTERSUB); \ | |
b5c08826 | 466 | PL_markstack_ptr--; \ |
86e5639b | 467 | return jump_o->op_next; \ |
9f39b4f1 | 468 | } \ |
b5c08826 DM |
469 | return NORMAL; \ |
470 | } \ | |
9f39b4f1 NC |
471 | } STMT_END |
472 | ||
8897dcaa NC |
473 | /* This is no longer used anywhere in the core. You might wish to consider |
474 | calling amagic_deref_call() directly, as it has a cleaner interface. */ | |
475 | #define tryAMAGICunDEREF(meth) \ | |
9f39b4f1 | 476 | STMT_START { \ |
e89bfaa6 | 477 | sv = amagic_deref_call(*sp, CAT2(meth,_amg)); \ |
25a9ffce | 478 | SPAGAIN; \ |
16e7e110 | 479 | } STMT_END |
e8c20960 | 480 | |
180b7b9b | 481 | |
533c011a | 482 | #define opASSIGN (PL_op->op_flags & OPf_STACKED) |
e9905555 | 483 | #define SETsv(sv) STMT_START { \ |
b162f9ea IZ |
484 | if (opASSIGN || (SvFLAGS(TARG) & SVs_PADMY)) \ |
485 | { sv_setsv(TARG, (sv)); SETTARG; } \ | |
486 | else SETs(sv); } STMT_END | |
487 | ||
488 | #define SETsvUN(sv) STMT_START { \ | |
489 | if (SvFLAGS(TARG) & SVs_PADMY) \ | |
490 | { sv_setsv(TARG, (sv)); SETTARG; } \ | |
e9905555 | 491 | else SETs(sv); } STMT_END |
a0d0e21e | 492 | |
78f9721b SM |
493 | /* |
494 | =for apidoc mU||LVRET | |
495 | True if this op will be the return value of an lvalue subroutine | |
496 | ||
497 | =cut */ | |
9d96b2e7 | 498 | #define LVRET ((PL_op->op_private & OPpMAYBE_LVSUB) && is_lvalue_sub()) |
1b6737cc | 499 | |
d30e492c VP |
500 | #define SvCANEXISTDELETE(sv) \ |
501 | (!SvRMAGICAL(sv) \ | |
2c5f48c2 FC |
502 | || !(mg = mg_find((const SV *) sv, PERL_MAGIC_tied)) \ |
503 | || ( (stash = SvSTASH(SvRV(SvTIED_obj(MUTABLE_SV(sv), mg)))) \ | |
d30e492c VP |
504 | && gv_fetchmethod_autoload(stash, "EXISTS", TRUE) \ |
505 | && gv_fetchmethod_autoload(stash, "DELETE", TRUE) \ | |
506 | ) \ | |
507 | ) | |
508 | ||
d682515d | 509 | #ifdef PERL_CORE |
557fbd17 | 510 | |
d682515d NC |
511 | /* These are just for Perl_tied_method(), which is not part of the public API. |
512 | Use 0x04 rather than the next available bit, to help the compiler if the | |
513 | architecture can generate more efficient instructions. */ | |
514 | # define TIED_METHOD_MORTALIZE_NOT_NEEDED 0x04 | |
515 | # define TIED_METHOD_ARGUMENTS_ON_STACK 0x08 | |
94bc412f | 516 | # define TIED_METHOD_SAY 0x10 |
557fbd17 FC |
517 | |
518 | /* Used in various places that need to dereference a glob or globref */ | |
094a3eec | 519 | # define MAYBE_DEREF_GV_flags(sv,phlags) \ |
557fbd17 | 520 | ( \ |
094a3eec | 521 | (void)(phlags & SV_GMAGIC && (SvGETMAGIC(sv),0)), \ |
557fbd17 | 522 | isGV_with_GP(sv) \ |
4e794a06 | 523 | ? (GV *)(sv) \ |
f8afbfa6 FC |
524 | : SvROK(sv) && SvTYPE(SvRV(sv)) <= SVt_PVLV && \ |
525 | (SvGETMAGIC(SvRV(sv)), isGV_with_GP(SvRV(sv))) \ | |
557fbd17 FC |
526 | ? (GV *)SvRV(sv) \ |
527 | : NULL \ | |
528 | ) | |
094a3eec FC |
529 | # define MAYBE_DEREF_GV(sv) MAYBE_DEREF_GV_flags(sv,SV_GMAGIC) |
530 | # define MAYBE_DEREF_GV_nomg(sv) MAYBE_DEREF_GV_flags(sv,0) | |
557fbd17 | 531 | |
db4cf31d | 532 | # define FIND_RUNCV_padid_eq 1 |
b4b0692a | 533 | # define FIND_RUNCV_level_eq 2 |
70794f7b | 534 | |
d682515d NC |
535 | #endif |
536 | ||
1b6737cc AL |
537 | /* |
538 | * Local variables: | |
539 | * c-indentation-style: bsd | |
540 | * c-basic-offset: 4 | |
14d04a33 | 541 | * indent-tabs-mode: nil |
1b6737cc AL |
542 | * End: |
543 | * | |
14d04a33 | 544 | * ex: set ts=8 sts=4 sw=4 et: |
1b6737cc | 545 | */ |