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