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