perl 3.0 patch #4 Patch #2 continued
[p5sagit/p5-mst-13.2.git] / cmd.h
1 /* $Header: cmd.h,v 3.0.1.1 89/10/26 23:05:43 lwall Locked $
2  *
3  *    Copyright (c) 1989, Larry Wall
4  *
5  *    You may distribute under the terms of the GNU General Public License
6  *    as specified in the README file that comes with the perl 3.0 kit.
7  *
8  * $Log:        cmd.h,v $
9  * Revision 3.0.1.1  89/10/26  23:05:43  lwall
10  * patch1: unless was broken when run under the debugger
11  * 
12  * Revision 3.0  89/10/18  15:09:15  lwall
13  * 3.0 baseline
14  * 
15  */
16
17 #define C_NULL 0
18 #define C_IF 1
19 #define C_ELSE 2
20 #define C_WHILE 3
21 #define C_BLOCK 4
22 #define C_EXPR 5
23 #define C_NEXT 6
24 #define C_ELSIF 7       /* temporary--turns into an IF + ELSE */
25 #define C_CSWITCH 8     /* created by switch optimization in block_head() */
26 #define C_NSWITCH 9     /* likewise */
27
28 #ifdef DEBUGGING
29 #ifndef DOINIT
30 extern char *cmdname[];
31 #else
32 char *cmdname[] = {
33     "NULL",
34     "IF",
35     "ELSE",
36     "WHILE",
37     "BLOCK",
38     "EXPR",
39     "NEXT",
40     "ELSIF",
41     "CSWITCH",
42     "NSWITCH",
43     "10"
44 };
45 #endif
46 #endif /* DEBUGGING */
47
48 #define CF_OPTIMIZE 077 /* type of optimization */
49 #define CF_FIRSTNEG 0100/* conditional is ($register NE 'string') */
50 #define CF_NESURE 0200  /* if short doesn't match we're sure */
51 #define CF_EQSURE 0400  /* if short does match we're sure */
52 #define CF_COND 01000   /* test c_expr as conditional first, if not null. */
53                         /* Set for everything except do {} while currently */
54 #define CF_LOOP 02000   /* loop on the c_expr conditional (loop modifiers) */
55 #define CF_INVERT 04000 /* it's an "unless" or an "until" */
56 #define CF_ONCE 010000  /* we've already pushed the label on the stack */
57 #define CF_FLIP 020000  /* on a match do flipflop */
58 #define CF_TERM 040000  /* value of this cmd might be returned */
59 #define CF_DBSUB 0100000 /* this is an inserted cmd for debugging */
60
61 #define CFT_FALSE 0     /* c_expr is always false */
62 #define CFT_TRUE 1      /* c_expr is always true */
63 #define CFT_REG 2       /* c_expr is a simple register */
64 #define CFT_ANCHOR 3    /* c_expr is an anchored search /^.../ */
65 #define CFT_STROP 4     /* c_expr is a string comparison */
66 #define CFT_SCAN 5      /* c_expr is an unanchored search /.../ */
67 #define CFT_GETS 6      /* c_expr is <filehandle> */
68 #define CFT_EVAL 7      /* c_expr is not optimized, so call eval() */
69 #define CFT_UNFLIP 8    /* 2nd half of range not optimized */
70 #define CFT_CHOP 9      /* c_expr is a chop on a register */
71 #define CFT_ARRAY 10    /* this is a foreach loop */
72 #define CFT_INDGETS 11  /* c_expr is <$variable> */
73 #define CFT_NUMOP 12    /* c_expr is a numeric comparison */
74 #define CFT_CCLASS 13   /* c_expr must start with one of these characters */
75
76 #ifdef DEBUGGING
77 #ifndef DOINIT
78 extern char *cmdopt[];
79 #else
80 char *cmdopt[] = {
81     "FALSE",
82     "TRUE",
83     "REG",
84     "ANCHOR",
85     "STROP",
86     "SCAN",
87     "GETS",
88     "EVAL",
89     "UNFLIP",
90     "CHOP",
91     "ARRAY",
92     "INDGETS",
93     "NUMOP",
94     "CCLASS",
95     "14"
96 };
97 #endif
98 #endif /* DEBUGGING */
99
100 struct acmd {
101     STAB        *ac_stab;       /* a symbol table entry */
102     ARG         *ac_expr;       /* any associated expression */
103 };
104
105 struct ccmd {
106     CMD         *cc_true;       /* normal code to do on if and while */
107     CMD         *cc_alt;        /* else cmd ptr or continue code */
108 };
109
110 struct scmd {
111     CMD         **sc_next;      /* array of pointers to commands */
112     short       sc_offset;      /* first value - 1 */
113     short       sc_max;         /* last value + 1 */
114 };
115
116 struct cmd {
117     CMD         *c_next;        /* the next command at this level */
118     ARG         *c_expr;        /* conditional expression */
119     CMD         *c_head;        /* head of this command list */
120     STR         *c_short;       /* string to match as shortcut */
121     STAB        *c_stab;        /* a symbol table entry, mostly for fp */
122     SPAT        *c_spat;        /* pattern used by optimization */
123     char        *c_label;       /* label for this construct */
124     union ucmd {
125         struct acmd acmd;       /* normal command */
126         struct ccmd ccmd;       /* compound command */
127         struct scmd scmd;       /* switch command */
128     } ucmd;
129     short       c_slen;         /* len of c_short, if not null */
130     short       c_flags;        /* optimization flags--see above */
131     char        *c_file;        /* file the following line # is from */
132     line_t      c_line;         /* line # of this command */
133     char        c_type;         /* what this command does */
134 };
135
136 #define Nullcmd Null(CMD*)
137
138 EXT CMD *main_root INIT(Nullcmd);
139 EXT CMD *eval_root INIT(Nullcmd);
140
141 struct compcmd {
142     CMD *comp_true;
143     CMD *comp_alt;
144 };
145
146 void opt_arg();
147 void evalstatic();
148 int cmd_exec();