]> gitweb.factorcode.org Git - factor.git/commitdiff
io: add read-unsafe and read-partial-unsafe words
authorJoe Groff <arcata@gmail.com>
Thu, 13 Oct 2011 21:53:13 +0000 (14:53 -0700)
committerJoe Groff <arcata@gmail.com>
Tue, 18 Oct 2011 04:23:05 +0000 (21:23 -0700)
Add shortcut words to operate on the input-stream like the other stream methods have. Make all those words inline too just for fun.

core/io/io.factor

index fda1c7ac0fbb1dd937b897d21f2eb0d89ee892d3..ea8f99476dbd2a33bffbe3c7f6393bb58e9fab13 100644 (file)
@@ -33,19 +33,22 @@ SYMBOL: input-stream
 SYMBOL: output-stream
 SYMBOL: error-stream
 
-: readln ( -- str/f ) input-stream get stream-readln ;
-: read1 ( -- elt ) input-stream get stream-read1 ;
-: read-until ( seps -- seq sep/f ) input-stream get stream-read-until ;
-: tell-input ( -- n ) input-stream get stream-tell ;
-: tell-output ( -- n ) output-stream get stream-tell ;
-: seek-input ( n seek-type -- ) input-stream get stream-seek ;
-: seek-output ( n seek-type -- ) output-stream get stream-seek ;
-
-: write1 ( elt -- ) output-stream get stream-write1 ;
-: write ( seq -- ) output-stream get stream-write ;
-: flush ( -- ) output-stream get stream-flush ;
-
-: nl ( -- ) output-stream get stream-nl ;
+: readln ( -- str/f ) input-stream get stream-readln ; inline
+: read1 ( -- elt ) input-stream get stream-read1 ; inline
+: read-unsafe ( n buf -- count ) input-stream get stream-read-unsafe ; inline
+: read-partial-unsafe ( n buf -- count )
+    input-stream get stream-read-partial-unsafe ; inline
+: read-until ( seps -- seq sep/f ) input-stream get stream-read-until ; inline
+: tell-input ( -- n ) input-stream get stream-tell ; inline
+: tell-output ( -- n ) output-stream get stream-tell ; inline
+: seek-input ( n seek-type -- ) input-stream get stream-seek ; inline
+: seek-output ( n seek-type -- ) output-stream get stream-seek ; inline
+
+: write1 ( elt -- ) output-stream get stream-write1 ; inline
+: write ( seq -- ) output-stream get stream-write ; inline
+: flush ( -- ) output-stream get stream-flush ; inline
+
+: nl ( -- ) output-stream get stream-nl ; inline
 
 : with-input-stream* ( stream quot -- )
     input-stream swap with-variable ; inline
@@ -68,7 +71,7 @@ SYMBOL: error-stream
     #! buffer before closing the FD.
     swapd [ with-output-stream ] curry with-input-stream ; inline
 
-: print ( str -- ) output-stream get stream-print ;
+: print ( str -- ) output-stream get stream-print ; inline
 
 : bl ( -- ) " " write ;
 
@@ -104,8 +107,8 @@ PRIVATE>
 : stream-read-partial ( n stream -- seq/f )
     [ stream-read-partial-unsafe ] (read-into-new) ; inline
 
-: read ( n -- seq ) input-stream get stream-read ;
-: read-partial ( n -- seq ) input-stream get stream-read-partial ;
+: read ( n -- seq ) input-stream get stream-read ; inline
+: read-partial ( n -- seq ) input-stream get stream-read-partial ; inline
 
 : each-stream-line ( ... stream quot: ( ... line -- ... ) -- ... )
     swap [ stream-readln ] curry each-morsel ; inline