1/* $NetBSD: bcdefs.h,v 1.1 2017/04/10 02:28:23 phil Exp $ */ 2 3/* 4 * Copyright (C) 1991-1994, 1997, 2006, 2008, 2012-2017 Free Software Foundation, Inc. 5 * Copyright (C) 2016-2017 Philip A. Nelson. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. The names Philip A. Nelson and Free Software Foundation may not be 18 * used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY PHILIP A. NELSON ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * IN NO EVENT SHALL PHILIP A. NELSON OR THE FREE SOFTWARE FOUNDATION BE 25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 * THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34/* bcdefs.h: The single file to include all constants and type definitions. */ 35 36/* Include the configuration file. */ 37#include "config.h" 38 39/* Standard includes for all files. */ 40#include <stdio.h> 41#include <sys/types.h> 42#include <ctype.h> 43#ifdef HAVE_STRING_H 44#include <string.h> 45#else 46#include <strings.h> 47#endif 48#ifdef HAVE_LIMITS_H 49#include <limits.h> 50#endif 51 52#if defined(LIBEDIT) 53#include <histedit.h> 54#endif 55 56#if defined(READLINE) 57#include <readline/readline.h> 58#include <readline/history.h> 59#endif 60 61/* Initialization magic ... */ 62#ifdef _GLOBAL_C 63#define EXTERN 64#define INIT(x) = x 65#else 66#define EXTERN extern 67#define INIT(x) 68#endif 69 70/* Include the other definitions. */ 71#include "const.h" 72#include "number.h" 73 74/* These definitions define all the structures used in 75 code and data storage. This includes the representation of 76 labels. The "guiding" principle is to make structures that 77 take a minimum of space when unused but can be built to contain 78 the full structures. */ 79 80/* Labels are first. Labels are generated sequentially in functions 81 and full code. They just "point" to a single bye in the code. The 82 "address" is the byte number. The byte number is used to get an 83 actual character pointer. */ 84 85typedef struct bc_label_group 86 { 87 unsigned long l_adrs [ BC_LABEL_GROUP ]; 88 struct bc_label_group *l_next; 89 } bc_label_group; 90 91/* Argument list. Recorded in the function so arguments can 92 be checked at call time. */ 93 94typedef struct arg_list 95 { 96 int av_name; 97 int arg_is_var; /* Extension ... variable parameters. */ 98 struct arg_list *next; 99 } arg_list; 100 101/* Each function has its own code segments and labels. There can be 102 no jumps between functions so labels are unique to a function. */ 103 104typedef struct 105 { 106 char f_defined; /* Is this function defined yet. */ 107 char f_void; /* Is this function a void function. */ 108 char *f_body; 109 size_t f_body_size; /* Size of body. Power of 2. */ 110 size_t f_code_size; 111 bc_label_group *f_label; 112 arg_list *f_params; 113 arg_list *f_autos; 114 } bc_function; 115 116/* Code addresses. */ 117typedef struct { 118 unsigned int pc_func; 119 unsigned int pc_addr; 120 } program_counter; 121 122 123/* Variables are "pushable" (auto) and thus we need a stack mechanism. 124 This is built into the variable record. */ 125 126typedef struct bc_var 127 { 128 bc_num v_value; 129 struct bc_var *v_next; 130 } bc_var; 131 132 133/* bc arrays can also be "auto" variables and thus need the same 134 kind of stacking mechanisms. */ 135 136typedef struct bc_array_node 137 { 138 union 139 { 140 bc_num n_num [NODE_SIZE]; 141 struct bc_array_node *n_down [NODE_SIZE]; 142 } n_items; 143 } bc_array_node; 144 145typedef struct bc_array 146 { 147 bc_array_node *a_tree; 148 short a_depth; 149 } bc_array; 150 151typedef struct bc_var_array 152 { 153 bc_array *a_value; 154 char a_param; 155 struct bc_var_array *a_next; 156 } bc_var_array; 157 158 159/* For the stacks, execution and function, we need records to allow 160 for arbitrary size. */ 161 162typedef struct estack_rec { 163 bc_num s_num; 164 struct estack_rec *s_next; 165} estack_rec; 166 167typedef struct fstack_rec { 168 int s_val; 169 struct fstack_rec *s_next; 170} fstack_rec; 171 172 173/* The following are for the name tree. */ 174 175typedef struct id_rec { 176 char *id; /* The program name. */ 177 /* A name == 0 => nothing assigned yet. */ 178 int a_name; /* The array variable name (number). */ 179 int f_name; /* The function name (number). */ 180 int v_name; /* The variable name (number). */ 181 short balance; /* For the balanced tree. */ 182 struct id_rec *left, *right; /* Tree pointers. */ 183} id_rec; 184 185 186/* A list of files to process. */ 187 188typedef struct file_node { 189 char *name; 190 struct file_node *next; 191} file_node; 192 193/* Macro Definitions */ 194 195#if defined(LIBEDIT) 196#define HISTORY_SIZE(n) history(hist, &histev, H_SETSIZE, n) 197#define UNLIMIT_HISTORY history(hist, &histev, H_SETSIZE, INT_MAX) 198#endif 199 200#if defined(READLINE) 201#define HISTORY_SIZE(n) stifle_history(n) 202#define UNLIMIT_HISTORY unstifle_history() 203#endif 204 205/* Now the global variable declarations. */ 206#include "global.h" 207