diff --git a/src/ikarus.boot b/src/ikarus.boot index 64de896..b04a456 100644 Binary files a/src/ikarus.boot and b/src/ikarus.boot differ diff --git a/src/ikarus.bytevectors.ss b/src/ikarus.bytevectors.ss index 464d682..d0d7728 100644 --- a/src/ikarus.bytevectors.ss +++ b/src/ikarus.bytevectors.ss @@ -5,8 +5,8 @@ bytevector-copy! u8-list->bytevector bytevector->u8-list bytevector-u16-native-ref bytevector-u16-native-set! bytevector-u16-ref bytevector-u16-set! - bytevector-s16-native-ref - bytevector-s16-ref + bytevector-s16-native-ref bytevector-s16-native-set! + bytevector-s16-ref bytevector-s16-set! bytevector-fill! bytevector-copy bytevector=? bytevector-uint-ref bytevector-sint-ref bytevector-uint-set! bytevector-sint-set! @@ -19,8 +19,8 @@ bytevector-copy! u8-list->bytevector bytevector->u8-list bytevector-u16-native-ref bytevector-u16-native-set! bytevector-u16-ref bytevector-u16-set! - bytevector-s16-native-ref - bytevector-s16-ref + bytevector-s16-native-ref bytevector-s16-native-set! + bytevector-s16-ref bytevector-s16-set! bytevector-fill! bytevector-copy bytevector=? bytevector-uint-ref bytevector-sint-ref bytevector-uint-set! bytevector-sint-set! @@ -119,7 +119,7 @@ (if (bytevector? x) (if (and (fixnum? n) ($fx<= 0 n) - ($fx<= n (expt 2 16))) + ($fx<= n #xFFFF)) (if (and (fixnum? i) ($fx<= 0 i) ($fx< i ($fxsub1 ($bytevector-length x))) @@ -131,6 +131,24 @@ (error 'bytevector-u8-native-set! "invalid value ~s" n)) (error 'bytevector-u16-native-set! "~s is not a bytevector" x)))) + + (define bytevector-s16-native-set! + (lambda (x i n) + (if (bytevector? x) + (if (and (fixnum? n) + ($fx<= #x-8000 n) + ($fx<= n #x7FFF)) + (if (and (fixnum? i) + ($fx<= 0 i) + ($fx< i ($fxsub1 ($bytevector-length x))) + ($fxzero? ($fxlogand i 1))) + (begin + ($bytevector-set! x i ($fxsra n 8)) + ($bytevector-set! x ($fxadd1 i) n)) + (error 'bytevector-s16-native-set! "invalid index ~s" i)) + (error 'bytevector-s16-native-set! "invalid value ~s" n)) + (error 'bytevector-s16-native-set! "~s is not a bytevector" x)))) + (define bytevector-s16-native-ref (lambda (x i) (if (bytevector? x) @@ -203,6 +221,28 @@ (error 'bytevector-s16-ref "invalid index ~s" i)) (error 'bytevector-s16-ref "~s is not a bytevector" x)))) + + (define bytevector-s16-set! + (lambda (x i n end) + (if (bytevector? x) + (if (and (fixnum? n) + ($fx<= #x-8000 n) + ($fx<= n #x7FFF)) + (if (and (fixnum? i) + ($fx<= 0 i) + ($fx< i ($fxsub1 ($bytevector-length x)))) + (case end + [(big) + ($bytevector-set! x i ($fxsra n 8)) + ($bytevector-set! x ($fxadd1 i) n)] + [(little) + ($bytevector-set! x i n) + ($bytevector-set! x ($fxadd1 i) (fxsra n 8))] + [else (error 'bytevector-s16-ref "invalid endianness ~s" end)]) + (error 'bytevector-s16-set! "invalid index ~s" i)) + (error 'bytevector-s16-set! "invalid value ~s" n)) + (error 'bytevector-s16-set! "~s is not a bytevector" x)))) + (define bytevector->u8-list (lambda (x) (unless (bytevector? x) diff --git a/src/makefile.ss b/src/makefile.ss index 5c31d31..2e7a32d 100755 --- a/src/makefile.ss +++ b/src/makefile.ss @@ -396,7 +396,9 @@ [bytevector-u16-native-ref i] [bytevector-u16-native-set! i] [bytevector-s16-ref i] + [bytevector-s16-set! i] [bytevector-s16-native-ref i] + [bytevector-s16-native-set! i] [bytevector->u8-list i] [u8-list->bytevector i] [bytevector-copy! i] diff --git a/src/tests/bytevectors.ss b/src/tests/bytevectors.ss index 8bab11c..11a82ac 100644 --- a/src/tests/bytevectors.ss +++ b/src/tests/bytevectors.ss @@ -210,6 +210,35 @@ (bytevector-u16-set! v 0 12345 'big) (bytevector-u16-ref v 0 'big))] + [(lambda (x) (= x 12345)) + (let ([v (make-bytevector 2)]) + (bytevector-s16-native-set! v 0 12345) + (bytevector-s16-native-ref v 0))] + [(lambda (x) (= x 12345)) + (let ([v (make-bytevector 2)]) + (bytevector-s16-set! v 0 12345 'little) + (bytevector-s16-ref v 0 'little))] + [(lambda (x) (= x 12345)) + (let ([v (make-bytevector 2)]) + (bytevector-s16-set! v 0 12345 'big) + (bytevector-s16-ref v 0 'big))] + + [(lambda (x) (= x -12345)) + (let ([v (make-bytevector 2)]) + (bytevector-s16-native-set! v 0 -12345) + (bytevector-s16-native-ref v 0))] + [(lambda (x) (= x -12345)) + (let ([v (make-bytevector 2)]) + (bytevector-s16-set! v 0 -12345 'little) + (bytevector-s16-ref v 0 'little))] + [(lambda (x) (= x -12345)) + (let ([v (make-bytevector 2)]) + (bytevector-s16-set! v 0 -12345 'big) + (bytevector-s16-ref v 0 'big))] + + + + )) diff --git a/src/todo-r6rs.ss b/src/todo-r6rs.ss index c68af99..81115c8 100755 --- a/src/todo-r6rs.ss +++ b/src/todo-r6rs.ss @@ -365,9 +365,9 @@ [bytevector-ieee-single-ref S bv] [bytevector-length C bv] [bytevector-s16-native-ref C bv] - [bytevector-s16-native-set! S bv] + [bytevector-s16-native-set! C bv] [bytevector-s16-ref C bv] - [bytevector-s16-set! S bv] + [bytevector-s16-set! C bv] [bytevector-s32-native-ref S bv] [bytevector-s32-native-set! S bv] [bytevector-s32-ref S bv] @@ -383,7 +383,7 @@ [bytevector-u16-native-ref C bv] [bytevector-u16-native-set! C bv] [bytevector-u16-ref C bv] - [bytevector-u16-set! S bv] + [bytevector-u16-set! C bv] [bytevector-u32-native-ref S bv] [bytevector-u32-native-set! S bv] [bytevector-u32-ref S bv]