From 6c0dd93ff116eeab9930d37f79a79a11fc26f5bf Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Thu, 21 Feb 2008 01:26:44 -0600 Subject: [PATCH] :vars and .vars --- core/debugger/debugger.factor | 3 +++ core/inspector/inspector.factor | 11 ++++++++++- core/mirrors/mirrors.factor | 11 ++++++++--- core/prettyprint/prettyprint-tests.factor | 2 +- core/prettyprint/prettyprint.factor | 3 +++ 5 files changed, 25 insertions(+), 5 deletions(-) mode change 100644 => 100755 core/inspector/inspector.factor mode change 100644 => 100755 core/mirrors/mirrors.factor diff --git a/core/debugger/debugger.factor b/core/debugger/debugger.factor index 776e2976d9..95470dcbcd 100755 --- a/core/debugger/debugger.factor +++ b/core/debugger/debugger.factor @@ -31,6 +31,9 @@ M: string error. print ; : :get ( variable -- value ) error-continuation get continuation-name assoc-stack ; +: :vars ( -- ) + error-continuation get continuation-name namestack. ; + : :res ( n -- ) 1- restarts get-global nth f restarts set-global restart ; diff --git a/core/inspector/inspector.factor b/core/inspector/inspector.factor old mode 100644 new mode 100755 index 868cffb81c..449d34f05b --- a/core/inspector/inspector.factor +++ b/core/inspector/inspector.factor @@ -1,4 +1,4 @@ -! Copyright (C) 2005, 2007 Slava Pestov. +! Copyright (C) 2005, 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: arrays generic hashtables io kernel assocs math namespaces prettyprint sequences strings io.styles vectors words @@ -93,6 +93,15 @@ SYMBOL: +editable+ : describe ( obj -- ) H{ } describe* ; +: namestack. ( seq -- ) + [ + [ global eq? not ] subset + [ keys ] map concat prune + ] keep [ dupd assoc-stack ] curry H{ } map>assoc describe ; + +: .vars ( -- ) + namestack namestack. ; + SYMBOL: inspector-hook [ H{ { +number-rows+ t } } describe* ] inspector-hook set-global diff --git a/core/mirrors/mirrors.factor b/core/mirrors/mirrors.factor old mode 100644 new mode 100755 index 7d3d5a53d0..af540ef86c --- a/core/mirrors/mirrors.factor +++ b/core/mirrors/mirrors.factor @@ -1,8 +1,8 @@ -! Copyright (C) 2007 Slava Pestov. +! Copyright (C) 2007, 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: assocs hashtables kernel sequences generic words arrays classes slots slots.private tuples math vectors -quotations ; +quotations sorting prettyprint ; IN: mirrors GENERIC: object-slots ( obj -- seq ) @@ -69,8 +69,13 @@ M: enum clear-assoc enum-seq delete-all ; INSTANCE: enum assoc +: sort-assoc ( assoc -- alist ) + >alist + [ dup first unparse-short swap ] { } map>assoc + sort-keys values ; + GENERIC: make-mirror ( obj -- assoc ) -M: hashtable make-mirror ; +M: hashtable make-mirror sort-assoc ; M: integer make-mirror drop f ; M: array make-mirror ; M: vector make-mirror ; diff --git a/core/prettyprint/prettyprint-tests.factor b/core/prettyprint/prettyprint-tests.factor index 11a685d581..a159cc8733 100755 --- a/core/prettyprint/prettyprint-tests.factor +++ b/core/prettyprint/prettyprint-tests.factor @@ -67,7 +67,7 @@ unit-test [ "[ \\ [ ]" ] [ [ \ [ ] unparse ] unit-test [ t ] [ - 100 \ dup [ pprint-short ] with-string-writer + 100 \ dup unparse-short "{" head? ] unit-test diff --git a/core/prettyprint/prettyprint.factor b/core/prettyprint/prettyprint.factor index 44477b740d..0cbde2a586 100755 --- a/core/prettyprint/prettyprint.factor +++ b/core/prettyprint/prettyprint.factor @@ -75,6 +75,9 @@ combinators quotations ; { string-limit t } } clone [ pprint ] bind ; +: unparse-short ( obj -- str ) + [ pprint-short ] with-string-writer ; + : short. ( obj -- ) pprint-short nl ; : .b ( n -- ) >bin print ;