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 * CPerlObj::s(ARGSproto)
20 #define PP(s) OP * s(ARGSproto)
27 #define PUSHMARK(p) if (++PL_markstack_ptr == PL_markstack_max) \
29 *PL_markstack_ptr = (p) - PL_stack_base
31 #define TOPMARK (*PL_markstack_ptr)
32 #define POPMARK (*PL_markstack_ptr--)
34 #define djSP register SV **sp = PL_stack_sp
35 #define dSP dTHR; djSP
36 #define dMARK register SV **mark = PL_stack_base + POPMARK
37 #define dORIGMARK I32 origmark = mark - PL_stack_base
38 #define SETORIGMARK origmark = mark - PL_stack_base
39 #define ORIGMARK (PL_stack_base + origmark)
41 #define SPAGAIN sp = PL_stack_sp
42 #define MSPAGAIN sp = PL_stack_sp; mark = ORIGMARK
44 #define GETTARGETSTACKED targ = (PL_op->op_flags & OPf_STACKED ? POPs : PAD_SV(PL_op->op_targ))
45 #define dTARGETSTACKED SV * GETTARGETSTACKED
47 #define GETTARGET targ = PAD_SV(PL_op->op_targ)
48 #define dTARGET SV * GETTARGET
50 #define GETATARGET targ = (PL_op->op_flags & OPf_STACKED ? sp[-1] : PAD_SV(PL_op->op_targ))
51 #define dATARGET SV * GETATARGET
53 #define dTARG SV *targ
55 #define NORMAL PL_op->op_next
56 #define DIE return die
58 #define PUTBACK PL_stack_sp = sp
59 #define RETURN return PUTBACK, NORMAL
60 #define RETURNOP(o) return PUTBACK, o
61 #define RETURNX(x) return x, PUTBACK, NORMAL
64 #define POPp (SvPVx(POPs, PL_na))
65 #define POPn (SvNVx(POPs))
66 #define POPi ((IV)SvIVx(POPs))
67 #define POPu ((UV)SvUVx(POPs))
68 #define POPl ((long)SvIVx(POPs))
71 #define TOPp (SvPV(TOPs, PL_na))
72 #define TOPn (SvNV(TOPs))
73 #define TOPi ((IV)SvIV(TOPs))
74 #define TOPu ((UV)SvUV(TOPs))
75 #define TOPl ((long)SvIV(TOPs))
77 /* Go to some pains in the rare event that we must extend the stack. */
78 #define EXTEND(p,n) STMT_START { if (PL_stack_max - p < (n)) { \
79 sp = stack_grow(sp,p, (int) (n)); \
82 /* Same thing, but update mark register too. */
83 #define MEXTEND(p,n) STMT_START {if (PL_stack_max - p < (n)) { \
84 int markoff = mark - PL_stack_base; \
85 sp = stack_grow(sp,p,(int) (n)); \
86 mark = PL_stack_base + markoff; \
89 #define PUSHs(s) (*++sp = (s))
90 #define PUSHTARG STMT_START { SvSETMAGIC(TARG); PUSHs(TARG); } STMT_END
91 #define PUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); PUSHTARG; } STMT_END
92 #define PUSHn(n) STMT_START { sv_setnv(TARG, (double)(n)); PUSHTARG; } STMT_END
93 #define PUSHi(i) STMT_START { sv_setiv(TARG, (IV)(i)); PUSHTARG; } STMT_END
94 #define PUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); PUSHTARG; } STMT_END
96 #define XPUSHs(s) STMT_START { EXTEND(sp,1); (*++sp = (s)); } STMT_END
97 #define XPUSHTARG STMT_START { SvSETMAGIC(TARG); XPUSHs(TARG); } STMT_END
98 #define XPUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); XPUSHTARG; } STMT_END
99 #define XPUSHn(n) STMT_START { sv_setnv(TARG, (double)(n)); XPUSHTARG; } STMT_END
100 #define XPUSHi(i) STMT_START { sv_setiv(TARG, (IV)(i)); XPUSHTARG; } STMT_END
101 #define XPUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); XPUSHTARG; } STMT_END
103 #define SETs(s) (*sp = s)
104 #define SETTARG STMT_START { SvSETMAGIC(TARG); SETs(TARG); } STMT_END
105 #define SETp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); SETTARG; } STMT_END
106 #define SETn(n) STMT_START { sv_setnv(TARG, (double)(n)); SETTARG; } STMT_END
107 #define SETi(i) STMT_START { sv_setiv(TARG, (IV)(i)); SETTARG; } STMT_END
108 #define SETu(u) STMT_START { sv_setuv(TARG, (UV)(u)); SETTARG; } STMT_END
110 #define dTOPss SV *sv = TOPs
111 #define dPOPss SV *sv = POPs
112 #define dTOPnv double value = TOPn
113 #define dPOPnv double value = POPn
114 #define dTOPiv IV value = TOPi
115 #define dPOPiv IV value = POPi
116 #define dTOPuv UV value = TOPu
117 #define dPOPuv UV value = POPu
119 #define dPOPXssrl(X) SV *right = POPs; SV *left = CAT2(X,s)
120 #define dPOPXnnrl(X) double right = POPn; double left = CAT2(X,n)
121 #define dPOPXiirl(X) IV right = POPi; IV left = CAT2(X,i)
123 #define USE_LEFT(sv) \
124 (SvOK(sv) || SvGMAGICAL(sv) || !(PL_op->op_flags & OPf_STACKED))
125 #define dPOPXnnrl_ul(X) \
126 double right = POPn; \
127 SV *leftsv = CAT2(X,s); \
128 double left = USE_LEFT(leftsv) ? SvNV(leftsv) : 0.0
129 #define dPOPXiirl_ul(X) \
131 SV *leftsv = CAT2(X,s); \
132 IV left = USE_LEFT(leftsv) ? SvIV(leftsv) : 0
134 #define dPOPPOPssrl dPOPXssrl(POP)
135 #define dPOPPOPnnrl dPOPXnnrl(POP)
136 #define dPOPPOPnnrl_ul dPOPXnnrl_ul(POP)
137 #define dPOPPOPiirl dPOPXiirl(POP)
138 #define dPOPPOPiirl_ul dPOPXiirl_ul(POP)
140 #define dPOPTOPssrl dPOPXssrl(TOP)
141 #define dPOPTOPnnrl dPOPXnnrl(TOP)
142 #define dPOPTOPnnrl_ul dPOPXnnrl_ul(TOP)
143 #define dPOPTOPiirl dPOPXiirl(TOP)
144 #define dPOPTOPiirl_ul dPOPXiirl_ul(TOP)
146 #define RETPUSHYES RETURNX(PUSHs(&PL_sv_yes))
147 #define RETPUSHNO RETURNX(PUSHs(&PL_sv_no))
148 #define RETPUSHUNDEF RETURNX(PUSHs(&PL_sv_undef))
150 #define RETSETYES RETURNX(SETs(&PL_sv_yes))
151 #define RETSETNO RETURNX(SETs(&PL_sv_no))
152 #define RETSETUNDEF RETURNX(SETs(&PL_sv_undef))
154 #define ARGTARG PL_op->op_targ
155 #define MAXARG PL_op->op_private
157 #define SWITCHSTACK(f,t) \
159 AvFILLp(f) = sp - PL_stack_base; \
160 PL_stack_base = AvARRAY(t); \
161 PL_stack_max = PL_stack_base + AvMAX(t); \
162 sp = PL_stack_sp = PL_stack_base + AvFILLp(t); \
166 #define EXTEND_MORTAL(n) \
168 if (PL_tmps_ix + (n) >= PL_tmps_max) \
169 Renew(PL_tmps_stack, PL_tmps_max = PL_tmps_ix + (n) + 1, SV*); \
174 #define AMGf_noright 1
175 #define AMGf_noleft 2
176 #define AMGf_assign 4
179 #define tryAMAGICbinW(meth,assign,set) STMT_START { \
180 if (PL_amagic_generation) { \
182 SV* right= *(sp); SV* left= *(sp-1);\
183 if ((SvAMAGIC(left)||SvAMAGIC(right))&&\
184 (tmpsv=amagic_call(left, \
187 (assign)? AMGf_assign: 0))) {\
189 (void)POPs; set(tmpsv); RETURN; } \
193 #define tryAMAGICbin(meth,assign) tryAMAGICbinW(meth,assign,SETsv)
194 #define tryAMAGICbinSET(meth,assign) tryAMAGICbinW(meth,assign,SETs)
196 #define AMG_CALLun(sv,meth) amagic_call(sv,&PL_sv_undef, \
197 CAT2(meth,_amg),AMGf_noright | AMGf_unary)
198 #define AMG_CALLbinL(left,right,meth) \
199 amagic_call(left,right,CAT2(meth,_amg),AMGf_noright)
201 #define tryAMAGICunW(meth,set) STMT_START { \
202 if (PL_amagic_generation) { \
205 if ((SvAMAGIC(arg))&&\
206 (tmpsv=AMG_CALLun(arg,meth))) {\
208 set(tmpsv); RETURN; } \
212 #define tryAMAGICun tryAMAGICunSET
213 #define tryAMAGICunSET(meth) tryAMAGICunW(meth,SETs)
215 #define opASSIGN (PL_op->op_flags & OPf_STACKED)
216 #define SETsv(sv) STMT_START { \
217 if (opASSIGN) { sv_setsv(TARG, (sv)); SETTARG; } \
218 else SETs(sv); } STMT_END
220 /* newSVsv does not behave as advertised, so we copy missing
221 * information by hand */
223 /* SV* ref causes confusion with the member variable
224 changed SV* ref to SV* tmpRef */
225 #define RvDEEPCP(rv) STMT_START { SV* tmpRef=SvRV(rv); \
226 if (SvREFCNT(tmpRef)>1) { \
227 SvREFCNT_dec(tmpRef); \
228 SvRV(rv)=AMG_CALLun(rv,copy); \
232 #define tryAMAGICbin(a,b)
233 #define tryAMAGICbinSET(a,b)
234 #define tryAMAGICun(a)
235 #define tryAMAGICunSET(a)
237 #endif /* OVERLOAD */