home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / MAWK113.ZIP / mawk113 / symtype.h < prev    next >
C/C++ Source or Header  |  1992-12-16  |  5KB  |  190 lines

  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 5.3  1992/12/17  02:48:01  mike
  15.  * 1.1.2d changes for DOS
  16.  *
  17.  * Revision 5.2  1992/07/08  15:44:44  brennan
  18.  * patch2: length returns.  I am a wimp
  19.  *
  20.  * Revision 5.1  1991/12/05  07:59:37  brennan
  21.  * 1.1 pre-release
  22.  *
  23. */
  24.  
  25. /* types related to symbols are defined here */
  26.  
  27. #ifndef  SYMTYPE_H
  28. #define  SYMTYPE_H
  29.  
  30.  
  31. /* struct to hold info about builtins */
  32. typedef struct {
  33. char *name ;
  34. PF_CP  fp ;  /* ptr to function that does the builtin */
  35. unsigned char min_args, max_args ; 
  36. /* info for parser to check correct number of arguments */
  37. } BI_REC ;
  38.  
  39. /*---------------------------
  40.    structures and types for arrays
  41.  *--------------------------*/
  42.  
  43. /* array hash nodes */
  44.  
  45. /* string node */
  46. typedef  struct anode {
  47. struct anode *link , *ilink ;
  48. STRING *sval ;
  49. long     ival ;
  50. CELL   *cp ;
  51. }  ANODE ;
  52.  
  53.  
  54. typedef struct array {
  55. ANODE *link , *ilink ;
  56. } *ARRAY ;
  57.  
  58. #define  CREATE         1
  59. #define  NO_CREATE      0
  60.  
  61. /* note ARRAY is a ptr to a hash table */
  62.  
  63. CELL *PROTO(array_find, (ARRAY,CELL *, int) ) ;
  64. INST *PROTO(array_loop, (INST *, CELL *, CELL *) ) ;
  65. void PROTO(array_delete, (ARRAY, CELL *) ) ;
  66. CELL *PROTO(array_cat, (CELL *, int) ) ;
  67. void PROTO(array_free, (ARRAY) ) ;
  68. void PROTO(load_array, (ARRAY,int)) ;
  69.  
  70. #define new_ARRAY() (ARRAY)memset(zmalloc(A_HASH_PRIME *\
  71.                         sizeof(struct array)),\
  72.                         0 , SIZE_T(A_HASH_PRIME*sizeof(struct array)))
  73.  
  74. extern  ARRAY  Argv ;
  75.  
  76. /* struct to hold the state of an array loop */
  77. typedef struct {
  78. CELL *var ;
  79. ARRAY  A  ;
  80. int index ;   /* A[index]  */
  81. ANODE *ptr ;
  82. } ALOOP_STATE ;
  83.  
  84. int  PROTO( inc_aloop_state, (ALOOP_STATE*)) ;
  85.  
  86. /* for parsing  (i,j) in A  */
  87. typedef  struct {
  88. INST *start ;
  89. int cnt ;
  90. } ARG2_REC ;
  91.  
  92. /*------------------------
  93.   user defined functions
  94.   ------------------------*/
  95.  
  96. typedef  struct fblock {
  97. char *name ;
  98. INST *code  ;
  99. unsigned short nargs ;
  100. char *typev ;  /* array of size nargs holding types */
  101. } FBLOCK ;   /* function block */
  102.  
  103. void  PROTO(add_to_fdump_list, (FBLOCK *) ) ;
  104. void  PROTO( fdump, (void) ) ;
  105.  
  106. /*-------------------------
  107.   elements of the symbol table
  108.   -----------------------*/
  109.  
  110. #define  ST_NONE 0
  111. #define  ST_VAR   1
  112. #define  ST_KEYWORD   2
  113. #define  ST_BUILTIN 3 /* a pointer to a builtin record */
  114. #define  ST_ARRAY   4 /* a void * ptr to a hash table */
  115. #define  ST_FIELD   5  /* a cell ptr to a field */
  116. #define  ST_FUNCT   6
  117. #define  ST_NR      7  /*  NR is special */
  118. #define  ST_ENV     8  /* and so is ENVIRON */
  119. #define  ST_LENGTH  9  /* ditto and bozo */
  120. #define  ST_LOCAL_NONE  10
  121. #define  ST_LOCAL_VAR   11
  122. #define  ST_LOCAL_ARRAY 12
  123.  
  124. #define  is_local(stp)   ((stp)->type>=ST_LOCAL_NONE)
  125.  
  126. typedef  struct {
  127. char *name ;
  128. char type ;
  129. unsigned char offset ;  /* offset in stack frame for local vars */
  130. union {
  131. CELL *cp ;
  132. int  kw ;
  133. PF_CP fp ;
  134. BI_REC *bip ;
  135. ARRAY  array ; 
  136. FBLOCK  *fbp ;
  137. } stval ;
  138. }  SYMTAB ;
  139.  
  140.  
  141. /*****************************
  142.  structures for type checking function calls
  143.  ******************************/
  144.  
  145. typedef  struct ca_rec {
  146. struct ca_rec  *link ;
  147. short type ;
  148. short arg_num ;  /* position in callee's stack */
  149. /*---------  this data only set if we'll  need to patch -------*/
  150. /* happens if argument is an ID or type ST_NONE or ST_LOCAL_NONE */
  151.  
  152. int call_offset ;
  153. /* where the type is stored */
  154. SYMTAB  *sym_p ;  /* if type is ST_NONE  */
  155. char *type_p ;  /* if type  is ST_LOCAL_NONE */
  156. }  CA_REC  ; /* call argument record */
  157.  
  158. /* type field of CA_REC matches with ST_ types */
  159. #define   CA_EXPR       ST_LOCAL_VAR
  160. #define   CA_ARRAY      ST_LOCAL_ARRAY
  161.  
  162. typedef  struct fcall {
  163. struct fcall *link ;
  164. FBLOCK  *callee ;
  165. short   call_scope ;
  166. FBLOCK  *call ;  /* only used if call_scope == SCOPE_FUNCT  */
  167. INST    *call_start ; /* computed later as code may be moved */
  168. CA_REC  *arg_list ;
  169. short   arg_cnt_checked ;
  170. unsigned line_no ; /* for error messages */
  171. } FCALL_REC ;
  172.  
  173. extern  FCALL_REC  *resolve_list ;
  174.  
  175. void PROTO(resolve_fcalls, (void) ) ;
  176. void PROTO(check_fcall, (FBLOCK*,int,FBLOCK*,CA_REC*,unsigned) ) ;
  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 */
  190.