scheme48.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. /* This file was generated automatically.
  2. It's probably not a good idea to change it. */
  3. #ifndef _H_SCHEME48
  4. #define _H_SCHEME48
  5. /* Copyright (c) 1993-2005 by Richard Kelsey and Jonathan Rees.
  6. See file COPYING. */
  7. #ifdef __cplusplus
  8. extern "C"
  9. {
  10. #endif
  11. /*
  12. * For building and linking DLLs on Windows, we need to mark functions
  13. * the DLL calls in Scheme 48 and vice versa explicitly---and differently
  14. * depending on whether we're compiling the DLL or Scheme 48 itself.
  15. *
  16. * Therefore, on Windows, we assume that __COMPILING_SCHEME48_ITSELF__
  17. * is defined when Scheme 48 itself is being compiled, and not when
  18. * we're compiling something external against it.
  19. */
  20. #ifdef _WIN32
  21. # ifdef __COMPILING_SCHEME48_ITSELF__
  22. # define S48_EXTERN_ADD_ONS __declspec(dllexport)
  23. # else
  24. # define S48_EXTERN_ADD_ONS __declspec(dllimport)
  25. # endif
  26. #endif
  27. #ifndef S48_EXTERN_ADD_ONS
  28. # define S48_EXTERN_ADD_ONS
  29. #endif
  30. #define S48_EXTERN extern S48_EXTERN_ADD_ONS
  31. #include "scheme48write-barrier.h"
  32. typedef long s48_value;
  33. #define NO_ERRORS 0 /* errno value */
  34. /* Misc stuff */
  35. #define S48_EQ_P(v1, v2) ((v1) == (v2))
  36. /* Superceded name for the above definition, retained for compatibility. */
  37. #define S48_EQ(v1, v2) ((v1) == (v2))
  38. #define S48_MAX_FIXNUM_VALUE ((1 << 29) - 1)
  39. #define S48_MIN_FIXNUM_VALUE (-1 << 29)
  40. S48_EXTERN int s48_stob_has_type(s48_value, int);
  41. S48_EXTERN long s48_stob_length(s48_value, int);
  42. S48_EXTERN long s48_stob_byte_length(s48_value, int);
  43. S48_EXTERN s48_value s48_stob_ref(s48_value, int, long);
  44. S48_EXTERN void s48_stob_set(s48_value, int, long, s48_value);
  45. S48_EXTERN char s48_stob_byte_ref(s48_value, int, long);
  46. S48_EXTERN void s48_stob_byte_set(s48_value, int, long, char);
  47. S48_EXTERN char * s48_register_gc_rootB(char *);
  48. S48_EXTERN void s48_unregister_gc_rootB(char *);
  49. S48_EXTERN void s48_push_gc_rootsB(char *, long);
  50. S48_EXTERN char s48_pop_gc_rootsB(void);
  51. S48_EXTERN char s48_pop_gc_roots_up_to_markerB(char *);
  52. S48_EXTERN s48_value s48_enter_char(unsigned char);
  53. S48_EXTERN unsigned char s48_extract_char(s48_value);
  54. S48_EXTERN s48_value s48_enter_fixnum(long);
  55. S48_EXTERN long s48_extract_fixnum(s48_value);
  56. S48_EXTERN s48_value s48_enter_integer(long);
  57. S48_EXTERN long s48_extract_integer(s48_value);
  58. S48_EXTERN s48_value s48_enter_double(double);
  59. S48_EXTERN double s48_extract_double(s48_value);
  60. S48_EXTERN s48_value s48_cons(s48_value, s48_value);
  61. S48_EXTERN s48_value s48_enter_string(char *);
  62. S48_EXTERN char * s48_extract_string(s48_value);
  63. S48_EXTERN s48_value s48_enter_substring(char *, long);
  64. S48_EXTERN s48_value s48_enter_byte_vector(char *, long);
  65. S48_EXTERN char * s48_extract_byte_vector(s48_value);
  66. S48_EXTERN s48_value s48_make_string(int, char);
  67. S48_EXTERN s48_value s48_make_vector(int, s48_value);
  68. S48_EXTERN s48_value s48_make_byte_vector(int);
  69. S48_EXTERN s48_value s48_make_record(s48_value);
  70. S48_EXTERN s48_value s48_make_weak_pointer(s48_value);
  71. S48_EXTERN void s48_check_record_type(s48_value, s48_value);
  72. S48_EXTERN long s48_length(s48_value);
  73. S48_EXTERN s48_value s48_enter_pointer(void *);
  74. S48_EXTERN s48_value s48_get_imported_binding(char *);
  75. S48_EXTERN void s48_define_exported_binding(char *, s48_value);
  76. S48_EXTERN s48_value s48_set_channel_os_index(s48_value, long);
  77. S48_EXTERN s48_value s48_add_channel(s48_value, s48_value, long);
  78. S48_EXTERN void s48_close_channel(long);
  79. S48_EXTERN s48_value s48_call_scheme(s48_value proc, long nargs, ...);
  80. #define S48_EXPORT_FUNCTION(p) (s48_define_exported_binding(#p, s48_enter_pointer((void*) p)))
  81. #define S48_MAKE_VALUE(type) (s48_make_byte_vector(sizeof(type)))
  82. S48_EXTERN void * s48_value_pointer(s48_value);
  83. #define S48_EXTRACT_VALUE_POINTER(x, type) ((type *) s48_value_pointer(x))
  84. #define S48_EXTRACT_VALUE(x, type) (*(S48_EXTRACT_VALUE_POINTER((x), type)))
  85. #define S48_SET_VALUE(x, type, v) (S48_EXTRACT_VALUE((x), type) = (v))
  86. #define S48_UNSAFE_EXTRACT_VALUE_POINTER(x, type) \
  87. (S48_ADDRESS_AFTER_HEADER((x), type))
  88. #define S48_UNSAFE_EXTRACT_VALUE(x, type) \
  89. (*(S48_UNSAFE_EXTRACT_VALUE_POINTER((x), type)))
  90. #define S48_UNSAFE_SET_VALUE(x, type, v) \
  91. (S48_UNSAFE_EXTRACT_VALUE((x), type) = (v))
  92. #define S48_UNSAFE_EXTRACT_DOUBLE(x) \
  93. (*(S48_ADDRESS_AFTER_HEADER((x), double)))
  94. #define S48_DECLARE_GC_PROTECT(n) long ___gc_buffer[(n)+2]
  95. #define S48_GC_PROTECT_1(v) \
  96. (___gc_buffer[2]=(long)&(v), \
  97. s48_push_gc_rootsB((char *) ___gc_buffer, 1))
  98. #define S48_GC_PROTECT_2(v1, v2) \
  99. (___gc_buffer[2]=(long)&(v1), ___gc_buffer[3]=(long)&(v2), \
  100. s48_push_gc_rootsB((char *) ___gc_buffer, 2))
  101. #define S48_GC_PROTECT_3(v1, v2, v3) \
  102. (___gc_buffer[2]=(long)&(v1), \
  103. ___gc_buffer[3]=(long)&(v2), \
  104. ___gc_buffer[4]=(long)&(v3), \
  105. s48_push_gc_rootsB((char *) ___gc_buffer, 3))
  106. #define S48_GC_PROTECT_4(v1, v2, v3, v4) \
  107. (___gc_buffer[2]=(long)&(v1), \
  108. ___gc_buffer[3]=(long)&(v2), \
  109. ___gc_buffer[4]=(long)&(v3), \
  110. ___gc_buffer[5]=(long)&(v4), \
  111. s48_push_gc_rootsB((char *) ___gc_buffer, 4))
  112. #define S48_GC_PROTECT_5(v1, v2, v3, v4, v5) \
  113. (___gc_buffer[2]=(long)&(v1), \
  114. ___gc_buffer[3]=(long)&(v2), \
  115. ___gc_buffer[4]=(long)&(v3), \
  116. ___gc_buffer[5]=(long)&(v4), \
  117. ___gc_buffer[6]=(long)&(v5), \
  118. s48_push_gc_rootsB((char *) ___gc_buffer, 5))
  119. #define S48_GC_PROTECT_6(v1, v2, v3, v4, v5, v6) \
  120. (___gc_buffer[2]=(long)&(v1), \
  121. ___gc_buffer[3]=(long)&(v2), \
  122. ___gc_buffer[4]=(long)&(v3), \
  123. ___gc_buffer[5]=(long)&(v4), \
  124. ___gc_buffer[6]=(long)&(v5), \
  125. ___gc_buffer[7]=(long)&(v6), \
  126. s48_push_gc_rootsB((char *) ___gc_buffer, 6))
  127. #define S48_GC_PROTECT_7(v1, v2, v3, v4, v5, v6, v7) \
  128. (___gc_buffer[2]=(long)&(v1), \
  129. ___gc_buffer[3]=(long)&(v2), \
  130. ___gc_buffer[4]=(long)&(v3), \
  131. ___gc_buffer[5]=(long)&(v4), \
  132. ___gc_buffer[6]=(long)&(v5), \
  133. ___gc_buffer[7]=(long)&(v6), \
  134. ___gc_buffer[8]=(long)&(v7), \
  135. s48_push_gc_rootsB((char *) ___gc_buffer, 7))
  136. #define S48_GC_PROTECT_8(v1, v2, v3, v4, v5, v6, v7, v8) \
  137. (___gc_buffer[2]=(long)&(v1), \
  138. ___gc_buffer[3]=(long)&(v2), \
  139. ___gc_buffer[4]=(long)&(v3), \
  140. ___gc_buffer[5]=(long)&(v4), \
  141. ___gc_buffer[6]=(long)&(v5), \
  142. ___gc_buffer[7]=(long)&(v6), \
  143. ___gc_buffer[8]=(long)&(v7), \
  144. ___gc_buffer[9]=(long)&(v8), \
  145. s48_push_gc_rootsB((char *) ___gc_buffer, 8))
  146. #define S48_GC_PROTECT_9(v1, v2, v3, v4, v5, v6, v7, v8, v9) \
  147. (___gc_buffer[2]=(long)&(v1), \
  148. ___gc_buffer[3]=(long)&(v2), \
  149. ___gc_buffer[4]=(long)&(v3), \
  150. ___gc_buffer[5]=(long)&(v4), \
  151. ___gc_buffer[6]=(long)&(v5), \
  152. ___gc_buffer[7]=(long)&(v6), \
  153. ___gc_buffer[8]=(long)&(v7), \
  154. ___gc_buffer[9]=(long)&(v8), \
  155. ___gc_buffer[10]=(long)&(v9), \
  156. s48_push_gc_rootsB((char *) ___gc_buffer, 9))
  157. #define S48_GC_PROTECT_10(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) \
  158. (___gc_buffer[2]=(long)&(v1), \
  159. ___gc_buffer[3]=(long)&(v2), \
  160. ___gc_buffer[4]=(long)&(v3), \
  161. ___gc_buffer[5]=(long)&(v4), \
  162. ___gc_buffer[6]=(long)&(v5), \
  163. ___gc_buffer[7]=(long)&(v6), \
  164. ___gc_buffer[8]=(long)&(v7), \
  165. ___gc_buffer[9]=(long)&(v8), \
  166. ___gc_buffer[10]=(long)&(v9), \
  167. ___gc_buffer[11]=(long)&(v10), \
  168. s48_push_gc_rootsB((char *) ___gc_buffer, 10))
  169. #define S48_GC_UNPROTECT() \
  170. do { if (! s48_pop_gc_rootsB()) \
  171. s48_raise_scheme_exception( S48_EXCEPTION_GC_PROTECTION_MISMATCH, 0); \
  172. } while(0)
  173. #define S48_GC_PROTECT_GLOBAL(v) ((void*)(s48_register_gc_rootB((char *)&(v))))
  174. #define S48_GC_UNPROTECT_GLOBAL(f) (s48_unregister_gc_rootB((char *)(f)))
  175. /* Exceptions */
  176. S48_EXTERN void s48_raise_scheme_exception(long type, long nargs, ...);
  177. S48_EXTERN void s48_raise_argument_type_error(s48_value value);
  178. S48_EXTERN void s48_raise_argument_number_error(s48_value value,
  179. s48_value min,
  180. s48_value max);
  181. S48_EXTERN void s48_raise_range_error(s48_value value,
  182. s48_value min,
  183. s48_value max);
  184. S48_EXTERN void s48_raise_closed_channel_error();
  185. S48_EXTERN void s48_raise_os_error(int the_errno);
  186. S48_EXTERN void s48_raise_string_os_error(char *reason);
  187. S48_EXTERN void s48_raise_out_of_memory_error();
  188. /* Old names retained for compatibility; use the versions with 'ument_'
  189. after the '_arg'. */
  190. S48_EXTERN void s48_raise_argument_type_error(s48_value value);
  191. S48_EXTERN void s48_raise_argument_number_error(s48_value value,
  192. s48_value min,
  193. s48_value max);
  194. /* Type checking */
  195. #define S48_CHECK_PAIR(v) do { if (!S48_PAIR_P(v)) s48_raise_argument_type_error(v); } while (0)
  196. #define S48_CHECK_FIXNUM(v) do { if (!S48_FIXNUM_P(v)) s48_raise_argument_type_error(v); } while (0)
  197. #define S48_CHECK_STRING(v) do { if (!S48_STRING_P(v)) s48_raise_argument_type_error(v); } while (0)
  198. #define S48_CHECK_CHANNEL(v) do { if (!S48_CHANNEL_P(v)) s48_raise_argument_type_error(v); } while (0)
  199. #define S48_CHECK_RECORD(v) do { if (!S48_RECORD_P(v)) s48_raise_argument_type_error(v); } while (0)
  200. #define S48_CHECK_VALUE(v) do { if (!S48_BYTE_VECTOR_P(v)) s48_raise_argument_type_error(v); } while (0)
  201. #define S48_CHECK_EXPORT_BINDING(v) do { if (!S48_EXPORT_BINDING_P(v)) s48_raise_argument_type_error(v); } while (0)
  202. #define S48_CHECK_BOOLEAN(v) \
  203. do { s48_value s48_temp = (v); \
  204. if (s48_temp != S48_TRUE && s48_temp != S48_FALSE) \
  205. s48_raise_argument_type_error(v); } while (0)
  206. #define S48_VALUE_P(v) (S48_BYTE_VECTOR_P(v))
  207. #define S48_TRUE_P(v) ((v) == S48_TRUE)
  208. #define S48_FALSE_P(v) ((v) == S48_FALSE)
  209. #define S48_EXTRACT_BOOLEAN(v) ((v) != S48_FALSE)
  210. #define S48_ENTER_BOOLEAN(v) ((v) ? S48_TRUE : S48_FALSE)
  211. S48_EXTERN void s48_check_record_type(s48_value record, s48_value type_binding);
  212. #define S48_SHARED_BINDING_CHECK(binding) \
  213. do { if (S48_UNSPECIFIC == S48_SHARED_BINDING_REF(binding)) \
  214. s48_raise_scheme_exception(S48_EXCEPTION_UNBOUND_EXTERNAL_NAME, 1, \
  215. S48_SHARED_BINDING_NAME(binding)); \
  216. } while(0)
  217. #ifdef __cplusplus
  218. /* closing brace for extern "C" */
  219. }
  220. #endif
  221. #define S48_FIXNUM_TAG 0
  222. #define S48_FIXNUM_P(x) (((long)(x) & 3L) == S48_FIXNUM_TAG)
  223. #define S48_IMMEDIATE_TAG 1
  224. #define S48_IMMEDIATE_P(x) (((long)(x) & 3L) == S48_IMMEDIATE_TAG)
  225. #define S48_HEADER_TAG 2
  226. #define S48_HEADER_P(x) (((long)(x) & 3L) == S48_HEADER_TAG)
  227. #define S48_STOB_TAG 3
  228. #define S48_STOB_P(x) (((long)(x) & 3L) == S48_STOB_TAG)
  229. #define S48_UNSAFE_ENTER_FIXNUM(n) ((s48_value)((n) << 2))
  230. #define S48_UNSAFE_EXTRACT_FIXNUM(x) ((long)(x) >> 2)
  231. #define S48_MISC_IMMEDIATE(n) ((s48_value)(S48_IMMEDIATE_TAG | ((n) << 2)))
  232. #define S48_FALSE (S48_MISC_IMMEDIATE(0))
  233. #define S48_TRUE (S48_MISC_IMMEDIATE(1))
  234. #define S48_CHAR (S48_MISC_IMMEDIATE(2))
  235. #define S48_UNSPECIFIC (S48_MISC_IMMEDIATE(3))
  236. #define S48_UNDEFINED (S48_MISC_IMMEDIATE(4))
  237. #define S48_EOF (S48_MISC_IMMEDIATE(5))
  238. #define S48_NULL (S48_MISC_IMMEDIATE(6))
  239. #define S48_UNRELEASED (S48_MISC_IMMEDIATE(7))
  240. #define S48_UNSAFE_ENTER_CHAR(c) (S48_CHAR | ((c) << 8))
  241. #define S48_UNSAFE_EXTRACT_CHAR(x) ((unsigned char)((x) >> 8))
  242. #define S48_CHAR_P(x) ((((long) (x)) & 0xff) == S48_CHAR)
  243. #define S48_ADDRESS_AFTER_HEADER(x, type) ((type *)((x) - S48_STOB_TAG))
  244. #define S48_STOB_REF(x, i) (S48_ADDRESS_AFTER_HEADER(x, s48_value)[i])
  245. #define S48_STOB_BYTE_REF(x, i) (((char *)S48_ADDRESS_AFTER_HEADER(x, s48_value))[i])
  246. #define S48_STOB_SET(x, i, v) do { s48_value __stob_set_x = (x); long __stob_set_i = (i); s48_value __stob_set_v = (v); if (S48_STOB_IMMUTABLEP(__stob_set_x)) s48_raise_argument_type_error(__stob_set_x); else { S48_WRITE_BARRIER((__stob_set_x), (char *) (&S48_STOB_REF((__stob_set_x), (__stob_set_i))),(__stob_set_v)); *(&S48_STOB_REF((__stob_set_x), (__stob_set_i))) = (__stob_set_v); } } while (0)
  247. #define S48_STOB_BYTE_SET(x, i, v) do { s48_value __stob_set_x = (x); long __stob_set_i = (i); char __stob_set_v = (v); if (S48_STOB_IMMUTABLEP(__stob_set_x)) s48_raise_argument_type_error(__stob_set_x); else *(&S48_STOB_BYTE_REF((__stob_set_x), (__stob_set_i))) = (__stob_set_v); } while (0)
  248. #define S48_STOB_TYPE(x) ((S48_STOB_HEADER(x)>>2)&31)
  249. #define S48_STOB_HEADER(x) (S48_STOB_REF((x),-1))
  250. #define S48_STOB_ADDRESS(x) (&(S48_STOB_HEADER(x)))
  251. #define S48_STOB_BYTE_LENGTH(x) (S48_STOB_HEADER(x) >> 8)
  252. #define S48_STOB_DESCRIPTOR_LENGTH(x) (S48_STOB_HEADER(x) >> 10)
  253. #define S48_STOB_IMMUTABLEP(x) ((S48_STOB_HEADER(x)>>7) & 1)
  254. #define S48_STOB_MAKE_IMMUTABLE(x) ((S48_STOB_HEADER(x)) |= (1<<7))
  255. #define S48_STOBTYPE_PAIR 0
  256. #define S48_PAIR_P(x) (s48_stob_has_type(x, 0))
  257. #define S48_STOBTYPE_SYMBOL 1
  258. #define S48_SYMBOL_P(x) (s48_stob_has_type(x, 1))
  259. #define S48_STOBTYPE_VECTOR 2
  260. #define S48_VECTOR_P(x) (s48_stob_has_type(x, 2))
  261. #define S48_STOBTYPE_CLOSURE 3
  262. #define S48_CLOSURE_P(x) (s48_stob_has_type(x, 3))
  263. #define S48_STOBTYPE_LOCATION 4
  264. #define S48_LOCATION_P(x) (s48_stob_has_type(x, 4))
  265. #define S48_STOBTYPE_CELL 5
  266. #define S48_CELL_P(x) (s48_stob_has_type(x, 5))
  267. #define S48_STOBTYPE_CHANNEL 6
  268. #define S48_CHANNEL_P(x) (s48_stob_has_type(x, 6))
  269. #define S48_STOBTYPE_PORT 7
  270. #define S48_PORT_P(x) (s48_stob_has_type(x, 7))
  271. #define S48_STOBTYPE_RATNUM 8
  272. #define S48_RATNUM_P(x) (s48_stob_has_type(x, 8))
  273. #define S48_STOBTYPE_RECORD 9
  274. #define S48_RECORD_P(x) (s48_stob_has_type(x, 9))
  275. #define S48_STOBTYPE_CONTINUATION 10
  276. #define S48_CONTINUATION_P(x) (s48_stob_has_type(x, 10))
  277. #define S48_STOBTYPE_EXTENDED_NUMBER 11
  278. #define S48_EXTENDED_NUMBER_P(x) (s48_stob_has_type(x, 11))
  279. #define S48_STOBTYPE_TEMPLATE 12
  280. #define S48_TEMPLATE_P(x) (s48_stob_has_type(x, 12))
  281. #define S48_STOBTYPE_WEAK_POINTER 13
  282. #define S48_WEAK_POINTER_P(x) (s48_stob_has_type(x, 13))
  283. #define S48_STOBTYPE_SHARED_BINDING 14
  284. #define S48_SHARED_BINDING_P(x) (s48_stob_has_type(x, 14))
  285. #define S48_STOBTYPE_UNUSED_D_HEADER1 15
  286. #define S48_UNUSED_D_HEADER1_P(x) (s48_stob_has_type(x, 15))
  287. #define S48_STOBTYPE_UNUSED_D_HEADER2 16
  288. #define S48_UNUSED_D_HEADER2_P(x) (s48_stob_has_type(x, 16))
  289. #define S48_STOBTYPE_STRING 17
  290. #define S48_STRING_P(x) (s48_stob_has_type(x, 17))
  291. #define S48_STOBTYPE_BYTE_VECTOR 18
  292. #define S48_BYTE_VECTOR_P(x) (s48_stob_has_type(x, 18))
  293. #define S48_STOBTYPE_DOUBLE 19
  294. #define S48_DOUBLE_P(x) (s48_stob_has_type(x, 19))
  295. #define S48_STOBTYPE_BIGNUM 20
  296. #define S48_BIGNUM_P(x) (s48_stob_has_type(x, 20))
  297. #define S48_CAR_OFFSET 0
  298. #define S48_CAR(x) (s48_stob_ref((x), S48_STOBTYPE_PAIR, 0))
  299. #define S48_UNSAFE_CAR(x) (S48_STOB_REF((x), 0))
  300. #define S48_SET_CAR(x, v) (s48_stob_set((x), S48_STOBTYPE_PAIR, 0, (v)))
  301. #define S48_UNSAFE_SET_CAR(x, v) S48_STOB_SET((x), 0, (v))
  302. #define S48_CDR_OFFSET 1
  303. #define S48_CDR(x) (s48_stob_ref((x), S48_STOBTYPE_PAIR, 1))
  304. #define S48_UNSAFE_CDR(x) (S48_STOB_REF((x), 1))
  305. #define S48_SET_CDR(x, v) (s48_stob_set((x), S48_STOBTYPE_PAIR, 1, (v)))
  306. #define S48_UNSAFE_SET_CDR(x, v) S48_STOB_SET((x), 1, (v))
  307. #define S48_SYMBOL_TO_STRING_OFFSET 0
  308. #define S48_SYMBOL_TO_STRING(x) (s48_stob_ref((x), S48_STOBTYPE_SYMBOL, 0))
  309. #define S48_UNSAFE_SYMBOL_TO_STRING(x) (S48_STOB_REF((x), 0))
  310. #define S48_LOCATION_ID_OFFSET 0
  311. #define S48_LOCATION_ID(x) (s48_stob_ref((x), S48_STOBTYPE_LOCATION, 0))
  312. #define S48_UNSAFE_LOCATION_ID(x) (S48_STOB_REF((x), 0))
  313. #define S48_SET_LOCATION_ID(x, v) (s48_stob_set((x), S48_STOBTYPE_LOCATION, 0, (v)))
  314. #define S48_UNSAFE_SET_LOCATION_ID(x, v) S48_STOB_SET((x), 0, (v))
  315. #define S48_CONTENTS_OFFSET 1
  316. #define S48_CONTENTS(x) (s48_stob_ref((x), S48_STOBTYPE_LOCATION, 1))
  317. #define S48_UNSAFE_CONTENTS(x) (S48_STOB_REF((x), 1))
  318. #define S48_SET_CONTENTS(x, v) (s48_stob_set((x), S48_STOBTYPE_LOCATION, 1, (v)))
  319. #define S48_UNSAFE_SET_CONTENTS(x, v) S48_STOB_SET((x), 1, (v))
  320. #define S48_CELL_REF_OFFSET 0
  321. #define S48_CELL_REF(x) (s48_stob_ref((x), S48_STOBTYPE_CELL, 0))
  322. #define S48_UNSAFE_CELL_REF(x) (S48_STOB_REF((x), 0))
  323. #define S48_CELL_SET(x, v) (s48_stob_set((x), S48_STOBTYPE_CELL, 0, (v)))
  324. #define S48_UNSAFE_CELL_SET(x, v) S48_STOB_SET((x), 0, (v))
  325. #define S48_CLOSURE_TEMPLATE_OFFSET 0
  326. #define S48_CLOSURE_TEMPLATE(x) (s48_stob_ref((x), S48_STOBTYPE_CLOSURE, 0))
  327. #define S48_UNSAFE_CLOSURE_TEMPLATE(x) (S48_STOB_REF((x), 0))
  328. #define S48_CLOSURE_ENV_OFFSET 1
  329. #define S48_CLOSURE_ENV(x) (s48_stob_ref((x), S48_STOBTYPE_CLOSURE, 1))
  330. #define S48_UNSAFE_CLOSURE_ENV(x) (S48_STOB_REF((x), 1))
  331. #define S48_WEAK_POINTER_REF_OFFSET 0
  332. #define S48_WEAK_POINTER_REF(x) (s48_stob_ref((x), S48_STOBTYPE_WEAK_POINTER, 0))
  333. #define S48_UNSAFE_WEAK_POINTER_REF(x) (S48_STOB_REF((x), 0))
  334. #define S48_SHARED_BINDING_NAME_OFFSET 0
  335. #define S48_SHARED_BINDING_NAME(x) (s48_stob_ref((x), S48_STOBTYPE_SHARED_BINDING, 0))
  336. #define S48_UNSAFE_SHARED_BINDING_NAME(x) (S48_STOB_REF((x), 0))
  337. #define S48_SHARED_BINDING_IS_IMPORTP_OFFSET 1
  338. #define S48_SHARED_BINDING_IS_IMPORTP(x) (s48_stob_ref((x), S48_STOBTYPE_SHARED_BINDING, 1))
  339. #define S48_UNSAFE_SHARED_BINDING_IS_IMPORTP(x) (S48_STOB_REF((x), 1))
  340. #define S48_SHARED_BINDING_REF_OFFSET 2
  341. #define S48_SHARED_BINDING_REF(x) (s48_stob_ref((x), S48_STOBTYPE_SHARED_BINDING, 2))
  342. #define S48_UNSAFE_SHARED_BINDING_REF(x) (S48_STOB_REF((x), 2))
  343. #define S48_SHARED_BINDING_SET(x, v) (s48_stob_set((x), S48_STOBTYPE_SHARED_BINDING, 2, (v)))
  344. #define S48_UNSAFE_SHARED_BINDING_SET(x, v) S48_STOB_SET((x), 2, (v))
  345. #define S48_PORT_HANDLER_OFFSET 0
  346. #define S48_PORT_HANDLER(x) (s48_stob_ref((x), S48_STOBTYPE_PORT, 0))
  347. #define S48_UNSAFE_PORT_HANDLER(x) (S48_STOB_REF((x), 0))
  348. #define S48_PORT_STATUS_OFFSET 1
  349. #define S48_PORT_STATUS(x) (s48_stob_ref((x), S48_STOBTYPE_PORT, 1))
  350. #define S48_UNSAFE_PORT_STATUS(x) (S48_STOB_REF((x), 1))
  351. #define S48_SET_PORT_STATUS(x, v) (s48_stob_set((x), S48_STOBTYPE_PORT, 1, (v)))
  352. #define S48_UNSAFE_SET_PORT_STATUS(x, v) S48_STOB_SET((x), 1, (v))
  353. #define S48_PORT_LOCK_OFFSET 2
  354. #define S48_PORT_LOCK(x) (s48_stob_ref((x), S48_STOBTYPE_PORT, 2))
  355. #define S48_UNSAFE_PORT_LOCK(x) (S48_STOB_REF((x), 2))
  356. #define S48_SET_PORT_LOCK(x, v) (s48_stob_set((x), S48_STOBTYPE_PORT, 2, (v)))
  357. #define S48_UNSAFE_SET_PORT_LOCK(x, v) S48_STOB_SET((x), 2, (v))
  358. #define S48_PORT_DATA_OFFSET 3
  359. #define S48_PORT_DATA(x) (s48_stob_ref((x), S48_STOBTYPE_PORT, 3))
  360. #define S48_UNSAFE_PORT_DATA(x) (S48_STOB_REF((x), 3))
  361. #define S48_SET_PORT_DATA(x, v) (s48_stob_set((x), S48_STOBTYPE_PORT, 3, (v)))
  362. #define S48_UNSAFE_SET_PORT_DATA(x, v) S48_STOB_SET((x), 3, (v))
  363. #define S48_PORT_BUFFER_OFFSET 4
  364. #define S48_PORT_BUFFER(x) (s48_stob_ref((x), S48_STOBTYPE_PORT, 4))
  365. #define S48_UNSAFE_PORT_BUFFER(x) (S48_STOB_REF((x), 4))
  366. #define S48_SET_PORT_BUFFER(x, v) (s48_stob_set((x), S48_STOBTYPE_PORT, 4, (v)))
  367. #define S48_UNSAFE_SET_PORT_BUFFER(x, v) S48_STOB_SET((x), 4, (v))
  368. #define S48_PORT_INDEX_OFFSET 5
  369. #define S48_PORT_INDEX(x) (s48_stob_ref((x), S48_STOBTYPE_PORT, 5))
  370. #define S48_UNSAFE_PORT_INDEX(x) (S48_STOB_REF((x), 5))
  371. #define S48_SET_PORT_INDEX(x, v) (s48_stob_set((x), S48_STOBTYPE_PORT, 5, (v)))
  372. #define S48_UNSAFE_SET_PORT_INDEX(x, v) S48_STOB_SET((x), 5, (v))
  373. #define S48_PORT_LIMIT_OFFSET 6
  374. #define S48_PORT_LIMIT(x) (s48_stob_ref((x), S48_STOBTYPE_PORT, 6))
  375. #define S48_UNSAFE_PORT_LIMIT(x) (S48_STOB_REF((x), 6))
  376. #define S48_SET_PORT_LIMIT(x, v) (s48_stob_set((x), S48_STOBTYPE_PORT, 6, (v)))
  377. #define S48_UNSAFE_SET_PORT_LIMIT(x, v) S48_STOB_SET((x), 6, (v))
  378. #define S48_PORT_PENDING_EOFP_OFFSET 7
  379. #define S48_PORT_PENDING_EOFP(x) (s48_stob_ref((x), S48_STOBTYPE_PORT, 7))
  380. #define S48_UNSAFE_PORT_PENDING_EOFP(x) (S48_STOB_REF((x), 7))
  381. #define S48_SET_PORT_PENDING_EOFP(x, v) (s48_stob_set((x), S48_STOBTYPE_PORT, 7, (v)))
  382. #define S48_UNSAFE_SET_PORT_PENDING_EOFP(x, v) S48_STOB_SET((x), 7, (v))
  383. #define S48_CHANNEL_STATUS_OFFSET 0
  384. #define S48_CHANNEL_STATUS(x) (s48_stob_ref((x), S48_STOBTYPE_CHANNEL, 0))
  385. #define S48_UNSAFE_CHANNEL_STATUS(x) (S48_STOB_REF((x), 0))
  386. #define S48_CHANNEL_ID_OFFSET 1
  387. #define S48_CHANNEL_ID(x) (s48_stob_ref((x), S48_STOBTYPE_CHANNEL, 1))
  388. #define S48_UNSAFE_CHANNEL_ID(x) (S48_STOB_REF((x), 1))
  389. #define S48_CHANNEL_OS_INDEX_OFFSET 2
  390. #define S48_CHANNEL_OS_INDEX(x) (s48_stob_ref((x), S48_STOBTYPE_CHANNEL, 2))
  391. #define S48_UNSAFE_CHANNEL_OS_INDEX(x) (S48_STOB_REF((x), 2))
  392. #define S48_CHANNEL_CLOSE_SILENTLYP_OFFSET 3
  393. #define S48_CHANNEL_CLOSE_SILENTLYP(x) (s48_stob_ref((x), S48_STOBTYPE_CHANNEL, 3))
  394. #define S48_UNSAFE_CHANNEL_CLOSE_SILENTLYP(x) (S48_STOB_REF((x), 3))
  395. #define S48_VECTOR_LENGTH(x) (s48_stob_length((x), S48_STOBTYPE_VECTOR))
  396. #define S48_UNSAFE_VECTOR_LENGTH(x) (S48_STOB_DESCRIPTOR_LENGTH(x))
  397. #define S48_VECTOR_REF(x, i) (s48_stob_ref((x), S48_STOBTYPE_VECTOR, (i)))
  398. #define S48_VECTOR_SET(x, i, v) (s48_stob_set((x), S48_STOBTYPE_VECTOR, (i), (v)))
  399. #define S48_UNSAFE_VECTOR_REF(x, i) (S48_STOB_REF((x), (i)))
  400. #define S48_UNSAFE_VECTOR_SET(x, i, v) S48_STOB_SET((x), (i), (v))
  401. #define S48_RECORD_LENGTH(x) (s48_stob_length((x), S48_STOBTYPE_RECORD))
  402. #define S48_UNSAFE_RECORD_LENGTH(x) (S48_STOB_DESCRIPTOR_LENGTH(x))
  403. #define S48_RECORD_REF(x, i) (s48_stob_ref((x), S48_STOBTYPE_RECORD, (i) + 1))
  404. #define S48_RECORD_SET(x, i, v) (s48_stob_set((x), S48_STOBTYPE_RECORD, (i) + 1, (v)))
  405. #define S48_UNSAFE_RECORD_REF(x, i) (S48_STOB_REF((x), (i) + 1))
  406. #define S48_UNSAFE_RECORD_SET(x, i, v) S48_STOB_SET((x), (i) + 1, (v))
  407. #define S48_RECORD_TYPE(x) (s48_stob_ref((x), S48_STOBTYPE_RECORD, 0))
  408. #define S48_UNSAFE_RECORD_TYPE(x) (S48_STOB_REF((x), 0))
  409. #define S48_BYTE_VECTOR_LENGTH(x) (s48_stob_byte_length((x), S48_STOBTYPE_BYTE_VECTOR))
  410. #define S48_BYTE_VECTOR_REF(x, i) (s48_stob_byte_ref((x), S48_STOBTYPE_BYTE_VECTOR, (i)))
  411. #define S48_BYTE_VECTOR_SET(x, i, v) (s48_stob_byte_set((x), S48_STOBTYPE_BYTE_VECTOR, (i), (v)))
  412. #define S48_UNSAFE_BYTE_VECTOR_REF(x, i) (S48_STOB_BYTE_REF((x), (i)))
  413. #define S48_UNSAFE_BYTE_VECTOR_SET(x, i, v) S48_BYTE_STOB_SET((x), (i), (v))
  414. #define S48_STRING_LENGTH(x) (s48_stob_byte_length((x), S48_STOBTYPE_STRING))
  415. #define S48_STRING_REF(x, i) (s48_stob_byte_ref((x), S48_STOBTYPE_STRING, (i)))
  416. #define S48_STRING_SET(x, i, v) (s48_stob_byte_set((x), S48_STOBTYPE_STRING, (i), (v)))
  417. #define S48_UNSAFE_STRING_REF(x, i) (S48_STOB_BYTE_REF((x), (i)))
  418. #define S48_UNSAFE_STRING_SET(x, i, v) S48_BYTE_STOB_SET((x), (i), (v))
  419. #define S48_UNSAFE_BYTE_VECTOR_LENGTH(x) (S48_STOB_BYTE_LENGTH(x))
  420. #define S48_UNSAFE_STRING_LENGTH(x) (S48_STOB_BYTE_LENGTH(x) - 1)
  421. #define S48_UNSAFE_EXTRACT_STRING(x) (S48_ADDRESS_AFTER_HEADER((x), char))
  422. #define S48_EXTRACT_EXTERNAL_OBJECT(x, type) ((type *)(S48_ADDRESS_AFTER_HEADER(x, long)+1))
  423. #define S48_RECORD_TYPE_RESUMER(x) S48_RECORD_REF((x), 0)
  424. #define S48_RECORD_TYPE_UID(x) S48_RECORD_REF((x), 1)
  425. #define S48_RECORD_TYPE_NAME(x) S48_RECORD_REF((x), 2)
  426. #define S48_RECORD_TYPE_FIELD_NAMES(x) S48_RECORD_REF((x), 3)
  427. #define S48_RECORD_TYPE_NUMBER_OF_FIELDS(x) S48_RECORD_REF((x), 4)
  428. #define S48_RECORD_TYPE_DISCLOSER(x) S48_RECORD_REF((x), 5)
  429. #define S48_EXCEPTION_UNASSIGNED_LOCAL 0
  430. #define S48_EXCEPTION_UNDEFINED_GLOBAL 1
  431. #define S48_EXCEPTION_UNBOUND_GLOBAL 2
  432. #define S48_EXCEPTION_BAD_PROCEDURE 3
  433. #define S48_EXCEPTION_WRONG_NUMBER_OF_ARGUMENTS 4
  434. #define S48_EXCEPTION_WRONG_TYPE_ARGUMENT 5
  435. #define S48_EXCEPTION_ARITHMETIC_OVERFLOW 6
  436. #define S48_EXCEPTION_INDEX_OUT_OF_RANGE 7
  437. #define S48_EXCEPTION_HEAP_OVERFLOW 8
  438. #define S48_EXCEPTION_OUT_OF_MEMORY 9
  439. #define S48_EXCEPTION_CANNOT_OPEN_CHANNEL 10
  440. #define S48_EXCEPTION_CHANNEL_OS_INDEX_ALREADY_IN_USE 11
  441. #define S48_EXCEPTION_CLOSED_CHANNEL 12
  442. #define S48_EXCEPTION_BUFFER_FULLEMPTY 13
  443. #define S48_EXCEPTION_UNIMPLEMENTED_INSTRUCTION 14
  444. #define S48_EXCEPTION_TRAP 15
  445. #define S48_EXCEPTION_PROCEEDING_AFTER_EXCEPTION 16
  446. #define S48_EXCEPTION_BAD_OPTION 17
  447. #define S48_EXCEPTION_UNBOUND_EXTERNAL_NAME 18
  448. #define S48_EXCEPTION_TOO_MANY_ARGUMENTS_TO_EXTERNAL_PROCEDURE 19
  449. #define S48_EXCEPTION_TOO_MANY_ARGUMENTS_IN_CALLBACK 20
  450. #define S48_EXCEPTION_CALLBACK_RETURN_UNCOVERED 21
  451. #define S48_EXCEPTION_EXTENSION_EXCEPTION 22
  452. #define S48_EXCEPTION_EXTENSION_RETURN_ERROR 23
  453. #define S48_EXCEPTION_OS_ERROR 24
  454. #define S48_EXCEPTION_GC_PROTECTION_MISMATCH 25
  455. #define S48_EXCEPTION_NO_CURRENT_PROPOSAL 26
  456. #define S48_EXCEPTION_NATIVE_CODE_NOT_SUPPORTED 27
  457. #define S48_EXCEPTION_ILLEGAL_EXCEPTION_RETURN 28
  458. #define S48_CHANNEL_STATUS_CLOSED S48_UNSAFE_ENTER_FIXNUM(0)
  459. #define S48_CHANNEL_STATUS_INPUT S48_UNSAFE_ENTER_FIXNUM(1)
  460. #define S48_CHANNEL_STATUS_OUTPUT S48_UNSAFE_ENTER_FIXNUM(2)
  461. #define S48_CHANNEL_STATUS_SPECIAL_INPUT S48_UNSAFE_ENTER_FIXNUM(3)
  462. #define S48_CHANNEL_STATUS_SPECIAL_OUTPUT S48_UNSAFE_ENTER_FIXNUM(4)
  463. #endif /* _H_SCHEME48 */