3 * Copyright (c) 1991-1999, Larry Wall
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.
12 #define dARGS struct perl_thread *thr;
16 #endif /* USE_THREADS */
18 #define PP(s) OP * Perl_##s(pTHX)
24 #define PUSHMARK(p) if (++PL_markstack_ptr == PL_markstack_max) \
26 *PL_markstack_ptr = (p) - PL_stack_base
28 #define TOPMARK (*PL_markstack_ptr)
29 #define POPMARK (*PL_markstack_ptr--)
31 #define djSP register SV **sp = PL_stack_sp
32 #define dSP dTHR; djSP
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)
38 #define SPAGAIN sp = PL_stack_sp
39 #define MSPAGAIN sp = PL_stack_sp; mark = ORIGMARK
41 #define GETTARGETSTACKED targ = (PL_op->op_flags & OPf_STACKED ? POPs : PAD_SV(PL_op->op_targ))
42 #define dTARGETSTACKED SV * GETTARGETSTACKED
44 #define GETTARGET targ = PAD_SV(PL_op->op_targ)
45 #define dTARGET SV * GETTARGET
47 #define GETATARGET targ = (PL_op->op_flags & OPf_STACKED ? sp[-1] : PAD_SV(PL_op->op_targ))
48 #define dATARGET SV * GETATARGET
50 #define dTARG SV *targ
52 #define NORMAL PL_op->op_next
53 #define DIE return Perl_die
55 #define PUTBACK PL_stack_sp = sp
56 #define RETURN return PUTBACK, NORMAL
57 #define RETURNOP(o) return PUTBACK, o
58 #define RETURNX(x) return x, PUTBACK, NORMAL
61 #define POPp (SvPVx(POPs, PL_na)) /* deprecated */
62 #define POPpx (SvPVx(POPs, n_a))
63 #define POPn (SvNVx(POPs))
64 #define POPi ((IV)SvIVx(POPs))
65 #define POPu ((UV)SvUVx(POPs))
66 #define POPl ((long)SvIVx(POPs))
67 #define POPul ((unsigned long)SvIVx(POPs))
69 #define POPq ((Quad_t)SvIVx(POPs))
73 #define TOPp (SvPV(TOPs, PL_na)) /* deprecated */
74 #define TOPpx (SvPV(TOPs, n_a))
75 #define TOPn (SvNV(TOPs))
76 #define TOPi ((IV)SvIV(TOPs))
77 #define TOPu ((UV)SvUV(TOPs))
78 #define TOPl ((long)SvIV(TOPs))
79 #define TOPul ((unsigned long)SvIV(TOPs))
81 #define TOPq ((Quad_t)SvIV(TOPs))
84 /* Go to some pains in the rare event that we must extend the stack. */
85 #define EXTEND(p,n) STMT_START { if (PL_stack_max - p < (n)) { \
86 sp = stack_grow(sp,p, (int) (n)); \
89 /* Same thing, but update mark register too. */
90 #define MEXTEND(p,n) STMT_START {if (PL_stack_max - p < (n)) { \
91 int markoff = mark - PL_stack_base; \
92 sp = stack_grow(sp,p,(int) (n)); \
93 mark = PL_stack_base + markoff; \
96 #define PUSHs(s) (*++sp = (s))
97 #define PUSHTARG STMT_START { SvSETMAGIC(TARG); PUSHs(TARG); } STMT_END
98 #define PUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); PUSHTARG; } STMT_END
99 #define PUSHn(n) STMT_START { sv_setnv(TARG, (NV)(n)); PUSHTARG; } STMT_END
100 #define PUSHi(i) STMT_START { sv_setiv(TARG, (IV)(i)); PUSHTARG; } STMT_END
101 #define PUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); PUSHTARG; } STMT_END
103 #define XPUSHs(s) STMT_START { EXTEND(sp,1); (*++sp = (s)); } STMT_END
104 #define XPUSHTARG STMT_START { SvSETMAGIC(TARG); XPUSHs(TARG); } STMT_END
105 #define XPUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); XPUSHTARG; } STMT_END
106 #define XPUSHn(n) STMT_START { sv_setnv(TARG, (NV)(n)); XPUSHTARG; } STMT_END
107 #define XPUSHi(i) STMT_START { sv_setiv(TARG, (IV)(i)); XPUSHTARG; } STMT_END
108 #define XPUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); XPUSHTARG; } STMT_END
109 #define XPUSHundef STMT_START { SvOK_off(TARG); XPUSHs(TARG); } STMT_END
111 #define SETs(s) (*sp = s)
112 #define SETTARG STMT_START { SvSETMAGIC(TARG); SETs(TARG); } STMT_END
113 #define SETp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); SETTARG; } STMT_END
114 #define SETn(n) STMT_START { sv_setnv(TARG, (NV)(n)); SETTARG; } STMT_END
115 #define SETi(i) STMT_START { sv_setiv(TARG, (IV)(i)); SETTARG; } STMT_END
116 #define SETu(u) STMT_START { sv_setuv(TARG, (UV)(u)); SETTARG; } STMT_END
118 #define dTOPss SV *sv = TOPs
119 #define dPOPss SV *sv = POPs
120 #define dTOPnv NV value = TOPn
121 #define dPOPnv NV value = POPn
122 #define dTOPiv IV value = TOPi
123 #define dPOPiv IV value = POPi
124 #define dTOPuv UV value = TOPu
125 #define dPOPuv UV value = POPu
127 #define dPOPXssrl(X) SV *right = POPs; SV *left = CAT2(X,s)
128 #define dPOPXnnrl(X) NV right = POPn; NV left = CAT2(X,n)
129 #define dPOPXiirl(X) IV right = POPi; IV left = CAT2(X,i)
131 #define USE_LEFT(sv) \
132 (SvOK(sv) || SvGMAGICAL(sv) || !(PL_op->op_flags & OPf_STACKED))
133 #define dPOPXnnrl_ul(X) \
135 SV *leftsv = CAT2(X,s); \
136 NV left = USE_LEFT(leftsv) ? SvNV(leftsv) : 0.0
137 #define dPOPXiirl_ul(X) \
139 SV *leftsv = CAT2(X,s); \
140 IV left = USE_LEFT(leftsv) ? SvIV(leftsv) : 0
142 #define dPOPPOPssrl dPOPXssrl(POP)
143 #define dPOPPOPnnrl dPOPXnnrl(POP)
144 #define dPOPPOPnnrl_ul dPOPXnnrl_ul(POP)
145 #define dPOPPOPiirl dPOPXiirl(POP)
146 #define dPOPPOPiirl_ul dPOPXiirl_ul(POP)
148 #define dPOPTOPssrl dPOPXssrl(TOP)
149 #define dPOPTOPnnrl dPOPXnnrl(TOP)
150 #define dPOPTOPnnrl_ul dPOPXnnrl_ul(TOP)
151 #define dPOPTOPiirl dPOPXiirl(TOP)
152 #define dPOPTOPiirl_ul dPOPXiirl_ul(TOP)
154 #define RETPUSHYES RETURNX(PUSHs(&PL_sv_yes))
155 #define RETPUSHNO RETURNX(PUSHs(&PL_sv_no))
156 #define RETPUSHUNDEF RETURNX(PUSHs(&PL_sv_undef))
158 #define RETSETYES RETURNX(SETs(&PL_sv_yes))
159 #define RETSETNO RETURNX(SETs(&PL_sv_no))
160 #define RETSETUNDEF RETURNX(SETs(&PL_sv_undef))
162 #define ARGTARG PL_op->op_targ
164 /* See OPpTARGET_MY: */
165 #define MAXARG (PL_op->op_private & 15)
167 #define SWITCHSTACK(f,t) \
169 AvFILLp(f) = sp - PL_stack_base; \
170 PL_stack_base = AvARRAY(t); \
171 PL_stack_max = PL_stack_base + AvMAX(t); \
172 sp = PL_stack_sp = PL_stack_base + AvFILLp(t); \
176 #define EXTEND_MORTAL(n) \
178 if (PL_tmps_ix + (n) >= PL_tmps_max) \
182 #define AMGf_noright 1
183 #define AMGf_noleft 2
184 #define AMGf_assign 4
187 #define tryAMAGICbinW(meth,assign,set) STMT_START { \
188 if (PL_amagic_generation) { \
190 SV* right= *(sp); SV* left= *(sp-1);\
191 if ((SvAMAGIC(left)||SvAMAGIC(right))&&\
192 (tmpsv=amagic_call(left, \
195 (assign)? AMGf_assign: 0))) {\
197 (void)POPs; set(tmpsv); RETURN; } \
201 #define tryAMAGICbin(meth,assign) tryAMAGICbinW(meth,assign,SETsv)
202 #define tryAMAGICbinSET(meth,assign) tryAMAGICbinW(meth,assign,SETs)
204 #define AMG_CALLun(sv,meth) amagic_call(sv,&PL_sv_undef, \
205 CAT2(meth,_amg),AMGf_noright | AMGf_unary)
206 #define AMG_CALLbinL(left,right,meth) \
207 amagic_call(left,right,CAT2(meth,_amg),AMGf_noright)
209 #define tryAMAGICunW(meth,set,shift,ret) STMT_START { \
210 if (PL_amagic_generation) { \
212 SV* arg= sp[shift]; \
214 if ((SvAMAGIC(arg))&&\
215 (tmpsv=AMG_CALLun(arg,meth))) {\
216 SPAGAIN; if (shift) sp += shift; \
221 #define FORCE_SETs(sv) STMT_START { sv_setsv(TARG, (sv)); SETTARG; } STMT_END
223 #define tryAMAGICun(meth) tryAMAGICunW(meth,SETsvUN,0,RETURN)
224 #define tryAMAGICunSET(meth) tryAMAGICunW(meth,SETs,0,RETURN)
225 #define tryAMAGICunTARGET(meth, shift) \
226 { dSP; sp--; /* get TARGET from below PL_stack_sp */ \
228 { dSP; tryAMAGICunW(meth,FORCE_SETs,shift,RETURN);}}}
230 #define setAGAIN(ref) sv = arg = ref; \
232 Perl_croak(aTHX_ "Overloaded dereference did not return a reference"); \
235 #define tryAMAGICunDEREF(meth) tryAMAGICunW(meth,setAGAIN,0,(void)0)
237 #define opASSIGN (PL_op->op_flags & OPf_STACKED)
238 #define SETsv(sv) STMT_START { \
239 if (opASSIGN || (SvFLAGS(TARG) & SVs_PADMY)) \
240 { sv_setsv(TARG, (sv)); SETTARG; } \
241 else SETs(sv); } STMT_END
243 #define SETsvUN(sv) STMT_START { \
244 if (SvFLAGS(TARG) & SVs_PADMY) \
245 { sv_setsv(TARG, (sv)); SETTARG; } \
246 else SETs(sv); } STMT_END
248 /* newSVsv does not behave as advertised, so we copy missing
249 * information by hand */
251 /* SV* ref causes confusion with the member variable
252 changed SV* ref to SV* tmpRef */
253 #define RvDEEPCP(rv) STMT_START { SV* tmpRef=SvRV(rv); \
254 if (SvREFCNT(tmpRef)>1) { \
255 SvREFCNT_dec(tmpRef); \
256 SvRV(rv)=AMG_CALLun(rv,copy); \