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