a68g-common.h

You can download the current version of Algol 68 Genie and its documentation here.

   1 //! @file a68g-common.h
   2 //! @author J. Marcel van der Veer
   3 //!
   4 //! @section Copyright
   5 //!
   6 //! This file is part of Algol68G - an Algol 68 compiler-interpreter.
   7 //! Copyright 2001-2023 J. Marcel van der Veer .
   8 //!
   9 //! @section License
  10 //!
  11 //! This program is free software; you can redistribute it and/or modify it 
  12 //! under the terms of the GNU General Public License as published by the 
  13 //! Free Software Foundation; either version 3 of the License, or 
  14 //! (at your option) any later version.
  15 //!
  16 //! This program is distributed in the hope that it will be useful, but 
  17 //! WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
  18 //! or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 
  19 //! more details. You should have received a copy of the GNU General Public 
  20 //! License along with this program. If not, see .
  21 
  22 #if !defined (__A68G_COMMON_H__)
  23 #define __A68G_COMMON_H__
  24 
  25 typedef struct MODULE_T MODULE_T;
  26 struct MODULE_T
  27 {
  28   BOOL_T tree_listing_safe, cross_reference_safe;
  29   FILES_T files;
  30   NODE_T *top_node;
  31   MOID_T *top_moid, *standenv_moid;
  32   OPTIONS_T options;
  33   PROP_T global_prop;
  34   REFINEMENT_T *top_refinement;
  35   LINE_T *top_line;
  36   int error_count, warning_count, source_scan;
  37   jmp_buf rendez_vous;
  38   struct
  39   {
  40     LINE_T *save_l;
  41     char *save_s, save_c;
  42   } scan_state;
  43 };
  44 
  45 typedef struct MODE_CACHE_T MODE_CACHE_T;
  46 #define MODE(p)        A68 (a68_modes.p)
  47 struct MODE_CACHE_T
  48 {
  49   MOID_T *proc_bool;
  50   MOID_T *proc_char;
  51   MOID_T *proc_complex_complex;
  52   MOID_T *proc_int;
  53   MOID_T *proc_int_int;
  54   MOID_T *proc_int_int_real;
  55   MOID_T *proc_int_real;
  56   MOID_T *proc_int_real_real;
  57   MOID_T *proc_int_real_real_real;
  58   MOID_T *proc_real;
  59   MOID_T *proc_real_int_real;
  60   MOID_T *proc_real_real;
  61   MOID_T *proc_real_real_int_real;
  62   MOID_T *proc_real_real_real;
  63   MOID_T *proc_real_real_real_int;
  64   MOID_T *proc_real_real_real_real;
  65   MOID_T *proc_real_real_real_real_real;
  66   MOID_T *proc_real_real_real_real_real_real;
  67   MOID_T *proc_real_ref_real_ref_int_void;
  68   MOID_T *proc_void;
  69 };
  70 
  71 #define MAX_OPEN_FILES 64       // Some OS's won't open more than this number
  72 #define MAX_TRANSPUT_BUFFER (MAX_OPEN_FILES)
  73 
  74 typedef struct FILE_ENTRY FILE_ENTRY;
  75 struct FILE_ENTRY
  76 {
  77   NODE_T *pos;
  78   BOOL_T is_open, is_tmp;
  79   FILE_T fd;
  80   A68_REF idf;
  81 };
  82 
  83 // Administration for common (sub) expression elimination.
  84 // BOOK keeps track of already seen (temporary) variables and denotations.
  85 
  86 enum
  87 { BOOK_NONE = 0, BOOK_DECL, BOOK_INIT, BOOK_DEREF, BOOK_ARRAY, BOOK_COMPILE };
  88 
  89 typedef struct BOOK_T BOOK_T;
  90 struct BOOK_T
  91 {
  92   int action, phase;
  93   char *idf;
  94   void *info;
  95   int number;
  96 };
  97 
  98 typedef struct UNIC_T UNIC_T;
  99 struct UNIC_T
 100 {
 101   char *fun;
 102 };
 103 
 104 //
 105 
 106 #define A68(z)         (common.z)
 107 #define A68_JOB        A68 (job)
 108 #define A68_STANDENV   A68 (standenv)
 109 #define A68_MCACHE(z)  A68 (mode_cache.z)
 110 
 111 #define A68_SP         A68 (stack_pointer)
 112 #define A68_FP         A68 (frame_pointer)
 113 #define A68_HP         A68 (heap_pointer)
 114 #define A68_GLOBALS    A68 (global_pointer)
 115 #define A68_STACK      A68 (stack_segment)
 116 #define A68_HEAP       A68 (heap_segment)
 117 #define A68_HANDLES    A68 (handle_segment)
 118 
 119 typedef struct GC_GLOBALS_T GC_GLOBALS_T;
 120 #define A68_GC(z)      A68 (gc.z)
 121 struct GC_GLOBALS_T
 122 {
 123   A68_HANDLE *available_handles, *busy_handles;
 124   UNSIGNED_T free_handles, max_handles, sweeps, refused, freed, total;
 125   unt preemptive;
 126   REAL_T seconds;
 127 };
 128 
 129 typedef struct INDENT_GLOBALS_T INDENT_GLOBALS_T;
 130 #define A68_INDENT(z)  A68 (indent.z)
 131 struct INDENT_GLOBALS_T
 132 {
 133   FILE_T fd;
 134   int ind, col;
 135   int indentation;
 136   BOOL_T use_folder;
 137 };
 138 
 139 #define MON_STACK_SIZE 32
 140 
 141 typedef struct MONITOR_GLOBALS_T MONITOR_GLOBALS_T;
 142 #define A68_MON(z)     A68 (mon.z)
 143 struct MONITOR_GLOBALS_T
 144 {
 145   ADDR_T finish_frame_pointer;
 146   char *watchpoint_expression;
 147   BOOL_T in_monitor;
 148   int break_proc_level;
 149   char symbol[BUFFER_SIZE], error_text[BUFFER_SIZE], expr[BUFFER_SIZE];
 150   char prompt[BUFFER_SIZE];
 151   BOOL_T prompt_set;
 152   int current_frame;
 153   int max_row_elems;
 154   int mon_errors;
 155   int _m_sp;
 156   int pos, attr;
 157   int tabs;
 158   MOID_T *_m_stack[MON_STACK_SIZE];
 159 };
 160 
 161 typedef struct MP_GLOBALS_T MP_GLOBALS_T;
 162 #define A68_MP(z)      A68 (mp.z)
 163 
 164 struct MP_GLOBALS_T
 165 {
 166   int mp_gamma_size;
 167   int mp_ln_10_size;
 168   int mp_ln_scale_size;
 169   int mp_one_size;
 170   int mp_pi_size;
 171   int varying_mp_digits;
 172   MP_T *mp_180_over_pi;
 173   MP_T **mp_gam_ck;
 174   MP_T *mp_half_pi;
 175   MP_T *mp_ln_10;
 176   MP_T *mp_ln_pi;
 177   MP_T *mp_ln_scale;
 178   MP_T *mp_one;
 179   MP_T *mp_pi;
 180   MP_T *mp_pi_over_180;
 181   MP_T *mp_sqrt_pi;
 182   MP_T *mp_sqrt_two_pi;
 183   MP_T *mp_two_pi;
 184 };
 185 
 186 #define MAX_BOOK 1024
 187 #define MAX_UNIC 2048
 188 
 189 typedef struct OPTIMISER_GLOBALS_T OPTIMISER_GLOBALS_T;
 190 #define A68_OPT(z)     A68 (optimiser.z)
 191 struct OPTIMISER_GLOBALS_T
 192 {
 193   int OPTION_CODE_LEVEL;
 194   int indentation;
 195   int code_errors;
 196   int procedures;
 197   BOOK_T cse_book[MAX_BOOK];
 198   int cse_pointer;
 199   DEC_T *root_idf;
 200   BOOL_T put_idf_comma;
 201   UNIC_T unic_functions[MAX_UNIC];
 202   int unic_pointer;
 203 };
 204 
 205 #if defined (BUILD_PARALLEL_CLAUSE)
 206 
 207 typedef struct A68_STACK_DESCRIPTOR A68_STACK_DESCRIPTOR;
 208 typedef struct A68_THREAD_CONTEXT A68_THREAD_CONTEXT;
 209 
 210 struct A68_STACK_DESCRIPTOR
 211 {
 212   ADDR_T cur_ptr, ini_ptr;
 213   BYTE_T *swap, *start;
 214   int bytes;
 215 };
 216 
 217 struct A68_THREAD_CONTEXT
 218 {
 219   pthread_t parent, id;
 220   A68_STACK_DESCRIPTOR stack, frame;
 221   NODE_T *unit;
 222   int stack_used;
 223   BYTE_T *thread_stack_offset;
 224   BOOL_T active;
 225 };
 226 
 227 // Set an upper limit for number of threads.
 228 // Note that _POSIX_THREAD_THREADS_MAX may be ULONG_MAX.
 229 
 230 #define THREAD_LIMIT   256
 231 
 232 #if (_POSIX_THREAD_THREADS_MAX < THREAD_LIMIT)
 233 #undef  THREAD_LIMIT
 234 #define THREAD_LIMIT   _POSIX_THREAD_THREADS_MAX
 235 #endif
 236 
 237 #if !defined _POSIX_THREAD_THREADS_MAX
 238 #define _POSIX_THREAD_THREADS_MAX	(THREAD_LIMIT)
 239 #endif
 240 
 241 #if (_POSIX_THREAD_THREADS_MAX < THREAD_LIMIT)
 242 #define THREAD_MAX     (_POSIX_THREAD_THREADS_MAX)
 243 #else
 244 #define THREAD_MAX     (THREAD_LIMIT)
 245 #endif
 246 
 247 typedef struct PARALLEL_GLOBALS_T PARALLEL_GLOBALS_T;
 248 #define A68_PAR(z)     A68 (parallel.z)
 249 struct PARALLEL_GLOBALS_T
 250 {
 251   ADDR_T fp0, sp0;
 252   BOOL_T abend_all_threads, exit_from_threads;
 253   A68_THREAD_CONTEXT context[THREAD_MAX];
 254   int par_return_code;
 255   int context_index;
 256   NODE_T *jump_label;
 257   jmp_buf *jump_buffer;
 258   pthread_mutex_t unit_sema;
 259   pthread_t main_thread_id;
 260   pthread_t parent_thread_id;
 261 };
 262 
 263 #endif
 264 
 265 typedef struct PARSER_GLOBALS_T PARSER_GLOBALS_T;
 266 #define A68_PARSER(z)  A68 (parser.z)
 267 struct PARSER_GLOBALS_T
 268 {
 269   TAG_T *error_tag;
 270   BOOL_T stop_scanner, read_error, no_preprocessing;
 271   char *scan_buf;
 272   int max_scan_buf_length, source_file_size;
 273   int reductions;
 274   int tag_number;
 275   jmp_buf bottom_up_crash_exit, top_down_crash_exit;
 276 };
 277 
 278 typedef struct GLOBALS_T GLOBALS_T;
 279 
 280 struct GLOBALS_T
 281 {
 282   MODULE_T job;
 283   A68_CHANNEL stand_in_channel, stand_out_channel, stand_back_channel;
 284   A68_CHANNEL stand_draw_channel, stand_error_channel, associate_channel, skip_channel;
 285   A68_REF stand_in, stand_out, stand_back, stand_error, skip_file;
 286   BYTE_T *stack_segment, *heap_segment, *handle_segment;
 287   ADDR_T frame_pointer, stack_pointer, heap_pointer, global_pointer;
 288   ADDR_T fixed_heap_pointer, temp_heap_pointer;
 289   ADDR_T frame_start, frame_end, stack_start, stack_end;
 290   unt frame_stack_size, expr_stack_size, heap_size, handle_pool_size, stack_size;
 291   unt stack_limit, frame_stack_limit, expr_stack_limit;
 292   unt storage_overhead;
 293   int global_level, max_lex_lvl;
 294   int new_nodes, new_modes, new_postulates, new_node_infos, new_genie_infos;
 295   int symbol_table_count, mode_count; 
 296   int term_heigth, term_width;
 297   int argc;
 298   BOOL_T in_execution;
 299   BOOL_T close_tty_on_exit;
 300   BYTE_T *system_stack_offset;
 301   MODES_T a68_modes;
 302   NODE_T **node_register;
 303   char a68_cmd_name[BUFFER_SIZE];
 304   char **argv;
 305   char output_line[BUFFER_SIZE], edit_line[BUFFER_SIZE], input_line[BUFFER_SIZE];
 306   char *marker[BUFFER_SIZE];
 307   REAL_T cputime_0;
 308   clock_t clock_res;
 309   BOOL_T halt_typing;
 310   BOOL_T heap_is_fluid;
 311   BOOL_T in_monitor;
 312   BOOL_T do_confirm_exit; 
 313   BOOL_T no_warnings;
 314   int chars_in_tty_line;
 315   POSTULATE_T *postulates, *top_postulate, *top_postulate_list;
 316   KEYWORD_T *top_keyword;
 317   TOKEN_T *top_token;
 318   NODE_T *f_entry;
 319   TAG_T *error_tag;
 320   int ret_code, ret_line_number, ret_char_number;
 321   jmp_buf genie_exit_label;
 322   A68_PROCEDURE on_gc_event;
 323   TABLE_T *standenv;
 324   char *f_plugin;
 325   BOOL_T curses_mode;
 326   SOID_T *top_soid_list;
 327   int max_simplout_size;
 328   OPTIONS_T *options;
 329   FILE_ENTRY file_entries[MAX_OPEN_FILES];
 330 // Private structs
 331   MODE_CACHE_T mode_cache;
 332   MONITOR_GLOBALS_T mon;
 333   GC_GLOBALS_T gc;
 334   PARSER_GLOBALS_T parser;
 335   OPTIMISER_GLOBALS_T optimiser;
 336   MP_GLOBALS_T mp;
 337   INDENT_GLOBALS_T indent;
 338 #if defined (BUILD_PARALLEL_CLAUSE)
 339   PARALLEL_GLOBALS_T parallel;
 340 #endif
 341 };
 342 
 343 extern GLOBALS_T common;
 344 
 345 #endif