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