From 764cf6d3146c27742d206c60961c0a8d3801cfd2 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Tue, 4 Oct 2005 00:54:05 +0000 Subject: [PATCH] inspector improvements --- library/tools/describe.factor | 46 +++++++++++++++++++++++++++++++++- library/tools/inspector.factor | 27 +------------------- library/ui/editors.factor | 2 +- library/ui/load.factor | 6 ++--- library/ui/world.factor | 2 +- 5 files changed, 51 insertions(+), 32 deletions(-) diff --git a/library/tools/describe.factor b/library/tools/describe.factor index a6fc248415..4dfa276545 100644 --- a/library/tools/describe.factor +++ b/library/tools/describe.factor @@ -4,22 +4,66 @@ IN: inspector USING: arrays generic hashtables io kernel kernel-internals lists math prettyprint sequences strings vectors words ; +GENERIC: summary ( object -- string ) + +: sign-string ( n -- string ) + 0 > "a positive " "a negative " ? ; + +M: integer summary + dup sign-string over 2 mod 0 = "even " "odd " ? + rot class word-name append3 ; + +M: real summary + dup sign-string swap class word-name append ; + +: quadrant ( z -- n ) + >rect >r 0 >= 2 0 ? r> 0 >= 1 0 ? + ; + +M: complex summary + "a complex number in the " + swap quadrant { "first" "second" "third" "fourth" } nth + " quadrant" append3 ; + GENERIC: sheet ( obj -- sheet ) +M: object summary + "an instance of the " swap class word-name " class" append3 ; + M: object sheet ( obj -- sheet ) dup class "slots" word-prop dup [ second ] map -rot [ first slot ] map-with 2array ; +M: sequence summary + dup length 1 = [ + drop "a sequence of 1 element" + ] [ + "a sequence of " swap length number>string + " elements" append3 + ] if ; + M: list sheet 1array ; M: vector sheet 1array ; M: array sheet 1array ; +M: hashtable summary + "a hashtable storing " swap hash-size number>string + " keys" append3 ; + M: hashtable sheet dup hash-keys swap hash-values 2array ; +M: word summary ( word -- ) + dup word-vocabulary [ + dup interned? + "a word in the " "a word orphaned from the " ? + swap word-vocabulary " vocabulary" append3 + ] [ + drop "a uniquely generated symbol" + ] if ; + : format-column ( list ? -- list ) >r [ unparse-short ] map r> [ @@ -39,7 +83,7 @@ DEFER: describe dup format-sheet swap peek [ dup [ describe ] curry write-outliner ] 2each ; -: describe ( object -- ) sheet sheet. ; +: describe ( object -- ) dup summary print sheet sheet. ; : word. ( word -- ) dup word-name swap dup [ see ] curry write-outliner ; diff --git a/library/tools/inspector.factor b/library/tools/inspector.factor index 2a020d43ea..26938e9290 100644 --- a/library/tools/inspector.factor +++ b/library/tools/inspector.factor @@ -5,31 +5,6 @@ USING: arrays generic io kernel listener memory namespaces prettyprint sequences words ; ! Interactive inspector -GENERIC: extra-banner ( obj -- ) - -M: word extra-banner ( word -- ) - dup word-vocabulary [ - dup interned? [ - "This word is located in the " write - ] [ - "This is an orphan not part of the dictionary." print - "It claims to belong to the " write - ] if - word-vocabulary pprint " vocabulary." print - ] [ - drop - "The word is a uniquely generated symbol." print - ] if ; - -M: object extra-banner ( obj -- ) drop ; - -: inspect-banner ( obj -- ) - "You are looking at an instance of the " write dup class pprint - " class:" print - " " write dup pprint-short terpri - "It takes up " write dup size pprint " bytes of memory." print - extra-banner ; - SYMBOL: inspector-slots : sheet-numbers ( sheet -- sheet ) @@ -42,7 +17,7 @@ SYMBOL: inspector-stack : (inspect) ( obj -- ) dup inspector-stack get push - dup inspect-banner + dup summary print sheet sheet-numbers sheet. ; : inspector-help ( -- ) diff --git a/library/ui/editors.factor b/library/ui/editors.factor index 23d81da5a7..61507f4c70 100644 --- a/library/ui/editors.factor +++ b/library/ui/editors.factor @@ -72,7 +72,7 @@ TUPLE: editor line caret ; dup screen-loc swap editor-caret rect-extent nip v+ ; : ( completion editor -- menu-item ) - dupd [ [ complete ] with-editor ] curry curry cons ; + dupd [ [ complete ] with-editor drop ] curry curry cons ; : ( editor completions -- menu ) [ swap ] map-with ; diff --git a/library/ui/load.factor b/library/ui/load.factor index 790cd2c046..c3b8c1193c 100644 --- a/library/ui/load.factor +++ b/library/ui/load.factor @@ -5,13 +5,13 @@ USING: kernel parser sequences io ; "/library/ui/hierarchy.factor" "/library/ui/paint.factor" "/library/ui/theme.factor" + "/library/ui/world.factor" + "/library/ui/gestures.factor" + "/library/ui/hand.factor" "/library/ui/fonts.factor" "/library/ui/text.factor" - "/library/ui/gestures.factor" "/library/ui/borders.factor" "/library/ui/frames.factor" - "/library/ui/world.factor" - "/library/ui/hand.factor" "/library/ui/labels.factor" "/library/ui/buttons.factor" "/library/ui/line-editor.factor" diff --git a/library/ui/world.factor b/library/ui/world.factor index 16f0b9cbaa..a2c25e487a 100644 --- a/library/ui/world.factor +++ b/library/ui/world.factor @@ -50,7 +50,7 @@ DEFER: handle-event : world-step ( -- ? ) world get dup world-invalid >r layout-world r> - [ dup world-hand update-hand draw-world ] [ drop ] if ; + [ dup world-hand update-hand dup draw-world ] when drop ; : next-event ( -- event ? ) dup SDL_PollEvent ;