This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix a2p translation of '{print "a" "b" "c"}'
[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))
463ee0b2 58#define POPl ((long)SvIVx(POPs))
79072805
LW
59
60#define TOPs (*sp)
463ee0b2
LW
61#define TOPp (SvPV(TOPs, na))
62#define TOPn (SvNV(TOPs))
a0d0e21e 63#define TOPi ((IV)SvIV(TOPs))
463ee0b2 64#define TOPl ((long)SvIV(TOPs))
79072805
LW
65
66/* Go to some pains in the rare event that we must extend the stack. */
86547924 67#define EXTEND(p,n) STMT_START { if (stack_max - p < (n)) { \
a0d0e21e 68 sp = stack_grow(sp,p, (int) (n)); \
86547924 69 } } STMT_END
a0d0e21e 70
79072805 71/* Same thing, but update mark register too. */
86547924 72#define MEXTEND(p,n) STMT_START {if (stack_max - p < (n)) { \
a0d0e21e
LW
73 int markoff = mark - stack_base; \
74 sp = stack_grow(sp,p,(int) (n)); \
75 mark = stack_base + markoff; \
86547924 76 } } STMT_END
79072805
LW
77
78#define PUSHs(s) (*++sp = (s))
86547924
PP
79#define PUSHTARG STMT_START { SvSETMAGIC(TARG); PUSHs(TARG); } STMT_END
80#define PUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); PUSHTARG; } STMT_END
81#define PUSHn(n) STMT_START { sv_setnv(TARG, (double)(n)); PUSHTARG; } STMT_END
82#define PUSHi(i) STMT_START { sv_setiv(TARG, (IV)(i)); PUSHTARG; } STMT_END
79072805 83
86547924
PP
84#define XPUSHs(s) STMT_START { EXTEND(sp,1); (*++sp = (s)); } STMT_END
85#define XPUSHTARG STMT_START { SvSETMAGIC(TARG); XPUSHs(TARG); } STMT_END
86#define XPUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); XPUSHTARG; } STMT_END
87#define XPUSHn(n) STMT_START { sv_setnv(TARG, (double)(n)); XPUSHTARG; } STMT_END
88#define XPUSHi(i) STMT_START { sv_setiv(TARG, (IV)(i)); XPUSHTARG; } STMT_END
79072805
LW
89
90#define SETs(s) (*sp = s)
86547924
PP
91#define SETTARG STMT_START { SvSETMAGIC(TARG); SETs(TARG); } STMT_END
92#define SETp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); SETTARG; } STMT_END
93#define SETn(n) STMT_START { sv_setnv(TARG, (double)(n)); SETTARG; } STMT_END
94#define SETi(i) STMT_START { sv_setiv(TARG, (IV)(i)); SETTARG; } STMT_END
a0d0e21e 95
79072805
LW
96#define dTOPss SV *sv = TOPs
97#define dPOPss SV *sv = POPs
98#define dTOPnv double value = TOPn
99#define dPOPnv double value = POPn
a0d0e21e
LW
100#define dTOPiv IV value = TOPi
101#define dPOPiv IV value = POPi
79072805 102
a0d0e21e 103#define dPOPPOPssrl SV *right = POPs; SV *left = POPs
79072805 104#define dPOPPOPnnrl double right = POPn; double left = POPn
a0d0e21e 105#define dPOPPOPiirl IV right = POPi; IV left = POPi
79072805 106
a0d0e21e 107#define dPOPTOPssrl SV *right = POPs; SV *left = TOPs
79072805 108#define dPOPTOPnnrl double right = POPn; double left = TOPn
a0d0e21e 109#define dPOPTOPiirl IV right = POPi; IV left = TOPi
79072805
LW
110
111#define RETPUSHYES RETURNX(PUSHs(&sv_yes))
112#define RETPUSHNO RETURNX(PUSHs(&sv_no))
113#define RETPUSHUNDEF RETURNX(PUSHs(&sv_undef))
114
115#define RETSETYES RETURNX(SETs(&sv_yes))
116#define RETSETNO RETURNX(SETs(&sv_no))
117#define RETSETUNDEF RETURNX(SETs(&sv_undef))
118
119#define ARGTARG op->op_targ
120#define MAXARG op->op_private
121
122#define SWITCHSTACK(f,t) AvFILL(f) = sp - stack_base; \
123 stack_base = AvARRAY(t); \
124 stack_max = stack_base + AvMAX(t); \
a0d0e21e 125 sp = stack_sp = stack_base + AvFILL(t); \
e9905555 126 curstack = t;
79072805 127
a0d0e21e
LW
128#ifdef OVERLOAD
129
130#define AMGf_noright 1
131#define AMGf_noleft 2
132#define AMGf_assign 4
133#define AMGf_unary 8
134
86547924 135#define tryAMAGICbinW(meth,assign,set) STMT_START { \
a0d0e21e
LW
136 if (amagic_generation) { \
137 SV* tmpsv; \
138 SV* right= *(sp); SV* left= *(sp-1);\
139 if ((SvAMAGIC(left)||SvAMAGIC(right))&&\
140 (tmpsv=amagic_call(left, \
141 right, \
142 CAT2(meth,_amg), \
143 (assign)? AMGf_assign: 0))) {\
144 SPAGAIN; \
145 (void)POPs; set(tmpsv); RETURN; } \
146 } \
86547924 147 } STMT_END
a0d0e21e
LW
148
149#define tryAMAGICbin(meth,assign) tryAMAGICbinW(meth,assign,SETsv)
150#define tryAMAGICbinSET(meth,assign) tryAMAGICbinW(meth,assign,SETs)
151
152#define AMG_CALLun(sv,meth) amagic_call(sv,&sv_undef, \
153 CAT2(meth,_amg),AMGf_noright | AMGf_unary)
154#define AMG_CALLbinL(left,right,meth) \
155 amagic_call(left,right,CAT2(meth,_amg),AMGf_noright)
156
86547924 157#define tryAMAGICunW(meth,set) STMT_START { \
a0d0e21e
LW
158 if (amagic_generation) { \
159 SV* tmpsv; \
160 SV* arg= *(sp); \
161 if ((SvAMAGIC(arg))&&\
162 (tmpsv=AMG_CALLun(arg,meth))) {\
163 SPAGAIN; \
164 set(tmpsv); RETURN; } \
165 } \
86547924 166 } STMT_END
a0d0e21e 167
e9905555 168#define tryAMAGICun tryAMAGICunSET
a0d0e21e
LW
169#define tryAMAGICunSET(meth) tryAMAGICunW(meth,SETs)
170
171#define opASSIGN (op->op_flags & OPf_STACKED)
e9905555
PP
172#define SETsv(sv) STMT_START { \
173 if (opASSIGN) { sv_setsv(TARG, (sv)); SETTARG; } \
174 else SETs(sv); } STMT_END
a0d0e21e
LW
175
176/* newSVsv does not behave as advertised, so we copy missing
177 * information by hand */
178
179
86547924 180#define RvDEEPCP(rv) STMT_START { SV* ref=SvRV(rv); \
a0d0e21e
LW
181 if (SvREFCNT(ref)>1) { \
182 SvREFCNT_dec(ref); \
748a9306 183 SvRV(rv)=AMG_CALLun(rv,copy); \
86547924 184 } } STMT_END
a0d0e21e
LW
185#else
186
187#define tryAMAGICbin(a,b)
188#define tryAMAGICbinSET(a,b)
189#define tryAMAGICun(a)
190#define tryAMAGICunSET(a)
191
192#endif /* OVERLOAD */