From a100968f030fc1d67fa69c22f69045182c11974e Mon Sep 17 00:00:00 2001 From: Eduardo Cavazos Date: Wed, 19 Nov 2008 20:32:28 -0600 Subject: [PATCH 01/47] boids: another indentation fix --- extra/boids/boids.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/boids/boids.factor b/extra/boids/boids.factor index 3d4cd392ca..097b952db9 100644 --- a/extra/boids/boids.factor +++ b/extra/boids/boids.factor @@ -156,7 +156,7 @@ VAR: separation-radius 2&& ; : alignment-neighborhood ( self -- boids ) -boids> [ within-alignment-neighborhood? ] with filter ; + boids> [ within-alignment-neighborhood? ] with filter ; : alignment-force ( self -- force ) alignment-neighborhood From 825ad4e59de9bb6a2afea502850c9e7590bfb33f Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 19 Nov 2008 21:02:21 -0600 Subject: [PATCH 02/47] Remove unmaintained/io/ since basis/io/ now has all of the features from the old I/O library --- unmaintained/io/load.factor | 24 ------- unmaintained/io/os-unix-shell.factor | 46 ------------- unmaintained/io/os-unix.factor | 24 ------- unmaintained/io/os-winnt-shell.factor | 55 --------------- unmaintained/io/os-winnt.factor | 96 --------------------------- unmaintained/io/shell.factor | 40 ----------- unmaintained/io/test/io.factor | 42 ------------ unmaintained/io/test/mmap.factor | 21 ------ 8 files changed, 348 deletions(-) delete mode 100644 unmaintained/io/load.factor delete mode 100644 unmaintained/io/os-unix-shell.factor delete mode 100644 unmaintained/io/os-unix.factor delete mode 100644 unmaintained/io/os-winnt-shell.factor delete mode 100644 unmaintained/io/os-winnt.factor delete mode 100644 unmaintained/io/shell.factor delete mode 100644 unmaintained/io/test/io.factor delete mode 100644 unmaintained/io/test/mmap.factor diff --git a/unmaintained/io/load.factor b/unmaintained/io/load.factor deleted file mode 100644 index ac9b9542c5..0000000000 --- a/unmaintained/io/load.factor +++ /dev/null @@ -1,24 +0,0 @@ -USING: kernel ; - -REQUIRES: libs/calendar libs/shuffle ; - -PROVIDE: libs/io -{ +files+ { - "io.factor" - "mmap.factor" - "shell.factor" - { "os-unix.factor" [ unix? ] } - { "os-unix-shell.factor" [ unix? ] } - { "mmap-os-unix.factor" [ unix? ] } - - { "os-winnt.factor" [ winnt? ] } - { "os-winnt-shell.factor" [ winnt? ] } - { "mmap-os-winnt.factor" [ winnt? ] } - - { "os-wince.factor" [ wince? ] } -} } -{ +tests+ { - "test/io.factor" - "test/mmap.factor" -} } ; - diff --git a/unmaintained/io/os-unix-shell.factor b/unmaintained/io/os-unix-shell.factor deleted file mode 100644 index 6c3919ddb2..0000000000 --- a/unmaintained/io/os-unix-shell.factor +++ /dev/null @@ -1,46 +0,0 @@ -USING: arrays kernel libs-io sequences prettyprint unix-internals -calendar namespaces math ; -USE: io -IN: shell - -TUPLE: unix-shell ; - -T{ unix-shell } \ shell set-global - -TUPLE: file name mode nlink uid gid size mtime symbol ; - -M: unix-shell directory* ( path -- seq ) - dup (directory) [ tuck >r "/" r> 3append stat* 2array ] map-with ; - -M: unix-shell make-file ( path -- file ) - first2 - [ stat-mode ] keep - [ stat-nlink ] keep - [ stat-uid ] keep - [ stat-gid ] keep - [ stat-size ] keep - [ stat-mtime timespec>timestamp >local-time ] keep - stat-mode mode>symbol ; - -M: unix-shell file. ( file -- ) - [ [ file-mode >oct write ] keep ] with-cell - [ bl ] with-cell - [ [ file-nlink unparse write ] keep ] with-cell - [ bl ] with-cell - [ [ file-uid unparse write ] keep ] with-cell - [ bl ] with-cell - [ [ file-gid unparse write ] keep ] with-cell - [ bl ] with-cell - [ [ file-size unparse write ] keep ] with-cell - [ bl ] with-cell - [ [ file-mtime file-time-string write ] keep ] with-cell - [ bl ] with-cell - [ file-name write ] with-cell ; - -USE: unix-internals -M: unix-shell touch-file ( path -- ) - dup open-append dup -1 = [ - drop now dup set-file-times - ] [ - nip [ now dup set-file-times* ] keep close - ] if ; diff --git a/unmaintained/io/os-unix.factor b/unmaintained/io/os-unix.factor deleted file mode 100644 index 280908b406..0000000000 --- a/unmaintained/io/os-unix.factor +++ /dev/null @@ -1,24 +0,0 @@ -! Copyright (C) 2007 Doug Coleman. -! See http://factorcode.org/license.txt for BSD license. -USING: alien arrays calendar errors io io-internals kernel -math nonblocking-io sequences unix-internals unix-io ; -IN: libs-io - -: O_APPEND HEX: 100 ; inline -: O_EXCL HEX: 800 ; inline -: SEEK_SET 0 ; inline -: SEEK_CUR 1 ; inline -: SEEK_END 2 ; inline -: EEXIST 17 ; inline - -: mode>symbol ( mode -- ch ) - S_IFMT bitand - { - { [ dup S_IFDIR = ] [ drop "/" ] } - { [ dup S_IFIFO = ] [ drop "|" ] } - { [ dup S_IXUSR = ] [ drop "*" ] } - { [ dup S_IFLNK = ] [ drop "@" ] } - { [ dup S_IFWHT = ] [ drop "%" ] } - { [ dup S_IFSOCK = ] [ drop "=" ] } - { [ t ] [ drop "" ] } - } cond ; diff --git a/unmaintained/io/os-winnt-shell.factor b/unmaintained/io/os-winnt-shell.factor deleted file mode 100644 index a2be22daf8..0000000000 --- a/unmaintained/io/os-winnt-shell.factor +++ /dev/null @@ -1,55 +0,0 @@ -USING: alien calendar io io-internals kernel libs-io math -namespaces prettyprint sequences windows-api ; -IN: shell - -TUPLE: winnt-shell ; - -T{ winnt-shell } \ shell set-global - -TUPLE: file name size mtime attributes ; - -: ((directory*)) ( handle -- ) - "WIN32_FIND_DATA" [ FindNextFile ] 2keep - rot zero? [ 2drop ] [ , ((directory*)) ] if ; - -: (directory*) ( path -- ) - "WIN32_FIND_DATA" [ - FindFirstFile dup INVALID_HANDLE_VALUE = [ - win32-error - ] when - ] keep , - [ ((directory*)) ] keep FindClose win32-error=0/f ; - -: append-star ( path -- path ) - dup peek CHAR: \\ = "*" "\\*" ? append ; - -M: winnt-shell directory* ( path -- seq ) - normalize-pathname append-star [ (directory*) ] { } make ; - -: WIN32_FIND_DATA>file-size ( WIN32_FILE_ATTRIBUTE_DATA -- n ) - [ WIN32_FIND_DATA-nFileSizeLow ] keep - WIN32_FIND_DATA-nFileSizeHigh 32 shift + ; - -M: winnt-shell make-file ( WIN32_FIND_DATA -- file ) - [ WIN32_FIND_DATA-cFileName alien>u16-string ] keep - [ WIN32_FIND_DATA>file-size ] keep - [ - WIN32_FIND_DATA-ftCreationTime - FILETIME>timestamp >local-time - ] keep - WIN32_FIND_DATA-dwFileAttributes ; - -M: winnt-shell file. ( file -- ) - [ [ file-attributes >oct write ] keep ] with-cell - [ bl ] with-cell - [ [ file-size unparse write ] keep ] with-cell - [ bl ] with-cell - [ [ file-mtime file-time-string write ] keep ] with-cell - [ bl ] with-cell - [ file-name write ] with-cell ; - -M: winnt-shell touch-file ( path -- ) - #! Set the file write time to 'now' - normalize-pathname - dup maybe-create-file [ drop ] [ now set-file-write-time ] if ; - diff --git a/unmaintained/io/os-winnt.factor b/unmaintained/io/os-winnt.factor deleted file mode 100644 index 971ae79097..0000000000 --- a/unmaintained/io/os-winnt.factor +++ /dev/null @@ -1,96 +0,0 @@ -USING: alien calendar errors generic io io-internals kernel -math namespaces nonblocking-io parser quotations sequences -shuffle windows-api words ; -IN: libs-io - -: stat* ( path -- WIN32_FIND_DATA ) - "WIN32_FIND_DATA" - [ - FindFirstFile - [ INVALID_HANDLE_VALUE = [ win32-error ] when ] keep - FindClose win32-error=0/f - ] keep ; - -: set-file-time ( path timestamp/f timestamp/f timestamp/f -- ) - #! timestamp order: creation access write - >r >r >r open-existing dup r> r> r> - [ timestamp>FILETIME ] 3 napply - SetFileTime win32-error=0/f - close-handle ; - -: set-file-times ( path timestamp/f timestamp/f -- ) - f -rot set-file-time ; - -: set-file-create-time ( path timestamp -- ) - f f set-file-time ; - -: set-file-access-time ( path timestamp -- ) - >r f r> f set-file-time ; - -: set-file-write-time ( path timestamp -- ) - >r f f r> set-file-time ; - -: maybe-make-filetime ( ? -- FILETIME/f ) - [ "FILETIME" ] [ f ] if ; - -: file-time ( path ? ? ? -- FILETIME/f FILETIME/f FILETIME/f ) - >r >r >r open-existing dup r> r> r> - [ maybe-make-filetime ] 3 napply - [ GetFileTime win32-error=0/f close-handle ] 3keep ; - -: file-times ( path -- FILETIME FILETIME FILETIME ) - t t t file-time [ FILETIME>timestamp ] 3 napply ; - -: file-create-time ( path -- FILETIME ) - t f f file-time 2drop FILETIME>timestamp ; - -: file-access-time ( path -- FILETIME ) - f t f file-time drop nip FILETIME>timestamp ; - -: file-write-time ( path -- FILETIME ) - f f t file-time 2nip FILETIME>timestamp ; - -: attrib ( path -- n ) - [ stat* WIN32_FIND_DATA-dwFileAttributes ] catch - [ drop 0 ] when ; - -: (read-only?) ( mode -- ? ) - FILE_ATTRIBUTE_READONLY bit-set? ; - -: read-only? ( path -- ? ) - attrib (read-only?) ; - -: (hidden?) ( mode -- ? ) - FILE_ATTRIBUTE_HIDDEN bit-set? ; - -: hidden? ( path -- ? ) - attrib (hidden?) ; - -: (system?) ( mode -- ? ) - FILE_ATTRIBUTE_SYSTEM bit-set? ; - -: system? ( path -- ? ) - attrib (system?) ; - -: (directory?) ( mode -- ? ) - FILE_ATTRIBUTE_DIRECTORY bit-set? ; - -: directory? ( path -- ? ) - attrib (directory?) ; - -: (archive?) ( mode -- ? ) - FILE_ATTRIBUTE_ARCHIVE bit-set? ; - -: archive? ( path -- ? ) - attrib (archive?) ; - -! FILE_ATTRIBUTE_DEVICE -! FILE_ATTRIBUTE_NORMAL -! FILE_ATTRIBUTE_TEMPORARY -! FILE_ATTRIBUTE_SPARSE_FILE -! FILE_ATTRIBUTE_REPARSE_POINT -! FILE_ATTRIBUTE_COMPRESSED -! FILE_ATTRIBUTE_OFFLINE -! FILE_ATTRIBUTE_NOT_CONTENT_INDEXED -! FILE_ATTRIBUTE_ENCRYPTED - diff --git a/unmaintained/io/shell.factor b/unmaintained/io/shell.factor deleted file mode 100644 index 5213eb22c7..0000000000 --- a/unmaintained/io/shell.factor +++ /dev/null @@ -1,40 +0,0 @@ -USING: calendar io io-internals kernel math namespaces -nonblocking-io prettyprint quotations sequences ; -IN: shell - -SYMBOL: shell -HOOK: directory* shell ( path -- seq ) -HOOK: make-file shell ( bytes -- file ) -HOOK: file. shell ( file -- ) -HOOK: touch-file shell ( path -- ) - -: (ls) ( path -- ) - >r H{ } r> directory* - [ - [ [ make-file file. ] with-row ] each - ] curry tabular-output ; - -: ls ( -- ) - cwd (ls) ; - -: pwd ( -- ) - cwd pprint nl ; - -: (slurp) ( quot -- ) - >r default-buffer-size read r> over [ - dup slip (slurp) - ] [ - 2drop - ] if ; - -: slurp ( stream quot -- ) - [ (slurp) ] curry with-stream ; - -: cat ( path -- ) - stdio get - duplex-stream-out - [ write ] slurp ; - -: copy-file ( path path -- ) - >r r> - [ write ] slurp ; diff --git a/unmaintained/io/test/io.factor b/unmaintained/io/test/io.factor deleted file mode 100644 index 379e1233f0..0000000000 --- a/unmaintained/io/test/io.factor +++ /dev/null @@ -1,42 +0,0 @@ -USING: calendar errors io kernel libs-io math namespaces sequences -shell test ; -IN: temporary - -SYMBOL: file "file-appender-test.txt" \ file set -[ \ file get delete-file ] catch drop -[ f ] [ \ file get exists? ] unit-test -\ file get [ "asdf" write ] with-stream -[ t ] [ \ file get exists? ] unit-test -[ 4 ] [ \ file get file-length ] unit-test -\ file get [ "jkl;" write ] with-stream -[ t ] [ \ file get exists? ] unit-test -[ 8 ] [ \ file get file-length ] unit-test -[ "asdfjkl;" ] [ \ file get contents ] unit-test -\ file get delete-file -[ f ] [ \ file get exists? ] unit-test - -SYMBOL: directory "test-directory" \ directory set -\ directory get create-directory -[ t ] [ \ directory get directory? ] unit-test -\ directory get delete-directory -[ f ] [ \ directory get directory? ] unit-test - -SYMBOL: time "time-test.txt" \ time set -[ \ time get delete-file ] catch drop -\ time get touch-file -[ 0 ] [ \ time get file-length ] unit-test -[ t ] [ \ time get exists? ] unit-test -\ time get 0 unix-time>timestamp dup set-file-times -[ t ] [ \ time get file-write-time 0 unix-time>timestamp = ] unit-test -[ t ] [ \ time get file-access-time 0 unix-time>timestamp = ] unit-test -\ time get touch-file -[ t ] [ now \ time get file-write-time timestamp- 10 < ] unit-test -\ time get delete-file - -SYMBOL: longname "" 255 CHAR: a pad-left \ longname set -\ longname get touch-file -[ t ] [ \ longname get exists? ] unit-test -[ 0 ] [ \ longname get file-length ] unit-test -\ longname get delete-file -[ f ] [ \ longname get exists? ] unit-test - diff --git a/unmaintained/io/test/mmap.factor b/unmaintained/io/test/mmap.factor deleted file mode 100644 index faeca551c0..0000000000 --- a/unmaintained/io/test/mmap.factor +++ /dev/null @@ -1,21 +0,0 @@ -USING: alien errors io kernel libs-io mmap namespaces test ; - -IN: temporary -SYMBOL: mmap "mmap-test.txt" \ mmap set - -[ \ mmap get delete-file ] catch drop -\ mmap get [ - "Four" write -] with-file-writer - -\ mmap get [ - >r CHAR: R r> mmap-address 3 set-alien-unsigned-1 -] with-mmap - -\ mmap get [ - mmap-address 3 alien-unsigned-1 CHAR: R = [ - "mmap test failed" throw - ] unless -] with-mmap - -[ \ mmap get delete-file ] catch drop From 8f0b335f4b7c3acbbd3240231ceef6bd415626d7 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 19 Nov 2008 21:13:50 -0600 Subject: [PATCH 03/47] Clean up --- basis/ui/gadgets/frames/frames.factor | 29 +++++++++++++-------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/basis/ui/gadgets/frames/frames.factor b/basis/ui/gadgets/frames/frames.factor index c210d1b7e2..2005fefed7 100644 --- a/basis/ui/gadgets/frames/frames.factor +++ b/basis/ui/gadgets/frames/frames.factor @@ -11,16 +11,16 @@ TUPLE: frame < grid ; : ( -- grid ) 9 [ ] replicate 3 group ; -: @center 1 1 ; -: @left 0 1 ; -: @right 2 1 ; -: @top 1 0 ; -: @bottom 1 2 ; +: @center 1 1 ; inline +: @left 0 1 ; inline +: @right 2 1 ; inline +: @top 1 0 ; inline +: @bottom 1 2 ; inline -: @top-left 0 0 ; -: @top-right 2 0 ; -: @bottom-left 0 2 ; -: @bottom-right 2 2 ; +: @top-left 0 0 ; inline +: @top-right 2 0 ; inline +: @bottom-left 0 2 ; inline +: @bottom-right 2 2 ; inline : new-frame ( class -- frame ) swap new-grid ; inline @@ -28,13 +28,12 @@ TUPLE: frame < grid ; : ( -- frame ) frame new-frame ; -: (fill-center) ( vec n -- ) - over first pick third v+ [v-] 1 rot set-nth ; +: (fill-center) ( n vec -- ) + [ [ first ] [ third ] bi v+ [v-] ] keep set-second ; -: fill-center ( horiz vert dim -- ) - tuck (fill-center) (fill-center) ; +: fill-center ( dim horiz vert -- ) + [ over ] dip [ (fill-center) ] 2bi@ ; M: frame layout* dup compute-grid - [ rot rect-dim fill-center ] 3keep - grid-layout ; + [ [ rect-dim ] 2dip fill-center ] [ grid-layout ] 3bi ; From 5a99526598d7df109c76b5bca5b50cf1bd0593e6 Mon Sep 17 00:00:00 2001 From: Eduardo Cavazos Date: Wed, 19 Nov 2008 21:15:29 -0600 Subject: [PATCH 04/47] boids: adjust 'USING:' line --- extra/boids/boids.factor | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extra/boids/boids.factor b/extra/boids/boids.factor index 097b952db9..eeebe1c12d 100644 --- a/extra/boids/boids.factor +++ b/extra/boids/boids.factor @@ -1,5 +1,5 @@ -USING: combinators.short-circuit kernel namespaces +USING: kernel namespaces math math.constants math.functions @@ -10,6 +10,7 @@ USING: combinators.short-circuit kernel namespaces math.physics.vel combinators arrays sequences random vars combinators.lib + combinators.short-circuit accessors ; IN: boids From bcd2ffc830fa5d35b39872462fe52cc7d8e00cbb Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 19 Nov 2008 21:57:59 -0600 Subject: [PATCH 05/47] If rendering an error popup fails, don't open an endless stream --- basis/ui/gadgets/worlds/worlds.factor | 4 ++-- basis/ui/tools/debugger/debugger.factor | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/basis/ui/gadgets/worlds/worlds.factor b/basis/ui/gadgets/worlds/worlds.factor index 6f901c37ee..e338d6d4f4 100644 --- a/basis/ui/gadgets/worlds/worlds.factor +++ b/basis/ui/gadgets/worlds/worlds.factor @@ -30,7 +30,7 @@ ERROR: no-world-found ; : (request-focus) ( child world ? -- ) pick parent>> pick eq? [ - >r >r dup parent>> dup r> r> + [ dup parent>> dup ] 2dip [ (request-focus) ] keep ] unless focus-child ; @@ -80,7 +80,7 @@ SYMBOL: ui-error-hook : ui-error ( error -- ) ui-error-hook get [ call ] [ print-error ] if* ; -[ rethrow ] ui-error-hook set-global +ui-error-hook global [ [ rethrow ] or ] change-at : draw-world ( world -- ) dup draw-world? [ diff --git a/basis/ui/tools/debugger/debugger.factor b/basis/ui/tools/debugger/debugger.factor index 4ba4374bb8..1f019fca7c 100644 --- a/basis/ui/tools/debugger/debugger.factor +++ b/basis/ui/tools/debugger/debugger.factor @@ -35,7 +35,15 @@ M: debugger focusable-child* restarts>> ; #! No restarts for the debugger window f [ drop ] "Error" open-window ; -[ debugger-window ] ui-error-hook set-global +GENERIC: error-in-debugger? ( error -- ? ) + +M: world-error error-in-debugger? world>> gadget-child debugger? ; + +M: object error-in-debugger? drop f ; + +[ + dup error-in-debugger? [ rethrow ] [ debugger-window ] if +] ui-error-hook set-global M: world-error error. "An error occurred while drawing the world " write From 4af2592369d2ddeb41436398b84be36e45a09a6f Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 19 Nov 2008 21:58:45 -0600 Subject: [PATCH 06/47] Fix some scrollers problems --- .../gadgets/scrollers/scrollers-tests.factor | 23 ++++++- basis/ui/gadgets/scrollers/scrollers.factor | 62 ++++++++++--------- 2 files changed, 53 insertions(+), 32 deletions(-) diff --git a/basis/ui/gadgets/scrollers/scrollers-tests.factor b/basis/ui/gadgets/scrollers/scrollers-tests.factor index 625bfd7880..d6792abd49 100644 --- a/basis/ui/gadgets/scrollers/scrollers-tests.factor +++ b/basis/ui/gadgets/scrollers/scrollers-tests.factor @@ -2,7 +2,8 @@ USING: ui.gadgets ui.gadgets.scrollers namespaces tools.test kernel models models.compose models.range ui.gadgets.viewports ui.gadgets.labels ui.gadgets.grids ui.gadgets.frames ui.gadgets.sliders math math.vectors arrays sequences -tools.test.ui math.geometry.rect accessors ; +tools.test.ui math.geometry.rect accessors ui.gadgets.buttons +ui.gadgets.packs ; IN: ui.gadgets.scrollers.tests [ ] [ @@ -74,7 +75,7 @@ dup layout "g2" get scroll>gadget "s" get layout "s" get scroller-value - ] map [ { 3 0 } = ] all? + ] map [ { 2 0 } = ] all? ] unit-test [ ] [ "Hi"