diff --git a/basis/byte-vectors/byte-vectors-docs.factor b/basis/byte-vectors/byte-vectors-docs.factor new file mode 100644 index 0000000000..3873f73bfe --- /dev/null +++ b/basis/byte-vectors/byte-vectors-docs.factor @@ -0,0 +1,37 @@ +USING: arrays byte-arrays help.markup help.syntax kernel +byte-vectors.private combinators ; +IN: byte-vectors + +ARTICLE: "byte-vectors" "Byte vectors" +"A byte vector is a resizable mutable sequence of unsigned bytes. Byte vector words are found in the " { $vocab-link "byte-vectors" } " vocabulary." +$nl +"Byte vectors form a class:" +{ $subsection byte-vector } +{ $subsection byte-vector? } +"Creating byte vectors:" +{ $subsection >byte-vector } +{ $subsection } +"Literal syntax:" +{ $subsection POSTPONE: BV{ } +"If you don't care about initial capacity, a more elegant way to create a new byte vector is to write:" +{ $code "BV{ } clone" } ; + +ABOUT: "byte-vectors" + +HELP: byte-vector +{ $description "The class of resizable byte vectors. See " { $link "byte-vectors" } " for information." } ; + +HELP: +{ $values { "n" "a positive integer specifying initial capacity" } { "byte-vector" byte-vector } } +{ $description "Creates a new byte vector that can hold " { $snippet "n" } " bytes before resizing." } ; + +HELP: >byte-vector +{ $values { "seq" "a sequence" } { "byte-vector" byte-vector } } +{ $description "Outputs a freshly-allocated byte vector with the same elements as a given sequence." } +{ $errors "Throws an error if the sequence contains elements other than integers." } ; + +HELP: BV{ +{ $syntax "BV{ elements... }" } +{ $values { "elements" "a list of bytes" } } +{ $description "Marks the beginning of a literal byte vector. Literal byte vectors are terminated by " { $link POSTPONE: } } "." } +{ $examples { $code "BV{ 1 2 3 12 }" } } ; diff --git a/basis/byte-vectors/byte-vectors-tests.factor b/basis/byte-vectors/byte-vectors-tests.factor new file mode 100644 index 0000000000..9a100d9795 --- /dev/null +++ b/basis/byte-vectors/byte-vectors-tests.factor @@ -0,0 +1,17 @@ +IN: byte-vectors.tests +USING: tools.test byte-vectors vectors sequences kernel +prettyprint ; + +[ 0 ] [ 123 length ] unit-test + +: do-it + 123 [ over push ] each ; + +[ t ] [ + 3 do-it + 3 do-it sequence= +] unit-test + +[ t ] [ BV{ } byte-vector? ] unit-test + +[ "BV{ }" ] [ BV{ } unparse ] unit-test diff --git a/basis/byte-vectors/byte-vectors.factor b/basis/byte-vectors/byte-vectors.factor new file mode 100644 index 0000000000..b2c0d55c0f --- /dev/null +++ b/basis/byte-vectors/byte-vectors.factor @@ -0,0 +1,51 @@ +! Copyright (C) 2008 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: arrays kernel kernel.private math sequences +sequences.private growable byte-arrays accessors parser +prettyprint.backend ; +IN: byte-vectors + +TUPLE: byte-vector +{ underlying byte-array } +{ length array-capacity } ; + +: ( n -- byte-vector ) + 0 byte-vector boa ; inline + +: >byte-vector ( seq -- byte-vector ) + T{ byte-vector f B{ } 0 } clone-like ; + +M: byte-vector like + drop dup byte-vector? [ + dup byte-array? + [ dup length byte-vector boa ] [ >byte-vector ] if + ] unless ; + +M: byte-vector new-sequence + drop [ ] [ >fixnum ] bi byte-vector boa ; + +M: byte-vector equal? + over byte-vector? [ sequence= ] [ 2drop f ] if ; + +M: byte-array like + #! If we have an byte-array, we're done. + #! If we have a byte-vector, and it's at full capacity, + #! we're done. Otherwise, call resize-byte-array, which is a + #! relatively fast primitive. + drop dup byte-array? [ + dup byte-vector? [ + [ length ] [ underlying>> ] bi + 2dup length eq? + [ nip ] [ resize-byte-array ] if + ] [ >byte-array ] if + ] unless ; + +M: byte-array new-resizable drop ; + +: BV{ \ } [ >byte-vector ] parse-literal ; parsing + +M: byte-vector pprint* pprint-object ; +M: byte-vector pprint-delims drop \ BV{ \ } ; +M: byte-vector >pprint-sequence ; + +INSTANCE: byte-vector growable diff --git a/basis/byte-vectors/summary.txt b/basis/byte-vectors/summary.txt new file mode 100644 index 0000000000..e914ebb319 --- /dev/null +++ b/basis/byte-vectors/summary.txt @@ -0,0 +1 @@ +Growable byte arrays diff --git a/basis/byte-vectors/tags.txt b/basis/byte-vectors/tags.txt new file mode 100644 index 0000000000..42d711b32b --- /dev/null +++ b/basis/byte-vectors/tags.txt @@ -0,0 +1 @@ +collections diff --git a/basis/io/streams/byte-array/byte-array-docs.factor b/basis/io/streams/byte-array/byte-array-docs.factor new file mode 100644 index 0000000000..7b27621343 --- /dev/null +++ b/basis/io/streams/byte-array/byte-array-docs.factor @@ -0,0 +1,34 @@ +USING: help.syntax help.markup io byte-arrays quotations ; +IN: io.streams.byte-array + +ABOUT: "io.streams.byte-array" + +ARTICLE: "io.streams.byte-array" "Byte-array streams" +"Byte array streams:" +{ $subsection } +{ $subsection } +"Utility combinators:" +{ $subsection with-byte-reader } +{ $subsection with-byte-writer } ; + +HELP: +{ $values { "byte-array" byte-array } + { "encoding" "an encoding descriptor" } + { "stream" "a new byte reader" } } +{ $description "Creates an input stream reading from a byte array using an encoding." } ; + +HELP: +{ $values { "encoding" "an encoding descriptor" } + { "stream" "a new byte writer" } } +{ $description "Creates an output stream writing data to a byte array using an encoding." } ; + +HELP: with-byte-reader +{ $values { "encoding" "an encoding descriptor" } + { "quot" quotation } { "byte-array" byte-array } } +{ $description "Calls the quotation in a new dynamic scope with " { $link input-stream } " rebound to an input stream for reading from a byte array using an encoding." } ; + +HELP: with-byte-writer +{ $values { "encoding" "an encoding descriptor" } + { "quot" quotation } + { "byte-array" byte-array } } +{ $description "Calls the quotation in a new dynamic scope with " { $link output-stream } " rebound to an output stream writing data to a byte array using an encoding." } ; diff --git a/basis/io/streams/byte-array/byte-array-tests.factor b/basis/io/streams/byte-array/byte-array-tests.factor new file mode 100644 index 0000000000..77a9126740 --- /dev/null +++ b/basis/io/streams/byte-array/byte-array-tests.factor @@ -0,0 +1,9 @@ +USING: tools.test io.streams.byte-array io.encodings.binary +io.encodings.utf8 io kernel arrays strings ; + +[ B{ 1 2 3 } ] [ binary [ { 1 2 3 } write ] with-byte-writer ] unit-test +[ B{ 1 2 3 } ] [ { 1 2 3 } binary [ 3 read ] with-byte-reader ] unit-test + +[ B{ BIN: 11110101 BIN: 10111111 BIN: 10000000 BIN: 10111111 BIN: 11101111 BIN: 10000000 BIN: 10111111 BIN: 11011111 BIN: 10000000 CHAR: x } ] +[ { BIN: 101111111000000111111 BIN: 1111000000111111 BIN: 11111000000 CHAR: x } utf8 [ write ] with-byte-writer ] unit-test +[ { BIN: 101111111000000111111 } t ] [ { BIN: 11110101 BIN: 10111111 BIN: 10000000 BIN: 10111111 } utf8 contents dup >array swap string? ] unit-test diff --git a/basis/io/streams/byte-array/byte-array.factor b/basis/io/streams/byte-array/byte-array.factor new file mode 100644 index 0000000000..9d89c3d814 --- /dev/null +++ b/basis/io/streams/byte-array/byte-array.factor @@ -0,0 +1,16 @@ +USING: byte-arrays byte-vectors kernel io.encodings io.streams.string +sequences io namespaces io.encodings.private accessors ; +IN: io.streams.byte-array + +: ( encoding -- stream ) + 512 swap ; + +: with-byte-writer ( encoding quot -- byte-array ) + [ ] dip [ output-stream get ] compose with-output-stream* + dup encoder? [ stream>> ] when >byte-array ; inline + +: ( byte-array encoding -- stream ) + [ >byte-vector dup reverse-here ] dip ; + +: with-byte-reader ( byte-array encoding quot -- ) + [ ] dip with-input-stream* ; inline diff --git a/basis/ui/freetype/freetype.factor b/basis/ui/freetype/freetype.factor index 6c0eaaa9ac..22a4f1722d 100644 --- a/basis/ui/freetype/freetype.factor +++ b/basis/ui/freetype/freetype.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2005, 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: alien alien.accessors alien.c-types arrays io kernel libc -math math.vectors namespaces opengl opengl.gl prettyprint assocs +math math.vectors namespaces opengl opengl.gl assocs sequences io.files io.styles continuations freetype ui.gadgets.worlds ui.render ui.backend byte-arrays accessors locals specialized-arrays.direct.uchar ; diff --git a/basis/ui/gadgets/labelled/labelled.factor b/basis/ui/gadgets/labelled/labelled.factor index 108c5ae461..636e25cea5 100644 --- a/basis/ui/gadgets/labelled/labelled.factor +++ b/basis/ui/gadgets/labelled/labelled.factor @@ -3,7 +3,7 @@ USING: arrays ui.gadgets.buttons ui.gadgets.borders ui.gadgets.labels ui.gadgets.panes ui.gadgets.scrollers ui.gadgets.tracks ui.gadgets.theme ui.gadgets.frames -ui.gadgets.grids io kernel math models namespaces prettyprint +ui.gadgets.grids io kernel math models namespaces sequences sequences words classes.tuple ui.gadgets ui.render colors accessors ; IN: ui.gadgets.labelled diff --git a/basis/ui/gadgets/presentations/presentations.factor b/basis/ui/gadgets/presentations/presentations.factor index 33ef3bbe3a..61a55e926b 100644 --- a/basis/ui/gadgets/presentations/presentations.factor +++ b/basis/ui/gadgets/presentations/presentations.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2005, 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: arrays accessors definitions hashtables io kernel -prettyprint sequences strings io.styles words help math models +sequences strings io.styles words help math models namespaces quotations ui.gadgets ui.gadgets.borders ui.gadgets.buttons ui.gadgets.labels ui.gadgets.menus ui.gadgets.worlds diff --git a/basis/ui/gadgets/worlds/worlds.factor b/basis/ui/gadgets/worlds/worlds.factor index 68a2a18210..3b9b2fa1f3 100644 --- a/basis/ui/gadgets/worlds/worlds.factor +++ b/basis/ui/gadgets/worlds/worlds.factor @@ -3,7 +3,7 @@ USING: accessors arrays assocs continuations kernel math models namespaces opengl sequences io combinators fry math.vectors ui.gadgets ui.gestures ui.render ui.backend ui.gadgets.tracks -debugger math.geometry.rect ; +math.geometry.rect ; IN: ui.gadgets.worlds TUPLE: world < track @@ -76,7 +76,7 @@ C: world-error SYMBOL: ui-error-hook : ui-error ( error -- ) - ui-error-hook get [ call ] [ print-error ] if* ; + ui-error-hook get [ call ] [ die ] if* ; ui-error-hook global [ [ rethrow ] or ] change-at diff --git a/basis/ui/ui.factor b/basis/ui/ui.factor index de2eb71307..88f0a353b9 100644 --- a/basis/ui/ui.factor +++ b/basis/ui/ui.factor @@ -1,10 +1,10 @@ ! Copyright (C) 2006, 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: arrays assocs io kernel math models namespaces make -prettyprint dlists deques sequences threads sequences words -debugger ui.gadgets ui.gadgets.worlds ui.gadgets.tracks -ui.gestures ui.backend ui.render continuations init combinators -hashtables concurrency.flags sets accessors calendar ; +dlists deques sequences threads sequences words ui.gadgets +ui.gadgets.worlds ui.gadgets.tracks ui.gestures ui.backend +ui.render continuations init combinators hashtables +concurrency.flags sets accessors calendar ; IN: ui ! Assoc mapping aliens to gadgets diff --git a/basis/ui/x11/x11.factor b/basis/ui/x11/x11.factor index b65236d1f9..a532a13b69 100755 --- a/basis/ui/x11/x11.factor +++ b/basis/ui/x11/x11.factor @@ -5,7 +5,7 @@ ui.gestures ui.backend ui.clipboards ui.gadgets.worlds ui.render assocs kernel math namespaces opengl sequences strings x11.xlib x11.events x11.xim x11.glx x11.clipboard x11.constants x11.windows io.encodings.string io.encodings.ascii -io.encodings.utf8 combinators debugger command-line qualified +io.encodings.utf8 combinators command-line qualified math.vectors classes.tuple opengl.gl threads math.geometry.rect environment ascii ; IN: ui.x11