home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mitsch75.zip / scheme-7_5_17-src.zip / scheme-7.5.17 / src / microcode / psbmap.h < prev    next >
C/C++ Source or Header  |  2000-12-05  |  7KB  |  279 lines

  1. /* -*-C-*-
  2.  
  3. $Id: psbmap.h,v 9.44 2000/12/05 21:23:48 cph Exp $
  4.  
  5. Copyright (c) 1987-2000 Massachusetts Institute of Technology
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or (at
  10. your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful, but
  13. WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21.  
  22. /* This file contains macros and declarations for "bintopsb.c"
  23.    and "psbtobin.c". 
  24.  */
  25.  
  26. #ifndef PSBMAP_H_INCLUDED
  27. #define PSBMAP_H_INCLUDED
  28.  
  29. /* These definitions insure that the appropriate code is extracted
  30.    from the included files.
  31. */
  32.  
  33. #define fast register
  34.  
  35. #include "config.h"
  36. #include <stdio.h>
  37. #ifdef STDC_HEADERS
  38. #  include <stdlib.h>
  39. #endif
  40. #include "types.h"
  41. #include "object.h"
  42. #include "bignum.h"
  43. #include "bignmint.h"
  44. #include "bitstr.h"
  45. #include "sdata.h"
  46. #include "const.h"
  47. #include "gccode.h"
  48. #include "cmptype.h"
  49. #define boolean Boolean
  50. #include "comlin.h"
  51.  
  52. #ifndef COMPILER_PROCESSOR_TYPE
  53. #define COMPILER_PROCESSOR_TYPE COMPILER_NONE_TYPE
  54. #endif
  55.  
  56. extern double
  57.   EXFUN (frexp, (double, int *)),
  58.   EXFUN (ldexp, (double, int));
  59.  
  60. #define PORTABLE_VERSION    6
  61.  
  62. /* Number of objects which, when traced recursively, point at all other
  63.    objects dumped.
  64.    Currently the dumped object, and the compiler utilities.
  65.  */
  66.  
  67. #define NROOTS            2
  68.  
  69. /* Types to recognize external object references.  Any occurrence of these
  70.    (which are external types and thus handled separately) means a reference
  71.    to an external object.
  72.  */
  73.  
  74. #define CONSTANT_CODE            TC_FIXNUM
  75. #define HEAP_CODE            TC_CHARACTER
  76. #define PURE_CODE            TC_BIG_FIXNUM
  77.  
  78. #define fixnum_to_bits            FIXNUM_LENGTH
  79. #define hex_digits(nbits)        (((nbits) + 3) / 4)
  80.  
  81. #define to_pointer BYTES_TO_WORDS
  82.  
  83. #define float_to_pointer                        \
  84.   BYTES_TO_WORDS(sizeof(double))
  85.  
  86. #ifndef FLOATING_ALIGNMENT
  87.  
  88. #define flonum_to_pointer(nfloats)                    \
  89.   ((nfloats) * (1 + float_to_pointer))
  90.  
  91. #else /* FLOATING_ALIGNMENT */
  92.  
  93. /* When computing the space needed for flonums, the worst case is that
  94.    every flonum needs alignment.  To estimate the space needed, add
  95.    padding to each flonum to round it up to an alignment boundary.  */
  96.  
  97. #define flonum_to_pointer(nfloats)                    \
  98.   ((nfloats)                                \
  99.    * (((((1 + float_to_pointer) * (sizeof (char)))            \
  100.     & FLOATING_ALIGNMENT)                        \
  101.        == 0)                                \
  102.       ? (1 + float_to_pointer)                        \
  103.       : ((((1 + float_to_pointer) * (sizeof (char)))            \
  104.       + ((FLOATING_ALIGNMENT + 1)                    \
  105.          - (((1 + float_to_pointer) * (sizeof (char)))        \
  106.         & FLOATING_ALIGNMENT)))                    \
  107.      / (sizeof (char)))))
  108.  
  109. #endif /* FLOATING_ALIGNMENT */
  110.  
  111. #define char_to_pointer(nchars)                        \
  112.   BYTES_TO_WORDS(nchars)
  113.  
  114. #define pointer_to_char(npoints)                    \
  115.   ((npoints) * sizeof(SCHEME_OBJECT))
  116.  
  117. /* Status flags */
  118.  
  119. #define COMPACT_P    (1 << 0)
  120. #define NULL_NMV_P    (1 << 1)
  121. #define COMPILED_P    (1 << 2)
  122. #define NMV_P        (1 << 3)
  123. #define BAND_P        (1 << 4)
  124. #define C_CODE_P    (1 << 5)
  125.  
  126. #define MAKE_FLAGS()                            \
  127. (  (compact_p ? COMPACT_P : 0)                        \
  128.  | (null_nmv_p ? NULL_NMV_P : 0)                    \
  129.  | (compiled_p ? COMPILED_P : 0)                    \
  130.  | (nmv_p ? NMV_P : 0)                            \
  131.  | (band_p ? BAND_P : 0)                        \
  132.  | (c_compiled_p ? C_CODE_P : 0))
  133.  
  134. #define READ_FLAGS(f) do                        \
  135. {                                    \
  136.   compact_p = ((f) & COMPACT_P);                    \
  137.   null_nmv_p  = ((f) & NULL_NMV_P);                    \
  138.   compiled_p = ((f) & COMPILED_P);                    \
  139.   nmv_p = ((f) & NMV_P);                        \
  140.   band_p = ((f) & BAND_P);                        \
  141.   c_compiled_p = ((f) & C_CODE_P);                    \
  142. } while (0)
  143.  
  144. /*
  145.   If true, make all integers fixnums if possible, and all strings as
  146.   short as possible (trim extra stuff).
  147.  */
  148.  
  149. static Boolean compact_p = true;
  150.  
  151. /* If true, null out all elements of random non-marked vectors. */
  152.  
  153. static Boolean null_nmv_p = false;
  154.  
  155. /* If true, the portable file contains compiled code. */
  156.  
  157. static Boolean compiled_p = false;
  158.  
  159. /* If true, the portable file contains "random" non-marked vectors. */
  160.  
  161. static Boolean nmv_p = false;
  162.  
  163. #define TC_C_COMPILED_TAG            TC_MANIFEST_CLOSURE
  164. #define C_COMPILED_FAKE_NMV            0
  165. #define C_COMPILED_ENTRY_FORMAT            1
  166. #define C_COMPILED_ENTRY_CODE            2
  167. #define C_COMPILED_CLOSURE_HEADER        3
  168. #define C_COMPILED_MULTI_CLOSURE_HEADER        4
  169. #define C_COMPILED_LINKAGE_HEADER        5
  170. #define C_COMPILED_RAW_QUAD            6
  171. #define C_COMPILED_EXECUTE_ENTRY        7
  172. #define C_COMPILED_EXECUTE_ARITY        8
  173.  
  174. /* Global data */
  175.  
  176. #ifndef HEAP_IN_LOW_MEMORY
  177. SCHEME_OBJECT * memory_base;
  178. #endif
  179.  
  180. static long
  181.   compiler_processor_type = COMPILER_PROCESSOR_TYPE,
  182.   compiler_interface_version = 0;
  183.  
  184. static SCHEME_OBJECT
  185.   compiler_utilities = SHARP_F;
  186.  
  187. /* Utilities */
  188.  
  189. static char
  190.   *input_file_name = "-",
  191.   *output_file_name = "-";
  192.  
  193. FILE *input_file, *output_file;
  194.  
  195. static Boolean
  196. DEFUN (strequal, (s1, s2), register char * s1 AND register char * s2)
  197. {
  198.   for ( ; *s1 != '\0'; s1++, s2++)
  199.     if (*s1 != *s2)
  200.       return (false);
  201.   return (*s2 == '\0');
  202. }
  203.  
  204. static void
  205. DEFUN (setup_io, (input_mode, output_mode),
  206.        CONST char * input_mode AND CONST char * output_mode)
  207. {
  208.   if (strequal (input_file_name, "-"))
  209.     input_file = stdin;
  210.   else
  211.   {
  212.     input_file = (fopen (input_file_name, input_mode));
  213.     if (input_file == ((FILE *) NULL))
  214.     {
  215.       fprintf (stderr, "%s: failed to open %s for input.\n",
  216.            program_name, input_file_name);
  217.       exit (1);
  218.     }
  219.   }
  220.  
  221.   if (strequal (output_file_name, "-"))
  222.     output_file = stdout;
  223.   else
  224.   {
  225.     output_file = (fopen (output_file_name, output_mode));
  226.     if (output_file == ((FILE *) NULL))
  227.     {
  228.       fprintf (stderr, "%s: failed to open %s for output.\n",
  229.            program_name, output_file_name);
  230.       fclose (input_file);
  231.       exit (1);
  232.     }
  233.   }
  234.   return;
  235. }
  236.  
  237. static void
  238. DEFUN (quit, (code), int code)
  239. {
  240.   fclose(input_file);
  241.   fclose(output_file);
  242. #ifdef vms
  243.   /* This assumes that it is only invoked with 0 in tail recursive psn. */
  244.   if (code != 0)
  245.     exit(code);
  246.   else
  247.     return;
  248. #else /* not vms */
  249.   exit(code);
  250. #endif /*vms */
  251. }
  252.  
  253. #ifndef TERM_COMPILER_DEATH
  254. #define TERM_COMPILER_DEATH 0
  255. #endif
  256.  
  257. void
  258. DEFUN (gc_death, (code, message, scan, free),
  259.        long code
  260.        AND char * message
  261.        AND SCHEME_OBJECT * scan
  262.        AND SCHEME_OBJECT * free)
  263. {
  264.   fprintf (stderr, "%s: %s\n", program_name, message);
  265.   quit (1);
  266. }
  267.  
  268. /* Include the command line parser */
  269.  
  270. #include "comlin.c"
  271.  
  272. #define INPUT_KEYWORD()                        \
  273. KEYWORD("input", &input_file_name, STRING_KYWRD, SFRMT, NULL)
  274.  
  275. #define OUTPUT_KEYWORD()                    \
  276. KEYWORD("output", &output_file_name, STRING_KYWRD, SFRMT, NULL)
  277.  
  278. #endif /* PSBMAP_H_INCLUDED */
  279.