diff --git a/scheme/ikarus.io-primitives.ss b/scheme/ikarus.io-primitives.ss index e8619be..796bedb 100644 --- a/scheme/ikarus.io-primitives.ss +++ b/scheme/ikarus.io-primitives.ss @@ -16,7 +16,7 @@ (library (ikarus io-primitives) (export read-char unread-char peek-char write-char write-byte - put-u8 put-char put-string get-char get-u8 + put-u8 put-char put-string put-bytevector get-char get-u8 newline port-name input-port-name output-port-name close-input-port reset-input-port! flush-output-port close-output-port get-line) @@ -25,7 +25,7 @@ (ikarus system $fx) (ikarus system $ports) (except (ikarus) read-char unread-char peek-char write-char write-byte - put-u8 put-char put-string get-char get-u8 + put-u8 put-char put-string put-bytevector get-char get-u8 newline port-name input-port-name output-port-name close-input-port reset-input-port! flush-output-port close-output-port get-line)) @@ -244,6 +244,54 @@ c)) ($put-string p s i j)))]))) + (module (put-bytevector) + (import (ikarus system $bytevectors) + (ikarus system $fx)) + (define ($put-bytevector p bv i j) + (unless ($fx= i j) + ($write-byte ($bytevector-u8-ref bv i) p) + ($put-bytevector p bv ($fx+ i 1) j))) + (define put-bytevector + (case-lambda + [(p s) + (unless (output-port? p) + (error 'put-bytevector "not an output port" p)) + (unless (bytevector? s) + (error 'put-bytevector "not a bytevector" s)) + ($put-bytevector p s 0 (bytevector-length s))] + [(p s i) + (unless (output-port? p) + (error 'put-bytevector "not an output port" p)) + (unless (bytevector? s) + (error 'put-bytevector "not a bytevector" s)) + (let ([len ($bytevector-length s)]) + (unless (fixnum? i) + (error 'put-bytevector "starting index is not a fixnum" i)) + (when (or ($fx< i 0) ($fx> i len)) + (error 'put-bytevector + (format "starting index is out of range 0..~a" len) + i)) + ($put-bytevector p s i len))] + [(p s i c) + (unless (output-port? p) + (error 'put-bytevector "not an output port" p)) + (unless (bytevector? s) + (error 'put-bytevector "not a bytevector" s)) + (let ([len ($bytevector-length s)]) + (unless (fixnum? i) + (error 'put-bytevector "starting index is not a fixnum" i)) + (when (or ($fx< i 0) ($fx> i len)) + (error 'put-bytevector + (format "starting index is out of range 0..~a" len) + i)) + (unless (fixnum? c) + (error 'put-bytevector "count is not a fixnum" c)) + (let ([j (+ i c)]) + (when (or ($fx< c 0) (> j len)) + (error 'put-bytevector + (format "count is out of range 0..~a" (- len i)) + c)) + ($put-bytevector p s i j)))]))) ) diff --git a/scheme/last-revision b/scheme/last-revision index af6316f..0a75ff7 100644 --- a/scheme/last-revision +++ b/scheme/last-revision @@ -1 +1 @@ -1109 +1110 diff --git a/scheme/makefile.ss b/scheme/makefile.ss index 107fa13..297e837 100755 --- a/scheme/makefile.ss +++ b/scheme/makefile.ss @@ -1135,7 +1135,7 @@ [port-position r ip] [port-transcoder r ip] [port? i r ip] - [put-bytevector r ip] + [put-bytevector i r ip] [put-char i r ip] [put-datum i r ip] [put-string i r ip] diff --git a/scheme/todo-r6rs.ss b/scheme/todo-r6rs.ss index 4168f16..193cf34 100755 --- a/scheme/todo-r6rs.ss +++ b/scheme/todo-r6rs.ss @@ -640,7 +640,7 @@ [port-position S ip] [port-transcoder S ip] [port? C ip] - [put-bytevector S ip] + [put-bytevector C ip] [put-char C ip] [put-datum C ip] [put-string C ip]