[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)
- [Guile-commits] branch wip-port-refactor updated (d28d1a5 -> da456d2), Andy Wingo, 2016/05/16
- [Guile-commits] 07/21: Embed scm_t_port in scm_t_port_internal, Andy Wingo, 2016/05/16
- [Guile-commits] 21/21: Bump objcode version, Andy Wingo, 2016/05/16
- [Guile-commits] 02/21: Implement lookahead-u8, get-u8 in Scheme,
Andy Wingo <=
- [Guile-commits] 10/21: Make scm_t_port private, Andy Wingo, 2016/05/16
- [Guile-commits] 17/21: Update port mode bits documentation., Andy Wingo, 2016/05/16
- [Guile-commits] 08/21: Make file/line/column fields of ports private, Andy Wingo, 2016/05/16
- [Guile-commits] 20/21: Update NEWS for release, Andy Wingo, 2016/05/16
- [Guile-commits] 18/21: Document scm_c_make_port and friends, Andy Wingo, 2016/05/16
- [Guile-commits] 01/21: %read-char speedup, Andy Wingo, 2016/05/16
- [Guile-commits] 12/21: Update port documentation, Andy Wingo, 2016/05/16
- [Guile-commits] 04/21: Add (ice-9 sports) module, Andy Wingo, 2016/05/16
- [Guile-commits] 13/21: Make scm_t_ptob_descriptor private., Andy Wingo, 2016/05/16
- [Guile-commits] 15/21: Update port type documentation, Andy Wingo, 2016/05/16