diff --git a/basis/models/search/search.factor b/basis/models/search/search.factor index 41d9b5769e..62e4db38ac 100644 --- a/basis/models/search/search.factor +++ b/basis/models/search/search.factor @@ -1,9 +1,8 @@ ! Copyright (C) 2008 Slava Pestov ! See http://factorcode.org/license.txt for BSD license. -USING: arrays calendar fry kernel models.compose models.delay -models.filter sequences ; +USING: arrays fry kernel models.compose models.filter sequences ; IN: models.search -: ( values search quot -- model ) - [ 500 milliseconds 2array ] dip - '[ first2 @ ] ; \ No newline at end of file +: ( values search quot -- model ) + [ 2array ] dip + '[ first2 _ curry filter ] ; \ No newline at end of file diff --git a/basis/models/sort/sort.factor b/basis/models/sort/sort.factor new file mode 100644 index 0000000000..cbced931c3 --- /dev/null +++ b/basis/models/sort/sort.factor @@ -0,0 +1,8 @@ +! Copyright (C) 2008 Slava Pestov +! See http://factorcode.org/license.txt for BSD license. +USING: arrays fry kernel models.compose models.filter +sequences sorting ; +IN: models.sort + +: ( values sort -- model ) + 2array [ first2 sort ] ; \ No newline at end of file diff --git a/basis/tools/profiler/profiler.factor b/basis/tools/profiler/profiler.factor index 8391536374..8ddeb3897f 100644 --- a/basis/tools/profiler/profiler.factor +++ b/basis/tools/profiler/profiler.factor @@ -3,45 +3,26 @@ USING: accessors words sequences math prettyprint kernel arrays io io.styles namespaces assocs kernel.private strings combinators sorting math.parser vocabs definitions tools.profiler.private -continuations generic compiler.units sets ; +continuations generic compiler.units sets classes ; IN: tools.profiler : profile ( quot -- ) [ t profiling call ] [ f profiling ] [ ] cleanup ; -: counters ( words -- assoc ) - [ dup counter>> ] { } map>assoc ; +: counters ( words -- alist ) + [ dup counter>> ] { } map>assoc [ second 0 > ] filter ; -GENERIC: (profile.) ( obj -- ) - -TUPLE: usage-profile word ; - -C: usage-profile - -M: word (profile.) - [ name>> "( no name )" or ] [ ] bi write-object ; - -TUPLE: vocab-profile vocab ; - -C: vocab-profile - -M: string (profile.) - dup write-object ; - -M: method-body (profile.) - [ synopsis ] [ "method-generic" word-prop ] bi - write-object ; - -: counter. ( obj n -- ) - [ - [ [ (profile.) ] with-cell ] dip - [ number>string write ] with-cell - ] with-row ; +: vocab-counters ( -- alist ) + vocabs [ + dup + words + [ predicate? not ] filter + [ counter>> ] sigma + ] { } map>assoc ; : counters. ( assoc -- ) - [ second 0 > ] filter sort-values standard-table-style [ - [ counter. ] assoc-each + sort-values simple-table. ] tabular-output ; : profile. ( -- ) @@ -65,11 +46,7 @@ M: method-body (profile.) : vocabs-profile. ( -- ) "Call counts for all vocabularies:" print - vocabs [ - dup words - [ "predicating" word-prop not ] filter - [ counter>> ] map sum - ] { } map>assoc counters. ; + vocab-counters counters. ; : method-profile. ( -- ) all-words [ subwords ] map concat diff --git a/basis/ui/gadgets/buttons/buttons.factor b/basis/ui/gadgets/buttons/buttons.factor index 75469671ef..f237a427a2 100644 --- a/basis/ui/gadgets/buttons/buttons.factor +++ b/basis/ui/gadgets/buttons/buttons.factor @@ -197,12 +197,11 @@ M: radio-paint draw-boundary GL_LINE_STRIP 0 circle-steps 1+ glDrawArrays ; :: radio-knob-theme ( gadget -- gadget ) - [let | radio-paint [ black ] | - gadget - f f radio-paint radio-paint >>interior - radio-paint >>boundary - { 16 16 } >>dim - ] ; + black :> radio-paint + gadget + f f radio-paint radio-paint >>interior + radio-paint >>boundary + { 16 16 } >>dim ; : ( -- gadget ) radio-knob-theme ; @@ -221,8 +220,8 @@ M: radio-control model-changed over value>> = >>selected? relayout-1 ; -: ( assoc model parent quot: ( value model label -- ) -- parent ) - '[ _ swap _ call add-gadget ] assoc-each ; inline +: ( assoc model parent quot: ( value model label -- gadget ) -- parent ) + '[ _ swap @ add-gadget ] assoc-each ; inline : radio-button-theme ( gadget -- gadget ) { 5 5 } >>gap diff --git a/basis/ui/gadgets/panes/panes-tests.factor b/basis/ui/gadgets/panes/panes-tests.factor index 8627f7fbfe..1c51237035 100644 --- a/basis/ui/gadgets/panes/panes-tests.factor +++ b/basis/ui/gadgets/panes/panes-tests.factor @@ -2,7 +2,7 @@ USING: alien ui.gadgets.panes ui.gadgets namespaces kernel sequences io io.styles io.streams.string tools.test prettyprint definitions help help.syntax help.markup help.stylesheet splitting tools.test.ui models math summary -inspector accessors ; +inspector accessors help.topics ; IN: ui.gadgets.panes.tests : #children "pane" get children>> length ; @@ -79,6 +79,14 @@ IN: ui.gadgets.panes.tests ] test-gadget-text ] unit-test +[ t ] [ + [ + last-element off + \ = >link $title + "Hello world" print-content + ] test-gadget-text +] unit-test + ARTICLE: "test-article-1" "This is a test article" "Hello world, how are you today." ; diff --git a/basis/ui/gadgets/search-tables/search-tables.factor b/basis/ui/gadgets/search-tables/search-tables.factor index 6110657542..508d01dc12 100644 --- a/basis/ui/gadgets/search-tables/search-tables.factor +++ b/basis/ui/gadgets/search-tables/search-tables.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2008 Slava Pestov ! See http://factorcode.org/license.txt for BSD license. USING: accessors kernel delegate fry sequences -models models.search locals +models models.search models.delay calendar locals ui.gadgets.editors ui.gadgets.labels ui.gadgets.scrollers ui.gadgets.tables ui.gadgets.tracks ui.gadgets.borders ui.gadgets.buttons ; @@ -38,7 +38,7 @@ CONSULT: table-protocol search-table table>> ; values >>model search >>field dup field>> 2 f track-add - values search quot >>table + values search 500 milliseconds quot
>>table dup table>> 1 track-add ; M: search-table model-changed diff --git a/basis/ui/gadgets/tables/tables.factor b/basis/ui/gadgets/tables/tables.factor index b83b8e26bc..5c24767240 100644 --- a/basis/ui/gadgets/tables/tables.factor +++ b/basis/ui/gadgets/tables/tables.factor @@ -41,7 +41,7 @@ CONSTANT: table-gap 5 : column-widths ( font rows -- total widths ) [ drop 0 { } ] [ - tuck [ length 0 ] 2dip [ + tuck [ first length 0 ] 2dip [ [ string-width ] with map vmax ] with each 0 [ table-gap + + ] accumulate diff --git a/basis/ui/tools/operations/operations.factor b/basis/ui/tools/operations/operations.factor index a9405424dc..6f83a43a66 100644 --- a/basis/ui/tools/operations/operations.factor +++ b/basis/ui/tools/operations/operations.factor @@ -167,20 +167,13 @@ M: word com-stack-effect def>> com-stack-effect ; { +listener+ t } } define-operation -: com-show-profile ( workspace -- ) - profiler-gadget call-tool ; - -: com-profile ( quot -- ) profile f com-show-profile ; +: com-profile ( quot -- ) profile f profiler-window ; [ quotation? ] \ com-profile H{ { +keyboard+ T{ key-down f { C+ } "r" } } { +listener+ t } } define-operation -! Profiler presentations -[ dup usage-profile? swap vocab-profile? or ] -\ com-show-profile H{ { +primary+ t } } define-operation - ! Operations -> commands source-editor "word" diff --git a/basis/ui/tools/profiler/profiler.factor b/basis/ui/tools/profiler/profiler.factor index 7280efe885..b2d14e10bf 100644 --- a/basis/ui/tools/profiler/profiler.factor +++ b/basis/ui/tools/profiler/profiler.factor @@ -1,51 +1,83 @@ -! Copyright (C) 2007 Slava Pestov. +! Copyright (C) 2007, 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: ui.tools.workspace kernel quotations tools.profiler -ui.commands ui.gadgets ui.gadgets.panes ui.gadgets.scrollers -ui.gadgets.tracks ui.gestures ui.gadgets.buttons accessors fry ; +USING: ui.tools.workspace kernel quotations accessors fry +assocs present math math.order math.vectors arrays +models.search models.sort models sequences vocabs +tools.profiler ui ui.commands ui.gadgets ui.gadgets.panes +ui.gadgets.scrollers ui.gadgets.tracks ui.gestures +ui.gadgets.buttons ui.gadgets.tables ui.gadgets.search-tables +ui.gadgets.labelled ui.gadgets.buttons ui.gadgets.packs +ui.gadgets.labels ; +FROM: models.filter => ; +FROM: models.compose => ; IN: ui.tools.profiler -TUPLE: profiler-gadget < track pane ; +TUPLE: profiler-gadget < track sort vocabs vocab words ; -: ( -- gadget ) +SINGLETON: profile-renderer + +! Value is a { word count } pair +M: profile-renderer row-columns + drop [ [ present ] map ] [ { "All" "" } ] if* ; + +: ( values profiler -- model ) + [ [ [ second 0 > ] filter ] ] [ sort>> ] bi* ; + +: ( profiler -- model ) + [ + [ words>> ] [ vocab>> ] bi + [ [ [ first vocabulary>> ] [ first ] bi* = ] when* ] + ] keep ; + +: ( model -- table ) + [ swap dup [ first present subseq? ] [ 2drop t ] if ] + profile-renderer >>renderer ; + +: ( profiler -- model ) + [ vocab-counters ] dip + [ f prefix ] ; + +: sort-options ( -- alist ) + { + { [ [ first ] compare ] "by name" } + { [ [ second ] compare invert-comparison ] "by call count" } + } ; + +: ( profiler -- gadget ) + + { 5 5 } >>gap + over add-gadget + "Sort by:"