diff --git a/src/ikarus.boot b/src/ikarus.boot index 51e848c..0e9fc6b 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 373d036..58f0a62 100644 --- a/src/ikarus.bytevectors.ss +++ b/src/ikarus.bytevectors.ss @@ -5,6 +5,8 @@ bytevector-copy! u8-list->bytevector bytevector->u8-list bytevector-u16-native-ref bytevector-u16-ref + bytevector-s16-native-ref + bytevector-s16-ref bytevector-fill! bytevector-copy bytevector=? bytevector-uint-ref bytevector-sint-ref bytevector-uint-set! bytevector-sint-set! @@ -17,6 +19,8 @@ bytevector-copy! u8-list->bytevector bytevector->u8-list bytevector-u16-native-ref bytevector-u16-ref + bytevector-s16-native-ref + bytevector-s16-ref bytevector-fill! bytevector-copy bytevector=? bytevector-uint-ref bytevector-sint-ref bytevector-uint-set! bytevector-sint-set! @@ -104,29 +108,65 @@ ($fx<= 0 i) ($fx< i ($fxsub1 ($bytevector-length x))) ($fxzero? ($fxlogand i 1))) - ($fx+ ($fxsll ($bytevector-u8-ref x i) 8) - ($bytevector-u8-ref x ($fxadd1 i))) + ($fxlogor + ($fxsll ($bytevector-u8-ref x i) 8) + ($bytevector-u8-ref x ($fxadd1 i))) (error 'bytevector-u16-native-ref "invalid index ~s" i)) (error 'bytevector-u16-native-ref "~s is not a bytevector" x)))) + + (define bytevector-s16-native-ref + (lambda (x i) + (if (bytevector? x) + (if (and (fixnum? i) + ($fx<= 0 i) + ($fx< i ($fxsub1 ($bytevector-length x))) + ($fxzero? ($fxlogand i 1))) + ($fxlogor + ($fxsll ($bytevector-s8-ref x i) 8) + ($bytevector-u8-ref x ($fxadd1 i))) + (error 'bytevector-s16-native-ref "invalid index ~s" i)) + (error 'bytevector-s16-native-ref "~s is not a bytevector" x)))) + (define bytevector-u16-ref (lambda (x i end) (if (bytevector? x) (if (and (fixnum? i) ($fx<= 0 i) - ($fx< i ($fxsub1 ($bytevector-length x))) - ($fxzero? ($fxlogand i 1))) + ($fx< i ($fxsub1 ($bytevector-length x)))) (case end [(big) - ($fx+ ($fxsll ($bytevector-u8-ref x i) 8) - ($bytevector-u8-ref x ($fxadd1 i)))] + ($fxlogor + ($fxsll ($bytevector-u8-ref x i) 8) + ($bytevector-u8-ref x ($fxadd1 i)))] [(little) - ($fx+ ($fxsll ($bytevector-u8-ref x (fxadd1 i)) 8) - ($bytevector-u8-ref x i))] + ($fxlogor + ($fxsll ($bytevector-u8-ref x (fxadd1 i)) 8) + ($bytevector-u8-ref x i))] [else (error 'bytevector-u16-ref "invalid endianness ~s" end)]) (error 'bytevector-u16-ref "invalid index ~s" i)) (error 'bytevector-u16-ref "~s is not a bytevector" x)))) + + (define bytevector-s16-ref + (lambda (x i end) + (if (bytevector? x) + (if (and (fixnum? i) + ($fx<= 0 i) + ($fx< i ($fxsub1 ($bytevector-length x)))) + (case end + [(big) + ($fxlogor + ($fxsll ($bytevector-s8-ref x i) 8) + ($bytevector-u8-ref x ($fxadd1 i)))] + [(little) + ($fxlogor + ($fxsll ($bytevector-s8-ref x (fxadd1 i)) 8) + ($bytevector-u8-ref x i))] + [else (error 'bytevector-s16-ref "invalid endianness ~s" end)]) + (error 'bytevector-s16-ref "invalid index ~s" i)) + (error 'bytevector-s16-ref "~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 fd51ac5..42309e5 100755 --- a/src/makefile.ss +++ b/src/makefile.ss @@ -393,6 +393,8 @@ [bytevector-u8-set! i] [bytevector-u16-ref i] [bytevector-u16-native-ref i] + [bytevector-s16-ref i] + [bytevector-s16-native-ref 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 21c06c4..a64a082 100644 --- a/src/tests/bytevectors.ss +++ b/src/tests/bytevectors.ss @@ -192,6 +192,10 @@ (bytevector-u16-ref '#vu8(255 253) 0 'little)] [(lambda (x) (= x 65533)) (bytevector-u16-ref '#vu8(255 253) 0 'big)] + [(lambda (x) (= x -513)) + (bytevector-s16-ref '#vu8(255 253) 0 'little)] + [(lambda (x) (= x -3)) + (bytevector-s16-ref '#vu8(255 253) 0 'big)] )) diff --git a/src/todo-r6rs.ss b/src/todo-r6rs.ss index a985de3..fcb4af1 100755 --- a/src/todo-r6rs.ss +++ b/src/todo-r6rs.ss @@ -364,9 +364,9 @@ [bytevector-ieee-single-native-set! S bv] [bytevector-ieee-single-ref S bv] [bytevector-length C bv] - [bytevector-s16-native-ref S bv] + [bytevector-s16-native-ref C bv] [bytevector-s16-native-set! S bv] - [bytevector-s16-ref S bv] + [bytevector-s16-ref C bv] [bytevector-s16-set! S bv] [bytevector-s32-native-ref S bv] [bytevector-s32-native-set! S bv]