Allow MakeMaker 5.34 to use libraries containing '+' in name
[p5sagit/p5-mst-13.2.git] / cop.h
1 /*    cop.h
2  *
3  *    Copyright (c) 1991-1994, 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 struct cop {
11     BASEOP
12     char *      cop_label;      /* label for this construct */
13     HV *        cop_stash;      /* package line was compiled in */
14     GV *        cop_filegv;     /* file the following line # is from */
15     U32         cop_seq;        /* parse sequence number */
16     I32         cop_arybase;    /* array base this line was compiled with */
17     line_t      cop_line;       /* line # of this command */
18 };
19
20 #define Nullcop Null(COP*)
21
22 /*
23  * Here we have some enormously heavy (or at least ponderous) wizardry.
24  */
25
26 /* subroutine context */
27 struct block_sub {
28     CV *        cv;
29     GV *        gv;
30     GV *        dfoutgv;
31     AV *        savearray;
32     AV *        argarray;
33     U16         olddepth;
34     U8          hasargs;
35 };
36
37 #define PUSHSUB(cx)                                                     \
38         cx->blk_sub.cv = cv;                                            \
39         cx->blk_sub.olddepth = CvDEPTH(cv);                             \
40         cx->blk_sub.hasargs = hasargs;
41
42 #define PUSHFORMAT(cx)                                                  \
43         cx->blk_sub.cv = cv;                                            \
44         cx->blk_sub.gv = gv;                                            \
45         cx->blk_sub.hasargs = 0;                                        \
46         cx->blk_sub.dfoutgv = defoutgv;                                 \
47         (void)SvREFCNT_inc(cx->blk_sub.dfoutgv)
48
49 /* We muck with cxstack_ix since _dec may call a DESTROY, overwriting cx. */
50
51 #define POPSUB(cx)                                                      \
52         if (cx->blk_sub.hasargs) {   /* put back old @_ */              \
53             SvREFCNT_dec(GvAV(defgv));                                  \
54             GvAV(defgv) = cx->blk_sub.savearray;                        \
55         }                                                               \
56         if (cx->blk_sub.cv) {                                           \
57             if (!(CvDEPTH(cx->blk_sub.cv) = cx->blk_sub.olddepth)) {    \
58                 cxstack_ix++;                                           \
59                 SvREFCNT_dec((SV*)cx->blk_sub.cv);                      \
60                 cxstack_ix--;                                           \
61             }                                                           \
62         }
63
64 #define POPFORMAT(cx)                                                   \
65         setdefout(cx->blk_sub.dfoutgv);                                 \
66         SvREFCNT_dec(cx->blk_sub.dfoutgv);
67
68 /* eval context */
69 struct block_eval {
70     I32         old_in_eval;
71     I32         old_op_type;
72     char *      old_name;
73     OP *        old_eval_root;
74     SV *        cur_text;
75 };
76
77 #define PUSHEVAL(cx,n,fgv)                                              \
78         cx->blk_eval.old_in_eval = in_eval;                             \
79         cx->blk_eval.old_op_type = op->op_type;                         \
80         cx->blk_eval.old_name = n;                                      \
81         cx->blk_eval.old_eval_root = eval_root;                         \
82         cx->blk_eval.cur_text = linestr;
83
84 #define POPEVAL(cx)                                                     \
85         in_eval = cx->blk_eval.old_in_eval;                             \
86         optype = cx->blk_eval.old_op_type;                              \
87         eval_root = cx->blk_eval.old_eval_root;
88
89 /* loop context */
90 struct block_loop {
91     char *      label;
92     I32         resetsp;
93     OP *        redo_op;
94     OP *        next_op;
95     OP *        last_op;
96     SV **       itervar;
97     SV *        itersave;
98     SV *        iterlval;
99     AV *        iterary;
100     I32         iterix;
101 };
102
103 #define PUSHLOOP(cx, ivar, s)                                           \
104         cx->blk_loop.label = curcop->cop_label;                         \
105         cx->blk_loop.resetsp = s - stack_base;                          \
106         cx->blk_loop.redo_op = cLOOP->op_redoop;                        \
107         cx->blk_loop.next_op = cLOOP->op_nextop;                        \
108         cx->blk_loop.last_op = cLOOP->op_lastop;                        \
109         if (cx->blk_loop.itervar = (ivar))                              \
110             cx->blk_loop.itersave = SvREFCNT_inc(*cx->blk_loop.itervar);\
111         cx->blk_loop.iterlval = Nullsv;                                 \
112         cx->blk_loop.iterary = Nullav;                                  \
113         cx->blk_loop.iterix = -1;
114
115 #define POPLOOP(cx)                                                     \
116         newsp           = stack_base + cx->blk_loop.resetsp;            \
117         SvREFCNT_dec(cx->blk_loop.iterlval);                            \
118         if (cx->blk_loop.itervar) {                                     \
119             SvREFCNT_dec(*cx->blk_loop.itervar);                        \
120             *cx->blk_loop.itervar = cx->blk_loop.itersave;              \
121         }                                                               \
122         if (cx->blk_loop.iterary && cx->blk_loop.iterary != curstack)   \
123             SvREFCNT_dec(cx->blk_loop.iterary);
124
125 /* context common to subroutines, evals and loops */
126 struct block {
127     I32         blku_oldsp;     /* stack pointer to copy stuff down to */
128     COP *       blku_oldcop;    /* old curcop pointer */
129     I32         blku_oldretsp;  /* return stack index */
130     I32         blku_oldmarksp; /* mark stack index */
131     I32         blku_oldscopesp;        /* scope stack index */
132     PMOP *      blku_oldpm;     /* values of pattern match vars */
133     U8          blku_gimme;     /* is this block running in list context? */
134
135     union {
136         struct block_sub        blku_sub;
137         struct block_eval       blku_eval;
138         struct block_loop       blku_loop;
139     } blk_u;
140 };
141 #define blk_oldsp       cx_u.cx_blk.blku_oldsp
142 #define blk_oldcop      cx_u.cx_blk.blku_oldcop
143 #define blk_oldretsp    cx_u.cx_blk.blku_oldretsp
144 #define blk_oldmarksp   cx_u.cx_blk.blku_oldmarksp
145 #define blk_oldscopesp  cx_u.cx_blk.blku_oldscopesp
146 #define blk_oldpm       cx_u.cx_blk.blku_oldpm
147 #define blk_gimme       cx_u.cx_blk.blku_gimme
148 #define blk_sub         cx_u.cx_blk.blk_u.blku_sub
149 #define blk_eval        cx_u.cx_blk.blk_u.blku_eval
150 #define blk_loop        cx_u.cx_blk.blk_u.blku_loop
151
152 /* Enter a block. */
153 #define PUSHBLOCK(cx,t,sp) CXINC, cx = &cxstack[cxstack_ix],            \
154         cx->cx_type             = t,                                    \
155         cx->blk_oldsp           = sp - stack_base,                      \
156         cx->blk_oldcop          = curcop,                               \
157         cx->blk_oldmarksp       = markstack_ptr - markstack,            \
158         cx->blk_oldscopesp      = scopestack_ix,                        \
159         cx->blk_oldretsp        = retstack_ix,                          \
160         cx->blk_oldpm           = curpm,                                \
161         cx->blk_gimme           = gimme;                                \
162         DEBUG_l( PerlIO_printf(PerlIO_stderr(), "Entering block %ld, type %s\n",        \
163                     (long)cxstack_ix, block_type[t]); )
164
165 /* Exit a block (RETURN and LAST). */
166 #define POPBLOCK(cx,pm) cx = &cxstack[cxstack_ix--],                    \
167         newsp           = stack_base + cx->blk_oldsp,                   \
168         curcop          = cx->blk_oldcop,                               \
169         markstack_ptr   = markstack + cx->blk_oldmarksp,                \
170         scopestack_ix   = cx->blk_oldscopesp,                           \
171         retstack_ix     = cx->blk_oldretsp,                             \
172         pm              = cx->blk_oldpm,                                \
173         gimme           = cx->blk_gimme;                                \
174         DEBUG_l( PerlIO_printf(PerlIO_stderr(), "Leaving block %ld, type %s\n",         \
175                     (long)cxstack_ix+1,block_type[cx->cx_type]); )
176
177 /* Continue a block elsewhere (NEXT and REDO). */
178 #define TOPBLOCK(cx) cx = &cxstack[cxstack_ix],                         \
179         stack_sp        = stack_base + cx->blk_oldsp,                   \
180         markstack_ptr   = markstack + cx->blk_oldmarksp,                \
181         scopestack_ix   = cx->blk_oldscopesp,                           \
182         retstack_ix     = cx->blk_oldretsp
183
184 /* substitution context */
185 struct subst {
186     I32         sbu_iters;
187     I32         sbu_maxiters;
188     I32         sbu_safebase;
189     I32         sbu_oldsave;
190     bool        sbu_once;
191     bool        sbu_rxtainted;
192     char *      sbu_orig;
193     SV *        sbu_dstr;
194     SV *        sbu_targ;
195     char *      sbu_s;
196     char *      sbu_m;
197     char *      sbu_strend;
198     char *      sbu_subbase;
199     REGEXP *    sbu_rx;
200 };
201 #define sb_iters        cx_u.cx_subst.sbu_iters
202 #define sb_maxiters     cx_u.cx_subst.sbu_maxiters
203 #define sb_safebase     cx_u.cx_subst.sbu_safebase
204 #define sb_oldsave      cx_u.cx_subst.sbu_oldsave
205 #define sb_once         cx_u.cx_subst.sbu_once
206 #define sb_rxtainted    cx_u.cx_subst.sbu_rxtainted
207 #define sb_orig         cx_u.cx_subst.sbu_orig
208 #define sb_dstr         cx_u.cx_subst.sbu_dstr
209 #define sb_targ         cx_u.cx_subst.sbu_targ
210 #define sb_s            cx_u.cx_subst.sbu_s
211 #define sb_m            cx_u.cx_subst.sbu_m
212 #define sb_strend       cx_u.cx_subst.sbu_strend
213 #define sb_subbase      cx_u.cx_subst.sbu_subbase
214 #define sb_rx           cx_u.cx_subst.sbu_rx
215
216 #define PUSHSUBST(cx) CXINC, cx = &cxstack[cxstack_ix],                 \
217         cx->sb_iters            = iters,                                \
218         cx->sb_maxiters         = maxiters,                             \
219         cx->sb_safebase         = safebase,                             \
220         cx->sb_oldsave          = oldsave,                              \
221         cx->sb_once             = once,                                 \
222         cx->sb_rxtainted        = rxtainted,                            \
223         cx->sb_orig             = orig,                                 \
224         cx->sb_dstr             = dstr,                                 \
225         cx->sb_targ             = targ,                                 \
226         cx->sb_s                = s,                                    \
227         cx->sb_m                = m,                                    \
228         cx->sb_strend           = strend,                               \
229         cx->sb_rx               = rx,                                   \
230         cx->cx_type             = CXt_SUBST
231
232 #define POPSUBST(cx) cxstack_ix--
233
234 struct context {
235     I32         cx_type;        /* what kind of context this is */
236     union {
237         struct block    cx_blk;
238         struct subst    cx_subst;
239     } cx_u;
240 };
241 #define CXt_NULL        0
242 #define CXt_SUB         1
243 #define CXt_EVAL        2
244 #define CXt_LOOP        3
245 #define CXt_SUBST       4
246 #define CXt_BLOCK       5
247
248 #define CXINC (cxstack_ix < cxstack_max ? ++cxstack_ix : (cxstack_ix = cxinc()))
249
250 /* "gimme" values */
251 #define G_SCALAR        0
252 #define G_ARRAY         1
253
254 /* extra flags for perl_call_* routines */
255 #define G_DISCARD       2       /* Call FREETMPS. */
256 #define G_EVAL          4       /* Assume eval {} around subroutine call. */
257 #define G_NOARGS        8       /* Don't construct a @_ array. */
258 #define G_KEEPERR      16       /* Append errors to $@ rather than overwriting it */