Commit | Line | Data |
68decaef |
1 | /* $RCSfile: cmd.h,v $$Revision: 4.0.1.2 $$Date: 92/06/08 12:01:02 $ |
a687059c |
2 | * |
2b317908 |
3 | * Copyright (c) 1991, Larry Wall |
a687059c |
4 | * |
2b317908 |
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. |
8d063cd8 |
7 | * |
8 | * $Log: cmd.h,v $ |
68decaef |
9 | * Revision 4.0.1.2 92/06/08 12:01:02 lwall |
10 | * patch20: removed implicit int declarations on funcions |
11 | * |
2b317908 |
12 | * Revision 4.0.1.1 91/06/07 10:28:50 lwall |
13 | * patch4: new copyright notice |
14 | * patch4: length($`), length($&), length($') now optimized to avoid string copy |
15 | * |
fe14fcc3 |
16 | * Revision 4.0 91/03/20 01:04:34 lwall |
17 | * 4.0 baseline. |
8d063cd8 |
18 | * |
19 | */ |
20 | |
21 | #define C_NULL 0 |
22 | #define C_IF 1 |
a687059c |
23 | #define C_ELSE 2 |
24 | #define C_WHILE 3 |
8d063cd8 |
25 | #define C_BLOCK 4 |
a687059c |
26 | #define C_EXPR 5 |
27 | #define C_NEXT 6 |
28 | #define C_ELSIF 7 /* temporary--turns into an IF + ELSE */ |
29 | #define C_CSWITCH 8 /* created by switch optimization in block_head() */ |
30 | #define C_NSWITCH 9 /* likewise */ |
8d063cd8 |
31 | |
378cc40b |
32 | #ifdef DEBUGGING |
8d063cd8 |
33 | #ifndef DOINIT |
34 | extern char *cmdname[]; |
35 | #else |
36 | char *cmdname[] = { |
37 | "NULL", |
38 | "IF", |
a687059c |
39 | "ELSE", |
8d063cd8 |
40 | "WHILE", |
8d063cd8 |
41 | "BLOCK", |
a687059c |
42 | "EXPR", |
43 | "NEXT", |
44 | "ELSIF", |
45 | "CSWITCH", |
46 | "NSWITCH", |
47 | "10" |
8d063cd8 |
48 | }; |
49 | #endif |
378cc40b |
50 | #endif /* DEBUGGING */ |
8d063cd8 |
51 | |
52 | #define CF_OPTIMIZE 077 /* type of optimization */ |
53 | #define CF_FIRSTNEG 0100/* conditional is ($register NE 'string') */ |
378cc40b |
54 | #define CF_NESURE 0200 /* if short doesn't match we're sure */ |
55 | #define CF_EQSURE 0400 /* if short does match we're sure */ |
8d063cd8 |
56 | #define CF_COND 01000 /* test c_expr as conditional first, if not null. */ |
57 | /* Set for everything except do {} while currently */ |
58 | #define CF_LOOP 02000 /* loop on the c_expr conditional (loop modifiers) */ |
59 | #define CF_INVERT 04000 /* it's an "unless" or an "until" */ |
60 | #define CF_ONCE 010000 /* we've already pushed the label on the stack */ |
61 | #define CF_FLIP 020000 /* on a match do flipflop */ |
a687059c |
62 | #define CF_TERM 040000 /* value of this cmd might be returned */ |
03a14243 |
63 | #define CF_DBSUB 0100000 /* this is an inserted cmd for debugging */ |
8d063cd8 |
64 | |
65 | #define CFT_FALSE 0 /* c_expr is always false */ |
66 | #define CFT_TRUE 1 /* c_expr is always true */ |
67 | #define CFT_REG 2 /* c_expr is a simple register */ |
68 | #define CFT_ANCHOR 3 /* c_expr is an anchored search /^.../ */ |
69 | #define CFT_STROP 4 /* c_expr is a string comparison */ |
70 | #define CFT_SCAN 5 /* c_expr is an unanchored search /.../ */ |
378cc40b |
71 | #define CFT_GETS 6 /* c_expr is <filehandle> */ |
8d063cd8 |
72 | #define CFT_EVAL 7 /* c_expr is not optimized, so call eval() */ |
73 | #define CFT_UNFLIP 8 /* 2nd half of range not optimized */ |
74 | #define CFT_CHOP 9 /* c_expr is a chop on a register */ |
378cc40b |
75 | #define CFT_ARRAY 10 /* this is a foreach loop */ |
76 | #define CFT_INDGETS 11 /* c_expr is <$variable> */ |
77 | #define CFT_NUMOP 12 /* c_expr is a numeric comparison */ |
a687059c |
78 | #define CFT_CCLASS 13 /* c_expr must start with one of these characters */ |
39c3038c |
79 | #define CFT_D0 14 /* no special breakpoint at this line */ |
80 | #define CFT_D1 15 /* possible special breakpoint at this line */ |
8d063cd8 |
81 | |
378cc40b |
82 | #ifdef DEBUGGING |
8d063cd8 |
83 | #ifndef DOINIT |
84 | extern char *cmdopt[]; |
85 | #else |
86 | char *cmdopt[] = { |
87 | "FALSE", |
88 | "TRUE", |
89 | "REG", |
90 | "ANCHOR", |
91 | "STROP", |
92 | "SCAN", |
93 | "GETS", |
94 | "EVAL", |
95 | "UNFLIP", |
96 | "CHOP", |
378cc40b |
97 | "ARRAY", |
98 | "INDGETS", |
99 | "NUMOP", |
a687059c |
100 | "CCLASS", |
101 | "14" |
8d063cd8 |
102 | }; |
103 | #endif |
378cc40b |
104 | #endif /* DEBUGGING */ |
8d063cd8 |
105 | |
106 | struct acmd { |
107 | STAB *ac_stab; /* a symbol table entry */ |
108 | ARG *ac_expr; /* any associated expression */ |
109 | }; |
110 | |
111 | struct ccmd { |
112 | CMD *cc_true; /* normal code to do on if and while */ |
a687059c |
113 | CMD *cc_alt; /* else cmd ptr or continue code */ |
114 | }; |
115 | |
116 | struct scmd { |
117 | CMD **sc_next; /* array of pointers to commands */ |
118 | short sc_offset; /* first value - 1 */ |
119 | short sc_max; /* last value + 1 */ |
8d063cd8 |
120 | }; |
121 | |
122 | struct cmd { |
123 | CMD *c_next; /* the next command at this level */ |
124 | ARG *c_expr; /* conditional expression */ |
125 | CMD *c_head; /* head of this command list */ |
378cc40b |
126 | STR *c_short; /* string to match as shortcut */ |
8d063cd8 |
127 | STAB *c_stab; /* a symbol table entry, mostly for fp */ |
128 | SPAT *c_spat; /* pattern used by optimization */ |
129 | char *c_label; /* label for this construct */ |
130 | union ucmd { |
131 | struct acmd acmd; /* normal command */ |
132 | struct ccmd ccmd; /* compound command */ |
a687059c |
133 | struct scmd scmd; /* switch command */ |
8d063cd8 |
134 | } ucmd; |
378cc40b |
135 | short c_slen; /* len of c_short, if not null */ |
afd9f252 |
136 | VOLATILE short c_flags; /* optimization flags--see above */ |
39c3038c |
137 | HASH *c_stash; /* package line was compiled in */ |
138 | STAB *c_filestab; /* file the following line # is from */ |
378cc40b |
139 | line_t c_line; /* line # of this command */ |
8d063cd8 |
140 | char c_type; /* what this command does */ |
141 | }; |
142 | |
143 | #define Nullcmd Null(CMD*) |
39c3038c |
144 | #define Nullcsv Null(CSV*) |
8d063cd8 |
145 | |
afd9f252 |
146 | EXT CMD * VOLATILE main_root INIT(Nullcmd); |
147 | EXT CMD * VOLATILE eval_root INIT(Nullcmd); |
8d063cd8 |
148 | |
87250799 |
149 | EXT CMD compiling; |
150 | EXT CMD * VOLATILE curcmd INIT(&compiling); |
39c3038c |
151 | EXT CSV * VOLATILE curcsv INIT(Nullcsv); |
152 | |
153 | struct callsave { |
154 | SUBR *sub; |
155 | STAB *stab; |
156 | CSV *curcsv; |
157 | CMD *curcmd; |
158 | ARRAY *savearray; |
159 | ARRAY *argarray; |
160 | long depth; |
161 | int wantarray; |
162 | char hasargs; |
163 | }; |
87250799 |
164 | |
a687059c |
165 | struct compcmd { |
8d063cd8 |
166 | CMD *comp_true; |
167 | CMD *comp_alt; |
168 | }; |
169 | |
8d063cd8 |
170 | void opt_arg(); |
2b317908 |
171 | ARG* evalstatic(); |
a687059c |
172 | int cmd_exec(); |
68decaef |
173 | #ifdef DEBUGGING |
174 | void deb(); |
175 | #endif |
176 | int copyopt(); |