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))
70 #define POPuq ((Uquad_t)SvUVx(POPs))
74 #define TOPp (SvPV(TOPs, PL_na)) /* deprecated */
75 #define TOPpx (SvPV(TOPs, n_a))
76 #define TOPn (SvNV(TOPs))
77 #define TOPi ((IV)SvIV(TOPs))
78 #define TOPu ((UV)SvUV(TOPs))
79 #define TOPl ((long)SvIV(TOPs))
80 #define TOPul ((unsigned long)SvUV(TOPs))
82 #define TOPq ((Quad_t)SvIV(TOPs))
83 #define TOPuq ((Uquad_t)SvUV(TOPs))
86 /* Go to some pains in the rare event that we must extend the stack. */
87 #define EXTEND(p,n) STMT_START { if (PL_stack_max - p < (n)) { \
88 sp = stack_grow(sp,p, (int) (n)); \
91 /* Same thing, but update mark register too. */
92 #define MEXTEND(p,n) STMT_START {if (PL_stack_max - p < (n)) { \
93 int markoff = mark - PL_stack_base; \
94 sp = stack_grow(sp,p,(int) (n)); \
95 mark = PL_stack_base + markoff; \
98 #define PUSHs(s) (*++sp = (s))
99 #define PUSHTARG STMT_START { SvSETMAGIC(TARG); PUSHs(TARG); } STMT_END
100 #define PUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); PUSHTARG; } STMT_END
101 #define PUSHn(n) STMT_START { sv_setnv(TARG, (NV)(n)); PUSHTARG; } STMT_END
102 #define PUSHi(i) STMT_START { sv_setiv(TARG, (IV)(i)); PUSHTARG; } STMT_END
103 #define PUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); PUSHTARG; } STMT_END
105 #define XPUSHs(s) STMT_START { EXTEND(sp,1); (*++sp = (s)); } STMT_END
106 #define XPUSHTARG STMT_START { SvSETMAGIC(TARG); XPUSHs(TARG); } STMT_END
107 #define XPUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); XPUSHTARG; } STMT_END
108 #define XPUSHn(n) STMT_START { sv_setnv(TARG, (NV)(n)); XPUSHTARG; } STMT_END
109 #define XPUSHi(i) STMT_START { sv_setiv(TARG, (IV)(i)); XPUSHTARG; } STMT_END
110 #define XPUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); XPUSHTARG; } STMT_END
111 #define XPUSHundef STMT_START { SvOK_off(TARG); XPUSHs(TARG); } STMT_END
113 #define SETs(s) (*sp = s)
114 #define SETTARG STMT_START { SvSETMAGIC(TARG); SETs(TARG); } STMT_END
115 #define SETp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); SETTARG; } STMT_END
116 #define SETn(n) STMT_START { sv_setnv(TARG, (NV)(n)); SETTARG; } STMT_END
117 #define SETi(i) STMT_START { sv_setiv(TARG, (IV)(i)); SETTARG; } STMT_END
118 #define SETu(u) STMT_START { sv_setuv(TARG, (UV)(u)); SETTARG; } STMT_END
120 #define dTOPss SV *sv = TOPs
121 #define dPOPss SV *sv = POPs
122 #define dTOPnv NV value = TOPn
123 #define dPOPnv NV value = POPn
124 #define dTOPiv IV value = TOPi
125 #define dPOPiv IV value = POPi
126 #define dTOPuv UV value = TOPu
127 #define dPOPuv UV value = POPu
129 #define dTOPqv Quad_t value = TOPu
130 #define dPOPqv Quad_t value = POPu
131 #define dTOPuqv Uquad_t value = TOPuq
132 #define dPOPuqv Uquad_t value = POPuq
135 #define dPOPXssrl(X) SV *right = POPs; SV *left = CAT2(X,s)
136 #define dPOPXnnrl(X) NV right = POPn; NV left = CAT2(X,n)
137 #define dPOPXiirl(X) IV right = POPi; IV left = CAT2(X,i)
139 #define USE_LEFT(sv) \
140 (SvOK(sv) || SvGMAGICAL(sv) || !(PL_op->op_flags & OPf_STACKED))
141 #define dPOPXnnrl_ul(X) \
143 SV *leftsv = CAT2(X,s); \
144 NV left = USE_LEFT(leftsv) ? SvNV(leftsv) : 0.0
145 #define dPOPXiirl_ul(X) \
147 SV *leftsv = CAT2(X,s); \
148 IV left = USE_LEFT(leftsv) ? SvIV(leftsv) : 0
150 #define dPOPPOPssrl dPOPXssrl(POP)
151 #define dPOPPOPnnrl dPOPXnnrl(POP)
152 #define dPOPPOPnnrl_ul dPOPXnnrl_ul(POP)
153 #define dPOPPOPiirl dPOPXiirl(POP)
154 #define dPOPPOPiirl_ul dPOPXiirl_ul(POP)
156 #define dPOPTOPssrl dPOPXssrl(TOP)
157 #define dPOPTOPnnrl dPOPXnnrl(TOP)
158 #define dPOPTOPnnrl_ul dPOPXnnrl_ul(TOP)
159 #define dPOPTOPiirl dPOPXiirl(TOP)
160 #define dPOPTOPiirl_ul dPOPXiirl_ul(TOP)
162 #define RETPUSHYES RETURNX(PUSHs(&PL_sv_yes))
163 #define RETPUSHNO RETURNX(PUSHs(&PL_sv_no))
164 #define RETPUSHUNDEF RETURNX(PUSHs(&PL_sv_undef))
166 #define RETSETYES RETURNX(SETs(&PL_sv_yes))
167 #define RETSETNO RETURNX(SETs(&PL_sv_no))
168 #define RETSETUNDEF RETURNX(SETs(&PL_sv_undef))
170 #define ARGTARG PL_op->op_targ
172 /* See OPpTARGET_MY: */
173 #define MAXARG (PL_op->op_private & 15)
175 #define SWITCHSTACK(f,t) \
177 AvFILLp(f) = sp - PL_stack_base; \
178 PL_stack_base = AvARRAY(t); \
179 PL_stack_max = PL_stack_base + AvMAX(t); \
180 sp = PL_stack_sp = PL_stack_base + AvFILLp(t); \
184 #define EXTEND_MORTAL(n) \
186 if (PL_tmps_ix + (n) >= PL_tmps_max) \
190 #define AMGf_noright 1
191 #define AMGf_noleft 2
192 #define AMGf_assign 4
195 #define tryAMAGICbinW(meth,assign,set) STMT_START { \
196 if (PL_amagic_generation) { \
198 SV* right= *(sp); SV* left= *(sp-1);\
199 if ((SvAMAGIC(left)||SvAMAGIC(right))&&\
200 (tmpsv=amagic_call(left, \
203 (assign)? AMGf_assign: 0))) {\
205 (void)POPs; set(tmpsv); RETURN; } \
209 #define tryAMAGICbin(meth,assign) tryAMAGICbinW(meth,assign,SETsv)
210 #define tryAMAGICbinSET(meth,assign) tryAMAGICbinW(meth,assign,SETs)
212 #define AMG_CALLun(sv,meth) amagic_call(sv,&PL_sv_undef, \
213 CAT2(meth,_amg),AMGf_noright | AMGf_unary)
214 #define AMG_CALLbinL(left,right,meth) \
215 amagic_call(left,right,CAT2(meth,_amg),AMGf_noright)
217 #define tryAMAGICunW(meth,set,shift,ret) STMT_START { \
218 if (PL_amagic_generation) { \
220 SV* arg= sp[shift]; \
222 if ((SvAMAGIC(arg))&&\
223 (tmpsv=AMG_CALLun(arg,meth))) {\
224 SPAGAIN; if (shift) sp += shift; \
229 #define FORCE_SETs(sv) STMT_START { sv_setsv(TARG, (sv)); SETTARG; } STMT_END
231 #define tryAMAGICun(meth) tryAMAGICunW(meth,SETsvUN,0,RETURN)
232 #define tryAMAGICunSET(meth) tryAMAGICunW(meth,SETs,0,RETURN)
233 #define tryAMAGICunTARGET(meth, shift) \
234 { dSP; sp--; /* get TARGET from below PL_stack_sp */ \
236 { dSP; tryAMAGICunW(meth,FORCE_SETs,shift,RETURN);}}}
238 #define setAGAIN(ref) sv = arg = ref; \
240 Perl_croak(aTHX_ "Overloaded dereference did not return a reference"); \
243 #define tryAMAGICunDEREF(meth) tryAMAGICunW(meth,setAGAIN,0,(void)0)
245 #define opASSIGN (PL_op->op_flags & OPf_STACKED)
246 #define SETsv(sv) STMT_START { \
247 if (opASSIGN || (SvFLAGS(TARG) & SVs_PADMY)) \
248 { sv_setsv(TARG, (sv)); SETTARG; } \
249 else SETs(sv); } STMT_END
251 #define SETsvUN(sv) STMT_START { \
252 if (SvFLAGS(TARG) & SVs_PADMY) \
253 { sv_setsv(TARG, (sv)); SETTARG; } \
254 else SETs(sv); } STMT_END
256 /* newSVsv does not behave as advertised, so we copy missing
257 * information by hand */
259 /* SV* ref causes confusion with the member variable
260 changed SV* ref to SV* tmpRef */
261 #define RvDEEPCP(rv) STMT_START { SV* tmpRef=SvRV(rv); \
262 if (SvREFCNT(tmpRef)>1) { \
263 SvREFCNT_dec(tmpRef); \
264 SvRV(rv)=AMG_CALLun(rv,copy); \