Commit | Line | Data |
a0d0e21e |
1 | /* pp.h |
79072805 |
2 | * |
a0d0e21e |
3 | * Copyright (c) 1991-1994, Larry Wall |
79072805 |
4 | * |
a0d0e21e |
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. |
79072805 |
7 | * |
a0d0e21e |
8 | */ |
79072805 |
9 | |
10 | #define ARGS |
463ee0b2 |
11 | #define ARGSproto void |
79072805 |
12 | #define dARGS |
13 | #define PP(s) OP* s(ARGS) dARGS |
14 | |
15 | #define SP sp |
16 | #define MARK mark |
17 | #define TARG targ |
18 | |
a0d0e21e |
19 | #define PUSHMARK(p) if (++markstack_ptr == markstack_max) \ |
20 | markstack_grow(); \ |
21 | *markstack_ptr = (p) - stack_base |
22 | |
23 | #define TOPMARK (*markstack_ptr) |
79072805 |
24 | #define POPMARK (*markstack_ptr--) |
a0d0e21e |
25 | |
79072805 |
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 |
a0d0e21e |
30 | #define ORIGMARK (stack_base + origmark) |
79072805 |
31 | |
32 | #define SPAGAIN sp = stack_sp |
33 | #define MSPAGAIN sp = stack_sp; mark = ORIGMARK |
34 | |
35 | #define GETTARGETSTACKED targ = (op->op_flags & OPf_STACKED ? POPs : PAD_SV(op->op_targ)) |
36 | #define dTARGETSTACKED SV * GETTARGETSTACKED |
37 | |
38 | #define GETTARGET targ = PAD_SV(op->op_targ) |
39 | #define dTARGET SV * GETTARGET |
40 | |
41 | #define GETATARGET targ = (op->op_flags & OPf_STACKED ? sp[-1] : PAD_SV(op->op_targ)) |
42 | #define dATARGET SV * GETATARGET |
43 | |
44 | #define dTARG SV *targ |
45 | |
79072805 |
46 | #define NORMAL op->op_next |
47 | #define DIE return die |
79072805 |
48 | |
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 |
53 | |
54 | #define POPs (*sp--) |
463ee0b2 |
55 | #define POPp (SvPVx(POPs, na)) |
56 | #define POPn (SvNVx(POPs)) |
a0d0e21e |
57 | #define POPi ((IV)SvIVx(POPs)) |
ff68c719 |
58 | #define POPu ((UV)SvUVx(POPs)) |
463ee0b2 |
59 | #define POPl ((long)SvIVx(POPs)) |
79072805 |
60 | |
61 | #define TOPs (*sp) |
463ee0b2 |
62 | #define TOPp (SvPV(TOPs, na)) |
63 | #define TOPn (SvNV(TOPs)) |
a0d0e21e |
64 | #define TOPi ((IV)SvIV(TOPs)) |
ff68c719 |
65 | #define TOPu ((UV)SvUV(TOPs)) |
463ee0b2 |
66 | #define TOPl ((long)SvIV(TOPs)) |
79072805 |
67 | |
68 | /* Go to some pains in the rare event that we must extend the stack. */ |
bbce6d69 |
69 | #define EXTEND(p,n) STMT_START { if (stack_max - p < (n)) { \ |
70 | sp = stack_grow(sp,p, (int) (n)); \ |
86547924 |
71 | } } STMT_END |
a0d0e21e |
72 | |
79072805 |
73 | /* Same thing, but update mark register too. */ |
bbce6d69 |
74 | #define MEXTEND(p,n) STMT_START {if (stack_max - p < (n)) { \ |
75 | int markoff = mark - stack_base; \ |
76 | sp = stack_grow(sp,p,(int) (n)); \ |
77 | mark = stack_base + markoff; \ |
86547924 |
78 | } } STMT_END |
79072805 |
79 | |
80 | #define PUSHs(s) (*++sp = (s)) |
86547924 |
81 | #define PUSHTARG STMT_START { SvSETMAGIC(TARG); PUSHs(TARG); } STMT_END |
82 | #define PUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); PUSHTARG; } STMT_END |
83 | #define PUSHn(n) STMT_START { sv_setnv(TARG, (double)(n)); PUSHTARG; } STMT_END |
84 | #define PUSHi(i) STMT_START { sv_setiv(TARG, (IV)(i)); PUSHTARG; } STMT_END |
55497cff |
85 | #define PUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); PUSHTARG; } STMT_END |
79072805 |
86 | |
86547924 |
87 | #define XPUSHs(s) STMT_START { EXTEND(sp,1); (*++sp = (s)); } STMT_END |
88 | #define XPUSHTARG STMT_START { SvSETMAGIC(TARG); XPUSHs(TARG); } STMT_END |
89 | #define XPUSHp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); XPUSHTARG; } STMT_END |
90 | #define XPUSHn(n) STMT_START { sv_setnv(TARG, (double)(n)); XPUSHTARG; } STMT_END |
91 | #define XPUSHi(i) STMT_START { sv_setiv(TARG, (IV)(i)); XPUSHTARG; } STMT_END |
55497cff |
92 | #define XPUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); XPUSHTARG; } STMT_END |
79072805 |
93 | |
94 | #define SETs(s) (*sp = s) |
86547924 |
95 | #define SETTARG STMT_START { SvSETMAGIC(TARG); SETs(TARG); } STMT_END |
96 | #define SETp(p,l) STMT_START { sv_setpvn(TARG, (p), (l)); SETTARG; } STMT_END |
97 | #define SETn(n) STMT_START { sv_setnv(TARG, (double)(n)); SETTARG; } STMT_END |
98 | #define SETi(i) STMT_START { sv_setiv(TARG, (IV)(i)); SETTARG; } STMT_END |
55497cff |
99 | #define SETu(u) STMT_START { sv_setuv(TARG, (UV)(u)); SETTARG; } STMT_END |
a0d0e21e |
100 | |
79072805 |
101 | #define dTOPss SV *sv = TOPs |
102 | #define dPOPss SV *sv = POPs |
103 | #define dTOPnv double value = TOPn |
104 | #define dPOPnv double value = POPn |
a0d0e21e |
105 | #define dTOPiv IV value = TOPi |
106 | #define dPOPiv IV value = POPi |
55497cff |
107 | #define dTOPuv UV value = TOPu |
108 | #define dPOPuv UV value = POPu |
79072805 |
109 | |
7a4c00b4 |
110 | #define dPOPXssrl(X) SV *right = POPs; SV *left = CAT2(X,s) |
111 | #define dPOPXnnrl(X) double right = POPn; double left = CAT2(X,n) |
112 | #define dPOPXiirl(X) IV right = POPi; IV left = CAT2(X,i) |
113 | |
114 | #define USE_LEFT(sv) \ |
115 | (SvOK(sv) || SvGMAGICAL(sv) || !(op->op_flags & OPf_STACKED)) |
116 | #define dPOPXnnrl_ul(X) \ |
117 | double right = POPn; \ |
118 | SV *leftsv = CAT2(X,s); \ |
119 | double left = USE_LEFT(leftsv) ? SvNV(leftsv) : 0.0 |
120 | #define dPOPXiirl_ul(X) \ |
121 | IV right = POPi; \ |
122 | SV *leftsv = CAT2(X,s); \ |
123 | IV left = USE_LEFT(leftsv) ? SvIV(leftsv) : 0 |
124 | |
125 | #define dPOPPOPssrl dPOPXssrl(POP) |
126 | #define dPOPPOPnnrl dPOPXnnrl(POP) |
127 | #define dPOPPOPnnrl_ul dPOPXnnrl_ul(POP) |
128 | #define dPOPPOPiirl dPOPXiirl(POP) |
129 | #define dPOPPOPiirl_ul dPOPXiirl_ul(POP) |
130 | |
131 | #define dPOPTOPssrl dPOPXssrl(TOP) |
132 | #define dPOPTOPnnrl dPOPXnnrl(TOP) |
133 | #define dPOPTOPnnrl_ul dPOPXnnrl_ul(TOP) |
134 | #define dPOPTOPiirl dPOPXiirl(TOP) |
135 | #define dPOPTOPiirl_ul dPOPXiirl_ul(TOP) |
79072805 |
136 | |
137 | #define RETPUSHYES RETURNX(PUSHs(&sv_yes)) |
138 | #define RETPUSHNO RETURNX(PUSHs(&sv_no)) |
139 | #define RETPUSHUNDEF RETURNX(PUSHs(&sv_undef)) |
140 | |
141 | #define RETSETYES RETURNX(SETs(&sv_yes)) |
142 | #define RETSETNO RETURNX(SETs(&sv_no)) |
143 | #define RETSETUNDEF RETURNX(SETs(&sv_undef)) |
144 | |
145 | #define ARGTARG op->op_targ |
146 | #define MAXARG op->op_private |
147 | |
148 | #define SWITCHSTACK(f,t) AvFILL(f) = sp - stack_base; \ |
149 | stack_base = AvARRAY(t); \ |
150 | stack_max = stack_base + AvMAX(t); \ |
a0d0e21e |
151 | sp = stack_sp = stack_base + AvFILL(t); \ |
e9905555 |
152 | curstack = t; |
79072805 |
153 | |
bbce6d69 |
154 | #define EXTEND_MORTAL(n) \ |
155 | STMT_START { \ |
156 | if (tmps_ix + (n) >= tmps_max) \ |
157 | Renew(tmps_stack, tmps_max = tmps_ix + (n) + 1, SV*); \ |
158 | } STMT_END |
159 | |
a0d0e21e |
160 | #ifdef OVERLOAD |
161 | |
162 | #define AMGf_noright 1 |
163 | #define AMGf_noleft 2 |
164 | #define AMGf_assign 4 |
165 | #define AMGf_unary 8 |
166 | |
86547924 |
167 | #define tryAMAGICbinW(meth,assign,set) STMT_START { \ |
a0d0e21e |
168 | if (amagic_generation) { \ |
169 | SV* tmpsv; \ |
170 | SV* right= *(sp); SV* left= *(sp-1);\ |
171 | if ((SvAMAGIC(left)||SvAMAGIC(right))&&\ |
172 | (tmpsv=amagic_call(left, \ |
173 | right, \ |
174 | CAT2(meth,_amg), \ |
175 | (assign)? AMGf_assign: 0))) {\ |
176 | SPAGAIN; \ |
177 | (void)POPs; set(tmpsv); RETURN; } \ |
178 | } \ |
86547924 |
179 | } STMT_END |
a0d0e21e |
180 | |
181 | #define tryAMAGICbin(meth,assign) tryAMAGICbinW(meth,assign,SETsv) |
182 | #define tryAMAGICbinSET(meth,assign) tryAMAGICbinW(meth,assign,SETs) |
183 | |
184 | #define AMG_CALLun(sv,meth) amagic_call(sv,&sv_undef, \ |
185 | CAT2(meth,_amg),AMGf_noright | AMGf_unary) |
186 | #define AMG_CALLbinL(left,right,meth) \ |
187 | amagic_call(left,right,CAT2(meth,_amg),AMGf_noright) |
188 | |
86547924 |
189 | #define tryAMAGICunW(meth,set) STMT_START { \ |
a0d0e21e |
190 | if (amagic_generation) { \ |
191 | SV* tmpsv; \ |
192 | SV* arg= *(sp); \ |
193 | if ((SvAMAGIC(arg))&&\ |
194 | (tmpsv=AMG_CALLun(arg,meth))) {\ |
195 | SPAGAIN; \ |
196 | set(tmpsv); RETURN; } \ |
197 | } \ |
86547924 |
198 | } STMT_END |
a0d0e21e |
199 | |
e9905555 |
200 | #define tryAMAGICun tryAMAGICunSET |
a0d0e21e |
201 | #define tryAMAGICunSET(meth) tryAMAGICunW(meth,SETs) |
202 | |
203 | #define opASSIGN (op->op_flags & OPf_STACKED) |
e9905555 |
204 | #define SETsv(sv) STMT_START { \ |
205 | if (opASSIGN) { sv_setsv(TARG, (sv)); SETTARG; } \ |
206 | else SETs(sv); } STMT_END |
a0d0e21e |
207 | |
208 | /* newSVsv does not behave as advertised, so we copy missing |
209 | * information by hand */ |
210 | |
211 | |
86547924 |
212 | #define RvDEEPCP(rv) STMT_START { SV* ref=SvRV(rv); \ |
a0d0e21e |
213 | if (SvREFCNT(ref)>1) { \ |
214 | SvREFCNT_dec(ref); \ |
748a9306 |
215 | SvRV(rv)=AMG_CALLun(rv,copy); \ |
86547924 |
216 | } } STMT_END |
a0d0e21e |
217 | #else |
218 | |
219 | #define tryAMAGICbin(a,b) |
220 | #define tryAMAGICbinSET(a,b) |
221 | #define tryAMAGICun(a) |
222 | #define tryAMAGICunSET(a) |
223 | |
224 | #endif /* OVERLOAD */ |