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) do { 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) do {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 do { SvSETMAGIC(TARG); PUSHs(TARG); } while (0)
80 #define PUSHp(p,l) do { sv_setpvn(TARG, (p), (l)); PUSHTARG; } while (0)
81 #define PUSHn(n) do { sv_setnv(TARG, (double)(n)); PUSHTARG; } while (0)
82 #define PUSHi(i) do { sv_setiv(TARG, (IV)(i)); PUSHTARG; } while (0)
84 #define XPUSHs(s) do { EXTEND(sp,1); (*++sp = (s)); } while (0)
85 #define XPUSHTARG do { SvSETMAGIC(TARG); XPUSHs(TARG); } while (0)
86 #define XPUSHp(p,l) do { sv_setpvn(TARG, (p), (l)); XPUSHTARG; } while (0)
87 #define XPUSHn(n) do { sv_setnv(TARG, (double)(n)); XPUSHTARG; } while (0)
88 #define XPUSHi(i) do { sv_setiv(TARG, (IV)(i)); XPUSHTARG; } while (0)
90 #define SETs(s) (*sp = s)
91 #define SETTARG do { SvSETMAGIC(TARG); SETs(TARG); } while (0)
92 #define SETp(p,l) do { sv_setpvn(TARG, (p), (l)); SETTARG; } while (0)
93 #define SETn(n) do { sv_setnv(TARG, (double)(n)); SETTARG; } while (0)
94 #define SETi(i) do { sv_setiv(TARG, (IV)(i)); SETTARG; } while (0)
97 #define SETsv(sv) do { sv_setsv(TARG, (sv)); SETTARG; } while (0)
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) do { \
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) do { \
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) do { SV* ref=SvRV(rv); \
182 if (SvREFCNT(ref)>1) { \
184 SvRV(rv)=newSVsv(ref); \
188 #define tryAMAGICbin(a,b)
189 #define tryAMAGICbinSET(a,b)
190 #define tryAMAGICun(a)
191 #define tryAMAGICunSET(a)
193 #endif /* OVERLOAD */