t-features.scm 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. ; Copyright (c) 1993-2007 by Richard Kelsey and Jonathan Rees. See file COPYING.
  2. ; This is file t-features.scm.
  3. ; Synchronize any changes with all the other *-features.scm files.
  4. ; This hasn't been tested in a long time.
  5. (define (get-from-t name)
  6. (*value t-implementation-env name))
  7. ; (define error (get-from-t 'error)) - already present
  8. ; (define warn (get-from-t 'warn)) - already present?
  9. (define (interaction-environment)
  10. scheme-user-env) ;Foo
  11. (define scheme-report-environment
  12. (let ((env (interaction-environment))) ;Isn't there a scheme-env?
  13. (lambda (n) env)))
  14. (define (ignore-errors thunk)
  15. '(error "ignore-errors isn't implemented"))
  16. (define force-output (get-from-t 'force-output))
  17. (define char->ascii char->integer)
  18. (define ascii->char integer->char)
  19. (define (string-hash s)
  20. (let ((n (string-length s)))
  21. (do ((i 0 (+ i 1))
  22. (h 0 (+ h (char->ascii (string-ref s i)))))
  23. ((>= i n) h))))
  24. ;==============================================================================
  25. ; Bitwise logical operations on integers
  26. ; T's ASH doesn't work on negative numbers
  27. (define arithmetic-shift
  28. (let ((fx-ashl (get-from-t 'fx-ashl))
  29. (fx-ashr (get-from-t 'fx-ashr)))
  30. (lambda (integer count)
  31. (if (>= count 0)
  32. (fx-ashl integer count)
  33. (fx-ashr integer (- 0 count))))))
  34. ; This is from Olin Shivers:
  35. ; (define (correct-ash n m)
  36. ; (cond ((or (= m 0) (= n 0)) n)
  37. ; ((> n 0) (ash n m))
  38. ; ;; shifting a negative number.
  39. ; ((> m 0) ; left shift
  40. ; (- (ash (- n) m)))
  41. ; (else ; right shift
  42. ; (lognot (ash (lognot n) m)))))
  43. (define bitwise-and (get-from-t 'fx-and))
  44. (define bitwise-ior (get-from-t 'fx-ior))
  45. ;==============================================================================
  46. ; Code vectors
  47. (define make-bytev (get-from-t 'make-bytev))
  48. (define code-vector? (get-from-t 'bytev?))
  49. (define code-vector-length (get-from-t 'bytev-length))
  50. (define code-vector-ref (get-from-t 'bref-8))
  51. (define code-vector-set! ((get-from-t 'setter) code-vector-ref))
  52. (define (make-code-vector size . init)
  53. (let ((vec (make-bytev size)))
  54. (if (not (null? init))
  55. (code-vector-fill! vec (car init)))
  56. vec))
  57. (define (code-vector-fill! cv x)
  58. (do ((i 0 (+ i 1)))
  59. ((>= i (code-vector-length cv)))
  60. (code-vector-set! cv i x)))
  61. ;==============================================================================
  62. ; Bug fixes and modernizations
  63. ; I think syntax-rules will be needed, as well.
  64. ; Simulate a modernized DEFINE-SYNTAX.
  65. (#[syntax define-syntax] (define-syntax name xformer)
  66. `(#[syntax define-syntax] (,name . %tail%)
  67. (,xformer (cons ',name %tail%)
  68. (lambda (x) x) ;rename
  69. eq?))) ;compare
  70. ; T's MAKE-VECTOR and MAKE-STRING ignore their init argument.
  71. (define make-vector
  72. (let ((broken-make-vector (get-from-t 'make-vector)))
  73. (lambda (size . init)
  74. (let ((vec (broken-make-vector size)))
  75. (if (not (null? init))
  76. (vector-fill! vec (car init)))
  77. vec))))
  78. (define make-string
  79. (let ((make-string (get-from-t 'make-string))
  80. (string-fill (get-from-t 'string-fill)))
  81. (lambda (size . init-option)
  82. (if (null? init-option)
  83. (make-string size)
  84. (string-fill (make-string size) (car init-option))))))
  85. ; Dynamic-wind.
  86. (define (dynamic-wind before during after)
  87. (before)
  88. (let ((result (during)))
  89. (after)
  90. result))