<magnus--> http://www.caddr.com/macho/archives/sbcl-devel/2005-3/4764.html\r
<magnus--> http://clozure.com/cgi-bin/viewcvs.cgi/ccl/lisp-kernel/lisp-exceptions.c?rev=1.9&content-type=text/vnd.viewcvs-markup\r
\r
+- set-length should not shorten the underlying sequence\r
- there is a problem with hashcodes of words and bootstrapping\r
- http keep alive, and range get\r
- sleep word\r
IN: algebra
-USING: kernel lists math namespaces test stdio words parser
+USING: kernel lists math namespaces test io words parser
generic errors prettyprint vectors kernel-internals ;
SYMBOL: variable?
-IN: algebra USING: prettyprint stdio kernel parser ;
+IN: algebra USING: prettyprint io kernel parser ;
: algebra-repl ( -- )
"ok " write flush
-USING: algebra test math kernel prettyprint stdio ;
+USING: algebra test math kernel prettyprint io ;
[ [ - [ + x [ mod [ * 2 pi ] 4 ] ] ] ] [
([ - x + [ 2 * pi ] mod 4 ])
USE: cont-responder
USE: html
USE: kernel
-USE: stdio
+USE: io
USE: html
USE: lists
USE: strings
USE: parser
USE: html
USE: cont-responder
-USE: stdio
+USE: io
USE: namespaces
: web-print ( str -- )
USE: namespaces
USE: kernel
USE: combinators
-USE: stdio
+USE: io
: <cont-test-state> ( -- <state> )
#! Create a namespace holding data required
USE: html
USE: cont-responder
USE: kernel
-USE: stdio
USE: namespaces
-USE: streams
+USE: io
USE: parser
USE: lists
USE: errors
USE: namespaces
USE: html
USE: words
-USE: stdio
+USE: io
USE: kernel
USE: cont-responder
USE: prettyprint
! and the 'liveUpdater.js' code.
IN: live-updater
USE: kernel
-USE: streams
+USE: io
USE: strings
USE: html
USE: cont-responder
-USE: stdio
USE: namespaces
USE: lists
USE: threads
USE: prettyprint
USE: errors
-USE: stdio
+USE: io
USE: parser
IN: todo-example
USE: cont-responder
USE: html
-USE: html
-USE: stdio
+USE: io
USE: strings
USE: namespaces
USE: inspector
IN: todo
USE: parser
USE: strings
-USE: streams
+USE: io
USE: namespaces
USE: lists
USE: math
-USE: stdio
USE: kernel
USE: prettyprint
-USE: files
USE: hashtables
USE: sequences
USE: http
IN: crypto
-USING: kernel streams strings stdio sequences namespaces math prettyprint unparser test parser lists ;
+USING: kernel io strings sequences namespaces math prettyprint
+unparser test parser lists ;
SYMBOL: a
SYMBOL: b
DEFER: (lappend*)
TUPLE: lappend*-state current rest ;
-USE: stdio
+USE: io
: (lappend*-cdr) ( state -- llist )
#! Given the state object, do the cdr portion of the
USE: prettyprint
USE: parser
USE: unparser
-USE: stdio
+USE: io
! Testing <&>
: test1 "abcd" "a" token "b" token <&> call [ . ] leach ;
! Set username and password in the 'connect' word.
IN: postgresql-test
-USING: kernel postgresql alien errors stdio ;
+USING: kernel postgresql alien errors io ;
: connect ( -- PGconn )
! Then run this file.
USE: sqlite
USE: kernel
-USE: stdio
+USE: io
USE: prettyprint
: show-people ( statement -- )
! See http://factor.sf.net/license.txt for BSD license.
IN: dump
USING: alien assembler generic kernel kernel-internals lists
-math memory sequences stdio strings unparser ;
+math memory sequences io strings unparser ;
: cell. >hex cell 2 * CHAR: 0 pad write ;
! A simple IRC client written in Factor.
IN: irc
-USING: kernel lists math namespaces stdio streams strings
-threads words ;
+USING: kernel lists math namespaces io strings threads words ;
SYMBOL: irc-stream
SYMBOL: channels
-USING: sequences kernel math stdio strings ;
+USING: sequences kernel math io strings ;
: lcd-digit ( digit row -- str )
{
USE: vectors
USE: prettyprint
USE: sequences
-USE: stdio
+USE: io
USE: test
: f_ ( h s v i -- f ) >r swap rot >r 2dup r> 6 * r> - ;
! Numbers game example
IN: numbers-game
-USING: kernel math parser random stdio ;
+USING: kernel math parser random io ;
: read-number ( -- n ) read parse-number ;
! Contractor timesheet example
IN: timesheet
-USING: errors kernel lists math namespaces sequences stdio
+USING: errors kernel lists math namespaces sequences io
strings unparser vectors ;
! Adding a new entry to the time sheet.
IN: turing
USING: hashtables kernel lists namespaces sequences vectors math
-prettyprint stdio strings words ;
+prettyprint io strings words ;
! A turing machine simulator.
! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: alien
-USING: hashtables kernel lists math namespaces parser stdio ;
+USING: hashtables kernel lists math namespaces parser io ;
DEFER: dll?
BUILTIN: dll 15 dll? [ 1 "dll-path" f ] ;
IN: alien
USING: assembler compiler compiler-backend compiler-frontend
errors generic hashtables inference kernel lists math namespaces
-sequences stdio strings unparser words ;
+sequences io strings unparser words ;
! ! ! WARNING ! ! !
! Reloading this file into a running Factor instance on Win32
! See http://factor.sf.net/license.txt for BSD license.
IN: image
USING: generic hashtables kernel lists math memory namespaces
-parser prettyprint sequences stdio vectors words ;
+parser prettyprint sequences io vectors words ;
"Bootstrap stage 1..." print
"/library/io/stream.factor"
"/library/io/stdio.factor"
+ "/library/io/lines.factor"
"/library/io/c-streams.factor"
"/library/io/files.factor"
! Copyright (C) 2004, 2005 Slava Pestov.\r
! See http://factor.sf.net/license.txt for BSD license.\r
USING: alien assembler command-line compiler generic hashtables\r
-kernel lists memory namespaces parser sequences stdio unparser\r
+kernel lists memory namespaces parser sequences io unparser\r
words ;\r
\r
: pull-in ( ? list -- )\r
! See http://factor.sf.net/license.txt for BSD license.
USING: alien assembler command-line compiler compiler-backend
compiler-frontend io-internals kernel lists math namespaces
-parser sequences stdio unparser words ;
+parser sequences io unparser words ;
"Compiling base..." print
IN: kernel
USING: alien assembler command-line compiler console errors
generic inference kernel-internals listener lists math memory
-namespaces parser presentation prettyprint random stdio streams
+namespaces parser presentation prettyprint random io
unparser words ;
"Bootstrap stage 4..." print
IN: image
USING: errors generic hashtables kernel lists
-math namespaces parser prettyprint sequences sequences stdio
-streams strings vectors words ;
+math namespaces parser prettyprint sequences sequences io
+strings vectors words ;
! The image being constructed; a vector of word-size integers
SYMBOL: image
! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: kernel
-USING: io-internals namespaces parser stdio threads words ;
+USING: io-internals namespaces parser io threads words ;
: boot ( -- )
#! Initialize an interpreter with the basic services.
[ "eq?" "kernel" [ [ object object ] [ boolean ] ] ]
[ "getenv" "kernel-internals" [ [ fixnum ] [ object ] ] ]
[ "setenv" "kernel-internals" [ [ object fixnum ] [ ] ] ]
- [ "stat" "files" [ [ string ] [ general-list ] ] ]
- [ "(directory)" "files" [ [ string ] [ general-list ] ] ]
+ [ "stat" "io" [ [ string ] [ general-list ] ] ]
+ [ "(directory)" "io" [ [ string ] [ general-list ] ] ]
[ "gc" "memory" [ [ fixnum ] [ ] ] ]
[ "gc-time" "memory" [ [ string ] [ ] ] ]
[ "save-image" "memory" [ [ string ] [ ] ] ]
[ "millis" "kernel" [ [ ] [ integer ] ] ]
[ "(random-int)" "math" [ [ ] [ integer ] ] ]
[ "type" "kernel" [ [ object ] [ fixnum ] ] ]
- [ "cwd" "files" [ [ ] [ string ] ] ]
- [ "cd" "files" [ [ string ] [ ] ] ]
+ [ "cwd" "io" [ [ ] [ string ] ] ]
+ [ "cd" "io" [ [ string ] [ ] ] ]
[ "compiled-offset" "assembler" [ [ ] [ integer ] ] ]
[ "set-compiled-offset" "assembler" [ [ integer ] [ ] ] ]
[ "literal-top" "assembler" [ [ ] [ integer ] ] ]
! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-IN: streams
+IN: io
USE: compiler
USE: namespaces
-USE: stdio
USE: kernel
USE: win32-io-internals
USE: win32-stream
! Copyright (C) 2003, 2004 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: command-line
-USING: files kernel kernel-internals lists namespaces parser
+USING: io kernel kernel-internals lists namespaces parser
sequences strings ;
! This file is run as the last stage of boot.factor; it relies
! Copyright (C) 2004, 2005 Slava Pestov.
IN: compiler
USING: compiler-backend compiler-frontend errors inference
-kernel lists math namespaces prettyprint stdio words ;
+kernel lists math namespaces prettyprint io words ;
: supported-cpu? ( -- ? )
cpu "unknown" = not ;
! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: kernel
+USING: kernel-internals lists ;
DEFER: callcc1
IN: errors
-USING: kernel-internals lists namespaces streams ;
TUPLE: no-method object generic ;
! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
-IN: parser USING: kernel errors stdio ;
+IN: parser USING: kernel errors io ;
: eval-catch ( str -- )
[ eval ] [ [ print-error debug-help drop ] when* ] catch ;
! cont-responder facilities.
!
IN: browser-responder
-USING: html cont-responder kernel stdio namespaces words lists
-streams strings inspector kernel prettyprint words http parser
+USING: html cont-responder kernel io namespaces words lists
+io strings inspector kernel prettyprint words http parser
errors unparser listener hashtables memory
sequences ;
! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
IN: cont-responder
-USING: stdio http httpd math random namespaces streams
+USING: http httpd math random namespaces io
lists strings kernel html unparser hashtables
parser generic sequences ;
! Copyright (C) 2004,2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: file-responder
-USING: files html httpd kernel lists namespaces parser sequences
-stdio streams strings unparser ;
+USING: html httpd kernel lists namespaces parser sequences
+io strings unparser ;
: serving-path ( filename -- filename )
[ "" ] unless* "doc-root" get swap append ;
USE: strings
USE: lists
USE: kernel
-USE: stdio
+USE: io
USE: namespaces
USE: words
USE: sequences
! See http://factor.sf.net/license.txt for BSD license.
IN: html
USING: generic kernel lists namespaces presentation sequences
-stdio streams strings unparser http ;
+io strings unparser http ;
: html-entities ( -- alist )
[
! See http://factor.sf.net/license.txt for BSD license.
IN: http-client
USING: errors http kernel lists namespaces parser sequences
-stdio streams strings unparser ;
+io strings unparser ;
: parse-host ( url -- host port )
#! Extract the host name and port number from an HTTP URL.
! Copyright (C) 2003, 2005 Slava Pestov
IN: http
USING: errors kernel lists math namespaces parser sequences
-stdio streams strings unparser ;
+io strings unparser ;
: header-line ( alist line -- alist )
": " split1 dup [ cons swons ] [ 2drop ] ifte ;
! Copyright (C) 2003, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: httpd
-USING: errors kernel lists namespaces
-stdio streams strings threads http sequences ;
+USING: errors kernel lists namespaces io strings threads http
+sequences ;
: (url>path) ( uri -- path )
url-decode "http://" ?head [
-USING: kernel parser sequences stdio ;
+USING: kernel parser sequences io ;
[
"/library/httpd/http-common.factor"
"/library/httpd/mime.factor"
! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: httpd
-USING: files hashtables kernel lists namespaces ;
+USING: io hashtables kernel lists namespaces ;
: set-mime-types ( assoc -- )
"mime-types" global set-hash ;
! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: resource-responder
-USING: httpd kernel lists namespaces stdio streams ;
+USING: httpd kernel lists namespaces io ;
: resource-response ( mime-type -- )
"Content-Type" swons unit "200 OK" response terpri ;
! See http://factor.sf.net/license.txt for BSD license.
IN: httpd
USING: hashtables http kernel lists namespaces parser sequences
-stdio streams strings ;
+io strings ;
! Variables
SYMBOL: vhosts
! See http://factor.sf.net/license.txt for BSD license.
IN: inference
USING: errors interpreter kernel lists namespaces prettyprint
-sequences stdio ;
+sequences io ;
DEFER: recursive-state
! See http://factor.sf.net/license.txt for BSD license.
IN: test
USING: errors inference kernel lists namespaces prettyprint
-stdio strings unparser ;
+io strings unparser ;
: try-infer ( quot -- effect error )
[ infer f ] [ [ >r drop f r> ] when* ] catch ;
! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: ansi
-USING: lists kernel namespaces stdio streams strings
+USING: lists kernel namespaces io strings
presentation generic sequences ;
! <ansi-stream> raps the given stream in an ANSI stream. ANSI
! Copyright (C) 2003, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
-IN: stdio
+IN: io
USING: kernel lists math sequences strings ;
: be> ( seq -- x ) 0 swap [ >r 8 shift r> bitor ] each ;
! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: io-internals
-USING: errors kernel kernel-internals namespaces stdio streams
+USING: errors kernel kernel-internals namespaces io
strings threads ;
! Simple wrappers for ANSI C I/O functions, used for
! bootstrapping only.
-! Note that c-streams are pretty limited and broken. Namely,
-! there is a limit of 1024 characters per line, and lines
-! containing \0 are not read properly.
-
! More elaborate platform-specific I/O code is used on Unix and
! Windows; see library/unix and library/win32.
nip >r dup string? [ ch>string ] unless r>
c-stream-out fwrite ;
-M: c-stream stream-readln ( stream -- str )
- c-stream-in dup [ fgets ] when ;
-
M: c-stream stream-read1 ( stream -- str )
c-stream-in dup [ fgetc ] when ;
c-stream-out [ fclose ] when* ;
: init-io ( -- )
- 13 getenv 14 getenv t <c-stream> stdio set ;
+ 13 getenv 14 getenv t <c-stream> <line-reader> stdio set ;
-IN: streams
+IN: io
: <file-reader> ( path -- stream )
- "rb" fopen f f <c-stream> ;
+ "rb" fopen f f <c-stream> <line-reader> ;
: <file-writer> ( path -- stream )
"wb" fopen f swap f <c-stream> ;
! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
-IN: files
+IN: io
USING: kernel hashtables lists namespaces presentation
-sequences stdio streams strings unparser ;
+sequences strings unparser ;
! Hyperlinked directory listings.
! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
-IN: files
+IN: io
USING: kernel lists sequences strings ;
! Words for accessing filesystem meta-data.
--- /dev/null
+! Copyright (C) 2004, 2005 Slava Pestov.
+! See http://factor.sf.net/license.txt for BSD license.
+USING: generic kernel namespaces sequences io ;
+
+TUPLE: line-reader cr ;
+
+C: line-reader ( stream -- line ) [ set-delegate ] keep ;
+
+: cr> dup line-reader-cr f rot set-line-reader-cr ;
+
+: (read-line) ( ? line -- ? )
+ #! The flag is set after the first character is read.
+ dup delegate stream-read1 dup [
+ >r >r drop t r> r> dup CHAR: \r = [
+ drop t swap set-line-reader-cr
+ ] [
+ dup CHAR: \n = [
+ drop dup cr> [ (read-line) ] [ drop ] ifte
+ ] [
+ , (read-line)
+ ] ifte
+ ] ifte
+ ] [
+ 2drop
+ ] ifte ;
+
+M: line-reader stream-readln ( line -- string )
+ [ f swap (read-line) ] make-string
+ dup empty? [ f ? ] [ nip ] ifte ;
+
+M: line-reader stream-read ( count line -- string )
+ [ delegate stream-read ] keep dup cr> [
+ over empty?
+ [ drop ]
+ [ >r 1 swap tail r> stream-read1 [ append ] when* ] ifte
+ ] [
+ drop
+ ] ifte ;
! Copyright (C) 2003, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
-IN: streams
-USING: kernel namespaces stdio sequences strings unparser ;
+IN: io
+USING: kernel namespaces io sequences strings unparser ;
! A simple logging framework.
SYMBOL: log-stream
! Copyright (C) 2003, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
-IN: stdio
-USING: errors kernel lists namespaces streams generic strings ;
+IN: io
+USING: errors kernel lists namespaces generic strings ;
SYMBOL: stdio
! Copyright (C) 2003, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
-IN: files
-USING: kernel strings sequences ;
+IN: io
+USING: errors generic kernel lists math namespaces sequences
+strings ;
! We need this early during bootstrap.
: path+ ( path path -- path )
#! Combine two paths. This will be implemented later.
"/" swap append3 ;
-IN: stdio
DEFER: stdio
-IN: streams
-USING: errors generic lists math namespaces sequences ;
-
! Stream protocol.
GENERIC: stream-flush ( stream -- )
GENERIC: stream-auto-flush ( stream -- )
-USING: kernel parser sequences stdio ;
+USING: kernel parser sequences io ;
[
"/library/sdl/sdl.factor"
"/library/sdl/sdl-video.factor"
! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: parser
-USING: kernel lists namespaces sequences streams strings ;
+USING: kernel lists namespaces sequences io ;
: file-vocabs ( -- )
"file-in" get "in" set
! Copyright (C) 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: parser
-USING: errors kernel lists math namespaces sequences streams
+USING: errors kernel lists math namespaces sequences io
strings unparser words ;
! The parser uses a number of variables:
! See http://factor.sf.net/license.txt for BSD license.
IN: prettyprint
USING: alien errors generic hashtables kernel lists math
-matrices memory namespaces parser presentation sequences stdio
-streams strings unparser vectors words ;
+matrices memory namespaces parser presentation sequences io
+strings unparser vectors words ;
SYMBOL: prettyprint-limit
SYMBOL: one-line
! Copyright (C) 2003, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: prettyprint
-USING: #<unknown> generic hashtables kernel lists math
-namespaces sequences stdio streams strings unparser words ;
+USING: generic hashtables io kernel lists namespaces sequences
+streams strings unparser words ;
! Prettyprinting words
: vocab-actions ( search -- list )
IN: temporary
-USING: stdio test ;
+USING: io test ;
[ "\0\0\u0004\u00d2" ] [ 1234 4 >be ] unit-test
[ "\u00d2\u0004\0\0" ] [ 1234 4 >le ] unit-test
USE: kernel
USE: math
USE: test
-USE: stdio
+USE: io
USE: prettyprint
USE: namespaces
USE: lists
USE: math
USE: namespaces
-USE: stdio
+USE: io
USE: test
: (callcc1-test)
USE: test
USE: lists
USE: parser
-USE: stdio
+USE: io
[ f ] [ [ ] [ ] catch ] unit-test
IN: temporary
-USE: files
+USE: io
USE: httpd
USE: lists
USE: test
IN: temporary
-USING: parser prettyprint sequences stdio strings unparser ;
+USING: parser prettyprint sequences io strings unparser ;
USE: hashtables
USE: namespaces
IN: temporary
USE: html
USE: namespaces
-USE: stdio
-USE: streams
+USE: io
USE: strings
USE: test
USE: kernel
USE: http
USE: httpd
USE: namespaces
-USE: stdio
+USE: io
USE: test
USE: strings
USE: lists
USE: test
USE: image
USE: namespaces
-USE: stdio
+USE: io
USE: parser
USE: kernel
USE: generic
USE: interpreter
USE: test
USE: namespaces
-USE: stdio
+USE: io
USE: prettyprint
USE: math
USE: math-internals
IN: temporary
-USING: math parser stdio streams strings test ;
+USING: math parser io strings test ;
[ 4 ] [ "/library/test/io/no-trailing-eol.factor" run-resource ] unit-test
IN: temporary
USE: namespaces
-USE: stdio
+USE: io
USE: test
USE: parser
IN: temporary
USE: namespaces
-USE: streams
-USE: stdio
+USE: io
USE: test
USE: generic
USE: kernel
IN: test
USING: errors kernel lists math memory namespaces parser
-prettyprint sequences stdio strings unparser vectors words ;
+prettyprint sequences io strings unparser vectors words ;
TUPLE: assert got expect ;
IN: temporary
USE: namespaces
-USE: stdio
+USE: io
USE: test
USE: threads
USE: errors
! annotated words cannot be compiled; and annotating a word has
! no effect of compiled calls to that word.
USING: interpreter kernel lists prettyprint sequences
-stdio strings test ;
+io strings test ;
: annotate ( word quot -- | quot: word def -- def )
over >r >r dup word-def r> call r> swap (define-compound) ;
! See http://factor.sf.net/license.txt for BSD license.
IN: errors
USING: generic kernel kernel-internals lists math namespaces
-parser prettyprint sequences stdio streams strings unparser
+parser prettyprint sequences io strings unparser
vectors words ;
: expired-error. ( obj -- )
! See http://factor.sf.net/license.txt for BSD license.
IN: interpreter
USING: errors kernel kernel-internals lists math namespaces
-prettyprint sequences stdio strings vectors words ;
+prettyprint sequences io strings vectors words ;
! A Factor interpreter written in Factor. Used by compiler for
! partial evaluation, also by the walker.
! See http://factor.sf.net/license.txt for BSD license.
IN: jedit
USING: generic kernel listener lists namespaces parser
-prettyprint sequences stdio streams strings words ;
+prettyprint sequences io strings words ;
! Wire protocol for jEdit to evaluate Factor code.
! Packets are of the form:
! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: jedit
-USING: files kernel lists namespaces parser sequences stdio
-streams strings unparser words ;
+USING: kernel lists namespaces parser sequences io strings
+unparser words ;
: jedit-server-file ( -- path )
"jedit-server-file" get
! See http://factor.sf.net/license.txt for BSD license.
IN: listener
USING: errors kernel lists math memory namespaces parser
-sequences stdio strings presentation words unparser vectors ansi ;
+sequences io strings presentation words unparser vectors ansi ;
SYMBOL: cont-prompt
SYMBOL: listener-prompt
! See http://factor.sf.net/license.txt for BSD license.
IN: memory
USING: errors generic hashtables kernel kernel-internals lists
-math namespaces prettyprint sequences stdio strings unparser
+math namespaces prettyprint sequences io strings unparser
vectors words ;
: generations 15 getenv ;
! Copyright (C) 2003, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: telnetd
-USING: errors listener kernel namespaces stdio streams
-threads parser ;
+USING: errors listener kernel namespaces io threads parser ;
: telnet-client ( socket -- )
dup [ log-client listener ] with-stream ;
! See http://factor.sf.net/license.txt for BSD license.
IN: interpreter
USING: errors kernel listener lists math namespaces prettyprint
-sequences stdio strings vectors words ;
+sequences io strings vectors words ;
! The single-stepper simulates Factor in Factor to allow
! single-stepping through the execution of a quotation. It can
! Copyright (C) 2003, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: words
-USING: files generic inspector lists kernel namespaces
-prettyprint stdio streams strings sequences unparser math
+USING: generic inspector lists kernel namespaces
+prettyprint io strings sequences unparser math
hashtables parser ;
: vocab-apropos ( substring vocab -- list )
! See http://factor.sf.net/license.txt for BSD license.
IN: gadgets
USING: generic kernel lists math namespaces prettyprint sdl
-sequences stdio sequences ;
+sequences io sequences ;
: button-down? ( n -- ? ) hand hand-buttons contains? ;
! See http://factor.sf.net/license.txt for BSD license.
IN: gadgets
USING: alien generic kernel lists math namespaces prettyprint
-sequences sdl stdio ;
+sequences sdl io ;
DEFER: pick-up
! Copyright (C) 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: gadgets
-USING: generic kernel lists math namespaces sdl stdio
-sequences ;
+USING: generic kernel lists math namespaces sdl io sequences ;
! A label gadget draws a string.
TUPLE: label text ;
-USING: kernel parser sequences stdio ;
+USING: kernel parser sequences io ;
[
"/library/ui/shapes.factor"
"/library/ui/points.factor"
! See http://factor.sf.net/license.txt for BSD license.
IN: gadgets
USING: generic hashtables kernel lists math namespaces sdl
-stdio strings sequences ;
+io strings sequences ;
! Clipping
! See http://factor.sf.net/license.txt for BSD license.
IN: gadgets
USING: generic kernel line-editor listener lists math namespaces
-sequences stdio streams strings threads ;
+sequences io strings threads ;
! A pane is an area that can display text.
! Copyright (C) 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: gadgets
-USING: kernel lists namespaces prettyprint stdio unparser ;
+USING: kernel lists namespaces prettyprint io unparser ;
DEFER: inspect
! do not have x/y co-ordinates.
IN: gadgets
USING: alien hashtables kernel lists namespaces sdl sequences
-streams strings ;
+io strings ;
SYMBOL: fonts
! Copyright (C) 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: gadgets
-USING: kernel memory namespaces stdio ;
+USING: kernel memory namespaces io ;
SYMBOL: root-menu
! See http://factor.sf.net/license.txt for BSD license.
IN: gadgets
USING: alien errors generic kernel lists math
-memory namespaces prettyprint sdl sequences stdio strings
+memory namespaces prettyprint sdl sequences io strings
threads sequences ;
! The world gadget is the top level gadget that all (visible)
! Copyright (C) 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
-IN: streams
+IN: io
USE: io-internals
: <file-reader> ( path -- stream ) open-read <reader> ;
! See http://factor.sf.net/license.txt for BSD license.
IN: io-internals
USING: alien assembler errors generic hashtables kernel
-kernel-internals lists math sequences streams strings threads
+kernel-internals lists math sequences io strings threads
unix-internals unparser vectors ;
! We want namespaces::bind to shadow the bind system call from
: init-handle ( fd -- ) F_SETFL O_NONBLOCK fcntl io-error ;
! Common delegate of native stream readers and writers
-TUPLE: port handle buffer error timeout cutoff ;
+TUPLE: port handle buffer error timeout cutoff output? sbuf ;
: make-buffer ( n -- buffer/f )
dup 0 > [ <buffer> ] [ drop f ] ifte ;
[ >r make-buffer r> set-delegate ] keep
[ >r dup init-handle r> set-port-handle ] keep ;
-M: port stream-close ( port -- )
- dup port-handle close
- delegate [ buffer-free ] when* ;
-
: touch-port ( port -- )
- dup port-timeout dup 0 = [
- 2drop
- ] [
- millis + swap set-port-cutoff
- ] ifte ;
+ dup port-timeout dup 0 =
+ [ 2drop ] [ millis + swap set-port-cutoff ] ifte ;
M: port set-timeout ( timeout port -- )
[ set-port-timeout ] keep touch-port ;
! Readers
+: <reader> ( fd -- stream )
+ buffered-port <line-reader> ;
+
: open-read ( path -- fd )
O_RDONLY file-mode open dup io-error ;
-! The cr slot is set to true by read-line-loop if the last
-! character read was \r.
-TUPLE: reader line cr ;
-
-C: reader ( handle -- reader )
- [ >r buffered-port r> set-delegate ] keep ;
-
: pop-line ( reader -- sbuf/f )
- dup pending-error [ reader-line f ] keep set-reader-line ;
+ dup pending-error [ port-sbuf f ] keep set-port-sbuf ;
: read-fin ( reader -- str ) pop-line dup [ >string ] when ;
-: reader-cr> ( reader -- ? )
- dup reader-cr >r f swap set-reader-cr r> ;
-
-! Reading lines
-: read-line-char ( reader ch -- )
- f pick set-reader-cr swap reader-line push ;
-
-: read-line-loop ( reader -- ? )
- dup buffer-length 0 = [
- drop f
- ] [
- dup buffer-pop
- dup CHAR: \r = [
- drop t swap set-reader-cr t
- ] [
- dup CHAR: \n = [
- drop dup reader-cr> [
- read-line-loop
- ] [
- drop t
- ] ifte
- ] [
- dupd read-line-char read-line-loop
- ] ifte
- ] ifte
- ] ifte ;
-
-: init-reader ( count reader -- ) >r <sbuf> r> set-reader-line ;
-
-: can-read-line? ( reader -- ? )
- dup pending-error 80 over init-reader read-line-loop ;
+: init-reader ( count reader -- ) >r <sbuf> r> set-port-sbuf ;
: reader-eof ( reader -- )
- dup reader-line empty? [
- f swap set-reader-line
+ dup port-sbuf empty? [
+ f swap set-port-sbuf
] [
drop
] ifte ;
drop t
] ifte ;
-TUPLE: read-line-task ;
-
-C: read-line-task ( port -- task )
- [ >r <io-task> r> set-delegate ] keep ;
-
-M: read-line-task do-io-task ( task -- ? )
- io-task-port dup refill [
- dup eof? [
- reader-eof t
- ] [
- read-line-loop
- ] ifte
- ] [
- drop f
- ] ifte ;
-
-M: read-line-task task-container drop read-tasks get ;
-
-: wait-to-read-line ( port -- )
- dup can-read-line? [
- [ swap <read-line-task> add-io-task stop ] callcc0
- ] unless drop ;
-
-M: reader stream-readln ( stream -- line )
- dup wait-to-read-line read-fin ;
-
-: trailing-cr ( reader -- )
- #! Handle a corner case. If the previous request was a line
- #! read and the line ends with \r\n, the reader stopped
- #! reading at \r and set the reader-cr flag to true. But we
- #! must ignore the \n.
- dup buffer-length 1 >= [
- dup reader-cr [
- dup buffer-peek CHAR: \n = [
- 1 swap buffer-consume
- ] [
- drop
- ] ifte
- ] [
- drop
- ] ifte
- ] [
- drop
- ] ifte ;
-
! Reading character counts
: read-step ( count reader -- ? )
- dup trailing-cr
- dup reader-line -rot >r over length - ( remaining) r>
+ dup port-sbuf -rot >r over length - ( remaining) r>
2dup buffer-length <= [
buffer> nappend t
] [
[ -rot <read-task> add-io-task stop ] callcc0
] unless 2drop ;
-M: reader stream-read ( count stream -- string )
+M: port stream-read ( count stream -- string )
[ wait-to-read ] keep read-fin ;
-M: reader stream-read1 ( stream -- string )
- 1 over wait-to-read reader-line first ;
+M: port stream-read1 ( stream -- string )
+ 1 over wait-to-read port-sbuf first ;
! Writers
O_WRONLY O_CREAT bitor O_TRUNC bitor file-mode open
dup io-error ;
-TUPLE: writer ;
-
-C: writer ( fd -- writer )
- [ >r buffered-port r> set-delegate ] keep ;
+: <writer> ( fd -- writer )
+ buffered-port t over set-port-output? ;
: write-step ( port -- )
dup >port< dup buffer@ swap buffer-length write dup 0 >= [
add-io-task
] ifte* ;
-M: writer stream-flush ( stream -- )
- [ swap <write-task> add-write-io-task stop ] callcc0 drop ;
+M: port stream-flush ( stream -- )
+ dup port-output? [
+ [ swap <write-task> add-write-io-task stop ] callcc0
+ ] when drop ;
-M: writer stream-auto-flush ( stream -- ) drop ;
+M: port stream-auto-flush ( stream -- ) drop ;
: wait-to-write ( len port -- )
tuck can-write? [ drop ] [ stream-flush ] ifte ;
: blocking-write ( str writer -- )
over length over wait-to-write write-fin ;
-M: writer stream-write-attr ( string style writer -- )
+M: port stream-write-attr ( string style writer -- )
nip >r dup string? [ ch>string ] unless r> blocking-write ;
-M: writer stream-close ( stream -- )
- dup stream-flush delegate stream-close ;
+M: port stream-close ( stream -- )
+ dup stream-flush delegate [ buffer-free ] when* ;
! Make a duplex stream for reading/writing a pair of fds
+
: <fd-stream> ( infd outfd flush? -- stream )
>r >r <reader> r> <writer> r> <duplex-stream> ;
[ schedule-thread 10 io-multiplex stop ] callcc0
idle-io-task ;
-USE: stdio
+USE: io
: init-io ( -- )
#! Should only be called on startup. Calling this at any
! We need to fiddle with the exact search order here, since
! unix-internals::accept shadows streams::accept.
IN: io-internals
-USING: errors namespaces streams threads unparser alien generic
+USING: errors namespaces io threads unparser alien generic
kernel math unix-internals ;
: <socket-stream> ( fd -- stream )
dup 0 >= [ drop 1 listen ] [ ( fd n - n) nip ] ifte
] with-socket-fd ;
-IN: streams
+IN: io
C: client-stream ( host port fd -- stream )
[ >r <socket-stream> r> set-delegate ] keep
: timeout-opt ( fd level opt value -- )
"timeval" c-size setsockopt io-error ;
-IN: streams
+IN: io
: accept ( server -- client )
#! Wait for a client connection.
! For interactive
"scratchpad" "in" set
[
- "compiler" "debugger" "errors" "files" "generic"
+ "compiler" "debugger" "errors" "generic"
"hashtables" "inference" "interpreter" "jedit" "kernel"
- "listener" "lists" "math" "memory" "namespaces" "parser"
- "prettyprint" "processes" "profiler" "sequences"
- "streams" "stdio" "strings" "syntax" "test" "threads"
+ "listener" "lists" "math" "matrices" "memory"
+ "namespaces" "parser" "prettyprint" "processes"
+ "sequences" "io" "strings" "syntax" "test" "threads"
"unparser" "vectors" "words" "scratchpad"
] "use" set ;
IN: win32-io-internals
USING: alien errors kernel kernel-internals lists math namespaces threads
- vectors win32-api stdio streams generic io-internals sequences ;
+ vectors win32-api io generic io-internals sequences ;
SYMBOL: completion-port
SYMBOL: io-queue
IN: win32-stream
USING: alien errors generic kernel kernel-internals lists math namespaces
- prettyprint sequences stdio streams strings threads unparser win32-api
+ prettyprint sequences io strings threads unparser win32-api
win32-io-internals io-internals ;
TUPLE: win32-server this ;
M: win32-server stream-close ( server -- )
win32-server-this [ socket get CloseHandle drop ] bind ;
-IN: streams
+IN: io
: accept ( server -- client )
win32-server-this [
new-socket 64 <buffer>
IN: win32-stream
USING: alien continuations generic io-internals kernel
kernel-internals lists math namespaces prettyprint sequences
-stdio streams strings threads win32-api win32-io-internals ;
+io strings threads win32-api win32-io-internals ;
TUPLE: win32-stream this ; ! FIXME: rewrite using tuples
GENERIC: win32-stream-handle
box_alien(file);
}
-#define FACTOR_LINE_LEN 1024
-
-void primitive_fgets(void)
-{
- FILE* file;
- char line[FACTOR_LINE_LEN];
-
- maybe_gc(0);
-
- file = (FILE*)unbox_alien();
- if(fgets(line,FACTOR_LINE_LEN,file) == NULL)
- {
- if(feof(file))
- dpush(F);
- else
- io_error();
- }
- else
- dpush(tag_object(from_c_string(line)));
-}
-
void primitive_fgetc(void)
{
FILE* file = (FILE*)unbox_alien();
void primitive_fwrite(void);
void primitive_fflush(void);
void primitive_fclose(void);
-void primitive_fgets(void);
void primitive_fgetc(void);
primitive_die,
primitive_flush_icache,
primitive_fopen,
- primitive_fgets,
primitive_fgetc,
primitive_fwrite,
primitive_fflush,