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