avoid creating new files during make install
[p5sagit/p5-mst-13.2.git] / pp.h
1 /*    pp.h
2  *
3  *    Copyright (c) 1991-1999, Larry Wall
4  *
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.
7  *
8  */
9
10 #ifdef USE_THREADS
11 #define ARGS thr
12 #define dARGS struct perl_thread *thr;
13 #else
14 #define ARGS
15 #define dARGS
16 #endif /* USE_THREADS */
17
18 #define PP(s) OP * Perl_##s(pTHX)
19
20 #define SP sp
21 #define MARK mark
22 #define TARG targ
23
24 #define PUSHMARK(p) if (++PL_markstack_ptr == PL_markstack_max) \
25                         markstack_grow();                       \
26                     *PL_markstack_ptr = (p) - PL_stack_base
27
28 #define TOPMARK         (*PL_markstack_ptr)
29 #define POPMARK         (*PL_markstack_ptr--)
30
31 #define djSP            register SV **sp = PL_stack_sp
32 #define dSP             dTHR; djSP
33 #define dMARK           register SV **mark = PL_stack_base + POPMARK
34 #define dORIGMARK       I32 origmark = mark - PL_stack_base
35 #define SETORIGMARK     origmark = mark - PL_stack_base
36 #define ORIGMARK        (PL_stack_base + origmark)
37
38 #define SPAGAIN         sp = PL_stack_sp
39 #define MSPAGAIN        sp = PL_stack_sp; mark = ORIGMARK
40
41 #define GETTARGETSTACKED targ = (PL_op->op_flags & OPf_STACKED ? POPs : PAD_SV(PL_op->op_targ))
42 #define dTARGETSTACKED SV * GETTARGETSTACKED
43
44 #define GETTARGET targ = PAD_SV(PL_op->op_targ)
45 #define dTARGET SV * GETTARGET
46
47 #define GETATARGET targ = (PL_op->op_flags & OPf_STACKED ? sp[-1] : PAD_SV(PL_op->op_targ))
48 #define dATARGET SV * GETATARGET
49
50 #define dTARG SV *targ
51
52 #define NORMAL PL_op->op_next
53 #define DIE return Perl_die
54
55 #define PUTBACK         PL_stack_sp = sp
56 #define RETURN          return PUTBACK, NORMAL
57 #define RETURNOP(o)     return PUTBACK, o
58 #define RETURNX(x)      return x, PUTBACK, NORMAL
59
60 #define POPs            (*sp--)
61 #define POPp            (SvPVx(POPs, PL_na))            /* deprecated */
62 #define POPpx           (SvPVx(POPs, n_a))
63 #define POPn            (SvNVx(POPs))
64 #define POPi            ((IV)SvIVx(POPs))
65 #define POPu            ((UV)SvUVx(POPs))
66 #define POPl            ((long)SvIVx(POPs))
67 #define POPul           ((unsigned long)SvIVx(POPs))
68 #ifdef HAS_QUAD
69 #define POPq            ((Quad_t)SvIVx(POPs))
70 #define POPuq           ((Uquad_t)SvUVx(POPs))
71 #endif
72
73 #define TOPs            (*sp)
74 #define TOPp            (SvPV(TOPs, PL_na))             /* deprecated */
75 #define TOPpx           (SvPV(TOPs, n_a))
76 #define TOPn            (SvNV(TOPs))
77 #define TOPi            ((IV)SvIV(TOPs))
78 #define TOPu            ((UV)SvUV(TOPs))
79 #define TOPl            ((long)SvIV(TOPs))
80 #define TOPul           ((unsigned long)SvUV(TOPs))
81 #ifdef HAS_QUAD
82 #define TOPq            ((Quad_t)SvIV(TOPs))
83 #define TOPuq           ((Uquad_t)SvUV(TOPs))
84 #endif
85
86 /* Go to some pains in the rare event that we must extend the stack. */
87 #define EXTEND(p,n)     STMT_START { if (PL_stack_max - p < (n)) {              \
88                             sp = stack_grow(sp,p, (int) (n));           \
89                         } } STMT_END
90
91 /* Same thing, but update mark register too. */
92 #define MEXTEND(p,n)    STMT_START {if (PL_stack_max - p < (n)) {               \
93                             int markoff = mark - PL_stack_base;         \
94                             sp = stack_grow(sp,p,(int) (n));            \
95                             mark = PL_stack_base + markoff;             \
96                         } } STMT_END
97
98 #define PUSHs(s)        (*++sp = (s))
99 #define PUSHTARG        STMT_START { SvSETMAGIC(TARG); PUSHs(TARG); } STMT_END
100 #define PUSHp(p,l)      STMT_START { sv_setpvn(TARG, (p), (l)); PUSHTARG; } STMT_END
101 #define PUSHn(n)        STMT_START { sv_setnv(TARG, (NV)(n)); PUSHTARG; } STMT_END
102 #define PUSHi(i)        STMT_START { sv_setiv(TARG, (IV)(i)); PUSHTARG; } STMT_END
103 #define PUSHu(u)        STMT_START { sv_setuv(TARG, (UV)(u)); PUSHTARG; } STMT_END
104
105 #define XPUSHs(s)       STMT_START { EXTEND(sp,1); (*++sp = (s)); } STMT_END
106 #define XPUSHTARG       STMT_START { SvSETMAGIC(TARG); XPUSHs(TARG); } STMT_END
107 #define XPUSHp(p,l)     STMT_START { sv_setpvn(TARG, (p), (l)); XPUSHTARG; } STMT_END
108 #define XPUSHn(n)       STMT_START { sv_setnv(TARG, (NV)(n)); XPUSHTARG; } STMT_END
109 #define XPUSHi(i)       STMT_START { sv_setiv(TARG, (IV)(i)); XPUSHTARG; } STMT_END
110 #define XPUSHu(u)       STMT_START { sv_setuv(TARG, (UV)(u)); XPUSHTARG; } STMT_END
111 #define XPUSHundef      STMT_START { SvOK_off(TARG); XPUSHs(TARG); } STMT_END
112
113 #define SETs(s)         (*sp = s)
114 #define SETTARG         STMT_START { SvSETMAGIC(TARG); SETs(TARG); } STMT_END
115 #define SETp(p,l)       STMT_START { sv_setpvn(TARG, (p), (l)); SETTARG; } STMT_END
116 #define SETn(n)         STMT_START { sv_setnv(TARG, (NV)(n)); SETTARG; } STMT_END
117 #define SETi(i)         STMT_START { sv_setiv(TARG, (IV)(i)); SETTARG; } STMT_END
118 #define SETu(u)         STMT_START { sv_setuv(TARG, (UV)(u)); SETTARG; } STMT_END
119
120 #define dTOPss          SV *sv = TOPs
121 #define dPOPss          SV *sv = POPs
122 #define dTOPnv          NV value = TOPn
123 #define dPOPnv          NV value = POPn
124 #define dTOPiv          IV value = TOPi
125 #define dPOPiv          IV value = POPi
126 #define dTOPuv          UV value = TOPu
127 #define dPOPuv          UV value = POPu
128 #ifdef HAS_QUAD
129 #define dTOPqv          Quad_t value = TOPu
130 #define dPOPqv          Quad_t value = POPu
131 #define dTOPuqv         Uquad_t value = TOPuq
132 #define dPOPuqv         Uquad_t value = POPuq
133 #endif
134
135 #define dPOPXssrl(X)    SV *right = POPs; SV *left = CAT2(X,s)
136 #define dPOPXnnrl(X)    NV right = POPn; NV left = CAT2(X,n)
137 #define dPOPXiirl(X)    IV right = POPi; IV left = CAT2(X,i)
138
139 #define USE_LEFT(sv) \
140         (SvOK(sv) || SvGMAGICAL(sv) || !(PL_op->op_flags & OPf_STACKED))
141 #define dPOPXnnrl_ul(X) \
142     NV right = POPn;                            \
143     SV *leftsv = CAT2(X,s);                             \
144     NV left = USE_LEFT(leftsv) ? SvNV(leftsv) : 0.0
145 #define dPOPXiirl_ul(X) \
146     IV right = POPi;                                    \
147     SV *leftsv = CAT2(X,s);                             \
148     IV left = USE_LEFT(leftsv) ? SvIV(leftsv) : 0
149
150 #define dPOPPOPssrl     dPOPXssrl(POP)
151 #define dPOPPOPnnrl     dPOPXnnrl(POP)
152 #define dPOPPOPnnrl_ul  dPOPXnnrl_ul(POP)
153 #define dPOPPOPiirl     dPOPXiirl(POP)
154 #define dPOPPOPiirl_ul  dPOPXiirl_ul(POP)
155
156 #define dPOPTOPssrl     dPOPXssrl(TOP)
157 #define dPOPTOPnnrl     dPOPXnnrl(TOP)
158 #define dPOPTOPnnrl_ul  dPOPXnnrl_ul(TOP)
159 #define dPOPTOPiirl     dPOPXiirl(TOP)
160 #define dPOPTOPiirl_ul  dPOPXiirl_ul(TOP)
161
162 #define RETPUSHYES      RETURNX(PUSHs(&PL_sv_yes))
163 #define RETPUSHNO       RETURNX(PUSHs(&PL_sv_no))
164 #define RETPUSHUNDEF    RETURNX(PUSHs(&PL_sv_undef))
165
166 #define RETSETYES       RETURNX(SETs(&PL_sv_yes))
167 #define RETSETNO        RETURNX(SETs(&PL_sv_no))
168 #define RETSETUNDEF     RETURNX(SETs(&PL_sv_undef))
169
170 #define ARGTARG         PL_op->op_targ
171
172     /* See OPpTARGET_MY: */
173 #define MAXARG          (PL_op->op_private & 15)
174
175 #define SWITCHSTACK(f,t) \
176     STMT_START {                                                        \
177         AvFILLp(f) = sp - PL_stack_base;                                \
178         PL_stack_base = AvARRAY(t);                                     \
179         PL_stack_max = PL_stack_base + AvMAX(t);                        \
180         sp = PL_stack_sp = PL_stack_base + AvFILLp(t);                  \
181         PL_curstack = t;                                                \
182     } STMT_END
183
184 #define EXTEND_MORTAL(n) \
185     STMT_START {                                                        \
186         if (PL_tmps_ix + (n) >= PL_tmps_max)                            \
187             tmps_grow(n);                                               \
188     } STMT_END
189
190 #define AMGf_noright    1
191 #define AMGf_noleft     2
192 #define AMGf_assign     4
193 #define AMGf_unary      8
194
195 #define tryAMAGICbinW(meth,assign,set) STMT_START { \
196           if (PL_amagic_generation) { \
197             SV* tmpsv; \
198             SV* right= *(sp); SV* left= *(sp-1);\
199             if ((SvAMAGIC(left)||SvAMAGIC(right))&&\
200                 (tmpsv=amagic_call(left, \
201                                    right, \
202                                    CAT2(meth,_amg), \
203                                    (assign)? AMGf_assign: 0))) {\
204                SPAGAIN; \
205                (void)POPs; set(tmpsv); RETURN; } \
206           } \
207         } STMT_END
208
209 #define tryAMAGICbin(meth,assign) tryAMAGICbinW(meth,assign,SETsv)
210 #define tryAMAGICbinSET(meth,assign) tryAMAGICbinW(meth,assign,SETs)
211
212 #define AMG_CALLun(sv,meth) amagic_call(sv,&PL_sv_undef,  \
213                                         CAT2(meth,_amg),AMGf_noright | AMGf_unary)
214 #define AMG_CALLbinL(left,right,meth) \
215             amagic_call(left,right,CAT2(meth,_amg),AMGf_noright)
216
217 #define tryAMAGICunW(meth,set,shift,ret) STMT_START { \
218           if (PL_amagic_generation) { \
219             SV* tmpsv; \
220             SV* arg= sp[shift]; \
221           am_again: \
222             if ((SvAMAGIC(arg))&&\
223                 (tmpsv=AMG_CALLun(arg,meth))) {\
224                SPAGAIN; if (shift) sp += shift; \
225                set(tmpsv); ret; } \
226           } \
227         } STMT_END
228
229 #define FORCE_SETs(sv) STMT_START { sv_setsv(TARG, (sv)); SETTARG; } STMT_END
230
231 #define tryAMAGICun(meth)       tryAMAGICunW(meth,SETsvUN,0,RETURN)
232 #define tryAMAGICunSET(meth)    tryAMAGICunW(meth,SETs,0,RETURN)
233 #define tryAMAGICunTARGET(meth, shift)                                  \
234         { dSP; sp--;    /* get TARGET from below PL_stack_sp */         \
235             { dTARGETSTACKED;                                           \
236                 { dSP; tryAMAGICunW(meth,FORCE_SETs,shift,RETURN);}}}
237
238 #define setAGAIN(ref) sv = arg = ref;                                   \
239   if (!SvROK(ref))                                                      \
240       Perl_croak(aTHX_ "Overloaded dereference did not return a reference");    \
241   goto am_again;
242
243 #define tryAMAGICunDEREF(meth) tryAMAGICunW(meth,setAGAIN,0,(void)0)
244
245 #define opASSIGN (PL_op->op_flags & OPf_STACKED)
246 #define SETsv(sv)       STMT_START {                                    \
247                 if (opASSIGN || (SvFLAGS(TARG) & SVs_PADMY))            \
248                    { sv_setsv(TARG, (sv)); SETTARG; }                   \
249                 else SETs(sv); } STMT_END
250
251 #define SETsvUN(sv)     STMT_START {                                    \
252                 if (SvFLAGS(TARG) & SVs_PADMY)          \
253                    { sv_setsv(TARG, (sv)); SETTARG; }                   \
254                 else SETs(sv); } STMT_END
255
256 /* newSVsv does not behave as advertised, so we copy missing
257  * information by hand */
258
259 /* SV* ref causes confusion with the member variable
260    changed SV* ref to SV* tmpRef */
261 #define RvDEEPCP(rv) STMT_START { SV* tmpRef=SvRV(rv);      \
262   if (SvREFCNT(tmpRef)>1) {                 \
263     SvREFCNT_dec(tmpRef);                   \
264     SvRV(rv)=AMG_CALLun(rv,copy);        \
265   } } STMT_END