This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 5.0 alpha 2
[perl5.git] / op.h
CommitLineData
79072805
LW
1/* $RCSfile: arg.h,v $$Revision: 4.1 $$Date: 92/08/07 17:18:16 $
2 *
3 * Copyright (c) 1991, 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 * $Log: arg.h,v $
9 */
10
11/*
12 * The fields of BASEOP are:
13 * op_next Pointer to next ppcode to execute after this one.
14 * (Top level pre-grafted op points to first op,
15 * but this is replaced when op is grafted in, when
16 * this op will point to the real next op, and the new
17 * parent takes over role of remembering starting op.)
18 * op_ppaddr Pointer to current ppcode's function.
19 * op_type The type of the operation.
20 * op_flags Flags common to all operations. See OPf_* below.
21 * op_private Flags peculiar to a particular operation (BUT,
22 * by default, set to the number of children until
23 * the operation is privatized by a check routine,
24 * which may or may not check number of children).
25 */
26
27typedef U16 PADOFFSET;
28
29#ifdef DEBUGGING
30#define OPCODE opcode
31#else
32#define OPCODE U16
33#endif
34
35#define BASEOP \
36 OP* op_next; \
37 OP* op_sibling; \
38 OP* (*op_ppaddr)(); \
39 PADOFFSET op_targ; \
40 OPCODE op_type; \
41 U16 op_seq; \
42 char op_flags; \
43 char op_private;
44
45#define GIMME (op->op_flags & OPf_KNOW ? op->op_flags & OPf_LIST : getgimme(op))
46
47/* Public flags */
48#define OPf_LIST 1 /* Do operator in list context. */
49#define OPf_KNOW 2 /* Context is known. */
50#define OPf_KIDS 4 /* There is a firstborn child. */
51#define OPf_PARENS 8 /* This operator was parenthesized. */
52#define OPf_STACKED 16 /* Some arg is arriving on the stack. */
53#define OPf_LVAL 32 /* Certified reference (lvalue). */
54#define OPf_LOCAL 64 /* Lvalue must be localized */
55#define OPf_SPECIAL 128 /* Do something weird for this op: */
56 /* On local LVAL, don't init local value. */
57 /* On OP_SORT, subroutine is inlined. */
58 /* On OP_NOT, inversion was implicit. */
59 /* On file tests, we fstat filehandle */
60 /* On truncate, we truncate filehandle */
61 /* On control verbs, we saw no label */
62 /* On flipflop, we saw ... instead of .. */
63 /* On UNOPs, saw bare parens, e.g. eof(). */
64 /* On OP_ENTERSUBR || OP_NULL, saw a "do". */
65
66/* Private for OP_ASSIGN */
67#define OPpASSIGN_COMMON 1 /* Left & right have syms in common. */
68
69/* Private for OP_TRANS */
70#define OPpTRANS_SQUASH 1
71#define OPpTRANS_DELETE 2
72#define OPpTRANS_COMPLEMENT 4
73
74/* Private for OP_REPEAT */
75#define OPpREPEAT_DOLIST 1 /* List replication. */
76
77/* Private for OP_SUBR */
78#define OPpSUBR_DB 1 /* Debug subroutine. */
79
80/* Private for OP_CONST */
81#define OPpCONST_BARE 1 /* Was a bare word (filehandle?). */
82
83/* Private for OP_FLIP/FLOP */
84#define OPpFLIP_LINENUM 1 /* Range arg potentially a line num. */
85
86struct op {
87 BASEOP
88};
89
90struct unop {
91 BASEOP
92 OP * op_first;
93};
94
95struct binop {
96 BASEOP
97 OP * op_first;
98 OP * op_last;
99};
100
101struct logop {
102 BASEOP
103 OP * op_first;
104 OP * op_other;
105};
106
107struct condop {
108 BASEOP
109 OP * op_first;
110 OP * op_true;
111 OP * op_false;
112};
113
114struct listop {
115 BASEOP
116 OP * op_first;
117 OP * op_last;
118 U32 op_children;
119};
120
121struct pmop {
122 BASEOP
123 OP * op_first;
124 OP * op_last;
125 U32 op_children;
126 OP * op_pmreplroot;
127 OP * op_pmreplstart;
128 PMOP * op_pmnext; /* list of all scanpats */
129 REGEXP * op_pmregexp; /* compiled expression */
130 SV * op_pmshort; /* for a fast bypass of execute() */
131 short op_pmflags;
132 char op_pmslen;
133};
134#define PMf_USED 1 /* pm has been used once already */
135#define PMf_ONCE 2 /* use pattern only once per reset */
136#define PMf_SCANFIRST 4 /* initial constant not anchored */
137#define PMf_ALL 8 /* initial constant is whole pat */
138#define PMf_SKIPWHITE 16 /* skip leading whitespace for split */
139#define PMf_FOLD 32 /* case insensitivity */
140#define PMf_CONST 64 /* subst replacement is constant */
141#define PMf_KEEP 128 /* keep 1st runtime pattern forever */
142#define PMf_GLOBAL 256 /* pattern had a g modifier */
143#define PMf_RUNTIME 512 /* pattern coming in on the stack */
144#define PMf_EVAL 1024 /* evaluating replacement as expr */
145
146struct svop {
147 BASEOP
148 SV * op_sv;
149};
150
151struct gvop {
152 BASEOP
153 GV * op_gv;
154};
155
156struct pvop {
157 BASEOP
158 char * op_pv;
159};
160
161struct cvop {
162 BASEOP
163 CV * op_cv;
164 OP * op_cont;
165};
166
167struct loop {
168 BASEOP
169 OP * op_first;
170 OP * op_last;
171 U32 op_children;
172 OP * op_redoop;
173 OP * op_nextop;
174 OP * op_lastop;
175};
176
177#define cUNOP ((UNOP*)op)
178#define cBINOP ((BINOP*)op)
179#define cLISTOP ((LISTOP*)op)
180#define cLOGOP ((LOGOP*)op)
181#define cCONDOP ((CONDOP*)op)
182#define cPMOP ((PMOP*)op)
183#define cSVOP ((SVOP*)op)
184#define cGVOP ((GVOP*)op)
185#define cPVOP ((PVOP*)op)
186#define cCVOP ((CVOP*)op)
187#define cCOP ((COP*)op)
188#define cLOOP ((LOOP*)op)
189
190#define kUNOP ((UNOP*)kid)
191#define kBINOP ((BINOP*)kid)
192#define kLISTOP ((LISTOP*)kid)
193#define kLOGOP ((LOGOP*)kid)
194#define kCONDOP ((CONDOP*)kid)
195#define kPMOP ((PMOP*)kid)
196#define kSVOP ((SVOP*)kid)
197#define kGVOP ((GVOP*)kid)
198#define kPVOP ((PVOP*)kid)
199#define kCVOP ((CVOP*)kid)
200#define kCOP ((COP*)kid)
201#define kLOOP ((LOOP*)kid)
202
203#define Nullop Null(OP*)
204