From a33269daa7390afef72f7139f2af225474e534c9 Mon Sep 17 00:00:00 2001 From: Abdulaziz Ghuloum Date: Tue, 22 Jan 2008 10:59:04 -0500 Subject: [PATCH] Fixes bug 184959: get-bytevector-some missing --- scheme/ikarus.io.ss | 70 +++++++++++++++++++++++++++------------ scheme/ikarus.numerics.ss | 10 ++++-- scheme/last-revision | 2 +- scheme/makefile.ss | 8 ++--- scheme/todo-r6rs.ss | 4 +-- 5 files changed, 63 insertions(+), 31 deletions(-) diff --git a/scheme/ikarus.io.ss b/scheme/ikarus.io.ss index d5c942e..b443c87 100644 --- a/scheme/ikarus.io.ss +++ b/scheme/ikarus.io.ss @@ -669,30 +669,31 @@ ;(define-rrr port-has-set-port-position!?) ;(define-rrr set-port-position!) + (define (refill-bv-buffer p who) + (when ($port-closed? p) (die who "port is closed" p)) + (let ([bv ($port-buffer p)] [i ($port-index p)] [j ($port-size p)]) + (let ([c0 (fx- j i)]) + (unless (fx= c0 0) (bytevector-copy! bv i bv 0 c0)) + (let ([pos ($port-position p)]) + (when pos + ($set-port-position! p (fx+ pos i)))) + (let* ([max (fx- (bytevector-length bv) c0)] + [c1 (($port-read! p) bv c0 max)]) + (unless (fixnum? c1) + (die who "invalid return value from read! procedure" c1)) + (cond + [(fx>= j 0) + (unless (fx<= j max) + (die who "read! returned a value out of range" j)) + ($set-port-index! p c0) + ($set-port-size! p (fx+ c1 c0)) + c1] + [else + (die who "read! returned a value out of range" c1)]))))) + ;;; ---------------------------------------------------------- (module (read-char get-char lookahead-char) (import UNSAFE) - (define (refill-bv-buffer p who) - (when ($port-closed? p) (die who "port is closed" p)) - (let ([bv ($port-buffer p)] [i ($port-index p)] [j ($port-size p)]) - (let ([c0 (fx- j i)]) - (unless (fx= c0 0) (bytevector-copy! bv i bv 0 c0)) - (let ([pos ($port-position p)]) - (when pos - ($set-port-position! p (fx+ pos i)))) - (let* ([max (fx- (bytevector-length bv) c0)] - [c1 (($port-read! p) bv c0 max)]) - (unless (fixnum? c1) - (die who "invalid return value from read! procedure" c1)) - (cond - [(fx>= j 0) - (unless (fx<= j max) - (die who "read! returned a value out of range" j)) - ($set-port-index! p c0) - ($set-port-size! p (fx+ c1 c0)) - c1] - [else - (die who "read! returned a value out of range" c1)]))))) (define (get-char-latin-mode p who inc) (let ([n (refill-bv-buffer p who)]) (cond @@ -1594,7 +1595,32 @@ [($fx= c 0) 0] [else (die 'get-bytevector-n! "count is negative" c)]))) - (define-rrr get-bytevector-some) + (define (get-bytevector-some p) + (define who 'get-bytevector-some) +; (import UNSAFE) + (let ([m ($port-fast-attrs p)]) + (cond + [(eq? m fast-get-byte-tag) + (let ([i ($port-index p)] [j ($port-size p)]) + (let ([cnt (fx- j i)]) + (cond + [(fx> cnt 0) + (let f ([bv (make-bytevector cnt)] + [buf ($port-buffer p)] + [i i] [j j] [idx 0]) + (cond + [(fx= i j) + ($set-port-index! p j) + bv] + [else + (bytevector-u8-set! bv idx (bytevector-u8-ref buf i)) + (f bv buf (fx+ i 1) j (fx+ idx 1))]))] + [else + (refill-bv-buffer p who) + (if (fx= ($port-index p) ($port-size p)) + (eof-object) + (get-bytevector-some p))])))] + [else (die who "invalid port argument" p)]))) (define (get-bytevector-all p) (define (get-it p) diff --git a/scheme/ikarus.numerics.ss b/scheme/ikarus.numerics.ss index 03bd404..aa6a2a0 100644 --- a/scheme/ikarus.numerics.ss +++ b/scheme/ikarus.numerics.ss @@ -2497,11 +2497,17 @@ ) (library (ikarus complexnums) - (export real-part imag-part) - (import (except (ikarus) real-part imag-part)) + (export real-part imag-part magnitude) + (import (except (ikarus) real-part imag-part magnitude)) ;;; stub implementation since we don't have a way of ;;; constructing complex numbers yet. + (define magnitude + (lambda (x) + (if (number? x) + (abs x) + (die 'magnitude "not a number" x)))) + (define real-part (lambda (x) (if (number? x) diff --git a/scheme/last-revision b/scheme/last-revision index 5a57e1b..ea29ccd 100644 --- a/scheme/last-revision +++ b/scheme/last-revision @@ -1 +1 @@ -1361 +1362 diff --git a/scheme/makefile.ss b/scheme/makefile.ss index 58f2774..947b64f 100755 --- a/scheme/makefile.ss +++ b/scheme/makefile.ss @@ -673,7 +673,7 @@ [floor i r ba se] [for-each i r ba se] [gcd i r ba se] - [imag-part r ba se] + [imag-part i r ba se] [inexact i r ba] [inexact? i r ba se] [infinite? i r ba] @@ -689,7 +689,7 @@ [list-tail i r ba se] [list? i r ba se] [log i r ba se] - [magnitude r ba se] + [magnitude i r ba se] [make-polar r ba se] [make-rectangular r ba se] [make-string i r ba se] @@ -711,7 +711,7 @@ [rational-valued? i r ba] [rational? i r ba se] [rationalize i r ba se] - [real-part r ba se] + [real-part i r ba se] [real-valued? i r ba] [real? i r ba se] [reverse i r ba se] @@ -1056,7 +1056,7 @@ [get-bytevector-all i r ip] [get-bytevector-n i r ip] [get-bytevector-n! i r ip] - [get-bytevector-some r ip] + [get-bytevector-some i r ip] [get-char i r ip] [get-datum i r ip] [get-line i r ip] diff --git a/scheme/todo-r6rs.ss b/scheme/todo-r6rs.ss index b1baefc..80eced6 100755 --- a/scheme/todo-r6rs.ss +++ b/scheme/todo-r6rs.ss @@ -185,7 +185,7 @@ [list-tail C ba se] [list? C ba se] [log C ba se] - [magnitude S ba se] + [magnitude C ba se] [make-polar S ba se] [make-rectangular S ba se] [make-string C ba se] @@ -567,7 +567,7 @@ [get-bytevector-all C ip] [get-bytevector-n C ip] [get-bytevector-n! C ip] - [get-bytevector-some S ip] + [get-bytevector-some C ip] [get-char C ip] [get-datum C ip] [get-line C ip]