[win32] integrate mainline
[p5sagit/p5-mst-13.2.git] / pp.h
CommitLineData
a0d0e21e 1/* pp.h
79072805 2 *
9607fc9c 3 * Copyright (c) 1991-1997, 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 */
4e35701f 17#define PP(s) OP * s(ARGSproto)
79072805 18
19#define SP sp
20#define MARK mark
21#define TARG targ
22
a0d0e21e 23#define PUSHMARK(p) if (++markstack_ptr == markstack_max) \
24 markstack_grow(); \
25 *markstack_ptr = (p) - stack_base
26
27#define TOPMARK (*markstack_ptr)
79072805 28#define POPMARK (*markstack_ptr--)
a0d0e21e 29
4e35701f 30#define djSP register SV **sp = stack_sp
31#define dSP dTHR; djSP
79072805 32#define dMARK register SV **mark = stack_base + POPMARK
33#define dORIGMARK I32 origmark = mark - stack_base
34#define SETORIGMARK origmark = mark - stack_base
a0d0e21e 35#define ORIGMARK (stack_base + origmark)
79072805 36
37#define SPAGAIN sp = stack_sp
38#define MSPAGAIN sp = stack_sp; mark = ORIGMARK
39
40#define GETTARGETSTACKED targ = (op->op_flags & OPf_STACKED ? POPs : PAD_SV(op->op_targ))
41#define dTARGETSTACKED SV * GETTARGETSTACKED
42
43#define GETTARGET targ = PAD_SV(op->op_targ)
44#define dTARGET SV * GETTARGET
45
46#define GETATARGET targ = (op->op_flags & OPf_STACKED ? sp[-1] : PAD_SV(op->op_targ))
47#define dATARGET SV * GETATARGET
48
49#define dTARG SV *targ
50
79072805 51#define NORMAL op->op_next
52#define DIE return die
79072805 53
54#define PUTBACK stack_sp = sp
55#define RETURN return PUTBACK, NORMAL
56#define RETURNOP(o) return PUTBACK, o
57#define RETURNX(x) return x, PUTBACK, NORMAL
58
59#define POPs (*sp--)
463ee0b2 60#define POPp (SvPVx(POPs, na))
61#define POPn (SvNVx(POPs))
a0d0e21e 62#define POPi ((IV)SvIVx(POPs))
ff68c719 63#define POPu ((UV)SvUVx(POPs))
463ee0b2 64#define POPl ((long)SvIVx(POPs))
79072805 65
66#define TOPs (*sp)
463ee0b2 67#define TOPp (SvPV(TOPs, na))
68#define TOPn (SvNV(TOPs))
a0d0e21e 69#define TOPi ((IV)SvIV(TOPs))
ff68c719 70#define TOPu ((UV)SvUV(TOPs))
463ee0b2 71#define TOPl ((long)SvIV(TOPs))
79072805 72
73/* Go to some pains in the rare event that we must extend the stack. */
bbce6d69 74#define EXTEND(p,n) STMT_START { if (stack_max - p < (n)) { \
75 sp = stack_grow(sp,p, (int) (n)); \
86547924 76 } } STMT_END
a0d0e21e 77
79072805 78/* Same thing, but update mark register too. */
bbce6d69 79#define MEXTEND(p,n) STMT_START {if (stack_max - p < (n)) { \
80 int markoff = mark - stack_base; \
81 sp = stack_grow(sp,p,(int) (n)); \
82 mark = stack_base + markoff; \
86547924 83 } } STMT_END
79072805 84
85#define PUSHs(s) (*++sp = (s))
86547924 86#define PUSHTARG STMT_START { SvSETMAGIC(TARG); PUSHs(TARG); } STMT_END
87#define PUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); PUSHTARG; } STMT_END
88#define PUSHn(n) STMT_START { sv_setnv(TARG, (double)(n)); PUSHTARG; } STMT_END
89#define PUSHi(i) STMT_START { sv_setiv(TARG, (IV)(i)); PUSHTARG; } STMT_END
55497cff 90#define PUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); PUSHTARG; } STMT_END
79072805 91
86547924 92#define XPUSHs(s) STMT_START { EXTEND(sp,1); (*++sp = (s)); } STMT_END
93#define XPUSHTARG STMT_START { SvSETMAGIC(TARG); XPUSHs(TARG); } STMT_END
94#define XPUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); XPUSHTARG; } STMT_END
95#define XPUSHn(n) STMT_START { sv_setnv(TARG, (double)(n)); XPUSHTARG; } STMT_END
96#define XPUSHi(i) STMT_START { sv_setiv(TARG, (IV)(i)); XPUSHTARG; } STMT_END
55497cff 97#define XPUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); XPUSHTARG; } STMT_END
79072805 98
99#define SETs(s) (*sp = s)
86547924 100#define SETTARG STMT_START { SvSETMAGIC(TARG); SETs(TARG); } STMT_END
101#define SETp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); SETTARG; } STMT_END
102#define SETn(n) STMT_START { sv_setnv(TARG, (double)(n)); SETTARG; } STMT_END
103#define SETi(i) STMT_START { sv_setiv(TARG, (IV)(i)); SETTARG; } STMT_END
55497cff 104#define SETu(u) STMT_START { sv_setuv(TARG, (UV)(u)); SETTARG; } STMT_END
a0d0e21e 105
79072805 106#define dTOPss SV *sv = TOPs
107#define dPOPss SV *sv = POPs
108#define dTOPnv double value = TOPn
109#define dPOPnv double value = POPn
a0d0e21e 110#define dTOPiv IV value = TOPi
111#define dPOPiv IV value = POPi
55497cff 112#define dTOPuv UV value = TOPu
113#define dPOPuv UV value = POPu
79072805 114
7a4c00b4 115#define dPOPXssrl(X) SV *right = POPs; SV *left = CAT2(X,s)
116#define dPOPXnnrl(X) double right = POPn; double left = CAT2(X,n)
117#define dPOPXiirl(X) IV right = POPi; IV left = CAT2(X,i)
118
119#define USE_LEFT(sv) \
120 (SvOK(sv) || SvGMAGICAL(sv) || !(op->op_flags & OPf_STACKED))
121#define dPOPXnnrl_ul(X) \
122 double right = POPn; \
123 SV *leftsv = CAT2(X,s); \
124 double left = USE_LEFT(leftsv) ? SvNV(leftsv) : 0.0
125#define dPOPXiirl_ul(X) \
126 IV right = POPi; \
127 SV *leftsv = CAT2(X,s); \
128 IV left = USE_LEFT(leftsv) ? SvIV(leftsv) : 0
129
130#define dPOPPOPssrl dPOPXssrl(POP)
131#define dPOPPOPnnrl dPOPXnnrl(POP)
132#define dPOPPOPnnrl_ul dPOPXnnrl_ul(POP)
133#define dPOPPOPiirl dPOPXiirl(POP)
134#define dPOPPOPiirl_ul dPOPXiirl_ul(POP)
135
136#define dPOPTOPssrl dPOPXssrl(TOP)
137#define dPOPTOPnnrl dPOPXnnrl(TOP)
138#define dPOPTOPnnrl_ul dPOPXnnrl_ul(TOP)
139#define dPOPTOPiirl dPOPXiirl(TOP)
140#define dPOPTOPiirl_ul dPOPXiirl_ul(TOP)
79072805 141
142#define RETPUSHYES RETURNX(PUSHs(&sv_yes))
143#define RETPUSHNO RETURNX(PUSHs(&sv_no))
144#define RETPUSHUNDEF RETURNX(PUSHs(&sv_undef))
145
146#define RETSETYES RETURNX(SETs(&sv_yes))
147#define RETSETNO RETURNX(SETs(&sv_no))
148#define RETSETUNDEF RETURNX(SETs(&sv_undef))
149
150#define ARGTARG op->op_targ
151#define MAXARG op->op_private
152
93965878 153#define SWITCHSTACK(f,t) AvFILLp(f) = sp - stack_base; \
79072805 154 stack_base = AvARRAY(t); \
155 stack_max = stack_base + AvMAX(t); \
93965878 156 sp = stack_sp = stack_base + AvFILLp(t); \
e9905555 157 curstack = t;
79072805 158
bbce6d69 159#define EXTEND_MORTAL(n) \
160 STMT_START { \
161 if (tmps_ix + (n) >= tmps_max) \
162 Renew(tmps_stack, tmps_max = tmps_ix + (n) + 1, SV*); \
163 } STMT_END
164
a0d0e21e 165#ifdef OVERLOAD
166
167#define AMGf_noright 1
168#define AMGf_noleft 2
169#define AMGf_assign 4
170#define AMGf_unary 8
171
86547924 172#define tryAMAGICbinW(meth,assign,set) STMT_START { \
a0d0e21e 173 if (amagic_generation) { \
174 SV* tmpsv; \
175 SV* right= *(sp); SV* left= *(sp-1);\
176 if ((SvAMAGIC(left)||SvAMAGIC(right))&&\
177 (tmpsv=amagic_call(left, \
178 right, \
179 CAT2(meth,_amg), \
180 (assign)? AMGf_assign: 0))) {\
181 SPAGAIN; \
182 (void)POPs; set(tmpsv); RETURN; } \
183 } \
86547924 184 } STMT_END
a0d0e21e 185
186#define tryAMAGICbin(meth,assign) tryAMAGICbinW(meth,assign,SETsv)
187#define tryAMAGICbinSET(meth,assign) tryAMAGICbinW(meth,assign,SETs)
188
189#define AMG_CALLun(sv,meth) amagic_call(sv,&sv_undef, \
190 CAT2(meth,_amg),AMGf_noright | AMGf_unary)
191#define AMG_CALLbinL(left,right,meth) \
192 amagic_call(left,right,CAT2(meth,_amg),AMGf_noright)
193
86547924 194#define tryAMAGICunW(meth,set) STMT_START { \
a0d0e21e 195 if (amagic_generation) { \
196 SV* tmpsv; \
197 SV* arg= *(sp); \
198 if ((SvAMAGIC(arg))&&\
199 (tmpsv=AMG_CALLun(arg,meth))) {\
200 SPAGAIN; \
201 set(tmpsv); RETURN; } \
202 } \
86547924 203 } STMT_END
a0d0e21e 204
e9905555 205#define tryAMAGICun tryAMAGICunSET
a0d0e21e 206#define tryAMAGICunSET(meth) tryAMAGICunW(meth,SETs)
207
208#define opASSIGN (op->op_flags & OPf_STACKED)
e9905555 209#define SETsv(sv) STMT_START { \
210 if (opASSIGN) { sv_setsv(TARG, (sv)); SETTARG; } \
211 else SETs(sv); } STMT_END
a0d0e21e 212
213/* newSVsv does not behave as advertised, so we copy missing
214 * information by hand */
215
216
86547924 217#define RvDEEPCP(rv) STMT_START { SV* ref=SvRV(rv); \
a0d0e21e 218 if (SvREFCNT(ref)>1) { \
219 SvREFCNT_dec(ref); \
748a9306 220 SvRV(rv)=AMG_CALLun(rv,copy); \
86547924 221 } } STMT_END
a0d0e21e 222#else
223
224#define tryAMAGICbin(a,b)
225#define tryAMAGICbinSET(a,b)
226#define tryAMAGICun(a)
227#define tryAMAGICunSET(a)
228
229#endif /* OVERLOAD */