From 3f6893eb290e76f34e0378c2e22da78ad556b47a Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Mon, 26 Sep 2005 01:56:48 +0000 Subject: [PATCH] new describe tool is useful stand-alone --- library/bootstrap/boot-stage1.factor | 1 + library/tools/describe.factor | 49 ++++++++++++++++++++++++++++ library/tools/inspector.factor | 49 ++-------------------------- 3 files changed, 52 insertions(+), 47 deletions(-) create mode 100644 library/tools/describe.factor diff --git a/library/bootstrap/boot-stage1.factor b/library/bootstrap/boot-stage1.factor index 15b58f0ed2..769b8c403f 100644 --- a/library/bootstrap/boot-stage1.factor +++ b/library/bootstrap/boot-stage1.factor @@ -95,6 +95,7 @@ sequences io vectors words ; "/library/syntax/prettyprint.factor" "/library/tools/interpreter.factor" + "/library/tools/describe.factor" "/library/tools/debugger.factor" "/library/tools/memory.factor" "/library/tools/listener.factor" diff --git a/library/tools/describe.factor b/library/tools/describe.factor new file mode 100644 index 0000000000..985d71bffb --- /dev/null +++ b/library/tools/describe.factor @@ -0,0 +1,49 @@ +! Copyright (C) 2005 Slava Pestov. +! See http://factor.sf.net/license.txt for BSD license. +IN: inspector +USING: arrays generic hashtables io kernel kernel-internals +lists math prettyprint sequences strings vectors words ; + +GENERIC: sheet ( obj -- sheet ) + +M: object sheet ( obj -- sheet ) + dup class "slots" word-prop + dup [ second ] map -rot + [ first slot ] map-with + 2array ; + +M: list sheet 1array ; + +M: vector sheet 1array ; + +M: array sheet 1array ; + +M: hashtable sheet dup hash-keys swap hash-values 2array ; + +: format-column ( list -- list ) + [ [ pprint-short ] string-out ] map + [ 0 [ length max ] reduce ] keep + [ swap CHAR: \s pad-right ] map-with ; + +: format-sheet ( sheet -- list ) + [ format-column ] map flip [ " " join ] map ; + +: describe ( object -- ) + sheet dup format-sheet swap peek + [ dup [ describe ] curry write-outliner ] 2each ; + +: word. ( word -- ) + dup word-name swap dup [ see ] curry write-outliner ; + +: vocab. ( vocab -- ) + f over [ words [ word. ] each ] curry write-outliner ; + +: browser ( -- ) + #! Outlining word browser. + vocabs [ vocab. ] each ; + +: stack. ( seq -- seq ) + reverse-slice >array describe ; + +: .s datastack stack. ; +: .r callstack stack. ; diff --git a/library/tools/inspector.factor b/library/tools/inspector.factor index 40e0885bbe..2a020d43ea 100644 --- a/library/tools/inspector.factor +++ b/library/tools/inspector.factor @@ -1,53 +1,8 @@ ! Copyright (C) 2005 Slava Pestov. ! See http://factor.sf.net/license.txt for BSD license. IN: inspector -USING: arrays generic hashtables io kernel kernel-internals -listener lists math memory namespaces prettyprint sequences -strings styles test vectors words ; - -GENERIC: sheet ( obj -- sheet ) - -M: object sheet ( obj -- sheet ) - dup class "slots" word-prop - dup [ second ] map -rot - [ first slot ] map-with - 2array ; - -M: list sheet 1array ; - -M: vector sheet 1array ; - -M: array sheet 1array ; - -M: hashtable sheet dup hash-keys swap hash-values 2array ; - -: format-column ( list -- list ) - [ [ pprint-short ] string-out ] map - [ 0 [ length max ] reduce ] keep - [ swap CHAR: \s pad-right ] map-with ; - -: format-sheet ( sheet -- list ) - [ format-column ] map flip [ " " join ] map ; - -: describe ( object -- ) - sheet dup format-sheet swap peek - [ dup [ describe ] curry write-outliner ] 2each ; - -: word. ( word -- ) - dup word-name swap dup [ see ] curry write-outliner ; - -: vocab. ( vocab -- ) - f over [ words [ word. ] each ] curry write-outliner ; - -: browser ( -- ) - #! Outlining word browser. - vocabs [ vocab. ] each ; - -: stack. ( seq -- seq ) - reverse-slice >array describe ; - -: .s datastack stack. ; -: .r callstack stack. ; +USING: arrays generic io kernel listener memory namespaces +prettyprint sequences words ; ! Interactive inspector GENERIC: extra-banner ( obj -- )