Commit | Line | Data |
a0d0e21e |
1 | /* pp.h |
79072805 |
2 | * |
4eb8286e |
3 | * Copyright (c) 1991-1999, Larry Wall |
79072805 |
4 | * |
a0d0e21e |
5 | * You may distribute under the terms of either the GNU General Public |
6 | * License or the Artistic License, as specified in the README file. |
79072805 |
7 | * |
a0d0e21e |
8 | */ |
79072805 |
9 | |
11343788 |
10 | #ifdef USE_THREADS |
11 | #define ARGS thr |
52e1cb5e |
12 | #define dARGS struct perl_thread *thr; |
11343788 |
13 | #else |
79072805 |
14 | #define ARGS |
79072805 |
15 | #define dARGS |
11343788 |
16 | #endif /* USE_THREADS */ |
22c35a8c |
17 | |
cea2e8a9 |
18 | #define PP(s) OP * Perl_##s(pTHX) |
79072805 |
19 | |
20 | #define SP sp |
21 | #define MARK mark |
22 | #define TARG targ |
23 | |
3280af22 |
24 | #define PUSHMARK(p) if (++PL_markstack_ptr == PL_markstack_max) \ |
a0d0e21e |
25 | markstack_grow(); \ |
3280af22 |
26 | *PL_markstack_ptr = (p) - PL_stack_base |
a0d0e21e |
27 | |
3280af22 |
28 | #define TOPMARK (*PL_markstack_ptr) |
29 | #define POPMARK (*PL_markstack_ptr--) |
a0d0e21e |
30 | |
3280af22 |
31 | #define djSP register SV **sp = PL_stack_sp |
4e35701f |
32 | #define dSP dTHR; djSP |
3280af22 |
33 | #define dMARK register SV **mark = PL_stack_base + POPMARK |
34 | #define dORIGMARK I32 origmark = mark - PL_stack_base |
35 | #define SETORIGMARK origmark = mark - PL_stack_base |
36 | #define ORIGMARK (PL_stack_base + origmark) |
79072805 |
37 | |
3280af22 |
38 | #define SPAGAIN sp = PL_stack_sp |
39 | #define MSPAGAIN sp = PL_stack_sp; mark = ORIGMARK |
79072805 |
40 | |
533c011a |
41 | #define GETTARGETSTACKED targ = (PL_op->op_flags & OPf_STACKED ? POPs : PAD_SV(PL_op->op_targ)) |
79072805 |
42 | #define dTARGETSTACKED SV * GETTARGETSTACKED |
43 | |
533c011a |
44 | #define GETTARGET targ = PAD_SV(PL_op->op_targ) |
79072805 |
45 | #define dTARGET SV * GETTARGET |
46 | |
533c011a |
47 | #define GETATARGET targ = (PL_op->op_flags & OPf_STACKED ? sp[-1] : PAD_SV(PL_op->op_targ)) |
79072805 |
48 | #define dATARGET SV * GETATARGET |
49 | |
50 | #define dTARG SV *targ |
51 | |
533c011a |
52 | #define NORMAL PL_op->op_next |
cea2e8a9 |
53 | #define DIE return Perl_die |
79072805 |
54 | |
3280af22 |
55 | #define PUTBACK PL_stack_sp = sp |
79072805 |
56 | #define RETURN return PUTBACK, NORMAL |
57 | #define RETURNOP(o) return PUTBACK, o |
58 | #define RETURNX(x) return x, PUTBACK, NORMAL |
59 | |
60 | #define POPs (*sp--) |
2d8e6c8d |
61 | #define POPp (SvPVx(POPs, PL_na)) /* deprecated */ |
62 | #define POPpx (SvPVx(POPs, n_a)) |
463ee0b2 |
63 | #define POPn (SvNVx(POPs)) |
a0d0e21e |
64 | #define POPi ((IV)SvIVx(POPs)) |
ff68c719 |
65 | #define POPu ((UV)SvUVx(POPs)) |
463ee0b2 |
66 | #define POPl ((long)SvIVx(POPs)) |
d9b3e12d |
67 | #define POPul ((unsigned long)SvIVx(POPs)) |
1b8cd678 |
68 | #ifdef HAS_QUAD |
d9b3e12d |
69 | #define POPq ((Quad_t)SvIVx(POPs)) |
c5a0f51a |
70 | #define POPuq ((Uquad_t)SvUVx(POPs)) |
d9b3e12d |
71 | #endif |
79072805 |
72 | |
73 | #define TOPs (*sp) |
2d8e6c8d |
74 | #define TOPp (SvPV(TOPs, PL_na)) /* deprecated */ |
75 | #define TOPpx (SvPV(TOPs, n_a)) |
463ee0b2 |
76 | #define TOPn (SvNV(TOPs)) |
a0d0e21e |
77 | #define TOPi ((IV)SvIV(TOPs)) |
ff68c719 |
78 | #define TOPu ((UV)SvUV(TOPs)) |
463ee0b2 |
79 | #define TOPl ((long)SvIV(TOPs)) |
c5a0f51a |
80 | #define TOPul ((unsigned long)SvUV(TOPs)) |
1b8cd678 |
81 | #ifdef HAS_QUAD |
d9b3e12d |
82 | #define TOPq ((Quad_t)SvIV(TOPs)) |
c5a0f51a |
83 | #define TOPuq ((Uquad_t)SvUV(TOPs)) |
d9b3e12d |
84 | #endif |
79072805 |
85 | |
86 | /* Go to some pains in the rare event that we must extend the stack. */ |
3280af22 |
87 | #define EXTEND(p,n) STMT_START { if (PL_stack_max - p < (n)) { \ |
bbce6d69 |
88 | sp = stack_grow(sp,p, (int) (n)); \ |
86547924 |
89 | } } STMT_END |
a0d0e21e |
90 | |
79072805 |
91 | /* Same thing, but update mark register too. */ |
3280af22 |
92 | #define MEXTEND(p,n) STMT_START {if (PL_stack_max - p < (n)) { \ |
93 | int markoff = mark - PL_stack_base; \ |
bbce6d69 |
94 | sp = stack_grow(sp,p,(int) (n)); \ |
3280af22 |
95 | mark = PL_stack_base + markoff; \ |
86547924 |
96 | } } STMT_END |
79072805 |
97 | |
98 | #define PUSHs(s) (*++sp = (s)) |
86547924 |
99 | #define PUSHTARG STMT_START { SvSETMAGIC(TARG); PUSHs(TARG); } STMT_END |
100 | #define PUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); PUSHTARG; } STMT_END |
65202027 |
101 | #define PUSHn(n) STMT_START { sv_setnv(TARG, (NV)(n)); PUSHTARG; } STMT_END |
86547924 |
102 | #define PUSHi(i) STMT_START { sv_setiv(TARG, (IV)(i)); PUSHTARG; } STMT_END |
55497cff |
103 | #define PUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); PUSHTARG; } STMT_END |
79072805 |
104 | |
86547924 |
105 | #define XPUSHs(s) STMT_START { EXTEND(sp,1); (*++sp = (s)); } STMT_END |
106 | #define XPUSHTARG STMT_START { SvSETMAGIC(TARG); XPUSHs(TARG); } STMT_END |
107 | #define XPUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); XPUSHTARG; } STMT_END |
65202027 |
108 | #define XPUSHn(n) STMT_START { sv_setnv(TARG, (NV)(n)); XPUSHTARG; } STMT_END |
86547924 |
109 | #define XPUSHi(i) STMT_START { sv_setiv(TARG, (IV)(i)); XPUSHTARG; } STMT_END |
55497cff |
110 | #define XPUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); XPUSHTARG; } STMT_END |
b162f9ea |
111 | #define XPUSHundef STMT_START { SvOK_off(TARG); XPUSHs(TARG); } STMT_END |
79072805 |
112 | |
113 | #define SETs(s) (*sp = s) |
86547924 |
114 | #define SETTARG STMT_START { SvSETMAGIC(TARG); SETs(TARG); } STMT_END |
115 | #define SETp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); SETTARG; } STMT_END |
65202027 |
116 | #define SETn(n) STMT_START { sv_setnv(TARG, (NV)(n)); SETTARG; } STMT_END |
86547924 |
117 | #define SETi(i) STMT_START { sv_setiv(TARG, (IV)(i)); SETTARG; } STMT_END |
55497cff |
118 | #define SETu(u) STMT_START { sv_setuv(TARG, (UV)(u)); SETTARG; } STMT_END |
a0d0e21e |
119 | |
79072805 |
120 | #define dTOPss SV *sv = TOPs |
121 | #define dPOPss SV *sv = POPs |
65202027 |
122 | #define dTOPnv NV value = TOPn |
123 | #define dPOPnv NV value = POPn |
a0d0e21e |
124 | #define dTOPiv IV value = TOPi |
125 | #define dPOPiv IV value = POPi |
55497cff |
126 | #define dTOPuv UV value = TOPu |
127 | #define dPOPuv UV value = POPu |
1b8cd678 |
128 | #ifdef HAS_QUAD |
2d4389e4 |
129 | #define dTOPqv Quad_t value = TOPu |
130 | #define dPOPqv Quad_t value = POPu |
131 | #define dTOPuqv Uquad_t value = TOPuq |
132 | #define dPOPuqv Uquad_t value = POPuq |
133 | #endif |
79072805 |
134 | |
7a4c00b4 |
135 | #define dPOPXssrl(X) SV *right = POPs; SV *left = CAT2(X,s) |
65202027 |
136 | #define dPOPXnnrl(X) NV right = POPn; NV left = CAT2(X,n) |
7a4c00b4 |
137 | #define dPOPXiirl(X) IV right = POPi; IV left = CAT2(X,i) |
138 | |
139 | #define USE_LEFT(sv) \ |
533c011a |
140 | (SvOK(sv) || SvGMAGICAL(sv) || !(PL_op->op_flags & OPf_STACKED)) |
7a4c00b4 |
141 | #define dPOPXnnrl_ul(X) \ |
65202027 |
142 | NV right = POPn; \ |
7a4c00b4 |
143 | SV *leftsv = CAT2(X,s); \ |
65202027 |
144 | NV left = USE_LEFT(leftsv) ? SvNV(leftsv) : 0.0 |
7a4c00b4 |
145 | #define dPOPXiirl_ul(X) \ |
146 | IV right = POPi; \ |
147 | SV *leftsv = CAT2(X,s); \ |
148 | IV left = USE_LEFT(leftsv) ? SvIV(leftsv) : 0 |
149 | |
150 | #define dPOPPOPssrl dPOPXssrl(POP) |
151 | #define dPOPPOPnnrl dPOPXnnrl(POP) |
152 | #define dPOPPOPnnrl_ul dPOPXnnrl_ul(POP) |
153 | #define dPOPPOPiirl dPOPXiirl(POP) |
154 | #define dPOPPOPiirl_ul dPOPXiirl_ul(POP) |
155 | |
156 | #define dPOPTOPssrl dPOPXssrl(TOP) |
157 | #define dPOPTOPnnrl dPOPXnnrl(TOP) |
158 | #define dPOPTOPnnrl_ul dPOPXnnrl_ul(TOP) |
159 | #define dPOPTOPiirl dPOPXiirl(TOP) |
160 | #define dPOPTOPiirl_ul dPOPXiirl_ul(TOP) |
79072805 |
161 | |
3280af22 |
162 | #define RETPUSHYES RETURNX(PUSHs(&PL_sv_yes)) |
163 | #define RETPUSHNO RETURNX(PUSHs(&PL_sv_no)) |
164 | #define RETPUSHUNDEF RETURNX(PUSHs(&PL_sv_undef)) |
79072805 |
165 | |
3280af22 |
166 | #define RETSETYES RETURNX(SETs(&PL_sv_yes)) |
167 | #define RETSETNO RETURNX(SETs(&PL_sv_no)) |
168 | #define RETSETUNDEF RETURNX(SETs(&PL_sv_undef)) |
79072805 |
169 | |
533c011a |
170 | #define ARGTARG PL_op->op_targ |
b162f9ea |
171 | |
172 | /* See OPpTARGET_MY: */ |
173 | #define MAXARG (PL_op->op_private & 15) |
79072805 |
174 | |
e336de0d |
175 | #define SWITCHSTACK(f,t) \ |
176 | STMT_START { \ |
677b06e3 |
177 | AvFILLp(f) = sp - PL_stack_base; \ |
3280af22 |
178 | PL_stack_base = AvARRAY(t); \ |
677b06e3 |
179 | PL_stack_max = PL_stack_base + AvMAX(t); \ |
3280af22 |
180 | sp = PL_stack_sp = PL_stack_base + AvFILLp(t); \ |
677b06e3 |
181 | PL_curstack = t; \ |
e336de0d |
182 | } STMT_END |
79072805 |
183 | |
bbce6d69 |
184 | #define EXTEND_MORTAL(n) \ |
677b06e3 |
185 | STMT_START { \ |
186 | if (PL_tmps_ix + (n) >= PL_tmps_max) \ |
187 | tmps_grow(n); \ |
188 | } STMT_END |
bbce6d69 |
189 | |
a0d0e21e |
190 | #define AMGf_noright 1 |
191 | #define AMGf_noleft 2 |
192 | #define AMGf_assign 4 |
193 | #define AMGf_unary 8 |
194 | |
86547924 |
195 | #define tryAMAGICbinW(meth,assign,set) STMT_START { \ |
3280af22 |
196 | if (PL_amagic_generation) { \ |
a0d0e21e |
197 | SV* tmpsv; \ |
198 | SV* right= *(sp); SV* left= *(sp-1);\ |
199 | if ((SvAMAGIC(left)||SvAMAGIC(right))&&\ |
200 | (tmpsv=amagic_call(left, \ |
201 | right, \ |
202 | CAT2(meth,_amg), \ |
203 | (assign)? AMGf_assign: 0))) {\ |
204 | SPAGAIN; \ |
205 | (void)POPs; set(tmpsv); RETURN; } \ |
206 | } \ |
86547924 |
207 | } STMT_END |
a0d0e21e |
208 | |
209 | #define tryAMAGICbin(meth,assign) tryAMAGICbinW(meth,assign,SETsv) |
210 | #define tryAMAGICbinSET(meth,assign) tryAMAGICbinW(meth,assign,SETs) |
211 | |
3280af22 |
212 | #define AMG_CALLun(sv,meth) amagic_call(sv,&PL_sv_undef, \ |
a0d0e21e |
213 | CAT2(meth,_amg),AMGf_noright | AMGf_unary) |
214 | #define AMG_CALLbinL(left,right,meth) \ |
215 | amagic_call(left,right,CAT2(meth,_amg),AMGf_noright) |
216 | |
e8c20960 |
217 | #define tryAMAGICunW(meth,set,shift,ret) STMT_START { \ |
3280af22 |
218 | if (PL_amagic_generation) { \ |
a0d0e21e |
219 | SV* tmpsv; \ |
f5284f61 |
220 | SV* arg= sp[shift]; \ |
221 | am_again: \ |
a0d0e21e |
222 | if ((SvAMAGIC(arg))&&\ |
223 | (tmpsv=AMG_CALLun(arg,meth))) {\ |
f5284f61 |
224 | SPAGAIN; if (shift) sp += shift; \ |
e8c20960 |
225 | set(tmpsv); ret; } \ |
a0d0e21e |
226 | } \ |
86547924 |
227 | } STMT_END |
a0d0e21e |
228 | |
f5284f61 |
229 | #define FORCE_SETs(sv) STMT_START { sv_setsv(TARG, (sv)); SETTARG; } STMT_END |
230 | |
b162f9ea |
231 | #define tryAMAGICun(meth) tryAMAGICunW(meth,SETsvUN,0,RETURN) |
232 | #define tryAMAGICunSET(meth) tryAMAGICunW(meth,SETs,0,RETURN) |
f5284f61 |
233 | #define tryAMAGICunTARGET(meth, shift) \ |
234 | { dSP; sp--; /* get TARGET from below PL_stack_sp */ \ |
235 | { dTARGETSTACKED; \ |
e8c20960 |
236 | { dSP; tryAMAGICunW(meth,FORCE_SETs,shift,RETURN);}}} |
237 | |
238 | #define setAGAIN(ref) sv = arg = ref; \ |
239 | if (!SvROK(ref)) \ |
cea2e8a9 |
240 | Perl_croak(aTHX_ "Overloaded dereference did not return a reference"); \ |
e8c20960 |
241 | goto am_again; |
242 | |
0f4592ef |
243 | #define tryAMAGICunDEREF(meth) tryAMAGICunW(meth,setAGAIN,0,(void)0) |
a0d0e21e |
244 | |
533c011a |
245 | #define opASSIGN (PL_op->op_flags & OPf_STACKED) |
e9905555 |
246 | #define SETsv(sv) STMT_START { \ |
b162f9ea |
247 | if (opASSIGN || (SvFLAGS(TARG) & SVs_PADMY)) \ |
248 | { sv_setsv(TARG, (sv)); SETTARG; } \ |
249 | else SETs(sv); } STMT_END |
250 | |
251 | #define SETsvUN(sv) STMT_START { \ |
252 | if (SvFLAGS(TARG) & SVs_PADMY) \ |
253 | { sv_setsv(TARG, (sv)); SETTARG; } \ |
e9905555 |
254 | else SETs(sv); } STMT_END |
a0d0e21e |
255 | |
256 | /* newSVsv does not behave as advertised, so we copy missing |
257 | * information by hand */ |
258 | |
76e3520e |
259 | /* SV* ref causes confusion with the member variable |
260 | changed SV* ref to SV* tmpRef */ |
261 | #define RvDEEPCP(rv) STMT_START { SV* tmpRef=SvRV(rv); \ |
262 | if (SvREFCNT(tmpRef)>1) { \ |
263 | SvREFCNT_dec(tmpRef); \ |
748a9306 |
264 | SvRV(rv)=AMG_CALLun(rv,copy); \ |
86547924 |
265 | } } STMT_END |