alien.endian: read 64bit numbers of the opposite endian as two 32bit numbers, then bitor them together

db4
Doug Coleman 2011-11-15 13:22:12 -08:00
parent ddcc87f58a
commit 5a2243d481
1 changed files with 17 additions and 4 deletions

View File

@ -3,7 +3,7 @@
USING: accessors alien alien.accessors alien.c-types alien.data USING: accessors alien alien.accessors alien.c-types alien.data
classes.struct.private combinators compiler.units endian fry classes.struct.private combinators compiler.units endian fry
generalizations kernel macros math namespaces sequences words generalizations kernel macros math namespaces sequences words
arrays slots ; arrays slots math.bitwise ;
QUALIFIED-WITH: alien.c-types ac QUALIFIED-WITH: alien.c-types ac
IN: alien.endian IN: alien.endian
@ -57,9 +57,22 @@ ERROR: unknown-endian-c-type symbol ;
: change-c-type-accessors ( n ? c-type -- c-type' ) : change-c-type-accessors ( n ? c-type -- c-type' )
endian-c-type>c-type-symbol "c-type" word-prop clone endian-c-type>c-type-symbol "c-type" word-prop clone
-rot -rot over 8 = [
[ '[ [ _ _ byte-reverse ] compose ] change-getter drop ] [
[ '[ [ [ _ _ byte-reverse ] 2dip ] prepose ] change-setter ] 3bi ; nip
[
[
[ alien-unsigned-4 4 f byte-reverse 32 shift ]
[ 4 + alien-unsigned-4 4 f byte-reverse ] 2bi bitor
]
] dip [ [ 64 >signed ] compose ] when
>>getter drop
]
[ '[ [ [ _ _ byte-reverse ] 2dip ] prepose ] change-setter ] 3bi
] [
[ '[ [ _ _ byte-reverse ] compose ] change-getter drop ]
[ '[ [ [ _ _ byte-reverse ] 2dip ] prepose ] change-setter ] 3bi
] if ;
: typedef-endian ( n ? c-type endian -- ) : typedef-endian ( n ? c-type endian -- )
native-endianness get = [ native-endianness get = [