vm-utilities.scm 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. ; Part of Scheme 48 1.9. See file COPYING for notices and license.
  2. ; Authors: Richard Kelsey, Jonathan Rees, Mike Sperber
  3. (define (adjoin-bits high low k)
  4. (+ (shift-left high k) low))
  5. (define (low-bits n k)
  6. (bitwise-and n (- (shift-left 1 k) 1)))
  7. (define high-bits arithmetic-shift-right)
  8. (define unsigned-high-bits logical-shift-right)
  9. (define (digit? ch)
  10. (let ((ch (char->ascii ch)))
  11. (and (>= ch (char->ascii #\0))
  12. (<= ch (char->ascii #\9)))))
  13. (define (vector+length-fill! v length x)
  14. (do ((i 0 (+ i 1)))
  15. ((>= i length))
  16. (vector-set! v i x)))
  17. ; Apply PROC to 0 ... N-1.
  18. (define (natural-for-each proc n)
  19. (do ((i 0 (+ i 1)))
  20. ((= i n))
  21. (proc i)))
  22. (define (natural-for-each-while proc n)
  23. (do ((i 0 (+ i 1)))
  24. ((or (= i n)
  25. (not (proc i))))))
  26. ;----------------
  27. ; stderr
  28. (define (error? status)
  29. (not (eq? status (enum errors no-errors))))
  30. (define (write-error-string string)
  31. (write-string string (current-error-port)))
  32. (define (write-error-integer integer)
  33. (write-integer integer (current-error-port)))
  34. (define (write-error-newline)
  35. (write-char #\newline (current-error-port)))
  36. (define (error-message string)
  37. (write-error-string string)
  38. (write-error-newline))
  39. ; stdout
  40. (define (write-out-string string)
  41. (write-string string (current-output-port)))
  42. (define (write-out-integer integer)
  43. (write-integer integer (current-output-port)))
  44. (define (write-out-newline)
  45. (write-char #\newline (current-output-port)))
  46. (define (display-message str)
  47. (write-out-string str)
  48. (write-out-newline))
  49. (define (display-integer int)
  50. (write-out-integer int)
  51. (write-out-newline))