mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-29 22:40:34 +02:00
Implement lookahead-u8, get-u8 in Scheme
* module/ice-9/ports.scm (%lookahead-u8, %get-u8): Scheme implementations.
This commit is contained in:
parent
a8fe0f42f3
commit
df0dade9b7
1 changed files with 21 additions and 0 deletions
|
@ -306,6 +306,27 @@ interpret its input and output."
|
|||
(and (> buffered 0)
|
||||
(bytevector-u8-ref bv cur)))))
|
||||
|
||||
(define* (%lookahead-u8 port)
|
||||
(define (fast-path buf bv cur buffered)
|
||||
(bytevector-u8-ref bv cur))
|
||||
(define (slow-path buf bv cur buffered)
|
||||
(if (zero? buffered)
|
||||
the-eof-object
|
||||
(fast-path buf bv cur buffered)))
|
||||
(peek-bytes port 1 fast-path slow-path))
|
||||
|
||||
(define* (%get-u8 port)
|
||||
(define (fast-path buf bv cur buffered)
|
||||
(set-port-buffer-cur! buf (1+ cur))
|
||||
(bytevector-u8-ref bv cur))
|
||||
(define (slow-path buf bv cur buffered)
|
||||
(if (zero? buffered)
|
||||
(begin
|
||||
(set-port-buffer-has-eof?! buf #f)
|
||||
the-eof-object)
|
||||
(fast-path buf bv cur buffered)))
|
||||
(peek-bytes port 1 fast-path slow-path))
|
||||
|
||||
(define (decoding-error subr port)
|
||||
;; GNU/Linux definition; fixme?
|
||||
(define EILSEQ 84)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue