Read one byte from an open
Signature: (read-byte$ channel state-state) returns
This is a logic-mode function, but its logical definition is tricky; see logical-story-of-io. The main logical consequence is the updating of state.
Under the hood, we read a byte (i.e., a number between 0 and 255, inclusive)
from the Lisp input stream that is associated with
Theorem:
(defthm state-p1-of-read-byte$ (implies (and (state-p1 state) (symbolp channel) (open-input-channel-p1 channel :byte state)) (state-p1 (mv-nth 1 (read-byte$ channel state)))))
Theorem:
(defthm open-input-channel-p1-of-read-byte$ (implies (and (state-p1 state) (open-input-channel-p1 channel :byte state)) (open-input-channel-p1 channel :byte (mv-nth 1 (read-byte$ channel state)))))
Theorem:
(defthm bytep-of-read-byte$ (implies (and (state-p1 state) (open-input-channel-p1 channel :byte state) (mv-nth 0 (read-byte$ channel state))) (and (bytep (mv-nth 0 (read-byte$ channel state))) (natp (mv-nth 0 (read-byte$ channel state))) (integerp (mv-nth 0 (read-byte$ channel state))) (unsigned-byte-p 8 (mv-nth 0 (read-byte$ channel state))))))
Theorem:
(defthm bytep-of-read-byte$-type (implies (and (state-p1 state) (open-input-channel-p1 channel :byte state)) (or (null (mv-nth 0 (read-byte$ channel state))) (natp (mv-nth 0 (read-byte$ channel state))))) :rule-classes :type-prescription)
Theorem:
(defthm bytep-of-read-byte$-linear (implies (and (state-p1 state) (open-input-channel-p1 channel :byte state)) (and (< (mv-nth 0 (read-byte$ channel state)) 256) (<= 0 (mv-nth 0 (read-byte$ channel state))))) :rule-classes :linear)
Theorem:
(defthm no-bytes-after-read-byte$-null (let ((byte1 (mv-nth 0 (read-byte$ channel state))) (state2 (mv-nth 1 (read-byte$ channel state)))) (implies (and (not byte1) (state-p1 state) (open-input-channel-p1 channel :byte state)) (not (mv-nth 0 (read-byte$ channel state2))))))
Theorem:
(defthm state-preserved-by-read-byte$-when-eof (implies (and (not (mv-nth 0 (read-byte$ channel state))) (state-p1 state) (open-input-channel-p1 channel :byte state)) (equal (mv-nth 1 (read-byte$ channel state)) state)))