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