Initial import from FreeBSD RELENG_4:
[games.git] / contrib / bc / h / bcdefs.h
1 /* bcdefs.h:  The single file to include all constants and type definitions. */
2
3 /*  This file is part of GNU bc.
4     Copyright (C) 1991, 1992, 1993, 1994, 1997 Free Software Foundation, Inc.
5
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License , or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program; see the file COPYING.  If not, write to
18     the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19
20     You may contact the author by:
21        e-mail:  phil@cs.wwu.edu
22       us-mail:  Philip A. Nelson
23                 Computer Science Department, 9062
24                 Western Washington University
25                 Bellingham, WA 98226-9062
26        
27 *************************************************************************/
28
29 /* Include the configuration file. */
30 #include "config.h"
31
32 /* Standard includes for all files. */
33 #include <stdio.h>
34 #include <sys/types.h>
35 #include <ctype.h>
36 #ifdef HAVE_STRINGS_H
37 #include <strings.h>
38 #else
39 #include <string.h>
40 #endif
41 #ifdef HAVE_LIMITS_H
42 #include <limits.h>
43 #endif
44
45 /* Include the other definitions. */
46 #include "const.h"
47 #include "number.h"
48
49
50 /* These definitions define all the structures used in
51    code and data storage.  This includes the representation of
52    labels.   The "guiding" principle is to make structures that
53    take a minimum of space when unused but can be built to contain
54    the full structures.  */
55
56 /* Labels are first.  Labels are generated sequentially in functions
57    and full code.  They just "point" to a single bye in the code.  The
58    "address" is the byte number.  The byte number is used to get an
59    actual character pointer. */
60
61 typedef struct bc_label_group
62     {
63       long l_adrs [ BC_LABEL_GROUP ];
64       struct bc_label_group *l_next;
65     } bc_label_group;
66
67 /* Argument list.  Recorded in the function so arguments can
68    be checked at call time. */
69
70 typedef struct arg_list
71     {
72       int av_name;
73       int arg_is_var;           /* Extension ... variable parameters. */
74       struct arg_list *next;
75     } arg_list;
76
77 /* Each function has its own code segments and labels.  There can be
78    no jumps between functions so labels are unique to a function. */
79
80 typedef struct 
81     {
82       char f_defined;   /* Is this function defined yet. */
83       char *f_body[BC_MAX_SEGS];
84       int   f_code_size;
85       bc_label_group *f_label;
86       arg_list *f_params;
87       arg_list *f_autos;
88     } bc_function;
89
90 /* Code addresses. */
91 typedef struct {
92       int pc_func;
93       int pc_addr;
94     } program_counter;
95
96
97 /* Variables are "pushable" (auto) and thus we need a stack mechanism.
98    This is built into the variable record. */
99
100 typedef struct bc_var
101     {
102       bc_num v_value;
103       struct bc_var *v_next;
104     }  bc_var;
105
106
107 /* bc arrays can also be "auto" variables and thus need the same
108    kind of stacking mechanisms. */
109
110 typedef struct bc_array_node
111     {
112       union
113         {
114           bc_num n_num [NODE_SIZE];
115           struct bc_array_node *n_down [NODE_SIZE];
116         } n_items;
117     } bc_array_node;
118
119 typedef struct bc_array
120     {
121       bc_array_node *a_tree;
122       short a_depth;
123     } bc_array;
124
125 typedef struct bc_var_array
126     {
127       bc_array *a_value;
128       char      a_param;
129       struct bc_var_array *a_next;
130     } bc_var_array;
131
132
133 /* For the stacks, execution and function, we need records to allow
134    for arbitrary size. */
135
136 typedef struct estack_rec {
137         bc_num s_num;
138         struct estack_rec *s_next;
139 } estack_rec;
140
141 typedef struct fstack_rec {
142         int  s_val;
143         struct fstack_rec *s_next;
144 } fstack_rec;
145
146
147 /* The following are for the name tree. */
148
149 typedef struct id_rec {
150         char  *id;      /* The program name. */
151                         /* A name == 0 => nothing assigned yet. */
152         int   a_name;   /* The array variable name (number). */
153         int   f_name;   /* The function name (number).  */
154         int   v_name;   /* The variable name (number).  */
155         short balance;  /* For the balanced tree. */
156         struct id_rec *left, *right; /* Tree pointers. */
157 } id_rec;
158
159
160 /* A list of files to process. */
161
162 typedef struct file_node {
163         char *name;
164         struct file_node *next;
165 } file_node;
166