From c3ec74f137cd86284de1f16e02d172287eeca1b5 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Wed, 29 Dec 2021 21:21:44 -0800 Subject: [PATCH] endian: replaces io.binary and io.binary.fast. --- basis/bit-arrays/bit-arrays.factor | 2 +- basis/bitstreams/bitstreams.factor | 2 +- basis/bootstrap/image/image.factor | 12 +- basis/cbor/cbor.factor | 2 +- basis/checksums/common/common.factor | 4 +- basis/checksums/crc16/crc16.factor | 5 +- basis/checksums/fletcher/fletcher.factor | 2 +- basis/checksums/internet/internet.factor | 2 +- basis/checksums/metrohash/metrohash.factor | 2 +- basis/checksums/murmur/murmur.factor | 2 +- basis/checksums/sha/sha.factor | 2 +- basis/checksums/superfast/superfast.factor | 2 +- basis/checksums/wyhash/wyhash.factor | 2 +- basis/checksums/xxhash/xxhash.factor | 2 +- .../cfg/value-numbering/simd/simd.factor | 2 +- basis/compression/inflate/inflate.factor | 2 +- basis/cpu/ppc/assembler/assembler.factor | 3 +- basis/cpu/x86/assembler/assembler.factor | 2 +- basis/cpu/x86/features/features-tests.factor | 2 +- basis/dns/dns.factor | 4 +- basis/endian/endian-tests.factor | 42 ++++- basis/endian/endian.factor | 173 +++++++++++++++++- basis/furnace/auth/auth.factor | 4 +- basis/hints/hints.factor | 11 +- basis/io/encodings/euc/euc.factor | 7 +- basis/io/encodings/gb18030/gb18030.factor | 2 +- basis/io/encodings/iso2022/iso2022.factor | 4 +- basis/io/encodings/shift-jis/shift-jis.factor | 9 +- basis/io/encodings/utf32/utf32.factor | 4 +- basis/io/files/windows/windows.factor | 15 +- .../io/sockets/secure/openssl/openssl.factor | 2 +- basis/io/sockets/sockets.factor | 4 +- basis/math/bitwise/bitwise-docs.factor | 18 ++ basis/math/bitwise/bitwise-tests.factor | 4 + basis/math/bitwise/bitwise.factor | 9 + basis/msgpack/msgpack.factor | 4 +- basis/random/random.factor | 10 +- basis/serialize/serialize.factor | 2 +- basis/system-info/macosx/macosx.factor | 2 +- basis/uuid/uuid.factor | 2 +- basis/windows/processes/processes.factor | 4 +- core/checksums/crc32/crc32.factor | 12 +- core/io/binary/authors.txt | 1 - core/io/binary/binary-docs.factor | 72 -------- core/io/binary/binary-tests.factor | 37 ---- core/io/binary/binary.factor | 43 ----- core/io/binary/summary.txt | 1 - core/io/encodings/utf16/utf16.factor | 14 +- extra/asn1/asn1.factor | 2 +- extra/audio/aiff/aiff.factor | 5 +- extra/audio/wav/wav.factor | 2 +- extra/base24/base24-tests.factor | 2 +- extra/base24/base24.factor | 4 +- extra/base32/base32.factor | 2 +- extra/base36/base36.factor | 2 +- extra/base58/base58.factor | 2 +- extra/base62/base62.factor | 2 +- extra/base85/base85.factor | 2 +- .../cuckoo-filters/cuckoo-filters.factor | 2 +- extra/benchmark/udp-echo0/udp-echo0.factor | 2 +- extra/bittorrent/bittorrent.factor | 4 +- extra/bson/reader/reader.factor | 2 +- extra/bson/writer/writer.factor | 4 +- extra/compiler/cfg/gvn/simd/simd.factor | 4 +- extra/dbf/dbf.factor | 4 +- extra/fastcgi/fastcgi.factor | 4 +- extra/git/git.factor | 4 +- extra/icfp/2006/2006.factor | 2 +- extra/images/bitmap/bitmap.factor | 4 +- extra/images/gif/gif.factor | 4 +- extra/images/jpeg/jpeg.factor | 4 +- extra/images/png/png.factor | 4 +- extra/images/tga/tga.factor | 2 +- extra/images/tiff/tiff.factor | 2 +- extra/io/binary/fast/authors.txt | 1 - extra/io/binary/fast/fast-tests.factor | 17 -- extra/io/binary/fast/fast.factor | 128 ------------- extra/key-logger/key-logger.factor | 6 +- extra/libusb/libusb.factor | 2 +- extra/macho/macho.factor | 2 +- extra/midi/midi.factor | 2 +- extra/mongodb/operations/operations.factor | 8 +- extra/protocols/tftp/tftp.factor | 4 +- extra/shapefiles/shapefiles.factor | 7 +- extra/terminfo/terminfo.factor | 9 +- extra/tinyvg/tinyvg.factor | 2 +- extra/totp/totp.factor | 2 +- extra/tzinfo/tzinfo.factor | 6 +- extra/ulid/ulid-tests.factor | 2 +- extra/ulid/ulid.factor | 2 +- extra/windows/fullscreen/fullscreen.factor | 4 +- extra/windows/version/version.factor | 2 +- 92 files changed, 392 insertions(+), 461 deletions(-) delete mode 100644 core/io/binary/authors.txt delete mode 100644 core/io/binary/binary-docs.factor delete mode 100644 core/io/binary/binary-tests.factor delete mode 100644 core/io/binary/binary.factor delete mode 100644 core/io/binary/summary.txt delete mode 100644 extra/io/binary/fast/authors.txt delete mode 100644 extra/io/binary/fast/fast-tests.factor delete mode 100644 extra/io/binary/fast/fast.factor diff --git a/basis/bit-arrays/bit-arrays.factor b/basis/bit-arrays/bit-arrays.factor index 2bb4727d13..c71dc243d8 100644 --- a/basis/bit-arrays/bit-arrays.factor +++ b/basis/bit-arrays/bit-arrays.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2007, 2011 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors alien alien.accessors byte-arrays io.binary +USING: accessors alien alien.accessors byte-arrays endian kernel kernel.private math math.bitwise parser sequences sequences.private vocabs.loader ; IN: bit-arrays diff --git a/basis/bitstreams/bitstreams.factor b/basis/bitstreams/bitstreams.factor index 6b699cea0d..fb917f9794 100644 --- a/basis/bitstreams/bitstreams.factor +++ b/basis/bitstreams/bitstreams.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2009 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: accessors byte-arrays byte-vectors -combinators.short-circuit io.binary kernel math math.bitwise +combinators.short-circuit endian kernel math math.bitwise sequences sequences.private ; IN: bitstreams diff --git a/basis/bootstrap/image/image.factor b/basis/bootstrap/image/image.factor index 2e2ef09153..6bf93c7636 100644 --- a/basis/bootstrap/image/image.factor +++ b/basis/bootstrap/image/image.factor @@ -4,12 +4,12 @@ USING: accessors arrays assocs byte-arrays classes classes.builtin classes.private classes.tuple classes.tuple.private combinators combinators.short-circuit combinators.smart command-line compiler.codegen.relocation -compiler.units generic generic.single.private grouping -hashtables hashtables.private io io.binary io.encodings.binary -io.files io.pathnames kernel kernel.private layouts make math -math.order namespaces namespaces.private parser parser.notes -prettyprint quotations sequences sequences.private source-files -splitting strings system vectors vocabs words ; +compiler.units endian generic generic.single.private grouping +hashtables hashtables.private io io.encodings.binary io.files +io.pathnames kernel kernel.private layouts make math +math.bitwise math.order namespaces namespaces.private parser +parser.notes prettyprint quotations sequences sequences.private +source-files splitting strings system vectors vocabs words ; IN: bootstrap.image : arch-name ( os cpu -- arch ) diff --git a/basis/cbor/cbor.factor b/basis/cbor/cbor.factor index 2ec0341757..adcc651cf8 100644 --- a/basis/cbor/cbor.factor +++ b/basis/cbor/cbor.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license USING: accessors arrays assocs base64 byte-arrays calendar -calendar.format calendar.parser combinators io io.binary +calendar.format calendar.parser combinators endian io io.encodings.binary io.encodings.string io.encodings.utf8 io.streams.byte-array io.streams.string kernel math math.bitwise math.floats.half present sequences strings urls ; diff --git a/basis/checksums/common/common.factor b/basis/checksums/common/common.factor index 511910ec6e..bfd8554d75 100644 --- a/basis/checksums/common/common.factor +++ b/basis/checksums/common/common.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2006, 2008 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors byte-arrays byte-vectors checksums grouping -io.binary kernel locals make math sequences ; +USING: accessors byte-arrays byte-vectors checksums endian +grouping kernel locals make math sequences ; IN: checksums.common : calculate-pad-length ( length -- length' ) diff --git a/basis/checksums/crc16/crc16.factor b/basis/checksums/crc16/crc16.factor index 415a4090a4..0097b07c94 100644 --- a/basis/checksums/crc16/crc16.factor +++ b/basis/checksums/crc16/crc16.factor @@ -1,7 +1,6 @@ ! Copyright (C) 2016 Alexander Ilin. ! See http://factorcode.org/license.txt for BSD license. -USING: checksums io.binary kernel math sequences -sequences.private ; +USING: checksums endian kernel math sequences sequences.private ; IN: checksums.crc16 CONSTANT: crc16-polynomial 0xa001 @@ -16,7 +15,7 @@ CONSTANT: crc16-table V{ } : (crc16) ( crc ch -- crc ) dupd bitxor - mask-byte crc16-table nth-unsafe + 0xff bitand crc16-table nth-unsafe swap -8 shift bitxor ; inline SINGLETON: crc16 diff --git a/basis/checksums/fletcher/fletcher.factor b/basis/checksums/fletcher/fletcher.factor index 257912d8a8..bbe2de1027 100644 --- a/basis/checksums/fletcher/fletcher.factor +++ b/basis/checksums/fletcher/fletcher.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2013 John Benediktsson ! See http://factorcode.org/license.txt for BSD license -USING: checksums grouping io.binary kernel locals math sequences +USING: checksums endian grouping kernel locals math sequences ; IN: checksums.fletcher diff --git a/basis/checksums/internet/internet.factor b/basis/checksums/internet/internet.factor index 926e184fe5..41ff7a904f 100644 --- a/basis/checksums/internet/internet.factor +++ b/basis/checksums/internet/internet.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2010 John Benediktsson ! See http://factorcode.org/license.txt for BSD license -USING: checksums grouping io.binary kernel math sequences ; +USING: checksums endian grouping kernel math sequences ; IN: checksums.internet diff --git a/basis/checksums/metrohash/metrohash.factor b/basis/checksums/metrohash/metrohash.factor index ad9b6dcaac..d9f2620c34 100644 --- a/basis/checksums/metrohash/metrohash.factor +++ b/basis/checksums/metrohash/metrohash.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2018 John Benediktsson. ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien.c-types alien.data byte-arrays checksums -combinators grouping io.binary kernel locals math math.bitwise +combinators endian grouping kernel locals math math.bitwise sequences specialized-arrays ; SPECIALIZED-ARRAY: uint64_t SPECIALIZED-ARRAY: uint32_t diff --git a/basis/checksums/murmur/murmur.factor b/basis/checksums/murmur/murmur.factor index d18b1318a5..4a0955442c 100644 --- a/basis/checksums/murmur/murmur.factor +++ b/basis/checksums/murmur/murmur.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien alien.c-types alien.data byte-arrays -checksums fry grouping io.binary kernel math math.bitwise +checksums endian fry grouping kernel math math.bitwise math.ranges sequences ; IN: checksums.murmur diff --git a/basis/checksums/sha/sha.factor b/basis/checksums/sha/sha.factor index f87a32d250..43a3847ab1 100644 --- a/basis/checksums/sha/sha.factor +++ b/basis/checksums/sha/sha.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2008 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien.c-types arrays checksums checksums.common -combinators combinators.smart fry grouping io.binary kernel +combinators combinators.smart endian fry grouping kernel kernel.private literals locals math math.bitwise math.ranges sequences sequences.generalizations sequences.private specialized-arrays ; diff --git a/basis/checksums/superfast/superfast.factor b/basis/checksums/superfast/superfast.factor index c3b1545c50..e9491a0fb4 100644 --- a/basis/checksums/superfast/superfast.factor +++ b/basis/checksums/superfast/superfast.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien alien.c-types alien.data byte-arrays -checksums combinators fry grouping io.binary kernel math +checksums combinators endian fry grouping kernel math math.bitwise math.ranges sequences sequences.private ; IN: checksums.superfast diff --git a/basis/checksums/wyhash/wyhash.factor b/basis/checksums/wyhash/wyhash.factor index 00492f98ec..2035a9b7e8 100644 --- a/basis/checksums/wyhash/wyhash.factor +++ b/basis/checksums/wyhash/wyhash.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license USING: accessors alien.c-types alien.data byte-arrays checksums -grouping io.binary kernel literals math math.bitwise math.order +endian grouping kernel literals math math.bitwise math.order sequences sequences.generalizations sequences.private specialized-arrays ; SPECIALIZED-ARRAY: uint64_t diff --git a/basis/checksums/xxhash/xxhash.factor b/basis/checksums/xxhash/xxhash.factor index 1437eb81d9..021cf34f74 100644 --- a/basis/checksums/xxhash/xxhash.factor +++ b/basis/checksums/xxhash/xxhash.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien alien.c-types alien.data byte-arrays -checksums combinators generalizations grouping io.binary kernel +checksums combinators endian generalizations grouping kernel locals math math.bitwise math.ranges sequences specialized-arrays ; SPECIALIZED-ARRAY: uint64_t diff --git a/basis/compiler/cfg/value-numbering/simd/simd.factor b/basis/compiler/cfg/value-numbering/simd/simd.factor index adff45b5e5..298e0b31e0 100644 --- a/basis/compiler/cfg/value-numbering/simd/simd.factor +++ b/basis/compiler/cfg/value-numbering/simd/simd.factor @@ -5,7 +5,7 @@ combinators.short-circuit compiler.cfg.instructions compiler.cfg.utilities compiler.cfg.value-numbering.graph compiler.cfg.value-numbering.math compiler.cfg.value-numbering.rewrite cpu.architecture -generalizations grouping io.binary kernel locals make math +endian generalizations grouping kernel locals make math sequences ; IN: compiler.cfg.value-numbering.simd diff --git a/basis/compression/inflate/inflate.factor b/basis/compression/inflate/inflate.factor index fe17d23083..c6f22b912b 100644 --- a/basis/compression/inflate/inflate.factor +++ b/basis/compression/inflate/inflate.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2009, 2020 Marc Fauconneau, Abtin Molavi, Jacob Fischer. ! See http://factorcode.org/license.txt for BSD license. USING: accessors arrays assocs byte-vectors combinators -combinators.smart compression.huffman fry hashtables io.binary +combinators.smart compression.huffman endian fry hashtables kernel literals locals math math.bitwise math.order math.ranges sequences sorting memoize combinators.short-circuit byte-arrays ; QUALIFIED-WITH: bitstreams bs diff --git a/basis/cpu/ppc/assembler/assembler.factor b/basis/cpu/ppc/assembler/assembler.factor index 6f083373d5..137032d17a 100644 --- a/basis/cpu/ppc/assembler/assembler.factor +++ b/basis/cpu/ppc/assembler/assembler.factor @@ -1,6 +1,7 @@ ! Copyright (C) 2011 Erik Charlebois. ! See http://factorcode.org/license.txt for BSD license. -USING: kernel namespaces words math math.order locals math.bitwise io.binary make ; +USING: kernel namespaces words math math.order locals +math.bitwise endian make ; IN: cpu.ppc.assembler ! This vocabulary implements the V2.06B Power ISA found at http://www.power.org. diff --git a/basis/cpu/x86/assembler/assembler.factor b/basis/cpu/x86/assembler/assembler.factor index 46baef6121..4ea7e4eb08 100644 --- a/basis/cpu/x86/assembler/assembler.factor +++ b/basis/cpu/x86/assembler/assembler.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2005, 2010 Slava Pestov, Joe Groff. ! See http://factorcode.org/license.txt for BSD license. -USING: arrays io.binary kernel combinators +USING: arrays endian kernel combinators combinators.short-circuit math math.bitwise locals namespaces make sequences words system layouts math.order accessors cpu.x86.assembler.operands cpu.x86.assembler.operands.private ; diff --git a/basis/cpu/x86/features/features-tests.factor b/basis/cpu/x86/features/features-tests.factor index 63582ec1bf..b5a33637ee 100644 --- a/basis/cpu/x86/features/features-tests.factor +++ b/basis/cpu/x86/features/features-tests.factor @@ -1,5 +1,5 @@ USING: cpu.x86.features tools.test kernel sequences math math.order -strings system io.binary ; +strings system endian ; IN: cpu.x86.features.tests [ t ] [ sse-version 0 42 between? ] unit-test diff --git a/basis/dns/dns.factor b/basis/dns/dns.factor index 6bb3204b32..d31e5d830b 100644 --- a/basis/dns/dns.factor +++ b/basis/dns/dns.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2010 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien.enums alien.syntax arrays calendar -combinators combinators.smart constructors destructors grouping -io io.binary io.encodings.binary io.encodings.string +combinators combinators.smart constructors destructors endian +grouping io io.encodings.binary io.encodings.string io.encodings.utf8 io.sockets io.sockets.private io.streams.byte-array io.timeouts kernel make math math.bitwise math.parser namespaces random sequences slots.syntax splitting diff --git a/basis/endian/endian-tests.factor b/basis/endian/endian-tests.factor index f0650cc8fd..1b1889da9f 100644 --- a/basis/endian/endian-tests.factor +++ b/basis/endian/endian-tests.factor @@ -1,6 +1,46 @@ ! Copyright (C) 2009 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: endian kernel namespaces tools.test ; +USING: classes endian endian.private kernel math namespaces tools.test ; { t } [ [ endianness get big-endian = ] with-big-endian ] unit-test { t } [ [ endianness get little-endian = ] with-little-endian ] unit-test + +{ 0x0102 } [ B{ 01 02 } 2be> ] unit-test +{ 0x01020304 } [ B{ 01 02 03 04 } 4be> ] unit-test +{ 0x0102030405060708 } [ B{ 01 02 03 04 05 06 07 08 } 8be> ] unit-test + +{ 0x0102 } [ B{ 02 01 } 2le> ] unit-test +{ 0x01020304 } [ B{ 04 03 02 01 } 4le> ] unit-test +{ 0x0102030405060708 } [ B{ 08 07 06 05 04 03 02 01 } 8le> ] unit-test + +{ 0x7a2c793b2ff08554 } [ + B{ 0x54 0x85 0xf0 0x2f 0x3b 0x79 0x2c 0x7a } le> +] unit-test + +{ 0x988a259c3433f237 } [ + B{ 0x37 0xf2 0x33 0x34 0x9c 0x25 0x8a 0x98 } le> +] unit-test + +{ 0x03020100 } [ B{ 0 1 2 3 } le> ] unit-test +{ 0x00010203 } [ B{ 0 1 2 3 } be> ] unit-test + +{ 0x332211 } [ + B{ 0x11 0x22 0x33 } le> +] unit-test + +{ 0x04030201 } [ B{ 1 2 3 4 } signed-le> ] unit-test +{ 0x01020304 } [ B{ 1 2 3 4 } signed-be> ] unit-test + +{ -12 } [ B{ 0xf4 0xff 0xff 0xff } signed-le> ] unit-test +{ -12 } [ B{ 0xff 0xff 0xff 0xf4 } signed-be> ] unit-test + +{ B{ 0 0 4 0xd2 } } [ 1234 4 >be ] unit-test +{ B{ 0 0 0 0 0 0 4 0xd2 } } [ 1234 8 >be ] unit-test +{ B{ 0xd2 4 0 0 } } [ 1234 4 >le ] unit-test +{ B{ 0xd2 4 0 0 0 0 0 0 } } [ 1234 8 >le ] unit-test + +{ 1234 } [ 1234 4 >be be> ] unit-test +{ 1234 } [ 1234 4 >le le> ] unit-test + +{ fixnum } [ B{ 0 0 0 0 0 0 0 0 0 0 } be> class-of ] unit-test + diff --git a/basis/endian/endian.factor b/basis/endian/endian.factor index ba949b3aaa..90c6e28147 100644 --- a/basis/endian/endian.factor +++ b/basis/endian/endian.factor @@ -1,7 +1,13 @@ ! Copyright (C) 2009 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: alien.c-types alien.data grouping io.binary kernel + +USING: alien.c-types alien.data byte-arrays combinators +combinators.smart endian kernel math math.ranges sequences +sequences.generalizations ; + +USING: alien.c-types alien.data grouping kernel math.bitwise namespaces sequences ; + IN: endian SINGLETONS: big-endian little-endian ; @@ -9,12 +15,160 @@ SINGLETONS: big-endian little-endian ; : compute-native-endianness ( -- class ) 1 int char deref 0 = big-endian little-endian ? ; foldable + ( seq -- x ) 0 [ [ 8 shift ] dip + ] reduce ; + +: slow-le> ( seq -- x ) 0 [ 8 * shift + ] reduce-index ; + +ERROR: bad-length bytes n ; + +: check-length ( bytes n -- bytes n ) + 2dup [ length ] dip > [ bad-length ] when ; inline + +<< +: be-range ( n -- range ) + 1 - 8 * 0 -8 ; inline + +: le-range ( n -- range ) + 1 - 8 * 0 swap 8 ; inline + +: reassemble-bytes ( range -- quot ) + [ [ [ ] ] [ '[ _ shift ] ] if-zero ] map + '[ [ _ spread ] [ bitor ] reduce-outputs ] ; inline + +MACRO: reassemble-be ( n -- quot ) be-range reassemble-bytes ; + +MACRO: reassemble-le ( n -- quot ) le-range reassemble-bytes ; +>> + +:: n-be> ( bytes n -- x ) + bytes n check-length drop n firstn-unsafe n reassemble-be ; inline + +:: n-le> ( bytes n -- x ) + bytes n check-length drop n firstn-unsafe n reassemble-le ; inline + +! HINTS: n-be> { byte-array object } ; +! HINTS: n-le> { byte-array object } ; + +! { >le >be } [ +! { { fixnum fixnum } { bignum fixnum } } +! set-specializer +! ] each + +! { le> be> } [ +! { byte-array } set-specializer +! ] each + +: if-endian ( endian bytes-quot seq-quot -- ) + [ + compute-native-endianness = + [ dup byte-array? ] [ f ] if + ] 2dip if ; inline + +: 2be> ( bytes -- x ) + big-endian [ uint16_t deref ] [ 2 n-be> ] if-endian ; + +: 4be> ( bytes -- x ) + big-endian [ uint32_t deref ] [ 4 n-be> ] if-endian ; + +: 8be> ( bytes -- x ) + big-endian [ uint64_t deref ] [ 8 n-be> ] if-endian ; + +: 2le> ( bytes -- x ) + little-endian [ uint16_t deref ] [ 2 n-le> ] if-endian ; + +: 4le> ( bytes -- x ) + little-endian [ uint32_t deref ] [ 4 n-le> ] if-endian ; + +: 8le> ( bytes -- x ) + little-endian [ uint64_t deref ] [ 8 n-le> ] if-endian ; + +PRIVATE> + +: be> ( bytes -- x ) + dup length { + { 2 [ 2be> ] } + { 4 [ 4be> ] } + { 8 [ 8be> ] } + [ drop slow-be> ] + } case ; + +: le> ( bytes -- x ) + dup length { + { 2 [ 2le> ] } + { 4 [ 4le> ] } + { 8 [ 8le> ] } + [ drop slow-le> ] + } case ; + + ( x seq -- n ) + length 8 * 2dup 1 - bit? [ 2^ - ] [ drop ] if ; inline + +: slow-signed-le> ( bytes -- x ) [ le> ] [ signed> ] bi ; + +: slow-signed-be> ( bytes -- x ) [ be> ] [ signed> ] bi ; + +PRIVATE> + +: signed-be> ( bytes -- x ) + big-endian [ + dup length { + { 2 [ int16_t deref ] } + { 4 [ int32_t deref ] } + { 8 [ int64_t deref ] } + [ drop slow-signed-be> ] + } case + ] [ slow-signed-be> ] if-endian ; + +: signed-le> ( bytes -- x ) + little-endian [ + dup length { + { 2 [ int16_t deref ] } + { 4 [ int32_t deref ] } + { 8 [ int64_t deref ] } + [ drop slow-signed-le> ] + } case + ] [ slow-signed-le> ] if-endian ; + +: nth-byte ( x n -- b ) -8 * shift 0xff bitand ; inline + +slow-be ( x n -- byte-array ) map-bytes ; + +: >slow-le ( x n -- byte-array ) map-bytes ; + +PRIVATE> + +: >le ( x n -- bytes ) + compute-native-endianness little-endian = [ + { + { 2 [ int16_t ] } + { 4 [ int32_t ] } + { 8 [ int64_t ] } + [ >slow-le ] + } case + ] [ >slow-le ] if ; + +: >be ( x n -- bytes ) + compute-native-endianness big-endian = [ + { + { 2 [ int16_t ] } + { 4 [ int32_t ] } + { 8 [ int64_t ] } + [ >slow-be ] + } case + ] [ >slow-be ] if ; + SYMBOL: native-endianness native-endianness [ compute-native-endianness ] initialize -SYMBOL: endianness -endianness [ native-endianness get-global ] initialize - HOOK: >native-endian native-endianness ( obj n -- bytes ) M: big-endian >native-endian >be ; @@ -27,6 +181,9 @@ M: big-endian unsigned-native-endian> be> ; M: little-endian unsigned-native-endian> le> ; +SYMBOL: endianness +endianness [ native-endianness get-global ] initialize + : signed-native-endian> ( obj n -- n' ) [ unsigned-native-endian> ] dip >signed ; @@ -48,8 +205,11 @@ M: big-endian unsigned-endian> be> ; M: little-endian unsigned-endian> le> ; -: signed-endian> ( obj n -- bytes ) - [ unsigned-endian> ] dip >signed ; +HOOK: signed-endian> endianness ( obj -- bytes ) + +M: big-endian signed-endian> signed-be> ; + +M: little-endian signed-endian> signed-le> ; : with-endianness ( endian quot -- ) [ endianness ] dip with-variable ; inline @@ -74,3 +234,4 @@ M: little-endian unsigned-endian> le> ; '[ le> _ >be ] map ] if concat ] if ; inline + diff --git a/basis/furnace/auth/auth.factor b/basis/furnace/auth/auth.factor index e2930f461b..12997c4fba 100644 --- a/basis/furnace/auth/auth.factor +++ b/basis/furnace/auth/auth.factor @@ -1,8 +1,8 @@ ! Copyright (c) 2008, 2010 Slava Pestov ! See http://factorcode.org/license.txt for BSD license. USING: accessors assocs namespaces kernel sequences sets -destructors combinators fry logging io.encodings.utf8 -io.encodings.string io.binary io.sockets.secure random checksums +destructors combinators endian fry logging io.encodings.utf8 +io.encodings.string io.sockets.secure random checksums checksums.sha urls html.forms http.server diff --git a/basis/hints/hints.factor b/basis/hints/hints.factor index 9a372d5630..8e1c67c43e 100644 --- a/basis/hints/hints.factor +++ b/basis/hints/hints.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors arrays assocs byte-arrays byte-vectors classes combinators definitions fry generic generic.single -generic.standard hashtables io.binary kernel kernel.private math +generic.standard hashtables kernel kernel.private math math.parser parser sbufs sequences sequences.private splitting strings vectors words ; IN: hints @@ -123,15 +123,6 @@ set-specializer \ assoc-stack { vector } set-specializer -{ >le >be } [ - { { fixnum fixnum } { bignum fixnum } } - set-specializer -] each - -{ le> be> } [ - { byte-array } set-specializer -] each - \ base> { string fixnum } set-specializer M\ hashtable at* diff --git a/basis/io/encodings/euc/euc.factor b/basis/io/encodings/euc/euc.factor index 1d65e146ac..88878d18be 100644 --- a/basis/io/encodings/euc/euc.factor +++ b/basis/io/encodings/euc/euc.factor @@ -1,8 +1,9 @@ ! Copyright (C) 2009 Daniel Ehrenberg, Jonghyouk Yun. ! See http://factorcode.org/license.txt for BSD license. -USING: kernel io.encodings accessors assocs sequences biassocs generic -math.order simple-flat-file io io.binary byte-arrays locals combinators -words classes.singleton fry classes.parser parser quotations ; +USING: accessors assocs biassocs byte-arrays classes.parser +classes.singleton combinators endian generic io io.encodings +kernel math.bitwise math.order parser sequences simple-flat-file +words ; IN: io.encodings.euc TUPLE: euc { table biassoc read-only } ; diff --git a/basis/io/encodings/gb18030/gb18030.factor b/basis/io/encodings/gb18030/gb18030.factor index 760dc75dbd..82cf141621 100644 --- a/basis/io/encodings/gb18030/gb18030.factor +++ b/basis/io/encodings/gb18030/gb18030.factor @@ -3,7 +3,7 @@ USING: xml xml.data kernel io io.encodings interval-maps splitting fry math.parser sequences combinators assocs locals accessors math arrays byte-arrays ascii io.files biassocs math.order namespaces -combinators.short-circuit io.binary io.encodings.iana ; +combinators.short-circuit endian io.encodings.iana ; FROM: io.encodings.ascii => ascii ; IN: io.encodings.gb18030 diff --git a/basis/io/encodings/iso2022/iso2022.factor b/basis/io/encodings/iso2022/iso2022.factor index 9419293d16..8c52beaed6 100644 --- a/basis/io/encodings/iso2022/iso2022.factor +++ b/basis/io/encodings/iso2022/iso2022.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2009 Daniel Ehrenberg ! See http://factorcode.org/license.txt for BSD license. USING: accessors assocs biassocs byte-arrays combinators -combinators.short-circuit io io.binary io.encodings kernel -literals locals math namespaces sequences simple-flat-file ; +combinators.short-circuit endian io io.encodings kernel +literals math math.bitwise namespaces sequences simple-flat-file ; IN: io.encodings.iso2022 SINGLETON: iso2022 diff --git a/basis/io/encodings/shift-jis/shift-jis.factor b/basis/io/encodings/shift-jis/shift-jis.factor index 5e9307d8e7..f44deec096 100644 --- a/basis/io/encodings/shift-jis/shift-jis.factor +++ b/basis/io/encodings/shift-jis/shift-jis.factor @@ -1,10 +1,9 @@ ! Copyright (C) 2009 Daniel Ehrenberg ! See http://factorcode.org/license.txt for BSD license. -USING: sequences kernel io io.files combinators.short-circuit -math.order assocs io.encodings io.binary fry strings math -io.encodings.ascii arrays byte-arrays accessors splitting -math.parser biassocs io.encodings.iana namespaces -locals multiline combinators simple-flat-file ; +USING: accessors arrays assocs byte-arrays +combinators.short-circuit endian io io.encodings +io.encodings.iana kernel math.bitwise math.order namespaces +simple-flat-file ; IN: io.encodings.shift-jis SINGLETON: shift-jis diff --git a/basis/io/encodings/utf32/utf32.factor b/basis/io/encodings/utf32/utf32.factor index ba0938e1c0..249dcea48c 100644 --- a/basis/io/encodings/utf32/utf32.factor +++ b/basis/io/encodings/utf32/utf32.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2009 Daniel Ehrenberg. ! See http://factorcode.org/license.txt for BSD license. -USING: math kernel io.encodings combinators io io.encodings.utf16 -sequences io.binary io.encodings.iana ; +USING: combinators endian math io io.encodings +io.encodings.iana io.encodings.utf16 kernel sequences ; IN: io.encodings.utf32 SINGLETON: utf32be diff --git a/basis/io/files/windows/windows.factor b/basis/io/files/windows/windows.factor index 7f9bdfb960..ad18263548 100644 --- a/basis/io/files/windows/windows.factor +++ b/basis/io/files/windows/windows.factor @@ -2,13 +2,14 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien alien.c-types alien.data alien.strings alien.syntax arrays ascii assocs classes.struct combinators -combinators.short-circuit continuations destructors environment io -io.backend io.binary io.buffers io.files io.files.private -io.files.types io.pathnames io.pathnames.private io.ports io.streams.c -io.streams.null io.timeouts kernel libc literals locals math math.bitwise -namespaces sequences specialized-arrays system threads tr vectors windows -windows.errors windows.handles windows.kernel32 windows.shell32 -windows.time windows.types windows.winsock splitting ; +combinators.short-circuit continuations destructors environment +io io.backend io.buffers io.files io.files.private +io.files.types io.pathnames io.pathnames.private io.ports +io.streams.c io.streams.null io.timeouts kernel libc literals +locals math math.bitwise namespaces sequences specialized-arrays +system threads tr vectors windows windows.errors windows.handles +windows.kernel32 windows.shell32 windows.time windows.types +windows.winsock splitting ; SPECIALIZED-ARRAY: ushort IN: io.files.windows diff --git a/basis/io/sockets/secure/openssl/openssl.factor b/basis/io/sockets/secure/openssl/openssl.factor index d15015d207..7fe0d61293 100644 --- a/basis/io/sockets/secure/openssl/openssl.factor +++ b/basis/io/sockets/secure/openssl/openssl.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien alien.c-types alien.data alien.enums alien.strings assocs byte-arrays classes.struct combinators -combinators.short-circuit destructors io io.backend io.binary +combinators.short-circuit destructors endian io io.backend io.buffers io.encodings.latin1 io.encodings.string io.encodings.utf8 io.files io.pathnames io.ports io.sockets io.sockets.secure io.timeouts kernel libc math math.functions diff --git a/basis/io/sockets/sockets.factor b/basis/io/sockets/sockets.factor index b9b06158dc..da1d5c5205 100644 --- a/basis/io/sockets/sockets.factor +++ b/basis/io/sockets/sockets.factor @@ -3,8 +3,8 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien.c-types alien.data alien.strings arrays byte-arrays classes classes.struct combinators -combinators.short-circuit continuations destructors fry -grouping init io.backend io.binary io.encodings.ascii +combinators.short-circuit continuations destructors endian fry +grouping init io.backend io.encodings.ascii io.encodings.binary io.pathnames io.ports io.streams.duplex kernel locals math math.parser memoize namespaces present sequences sequences.private splitting strings summary system diff --git a/basis/math/bitwise/bitwise-docs.factor b/basis/math/bitwise/bitwise-docs.factor index aaf9f9d489..cc3c33a49b 100644 --- a/basis/math/bitwise/bitwise-docs.factor +++ b/basis/math/bitwise/bitwise-docs.factor @@ -494,6 +494,18 @@ HELP: wrap } } ; +HELP: d>w/w +{ $values { "d" "a 64-bit integer" } { "w1" "a 32-bit integer" } { "w2" "a 32-bit integer" } } +{ $description "Outputs two integers, the least followed by the most significant 32 bits of the input." } ; + +HELP: w>h/h +{ $values { "w" "a 32-bit integer" } { "h1" "a 16-bit integer" } { "h2" "a 16-bit integer" } } +{ $description "Outputs two integers, the least followed by the most significant 16 bits of the input." } ; + +HELP: h>b/b +{ $values { "h" "a 16-bit integer" } { "b1" "an 8-bit integer" } { "b2" "an 8-bit integer" } } +{ $description "Outputs two integers, the least followed by the most significant 8 bits of the input." } ; + ARTICLE: "math-bitfields" "Constructing bit fields" "Some applications, such as binary communication protocols and assemblers, need to construct integers from elaborate bit field specifications. Hand-coding this using " { $link shift } " and " { $link bitor } " results in repetitive code. A higher-level facility exists to factor out this repetition:" { $subsections bitfield } ; @@ -552,6 +564,12 @@ $nl W- W* } +"Words for taking larger integers apart into smaller integers:" +{ $subsections + d>w/w + w>h/h + h>b/b +} "Converting a number to the nearest even/odd/signed:" { $subsections >even diff --git a/basis/math/bitwise/bitwise-tests.factor b/basis/math/bitwise/bitwise-tests.factor index 7613b47876..79567c725c 100644 --- a/basis/math/bitwise/bitwise-tests.factor +++ b/basis/math/bitwise/bitwise-tests.factor @@ -116,3 +116,7 @@ SPECIALIZED-ARRAY: uint-4 { 3 } [ 0b101 bit-length ] unit-test { 3 } [ 0b110 bit-length ] unit-test { 3 } [ 0b111 bit-length ] unit-test + +{ 0x56780000 0x12340000 } [ 0x1234000056780000 d>w/w ] unit-test +{ 0x5678 0x1234 } [ 0x12345678 w>h/h ] unit-test +{ 0x34 0x12 } [ 0x1234 h>b/b ] unit-test diff --git a/basis/math/bitwise/bitwise.factor b/basis/math/bitwise/bitwise.factor index 4589f19065..ffed471cd6 100644 --- a/basis/math/bitwise/bitwise.factor +++ b/basis/math/bitwise/bitwise.factor @@ -150,3 +150,12 @@ M: object bit-count : even-parity? ( obj -- ? ) bit-count even? ; : odd-parity? ( obj -- ? ) bit-count odd? ; + +: d>w/w ( d -- w1 w2 ) + [ 0xffffffff bitand ] [ -32 shift 0xffffffff bitand ] bi ; + +: w>h/h ( w -- h1 h2 ) + [ 0xffff bitand ] [ -16 shift 0xffff bitand ] bi ; + +: h>b/b ( h -- b1 b2 ) + [ 0xff bitand ] [ -8 shift 0xff bitand ] bi ; diff --git a/basis/msgpack/msgpack.factor b/basis/msgpack/msgpack.factor index 021a96c3bb..6e8b715aed 100644 --- a/basis/msgpack/msgpack.factor +++ b/basis/msgpack/msgpack.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2013 John Benediktsson ! See http://factorcode.org/license.txt for BSD license -USING: arrays assocs byte-arrays combinators grouping hashtables -io io.binary io.encodings io.encodings.binary +USING: arrays assocs byte-arrays combinators endian grouping +hashtables io io.encodings io.encodings.binary io.encodings.string io.encodings.utf8 io.streams.byte-array io.streams.string kernel math math.bitwise math.order namespaces sequences strings ; diff --git a/basis/random/random.factor b/basis/random/random.factor index 0040ee77fb..b71291df92 100644 --- a/basis/random/random.factor +++ b/basis/random/random.factor @@ -1,11 +1,11 @@ ! Copyright (C) 2008 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien.data arrays assocs byte-arrays -byte-vectors combinators combinators.short-circuit fry -hashtables hashtables.private hash-sets hints io.backend -io.binary kernel locals math math.bitwise math.constants -math.functions math.order math.ranges namespaces sequences -sequences.private sets summary system typed vocabs ; +byte-vectors combinators combinators.short-circuit endian fry +hashtables hashtables.private hash-sets hints io.backend kernel +locals math math.bitwise math.constants math.functions +math.order math.ranges namespaces sequences sequences.private +sets summary system typed vocabs ; QUALIFIED-WITH: alien.c-types c QUALIFIED-WITH: sets sets IN: random diff --git a/basis/serialize/serialize.factor b/basis/serialize/serialize.factor index 2e5e33d137..b28f38f89c 100644 --- a/basis/serialize/serialize.factor +++ b/basis/serialize/serialize.factor @@ -7,7 +7,7 @@ ! See http://factorcode.org/license.txt for BSD license. ! USING: accessors arrays assocs byte-arrays classes classes.tuple -combinators hashtables hashtables.identity io io.binary +combinators endian hashtables hashtables.identity io io.encodings.binary io.encodings.string io.encodings.utf8 io.streams.byte-array kernel locals math namespaces prettyprint quotations sequences sequences.private strings vocabs words ; diff --git a/basis/system-info/macosx/macosx.factor b/basis/system-info/macosx/macosx.factor index b7a76f33a8..6dfd4cfabb 100644 --- a/basis/system-info/macosx/macosx.factor +++ b/basis/system-info/macosx/macosx.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2008 Doug Coleman, John Benediktsson. ! See http://factorcode.org/license.txt for BSD license. USING: alien.c-types alien.data alien.strings alien.syntax -arrays assocs byte-arrays core-foundation io.binary +arrays assocs byte-arrays core-foundation endian io.encodings.utf8 kernel libc sequences specialized-arrays splitting system system-info unix.users ; SPECIALIZED-ARRAY: int diff --git a/basis/uuid/uuid.factor b/basis/uuid/uuid.factor index b96434627b..cb72219a79 100644 --- a/basis/uuid/uuid.factor +++ b/basis/uuid/uuid.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2008 John Benediktsson ! See http://factorcode.org/license.txt for BSD license USING: byte-arrays calendar checksums checksums.md5 -checksums.sha io.binary kernel math math.parser math.ranges +checksums.sha endian kernel math math.parser math.ranges random sequences strings system unicode ; IN: uuid diff --git a/basis/windows/processes/processes.factor b/basis/windows/processes/processes.factor index b904003e1a..a803eca9f9 100644 --- a/basis/windows/processes/processes.factor +++ b/basis/windows/processes/processes.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2021 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien alien.c-types alien.data arrays -classes.struct destructors io.binary kernel literals sequences +classes.struct destructors endian kernel literals sequences strings windows windows.errors windows.handles windows.kernel32 windows.types ; IN: windows.processes @@ -122,4 +122,4 @@ IN: windows.processes le> head >string ; : get-my-process-image-name ( -- string ) - GetCurrentProcess get-process-image-name ; \ No newline at end of file + GetCurrentProcess get-process-image-name ; diff --git a/core/checksums/crc32/crc32.factor b/core/checksums/crc32/crc32.factor index f6f6870041..d646a0440d 100644 --- a/core/checksums/crc32/crc32.factor +++ b/core/checksums/crc32/crc32.factor @@ -1,7 +1,6 @@ ! Copyright (C) 2006 Doug Coleman ! See http://factorcode.org/license.txt for BSD license. -USING: checksums io.binary kernel math sequences -sequences.private ; +USING: checksums kernel math sequences sequences.private ; IN: checksums.crc32 CONSTANT: crc32-polynomial 0xedb88320 @@ -16,7 +15,7 @@ CONSTANT: crc32-table V{ } : (crc32) ( crc ch -- crc ) dupd bitxor - mask-byte crc32-table nth-unsafe + 0xff bitand crc32-table nth-unsafe swap -8 shift bitxor ; inline SINGLETON: crc32 @@ -26,8 +25,13 @@ INSTANCE: crc32 checksum : init-crc32 ( input checksum -- x y input ) drop [ 0xffffffff dup ] dip ; inline +be ( n -- byte-array ) ! duplicated from io.binary, but in core + { -24 -16 -8 0 } [ shift 0xff bitand ] with B{ } map-as ; +PRIVATE> + : finish-crc32 ( x y -- bytes ) - bitxor 4 >be ; inline + bitxor 4>be ; inline M: crc32 checksum-bytes init-crc32 diff --git a/core/io/binary/authors.txt b/core/io/binary/authors.txt deleted file mode 100644 index 1901f27a24..0000000000 --- a/core/io/binary/authors.txt +++ /dev/null @@ -1 +0,0 @@ -Slava Pestov diff --git a/core/io/binary/binary-docs.factor b/core/io/binary/binary-docs.factor deleted file mode 100644 index 078b0dfa6c..0000000000 --- a/core/io/binary/binary-docs.factor +++ /dev/null @@ -1,72 +0,0 @@ -USING: help.markup help.syntax io math byte-arrays ; -IN: io.binary - -ARTICLE: "stream-binary" "Working with binary data" -"Stream words on binary streams only read and write byte arrays. Packed binary integers can be read and written by converting to and from sequences of bytes. Floating point numbers can be read and written by converting them into a their bitwise integer representation (" { $link "floats" } ")." -$nl -"There are two ways to order the bytes making up an integer; " { $emphasis "little endian" } " byte order outputs the least significant byte first, and the most significant byte last, whereas " { $emphasis "big endian" } " is the other way around." -$nl -"Consider the hexadecimal integer " { $snippet "0xcafebabe" } ". Little endian byte order yields the following sequence of bytes:" -{ $table - { "Byte:" "1" "2" "3" "4" } - { "Value:" { $snippet "be" } { $snippet "ba" } { $snippet "fe" } { $snippet "ca" } } -} -"Compare this with big endian byte order:" -{ $table - { "Byte:" "1" "2" "3" "4" } - { "Value:" { $snippet "ca" } { $snippet "fe" } { $snippet "ba" } { $snippet "be" } } -} -"Two words convert a sequence of bytes into an integer:" -{ $subsections - be> - le> -} -"Two words convert an integer into a sequence of bytes:" -{ $subsections - >be - >le -} -"Words for taking larger integers apart into smaller integers:" -{ $subsections - d>w/w - w>h/h - h>b/b -} ; - -ABOUT: "stream-binary" - -HELP: be> -{ $values { "seq" { $sequence "bytes" } } { "x" "a non-negative integer" } } -{ $description "Converts a sequence of bytes in big endian order into an unsigned integer." } ; - -HELP: le> -{ $values { "seq" { $sequence "bytes" } } { "x" "a non-negative integer" } } -{ $description "Converts a sequence of bytes in little endian order into an unsigned integer." } ; - -HELP: nth-byte -{ $values { "x" integer } { "n" "a non-negative integer" } { "b" "a byte" } } -{ $description "Outputs the " { $snippet "n" } "th least significant byte of the sign-extended 2's complement representation of " { $snippet "x" } "." } ; - -HELP: >le -{ $values { "x" integer } { "n" "a non-negative integer" } { "byte-array" byte-array } } -{ $description "Converts an integer " { $snippet "x" } " into a string of " { $snippet "n" } " bytes in little endian order. Truncation will occur if the integer is not in the range " { $snippet "[-2^(8n),2^(8n))" } "." } ; - -HELP: >be -{ $values { "x" integer } { "n" "a non-negative integer" } { "byte-array" byte-array } } -{ $description "Converts an integer " { $snippet "x" } " into a string of " { $snippet "n" } " bytes in big endian order. Truncation will occur if the integer is not in the range " { $snippet "[-2^(8n),2^(8n))" } "." } ; - -HELP: mask-byte -{ $values { "x" integer } { "y" "a non-negative integer" } } -{ $description "Masks off the least significant 8 bits of an integer." } ; - -HELP: d>w/w -{ $values { "d" "a 64-bit integer" } { "w1" "a 32-bit integer" } { "w2" "a 32-bit integer" } } -{ $description "Outputs two integers, the least followed by the most significant 32 bits of the input." } ; - -HELP: w>h/h -{ $values { "w" "a 32-bit integer" } { "h1" "a 16-bit integer" } { "h2" "a 16-bit integer" } } -{ $description "Outputs two integers, the least followed by the most significant 16 bits of the input." } ; - -HELP: h>b/b -{ $values { "h" "a 16-bit integer" } { "b1" "an 8-bit integer" } { "b2" "an 8-bit integer" } } -{ $description "Outputs two integers, the least followed by the most significant 8 bits of the input." } ; diff --git a/core/io/binary/binary-tests.factor b/core/io/binary/binary-tests.factor deleted file mode 100644 index a06d68411a..0000000000 --- a/core/io/binary/binary-tests.factor +++ /dev/null @@ -1,37 +0,0 @@ -USING: io.binary tools.test classes math ; -IN: io.binary.tests - -{ 0x03020100 } [ B{ 0 1 2 3 } le> ] unit-test -{ 0x00010203 } [ B{ 0 1 2 3 } be> ] unit-test - -{ 0x332211 } [ - B{ 0x11 0x22 0x33 } le> -] unit-test - -{ 0x04030201 } [ B{ 1 2 3 4 } signed-le> ] unit-test -{ 0x01020304 } [ B{ 1 2 3 4 } signed-be> ] unit-test - -{ -12 } [ B{ 0xf4 0xff 0xff 0xff } signed-le> ] unit-test -{ -12 } [ B{ 0xff 0xff 0xff 0xf4 } signed-be> ] unit-test - -{ 0x7a2c793b2ff08554 } [ - B{ 0x54 0x85 0xf0 0x2f 0x3b 0x79 0x2c 0x7a } le> -] unit-test - -{ 0x988a259c3433f237 } [ - B{ 0x37 0xf2 0x33 0x34 0x9c 0x25 0x8a 0x98 } le> -] unit-test - -{ B{ 0 0 4 0xd2 } } [ 1234 4 >be ] unit-test -{ B{ 0 0 0 0 0 0 4 0xd2 } } [ 1234 8 >be ] unit-test -{ B{ 0xd2 4 0 0 } } [ 1234 4 >le ] unit-test -{ B{ 0xd2 4 0 0 0 0 0 0 } } [ 1234 8 >le ] unit-test - -{ 1234 } [ 1234 4 >be be> ] unit-test -{ 1234 } [ 1234 4 >le le> ] unit-test - -{ fixnum } [ B{ 0 0 0 0 0 0 0 0 0 0 } be> class-of ] unit-test - -{ 0x56780000 0x12340000 } [ 0x1234000056780000 d>w/w ] unit-test -{ 0x5678 0x1234 } [ 0x12345678 w>h/h ] unit-test -{ 0x34 0x12 } [ 0x1234 h>b/b ] unit-test diff --git a/core/io/binary/binary.factor b/core/io/binary/binary.factor deleted file mode 100644 index b85e9316e3..0000000000 --- a/core/io/binary/binary.factor +++ /dev/null @@ -1,43 +0,0 @@ -! Copyright (C) 2003, 2007 Slava Pestov. -! See http://factorcode.org/license.txt for BSD license. -USING: kernel math sequences ; -IN: io.binary - -: le> ( seq -- x ) 0 [ 8 * shift + ] reduce-index ; - -: be> ( seq -- x ) 0 [ [ 8 shift ] dip + ] reduce ; - -: mask-byte ( x -- y ) 0xff bitand ; inline - -: nth-byte ( x n -- b ) -8 * shift mask-byte ; inline - - - -: >le ( x n -- byte-array ) map-bytes ; - -: >be ( x n -- byte-array ) map-bytes ; - -: d>w/w ( d -- w1 w2 ) - [ 0xffffffff bitand ] [ -32 shift 0xffffffff bitand ] bi ; - -: w>h/h ( w -- h1 h2 ) - [ 0xffff bitand ] [ -16 shift 0xffff bitand ] bi ; - -: h>b/b ( h -- b1 b2 ) - [ mask-byte ] [ -8 shift mask-byte ] bi ; - - ( x seq -- n ) - length 8 * 2dup 1 - bit? [ 2^ - ] [ drop ] if ; inline - -PRIVATE> - -: signed-le> ( bytes -- x ) [ le> ] [ signed> ] bi ; - -: signed-be> ( bytes -- x ) [ be> ] [ signed> ] bi ; diff --git a/core/io/binary/summary.txt b/core/io/binary/summary.txt deleted file mode 100644 index 14d76d43eb..0000000000 --- a/core/io/binary/summary.txt +++ /dev/null @@ -1 +0,0 @@ -Utilities for reading and writing little and big endian data diff --git a/core/io/encodings/utf16/utf16.factor b/core/io/encodings/utf16/utf16.factor index 254f668c90..d889652909 100644 --- a/core/io/encodings/utf16/utf16.factor +++ b/core/io/encodings/utf16/utf16.factor @@ -1,9 +1,8 @@ ! Copyright (C) 2006, 2009 Daniel Ehrenberg. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors byte-arrays combinators io io.binary -io.encodings kernel math math.private namespaces sbufs -sequences sequences.private splitting strings strings.private -vectors ; +USING: accessors byte-arrays combinators io io.encodings kernel +math math.private namespaces sbufs sequences sequences.private +splitting strings strings.private vectors ; IN: io.encodings.utf16 SINGLETON: utf16be @@ -80,12 +79,15 @@ M: utf16le decode-char [ B{ } 2sequence ] dip stream-write ; inline ! [ stream-write1 ] curry bi@ ; inline +: split>b/b ( h -- b1 b2 ) ! duplicate from math.bitwise:h>b/b + [ 0xff bitand ] [ -8 shift 0xff bitand ] bi ; + : char>utf16be ( char stream -- ) over 0xFFFF > [ [ 0x10000 - ] dip [ [ encode-first ] dip stream-write2 ] [ [ encode-second ] dip stream-write2 ] 2bi - ] [ [ h>b/b swap ] dip stream-write2 ] if ; inline + ] [ [ split>b/b swap ] dip stream-write2 ] if ; inline M: utf16be encode-char drop char>utf16be ; @@ -95,7 +97,7 @@ M: utf16be encode-char [ 0x10000 - ] dip [ [ encode-first swap ] dip stream-write2 ] [ [ encode-second swap ] dip stream-write2 ] 2bi - ] [ [ h>b/b ] dip stream-write2 ] if ; inline + ] [ [ split>b/b ] dip stream-write2 ] if ; inline M: utf16le encode-char drop char>utf16le ; diff --git a/extra/asn1/asn1.factor b/extra/asn1/asn1.factor index ad86a8877d..9dad150214 100644 --- a/extra/asn1/asn1.factor +++ b/extra/asn1/asn1.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: arrays asn1.ldap assocs byte-arrays combinators -continuations io io.binary io.streams.string kernel math +continuations endian io io.streams.string kernel math math.parser namespaces make pack strings sequences accessors ; IN: asn1 diff --git a/extra/audio/aiff/aiff.factor b/extra/audio/aiff/aiff.factor index 3fd5dbdacf..e0c3c4fa43 100644 --- a/extra/audio/aiff/aiff.factor +++ b/extra/audio/aiff/aiff.factor @@ -2,9 +2,8 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien alien.c-types alien.data audio audio.chunked-file classes.struct combinators -combinators.short-circuit endian io io.binary -io.encodings.binary io.files kernel locals math sequences -audio.loader ; +combinators.short-circuit endian io io.encodings.binary +io.files kernel locals math sequences audio.loader ; IN: audio.aiff CONSTANT: FORM-MAGIC "FORM" diff --git a/extra/audio/wav/wav.factor b/extra/audio/wav/wav.factor index fe062df9cf..2aacaae0b1 100644 --- a/extra/audio/wav/wav.factor +++ b/extra/audio/wav/wav.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2009 Joe Groff. ! See http://factorcode.org/license.txt for BSD license. USING: alien.c-types alien.syntax audio combinators endian -combinators.short-circuit io io.binary io.encodings.binary +combinators.short-circuit endian io io.encodings.binary io.files io.streams.byte-array kernel locals math sequences alien alien.data classes.struct accessors audio.chunked-file audio.loader ; diff --git a/extra/base24/base24-tests.factor b/extra/base24/base24-tests.factor index ba213ccc1a..54e28120be 100644 --- a/extra/base24/base24-tests.factor +++ b/extra/base24/base24-tests.factor @@ -1,4 +1,4 @@ -USING: base24 grouping io.binary kernel math.parser sequences +USING: base24 endian grouping kernel math.parser sequences tools.test ; IN: base24.tests diff --git a/extra/base24/base24.factor b/extra/base24/base24.factor index 434866c014..9029172260 100644 --- a/extra/base24/base24.factor +++ b/extra/base24/base24.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2020 John Benediktsson ! See http://factorcode.org/license.txt for BSD license -USING: ascii assocs base64.private byte-arrays grouping -io.binary kernel kernel.private literals math sequences ; +USING: ascii assocs base64.private byte-arrays endian grouping +kernel kernel.private literals math sequences ; IN: base24 diff --git a/extra/base32/base32.factor b/extra/base32/base32.factor index 90c362f48f..3bace0d75f 100644 --- a/extra/base32/base32.factor +++ b/extra/base32/base32.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2019 John Benediktsson ! See http://factorcode.org/license.txt for BSD license -USING: base64.private byte-arrays combinators fry io io.binary +USING: base64.private byte-arrays combinators endian fry io io.encodings.binary io.streams.byte-array kernel kernel.private literals math namespaces sequences ; IN: base32 diff --git a/extra/base36/base36.factor b/extra/base36/base36.factor index e937e053f9..3d11cd619e 100644 --- a/extra/base36/base36.factor +++ b/extra/base36/base36.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: base64.private byte-arrays checksums checksums.sha -io.binary kernel kernel.private literals math math.functions +endian kernel kernel.private literals math math.functions sequences ; IN: base36 diff --git a/extra/base58/base58.factor b/extra/base58/base58.factor index a3601a7856..db5153866f 100644 --- a/extra/base58/base58.factor +++ b/extra/base58/base58.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: base64.private byte-arrays checksums checksums.sha -io.binary kernel kernel.private literals math sequences ; +endian kernel kernel.private literals math sequences ; IN: base58 diff --git a/extra/base62/base62.factor b/extra/base62/base62.factor index 40c29cacb0..9cc6d03721 100644 --- a/extra/base62/base62.factor +++ b/extra/base62/base62.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: base64.private byte-arrays checksums checksums.sha -io.binary kernel kernel.private literals math sequences ; +endian kernel kernel.private literals math sequences ; IN: base62 diff --git a/extra/base85/base85.factor b/extra/base85/base85.factor index bbf98e13c2..44d3d9289d 100644 --- a/extra/base85/base85.factor +++ b/extra/base85/base85.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2013 John Benediktsson. ! See http://factorcode.org/license.txt for BSD license. -USING: base64.private byte-arrays combinators io io.binary +USING: base64.private byte-arrays combinators endian io io.encodings.binary io.streams.byte-array kernel kernel.private literals math namespaces sequences ; IN: base85 diff --git a/extra/benchmark/cuckoo-filters/cuckoo-filters.factor b/extra/benchmark/cuckoo-filters/cuckoo-filters.factor index 95e92d95c7..16c668e1bf 100644 --- a/extra/benchmark/cuckoo-filters/cuckoo-filters.factor +++ b/extra/benchmark/cuckoo-filters/cuckoo-filters.factor @@ -1,4 +1,4 @@ -USING: cuckoo-filters fry io.binary kernel math sequences ; +USING: cuckoo-filters endian fry kernel math sequences ; IN: benchmark.cuckoo-filters : insert-data ( cuckoo-filter -- cuckoo-filter ) diff --git a/extra/benchmark/udp-echo0/udp-echo0.factor b/extra/benchmark/udp-echo0/udp-echo0.factor index 9338245b62..f4fa7c242a 100644 --- a/extra/benchmark/udp-echo0/udp-echo0.factor +++ b/extra/benchmark/udp-echo0/udp-echo0.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2011 John Benediktsson ! See http://factorcode.org/license.txt for BSD license -USING: accessors destructors fry io.binary io.sockets kernel +USING: accessors destructors endian fry io.sockets kernel sequences ; IN: benchmark.udp-echo0 diff --git a/extra/bittorrent/bittorrent.factor b/extra/bittorrent/bittorrent.factor index 70e4158e7b..a4416cb475 100644 --- a/extra/bittorrent/bittorrent.factor +++ b/extra/bittorrent/bittorrent.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2020 John Benediktsson ! See http://factorcode.org/license.txt for BSD license USING: accessors arrays assocs bencode byte-arrays byte-vectors -calendar checksums checksums.sha combinators destructors fry -grouping http.client io io.binary io.encodings.binary io.files +calendar checksums checksums.sha combinators destructors endian +fry grouping http.client io io.encodings.binary io.files io.pathnames io.sockets io.streams.byte-array io.streams.duplex kernel literals locals make math math.bitwise math.functions math.order math.parser math.ranges multiline namespaces diff --git a/extra/bson/reader/reader.factor b/extra/bson/reader/reader.factor index 62e76eb42c..c6ab3d4e88 100644 --- a/extra/bson/reader/reader.factor +++ b/extra/bson/reader/reader.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2010 Sascha Matzke. ! See http://factorcode.org/license.txt for BSD license. USING: accessors assocs bson.constants byte-arrays calendar -combinators combinators.short-circuit io io.binary io.encodings +combinators combinators.short-circuit endian io io.encodings io.encodings.binary io.encodings.utf8 io.files io.streams.byte-array kernel locals math namespaces sequences sequences.extras serialize strings typed vectors ; diff --git a/extra/bson/writer/writer.factor b/extra/bson/writer/writer.factor index 3d5bfeda94..7a9b398144 100644 --- a/extra/bson/writer/writer.factor +++ b/extra/bson/writer/writer.factor @@ -2,8 +2,8 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien.accessors arrays assocs bson.constants byte-arrays byte-vectors calendar combinators -combinators.short-circuit dlists fry hashtables io io.binary -io.encodings io.encodings.utf8 io.streams.byte-array kernel +combinators.short-circuit dlists endian fry hashtables +io io.encodings io.encodings.utf8 io.streams.byte-array kernel linked-assocs literals math math.parser namespaces quotations sequences serialize strings typed vectors words ; IN: bson.writer diff --git a/extra/compiler/cfg/gvn/simd/simd.factor b/extra/compiler/cfg/gvn/simd/simd.factor index 667d750f26..04cfd571b7 100644 --- a/extra/compiler/cfg/gvn/simd/simd.factor +++ b/extra/compiler/cfg/gvn/simd/simd.factor @@ -2,8 +2,8 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors combinators combinators.short-circuit arrays fry kernel layouts math namespaces sequences cpu.architecture -math.bitwise math.order classes generalizations -locals make alien.c-types io.binary grouping +math.bitwise math.order classes endian generalizations +locals make alien.c-types grouping math.vectors.simd.intrinsics compiler.cfg compiler.cfg.registers diff --git a/extra/dbf/dbf.factor b/extra/dbf/dbf.factor index e7f3e60d31..3d61947c7e 100644 --- a/extra/dbf/dbf.factor +++ b/extra/dbf/dbf.factor @@ -2,8 +2,8 @@ ! See http://factorcode.org/license.txt for BSD license USING: accessors alien.c-types alien.endian alien.strings assocs -calendar calendar.parser classes.struct combinators fry io -io.binary io.encodings.8-bit io.encodings.ascii +calendar calendar.parser classes.struct combinators endian fry +io io.encodings.8-bit io.encodings.ascii io.encodings.binary io.encodings.string io.files io.streams.byte-array kernel math math.parser namespaces sequences splitting strings ; diff --git a/extra/fastcgi/fastcgi.factor b/extra/fastcgi/fastcgi.factor index 271451ca38..1a64f3c24a 100644 --- a/extra/fastcgi/fastcgi.factor +++ b/extra/fastcgi/fastcgi.factor @@ -14,8 +14,8 @@ ! * REMOTE_ADDR USING: accessors alien.enums alien.syntax assocs combinators -combinators.smart formatting http http.server -http.server.responses io io.binary io.directories +combinators.smart endian formatting http http.server +http.server.responses io io.directories io.encodings.binary io.files io.servers io.sockets io.streams.byte-array kernel locals math namespaces pack prettyprint sequences sequences.deep strings threads diff --git a/extra/git/git.factor b/extra/git/git.factor index 9cbe8d439a..18727a588b 100644 --- a/extra/git/git.factor +++ b/extra/git/git.factor @@ -2,8 +2,8 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors arrays assocs assocs.extras calendar calendar.format checksums checksums.sha combinators -combinators.smart compression.zlib constructors grouping io -io.binary io.directories io.encodings.binary io.encodings.string +combinators.smart compression.zlib constructors endian grouping +io io.directories io.encodings.binary io.encodings.string io.encodings.utf8 io.files io.files.info io.pathnames io.streams.byte-array io.streams.peek kernel math math.bitwise math.parser namespaces random sequences sequences.extras diff --git a/extra/icfp/2006/2006.factor b/extra/icfp/2006/2006.factor index e50fa59617..7e14378c4e 100644 --- a/extra/icfp/2006/2006.factor +++ b/extra/icfp/2006/2006.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2007 Gavin Harrison ! See http://factorcode.org/license.txt for BSD license. USING: kernel math sequences kernel.private namespaces arrays io -io.files splitting grouping io.binary math.functions vectors +io.files splitting grouping math.functions vectors endian quotations combinators io.encodings.binary ; IN: icfp.2006 diff --git a/extra/images/bitmap/bitmap.factor b/extra/images/bitmap/bitmap.factor index 8c9de5005b..546749d2de 100644 --- a/extra/images/bitmap/bitmap.factor +++ b/extra/images/bitmap/bitmap.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2007, 2009 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien.c-types alien.data arrays byte-arrays -combinators compression.run-length fry grouping images -images.loader images.normalization io io.binary +combinators compression.run-length endian fry grouping images +images.loader images.normalization io io.encodings.latin1 io.encodings.string io.streams.throwing kernel math math.bitwise sequences specialized-arrays summary ; QUALIFIED-WITH: bitstreams b diff --git a/extra/images/gif/gif.factor b/extra/images/gif/gif.factor index 13e0cc1ac6..0fd010675d 100644 --- a/extra/images/gif/gif.factor +++ b/extra/images/gif/gif.factor @@ -1,8 +1,8 @@ ! Copyrigt (C) 2009 Doug Coleman, Keith Lazuka ! See http://factorcode.org/license.txt for BSD license. USING: accessors arrays combinators compression.lzw -constructors destructors grouping images images.loader io -io.binary io.buffers io.encodings.string io.encodings.utf8 +constructors destructors endian grouping images images.loader +io io.buffers io.encodings.string io.encodings.utf8 kernel make math math.bitwise namespaces sequences ; IN: images.gif diff --git a/extra/images/jpeg/jpeg.factor b/extra/images/jpeg/jpeg.factor index 9422bfe8e6..87897898a2 100644 --- a/extra/images/jpeg/jpeg.factor +++ b/extra/images/jpeg/jpeg.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2009 Marc Fauconneau. ! See http://factorcode.org/license.txt for BSD license. USING: accessors arrays byte-arrays combinators -compression.huffman fry grouping images images.loader -images.processing io io.binary io.encodings.binary +compression.huffman endian fry grouping images images.loader +images.processing io io.encodings.binary io.streams.byte-array io.streams.limited io.streams.throwing kernel locals math math.bitwise math.blas.matrices math.blas.vectors math.constants math.functions math.matrices diff --git a/extra/images/png/png.factor b/extra/images/png/png.factor index d6d4e5639d..ec3ebfae5c 100644 --- a/extra/images/png/png.factor +++ b/extra/images/png/png.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2009 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: accessors arrays assocs checksums checksums.crc32 -combinators compression.inflate fry grouping images -images.loader io io.binary io.encodings.ascii +combinators compression.inflate endian fry grouping images +images.loader io io.encodings.ascii io.encodings.binary io.encodings.latin1 io.encodings.string io.streams.byte-array io.streams.throwing kernel locals math math.bitwise math.functions sequences sorting ; diff --git a/extra/images/tga/tga.factor b/extra/images/tga/tga.factor index 1cbf8441d4..b592851db0 100644 --- a/extra/images/tga/tga.factor +++ b/extra/images/tga/tga.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2010 Erik Charlebois ! See http://factorcode.org/license.txt for BSD license. -USING: accessors images images.loader io io.binary kernel +USING: accessors endian images images.loader io kernel locals math sequences io.encodings.ascii io.encodings.string calendar math.ranges math.parser colors arrays hashtables ui.pixel-formats combinators continuations io.streams.throwing ; diff --git a/extra/images/tiff/tiff.factor b/extra/images/tiff/tiff.factor index 2fab7c147c..7bdbf34327 100644 --- a/extra/images/tiff/tiff.factor +++ b/extra/images/tiff/tiff.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors arrays assocs byte-arrays combinators combinators.short-circuit compression.lzw endian fry grouping -images images.loader io io.binary io.encodings.ascii +images images.loader io io.encodings.ascii io.encodings.string io.encodings.utf8 io.streams.throwing kernel math math.bitwise math.vectors pack sequences ; IN: images.tiff diff --git a/extra/io/binary/fast/authors.txt b/extra/io/binary/fast/authors.txt deleted file mode 100644 index 7c1b2f2279..0000000000 --- a/extra/io/binary/fast/authors.txt +++ /dev/null @@ -1 +0,0 @@ -Doug Coleman diff --git a/extra/io/binary/fast/fast-tests.factor b/extra/io/binary/fast/fast-tests.factor deleted file mode 100644 index 66c98b0876..0000000000 --- a/extra/io/binary/fast/fast-tests.factor +++ /dev/null @@ -1,17 +0,0 @@ -! Copyright (C) 2011 Doug Coleman. -! See http://factorcode.org/license.txt for BSD license. -USING: tools.test io.binary.fast ; - -{ 0x0102 } [ B{ 01 02 } 2be> ] unit-test -{ 0x01020304 } [ B{ 01 02 03 04 } 4be> ] unit-test -{ 0x0102030405060708 } [ B{ 01 02 03 04 05 06 07 08 } 8be> ] unit-test - -{ 0x0102 } [ B{ 02 01 } 2le> ] unit-test -{ 0x01020304 } [ B{ 04 03 02 01 } 4le> ] unit-test -{ 0x0102030405060708 } [ B{ 08 07 06 05 04 03 02 01 } 8le> ] unit-test - -{ 0x04030201 } [ B{ 1 2 3 4 } signed-le> ] unit-test -{ 0x01020304 } [ B{ 1 2 3 4 } signed-be> ] unit-test - -{ -12 } [ B{ 0xf4 0xff 0xff 0xff } signed-le> ] unit-test -{ -12 } [ B{ 0xff 0xff 0xff 0xf4 } signed-be> ] unit-test diff --git a/extra/io/binary/fast/fast.factor b/extra/io/binary/fast/fast.factor deleted file mode 100644 index 64206a7cd5..0000000000 --- a/extra/io/binary/fast/fast.factor +++ /dev/null @@ -1,128 +0,0 @@ -! Copyright (C) 2011 Doug Coleman. -! See http://factorcode.org/license.txt for BSD license. -USING: alien.c-types alien.data byte-arrays combinators -combinators.smart endian fry hints kernel locals macros math -math.ranges sequences sequences.generalizations ; -RENAME: be> io.binary => slow-be> -RENAME: le> io.binary => slow-le> -RENAME: signed-be> io.binary => slow-signed-be> -RENAME: signed-le> io.binary => slow-signed-le> -RENAME: >be io.binary => >slow-be -RENAME: >le io.binary => >slow-le -IN: io.binary.fast - -ERROR: bad-length bytes n ; - -: check-length ( bytes n -- bytes n ) - 2dup [ length ] dip > [ bad-length ] when ; inline - -<< -: be-range ( n -- range ) - 1 - 8 * 0 -8 ; inline - -: le-range ( n -- range ) - 1 - 8 * 0 swap 8 ; inline - -: reassemble-bytes ( range -- quot ) - [ [ [ ] ] [ '[ _ shift ] ] if-zero ] map - '[ [ _ spread ] [ bitor ] reduce-outputs ] ; inline - -MACRO: reassemble-be ( n -- quot ) be-range reassemble-bytes ; - -MACRO: reassemble-le ( n -- quot ) le-range reassemble-bytes ; ->> - -:: n-be> ( bytes n -- x ) - bytes n check-length drop n firstn-unsafe n reassemble-be ; inline - -:: n-le> ( bytes n -- x ) - bytes n check-length drop n firstn-unsafe n reassemble-le ; inline - -HINTS: n-be> { byte-array object } ; -HINTS: n-le> { byte-array object } ; - - - -: 2be> ( bytes -- x ) - big-endian [ uint16_t deref ] [ 2 n-be> ] if-endian ; - -: 4be> ( bytes -- x ) - big-endian [ uint32_t deref ] [ 4 n-be> ] if-endian ; - -: 8be> ( bytes -- x ) - big-endian [ uint64_t deref ] [ 8 n-be> ] if-endian ; - -: be> ( bytes -- x ) - dup length { - { 2 [ 2be> ] } - { 4 [ 4be> ] } - { 8 [ 8be> ] } - [ drop slow-be> ] - } case ; - -: signed-be> ( bytes -- x ) - compute-native-endianness big-endian = [ - dup byte-array? [ - dup length { - { 2 [ int16_t deref ] } - { 4 [ int32_t deref ] } - { 8 [ int64_t deref ] } - [ drop slow-signed-be> ] - } case - ] [ slow-signed-be> ] if - ] [ slow-signed-be> ] if ; - -: 2le> ( bytes -- x ) - little-endian [ uint16_t deref ] [ 2 n-le> ] if-endian ; - -: 4le> ( bytes -- x ) - little-endian [ uint32_t deref ] [ 4 n-le> ] if-endian ; - -: 8le> ( bytes -- x ) - little-endian [ uint64_t deref ] [ 8 n-le> ] if-endian ; - -: le> ( bytes -- x ) - dup length { - { 2 [ 2le> ] } - { 4 [ 4le> ] } - { 8 [ 8le> ] } - [ drop slow-le> ] - } case ; - -: signed-le> ( bytes -- x ) - compute-native-endianness little-endian = [ - dup byte-array? [ - dup length { - { 2 [ int16_t deref ] } - { 4 [ int32_t deref ] } - { 8 [ int64_t deref ] } - [ drop slow-signed-le> ] - } case - ] [ slow-signed-le> ] if - ] [ slow-signed-le> ] if ; - -: >le ( x n -- bytes ) - compute-native-endianness little-endian = [ - { - { 2 [ int16_t ] } - { 4 [ int32_t ] } - { 8 [ int64_t ] } - [ >slow-le ] - } case - ] [ >slow-le ] if ; - -: >be ( x n -- bytes ) - compute-native-endianness big-endian = [ - { - { 2 [ int16_t ] } - { 4 [ int32_t ] } - { 8 [ int64_t ] } - [ >slow-be ] - } case - ] [ >slow-be ] if ; diff --git a/extra/key-logger/key-logger.factor b/extra/key-logger/key-logger.factor index 75a1f0e717..eb662315ee 100644 --- a/extra/key-logger/key-logger.factor +++ b/extra/key-logger/key-logger.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2010 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors timers bit-arrays calendar game.input io -io.binary io.encodings.binary io.files kernel literals math -namespaces system threads ; +USING: accessors timers bit-arrays calendar endian game.input io +io.encodings.binary io.files kernel literals math namespaces +system threads ; IN: key-logger CONSTANT: frequency $[ 1/30 seconds ] diff --git a/extra/libusb/libusb.factor b/extra/libusb/libusb.factor index b7d60d7fbc..888e6c3b89 100644 --- a/extra/libusb/libusb.factor +++ b/extra/libusb/libusb.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2010 Erik Charlebois. ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien alien.c-types alien.data alien.libraries -alien.syntax classes.struct combinators endian io.binary +alien.syntax classes.struct combinators endian kernel locals math sequences specialized-arrays system unix.time unix.types ; FROM: alien.c-types => short ; diff --git a/extra/macho/macho.factor b/extra/macho/macho.factor index 83064ae923..f404317123 100644 --- a/extra/macho/macho.factor +++ b/extra/macho/macho.factor @@ -4,7 +4,7 @@ USING: accessors alien alien.c-types alien.data alien.strings alien.syntax classes classes.struct combinators combinators.short-circuit io.encodings.ascii io.encodings.string kernel literals make math sequences specialized-arrays typed -fry io.mmap formatting locals splitting io.binary arrays ; +fry io.mmap formatting locals splitting endian arrays ; FROM: alien.c-types => short ; IN: macho diff --git a/extra/midi/midi.factor b/extra/midi/midi.factor index 4a199111ee..adc5cf7693 100644 --- a/extra/midi/midi.factor +++ b/extra/midi/midi.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2015 John Benediktsson ! See http://factorcode.org/license.txt for BSD license -USING: accessors assocs byte-arrays combinators fry io io.binary +USING: accessors assocs byte-arrays combinators endian fry io io.encodings.binary io.encodings.string io.encodings.utf8 io.files io.streams.byte-array io.streams.peek kernel literals make math sequences sequences.generalizations ; diff --git a/extra/mongodb/operations/operations.factor b/extra/mongodb/operations/operations.factor index 7aaea3d6af..8e5fe548e4 100644 --- a/extra/mongodb/operations/operations.factor +++ b/extra/mongodb/operations/operations.factor @@ -1,7 +1,9 @@ USING: accessors assocs bson.reader bson.writer byte-arrays -byte-vectors combinators formatting fry io io.binary io.encodings.private -io.encodings.binary io.encodings.string io.encodings.utf8 io.encodings.utf8.private io.files -kernel locals math mongodb.msg namespaces sequences uuid bson.writer.private ; +byte-vectors combinators formatting endian fry io +io.encodings.private io.encodings.binary io.encodings.string +io.encodings.utf8 io.encodings.utf8.private io.files kernel +locals math mongodb.msg namespaces sequences uuid +bson.writer.private ; FROM: mongodb.connection => connection-buffer ; FROM: alien => byte-length ; diff --git a/extra/protocols/tftp/tftp.factor b/extra/protocols/tftp/tftp.factor index cebd82aeb8..ae9a8eb639 100644 --- a/extra/protocols/tftp/tftp.factor +++ b/extra/protocols/tftp/tftp.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2019 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: accessors arrays assocs combinators -combinators.short-circuit continuations destructors fry io -io.binary io.directories io.encodings.binary io.encodings.latin1 +combinators.short-circuit continuations destructors endian fry +io io.directories io.encodings.binary io.encodings.latin1 io.encodings.string io.encodings.utf8 io.files io.files.info io.sockets kernel math math.parser namespaces pack prettyprint random sequences sequences.extras splitting strings ; diff --git a/extra/shapefiles/shapefiles.factor b/extra/shapefiles/shapefiles.factor index 62a2ab59a2..de5b3ae11c 100644 --- a/extra/shapefiles/shapefiles.factor +++ b/extra/shapefiles/shapefiles.factor @@ -1,10 +1,9 @@ ! Copyright (C) 2018 John Benediktsson ! See http://factorcode.org/license.txt for BSD license -USING: accessors byte-arrays classes combinators io -io.binary.fast io.encodings.binary io.files -io.streams.byte-array kernel locals math math.order -math.statistics sequences sequences.extras sets ; +USING: accessors byte-arrays classes combinators endian io +io.encodings.binary io.files io.streams.byte-array kernel locals +math math.order math.statistics sequences sequences.extras sets IN: shapefiles diff --git a/extra/terminfo/terminfo.factor b/extra/terminfo/terminfo.factor index f2c6ff57d1..f756ab9b1b 100644 --- a/extra/terminfo/terminfo.factor +++ b/extra/terminfo/terminfo.factor @@ -1,10 +1,11 @@ ! Copyright (C) 2013 John Benediktsson. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors assocs combinators formatting fry grouping hashtables -io io.binary io.directories io.encodings.binary io.files -io.files.types io.pathnames kernel math math.parser memoize pack -sequences sequences.generalizations splitting strings system ; +USING: accessors assocs combinators formatting endian fry +grouping hashtables io io.directories io.encodings.binary +io.files io.files.types io.pathnames kernel math math.parser +memoize pack sequences sequences.generalizations splitting +strings system ; IN: terminfo diff --git a/extra/tinyvg/tinyvg.factor b/extra/tinyvg/tinyvg.factor index 95f41a81ce..9407b937f8 100644 --- a/extra/tinyvg/tinyvg.factor +++ b/extra/tinyvg/tinyvg.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2021 John Benediktsson ! See http://factorcode.org/license.txt for BSD license -USING: accessors colors combinators generalizations io io.binary +USING: accessors colors combinators endian generalizations io io.encodings.binary io.files io.streams.byte-array kernel math math.bitwise namespaces sequences ; diff --git a/extra/totp/totp.factor b/extra/totp/totp.factor index 28c172263e..ab5c2efee4 100644 --- a/extra/totp/totp.factor +++ b/extra/totp/totp.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2018, 2020 Alexander Ilin. ! See http://factorcode.org/license.txt for BSD license. -USING: base32 calendar checksums.hmac checksums.sha io.binary +USING: base32 calendar checksums.hmac checksums.sha endian kernel math math.bitwise math.parser namespaces sequences strings unicode ; IN: totp diff --git a/extra/tzinfo/tzinfo.factor b/extra/tzinfo/tzinfo.factor index 998353eab4..84a62e8d4f 100644 --- a/extra/tzinfo/tzinfo.factor +++ b/extra/tzinfo/tzinfo.factor @@ -2,9 +2,9 @@ ! See http://factorcode.org/license.txt for BSD license USING: accessors alien.c-types alien.data alien.endian arrays -assocs calendar classes.struct combinators hashtables io -io.binary io.encodings.binary io.files kernel locals math -math.order sequences strings ; +assocs calendar classes.struct combinators endian hashtables io +io.encodings.binary io.files kernel locals math math.order +sequences strings ; IN: tzinfo diff --git a/extra/ulid/ulid-tests.factor b/extra/ulid/ulid-tests.factor index a30e734e97..cd4ff69e1d 100644 --- a/extra/ulid/ulid-tests.factor +++ b/extra/ulid/ulid-tests.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2019 Alexander Ilin. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors io.binary kernel math namespaces sequences +USING: accessors endian kernel math namespaces sequences strings tools.test ulid ulid.private ; IN: ulid.tests diff --git a/extra/ulid/ulid.factor b/extra/ulid/ulid.factor index d9f82d0799..28ad1ac6c7 100644 --- a/extra/ulid/ulid.factor +++ b/extra/ulid/ulid.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2018, 2019 Alexander Ilin. ! See http://factorcode.org/license.txt for BSD license. -USING: ascii binary-search calendar io.binary kernel make math +USING: ascii binary-search calendar endian kernel make math math.bitwise math.order namespaces random sequences splitting summary system tr ; diff --git a/extra/windows/fullscreen/fullscreen.factor b/extra/windows/fullscreen/fullscreen.factor index dec93893d6..ff06dcade5 100644 --- a/extra/windows/fullscreen/fullscreen.factor +++ b/extra/windows/fullscreen/fullscreen.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2010 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien.c-types alien.data classes.struct -io.binary kernel literals locals make math math.bitwise +endian kernel literals locals make math math.bitwise sequences slots.syntax ui.backend.windows ui.gadgets.worlds windows.errors windows.gdi32 windows.shcore windows.types windows.user32 ; @@ -143,4 +143,4 @@ ERROR: unsupported-resolution triple ; : get-desktop-scale-factor ( -- n ) desktop-hmonitor 0 DEVICE_SCALE_FACTOR - [ GetScaleFactorForMonitor win32-error=0/f ] keep le> ; \ No newline at end of file + [ GetScaleFactorForMonitor win32-error=0/f ] keep le> ; diff --git a/extra/windows/version/version.factor b/extra/windows/version/version.factor index cda71866d5..70b2d3d320 100644 --- a/extra/windows/version/version.factor +++ b/extra/windows/version/version.factor @@ -1,6 +1,6 @@ USING: alien alien.data alien.libraries alien.syntax - destructors formatting io.binary kernel libc locals + destructors endian formatting kernel libc locals math math.bitwise sequences windows.types ; -- 2.34.1