Git init
[external/mawk.git] / symtype.h
1
2 /********************************************
3 symtype.h
4 copyright 1991, Michael D. Brennan
5
6 This is a source file for mawk, an implementation of
7 the AWK programming language.
8
9 Mawk is distributed without warranty under the terms of
10 the GNU General Public License, version 2, 1991.
11 ********************************************/
12
13 /*$Log: symtype.h,v $
14  * Revision 1.6  1996/02/01  04:39:43  mike
15  * dynamic array scheme
16  *
17  * Revision 1.5  1995/04/21  14:20:23  mike
18  * move_level variable to fix bug in arglist patching of moved code.
19  *
20  * Revision 1.4  1994/12/13  00:13:02  mike
21  * delete A statement to delete all of A at once
22  *
23  * Revision 1.3  1993/12/01  14:25:25  mike
24  * reentrant array loops
25  *
26  * Revision 1.2  1993/07/15  01:55:08  mike
27  * rm SIZE_T & indent
28  *
29  * Revision 1.1.1.1  1993/07/03  18:58:21  mike
30  * move source to cvs
31  *
32  * Revision 5.5  1993/01/09  19:03:44  mike
33  * code_pop checks if the resolve_list needs relocation
34  *
35  * Revision 5.4  1993/01/07  02:50:33  mike
36  * relative vs absolute code
37  *
38  * Revision 5.3  1992/12/17  02:48:01  mike
39  * 1.1.2d changes for DOS
40  *
41  * Revision 5.2  1992/07/08  15:44:44  brennan
42  * patch2: length returns.  I am a wimp
43  *
44  * Revision 5.1  1991/12/05  07:59:37  brennan
45  * 1.1 pre-release
46  *
47 */
48
49 /* types related to symbols are defined here */
50
51 #ifndef  SYMTYPE_H
52 #define  SYMTYPE_H
53
54
55 /* struct to hold info about builtins */
56 typedef struct {
57 char *name ;
58 PF_CP  fp ;  /* ptr to function that does the builtin */
59 unsigned char min_args, max_args ; 
60 /* info for parser to check correct number of arguments */
61 } BI_REC ;
62
63 /*---------------------------
64    structures and types for arrays
65  *--------------------------*/
66
67 #include "array.h"
68
69 extern  ARRAY  Argv ;
70
71 #if 0
72 /* struct to hold the state of an array loop */
73 typedef struct al_state {
74 struct al_state *link ;
75 CELL *var ;
76 ARRAY  A  ;
77 int index ;   /* A[index]  */
78 ANODE *ptr ;
79 } ALOOP_STATE ;
80
81 int  PROTO( inc_aloop_state, (ALOOP_STATE*)) ;
82 #endif
83
84 /* for parsing  (i,j) in A  */
85 typedef  struct {
86 int start ; /* offset to code_base */
87 int cnt ;
88 } ARG2_REC ;
89
90 /*------------------------
91   user defined functions
92   ------------------------*/
93
94 typedef  struct fblock {
95 char *name ;
96 INST *code  ;
97 unsigned short nargs ;
98 char *typev ;  /* array of size nargs holding types */
99 } FBLOCK ;   /* function block */
100
101 void  PROTO(add_to_fdump_list, (FBLOCK *) ) ;
102 void  PROTO( fdump, (void) ) ;
103
104 /*-------------------------
105   elements of the symbol table
106   -----------------------*/
107
108 #define  ST_NONE 0
109 #define  ST_VAR   1
110 #define  ST_KEYWORD   2
111 #define  ST_BUILTIN 3 /* a pointer to a builtin record */
112 #define  ST_ARRAY   4 /* a void * ptr to a hash table */
113 #define  ST_FIELD   5  /* a cell ptr to a field */
114 #define  ST_FUNCT   6
115 #define  ST_NR      7  /*  NR is special */
116 #define  ST_ENV     8  /* and so is ENVIRON */
117 #define  ST_LENGTH  9  /* ditto and bozo */
118 #define  ST_LOCAL_NONE  10
119 #define  ST_LOCAL_VAR   11
120 #define  ST_LOCAL_ARRAY 12
121
122 #define  is_local(stp)   ((stp)->type>=ST_LOCAL_NONE)
123
124 typedef  struct {
125 char *name ;
126 char type ;
127 unsigned char offset ;  /* offset in stack frame for local vars */
128 union {
129 CELL *cp ;
130 int  kw ;
131 PF_CP fp ;
132 BI_REC *bip ;
133 ARRAY  array ; 
134 FBLOCK  *fbp ;
135 } stval ;
136 }  SYMTAB ;
137
138
139 /*****************************
140  structures for type checking function calls
141  ******************************/
142
143 typedef  struct ca_rec {
144 struct ca_rec  *link ;
145 short type ;
146 short arg_num ;  /* position in callee's stack */
147 /*---------  this data only set if we'll  need to patch -------*/
148 /* happens if argument is an ID or type ST_NONE or ST_LOCAL_NONE */
149
150 int call_offset ;
151 /* where the type is stored */
152 SYMTAB  *sym_p ;  /* if type is ST_NONE  */
153 char *type_p ;  /* if type  is ST_LOCAL_NONE */
154 }  CA_REC  ; /* call argument record */
155
156 /* type field of CA_REC matches with ST_ types */
157 #define   CA_EXPR       ST_LOCAL_VAR
158 #define   CA_ARRAY      ST_LOCAL_ARRAY
159
160 typedef  struct fcall {
161 struct fcall *link ;
162 FBLOCK  *callee ;
163 short   call_scope ;
164 short   move_level ;  
165 FBLOCK  *call ;  /* only used if call_scope == SCOPE_FUNCT  */
166 INST    *call_start ; /* computed later as code may be moved */
167 CA_REC  *arg_list ;
168 short   arg_cnt_checked ;
169 unsigned line_no ; /* for error messages */
170 } FCALL_REC ;
171
172 extern  FCALL_REC  *resolve_list ;
173
174 void PROTO(resolve_fcalls, (void) ) ;
175 void PROTO(check_fcall, (FBLOCK*,int,int,FBLOCK*,CA_REC*,unsigned) ) ;
176 void  PROTO(relocate_resolve_list, (int,int,FBLOCK*,int,unsigned,int)) ;
177
178 /* hash.c */
179 unsigned  PROTO( hash, (char *) ) ;
180 SYMTAB *PROTO( insert, (char *) ) ;
181 SYMTAB *PROTO( find, (char *) ) ;
182 char *PROTO( reverse_find, (int, PTR)) ;
183 SYMTAB *PROTO( save_id, (char *) ) ;
184 void    PROTO( restore_ids, (void) ) ;
185
186 /* error.c */
187 void  PROTO(type_error, (SYMTAB *) ) ;
188
189 #endif  /* SYMTYPE_H */