From 34dcd283625886996938d6234f9e966196ca65dc Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 10 Jun 2009 09:45:48 -0500 Subject: [PATCH 1/5] add an iota --- basis/compiler/tree/dead-code/branches/branches.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basis/compiler/tree/dead-code/branches/branches.factor b/basis/compiler/tree/dead-code/branches/branches.factor index fd1b2d5adb..f027ccdb61 100644 --- a/basis/compiler/tree/dead-code/branches/branches.factor +++ b/basis/compiler/tree/dead-code/branches/branches.factor @@ -32,7 +32,7 @@ M: #branch remove-dead-code* pad-with-bottom >>phi-in-d drop ; : live-value-indices ( values -- indices ) - [ length ] keep live-values get + [ length iota ] keep live-values get '[ _ nth _ key? ] filter ; inline : drop-indexed-values ( values indices -- node ) From 0c7671931270683d1f6081b8ea2fba47f9e835b6 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Wed, 2 Sep 2009 12:06:38 +0200 Subject: [PATCH 2/5] Make "divisors" work with 1 as well --- basis/math/primes/factors/factors-tests.factor | 1 + basis/math/primes/factors/factors.factor | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/basis/math/primes/factors/factors-tests.factor b/basis/math/primes/factors/factors-tests.factor index eea59b6f9b..02610e941e 100644 --- a/basis/math/primes/factors/factors-tests.factor +++ b/basis/math/primes/factors/factors-tests.factor @@ -10,3 +10,4 @@ USING: math.primes.factors sequences tools.test ; { { 13 4253 15823 32472893749823741 } } [ 28408516453955558205925627 factors ] unit-test { { 1 2 3 4 6 8 12 24 } } [ 24 divisors ] unit-test { 24 } [ 360 divisors length ] unit-test +{ { 1 } } [ 1 divisors ] unit-test diff --git a/basis/math/primes/factors/factors.factor b/basis/math/primes/factors/factors.factor index da1c36196b..c71fa18ab2 100644 --- a/basis/math/primes/factors/factors.factor +++ b/basis/math/primes/factors/factors.factor @@ -43,5 +43,9 @@ PRIVATE> } cond ; foldable : divisors ( n -- seq ) - group-factors [ first2 [0,b] [ ^ ] with map ] map - [ product ] product-map natural-sort ; + dup 1 = [ + 1array + ] [ + group-factors [ first2 [0,b] [ ^ ] with map ] map + [ product ] product-map natural-sort + ] if ; From 9a7a76b978b6cd85efc61a5af5a539b398f2a4b6 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Tue, 8 Sep 2009 13:13:30 -0500 Subject: [PATCH 3/5] Improved line number handling for unit test failure errors --- basis/tools/test/test.factor | 2 +- basis/ui/tools/error-list/error-list.factor | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/basis/tools/test/test.factor b/basis/tools/test/test.factor index 42721bada1..2692c5a8b6 100644 --- a/basis/tools/test/test.factor +++ b/basis/tools/test/test.factor @@ -45,7 +45,7 @@ T{ error-type SYMBOL: file : file-failure ( error -- ) - f file get f failure ; + [ f file get ] keep error-line failure ; :: (unit-test) ( output input -- error ? ) [ { } input with-datastack output assert-sequence= f f ] [ t ] recover ; diff --git a/basis/ui/tools/error-list/error-list.factor b/basis/ui/tools/error-list/error-list.factor index a1da59fe39..34a5221307 100644 --- a/basis/ui/tools/error-list/error-list.factor +++ b/basis/ui/tools/error-list/error-list.factor @@ -97,7 +97,7 @@ M: error-renderer column-titles M: error-renderer column-alignment drop { 0 1 0 0 } ; : sort-errors ( seq -- seq' ) - [ [ [ line#>> ] [ asset>> unparse-short ] bi 2array ] keep ] { } map>assoc + [ [ [ line#>> 0 or ] [ asset>> unparse-short ] bi 2array ] keep ] { } map>assoc sort-keys values ; : file-matches? ( error pathname/f -- ? ) From 1e9f870e6605719aea533ed2a09025adaa7ad715 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Tue, 8 Sep 2009 13:37:25 -0500 Subject: [PATCH 4/5] math.vectors.specialization: specialized vector words are now subwords of the generic vector word. This ensures that specializations get compiled correctly in all cases --- .../vectors/specialization/specialization.factor | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/basis/math/vectors/specialization/specialization.factor b/basis/math/vectors/specialization/specialization.factor index c9db3e02b3..a31a209a19 100644 --- a/basis/math/vectors/specialization/specialization.factor +++ b/basis/math/vectors/specialization/specialization.factor @@ -69,12 +69,16 @@ H{ { vtruncate { +vector+ -> +vector+ } } } -SYMBOL: specializations +PREDICATE: vector-word < word vector-words key? ; -specializations [ vector-words keys [ V{ } clone ] H{ } map>assoc ] initialize +: specializations ( word -- assoc ) + dup "specializations" word-prop + [ ] [ V{ } clone [ "specializations" set-word-prop ] keep ] ?if ; + +M: vector-word subwords specializations values ; : add-specialization ( new-word signature word -- ) - specializations get at set-at ; + specializations set-at ; : word-schema ( word -- schema ) vector-words at ; @@ -98,7 +102,7 @@ specializations [ vector-words keys [ V{ } clone ] H{ } map>assoc ] initialize ] each ; : find-specialization ( classes word -- word/f ) - specializations get at + specializations [ first [ class<= ] 2all? ] with find swap [ second ] when ; From f64ebbfc86cb877781dd53fcdabe3f3614b3a24e Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Tue, 8 Sep 2009 14:15:25 -0500 Subject: [PATCH 5/5] remove deprecated inotify-event struct --- basis/io/monitors/linux/linux.factor | 18 +++++++++--------- basis/unix/linux/inotify/inotify.factor | 19 +++++++++---------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/basis/io/monitors/linux/linux.factor b/basis/io/monitors/linux/linux.factor index 9b3688d023..3e1e919217 100644 --- a/basis/io/monitors/linux/linux.factor +++ b/basis/io/monitors/linux/linux.factor @@ -5,7 +5,7 @@ io.files io.pathnames io.buffers io.ports io.timeouts io.backend.unix io.encodings.utf8 unix.linux.inotify assocs namespaces make threads continuations init math math.bitwise sets alien alien.strings alien.c-types vocabs.loader accessors -system hashtables destructors unix ; +system hashtables destructors unix classes.struct ; IN: io.monitors.linux SYMBOL: watches @@ -82,30 +82,30 @@ M: linux-monitor dispose* ( monitor -- ) ] { } make prune ; : parse-event-name ( event -- name ) - dup inotify-event-len zero? - [ drop "" ] [ inotify-event-name utf8 alien>string ] if ; + dup len>> zero? + [ drop "" ] [ name>> utf8 alien>string ] if ; : parse-file-notify ( buffer -- path changed ) - dup inotify-event-mask ignore-flags? [ + dup mask>> ignore-flags? [ drop f f ] [ - [ parse-event-name ] [ inotify-event-mask parse-action ] bi + [ parse-event-name ] [ mask>> parse-action ] bi ] if ; : events-exhausted? ( i buffer -- ? ) fill>> >= ; -: inotify-event@ ( i buffer -- alien ) - ptr>> ; +: inotify-event@ ( i buffer -- inotify-event ) + ptr>> inotify-event memory>struct ; : next-event ( i buffer -- i buffer ) 2dup inotify-event@ - inotify-event-len "inotify-event" heap-size + + len>> inotify-event heap-size + swap [ + ] dip ; : parse-file-notifications ( i buffer -- ) 2dup events-exhausted? [ 2drop ] [ - 2dup inotify-event@ dup inotify-event-wd wd>monitor + 2dup inotify-event@ dup wd>> wd>monitor [ parse-file-notify ] dip queue-change next-event parse-file-notifications ] if ; diff --git a/basis/unix/linux/inotify/inotify.factor b/basis/unix/linux/inotify/inotify.factor index e3d40b5b28..5f9bf5d462 100644 --- a/basis/unix/linux/inotify/inotify.factor +++ b/basis/unix/linux/inotify/inotify.factor @@ -1,15 +1,14 @@ ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: alien.syntax math math.bitwise ; +USING: alien.syntax math math.bitwise classes.struct ; IN: unix.linux.inotify -C-STRUCT: inotify-event - { "int" "wd" } ! watch descriptor - { "uint" "mask" } ! watch mask - { "uint" "cookie" } ! cookie to synchronize two events - { "uint" "len" } ! length (including nulls) of name - { "char[0]" "name" } ! stub for possible name - ; +STRUCT: inotify-event + { wd int } + { mask uint } + { cookie uint } + { len uint } + { name char[0] } ; CONSTANT: IN_ACCESS HEX: 1 ! File was accessed CONSTANT: IN_MODIFY HEX: 2 ! File was modified @@ -28,8 +27,8 @@ CONSTANT: IN_UNMOUNT HEX: 2000 ! Backing fs was unmounted CONSTANT: IN_Q_OVERFLOW HEX: 4000 ! Event queued overflowed CONSTANT: IN_IGNORED HEX: 8000 ! File was ignored -: IN_CLOSE ( -- n ) IN_CLOSE_WRITE IN_CLOSE_NOWRITE bitor ; inline ! close -: IN_MOVE ( -- n ) IN_MOVED_FROM IN_MOVED_TO bitor ; inline ! moves +: IN_CLOSE ( -- n ) { IN_CLOSE_WRITE IN_CLOSE_NOWRITE } flags ; foldable ! close +: IN_MOVE ( -- n ) { IN_MOVED_FROM IN_MOVED_TO } flags ; foldable ! moves CONSTANT: IN_ONLYDIR HEX: 1000000 ! only watch the path if it is a directory CONSTANT: IN_DONT_FOLLOW HEX: 2000000 ! don't follow a sym link