• Top
    • Documentation
    • Books
    • Recursion-and-induction
    • Boolean-reasoning
    • Debugging
    • Projects
    • Std
      • Std/lists
      • Std/alists
      • Obags
      • Std/util
      • Std/strings
      • Std/io
        • Open-channel-lemmas
        • Std/io/read-char$
        • Std/io/read-object
        • Std/io/open-output-channel
        • Unsound-read
        • Read-string
        • Read-bytes$
        • File-measure
        • Read-bytes$-n
        • Std/io/read-byte$
        • Std/io/open-input-channel
        • Print-compressed
        • Read-file-lines-no-newlines
        • Nthcdr-bytes
        • Read-file-lines
        • Std/io/close-output-channel
        • Read-file-characters
        • Read-file-bytes
          • Read-byte$-all
          • Print-legibly
          • Std/io/close-input-channel
          • Read-file-objects
          • Logical-story-of-io
          • Take-bytes
          • Std/io/peek-char$
          • Read-file-characters-rev
          • Read-file-as-string
          • Std/io/write-byte$
          • Std/io/set-serialize-character
          • Std/io/print-object$
          • Std/io/princ$
          • Std/io/read-file-into-string
          • *file-types*
        • Std/osets
        • Std/system
        • Std/basic
        • Std/typed-lists
        • Std/bitsets
        • Std/testing
        • Std/typed-alists
        • Std/stobjs
        • Std-extensions
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Testing-utilities
      • Math
    • Read-file-bytes

    Read-byte$-all

    (read-byte$-all channel state) reads all remaining bytes from a file.

    This is the main loop inside read-file-bytes. It reads everything in the file, but doesn't handle opening or closing the file.

    Definitions and Theorems

    Function: tr-read-byte$-all

    (defun
       tr-read-byte$-all (channel state acc)
       (declare (xargs :guard (and (state-p state)
                                   (symbolp channel)
                                   (open-input-channel-p channel
                                                         :byte state))))
       (b* (((unless (mbt (state-p state)))
             (mv acc state))
            ((mv byte state)
             (read-byte$ channel state))
            ((unless byte) (mv acc state))
            (acc (cons (mbe :logic (if (unsigned-byte-p 8 byte) byte 0)
                            :exec byte)
                       acc)))
           (tr-read-byte$-all channel state acc)))

    Function: read-byte$-all

    (defun
       read-byte$-all (channel state)
       (declare (xargs :guard (and (state-p state)
                                   (symbolp channel)
                                   (open-input-channel-p channel
                                                         :byte state))))
       (mbe :logic (b* (((unless (state-p state))
                         (mv nil state))
                        ((mv byte state)
                         (read-byte$ channel state))
                        ((unless byte) (mv nil state))
                        ((mv rest state)
                         (read-byte$-all channel state))
                        (byte (if (unsigned-byte-p 8 byte) byte 0)))
                       (mv (cons byte rest) state))
            :exec (b* (((mv contents state)
                        (tr-read-byte$-all channel state nil)))
                      (mv (reverse contents) state))))

    Theorem: tr-read-byte$-all-removal

    (defthm tr-read-byte$-all-removal
            (equal (tr-read-byte$-all channel state nil)
                   (mv (rev (mv-nth 0 (read-byte$-all channel state)))
                       (mv-nth 1 (read-byte$-all channel state)))))

    Theorem: true-listp-of-read-byte$-all

    (defthm true-listp-of-read-byte$-all
            (true-listp (mv-nth 0 (read-byte$-all channel state)))
            :rule-classes :type-prescription)

    Theorem: state-p1-of-read-byte$-all

    (defthm
         state-p1-of-read-byte$-all
         (implies (and (force (state-p1 state))
                       (force (symbolp channel))
                       (force (open-input-channel-p1 channel
                                                     :byte state)))
                  (state-p1 (mv-nth 1 (read-byte$-all channel state)))))

    Theorem: open-input-channel-p1-of-read-byte$-all

    (defthm
        open-input-channel-p1-of-read-byte$-all
        (implies (and (force (state-p1 state))
                      (force (symbolp channel))
                      (force (open-input-channel-p1 channel
                                                    :byte state)))
                 (open-input-channel-p1
                      channel
                      :byte (mv-nth 1 (read-byte$-all channel state)))))

    Theorem: integer-listp-of-read-byte$-all

    (defthm integer-listp-of-read-byte$-all
            (integer-listp (mv-nth 0 (read-byte$-all channel state))))

    Theorem: nat-listp-of-read-byte$-all

    (defthm nat-listp-of-read-byte$-all
            (nat-listp (mv-nth 0 (read-byte$-all channel state))))

    Theorem: unsigned-byte-listp-of-read-byte$-all

    (defthm
        unsigned-byte-listp-of-read-byte$-all
        (unsigned-byte-listp 8
                             (mv-nth 0 (read-byte$-all channel state))))