guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 02/21: Implement lookahead-u8, get-u8 in Scheme


From: Andy Wingo
Subject: [Guile-commits] 02/21: Implement lookahead-u8, get-u8 in Scheme
Date: Mon, 16 May 2016 07:39:33 +0000 (UTC)

wingo pushed a commit to branch wip-port-refactor
in repository guile.

commit df0dade9b7b3e1d488a5049d3cc730abd67c6692
Author: Andy Wingo <address@hidden>
Date:   Thu May 12 08:57:01 2016 +0200

    Implement lookahead-u8, get-u8 in Scheme
    
    * module/ice-9/ports.scm (%lookahead-u8, %get-u8): Scheme
      implementations.
---
 module/ice-9/ports.scm |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/module/ice-9/ports.scm b/module/ice-9/ports.scm
index 27a5708..9d2e36d 100644
--- a/module/ice-9/ports.scm
+++ b/module/ice-9/ports.scm
@@ -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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]