prescheme.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Part of Scheme 48 1.9. See file COPYING for notices and license.
  3. *
  4. * Authors: Richard Kelsey, Jonathan Rees, Mike Sperber, Marcus Crestani,
  5. * David Frese, Timo Harter
  6. */
  7. #include <errno.h>
  8. #include "io.h"
  9. #include "scheme48arch.h"
  10. #ifdef __GNUC__
  11. // This requires the "labels as values" extension of GCC
  12. #define USE_DIRECT_THREADING
  13. #endif
  14. #if SIZEOF_VOID_P == 4
  15. #define BITS_PER_CELL 32
  16. #elif SIZEOF_VOID_P == 8
  17. #define BITS_PER_CELL 64
  18. #else
  19. #error "What size are your pointers, really?"
  20. #endif
  21. #define PS_READ_CHAR(PORT,RESULT,EOFP,STATUS) \
  22. { \
  23. FILE * TTport = PORT; \
  24. int TTchar; \
  25. if (EOF == (TTchar = getc(TTport))) \
  26. RESULT = ps_read_char(TTport, &EOFP, &STATUS, 0==1);\
  27. else { \
  28. RESULT = TTchar; \
  29. EOFP = 0; \
  30. STATUS = 0; } \
  31. }
  32. #define PS_PEEK_CHAR(PORT,RESULT,EOFP,STATUS) \
  33. { \
  34. FILE * TTport = PORT; \
  35. int TTchar; \
  36. if (EOF == (TTchar = getc(TTport))) \
  37. RESULT = ps_read_char(TTport, &EOFP, &STATUS, 0==0);\
  38. else { \
  39. RESULT = TTchar; \
  40. ungetc(RESULT, TTport); \
  41. EOFP = 0; \
  42. STATUS = 0; } \
  43. }
  44. #define PS_READ_INTEGER(PORT,RESULT,EOFP,STATUS) \
  45. RESULT = ps_read_integer(PORT,&EOFP,&STATUS);
  46. #define PS_WRITE_CHAR(CHAR,PORT,STATUS) \
  47. { \
  48. FILE * TTport = PORT; \
  49. char TTchar = CHAR; \
  50. if (EOF == putc(TTchar,TTport)) \
  51. STATUS = ps_write_char(TTchar,TTport); \
  52. else { \
  53. STATUS = 0; } \
  54. }
  55. /*
  56. * C shifts may not work if the amount is greater than the machine word size.
  57. * Also, undefined for negative values.
  58. */
  59. #define PS_SHIFT_LEFT_INLINE(X, Y) ((X)*(1L<<(Y)))
  60. static long
  61. PS_SHIFT_RIGHT_INLINE(long x, long y) {
  62. if (x < 0 && y > 0)
  63. return x >> y | ~(~0LU >> y);
  64. else
  65. return x >> y;
  66. }
  67. #define PS_SHIFT_RIGHT(X,Y,RESULT) \
  68. { \
  69. long TTx = X, TTy = Y; \
  70. if ((TTx < 0) && (TTy > 0)) \
  71. RESULT = (unsigned long)TTx >> TTy | ~(~0LU >> TTy); \
  72. else \
  73. RESULT = TTx >> TTy; \
  74. }
  75. #define PS_SHIFT_LEFT(X,Y,RESULT) \
  76. { \
  77. RESULT = ((X)*(1L<<(Y))); \
  78. }
  79. #define PS_SHIFT_RIGHT_LOGICAL(X,Y,RESULT) \
  80. { \
  81. RESULT = ((unsigned long) X) >> Y; \
  82. }
  83. #define PS_SHIFT_RIGHT_LOGICAL_INLINE(X,Y) ((long)(unsigned long)(((unsigned long) (X)) >> (Y)))
  84. extern double ps_pos_infinity(void), ps_neg_infinity(void), ps_not_a_number(void);
  85. #define PS_POS_INF ps_pos_infinity()
  86. #define PS_NEG_INF ps_neg_infinity()
  87. #define PS_NAN ps_not_a_number()
  88. extern long s48_return_value, s48_run_machine();