From 9baf908d86bd547e5338c05cd6ff8368e49046c5 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 23 Apr 2005 21:42:42 +0000 Subject: [PATCH] I/O code fixes; it now works on FreeBSD 4.11 --- TODO.FACTOR.txt | 39 +++++++----- library/bootstrap/boot-stage1.factor | 2 +- library/bootstrap/boot-stage2.factor | 2 + library/bootstrap/boot-stage3.factor | 91 +++++++++++++++++++--------- library/bootstrap/boot-stage4.factor | 18 ------ library/bootstrap/init.factor | 2 +- library/threads.factor | 3 +- library/unix/io.factor | 10 ++- 8 files changed, 98 insertions(+), 69 deletions(-) diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index d35a5539bd..f186cc2c70 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -1,18 +1,3 @@ -- faster layout -- faster repaint -- linux/ppc and mac os x ffi -- stream server can hang because of exception handler limitations -- better i/o scheduler -- add a socket timeout -- unix ffi i/o -- powerpc has weird callstack residue -- console with presentations -- renumber types appopriately -- stop word needs a fix -- fix logging -- re-add httpd to bootstrap -- linux? freebsd? words, linux i/o stuff - + plugin: - extract word: if selection empty, move caret to new word after @@ -21,6 +6,9 @@ + ui: +- faster layout +- faster repaint +- console with presentations - ui browser - auto-updating inspector - word preview for parsing words @@ -79,6 +67,8 @@ + kernel: +- powerpc has weird callstack residue +- .factor-rc loading errors are not reported properly - instances: do not use make-list - unions containing tuples do not work properly - need G: combinations @@ -86,7 +76,6 @@ - code walker & exceptions - string sub-primitives - clean up metaclasses -- unify unparse and prettyprint - condition system with restarts - nicer way to combine two paths - vectors: ensure its ok with bignum indices @@ -95,6 +84,24 @@ - doc comments of generics - proper ordering for classes ++ i/o: + +- separate words for writing characters and strings +- perhaps: + GENERIC: set-style ( style stream -- ) + GENERIC: stream-write + GENERIC: stream-write-char +- linux/ppc and mac os x ffi +- stream server can hang because of exception handler limitations +- better i/o scheduler +- add a socket timeout +- unix ffi i/o +- renumber types appopriately +- linux? freebsd? words, linux i/o stuff +- clean up errors +- implement fcopy +- unify unparse and prettyprint + + nice to have libraries: - regexps diff --git a/library/bootstrap/boot-stage1.factor b/library/bootstrap/boot-stage1.factor index ebc7f0acf9..08fdcae59b 100644 --- a/library/bootstrap/boot-stage1.factor +++ b/library/bootstrap/boot-stage1.factor @@ -38,11 +38,11 @@ hashtables ; "/library/vocabularies.factor" "/library/errors.factor" "/library/continuations.factor" - "/library/threads.factor" "/library/io/stream.factor" "/library/io/stdio.factor" "/library/io/c-streams.factor" "/library/io/files.factor" + "/library/threads.factor" "/library/syntax/parse-numbers.factor" "/library/syntax/parse-words.factor" "/library/syntax/parse-errors.factor" diff --git a/library/bootstrap/boot-stage2.factor b/library/bootstrap/boot-stage2.factor index 29dd809999..616a1cea25 100644 --- a/library/bootstrap/boot-stage2.factor +++ b/library/bootstrap/boot-stage2.factor @@ -48,6 +48,8 @@ t [ "/library/alien/c-types.factor" "/library/alien/compiler.factor" + "/library/alien/enums.factor" + "/library/alien/structs.factor" ] pull-in cpu "x86" = [ diff --git a/library/bootstrap/boot-stage3.factor b/library/bootstrap/boot-stage3.factor index 8deb6485f4..3197061766 100644 --- a/library/bootstrap/boot-stage3.factor +++ b/library/bootstrap/boot-stage3.factor @@ -1,10 +1,30 @@ ! Copyright (C) 2004, 2005 Slava Pestov. ! See http://factor.sf.net/license.txt for BSD license. -USING: assembler compiler kernel lists namespaces parser -sequences stdio unparser ; +USING: alien assembler compiler io-internals kernel lists +namespaces parser sequences stdio unparser words ; "Bootstrap stage 3..." print +os "unix" = [ + "libc" "libc.so" "cdecl" add-library +] when + +os "win32" = [ + "kernel32" "kernel32.dll" "stdcall" add-library + "user32" "user32.dll" "stdcall" add-library + "gdi32" "gdi32.dll" "stdcall" add-library + "winsock" "ws2_32.dll" "stdcall" add-library + "mswsock" "mswsock.dll" "stdcall" add-library + "libc" "msvcrt.dll" "cdecl" add-library + "sdl" "SDL.dll" "cdecl" add-library + "sdl-gfx" "SDL_gfx.dll" "cdecl" add-library + "sdl-ttf" "SDL_ttf.dll" "cdecl" add-library + ! FIXME: KLUDGE to get FFI-based IO going in Windows. + "/library/bootstrap/win32-io.factor" run-resource +] when + +"/library/io/buffer.factor" run-resource + "compile" get supported-cpu? and [ init-assembler \ car compile @@ -12,12 +32,28 @@ sequences stdio unparser ; \ length compile \ unparse compile \ scan compile + + [ + "imalloc" "ifree" "irealloc" "imemcpy" + ] [ + [ "io-internals" ] search compile + ] each + + os "unix" = [ + "/library/unix/syscalls.factor" + "/library/unix/io.factor" + "/library/unix/sockets.factor" + "/library/unix/files.factor" + ] pull-in + + os "unix" = [ + "unix-internals" words [ compile ] each + ] when + + init-io ] when t [ - "/library/alien/enums.factor" - "/library/alien/structs.factor" - "/library/math/constants.factor" "/library/math/pow.factor" "/library/math/trig-hyp.factor" @@ -27,8 +63,6 @@ t [ "/library/random.factor" "/library/io/directories.factor" - "/library/io/buffer.factor" -! "/library/io/logging.factor" "/library/io/stdio-binary.factor" "/library/eval-catch.factor" @@ -39,29 +73,34 @@ t [ "/library/syntax/see.factor" "/library/test/test.factor" "/library/inference/test.factor" -! "/library/tools/telnetd.factor" -! "/library/tools/jedit-wire.factor" "/library/tools/profiler.factor" "/library/tools/walker.factor" "/library/tools/annotations.factor" -! "/library/tools/jedit.factor" "/library/tools/dump.factor" "/library/bootstrap/image.factor" +] pull-in -! "/library/httpd/url-encoding.factor" -! "/library/httpd/mime.factor" -! "/library/httpd/html-tags.factor" -! "/library/httpd/html.factor" -! "/library/httpd/http-common.factor" -! "/library/httpd/responder.factor" -! "/library/httpd/httpd.factor" -! "/library/httpd/file-responder.factor" -! "/library/httpd/test-responder.factor" -! "/library/httpd/quit-responder.factor" -! "/library/httpd/resource-responder.factor" -! "/library/httpd/cont-responder.factor" -! "/library/httpd/browser-responder.factor" -! "/library/httpd/default-responders.factor" +"compile" get "mini" get not and [ + "/library/io/logging.factor" + + "/library/tools/telnetd.factor" + "/library/tools/jedit-wire.factor" + "/library/tools/jedit.factor" + + "/library/httpd/url-encoding.factor" + "/library/httpd/mime.factor" + "/library/httpd/html-tags.factor" + "/library/httpd/html.factor" + "/library/httpd/http-common.factor" + "/library/httpd/responder.factor" + "/library/httpd/httpd.factor" + "/library/httpd/file-responder.factor" + "/library/httpd/test-responder.factor" + "/library/httpd/quit-responder.factor" + "/library/httpd/resource-responder.factor" + "/library/httpd/cont-responder.factor" + "/library/httpd/browser-responder.factor" + "/library/httpd/default-responders.factor" "/library/sdl/sdl.factor" "/library/sdl/sdl-video.factor" @@ -115,10 +154,6 @@ os "win32" = [ "/library/win32/win32-server.factor" ] pull-in -os "unix" = [ - "/library/unix/syscalls.factor" -] pull-in - FORGET: pull-in "/library/bootstrap/boot-stage4.factor" dup print run-resource diff --git a/library/bootstrap/boot-stage4.factor b/library/bootstrap/boot-stage4.factor index cc0db3f16c..518d599fdf 100644 --- a/library/bootstrap/boot-stage4.factor +++ b/library/bootstrap/boot-stage4.factor @@ -33,24 +33,6 @@ words ; warm-boot -os "win32" = [ - "kernel32" "kernel32.dll" "stdcall" add-library - "user32" "user32.dll" "stdcall" add-library - "gdi32" "gdi32.dll" "stdcall" add-library - "winsock" "ws2_32.dll" "stdcall" add-library - "mswsock" "mswsock.dll" "stdcall" add-library - "libc" "msvcrt.dll" "cdecl" add-library - "sdl" "SDL.dll" "cdecl" add-library - "sdl-gfx" "SDL_gfx.dll" "cdecl" add-library - "sdl-ttf" "SDL_ttf.dll" "cdecl" add-library - ! FIXME: KLUDGE to get FFI-based IO going in Windows. - "/library/bootstrap/win32-io.factor" run-resource -] when - -os "unix" = [ - "libc" "libc.so" "cdecl" add-library -] when - "Compiling system..." print "compile" get [ compile-all ] when diff --git a/library/bootstrap/init.factor b/library/bootstrap/init.factor index 562425bad3..73ef36742e 100644 --- a/library/bootstrap/init.factor +++ b/library/bootstrap/init.factor @@ -7,7 +7,7 @@ USING: io-internals namespaces parser stdio threads words ; #! Initialize an interpreter with the basic services. global >n init-threads - init-c-io + init-io "HOME" os-env [ "." ] unless* "~" set init-search-path ; diff --git a/library/threads.factor b/library/threads.factor index b0c6cc37f9..74a8bbaa3a 100644 --- a/library/threads.factor +++ b/library/threads.factor @@ -27,8 +27,7 @@ namespaces ; next-thread [ call ] [ - "No more tasks" throw - ! next-io-task [ call ] [ stop ] ifte* + io-multiplex [ call ] [ stop ] ifte* ] ifte* ; : yield ( -- ) diff --git a/library/unix/io.factor b/library/unix/io.factor index 2b813b0a30..c4dfb0f9f2 100644 --- a/library/unix/io.factor +++ b/library/unix/io.factor @@ -182,7 +182,7 @@ M: read-line-task io-task-events ( task -- events ) drop ] [ [ - swap add-io-task io-multiplex + swap add-io-task stop ] callcc0 drop ] ifte ; @@ -228,7 +228,7 @@ M: read-task io-task-events ( task -- events ) 2drop ] [ [ - swap add-io-task io-multiplex + swap add-io-task stop ] callcc0 2drop ] ifte ; @@ -296,7 +296,7 @@ M: write-task io-task-events ( task -- events ) M: writer stream-flush ( stream -- ) [ - swap add-write-io-task io-multiplex + swap add-write-io-task stop ] callcc0 drop ; M: writer stream-auto-flush ( stream -- ) drop ; @@ -344,3 +344,7 @@ M: writer stream-close ( stream -- ) io-tasks set 0 1 t stdio set ] bind ; + +IN: streams + +: fcopy 2drop ;