schemetoc-features.scm 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. ; Copyright (c) 1993-2007 by Richard Kelsey and Jonathan Rees. See file COPYING.
  2. ; BUG: (+ (expt 2 28) (expt 2 28)), (* (expt 2 28) 2)
  3. (define-external schemetoc-error ;(schemetoc-error symbol format-string . args)
  4. "scdebug" "error_v")
  5. (eval-when (eval)
  6. (define schemetoc-error error))
  7. ; SIGNALS
  8. (define (error message . irritants)
  9. (if (symbol? message)
  10. (apply schemetoc-error message irritants)
  11. (apply schemetoc-error
  12. "Error:"
  13. (apply string-append
  14. message
  15. (map (lambda (x) "~% ~s")
  16. irritants))
  17. irritants)))
  18. (define (warn message . irritants)
  19. (display-error-message "Warning: " message irritants))
  20. (define (display-error-message heading message irritants)
  21. (display heading)
  22. (display message)
  23. (newline)
  24. (let ((spaces (list->string
  25. (map (lambda (c) #\space) (string->list heading)))))
  26. (for-each (lambda (irritant)
  27. (display spaces)
  28. (write irritant)
  29. (newline))
  30. irritants)))
  31. (define (signal type . stuff)
  32. (apply warn "condition signalled" type stuff))
  33. (define (syntax-error . rest) ; Must return a valid expression.
  34. (apply warn rest)
  35. ''syntax-error)
  36. (define (call-error message proc . args)
  37. (error message (cons proc args)))
  38. ; FEATURES
  39. (define force-output flush-buffer)
  40. (define (string-hash s)
  41. (let ((n (string-length s)))
  42. (do ((i 0 (+ i 1))
  43. (h 0 (+ h (char->ascii (string-ref s i)))))
  44. ((>= i n) h))))
  45. (define (make-immutable! thing) thing)
  46. (define (immutable? thing) #f)
  47. ; BITWISE
  48. (define (arithmetic-shift x n)
  49. (if (< x 0)
  50. (let ((r (- -1 (arithmetic-shift (- -1 x) n))))
  51. (if (> n 0)
  52. (- r (- (arithmetic-shift 1 n) 1))
  53. r))
  54. (if (>= n 0) ;shift left?
  55. (if (and (<= n 8)
  56. (exact? x)
  57. (< x 4194304))
  58. (bit-lsh x n)
  59. (* x (expt 2 n)))
  60. (if (and (<= n 28) (exact? x))
  61. (bit-rsh x (- n))
  62. (floor (* x (expt 2. n)))))))
  63. (define (bitwise-and x y)
  64. (if (and (< x 0) (< y 0))
  65. (- -1 (bit-or (- -1 x) (- -1 y)))
  66. (bit-and x y)))
  67. (define (bitwise-ior x y)
  68. (if (or (< x 0) (< y 0))
  69. (- -1 (bit-and (- -1 x) (- -1 y)))
  70. (bit-or x y)))
  71. (define (bitwise-not x) (- -1 x))
  72. ; ASCII
  73. (define char->ascii char->integer)
  74. (define ascii->char integer->char)
  75. (define ascii-limit 256)
  76. (define ascii-whitespaces '(32 10 9 12 13))
  77. ; CODE-VECTORS (= alt/code-vectors.scm)
  78. (define *code-vector-marker* (list '*code-vector-marker*))
  79. (define (make-code-vector len init)
  80. (let ((t (make-vector (+ len 1) init)))
  81. (vector-set! t 0 *code-vector-marker*)
  82. t))
  83. (define (code-vector? obj)
  84. (and (vector? obj)
  85. (> (vector-length obj) 0)
  86. (eq? (vector-ref obj 0) *code-vector-marker*)))
  87. (define (code-vector-length t) (- (vector-length t) 1))
  88. (define (code-vector-ref t i) (vector-ref t (+ i 1)))
  89. (define (code-vector-set! t i x) (vector-set! t (+ i 1) x))
  90. (define (write-byte byte port)
  91. (write-char (ascii->char byte) port))