3 * Copyright (c) 1991-1997, 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 * s(ARGSproto)
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 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))
69 #define TOPp (SvPV(TOPs, PL_na)) /* deprecated */
70 #define TOPpx (SvPV(TOPs, n_a))
71 #define TOPn (SvNV(TOPs))
72 #define TOPi ((IV)SvIV(TOPs))
73 #define TOPu ((UV)SvUV(TOPs))
74 #define TOPl ((long)SvIV(TOPs))
76 /* Go to some pains in the rare event that we must extend the stack. */
77 #define EXTEND(p,n) STMT_START { if (PL_stack_max - p < (n)) { \
78 sp = stack_grow(sp,p, (int) (n)); \
81 /* Same thing, but update mark register too. */
82 #define MEXTEND(p,n) STMT_START {if (PL_stack_max - p < (n)) { \
83 int markoff = mark - PL_stack_base; \
84 sp = stack_grow(sp,p,(int) (n)); \
85 mark = PL_stack_base + markoff; \
88 #define PUSHs(s) (*++sp = (s))
89 #define PUSHTARG STMT_START { SvSETMAGIC(TARG); PUSHs(TARG); } STMT_END
90 #define PUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); PUSHTARG; } STMT_END
91 #define PUSHn(n) STMT_START { sv_setnv(TARG, (double)(n)); PUSHTARG; } STMT_END
92 #define PUSHi(i) STMT_START { sv_setiv(TARG, (IV)(i)); PUSHTARG; } STMT_END
93 #define PUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); PUSHTARG; } STMT_END
95 #define XPUSHs(s) STMT_START { EXTEND(sp,1); (*++sp = (s)); } STMT_END
96 #define XPUSHTARG STMT_START { SvSETMAGIC(TARG); XPUSHs(TARG); } STMT_END
97 #define XPUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); XPUSHTARG; } STMT_END
98 #define XPUSHn(n) STMT_START { sv_setnv(TARG, (double)(n)); XPUSHTARG; } STMT_END
99 #define XPUSHi(i) STMT_START { sv_setiv(TARG, (IV)(i)); XPUSHTARG; } STMT_END
100 #define XPUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); XPUSHTARG; } STMT_END
102 #define SETs(s) (*sp = s)
103 #define SETTARG STMT_START { SvSETMAGIC(TARG); SETs(TARG); } STMT_END
104 #define SETp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); SETTARG; } STMT_END
105 #define SETn(n) STMT_START { sv_setnv(TARG, (double)(n)); SETTARG; } STMT_END
106 #define SETi(i) STMT_START { sv_setiv(TARG, (IV)(i)); SETTARG; } STMT_END
107 #define SETu(u) STMT_START { sv_setuv(TARG, (UV)(u)); SETTARG; } STMT_END
109 #define dTOPss SV *sv = TOPs
110 #define dPOPss SV *sv = POPs
111 #define dTOPnv double value = TOPn
112 #define dPOPnv double value = POPn
113 #define dTOPiv IV value = TOPi
114 #define dPOPiv IV value = POPi
115 #define dTOPuv UV value = TOPu
116 #define dPOPuv UV value = POPu
118 #define dPOPXssrl(X) SV *right = POPs; SV *left = CAT2(X,s)
119 #define dPOPXnnrl(X) double right = POPn; double left = CAT2(X,n)
120 #define dPOPXiirl(X) IV right = POPi; IV left = CAT2(X,i)
122 #define USE_LEFT(sv) \
123 (SvOK(sv) || SvGMAGICAL(sv) || !(PL_op->op_flags & OPf_STACKED))
124 #define dPOPXnnrl_ul(X) \
125 double right = POPn; \
126 SV *leftsv = CAT2(X,s); \
127 double left = USE_LEFT(leftsv) ? SvNV(leftsv) : 0.0
128 #define dPOPXiirl_ul(X) \
130 SV *leftsv = CAT2(X,s); \
131 IV left = USE_LEFT(leftsv) ? SvIV(leftsv) : 0
133 #define dPOPPOPssrl dPOPXssrl(POP)
134 #define dPOPPOPnnrl dPOPXnnrl(POP)
135 #define dPOPPOPnnrl_ul dPOPXnnrl_ul(POP)
136 #define dPOPPOPiirl dPOPXiirl(POP)
137 #define dPOPPOPiirl_ul dPOPXiirl_ul(POP)
139 #define dPOPTOPssrl dPOPXssrl(TOP)
140 #define dPOPTOPnnrl dPOPXnnrl(TOP)
141 #define dPOPTOPnnrl_ul dPOPXnnrl_ul(TOP)
142 #define dPOPTOPiirl dPOPXiirl(TOP)
143 #define dPOPTOPiirl_ul dPOPXiirl_ul(TOP)
145 #define RETPUSHYES RETURNX(PUSHs(&PL_sv_yes))
146 #define RETPUSHNO RETURNX(PUSHs(&PL_sv_no))
147 #define RETPUSHUNDEF RETURNX(PUSHs(&PL_sv_undef))
149 #define RETSETYES RETURNX(SETs(&PL_sv_yes))
150 #define RETSETNO RETURNX(SETs(&PL_sv_no))
151 #define RETSETUNDEF RETURNX(SETs(&PL_sv_undef))
153 #define ARGTARG PL_op->op_targ
154 #define MAXARG PL_op->op_private
156 #define SWITCHSTACK(f,t) \
158 AvFILLp(f) = sp - PL_stack_base; \
159 PL_stack_base = AvARRAY(t); \
160 PL_stack_max = PL_stack_base + AvMAX(t); \
161 sp = PL_stack_sp = PL_stack_base + AvFILLp(t); \
165 #define EXTEND_MORTAL(n) \
167 if (PL_tmps_ix + (n) >= PL_tmps_max) \
168 Renew(PL_tmps_stack, PL_tmps_max = PL_tmps_ix + (n) + 1, SV*); \
173 #define AMGf_noright 1
174 #define AMGf_noleft 2
175 #define AMGf_assign 4
178 #define tryAMAGICbinW(meth,assign,set) STMT_START { \
179 if (PL_amagic_generation) { \
181 SV* right= *(sp); SV* left= *(sp-1);\
182 if ((SvAMAGIC(left)||SvAMAGIC(right))&&\
183 (tmpsv=amagic_call(left, \
186 (assign)? AMGf_assign: 0))) {\
188 (void)POPs; set(tmpsv); RETURN; } \
192 #define tryAMAGICbin(meth,assign) tryAMAGICbinW(meth,assign,SETsv)
193 #define tryAMAGICbinSET(meth,assign) tryAMAGICbinW(meth,assign,SETs)
195 #define AMG_CALLun(sv,meth) amagic_call(sv,&PL_sv_undef, \
196 CAT2(meth,_amg),AMGf_noright | AMGf_unary)
197 #define AMG_CALLbinL(left,right,meth) \
198 amagic_call(left,right,CAT2(meth,_amg),AMGf_noright)
200 #define tryAMAGICunW(meth,set,shift,ret) STMT_START { \
201 if (PL_amagic_generation) { \
203 SV* arg= sp[shift]; \
205 if ((SvAMAGIC(arg))&&\
206 (tmpsv=AMG_CALLun(arg,meth))) {\
207 SPAGAIN; if (shift) sp += shift; \
212 #define FORCE_SETs(sv) STMT_START { sv_setsv(TARG, (sv)); SETTARG; } STMT_END
214 #define tryAMAGICun tryAMAGICunSET
215 #define tryAMAGICunSET(meth) tryAMAGICunW(meth,SETs,0,RETURN)
216 #define tryAMAGICunTARGET(meth, shift) \
217 { dSP; sp--; /* get TARGET from below PL_stack_sp */ \
219 { dSP; tryAMAGICunW(meth,FORCE_SETs,shift,RETURN);}}}
221 #define setAGAIN(ref) sv = arg = ref; \
223 croak("Overloaded dereference did not return a reference"); \
226 #define tryAMAGICunDEREF(meth) tryAMAGICunW(meth,setAGAIN,0,(void)0)
228 #define opASSIGN (PL_op->op_flags & OPf_STACKED)
229 #define SETsv(sv) STMT_START { \
230 if (opASSIGN) { sv_setsv(TARG, (sv)); SETTARG; } \
231 else SETs(sv); } STMT_END
233 /* newSVsv does not behave as advertised, so we copy missing
234 * information by hand */
236 /* SV* ref causes confusion with the member variable
237 changed SV* ref to SV* tmpRef */
238 #define RvDEEPCP(rv) STMT_START { SV* tmpRef=SvRV(rv); \
239 if (SvREFCNT(tmpRef)>1) { \
240 SvREFCNT_dec(tmpRef); \
241 SvRV(rv)=AMG_CALLun(rv,copy); \
245 #define tryAMAGICbin(a,b)
246 #define tryAMAGICbinSET(a,b)
247 #define tryAMAGICun(a)
248 #define tryAMAGICunSET(a)
250 #endif /* OVERLOAD */