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 / foreign.h < prev    next >
C/C++ Source or Header  |  2000-12-05  |  6KB  |  208 lines

  1. /* -*-C-*-
  2.  
  3. $Id: foreign.h,v 1.3 2000/12/05 21:23:44 cph Exp $
  4.  
  5. Copyright (c) 1992, 1999, 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 the primitive support for the foreign function */
  23. /* interface. */
  24.  
  25. struct foreign_function {
  26.   char * name;
  27.   PTR    applicable_function;
  28. };
  29.  
  30. typedef unsigned int HANDLE;
  31.  
  32. typedef struct foreign_function FOREIGN_FUNCTION;
  33.  
  34. struct foreign_object {
  35.   PTR    ptr;
  36.   HANDLE handle;
  37. };
  38.  
  39. typedef struct foreign_object FOREIGN_OBJECT;
  40.  
  41. #ifdef __HPUX__
  42. typedef shl_t LOAD_DESCRIPTOR;
  43. typedef unsigned long LOAD_ADDRESS;
  44. #endif
  45.  
  46. struct load_info {
  47.   LOAD_DESCRIPTOR load_module_descriptor;
  48.   LOAD_ADDRESS program_start;
  49.   LOAD_ADDRESS program_end;
  50.   LOAD_ADDRESS data_start;
  51.   LOAD_ADDRESS data_end;
  52. };
  53.  
  54. typedef struct load_info LOAD_INFO;  
  55.  
  56. #define index_to_handle(index)     ((HANDLE) index)
  57. #define handle_to_index(handle)    ((unsigned int) handle)
  58. #define handle_to_integer(handle) (long_to_integer ((unsigned long) handle))
  59. #define foreign_primtive_type_p(object) (FIXNUM_P (object))
  60. #define foreign_composite_type_p(object) (PAIR_P (object))
  61. #define which_composite_type(type) (PAIR_CAR (type))
  62. #define composite_type_field_types(type) (PAIR_CDR (type))
  63.  
  64. /* the following define should be in some other .h file */
  65. #define TEMP_FILE_NAME_MAX_LEN     L_tmpnam  /* in stdio.h */
  66.  
  67. /* The following should be ifdef'ed up the wazoo for different machines */
  68. #define DYNAMIC_COMPILE_SWITCHES  "+z"
  69.  
  70. /* These need to match the appropriate enumerations in foreign.scm */
  71. #define FOREIGN_FIRST_TYPE    0
  72. #define FOREIGN_INT         0
  73. #define FOREIGN_SHORT         1
  74. #define FOREIGN_LONG         2
  75. #define FOREIGN_CHAR         3
  76. #define FOREIGN_FLOAT         4
  77. #define FOREIGN_DOUBLE         5
  78. #define FOREIGN_STRING         6
  79. #define FOREIGN_PTR         7
  80. #define FOREIGN_STRUCT         8
  81. #define FOREIGN_UNION         9
  82. #define FOREIGN_LAST_TYPE    9
  83.  
  84. /* This is a bunch of stuff to figure out the alignment of fields in
  85.    structures */
  86.  
  87. /* This defines a union which is guaranteed to have the most restrictive
  88.    possible alignment constraint */
  89. union greatest_alignment {
  90.   int my_int;
  91.   short my_short;
  92.   long my_long;
  93.   char my_char;
  94.   float my_float;
  95.   double my_double;
  96.   char * my_string;
  97.   void * my_ptr;
  98. }
  99.  
  100. /* We hope that char's are the smallest sized objects */
  101. typedef char smallest_size;
  102.  
  103. struct int_field {
  104.   union greatest_alignment foo;
  105.   smallest_size bar;
  106.   int int_item;
  107. }
  108. #define INT_ALIGNMENT_MASK \
  109.         ((long) ((sizeof (int_field) - sizeof (int)) - 1))
  110.  
  111. struct short_field {
  112.   union greatest_alignment foo;
  113.   smallest_size bar;
  114.   short short_item;
  115. }
  116. #define SHORT_ALIGNMENT_MASK \
  117.         ((long) ((sizeof (short_field) - sizeof (short)) - 1))
  118.  
  119. struct long_field {
  120.   union greatest_alignment foo;
  121.   smallest_size bar;
  122.   long long_item;
  123. }
  124. #define LONG_ALIGNMENT_MASK \
  125.         ((long) ((sizeof (long_field) - sizeof (long)) - 1))
  126.  
  127. struct char_field {
  128.   union greatest_alignment foo;
  129.   smallest_size bar;
  130.   char char_item;
  131. }
  132. #define CHAR_ALIGNMENT_MASK \
  133.         ((long) ((sizeof (char_field) - sizeof (char)) - 1))
  134.  
  135. struct float_field {
  136.   union greatest_alignment foo;
  137.   smallest_size bar;
  138.   float float_item;
  139. }
  140. #define FLOAT_ALIGNMENT_MASK \
  141.         ((long) ((sizeof (float_field) - sizeof (float)) - 1))
  142.  
  143. struct double_field {
  144.   union greatest_alignment foo;
  145.   smallest_size bar;
  146.   double double_item;
  147. }
  148. #define DOUBLE_ALIGNMENT_MASK \
  149.         ((long) ((sizeof (double_field) - sizeof (double)) - 1))
  150.  
  151. struct string_field {
  152.   union greatest_alignment foo;
  153.   smallest_size bar;
  154.   char * string_item;
  155. }
  156. #define STRING_ALIGNMENT_MASK \
  157.         ((long) ((sizeof (string_field) - sizeof (char *)) - 1))
  158.  
  159. struct ptr_field {
  160.   union greatest_alignment foo;
  161.   smallest_size bar;
  162.   PTR ptr_item;
  163. }
  164. #define PTR_ALIGNMENT_MASK \
  165.         ((long) ((sizeof (ptr_field) - sizeof (PTR)) - 1))
  166.  
  167. struct struct_field {
  168.   union greatest_alignment foo;
  169.   smallest_size bar;
  170.   struct greatest_alignment2 struct_item;
  171. }
  172.  
  173. #define ALIGN_FOREIGN_POINTER(ptr,type) \
  174. #  if (type == FOREIGN_INT) \
  175.      (((int *) (ptr & INT_ALIGNMENT_MASK)) + 1) \
  176. #  else \
  177. #  if (type == FOREIGN_SHORT) \
  178.      (((short *) (ptr & SHORT_ALIGNMENT_MASK)) + 1) \
  179. #  else \
  180. #  if (type == FOREIGN_LONG) \
  181.      (((long *) (ptr & LONG_ALIGNMENT_MASK)) + 1) \
  182. #  else \
  183. #  if (type == FOREIGN_CHAR) \
  184.      (((char *) (ptr & CHAR_ALIGNMENT_MASK)) + 1) \
  185. #  else \
  186. #  if (type == FOREIGN_FLOAT) \
  187.      (((float *) (ptr & FLOAT_ALIGNMENT_MASK)) + 1) \
  188. #  else \
  189. #  if (type == FOREIGN_DOUBLE) \
  190.      (((double *) (ptr & DOUBLE_ALIGNMENT_MASK)) + 1) \
  191. #  else \
  192. #  if (type == FOREIGN_STRING) \
  193.      (((unsigned char *) (ptr & STRING_ALIGNMENT_MASK)) + 1) \
  194. #  else \
  195. #  if (type == FOREIGN_PTR) \
  196.      (((PTR) (ptr & PTR_ALIGNMENT_MASK)) + 1) \
  197. #  endif \
  198. #  endif \
  199. #  endif \
  200. #  endif \
  201. #  endif \
  202. #  endif \
  203. #  endif \
  204. #  endif
  205.  
  206.  
  207. /* End of alignment junk */
  208.