3 * Copyright (c) 1991-1994, 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.
11 #define ARGSproto void
13 #define PP(s) OP* s(ARGS) dARGS
19 #define PUSHMARK(p) if (++markstack_ptr == markstack_max) \
21 *markstack_ptr = (p) - stack_base
23 #define TOPMARK (*markstack_ptr)
24 #define POPMARK (*markstack_ptr--)
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
30 #define ORIGMARK (stack_base + origmark)
32 #define SPAGAIN sp = stack_sp
33 #define MSPAGAIN sp = stack_sp; mark = ORIGMARK
35 #define GETTARGETSTACKED targ = (op->op_flags & OPf_STACKED ? POPs : PAD_SV(op->op_targ))
36 #define dTARGETSTACKED SV * GETTARGETSTACKED
38 #define GETTARGET targ = PAD_SV(op->op_targ)
39 #define dTARGET SV * GETTARGET
41 #define GETATARGET targ = (op->op_flags & OPf_STACKED ? sp[-1] : PAD_SV(op->op_targ))
42 #define dATARGET SV * GETATARGET
44 #define dTARG SV *targ
46 #define NORMAL op->op_next
47 #define DIE return die
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
55 #define POPp (SvPVx(POPs, na))
56 #define POPn (SvNVx(POPs))
57 #define POPi ((IV)SvIVx(POPs))
58 #define POPl ((long)SvIVx(POPs))
61 #define TOPp (SvPV(TOPs, na))
62 #define TOPn (SvNV(TOPs))
63 #define TOPi ((IV)SvIV(TOPs))
64 #define TOPl ((long)SvIV(TOPs))
66 /* Go to some pains in the rare event that we must extend the stack. */
67 #define EXTEND(p,n) STMT_START { if (stack_max - p < (n)) { \
68 sp = stack_grow(sp,p, (int) (n)); \
71 /* Same thing, but update mark register too. */
72 #define MEXTEND(p,n) STMT_START {if (stack_max - p < (n)) { \
73 int markoff = mark - stack_base; \
74 sp = stack_grow(sp,p,(int) (n)); \
75 mark = stack_base + markoff; \
78 #define PUSHs(s) (*++sp = (s))
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
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
90 #define SETs(s) (*sp = s)
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
97 #define SETsv(sv) STMT_START { sv_setsv(TARG, (sv)); SETTARG; } STMT_END
100 #define dTOPss SV *sv = TOPs
101 #define dPOPss SV *sv = POPs
102 #define dTOPnv double value = TOPn
103 #define dPOPnv double value = POPn
104 #define dTOPiv IV value = TOPi
105 #define dPOPiv IV value = POPi
107 #define dPOPPOPssrl SV *right = POPs; SV *left = POPs
108 #define dPOPPOPnnrl double right = POPn; double left = POPn
109 #define dPOPPOPiirl IV right = POPi; IV left = POPi
111 #define dPOPTOPssrl SV *right = POPs; SV *left = TOPs
112 #define dPOPTOPnnrl double right = POPn; double left = TOPn
113 #define dPOPTOPiirl IV right = POPi; IV left = TOPi
115 #define RETPUSHYES RETURNX(PUSHs(&sv_yes))
116 #define RETPUSHNO RETURNX(PUSHs(&sv_no))
117 #define RETPUSHUNDEF RETURNX(PUSHs(&sv_undef))
119 #define RETSETYES RETURNX(SETs(&sv_yes))
120 #define RETSETNO RETURNX(SETs(&sv_no))
121 #define RETSETUNDEF RETURNX(SETs(&sv_undef))
123 #define ARGTARG op->op_targ
124 #define MAXARG op->op_private
126 #define SWITCHSTACK(f,t) AvFILL(f) = sp - stack_base; \
127 stack_base = AvARRAY(t); \
128 stack_max = stack_base + AvMAX(t); \
129 sp = stack_sp = stack_base + AvFILL(t); \
134 #define AMGf_noright 1
135 #define AMGf_noleft 2
136 #define AMGf_assign 4
139 #define tryAMAGICbinW(meth,assign,set) STMT_START { \
140 if (amagic_generation) { \
142 SV* right= *(sp); SV* left= *(sp-1);\
143 if ((SvAMAGIC(left)||SvAMAGIC(right))&&\
144 (tmpsv=amagic_call(left, \
147 (assign)? AMGf_assign: 0))) {\
149 (void)POPs; set(tmpsv); RETURN; } \
153 #define tryAMAGICbin(meth,assign) tryAMAGICbinW(meth,assign,SETsv)
154 #define tryAMAGICbinSET(meth,assign) tryAMAGICbinW(meth,assign,SETs)
156 #define AMG_CALLun(sv,meth) amagic_call(sv,&sv_undef, \
157 CAT2(meth,_amg),AMGf_noright | AMGf_unary)
158 #define AMG_CALLbinL(left,right,meth) \
159 amagic_call(left,right,CAT2(meth,_amg),AMGf_noright)
161 #define tryAMAGICunW(meth,set) STMT_START { \
162 if (amagic_generation) { \
165 if ((SvAMAGIC(arg))&&\
166 (tmpsv=AMG_CALLun(arg,meth))) {\
168 set(tmpsv); RETURN; } \
172 #define tryAMAGICun(meth) tryAMAGICunW(meth,SETsv)
173 #define tryAMAGICunSET(meth) tryAMAGICunW(meth,SETs)
175 #define opASSIGN (op->op_flags & OPf_STACKED)
177 /* newSVsv does not behave as advertised, so we copy missing
178 * information by hand */
181 #define RvDEEPCP(rv) STMT_START { SV* ref=SvRV(rv); \
182 if (SvREFCNT(ref)>1) { \
184 SvRV(rv)=AMG_CALLun(rv,copy); \
188 #define tryAMAGICbin(a,b)
189 #define tryAMAGICbinSET(a,b)
190 #define tryAMAGICun(a)
191 #define tryAMAGICunSET(a)
193 #endif /* OVERLOAD */