From a25b0a8cb15d60ff3c75de89fe4d0d98a3cc874a Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 27 Jun 2008 00:48:05 -0500 Subject: [PATCH] Fix &add, etc --- core/inspector/inspector-tests.factor | 26 ++++++++++++++++++++++++++ core/inspector/inspector.factor | 11 +++++++++-- core/mirrors/mirrors.factor | 9 ++------- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/core/inspector/inspector-tests.factor b/core/inspector/inspector-tests.factor index 72c1a9a6bf..c230364342 100644 --- a/core/inspector/inspector-tests.factor +++ b/core/inspector/inspector-tests.factor @@ -9,3 +9,29 @@ H{ } describe H{ } describe [ "fixnum instance\n" ] [ [ 3 describe ] with-string-writer ] unit-test + +[ ] [ inspector-hook get-global inspector-hook set ] unit-test + +[ ] [ H{ } clone inspect ] unit-test + +[ ] [ "a" "b" &add ] unit-test + +[ H{ { "b" "a" } } ] [ me get ] unit-test + +[ ] [ "x" 0 &put ] unit-test + +[ H{ { "b" "x" } } ] [ me get ] unit-test + +[ ] [ 0 &at ] unit-test + +[ "x" ] [ me get ] unit-test + +[ ] [ &back ] unit-test + +[ ] [ "y" 0 &rename ] unit-test + +[ H{ { "y" "x" } } ] [ me get ] unit-test + +[ ] [ 0 &delete ] unit-test + +[ H{ } ] [ me get ] unit-test diff --git a/core/inspector/inspector.factor b/core/inspector/inspector.factor index fd4e11901a..d32f1c90cf 100755 --- a/core/inspector/inspector.factor +++ b/core/inspector/inspector.factor @@ -3,7 +3,7 @@ USING: arrays generic hashtables io kernel assocs math namespaces prettyprint sequences strings io.styles vectors words quotations mirrors splitting math.parser classes vocabs refs -sets ; +sets sorting ; IN: inspector GENERIC: summary ( object -- string ) @@ -78,10 +78,17 @@ SYMBOL: +editable+ : summary. ( obj -- ) [ summary ] keep write-object nl ; +: sorted-keys ( assoc -- alist ) + dup mirror? [ keys ] [ + keys + [ [ unparse-short ] keep ] { } map>assoc + sort-keys values + ] if ; + : describe* ( obj flags -- ) clone [ dup summary. - make-mirror dup keys dup empty? [ + make-mirror dup sorted-keys dup empty? [ 2drop ] [ dup enum? [ +sequence+ on ] when diff --git a/core/mirrors/mirrors.factor b/core/mirrors/mirrors.factor index 0a49163075..607ba1542f 100755 --- a/core/mirrors/mirrors.factor +++ b/core/mirrors/mirrors.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: assocs hashtables kernel sequences generic words arrays classes slots slots.private classes.tuple math vectors -quotations sorting prettyprint accessors ; +quotations accessors ; IN: mirrors : all-slots ( class -- slots ) @@ -47,13 +47,8 @@ M: mirror assoc-size mirror-slots length ; INSTANCE: mirror assoc -: sort-assoc ( assoc -- alist ) - >alist - [ [ first unparse-short ] keep ] { } map>assoc - sort-keys values ; - GENERIC: make-mirror ( obj -- assoc ) -M: hashtable make-mirror sort-assoc ; +M: hashtable make-mirror ; M: integer make-mirror drop f ; M: array make-mirror ; M: vector make-mirror ;