]> gitweb.factorcode.org Git - factor.git/commitdiff
io: input-stream and output-stream mixins
authorJoe Groff <arcata@gmail.com>
Tue, 18 Oct 2011 23:24:50 +0000 (16:24 -0700)
committerJoe Groff <arcata@gmail.com>
Tue, 18 Oct 2011 23:25:09 +0000 (16:25 -0700)
21 files changed:
basis/html/streams/streams.factor
basis/io/ports/ports.factor
basis/io/streams/duplex/duplex.factor
basis/io/streams/null/null.factor
basis/io/streams/string/string.factor
basis/io/streams/throwing/throwing.factor
basis/io/styles/styles.factor
basis/ui/gadgets/panes/panes.factor
basis/ui/tools/listener/listener.factor
core/io/encodings/encodings.factor
core/io/io-tests.factor
core/io/io.factor
core/io/streams/byte-array/byte-array.factor
core/io/streams/c/c.factor
core/io/streams/memory/memory.factor
core/io/streams/sequence/sequence.factor
extra/benchmark/tcp-echo0/tcp-echo0.factor
extra/curses/listener/listener.factor
extra/io/streams/peek/peek.factor
extra/irc/client/internals/internals-tests.factor
extra/readline-listener/readline-listener.factor

index b865206219fcbca4b148d61db3e1e3625d473bb4..1b1e3c2dea1234b8dc17fa04f21b0e1f95d51485 100644 (file)
@@ -11,6 +11,7 @@ GENERIC: url-of ( object -- url )
 M: object url-of drop f ;
 
 TUPLE: html-writer data ;
+INSTANCE: html-writer output-stream
 
 <PRIVATE
 
index 6f1328956f5c4c7b57b6e100c3ac38854d9bcc1d..b255834dc0f742e7567e4a06ce56431773ce56aa 100644 (file)
@@ -29,6 +29,7 @@ TUPLE: buffered-port < port { buffer buffer } ;
         default-buffer-size get <buffer> >>buffer ; inline
 
 TUPLE: input-port < buffered-port ;
+INSTANCE: input-port input-stream
 
 M: input-port stream-element-type drop +byte+ ; inline
 
@@ -108,6 +109,7 @@ M: input-port stream-read-until ( seps port -- str/f sep/f )
     ] if ;
 
 TUPLE: output-port < buffered-port ;
+INSTANCE: output-port output-stream
 
 : <output-port> ( handle -- output-port )
     output-port <buffered-port> ;
index 0e4d1fd19527fc815a2a9590bddadc5d3ee713b6..ddc5974bdedaf3abd12d121e167817b97701c8eb 100644 (file)
@@ -13,6 +13,9 @@ CONSULT: input-stream-protocol duplex-stream in>> ;
 CONSULT: output-stream-protocol duplex-stream out>> ;
 CONSULT: formatted-output-stream-protocol duplex-stream out>> ;
 
+INSTANCE: duplex-stream input-stream
+INSTANCE: duplex-stream output-stream
+
 : >duplex-stream< ( stream -- in out ) [ in>> ] [ out>> ] bi ; inline
 
 M: duplex-stream stream-element-type
index ae4fae2a9021e1920a56d26ec023900ab47ef38d..e1688c87fecde2886975cbe2fc8578a9a7256035 100644 (file)
@@ -5,6 +5,8 @@ IN: io.streams.null
 
 SINGLETONS: null-reader null-writer ;
 UNION: null-stream null-reader null-writer ;
+INSTANCE: null-reader input-stream
+INSTANCE: null-writer output-stream
 INSTANCE: null-writer plain-writer
 
 M: null-stream dispose drop ;
index a1fad6ba681a223773eff28dc36590276c3a6421..29bd602cc968f033dd512fc2e3ab5968e40909df 100644 (file)
@@ -8,6 +8,7 @@ IN: io.streams.string
 
 ! Readers
 TUPLE: string-reader { underlying string read-only } { i array-capacity } ;
+INSTANCE: string-reader input-stream
 
 M: string-reader stream-element-type drop +character+ ;
 M: string-reader stream-read-unsafe sequence-read-unsafe ;
index bc80bb08d7121b7b5924d3eeccfe801ff55f5674..1d53d14d3ae415c721a174a43e0f0c192ba3c414 100644 (file)
@@ -7,6 +7,7 @@ IN: io.streams.throwing
 ERROR: stream-exhausted n stream word ;
 
 TUPLE: throws-on-eof-stream stream ;
+INSTANCE: throws-on-eof-stream input-stream
 
 C: <throws-on-eof-stream> throws-on-eof-stream
 
index d4e1d2c557a4df20e7382a0a7c2be2b3c79fc690..3b4b6ce9ca0d4211562899cc8235e5d36d8c4344 100644 (file)
@@ -60,6 +60,7 @@ M: ignore-close-stream dispose drop ;
 C: <ignore-close-stream> ignore-close-stream
 
 TUPLE: style-stream < filter-writer style ;
+INSTANCE: style-stream output-stream
 
 : do-nested-style ( style style-stream -- style stream )
     [ style>> swap assoc-union ] [ stream>> ] bi ; inline
index 773ad29c935478d65b38a2a846fb3efbb980fc9c..1680e7b2a874e015cb4882bde544889f9cd8e0e0 100644 (file)
@@ -19,6 +19,7 @@ output current input last-line prototype scrolls?
 selection-color caret mark selecting? ;
 
 TUPLE: pane-stream pane ;
+INSTANCE: pane-stream output-stream
 
 C: <pane-stream> pane-stream
 
index b8f78505a94d3613c661ab81c9faf69d2ed621c4..dbcab33776f852b45871ad28bbb500b4db844a67 100644 (file)
@@ -24,6 +24,8 @@ IN: ui.tools.listener
 TUPLE: interactor < source-editor
 output history flag mailbox thread waiting token-model word-model popup ;
 
+INSTANCE: interactor input-stream
+
 : register-self ( interactor -- )
     <mailbox> >>mailbox
     self >>thread
index be99b178d4d9132aa408a86bb44c3ce9bb892b5b..8afda8ed60a79b6cb51d18c12731edd8a2edba97 100644 (file)
@@ -26,12 +26,14 @@ GENERIC: <decoder> ( stream encoding -- newstream )
 CONSTANT: replacement-char HEX: fffd
 
 TUPLE: decoder { stream read-only } { code read-only } { cr boolean } ;
+INSTANCE: decoder input-stream
 
 ERROR: decode-error ;
 
 GENERIC: <encoder> ( stream encoding -- newstream )
 
 TUPLE: encoder { stream read-only } { code read-only } ;
+INSTANCE: encoder output-stream
 
 ERROR: encode-error ;
 
index 511e7eebf48b673a8d565130d22012e76b45dcb9..237c0f617c91ae8819cb272e91d1a03fdb2049cd 100644 (file)
@@ -13,6 +13,7 @@ IN: io.tests
 ! Test default input stream protocol methods
 
 TUPLE: up-to-13-reader { i fixnum initial: 0 } ;
+INSTANCE: up-to-13-reader input-stream
 
 M: up-to-13-reader stream-element-type drop +byte+ ; inline
 M: up-to-13-reader stream-read1
@@ -55,6 +56,7 @@ M: up-to-13-reader stream-read1
 ! Test default output stream protocol methods
 
 TUPLE: dumb-writer vector ;
+INSTANCE: dumb-writer output-stream
 
 : <dumb-writer> ( -- x ) BV{ } clone dumb-writer boa ; inline
 
index e7e16371ad27657168e567938f74ef13cb13c734..110f0f5943c5b0a2742405a76017757c8086bc5b 100644 (file)
@@ -32,8 +32,8 @@ GENERIC: stream-length ( stream -- n/f )
 : stream-print ( str stream -- ) [ stream-write ] [ stream-nl ] bi ;
 
 ! Default streams
-SYMBOL: input-stream
-SYMBOL: output-stream
+MIXIN: input-stream
+MIXIN: output-stream
 SYMBOL: error-stream
 
 : readln ( -- str/f ) input-stream get stream-readln ; inline
@@ -216,16 +216,18 @@ ERROR: invalid-read-buffer buf stream ;
     [ stream-exemplar ] bi produce-as swap finalize-read-until ; inline
 PRIVATE>
 
-M: object stream-read-unsafe rot 0 read-loop ;
-M: object stream-read-partial-unsafe stream-read-unsafe ; inline
-M: object stream-read-until read-until-loop ;
-M: object stream-readln
+M: input-stream stream-read-unsafe rot 0 read-loop ;
+M: input-stream stream-read-partial-unsafe stream-read-unsafe ; inline
+M: input-stream stream-read-until read-until-loop ;
+M: input-stream stream-readln
     "\n" swap stream-read-until drop ; inline
-M: object stream-contents (stream-contents-by-length-or-block) ; inline
-M: object stream-seekable? drop f ; inline
-M: object stream-length drop f ; inline
-
-M: object stream-write [ stream-write1 ] curry each ; inline
-M: object stream-flush drop ; inline
-M: object stream-nl CHAR: \n swap stream-write1 ; inline
+M: input-stream stream-contents (stream-contents-by-length-or-block) ; inline
+M: input-stream stream-seekable? drop f ; inline
+M: input-stream stream-length drop f ; inline
+
+M: output-stream stream-write [ stream-write1 ] curry each ; inline
+M: output-stream stream-flush drop ; inline
+M: output-stream stream-nl CHAR: \n swap stream-write1 ; inline
+M: output-stream stream-seekable? drop f ; inline
+M: output-stream stream-length drop f ; inline
 
index b8668e78b959a8c62732c8a5107a22a0775e4dd3..930bee22399a3292796af202b13ec8cb5ca118b5 100644 (file)
@@ -5,6 +5,7 @@ io.encodings io.private io.streams.sequence kernel namespaces
 sequences sequences.private ;
 IN: io.streams.byte-array
 
+INSTANCE: byte-vector output-stream
 M: byte-vector stream-element-type drop +byte+ ;
 
 : <byte-writer> ( encoding -- stream )
@@ -15,6 +16,7 @@ M: byte-vector stream-element-type drop +byte+ ;
     dup encoder? [ stream>> ] when >byte-array ; inline
 
 TUPLE: byte-reader { underlying byte-array read-only } { i array-capacity } ;
+INSTANCE: byte-reader input-stream
 
 M: byte-reader stream-element-type drop +byte+ ;
 
index ea5443a58aebeafb8a0852ea1befaf8e10f2cb6b..8f43181656b17ba0e7a634f0daa88abbcdc279a5 100644 (file)
@@ -14,6 +14,7 @@ TUPLE: c-stream < disposable handle ;
 M: c-stream dispose* handle>> fclose ;
 
 TUPLE: c-writer < c-stream ;
+INSTANCE: c-writer output-stream
 
 : <c-writer> ( handle -- stream ) c-writer new-c-stream ;
 
@@ -28,6 +29,7 @@ M: c-writer stream-write
 M: c-writer stream-flush dup check-disposed handle>> fflush ;
 
 TUPLE: c-reader < c-stream ;
+INSTANCE: c-reader input-stream
 
 : <c-reader> ( handle -- stream ) c-reader new-c-stream ;
 
index 67dc53844e21190b1cefa7a2cc051ade478196a6..9099b620e4f80217c5e06fbab472f4a610931952 100644 (file)
@@ -8,6 +8,8 @@ TUPLE: memory-stream alien ;
 : <memory-stream> ( alien -- stream )
     memory-stream boa ;
 
+INSTANCE: memory-stream input-stream
+
 M: memory-stream stream-element-type drop +byte+ ;
 
 M: memory-stream stream-read1
index 14a164f4b10731fda214709ca493c3c432d1a0e0..26093d07b309bb27dc3fd8711b1b9af4f2f4c1a3 100644 (file)
@@ -48,6 +48,7 @@ M: growable stream-write1 push ;
 M: growable stream-write push-all ;
 M: growable stream-flush drop ;
 
+INSTANCE: growable output-stream
 INSTANCE: growable plain-writer
 
 ! Seeking
index 8387a1ae3a4ccc37bb536444567e33ba3edee107..76860c66676a0457fab7132c33bfd15b3eb22012 100644 (file)
@@ -6,7 +6,7 @@ locals formatting ;
 IN: benchmark.tcp-echo0
 
 ! Max size here is 26 2^ 1 - because array-capacity limits on 32bit platforms
-CONSTANT: test-size0 $[ 26 2^ 1 - ]
+CONSTANT: test-size0 $[ 25 2^ 1 - ]
 
 MEMO: test-bytes ( n -- byte-array ) iota >byte-array ;
 
index 6051b1ca015992392ed0ac67eacce0d1de3b2272..bd668cee013c6b82789874dd6af285f130fe7539 100644 (file)
@@ -39,6 +39,9 @@ IN: curses.listener
 
 SINGLETON: curses-listener-stream
 
+INSTANCE: curses-listener-stream input-stream
+INSTANCE: curses-listener-stream output-stream
+
 M: curses-listener-stream stream-readln
     drop [ curses-stream-readln ] B{ } make utf8 decode ;
 
index ab0085c6d283f88df74f48cf504abb9092c87011..886b4c0254d206044ea15b0e4eaf0cf52fff2a88 100644 (file)
@@ -6,6 +6,8 @@ vectors ;
 IN: io.streams.peek
 
 TUPLE: peek-stream stream peeked ;
+INSTANCE: peek-stream input-stream
+INSTANCE: peek-stream output-stream
 
 M: peek-stream dispose stream>> dispose ;
 
index 84510fb67e350d674ae0a5c8668c984ac3504368..377c80cf51efdb486edbd2a104ad906f2f89aae9 100644 (file)
@@ -11,7 +11,11 @@ IN: irc.client.internals.tests
 
 ! Streams for testing
 TUPLE: mb-writer lines last-line disposed ;
+INSTANCE: mb-writer output-stream
+
 TUPLE: mb-reader lines disposed ;
+INSTANCE: mb-reader input-stream
+
 : <mb-writer> ( -- mb-writer ) V{ } clone V{ } clone f mb-writer boa ;
 : <mb-reader> ( -- mb-reader ) <mailbox> f mb-reader boa ;
 : push-line ( line test-reader-stream -- ) lines>> mailbox-put ;
index c1eba4e96dae1693839db29459435b1064e95082..9f23b8ef36e842863b99cca70521f73a57c124b9 100644 (file)
@@ -10,6 +10,8 @@ IN: readline-listener
 SYMBOL: completions
 
 TUPLE: readline-reader { prompt initial: f } ;
+INSTANCE: readline-reader input-stream
+
 M: readline-reader stream-readln
     flush [ prompt>> dup [ " " append ] [ ] if readline ]
     keep f >>prompt drop ;