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)) |
463ee0b2 |
58 | #define POPl ((long)SvIVx(POPs)) |
79072805 |
59 | |
60 | #define TOPs (*sp) |
463ee0b2 |
61 | #define TOPp (SvPV(TOPs, na)) |
62 | #define TOPn (SvNV(TOPs)) |
a0d0e21e |
63 | #define TOPi ((IV)SvIV(TOPs)) |
463ee0b2 |
64 | #define TOPl ((long)SvIV(TOPs)) |
79072805 |
65 | |
66 | /* Go to some pains in the rare event that we must extend the stack. */ |
86547924 |
67 | #define EXTEND(p,n) STMT_START { if (stack_max - p < (n)) { \ |
a0d0e21e |
68 | sp = stack_grow(sp,p, (int) (n)); \ |
86547924 |
69 | } } STMT_END |
a0d0e21e |
70 | |
79072805 |
71 | /* Same thing, but update mark register too. */ |
86547924 |
72 | #define MEXTEND(p,n) STMT_START {if (stack_max - p < (n)) { \ |
a0d0e21e |
73 | int markoff = mark - stack_base; \ |
74 | sp = stack_grow(sp,p,(int) (n)); \ |
75 | mark = stack_base + markoff; \ |
86547924 |
76 | } } STMT_END |
79072805 |
77 | |
78 | #define PUSHs(s) (*++sp = (s)) |
86547924 |
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 |
79072805 |
83 | |
86547924 |
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 |
79072805 |
89 | |
90 | #define SETs(s) (*sp = s) |
86547924 |
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 |
a0d0e21e |
95 | |
96 | #ifdef OVERLOAD |
86547924 |
97 | #define SETsv(sv) STMT_START { sv_setsv(TARG, (sv)); SETTARG; } STMT_END |
a0d0e21e |
98 | #endif /* OVERLOAD */ |
79072805 |
99 | |
100 | #define dTOPss SV *sv = TOPs |
101 | #define dPOPss SV *sv = POPs |
102 | #define dTOPnv double value = TOPn |
103 | #define dPOPnv double value = POPn |
a0d0e21e |
104 | #define dTOPiv IV value = TOPi |
105 | #define dPOPiv IV value = POPi |
79072805 |
106 | |
a0d0e21e |
107 | #define dPOPPOPssrl SV *right = POPs; SV *left = POPs |
79072805 |
108 | #define dPOPPOPnnrl double right = POPn; double left = POPn |
a0d0e21e |
109 | #define dPOPPOPiirl IV right = POPi; IV left = POPi |
79072805 |
110 | |
a0d0e21e |
111 | #define dPOPTOPssrl SV *right = POPs; SV *left = TOPs |
79072805 |
112 | #define dPOPTOPnnrl double right = POPn; double left = TOPn |
a0d0e21e |
113 | #define dPOPTOPiirl IV right = POPi; IV left = TOPi |
79072805 |
114 | |
115 | #define RETPUSHYES RETURNX(PUSHs(&sv_yes)) |
116 | #define RETPUSHNO RETURNX(PUSHs(&sv_no)) |
117 | #define RETPUSHUNDEF RETURNX(PUSHs(&sv_undef)) |
118 | |
119 | #define RETSETYES RETURNX(SETs(&sv_yes)) |
120 | #define RETSETNO RETURNX(SETs(&sv_no)) |
121 | #define RETSETUNDEF RETURNX(SETs(&sv_undef)) |
122 | |
123 | #define ARGTARG op->op_targ |
124 | #define MAXARG op->op_private |
125 | |
126 | #define SWITCHSTACK(f,t) AvFILL(f) = sp - stack_base; \ |
127 | stack_base = AvARRAY(t); \ |
128 | stack_max = stack_base + AvMAX(t); \ |
a0d0e21e |
129 | sp = stack_sp = stack_base + AvFILL(t); \ |
79072805 |
130 | stack = t; |
131 | |
a0d0e21e |
132 | #ifdef OVERLOAD |
133 | |
134 | #define AMGf_noright 1 |
135 | #define AMGf_noleft 2 |
136 | #define AMGf_assign 4 |
137 | #define AMGf_unary 8 |
138 | |
86547924 |
139 | #define tryAMAGICbinW(meth,assign,set) STMT_START { \ |
a0d0e21e |
140 | if (amagic_generation) { \ |
141 | SV* tmpsv; \ |
142 | SV* right= *(sp); SV* left= *(sp-1);\ |
143 | if ((SvAMAGIC(left)||SvAMAGIC(right))&&\ |
144 | (tmpsv=amagic_call(left, \ |
145 | right, \ |
146 | CAT2(meth,_amg), \ |
147 | (assign)? AMGf_assign: 0))) {\ |
148 | SPAGAIN; \ |
149 | (void)POPs; set(tmpsv); RETURN; } \ |
150 | } \ |
86547924 |
151 | } STMT_END |
a0d0e21e |
152 | |
153 | #define tryAMAGICbin(meth,assign) tryAMAGICbinW(meth,assign,SETsv) |
154 | #define tryAMAGICbinSET(meth,assign) tryAMAGICbinW(meth,assign,SETs) |
155 | |
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) |
160 | |
86547924 |
161 | #define tryAMAGICunW(meth,set) STMT_START { \ |
a0d0e21e |
162 | if (amagic_generation) { \ |
163 | SV* tmpsv; \ |
164 | SV* arg= *(sp); \ |
165 | if ((SvAMAGIC(arg))&&\ |
166 | (tmpsv=AMG_CALLun(arg,meth))) {\ |
167 | SPAGAIN; \ |
168 | set(tmpsv); RETURN; } \ |
169 | } \ |
86547924 |
170 | } STMT_END |
a0d0e21e |
171 | |
172 | #define tryAMAGICun(meth) tryAMAGICunW(meth,SETsv) |
173 | #define tryAMAGICunSET(meth) tryAMAGICunW(meth,SETs) |
174 | |
175 | #define opASSIGN (op->op_flags & OPf_STACKED) |
176 | |
177 | /* newSVsv does not behave as advertised, so we copy missing |
178 | * information by hand */ |
179 | |
180 | |
86547924 |
181 | #define RvDEEPCP(rv) STMT_START { SV* ref=SvRV(rv); \ |
a0d0e21e |
182 | if (SvREFCNT(ref)>1) { \ |
183 | SvREFCNT_dec(ref); \ |
748a9306 |
184 | SvRV(rv)=AMG_CALLun(rv,copy); \ |
86547924 |
185 | } } STMT_END |
a0d0e21e |
186 | #else |
187 | |
188 | #define tryAMAGICbin(a,b) |
189 | #define tryAMAGICbinSET(a,b) |
190 | #define tryAMAGICun(a) |
191 | #define tryAMAGICunSET(a) |
192 | |
193 | #endif /* OVERLOAD */ |