a68g.h

     
   1  //! @file a68g.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 [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  //! Master include file.
  25  
  26  #if ! defined (__A68G_H__)
  27  #define __A68G_H__
  28  
  29  // Debugging switch, only useful during development.
  30  #undef A68_DEBUG
  31  
  32  // Early typedef
  33  #define unt unsigned
  34  
  35  // Configuration
  36  
  37  #include "a68g-platform.h"
  38  #include "a68g-includes.h"
  39  
  40  // Build switches depending on platform.
  41  
  42  #if ((defined (BUILD_LINUX) || defined (BUILD_BSD)) && defined (HAVE_DL))
  43  #  if defined (HAVE_QUADMATH)
  44  #    define BUILD_A68_COMPILER
  45  #  else
  46  #    undef BUILD_A68_COMPILER
  47  #  endif
  48  #else
  49  #  undef BUILD_A68_COMPILER
  50  #endif
  51  
  52  #if defined (BUILD_LINUX)
  53  #  define BUILD_UNIX
  54  #elif defined (BUILD_BSD)
  55  #  define BUILD_UNIX
  56  #elif defined (BUILD_CYGWIN)
  57  #  define BUILD_UNIX
  58  #elif defined (BUILD_HAIKU)
  59  #  define BUILD_UNIX
  60  #endif
  61  
  62  // REAL_T should be a REAL*8 for external libs.
  63  typedef double REAL_T; 
  64  
  65  #if (A68_LEVEL >= 3)
  66  #  include <quadmath.h>
  67  #endif
  68  
  69  // Can we access the internet?
  70  #if defined (BUILD_WIN32)
  71  #  undef BUILD_HTTP
  72  #else
  73  #  if (defined (HAVE_NETDB_H) && defined (HAVE_NETINET_IN_H) && defined (HAVE_SYS_SOCKET_H))
  74  #    if (defined (BUILD_LINUX) || defined (BUILD_BSD) || defined (BUILD_HAIKU))
  75  #      define BUILD_HTTP
  76  #    endif
  77  #  endif
  78  #endif
  79  
  80  // Compatibility.
  81  
  82  #if ! defined (O_BINARY)
  83  #  define O_BINARY 0x0000
  84  #endif
  85  
  86  // Forward type definitions.
  87  
  88  typedef struct NODE_T NODE_T;
  89  typedef unt STATUS_MASK_T, BOOL_T;
  90  
  91  // Decide the internal representation of A68 modes.
  92  
  93  #include "a68g-stddef.h"
  94  
  95  #define ALIGNED __attribute__((aligned (sizeof (A68_ALIGN_T))))
  96  
  97  #if (A68_LEVEL >= 3)
  98  #  include "a68g-level-3.h"
  99  #else // Vintage Algol 68 Genie (versions 1 and 2).
 100  #  include "a68g-generic.h"
 101  #endif
 102  
 103  #define MP_REAL_RADIX ((MP_REAL_T) MP_RADIX)
 104  
 105  #if defined (BUILD_WIN32)
 106  typedef unt __off_t;
 107  #  if defined (__MSVCRT__) && defined (_environ)
 108  #    undef _environ
 109  #  endif
 110  #endif
 111  
 112  #define A68_ALIGN(s) ((int) ((s) % A68_ALIGNMENT) == 0 ? (s) : ((s) - (s) % A68_ALIGNMENT + A68_ALIGNMENT))
 113  #define A68_ALIGNMENT ((int) (sizeof (A68_ALIGN_T)))
 114  
 115  #include "a68g-defines.h"
 116  #include "a68g-stack.h"
 117  #include "a68g-masks.h"
 118  #include "a68g-enums.h"
 119  #include "a68g-types.h"
 120  #include "a68g-nil.h"
 121  #include "a68g-diagnostics.h"
 122  #include "a68g-common.h"
 123  #include "a68g-lib.h"
 124  
 125  // Global declarations
 126  
 127  extern BOOL_T a68_mkstemp (char *, int, mode_t);
 128  extern BYTE_T *get_fixed_heap_space (size_t);
 129  extern BYTE_T *get_heap_space (size_t);
 130  extern BYTE_T *get_temp_heap_space (size_t);
 131  extern char *a68_basename (char *);
 132  extern char *a68_dirname (char *);
 133  extern char *a68_relpath (char *, char *, char *);
 134  extern char *ctrl_char (int);
 135  extern char *moid_to_string (MOID_T *, int, NODE_T *);
 136  extern char *new_fixed_string (char *);
 137  extern char *new_string (char *, ...);
 138  extern char *new_temp_string (char *);
 139  extern char *non_terminal_string (char *, int);
 140  extern char *read_string_from_tty (char *);
 141  extern char *standard_environ_proc_name (GPROC);
 142  extern int get_row_size (A68_TUPLE *, int);
 143  extern int moid_digits (MOID_T *);
 144  extern int moid_size (MOID_T *);
 145  extern int (snprintf) (char *, size_t, const char *, ...); // Prevent macro substitution on Darwin.
 146  extern void *a68_alloc (size_t, const char *, int);
 147  extern void a68_exit (int);
 148  extern void a68_free (void *);
 149  extern void a68_getty (int *, int *);
 150  extern void *a68_memmove (void *, void *, size_t);
 151  extern void abend (char *, char *, char *, int);
 152  extern void announce_phase (char *);
 153  extern void apropos (FILE_T, char *, char *);
 154  extern void bufcat (char *, char *, int);
 155  extern void bufcpy (char *, char *, int);
 156  extern void default_mem_sizes (int);
 157  extern void discard_heap (void);
 158  extern void free_file_entries (void);
 159  extern void free_syntax_tree (NODE_T *);
 160  extern void get_stack_size (void);
 161  extern void indenter (MODULE_T *);
 162  extern void init_curses (void);
 163  extern void init_file_entries (void);
 164  extern void init_file_entry (int);
 165  extern void init_heap (void);
 166  extern void init_rng (unt);
 167  extern void init_tty (void);
 168  extern void install_signal_handlers (void);
 169  extern void online_help (FILE_T);
 170  extern void state_version (FILE_T);
 171  
 172  // Below from R mathlib
 173  
 174  extern void GetRNGstate(void);
 175  extern void PutRNGstate(void);
 176  extern REAL_T a68_unif_rand(void);
 177  extern REAL_T R_unif_index(REAL_T);
 178  
 179  #endif