1 ! Copyright (C) 2005, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays generic hashtables io kernel assocs math
4 namespaces prettyprint sequences strings io.styles vectors words
5 quotations mirrors splitting math.parser classes vocabs refs
6 sets sorting summary debugger continuations fry ;
9 : value-editor ( path -- )
11 [ pprint-short ] presented-printer set
12 dup presented-path set
14 [ get-ref pprint-short ] with-nesting ;
20 : write-slot-editor ( path -- )
29 : write-key ( mirror key -- )
31 [ 2drop ] [ <key-ref> write-slot-editor ] if ;
33 : write-value ( mirror key -- )
34 <value-ref> write-slot-editor ;
36 : describe-row ( mirror key n -- )
38 +number-rows+ get [ pprint-cell ] [ drop ] if
39 [ write-key ] [ write-value ] 2bi
42 : summary. ( obj -- ) [ summary ] keep write-object nl ;
44 : sorted-keys ( assoc -- alist )
47 [ [ unparse-short ] keep ] { } map>assoc
51 : describe* ( obj mirror keys -- )
54 dup enum? [ +sequence+ on ] when
55 standard-table-style [
56 swap '[ [ _ ] 2dip describe-row ] each-index
61 dup make-mirror dup sorted-keys describe* ;
63 M: tuple error. describe ;
65 : namestack. ( seq -- )
66 [ [ global eq? not ] filter [ keys ] gather ] keep
67 '[ dup _ assoc-stack ] H{ } map>assoc describe ;
70 namestack namestack. ;
73 error-continuation get name>> namestack. ;
75 SYMBOL: inspector-hook
77 [ t +number-rows+ [ describe* ] with-variable ] inspector-hook set-global
79 SYMBOL: inspector-stack
83 : reinspect ( obj -- )
86 dup make-mirror dup mirror set dup sorted-keys dup \ keys set
87 inspector-hook get call
90 : (inspect) ( obj -- )
91 [ inspector-stack get push ] [ reinspect ] bi ;
93 : key@ ( n -- key ) \ keys get nth ;
95 : &push ( -- obj ) me get ;
97 : &at ( n -- ) key@ mirror get at (inspect) ;
101 dup length 1 <= [ drop ] [ dup pop* peek reinspect ] if ;
103 : &add ( value key -- ) mirror get set-at &push reinspect ;
105 : &put ( value n -- ) key@ &add ;
107 : &delete ( n -- ) key@ mirror get delete-at &push reinspect ;
109 : &rename ( key n -- ) key@ mirror get rename-at &push reinspect ;
112 #! A tribute to Slate:
113 "You are in a twisty little maze of objects, all alike." print
115 "'n' is a slot number in the following:" print
117 "&back -- return to previous object" print
118 "&push ( -- obj ) push this object" print
119 "&at ( n -- ) inspect nth slot" print
120 "&put ( value n -- ) change nth slot" print
121 "&add ( value key -- ) add new slot" print
122 "&delete ( n -- ) remove a slot" print
123 "&rename ( key n -- ) change a slot's key" print
124 "&globals ( -- ) inspect global namespace" print
125 "&help -- display this message" print
128 : inspector ( obj -- )
130 V{ } clone inspector-stack set
134 inspector-stack get [ (inspect) ] [ inspector ] if ;
136 : &globals ( -- ) global inspect ;