a68g-common.h

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


© 2002-2024 J.M. van der Veer (jmvdveer@xs4all.nl)