inspection.scm 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. (define-module (utils inspection))
  2. (use-modules
  3. ;; SRFI 60: procedures for treating integers as bits
  4. (srfi srfi-60)
  5. (ice-9 format))
  6. (define-public format-bit-integer
  7. (lambda* (bit-int
  8. #:key
  9. (width 8)
  10. (padding-char #\0))
  11. (let ([format-string
  12. (string-join
  13. (list "~"
  14. (number->string width)
  15. "'" (list->string (list padding-char))
  16. ","
  17. "b"
  18. "~"
  19. "%")
  20. "")])
  21. (display (simple-format #f "format-string is: ~a\n" format-string))
  22. (format #t format-string bit-int))))
  23. (define-public display-bit-integer
  24. (lambda* (bit-integer
  25. #:optional (output-port (current-output-port))
  26. #:key
  27. (width 8)
  28. (padding-char #\0))
  29. (display (simple-format #f "DEBUG: integer to display: ~a\n" bit-integer) output-port)
  30. (display (format-bit-integer bit-integer #:width width #:padding-char padding-char)
  31. output-port)))
  32. (define display-hash-map
  33. (lambda* (hash-map
  34. #:optional (output-port (current-output-port))
  35. #:key
  36. (sep "\n")
  37. (end "\n")
  38. (format-entry-proc
  39. (lambda (entry)
  40. (format-bit-integer entry #:width 64))))
  41. (let loop ([remaining (hash-map->list cons hash-map)])
  42. (cond
  43. [(null? remaining)
  44. (display end output-port)
  45. 'done]
  46. [else
  47. (display (format-entry-proc (car remaining)) output-port)
  48. (display sep output-port)
  49. (loop (cdr remaining))]))))