Logically nice loop for vl-read-file.
(vl-read-file-loop channel filename line col &key (state 'state)) → (mv data state)
Function:
(defun vl-read-file-loop-fn (channel filename line col state) (declare (xargs :stobjs (state))) (declare (xargs :guard (and (symbolp channel) (stringp filename) (posp line) (natp col)))) (declare (xargs :guard (open-input-channel-p channel :byte state))) (let ((__function__ 'vl-read-file-loop)) (declare (ignorable __function__)) (mbe :logic (b* (((unless (state-p state)) (mv nil state)) ((mv byte state) (read-byte$ channel state)) ((unless byte) (mv nil state)) (char (code-char (the (unsigned-byte 8) byte))) (echar (make-vl-echar-fast :char char :filename filename :line line :col col)) (newlinep (eql char #\Newline)) (next-line (if newlinep (+ 1 line) line)) (next-col (if newlinep 0 (+ 1 col))) ((mv rest state) (vl-read-file-loop channel filename next-line next-col))) (mv (cons echar rest) state)) :exec (with-local-stobj nrev (mv-let (echars nrev state) (b* (((mv nrev state) (vl-read-file-loop-aux channel filename line col nrev)) ((mv echars nrev) (nrev-finish nrev))) (mv echars nrev state)) (mv echars state))))))
Theorem:
(defthm vl-echarlist-p-of-vl-read-file-loop.data (implies (and (force (state-p state)) (force (symbolp channel)) (force (stringp filename)) (force (posp line)) (force (natp col)) (force (open-input-channel-p channel ':byte state))) (b* (((mv ?data acl2::?state) (vl-read-file-loop-fn channel filename line col state))) (vl-echarlist-p data))) :rule-classes :rewrite)
Theorem:
(defthm state-p1-of-vl-read-file-loop.state (implies (and (force (state-p state)) (force (symbolp channel)) (force (stringp filename)) (force (posp line)) (force (natp col)) (force (open-input-channel-p channel ':byte state))) (b* (((mv ?data acl2::?state) (vl-read-file-loop-fn channel filename line col state))) (state-p1 state))) :rule-classes :rewrite)
Theorem:
(defthm true-listp-of-vl-read-file-loop (true-listp (mv-nth 0 (vl-read-file-loop channel filename line col))) :rule-classes :type-prescription)
Theorem:
(defthm vl-read-file-loop-aux-redef (equal (vl-read-file-loop-aux channel filename line col acc) (b* (((mv data state) (vl-read-file-loop channel filename line col))) (mv (append acc data) state))))
Theorem:
(defthm vl-read-file-loop-preserves-open-input-channel-p1 (implies (and (force (state-p1 state)) (force (symbolp channel)) (force (open-input-channel-p1 channel :byte state))) (b* (((mv ?data state) (vl-read-file-loop channel filename line col))) (open-input-channel-p1 channel :byte state))))